forked from edo9300/ygopro-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibdebug.cpp
229 lines (227 loc) · 6.94 KB
/
libdebug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* libdebug.cpp
*
* Created on: 2012-2-8
* Author: Argon
*/
#include <string.h>
#include "scriptlib.h"
#include "duel.h"
#include "field.h"
#include "card.h"
#include "effect.h"
#include "ocgapi.h"
int32 scriptlib::debug_message(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
lua_getglobal(L, "tostring");
lua_pushvalue(L, -2);
lua_pcall(L, 1, 1, 0);
interpreter::sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
handle_message(pduel, 2);
return 0;
}
int32 scriptlib::debug_add_card(lua_State *L) {
check_param_count(L, 6);
duel* pduel = interpreter::get_duel_info(L);
int32 code = lua_tonumberint(L, 1);
int32 owner = lua_tonumberint(L, 2);
int32 playerid = lua_tonumberint(L, 3);
int32 location = lua_tonumberint(L, 4);
int32 sequence = lua_tonumberint(L, 5);
int32 position = lua_tonumberint(L, 6);
int32 proc = lua_toboolean(L, 7);
if(owner != 0 && owner != 1)
return 0;
if(playerid != 0 && playerid != 1)
return 0;
if(pduel->game_field->is_location_useable(playerid, location, sequence)) {
card* pcard = pduel->new_card(code);
pcard->owner = owner;
pcard->sendto_param.position = position;
if(location == LOCATION_PZONE) {
int32 seq = pduel->game_field->get_pzone_index(sequence);
pduel->game_field->add_card(playerid, pcard, LOCATION_SZONE, seq, TRUE);
} else if(location == LOCATION_FZONE) {
int32 loc = LOCATION_SZONE;
pduel->game_field->add_card(playerid, pcard, loc, 5);
} else
pduel->game_field->add_card(playerid, pcard, location, sequence);
pcard->current.position = position;
if(!(location & (LOCATION_ONFIELD | LOCATION_PZONE)) || (position & POS_FACEUP)) {
pcard->enable_field_effect(true);
pduel->game_field->adjust_instant();
}
if(proc)
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
interpreter::card2value(L, pcard);
return 1;
} else if(location == LOCATION_MZONE) {
card* pcard = pduel->new_card(code);
pcard->owner = owner;
card* fcard = pduel->game_field->get_field_card(playerid, location, sequence);
fcard->xyz_materials.push_back(pcard);
pcard->overlay_target = fcard;
pcard->current.controler = playerid;
pcard->current.location = LOCATION_OVERLAY;
pcard->current.sequence = fcard->xyz_materials.size() - 1;
for(auto& eit : pcard->xmaterial_effect) {
effect* peffect = eit.second;
if(peffect->type & EFFECT_TYPE_FIELD)
pduel->game_field->add_effect(peffect);
}
interpreter::card2value(L, pcard);
return 1;
}
return 0;
}
int32 scriptlib::debug_set_player_info(lua_State *L) {
check_param_count(L, 4);
duel* pduel = interpreter::get_duel_info(L);
uint32 playerid = lua_tonumberint(L, 1);
uint32 lp = lua_tonumberint(L, 2);
uint32 startcount = lua_tonumberint(L, 3);
uint32 drawcount = lua_tonumberint(L, 4);
if(playerid != 0 && playerid != 1)
return 0;
pduel->game_field->player[playerid].lp = lp;
pduel->game_field->player[playerid].start_lp = lp;
pduel->game_field->player[playerid].start_count = startcount;
pduel->game_field->player[playerid].draw_count = drawcount;
return 0;
}
int32 scriptlib::debug_pre_summon(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
uint32 summon_type = lua_tonumberint(L, 2);
uint8 summon_location = 0;
if(lua_gettop(L) > 2)
summon_location = lua_tonumberint(L, 3);
pcard->summon_info = summon_type | (summon_location << 16);
return 0;
}
int32 scriptlib::debug_pre_equip(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_CARD, 2);
card* equip_card = *(card**) lua_touserdata(L, 1);
card* target = *(card**) lua_touserdata(L, 2);
if((equip_card->current.location != LOCATION_SZONE)
|| (target->current.location != LOCATION_MZONE)
|| (target->current.position & POS_FACEDOWN))
lua_pushboolean(L, 0);
else {
equip_card->equip(target, FALSE);
equip_card->effect_target_cards.insert(target);
target->effect_target_owner.insert(equip_card);
lua_pushboolean(L, 1);
}
return 1;
}
int32 scriptlib::debug_pre_set_target(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_CARD, 2);
card* t_card = *(card**) lua_touserdata(L, 1);
card* target = *(card**) lua_touserdata(L, 2);
t_card->add_card_target(target);
return 0;
}
int32 scriptlib::debug_pre_add_counter(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
uint32 countertype = lua_tonumberint(L, 2);
uint32 count = lua_tonumberint(L, 3);
uint16 cttype = countertype & ~COUNTER_NEED_ENABLE;
auto pr = pcard->counters.emplace(cttype, card::counter_map::mapped_type());
auto cmit = pr.first;
if(pr.second) {
cmit->second[0] = 0;
cmit->second[1] = 0;
}
if((countertype & COUNTER_WITHOUT_PERMIT) && !(countertype & COUNTER_NEED_ENABLE))
cmit->second[0] += count;
else
cmit->second[1] += count;
return 0;
}
int32 scriptlib::debug_reload_field_begin(lua_State *L) {
check_param_count(L, 1);
duel* pduel = interpreter::get_duel_info(L);
uint32 flag = lua_tonumberint(L, 1);
int32 rule = lua_tonumberint(L, 2);
bool build = lua_toboolean(L, 3);
if (!rule)
rule = 3;
pduel->clear();
if(rule && !build) {
switch (rule) {
case 1: {
flag |= MASTER_RULE_1;
break;
}
case 2: {
flag |= MASTER_RULE_2;
break;
}
case 3: {
flag |= MASTER_RULE_3;
break;
}
case 4: {
flag |= MASTER_RULE_4;
break;
}
}
} else if (flag & DUEL_OBSOLETE_RULING) {
flag |= MASTER_RULE_1;
pduel->game_field->core.duel_rule = 1;
pduel->game_field->core.duel_options = flag;
return 0;
}
pduel->game_field->core.duel_rule = 2;
if(flag & DUEL_EMZONE)
pduel->game_field->core.duel_rule = 4;
else if (flag & DUEL_PZONE)
pduel->game_field->core.duel_rule = 3;
pduel->game_field->core.duel_options = flag;
return 0;
}
int32 scriptlib::debug_reload_field_end(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->core.shuffle_hand_check[0] = FALSE;
pduel->game_field->core.shuffle_hand_check[1] = FALSE;
pduel->game_field->core.shuffle_deck_check[0] = FALSE;
pduel->game_field->core.shuffle_deck_check[1] = FALSE;
pduel->game_field->reload_field_info();
return 0;
}
int32 scriptlib::debug_set_ai_name(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_STRING, 1);
duel* pduel = interpreter::get_duel_info(L);
pduel->write_buffer8(MSG_AI_NAME);
const char* pstr = lua_tostring(L, 1);
int len = strlen(pstr);
if(len > 100)
len = 100;
pduel->write_buffer16(len);
pduel->write_buffer((void*)pstr, len);
pduel->write_buffer8(0);
return 0;
}
int32 scriptlib::debug_show_hint(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_STRING, 1);
duel* pduel = interpreter::get_duel_info(L);
pduel->write_buffer8(MSG_SHOW_HINT);
const char* pstr = lua_tostring(L, 1);
int len = strlen(pstr);
if(len > 1024)
len = 1024;
pduel->write_buffer16(len);
pduel->write_buffer((void*)pstr, len);
pduel->write_buffer8(0);
return 0;
}