Commit 3f7aa8ed authored by DailyShana's avatar DailyShana Committed by GitHub

use lua continuation to give return value of operation functions (#222)

* use lua continuation to give return value of operation functions
* update
* fix
* fix
* fix
* tweak
parent b20174d9
......@@ -707,7 +707,6 @@ public:
#define PROCESSOR_SELECT_PLACE 18
#define PROCESSOR_SELECT_POSITION 19
#define PROCESSOR_SELECT_TRIBUTE_P 20
//#define PROCESSOR_SORT_CHAIN 21
#define PROCESSOR_SELECT_COUNTER 22
#define PROCESSOR_SELECT_SUM 23
#define PROCESSOR_SELECT_DISFIELD 24
......@@ -756,10 +755,6 @@ public:
#define PROCESSOR_ATTACK_DISABLE 82
#define PROCESSOR_ACTIVATE_EFFECT 83
#define PROCESSOR_DESTROY_S 100
#define PROCESSOR_RELEASE_S 101
#define PROCESSOR_SENDTO_S 102
#define PROCESSOR_CHANGEPOS_S 103
#define PROCESSOR_ANNOUNCE_RACE 110
#define PROCESSOR_ANNOUNCE_ATTRIB 111
#define PROCESSOR_ANNOUNCE_LEVEL 112
......@@ -770,36 +765,43 @@ public:
#define PROCESSOR_TOSS_DICE 117
#define PROCESSOR_TOSS_COIN 118
#define PROCESSOR_ROCK_PAPER_SCISSORS 119
#define PROCESSOR_SELECT_YESNO_S 120
#define PROCESSOR_SELECT_OPTION_S 121
#define PROCESSOR_SELECT_CARD_S 122
#define PROCESSOR_SELECT_EFFECTYN_S 123
#define PROCESSOR_SELECT_UNSELECT_CARD_S 124
//#define PROCESSOR_SELECT_PLACE_S 125
#define PROCESSOR_SELECT_POSITION_S 126
#define PROCESSOR_SELECT_TRIBUTE_S 127
#define PROCESSOR_SORT_CARDS_S 128
#define PROCESSOR_SELECT_RELEASE_S 129
#define PROCESSOR_SELECT_TARGET 130
#define PROCESSOR_SELECT_FUSION 131
#define PROCESSOR_SELECT_SYNCHRO 132
#define PROCESSOR_SELECT_SUM_S 133
#define PROCESSOR_SELECT_DISFIELD_S 134
#define PROCESSOR_SPSUMMON_S 135
#define PROCESSOR_SPSUMMON_STEP_S 136
#define PROCESSOR_SPSUMMON_COMP_S 137
#define PROCESSOR_RANDOM_SELECT_S 138
#define PROCESSOR_SELECT_XMATERIAL 139
#define PROCESSOR_DRAW_S 140
#define PROCESSOR_DAMAGE_S 141
#define PROCESSOR_RECOVER_S 142
#define PROCESSOR_EQUIP_S 143
#define PROCESSOR_GET_CONTROL_S 144
#define PROCESSOR_SWAP_CONTROL_S 145
#define PROCESSOR_DISCARD_HAND_S 150
#define PROCESSOR_DISCARD_DECK_S 151
#define PROCESSOR_SORT_DECK_S 152
#define PROCESSOR_REMOVEOL_S 160
#define PROCESSOR_MOVETOFIELD_S 161
#define PROCESSOR_DISCARD_HAND 150
#define PROCESSOR_DISCARD_DECK 151
#define PROCESSOR_SORT_DECK 152
#define PROCESSOR_REMOVE_OVERLAY 160
//#define PROCESSOR_SORT_CHAIN 21
//#define PROCESSOR_DESTROY_S 100
//#define PROCESSOR_RELEASE_S 101
//#define PROCESSOR_SENDTO_S 102
//#define PROCESSOR_CHANGEPOS_S 103
//#define PROCESSOR_SELECT_YESNO_S 120
//#define PROCESSOR_SELECT_OPTION_S 121
//#define PROCESSOR_SELECT_CARD_S 122
//#define PROCESSOR_SELECT_EFFECTYN_S 123
//#define PROCESSOR_SELECT_UNSELECT_CARD_S 124
//#define PROCESSOR_SELECT_PLACE_S 125
//#define PROCESSOR_SELECT_POSITION_S 126
//#define PROCESSOR_SELECT_TRIBUTE_S 127
//#define PROCESSOR_SORT_CARDS_S 128
//#define PROCESSOR_SELECT_RELEASE_S 129
//#define PROCESSOR_SELECT_TARGET 130
//#define PROCESSOR_SELECT_SUM_S 133
//#define PROCESSOR_SELECT_DISFIELD_S 134
//#define PROCESSOR_SPSUMMON_S 135
//#define PROCESSOR_SPSUMMON_STEP_S 136
//#define PROCESSOR_SPSUMMON_COMP_S 137
//#define PROCESSOR_RANDOM_SELECT_S 138
//#define PROCESSOR_DRAW_S 140
//#define PROCESSOR_DAMAGE_S 141
//#define PROCESSOR_RECOVER_S 142
//#define PROCESSOR_EQUIP_S 143
//#define PROCESSOR_GET_CONTROL_S 144
//#define PROCESSOR_SWAP_CONTROL_S 145
//#define PROCESSOR_MOVETOFIELD_S 161
#endif /* FIELD_H_ */
......@@ -1345,7 +1345,11 @@ int32 scriptlib::card_remove_overlay_card(lua_State *L) {
int32 reason = lua_tointeger(L, 5);
duel* pduel = pcard->pduel;
pduel->game_field->remove_overlay_card(reason, pcard, playerid, 0, 0, min, max);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::card_get_attacked_group(lua_State *L) {
check_param_count(L, 1);
......@@ -2572,21 +2576,26 @@ int32 scriptlib::card_remove_counter(lua_State *L) {
uint32 countertype = lua_tointeger(L, 3);
uint32 count = lua_tointeger(L, 4);
uint32 reason = lua_tointeger(L, 5);
duel* pduel = pcard->pduel;
if(countertype == 0) {
// c38834303: remove all counters
for(const auto& cmit : pcard->counters) {
pcard->pduel->write_buffer8(MSG_REMOVE_COUNTER);
pcard->pduel->write_buffer16(cmit.first);
pcard->pduel->write_buffer8(pcard->current.controler);
pcard->pduel->write_buffer8(pcard->current.location);
pcard->pduel->write_buffer8(pcard->current.sequence);
pcard->pduel->write_buffer16(cmit.second[0] + cmit.second[1]);
pduel->write_buffer8(MSG_REMOVE_COUNTER);
pduel->write_buffer16(cmit.first);
pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location);
pduel->write_buffer8(pcard->current.sequence);
pduel->write_buffer16(cmit.second[0] + cmit.second[1]);
}
pcard->counters.clear();
return 0;
} else {
pcard->pduel->game_field->remove_counter(reason, pcard, rplayer, 0, 0, countertype, count);
return lua_yield(L, 0);
pduel->game_field->remove_counter(reason, pcard, rplayer, 0, 0, countertype, count);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
}
int32 scriptlib::card_get_counter(lua_State *L) {
......
......@@ -199,8 +199,11 @@ int32 scriptlib::duel_destroy(lua_State *L) {
pduel->game_field->destroy(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, PLAYER_NONE, dest, 0);
else
pduel->game_field->destroy(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, PLAYER_NONE, dest, 0);
pduel->game_field->core.subunits.back().type = PROCESSOR_DESTROY_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_remove(lua_State *L) {
check_action_permission(L);
......@@ -222,8 +225,11 @@ int32 scriptlib::duel_remove(lua_State *L) {
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, pos);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, pos);
pduel->game_field->core.subunits.back().type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_sendto_grave(lua_State *L) {
check_action_permission(L);
......@@ -244,8 +250,11 @@ int32 scriptlib::duel_sendto_grave(lua_State *L) {
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
pduel->game_field->core.subunits.back().type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_summon(lua_State *L) {
check_action_permission(L);
......@@ -486,8 +495,11 @@ int32 scriptlib::duel_special_summon(lua_State *L) {
pduel->game_field->special_summon(&cset, sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
} else
pduel->game_field->special_summon(&(pgroup->container), sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
pduel->game_field->core.subunits.back().type = PROCESSOR_SPSUMMON_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_special_summon_step(lua_State *L) {
check_action_permission(L);
......@@ -505,14 +517,21 @@ int32 scriptlib::duel_special_summon_step(lua_State *L) {
if(lua_gettop(L) >= 8)
zone = lua_tointeger(L, 8);
pduel->game_field->special_summon_step(pcard, sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
pduel->game_field->core.subunits.back().type = PROCESSOR_SPSUMMON_STEP_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_special_summon_complete(lua_State *L) {
check_action_permission(L);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->special_summon_complete(pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_sendto_hand(lua_State *L) {
check_action_permission(L);
......@@ -536,8 +555,11 @@ int32 scriptlib::duel_sendto_hand(lua_State *L) {
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_HAND, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_HAND, 0, POS_FACEUP);
pduel->game_field->core.subunits.back().type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_sendto_deck(lua_State *L) {
check_action_permission(L);
......@@ -562,8 +584,11 @@ int32 scriptlib::duel_sendto_deck(lua_State *L) {
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_DECK, sequence, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_DECK, sequence, POS_FACEUP);
pduel->game_field->core.subunits.back().type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_sendto_extra(lua_State *L) {
check_action_permission(L);
......@@ -587,8 +612,11 @@ int32 scriptlib::duel_sendto_extra(lua_State *L) {
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
pduel->game_field->core.subunits.back().type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_get_operated_group(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
......@@ -629,7 +657,11 @@ int32 scriptlib::duel_remove_counter(lua_State *L) {
uint32 reason = lua_tointeger(L, 6);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->remove_counter(reason, 0, rplayer, s, o, countertype, count);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_is_can_remove_counter(lua_State *L) {
check_param_count(L, 6);
......@@ -685,8 +717,11 @@ int32 scriptlib::duel_change_form(lua_State *L) {
pduel->game_field->change_position(&cset, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE);
} else
pduel->game_field->change_position(&(pgroup->container), pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE);
pduel->game_field->core.subunits.back().type = PROCESSOR_CHANGEPOS_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_release(lua_State *L) {
check_action_permission(L);
......@@ -707,8 +742,11 @@ int32 scriptlib::duel_release(lua_State *L) {
pduel->game_field->release(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player);
else
pduel->game_field->release(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player);
pduel->game_field->core.subunits.back().type = PROCESSOR_RELEASE_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_move_to_field(lua_State *L) {
check_action_permission(L);
......@@ -729,8 +767,11 @@ int32 scriptlib::duel_move_to_field(lua_State *L) {
pcard->enable_field_effect(false);
pduel->game_field->adjust_instant();
pduel->game_field->move_to_field(pcard, move_player, playerid, destination, positions, enable, 0, FALSE, zone);
pduel->game_field->core.subunits.back().type = PROCESSOR_MOVETOFIELD_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_return_to_field(lua_State *L) {
check_action_permission(L);
......@@ -750,8 +791,11 @@ int32 scriptlib::duel_return_to_field(lua_State *L) {
pduel->game_field->adjust_instant();
pduel->game_field->refresh_location_info_instant();
pduel->game_field->move_to_field(pcard, pcard->previous.controler, pcard->previous.controler, pcard->previous.location, pos, TRUE, 1, 0, zone);
pduel->game_field->core.subunits.back().type = PROCESSOR_MOVETOFIELD_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_move_sequence(lua_State *L) {
check_param_count(L, 2);
......@@ -948,7 +992,7 @@ int32 scriptlib::duel_sort_decktop(lua_State *L) {
if(count < 1 || count > 16)
return 0;
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_SORT_DECK_S, 0, 0, 0, sort_player + (target_player << 16), count);
pduel->game_field->add_process(PROCESSOR_SORT_DECK, 0, 0, 0, sort_player + (target_player << 16), count);
return lua_yield(L, 0);
}
int32 scriptlib::duel_check_event(lua_State *L) {
......@@ -1147,8 +1191,11 @@ int32 scriptlib::duel_draw(lua_State *L) {
uint32 reason = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->draw(pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, count);
pduel->game_field->core.subunits.back().type = PROCESSOR_DRAW_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_damage(lua_State *L) {
check_action_permission(L);
......@@ -1165,8 +1212,11 @@ int32 scriptlib::duel_damage(lua_State *L) {
is_step = lua_toboolean(L, 4);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->damage(pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, 0, playerid, amount, is_step);
pduel->game_field->core.subunits.back().type = PROCESSOR_DAMAGE_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_recover(lua_State *L) {
check_action_permission(L);
......@@ -1183,8 +1233,11 @@ int32 scriptlib::duel_recover(lua_State *L) {
is_step = lua_toboolean(L, 4);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->recover(pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, amount, is_step);
pduel->game_field->core.subunits.back().type = PROCESSOR_RECOVER_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_rd_complete(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
......@@ -1209,8 +1262,11 @@ int32 scriptlib::duel_equip(lua_State *L) {
step = lua_toboolean(L, 5);
duel* pduel = target->pduel;
pduel->game_field->equip(playerid, equip_card, target, up, step);
pduel->game_field->core.subunits.back().type = PROCESSOR_EQUIP_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_equip_complete(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
......@@ -1262,8 +1318,11 @@ int32 scriptlib::duel_get_control(lua_State *L) {
pduel->game_field->get_control(pcard, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, playerid, reset_phase, reset_count, zone);
else
pduel->game_field->get_control(&pgroup->container, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, playerid, reset_phase, reset_count, zone);
pduel->game_field->core.subunits.back().type = PROCESSOR_GET_CONTROL_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_swap_control(lua_State *L) {
check_action_permission(L);
......@@ -1293,8 +1352,11 @@ int32 scriptlib::duel_swap_control(lua_State *L) {
pduel->game_field->swap_control(pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, pcard1, pcard2, reset_phase, reset_count);
else
pduel->game_field->swap_control(pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, &pgroup1->container, &pgroup2->container, reset_phase, reset_count);
pduel->game_field->core.subunits.back().type = PROCESSOR_SWAP_CONTROL_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_check_lp_cost(lua_State *L) {
check_param_count(L, 2);
......@@ -1324,8 +1386,12 @@ int32 scriptlib::duel_discard_deck(lua_State *L) {
uint32 count = lua_tointeger(L, 2);
uint32 reason = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_DISCARD_DECK_S, 0, 0, 0, playerid + (count << 16), reason);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_DISCARD_DECK, 0, 0, 0, playerid + (count << 16), reason);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_discard_hand(lua_State *L) {
check_action_permission(L);
......@@ -1354,8 +1420,12 @@ int32 scriptlib::duel_discard_hand(lua_State *L) {
lua_pushinteger(L, 0);
return 1;
}
pduel->game_field->add_process(PROCESSOR_DISCARD_HAND_S, 0, NULL, NULL, playerid, min + (max << 16), reason);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_DISCARD_HAND, 0, NULL, NULL, playerid, min + (max << 16), reason);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_disable_shuffle_check(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
......@@ -2109,7 +2179,11 @@ int32 scriptlib::duel_get_attack_target(lua_State *L) {
int32 scriptlib::duel_disable_attack(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_ATTACK_DISABLE, 0, 0, 0, 0, 0);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_chain_attack(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
......@@ -2127,7 +2201,6 @@ int32 scriptlib::duel_readjust(lua_State *L) {
pduel->game_field->core.readjust_map[adjcard]++;
if(pduel->game_field->core.readjust_map[adjcard] > 3) {
pduel->game_field->send_to(adjcard, 0, REASON_RULE, pduel->game_field->core.reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
pduel->game_field->core.subunits.back().type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
}
pduel->game_field->core.re_adjust = TRUE;
......@@ -2339,8 +2412,17 @@ int32 scriptlib::duel_select_matching_cards(lua_State *L) {
group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs);
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
pduel->game_field->add_process(PROCESSOR_SELECT_CARD_S, 0, 0, 0, playerid, min + (max << 16));
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
/**
* \brief Duel.GetReleaseGroup
......@@ -2427,8 +2509,17 @@ int32 scriptlib::duel_select_release_group(lua_State *L) {
pduel->game_field->core.release_cards_ex.clear();
pduel->game_field->core.release_cards_ex_oneof.clear();
pduel->game_field->get_release_list(playerid, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, use_con, FALSE, 2, extraargs, pexception, pexgroup);
pduel->game_field->add_process(PROCESSOR_SELECT_RELEASE_S, 0, 0, 0, playerid, (max << 16) + min);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_RELEASE, 0, 0, 0, playerid, (max << 16) + min);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
int32 scriptlib::duel_check_release_group_ex(lua_State *L) {
check_param_count(L, 4);
......@@ -2479,8 +2570,17 @@ int32 scriptlib::duel_select_release_group_ex(lua_State *L) {
pduel->game_field->core.release_cards_ex.clear();
pduel->game_field->core.release_cards_ex_oneof.clear();
pduel->game_field->get_release_list(playerid, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, use_con, TRUE, 2, extraargs, pexception, pexgroup);
pduel->game_field->add_process(PROCESSOR_SELECT_RELEASE_S, 0, 0, 0, playerid, (max << 16) + min);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_RELEASE, 0, 0, 0, playerid, (max << 16) + min);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
/**
* \brief Duel.GetTributeGroup
......@@ -2581,8 +2681,16 @@ int32 scriptlib::duel_select_tribute(lua_State *L) {
pduel->game_field->core.release_cards_ex_oneof.clear();
pduel->game_field->get_summon_release_list(target, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, mg, ex, releasable);
pduel->game_field->select_tribute_cards(0, playerid, 0, min, max, toplayer, zone);
pduel->game_field->core.subunits.back().type = PROCESSOR_SELECT_TRIBUTE_S;
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
/**
* \brief Duel.GetTargetCount
......@@ -2666,8 +2774,39 @@ int32 scriptlib::duel_select_target(lua_State *L) {
group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, 0, 0, TRUE);
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
pduel->game_field->add_process(PROCESSOR_SELECT_TARGET, 0, 0, 0, playerid, min + (max << 16));
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
chain* ch = pduel->game_field->get_chain(0);
if(!ch)
return 0;
if(!ch->target_cards) {
ch->target_cards = pduel->new_group();
ch->target_cards->is_readonly = TRUE;
}
group* tg = ch->target_cards;
effect* peffect = ch->triggering_effect;
if(peffect->type & EFFECT_TYPE_CONTINUOUS) {
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i)
tg->container.insert(pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]]);
interpreter::group2value(L, tg);
} else {
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
tg->container.insert(pcard);
pgroup->container.insert(pcard);
pcard->create_relation(*ch);
if(peffect->is_flag(EFFECT_FLAG_CARD_TARGET)) {
pduel->write_buffer8(MSG_BECOME_TARGET);
pduel->write_buffer8(1);
pduel->write_buffer32(pcard->get_info_location());
}
}
interpreter::group2value(L, pgroup);
}
return 1;
});
}
int32 scriptlib::duel_select_fusion_material(lua_State *L) {
check_action_permission(L);
......@@ -2688,7 +2827,17 @@ int32 scriptlib::duel_select_fusion_material(lua_State *L) {
card* pcard = *(card**) lua_touserdata(L, 2);
group* pgroup = *(group**) lua_touserdata(L, 3);
pcard->fusion_select(playerid, pgroup, cg, chkf);
return lua_yield(L, 0);
duel* pduel = pcard->pduel;
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group(pduel->game_field->core.fusion_materials);
if(lua_gettop(L) > 3 && !lua_isnil(L, 4)) {
card* cg = *(card**)lua_touserdata(L, 4);
pgroup->container.insert(cg);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
int32 scriptlib::duel_set_fusion_material(lua_State *L) {
check_param_count(L, 1);
......@@ -3163,7 +3312,11 @@ int32 scriptlib::duel_remove_overlay_card(lua_State *L) {
int32 reason = lua_tointeger(L, 6);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->remove_overlay_card(reason, 0, playerid, s, o, min, max);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_hint(lua_State * L) {
check_param_count(L, 3);
......@@ -3205,8 +3358,12 @@ int32 scriptlib::duel_select_effect_yesno(lua_State * L) {
if(lua_gettop(L) >= 3)
desc = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_SELECT_EFFECTYN_S, 0, 0, (group*)pcard, playerid, desc);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_EFFECTYN, 0, 0, (group*)pcard, playerid, desc);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_select_yesno(lua_State * L) {
check_action_permission(L);
......@@ -3216,8 +3373,12 @@ int32 scriptlib::duel_select_yesno(lua_State * L) {
return 0;
int32 desc = lua_tointeger(L, 2);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_SELECT_YESNO_S, 0, 0, 0, playerid, desc);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_YESNO, 0, 0, 0, playerid, desc);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_select_option(lua_State * L) {
check_action_permission(L);
......@@ -3230,8 +3391,17 @@ int32 scriptlib::duel_select_option(lua_State * L) {
pduel->game_field->core.select_options.clear();
for(uint32 i = 0; i < count; ++i)
pduel->game_field->core.select_options.push_back(lua_tointeger(L, i + 2));
pduel->game_field->add_process(PROCESSOR_SELECT_OPTION_S, 0, 0, 0, playerid, 0);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_OPTION, 0, 0, 0, playerid, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 playerid = lua_tointeger(L, 1);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_OPSELECTED);
pduel->write_buffer8(playerid);
pduel->write_buffer32(pduel->game_field->core.select_options[pduel->game_field->returns.ivalue[0]]);
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_select_sequence(lua_State * L) {
check_action_permission(L);
......@@ -3245,8 +3415,12 @@ int32 scriptlib::duel_select_position(lua_State * L) {
card* pcard = *(card**) lua_touserdata(L, 2);
uint32 positions = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_SELECT_POSITION_S, 0, 0, 0, playerid + (positions << 16), pcard->data.code);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_POSITION, 0, 0, 0, playerid + (positions << 16), pcard->data.code);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_select_disable_field(lua_State * L) {
check_action_permission(L);
......@@ -3281,8 +3455,23 @@ int32 scriptlib::duel_select_disable_field(lua_State * L) {
count = ct1 + ct2 + ct3 + ct4;
if(count == 0)
return 0;
pduel->game_field->add_process(PROCESSOR_SELECT_DISFIELD_S, 0, 0, 0, playerid, flag, count);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_DISFIELD, 0, 0, 0, playerid, flag, count);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 playerid = lua_tointeger(L, 1);
uint32 count = lua_tointeger(L, 2);
int32 dfflag = 0;
uint8 pa = 0;
for(uint32 i = 0; i < count; ++i) {
uint8 p = pduel->game_field->returns.bvalue[pa];
uint8 l = pduel->game_field->returns.bvalue[pa + 1];
uint8 s = pduel->game_field->returns.bvalue[pa + 2];
dfflag |= 0x1u << (s + (p == playerid ? 0 : 16) + (l == LOCATION_MZONE ? 0 : 8));
pa += 3;
}
lua_pushinteger(L, dfflag);
return 1;
});
}
int32 scriptlib::duel_announce_race(lua_State * L) {
check_action_permission(L);
......@@ -3292,7 +3481,11 @@ int32 scriptlib::duel_announce_race(lua_State * L) {
int32 available = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_ANNOUNCE_RACE, 0, 0, 0, playerid + (count << 16), available);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_announce_attribute(lua_State * L) {
check_action_permission(L);
......@@ -3302,7 +3495,11 @@ int32 scriptlib::duel_announce_attribute(lua_State * L) {
int32 available = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
pduel->game_field->add_process(PROCESSOR_ANNOUNCE_ATTRIB, 0, 0, 0, playerid + (count << 16), available);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_announce_level(lua_State * L) {
check_action_permission(L);
......@@ -3345,7 +3542,12 @@ int32 scriptlib::duel_announce_level(lua_State * L) {
if(count == 0)
return 0;
pduel->game_field->add_process(PROCESSOR_ANNOUNCE_NUMBER, 0, 0, 0, playerid + 0x10000, 0xc0001);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->core.select_options[pduel->game_field->returns.ivalue[0]]);
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 2;
});
}
int32 scriptlib::duel_announce_card(lua_State * L) {
check_action_permission(L);
......@@ -3357,7 +3559,11 @@ int32 scriptlib::duel_announce_card(lua_State * L) {
if(lua_gettop(L) >= 2)
ttype = lua_tointeger(L, 2);
pduel->game_field->add_process(PROCESSOR_ANNOUNCE_CARD, 0, 0, 0, playerid, ttype);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_announce_card_filter(lua_State * L) {
check_action_permission(L);
......@@ -3368,7 +3574,11 @@ int32 scriptlib::duel_announce_card_filter(lua_State * L) {
for(int32 i = 2; i <= lua_gettop(L); ++i)
pduel->game_field->core.select_options.push_back(lua_tointeger(L, i));
pduel->game_field->add_process(PROCESSOR_ANNOUNCE_CARD, 0, 0, 0, playerid, 0);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_announce_type(lua_State * L) {
check_action_permission(L);
......@@ -3379,8 +3589,17 @@ int32 scriptlib::duel_announce_type(lua_State * L) {
pduel->game_field->core.select_options.push_back(70);
pduel->game_field->core.select_options.push_back(71);
pduel->game_field->core.select_options.push_back(72);
pduel->game_field->add_process(PROCESSOR_SELECT_OPTION_S, 0, 0, 0, playerid, 0);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_OPTION, 0, 0, 0, playerid, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 playerid = lua_tointeger(L, 1);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_OPSELECTED);
pduel->write_buffer8(playerid);
pduel->write_buffer32(pduel->game_field->core.select_options[pduel->game_field->returns.ivalue[0]]);
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_announce_number(lua_State * L) {
check_action_permission(L);
......@@ -3391,7 +3610,12 @@ int32 scriptlib::duel_announce_number(lua_State * L) {
for(int32 i = 2; i <= lua_gettop(L); ++i)
pduel->game_field->core.select_options.push_back(lua_tointeger(L, i));
pduel->game_field->add_process(PROCESSOR_ANNOUNCE_NUMBER, 0, 0, 0, playerid, 0);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->core.select_options[pduel->game_field->returns.ivalue[0]]);
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 2;
});
}
int32 scriptlib::duel_announce_coin(lua_State * L) {
check_action_permission(L);
......@@ -3401,8 +3625,17 @@ int32 scriptlib::duel_announce_coin(lua_State * L) {
pduel->game_field->core.select_options.clear();
pduel->game_field->core.select_options.push_back(60);
pduel->game_field->core.select_options.push_back(61);
pduel->game_field->add_process(PROCESSOR_SELECT_OPTION_S, 0, 0, 0, playerid, 0);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_OPTION, 0, 0, 0, playerid, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 playerid = lua_tointeger(L, 1);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_OPSELECTED);
pduel->write_buffer8(playerid);
pduel->write_buffer32(pduel->game_field->core.select_options[pduel->game_field->returns.ivalue[0]]);
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_toss_coin(lua_State * L) {
check_action_permission(L);
......@@ -3415,7 +3648,13 @@ int32 scriptlib::duel_toss_coin(lua_State * L) {
if(count > 5)
count = 5;
pduel->game_field->add_process(PROCESSOR_TOSS_COIN, 0, pduel->game_field->core.reason_effect, 0, (pduel->game_field->core.reason_player << 16) + playerid, count);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 count = lua_tointeger(L, 2);
for(int32 i = 0; i < count; ++i)
lua_pushinteger(L, pduel->game_field->core.coin_result[i]);
return count;
});
}
int32 scriptlib::duel_toss_dice(lua_State * L) {
check_action_permission(L);
......@@ -3433,7 +3672,16 @@ int32 scriptlib::duel_toss_dice(lua_State * L) {
if(count2 > 5 - count1)
count2 = 5 - count1;
pduel->game_field->add_process(PROCESSOR_TOSS_DICE, 0, pduel->game_field->core.reason_effect, 0, (pduel->game_field->core.reason_player << 16) + playerid, count1 + (count2 << 16));
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 count1 = lua_tointeger(L, 2);
int32 count2 = 0;
if(lua_gettop(L) > 2)
count2 = lua_tointeger(L, 3);
for(int32 i = 0; i < count1 + count2; ++i)
lua_pushinteger(L, pduel->game_field->core.dice_result[i]);
return count1 + count2;
});
}
int32 scriptlib::duel_rock_paper_scissors(lua_State * L) {
duel* pduel = interpreter::get_duel_info(L);
......@@ -3441,7 +3689,11 @@ int32 scriptlib::duel_rock_paper_scissors(lua_State * L) {
if (lua_gettop(L) > 0)
repeat = lua_toboolean(L, 1);
pduel->game_field->add_process(PROCESSOR_ROCK_PAPER_SCISSORS, 0, 0, 0, repeat, 0);
return lua_yield(L, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
return 1;
});
}
int32 scriptlib::duel_get_coin_result(lua_State * L) {
duel* pduel = interpreter::get_duel_info(L);
......
......@@ -217,8 +217,17 @@ int32 scriptlib::group_filter_select(lua_State *L) {
if(pduel->lua->check_matching(pcard, 3, extraargs))
pduel->game_field->core.select_cards.push_back(pcard);
}
pduel->game_field->add_process(PROCESSOR_SELECT_CARD_S, 0, 0, 0, playerid, min + (max << 16));
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
int32 scriptlib::group_select(lua_State *L) {
check_action_permission(L);
......@@ -244,8 +253,17 @@ int32 scriptlib::group_select(lua_State *L) {
for (auto& pcard : cset) {
pduel->game_field->core.select_cards.push_back(pcard);
}
pduel->game_field->add_process(PROCESSOR_SELECT_CARD_S, 0, 0, 0, playerid, min + (max << 16));
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
for(int32 i = 0; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
interpreter::group2value(L, pgroup);
return 1;
});
}
int32 scriptlib::group_select_unselect(lua_State *L) {
check_action_permission(L);
......@@ -294,17 +312,54 @@ int32 scriptlib::group_select_unselect(lua_State *L) {
for(auto it = pgroup2->container.begin(); it != pgroup2->container.end(); ++it) {
pduel->game_field->core.unselect_cards.push_back(*it);
}
pduel->game_field->add_process(PROCESSOR_SELECT_UNSELECT_CARD_S, 0, 0, 0, playerid + (cancelable << 16), min + (max << 16), finishable);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_UNSELECT_CARD, 0, 0, 0, playerid + (cancelable << 16), min + (max << 16), finishable);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
if(pduel->game_field->returns.bvalue[0] == -1) {
lua_pushnil(L);
} else {
card* pcard;
if((size_t)pduel->game_field->returns.bvalue[1] < pduel->game_field->core.select_cards.size())
pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[1]];
else
pcard = pduel->game_field->core.unselect_cards[pduel->game_field->returns.bvalue[1] - pduel->game_field->core.select_cards.size()];
interpreter::card2value(L, pcard);
}
return 1;
});
}
int32 scriptlib::group_random_select(lua_State *L) {
check_param_count(L, 3);
check_param(L, PARAM_TYPE_GROUP, 1);
group* pgroup = *(group**) lua_touserdata(L, 1);
int32 playerid = lua_tointeger(L, 2);
int32 count = lua_tointeger(L, 3);
pgroup->pduel->game_field->add_process(PROCESSOR_RANDOM_SELECT_S, 0, 0, pgroup, playerid, count);
return lua_yield(L, 0);
uint32 count = lua_tointeger(L, 3);
duel* pduel = pgroup->pduel;
group* newgroup = pduel->new_group();
if(count > pgroup->container.size())
count = pgroup->container.size();
if(count == 0) {
interpreter::group2value(L, newgroup);
return 1;
}
if(count == pgroup->container.size())
newgroup->container = pgroup->container;
else {
while(newgroup->container.size() < count) {
int32 i = pduel->get_next_integer(0, pgroup->container.size() - 1);
auto cit = pgroup->container.begin();
std::advance(cit, i);
newgroup->container.insert(*cit);
}
}
pduel->write_buffer8(MSG_RANDOM_SELECTED);
pduel->write_buffer8(playerid);
pduel->write_buffer8(count);
for(auto& pcard : newgroup->container) {
pduel->write_buffer32(pcard->get_info_location());
}
interpreter::group2value(L, newgroup);
return 1;
}
int32 scriptlib::group_is_exists(lua_State *L) {
check_param_count(L, 4);
......@@ -398,8 +453,19 @@ int32 scriptlib::group_select_with_sum_equal(lua_State *L) {
interpreter::group2value(L, empty_group);
return 1;
}
pduel->game_field->add_process(PROCESSOR_SELECT_SUM_S, 0, 0, 0, acc, playerid + (min << 16) + (max << 24));
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_SUM, 0, 0, 0, acc, playerid + (min << 16) + (max << 24));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
int32 mcount = pduel->game_field->core.must_select_cards.size();
for(int32 i = mcount; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
pduel->game_field->core.must_select_cards.clear();
interpreter::group2value(L, pgroup);
return 1;
});
}
int32 scriptlib::group_check_with_sum_greater(lua_State *L) {
check_param_count(L, 3);
......@@ -450,8 +516,19 @@ int32 scriptlib::group_select_with_sum_greater(lua_State *L) {
interpreter::group2value(L, empty_group);
return 1;
}
pduel->game_field->add_process(PROCESSOR_SELECT_SUM_S, 0, 0, 0, acc, playerid);
return lua_yield(L, 0);
pduel->game_field->add_process(PROCESSOR_SELECT_SUM, 0, 0, 0, acc, playerid);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
group* pgroup = pduel->new_group();
int32 mcount = pduel->game_field->core.must_select_cards.size();
for(int32 i = mcount; i < pduel->game_field->returns.bvalue[0]; ++i) {
card* pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
pduel->game_field->core.must_select_cards.clear();
interpreter::group2value(L, pgroup);
return 1;
});
}
int32 scriptlib::group_get_min_group(lua_State *L) {
check_param_count(L, 2);
......
......@@ -101,7 +101,7 @@ void field::remove_counter(uint32 reason, card* pcard, uint32 rplayer, uint32 s,
add_process(PROCESSOR_REMOVE_COUNTER, 0, NULL, (group*)pcard, (rplayer << 16) + (s << 8) + o, countertype, count, reason);
}
void field::remove_overlay_card(uint32 reason, card* pcard, uint32 rplayer, uint32 s, uint32 o, uint16 min, uint16 max) {
add_process(PROCESSOR_REMOVEOL_S, 0, NULL, (group*)pcard, (rplayer << 16) + (s << 8) + o, (max << 16) + min, reason);
add_process(PROCESSOR_REMOVE_OVERLAY, 0, NULL, (group*)pcard, (rplayer << 16) + (s << 8) + o, (max << 16) + min, reason);
}
void field::get_control(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone) {
group* ng = pduel->new_group(*targets);
......@@ -191,7 +191,7 @@ void field::special_summon_complete(effect* reason_effect, uint8 reason_player)
ng->container.swap(core.special_summoning);
ng->is_readonly = TRUE;
//core.special_summoning.clear();
add_process(PROCESSOR_SPSUMMON_COMP_S, 0, reason_effect, ng, reason_player, 0);
add_process(PROCESSOR_SPSUMMON, 1, reason_effect, ng, reason_player, 0);
}
void field::destroy(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence) {
for(auto cit = targets->begin(); cit != targets->end();) {
......
......@@ -410,7 +410,6 @@ int32 field::process() {
}
case PROCESSOR_SSET_G: {
if (sset_g(it->step, it->arg1, it->arg2, it->ptarget, it->arg3, it->peffect)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else
it->step++;
......@@ -496,7 +495,6 @@ int32 field::process() {
}
case PROCESSOR_REMOVE_COUNTER: {
if (remove_counter(it->step, it->arg4, (card*)it->ptarget, (it->arg1 >> 16) & 0xff, (it->arg1 >> 8) & 0xff, it->arg1 & 0xff, it->arg2, it->arg3)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
} else
it->step++;
......@@ -511,7 +509,6 @@ int32 field::process() {
|| !attacker->is_capable_attack()
|| !attacker->is_affect_by_effect(core.reason_effect)) {
returns.ivalue[0] = 0;
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
} else {
effect* peffect = pduel->new_effect();
......@@ -525,54 +522,12 @@ int32 field::process() {
}
} else {
returns.ivalue[0] = 1;
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_DESTROY_S: {
if(it->step == 0) {
add_process(PROCESSOR_DESTROY, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_RELEASE_S: {
if(it->step == 0) {
add_process(PROCESSOR_RELEASE, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SENDTO_S: {
if(it->step == 0) {
add_process(PROCESSOR_SENDTO, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_CHANGEPOS_S: {
if(it->step == 0) {
add_process(PROCESSOR_CHANGEPOS, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_ANNOUNCE_RACE: {
if(announce_race(it->step, it->arg1 & 0xffff, it->arg1 >> 16, it->arg2)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else {
it->step++;
......@@ -581,7 +536,6 @@ int32 field::process() {
}
case PROCESSOR_ANNOUNCE_ATTRIB: {
if(announce_attribute(it->step, it->arg1 & 0xffff, it->arg1 >> 16, it->arg2)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else {
it->step++;
......@@ -590,7 +544,6 @@ int32 field::process() {
}
case PROCESSOR_ANNOUNCE_CARD: {
if(announce_card(it->step, it->arg1, it->arg2)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else {
if(it->step == 0)
......@@ -600,8 +553,6 @@ int32 field::process() {
}
case PROCESSOR_ANNOUNCE_NUMBER: {
if(announce_number(it->step, it->arg1)) {
pduel->lua->add_param(core.select_options[returns.ivalue[0]], PARAM_TYPE_INT);
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else {
it->step++;
......@@ -610,8 +561,6 @@ int32 field::process() {
}
case PROCESSOR_TOSS_DICE: {
if(toss_dice(it->step, it->peffect, it->arg1 >> 16, it->arg1 & 0xff, it->arg2 & 0xff, it->arg2 >> 16)) {
for(int32 i = 0; i < (it->arg2 & 0xff) + (it->arg2 >> 16); ++i)
pduel->lua->add_param(core.dice_result[i], PARAM_TYPE_INT);
core.units.pop_front();
} else
it->step++;
......@@ -619,8 +568,6 @@ int32 field::process() {
}
case PROCESSOR_TOSS_COIN: {
if (toss_coin(it->step, it->peffect, (it->arg1 >> 16), it->arg1 & 0xff, it->arg2)) {
for(int32 i = 0; i < it->arg2; ++i)
pduel->lua->add_param(core.coin_result[i], PARAM_TYPE_INT);
core.units.pop_front();
} else
it->step++;
......@@ -628,163 +575,11 @@ int32 field::process() {
}
case PROCESSOR_ROCK_PAPER_SCISSORS: {
if (rock_paper_scissors(it->step, it->arg1)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else
it->step++;
return pduel->bufferlen;
}
case PROCESSOR_SELECT_EFFECTYN_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_EFFECTYN, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_YESNO_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_YESNO, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_OPTION_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_OPTION, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_OPSELECTED);
pduel->write_buffer8(it->arg1);
pduel->write_buffer32(core.select_options[returns.ivalue[0]]);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_CARD_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_CARD, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
group* pgroup = pduel->new_group();
for(int32 i = 0; i < returns.bvalue[0]; ++i) {
card* pcard = core.select_cards[returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
pduel->lua->add_param(pgroup, PARAM_TYPE_GROUP);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_UNSELECT_CARD_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_UNSELECT_CARD, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3);
it->step++;
} else {
if(returns.bvalue[0] == -1)
pduel->lua->add_param((void*)0, PARAM_TYPE_GROUP);
else {
card* pcard;
if((uint8)returns.bvalue[1] < core.select_cards.size())
pcard = core.select_cards[returns.bvalue[1]];
else
pcard = core.unselect_cards[returns.bvalue[1] - core.select_cards.size()];
pduel->lua->add_param(pcard, PARAM_TYPE_CARD);
}
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_POSITION_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_POSITION, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_RELEASE_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_RELEASE, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
group* pgroup = pduel->new_group();
for(int32 i = 0; i < returns.bvalue[0]; ++i) {
card* pcard = core.select_cards[returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
pduel->lua->add_param(pgroup, PARAM_TYPE_GROUP);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_TRIBUTE_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_TRIBUTE, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3, it->arg4);
it->step++;
} else {
group* pgroup = pduel->new_group();
for(int32 i = 0; i < returns.bvalue[0]; ++i) {
card* pcard = core.select_cards[returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
pduel->lua->add_param(pgroup, PARAM_TYPE_GROUP);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SORT_CARDS_S:
core.units.pop_front();
break;
case PROCESSOR_SELECT_TARGET: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_CARD, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
chain* ch = get_chain(0);
if(ch) {
if(!ch->target_cards) {
ch->target_cards = pduel->new_group();
ch->target_cards->is_readonly = TRUE;
}
group* tg = ch->target_cards;
effect* peffect = ch->triggering_effect;
if(peffect->type & EFFECT_TYPE_CONTINUOUS) {
for(int32 i = 0; i < returns.bvalue[0]; ++i)
tg->container.insert(core.select_cards[returns.bvalue[i + 1]]);
pduel->lua->add_param(tg, PARAM_TYPE_GROUP);
} else {
group* pret = pduel->new_group();
for(int32 i = 0; i < returns.bvalue[0]; ++i) {
tg->container.insert(core.select_cards[returns.bvalue[i + 1]]);
pret->container.insert(core.select_cards[returns.bvalue[i + 1]]);
}
if((returns.bvalue[0] > 0) && peffect->is_flag(EFFECT_FLAG_CARD_TARGET)) {
for(int32 i = 0; i < returns.bvalue[0]; ++i) {
card* pcard = core.select_cards[returns.bvalue[i + 1]];
pduel->write_buffer8(MSG_BECOME_TARGET);
pduel->write_buffer8(1);
pduel->write_buffer32(pcard->get_info_location());
}
}
for(auto& pcard : pret->container)
pcard->create_relation(*ch);
pduel->lua->add_param(pret, PARAM_TYPE_GROUP);
}
}
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_FUSION: {
if(it->step == 0) {
tevent e;
......@@ -802,10 +597,6 @@ int32 field::process() {
add_process(PROCESSOR_EXECUTE_OPERATION, 0, it->peffect, 0, it->arg1 & 0xffff, 0);
it->step++;
} else {
group* pgroup = pduel->new_group(core.fusion_materials);
if(it->ptr1)
pgroup->container.insert((card*)it->ptr1);
pduel->lua->add_param(pgroup, PARAM_TYPE_GROUP);
core.units.pop_front();
}
return pduel->bufferlen;
......@@ -822,106 +613,6 @@ int32 field::process() {
it->step++;
return pduel->bufferlen;
}
case PROCESSOR_SELECT_SUM_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_SUM, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
group* pgroup = pduel->new_group();
int32 mcount = core.must_select_cards.size();
for(int32 i = mcount; i < returns.bvalue[0]; ++i) {
card* pcard = core.select_cards[returns.bvalue[i + 1]];
pgroup->container.insert(pcard);
}
core.must_select_cards.clear();
pduel->lua->add_param(pgroup, PARAM_TYPE_GROUP);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_DISFIELD_S: {
if(it->step == 0) {
add_process(PROCESSOR_SELECT_DISFIELD, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3);
it->step++;
} else {
int32 playerid = it->arg1;
int32 count = it->arg3;
int32 dfflag = 0;
uint8 pa = 0;
for(int32 i = 0; i < count; ++i) {
uint8 p = returns.bvalue[pa];
uint8 l = returns.bvalue[pa + 1];
uint8 s = returns.bvalue[pa + 2];
dfflag |= 0x1u << (s + (p == playerid ? 0 : 16) + (l == LOCATION_MZONE ? 0 : 8));
pa += 3;
}
pduel->lua->add_param(dfflag, PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SPSUMMON_S: {
if(it->step == 0) {
add_process(PROCESSOR_SPSUMMON, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SPSUMMON_STEP_S: {
if(it->step == 0) {
add_process(PROCESSOR_SPSUMMON_STEP, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3, it->arg4, it->ptr1);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SPSUMMON_COMP_S: {
if(it->step == 0) {
add_process(PROCESSOR_SPSUMMON, 1, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_RANDOM_SELECT_S: {
uint32 count = it->arg2;
group* pgroup = it->ptarget;
group* newgroup = pduel->new_group();
if(count > pgroup->container.size())
count = pgroup->container.size();
if(count == 0) {
pduel->lua->add_param(newgroup, PARAM_TYPE_GROUP);
core.units.pop_front();
return pduel->bufferlen;
}
duel* pduel = pgroup->pduel;
if(count == pgroup->container.size())
newgroup->container = pgroup->container;
else {
while(newgroup->container.size() < count) {
int32 i = pduel->get_next_integer(0, pgroup->container.size() - 1);
auto cit = pgroup->container.begin();
std::advance(cit, i);
newgroup->container.insert(*cit);
}
}
pduel->lua->add_param(newgroup, PARAM_TYPE_GROUP);
pduel->write_buffer8(MSG_RANDOM_SELECTED);
pduel->write_buffer8(it->arg1);
pduel->write_buffer8(count);
for(auto& pcard : newgroup->container) {
pduel->write_buffer32(pcard->get_info_location());
}
core.units.pop_front();
return pduel->bufferlen;
}
case PROCESSOR_SELECT_XMATERIAL: {
if (select_xyz_material(it->step, it->arg1 & 0xffff, it->arg1 >> 16, (card*)it->ptarget, it->arg2 & 0xffff, it->arg2 >> 16))
core.units.pop_front();
......@@ -929,67 +620,7 @@ int32 field::process() {
it->step++;
return pduel->bufferlen;
}
case PROCESSOR_DRAW_S: {
if(it->step == 0) {
add_process(PROCESSOR_DRAW, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_DAMAGE_S: {
if(it->step == 0) {
add_process(PROCESSOR_DAMAGE, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_RECOVER_S: {
if(it->step == 0) {
add_process(PROCESSOR_RECOVER, 0, it->peffect, it->ptarget, it->arg1, it->arg2);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_EQUIP_S: {
if(it->step == 0) {
add_process(PROCESSOR_EQUIP, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3, it->arg4, it->ptr1);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_GET_CONTROL_S: {
if(it->step == 0) {
add_process(PROCESSOR_GET_CONTROL, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_SWAP_CONTROL_S: {
if(it->step == 0) {
add_process(PROCESSOR_SWAP_CONTROL, 0, it->peffect, it->ptarget, it->arg1, it->arg2, it->arg3, it->arg4, it->ptr1);
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_DISCARD_HAND_S: {
case PROCESSOR_DISCARD_HAND: {
if(it->step == 0) {
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_SELECTMSG);
......@@ -1012,21 +643,19 @@ int32 field::process() {
returns.ivalue[0] = 0;
it->step++;
} else {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
}
return pduel->bufferlen;
}
case PROCESSOR_DISCARD_DECK_S: {
case PROCESSOR_DISCARD_DECK: {
if(discard_deck(it->step, it->arg1 & 0xff, it->arg1 >> 16, it->arg2)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_INT);
core.units.pop_front();
} else {
it->step++;
}
return pduel->bufferlen;
}
case PROCESSOR_SORT_DECK_S: {
case PROCESSOR_SORT_DECK: {
uint8 sort_player = it->arg1 & 0xffff;
uint8 target_player = it->arg1 >> 16;
uint8 count = it->arg2, i = 0;
......@@ -1068,24 +697,15 @@ int32 field::process() {
}
return pduel->bufferlen;
}
case PROCESSOR_REMOVEOL_S: {
case PROCESSOR_REMOVE_OVERLAY: {
if(remove_overlay_card(it->step, it->arg3, (card*)(it->ptarget), it->arg1 >> 16,
(it->arg1 >> 8) & 0xff, it->arg1 & 0xff, it->arg2 & 0xffff, it->arg2 >> 16)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
} else {
it->step++;
}
return pduel->bufferlen;
}
case PROCESSOR_MOVETOFIELD_S: {
if (move_to_field(it->step, (card*)it->ptarget, it->arg1, it->arg2 & 0xff, (it->arg2 >> 8) & 0xff, it->arg3)) {
pduel->lua->add_param(returns.ivalue[0], PARAM_TYPE_BOOLEAN);
core.units.pop_front();
} else
it->step++;
return pduel->bufferlen;
}
}
return pduel->bufferlen;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment