Commit 9a253618 authored by edo9300's avatar edo9300 Committed by mercury233

Added Group.SelectUnselect() (#87)

parent e50e6fea
......@@ -171,6 +171,7 @@ struct processor {
processor_list subunits;
processor_unit reserved;
card_vector select_cards;
card_vector unselect_cards;
card_vector summonable_cards;
card_vector spsummonable_cards;
card_vector repositionable_cards;
......@@ -581,6 +582,7 @@ public:
int32 select_yes_no(uint16 step, uint8 playerid, uint32 description);
int32 select_option(uint16 step, uint8 playerid);
int32 select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 min, uint8 max);
int32 select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 min, uint8 max, uint8 ok);
int32 select_chain(uint16 step, uint8 playerid, uint8 spe_count, uint8 forced);
int32 select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count);
int32 select_position(uint16 step, uint8 playerid, uint32 code, uint8 positions);
......@@ -675,6 +677,7 @@ public:
#define PROCESSOR_SELECT_OPTION 14
#define PROCESSOR_SELECT_CARD 15
#define PROCESSOR_SELECT_CHAIN 16
#define PROCESSOR_SELECT_UNSELECT_CARD 17
#define PROCESSOR_SELECT_PLACE 18
#define PROCESSOR_SELECT_POSITION 19
#define PROCESSOR_SELECT_TRIBUTE_P 20
......@@ -745,6 +748,7 @@ public:
#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
......@@ -835,6 +839,7 @@ public:
#define MSG_SELECT_SUM 23
#define MSG_SELECT_DISFIELD 24
#define MSG_SORT_CARD 25
#define MSG_SELECT_UNSELECT_CARD 26
#define MSG_CONFIRM_DECKTOP 30
#define MSG_CONFIRM_CARDS 31
#define MSG_SHUFFLE_DECK 32
......@@ -906,4 +911,5 @@ public:
#define MSG_PLAYER_HINT 165
#define MSG_MATCH_KILL 170
#define MSG_CUSTOM_MSG 180
#endif /* FIELD_H_ */
......@@ -337,6 +337,7 @@ static const struct luaL_Reg grouplib[] = {
{ "FilterCount", scriptlib::group_filter_count },
{ "FilterSelect", scriptlib::group_filter_select },
{ "Select", scriptlib::group_select },
{ "SelectUnselect", scriptlib::group_select_unselect },
{ "RandomSelect", scriptlib::group_random_select },
{ "IsExists", scriptlib::group_is_exists },
{ "CheckWithSumEqual", scriptlib::group_check_with_sum_equal },
......
......@@ -247,6 +247,56 @@ int32 scriptlib::group_select(lua_State *L) {
pduel->game_field->add_process(PROCESSOR_SELECT_CARD_S, 0, 0, 0, playerid, min + (max << 16));
return lua_yield(L, 0);
}
int32 scriptlib::group_select_unselect(lua_State *L) {
check_action_permission(L);
check_param_count(L, 3);
check_param(L, PARAM_TYPE_GROUP, 1);
check_param(L, PARAM_TYPE_GROUP, 2);
group* pgroup1 = *(group**)lua_touserdata(L, 1);
group* pgroup2 = *(group**)lua_touserdata(L, 2);
duel* pduel = pgroup1->pduel;
uint32 playerid = lua_tointeger(L, 3);
if(playerid != 0 && playerid != 1)
return 0;
if(pgroup1->container.size() + pgroup2->container.size() == 0)
return 0;
for(auto it = pgroup2->container.begin(); it != pgroup2->container.end(); ++it) {
card* pcard = *it;
for(auto it2 = pgroup1->container.begin(); it2 != pgroup1->container.end(); ++it2) {
if((*it2) == pcard) {
return 0;
}
}
}
uint32 buttonok = FALSE;
if(lua_gettop(L) > 3) {
buttonok = lua_toboolean(L, 4);
}
uint32 cancelable = FALSE;
if(lua_gettop(L) > 4) {
cancelable = lua_toboolean(L, 5);
}
uint32 min = 1;
if(lua_gettop(L) > 5) {
min = lua_tointeger(L, 6);
}
uint32 max = 1;
if(lua_gettop(L) > 6) {
max = lua_tointeger(L, 7);
}
if(min > max)
min = max;
pduel->game_field->core.select_cards.clear();
pduel->game_field->core.unselect_cards.clear();
for(auto it = pgroup1->container.begin(); it != pgroup1->container.end(); ++it) {
pduel->game_field->core.select_cards.push_back(*it);
}
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), buttonok);
return lua_yield(L, 0);
}
int32 scriptlib::group_random_select(lua_State *L) {
check_param_count(L, 3);
check_param(L, PARAM_TYPE_GROUP, 1);
......
......@@ -287,6 +287,55 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi
return TRUE;
}
}
int32 field::select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 min, uint8 max, uint8 buttonok) {
if(step == 0) {
returns.bvalue[0] = 0;
if(core.select_cards.empty() && core.unselect_cards.empty())
return TRUE;
if((playerid == 1) && (core.duel_options & DUEL_SIMPLE_AI)) {
returns.bvalue[0] = 1;
for(uint8 i = 0; i < 1; ++i)
returns.bvalue[i + 1] = i;
return TRUE;
}
pduel->write_buffer8(MSG_SELECT_UNSELECT_CARD);
pduel->write_buffer8(playerid);
pduel->write_buffer8(buttonok);
pduel->write_buffer8(cancelable);
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8(core.select_cards.size());
card* pcard;
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
for(uint32 i = 0; i < core.select_cards.size(); ++i) {
pcard = core.select_cards[i];
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_info_location());
}
pduel->write_buffer8(core.unselect_cards.size());
for(uint32 i = 0; i < core.unselect_cards.size(); ++i) {
pcard = core.unselect_cards[i];
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_info_location());
}
return FALSE;
} else {
if(returns.ivalue[0] == -1)
return TRUE;
byte c[64];
memset(c, 0, 64);
uint8 m = core.select_cards.size() + core.unselect_cards.size(), v = 0;
for(int32 i = 0; i < returns.bvalue[0]; ++i) {
v = returns.bvalue[i + 1];
if(v < 0 || v >= m || v >= 63 || c[v]) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
c[v] = 1;
}
return TRUE;
}
}
int32 field::select_chain(uint16 step, uint8 playerid, uint8 spe_count, uint8 forced) {
if(step == 0) {
returns.ivalue[0] = -1;
......
......@@ -115,6 +115,15 @@ int32 field::process() {
return PROCESSOR_WAITING + pduel->bufferlen;
}
}
case PROCESSOR_SELECT_UNSELECT_CARD: {
if (select_unselect_card(it->step, it->arg1 & 0xff, (it->arg1 >> 16) & 0xff, (it->arg2) & 0xff, (it->arg2 >> 16) & 0xff, (it->arg3) & 0xff)) {
core.units.pop_front();
return pduel->bufferlen;
} else {
it->step = 1;
return PROCESSOR_WAITING + pduel->bufferlen;
}
}
case PROCESSOR_SELECT_CHAIN: {
if (select_chain(it->step, it->arg1, (it->arg2 & 0xffff), it->arg2 >> 16)) {
core.units.pop_front();
......@@ -682,6 +691,26 @@ int32 field::process() {
}
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 {
group* pgroup = pduel->new_group();
card* pcard;
if(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);
......
......@@ -334,6 +334,7 @@ public:
static int32 group_filter_count(lua_State *L);
static int32 group_filter_select(lua_State *L);
static int32 group_select(lua_State *L);
static int32 group_select_unselect(lua_State *L);
static int32 group_random_select(lua_State *L);
static int32 group_is_exists(lua_State *L);
static int32 group_check_with_sum_equal(lua_State *L);
......
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