Commit 7f4e9653 authored by salix5's avatar salix5

remove_counter(), select_counter()

Now a player can remove 2^16-1=65535 counters in both ways.
parent 93c62a6e
......@@ -536,7 +536,7 @@ public:
int32 select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count);
int32 select_position(uint16 step, uint8 playerid, uint32 code, uint8 positions);
int32 select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8 min, uint8 max);
int32 select_counter(uint16 step, uint8 playerid, uint16 countertype, uint16 count);
int32 select_counter(uint16 step, uint8 playerid, uint16 countertype, uint16 count, uint8 s, uint8 o);
int32 select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 min, int max);
int32 sort_card(int16 step, uint8 playerid, uint8 is_chain);
int32 announce_race(int16 step, uint8 playerid, int32 count, int32 available);
......
......@@ -1875,7 +1875,7 @@ int32 scriptlib::card_remove_counter(lua_State *L) {
uint32 count = lua_tointeger(L, 4);
uint32 reason = lua_tointeger(L, 5);
if(countertype == 0) {
// c38834303
// c38834303: remove all counters
for(auto cmit = pcard->counters.begin(); cmit != pcard->counters.end(); ++cmit) {
pcard->pduel->write_buffer8(MSG_REMOVE_COUNTER);
pcard->pduel->write_buffer16(cmit->first);
......
......@@ -100,7 +100,7 @@ void field::change_target_param(uint8 chaincount, int32 param) {
core.current_chain[chaincount - 1].target_param = param;
}
void field::remove_counter(uint32 reason, card* pcard, uint32 rplayer, uint32 s, uint32 o, uint32 countertype, uint32 count) {
add_process(PROCESSOR_REMOVE_COUNTER, 0, NULL, (group*)pcard, (rplayer << 16) + (s << 8) + o, countertype + (count << 16), reason);
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);
......@@ -636,6 +636,8 @@ int32 field::pay_lp_cost(uint32 step, uint8 playerid, uint32 cost) {
}
// rplayer rmoves counter from pcard or the field
// s,o: binary value indicating the available side
// from pcard: Card.RemoveCounter() -> here -> card::remove_counter() -> the script should raise EVENT_REMOVE_COUNTER if necessary
// from the field: Duel.RemoveCounter() -> here -> field::select_counter() -> the system raises EVENT_REMOVE_COUNTER automatically
int32 field::remove_counter(uint16 step, uint32 reason, card* pcard, uint8 rplayer, uint8 s, uint8 o, uint16 countertype, uint16 count) {
switch(step) {
case 0: {
......@@ -692,31 +694,7 @@ int32 field::remove_counter(uint16 step, uint32 reason, card* pcard, uint8 rplay
core.units.begin()->step = 3;
return FALSE;
}
card* pcard;
core.select_cards.clear();
uint8 fc = s;
uint8 fp = rplayer;
for(int p = 0; p < 2; ++p) {
if(fc) {
for(uint32 j = 0; j < 5; ++j) {
pcard = player[fp].list_mzone[j];
if(pcard && pcard->get_counter(countertype)) {
core.select_cards.push_back(pcard);
pcard->operation_param = pcard->get_counter(countertype);
}
}
for(uint32 j = 0; j < 8; ++j) {
pcard = player[fp].list_szone[j];
if(pcard && pcard->get_counter(countertype)) {
core.select_cards.push_back(pcard);
pcard->operation_param = pcard->get_counter(countertype);
}
}
}
fp = 1 - fp;
fc = o;
}
add_process(PROCESSOR_SELECT_COUNTER, 0, 0, 0, rplayer, countertype + (((uint32)count) << 16));
add_process(PROCESSOR_SELECT_COUNTER, 0, NULL, NULL, rplayer, countertype, count, (s << 8) + o);
return FALSE;
}
case 2: {
......
......@@ -494,23 +494,44 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8
return TRUE;
}
}
int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uint16 count) {
int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uint16 count, uint8 s, uint8 o) {
if(step == 0) {
if(core.select_cards.empty() || count == 0)
if(count == 0)
return TRUE;
uint8 tm = 0;
for(uint32 i = 0; i < core.select_cards.size(); ++i)
tm += core.select_cards[i]->operation_param;
if(count > tm) {
count = tm;
core.units.begin()->arg2 = countertype + (((uint32)count) << 16);
card* pcard;
uint8 avail = s;
uint8 fp = playerid;
uint32 total = 0;
core.select_cards.clear();
for(int p = 0; p < 2; ++p) {
if(avail) {
for(int j = 0; j < 5; ++j) {
pcard = player[fp].list_mzone[j];
if(pcard && pcard->get_counter(countertype)) {
core.select_cards.push_back(pcard);
total += pcard->get_counter(countertype);
}
}
for(int j = 0; j < 8; ++j) {
pcard = player[fp].list_szone[j];
if(pcard && pcard->get_counter(countertype)) {
core.select_cards.push_back(pcard);
total += pcard->get_counter(countertype);
}
}
}
fp = 1 - fp;
avail = o;
}
if(count > total) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
pduel->write_buffer8(MSG_SELECT_COUNTER);
pduel->write_buffer8(playerid);
pduel->write_buffer16(countertype);
pduel->write_buffer8((uint8)count);
pduel->write_buffer16(count);
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];
......@@ -518,13 +539,13 @@ int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uin
pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location);
pduel->write_buffer8(pcard->current.sequence);
pduel->write_buffer8(pcard->operation_param);
pduel->write_buffer16(pcard->get_counter(countertype));
}
return FALSE;
} else {
uint16 ct = 0;
for(uint32 i = 0; i < core.select_cards.size(); ++i) {
if(core.select_cards[i]->operation_param < (uint32)returns.bvalue[i]) {
if(core.select_cards[i]->get_counter(countertype) < (uint32)returns.bvalue[i]) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
......
......@@ -161,7 +161,7 @@ int32 field::process() {
return pduel->bufferlen;
}
case PROCESSOR_SELECT_COUNTER: {
if (select_counter(it->step, it->arg1, (it->arg2) & 0xffff, (it->arg2 >> 16) & 0xffff)) {
if (select_counter(it->step, it->arg1, it->arg2, it->arg3, it->arg4 >> 8, it->arg4 & 0xff)) {
core.units.pop_front();
return pduel->bufferlen;
} else {
......@@ -487,7 +487,7 @@ int32 field::process() {
return pduel->bufferlen;
}
case PROCESSOR_REMOVE_COUNTER: {
if (remove_counter(it->step, it->arg3, (card*)it->ptarget, (it->arg1 >> 16) & 0xff, (it->arg1 >> 8) & 0xff, it->arg1 & 0xff, it->arg2 & 0xffff, it->arg2 >> 16)) {
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
......
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