Commit 613fe16d authored by VanillaSalt's avatar VanillaSalt

fix operation_replace

parent 2835740b
......@@ -519,6 +519,7 @@ public:
void move_to_field(card* target, uint32 move_player, uint32 playerid, uint32 destination, uint32 positions, uint32 enable = FALSE, uint32 ret = 0, uint32 is_equip = FALSE, uint32 zone = 0xff);
void change_position(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 au, uint32 ad, uint32 du, uint32 dd, uint32 flag, uint32 enable = FALSE);
void change_position(card* target, effect* reason_effect, uint32 reason_player, uint32 npos, uint32 flag, uint32 enable = FALSE);
void operation_replace(int32 type, int32 step, group* targets);
int32 remove_counter(uint16 step, uint32 reason, card* pcard, uint8 rplayer, uint8 s, uint8 o, uint16 countertype, uint16 count);
int32 remove_overlay_card(uint16 step, uint32 reason, card* pcard, uint8 rplayer, uint8 s, uint8 o, uint16 min, uint16 max);
......@@ -547,7 +548,7 @@ public:
int32 discard_deck(uint16 step, uint8 playerid, uint8 count, uint32 reason);
int32 move_to_field(uint16 step, card* target, uint32 enable, uint32 ret, uint32 is_equip, uint32 zone);
int32 change_position(uint16 step, group* targets, effect* reason_effect, uint8 reason_player, uint32 enable);
int32 operation_replace(uint16 step, effect* replace_effect, group* targets, card* arg, ptr replace_type);
int32 operation_replace(uint16 step, effect* replace_effect, group* targets, card* target, int32 is_destroy);
int32 activate_effect(uint16 step, effect* peffect);
int32 select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg);
int32 select_xyz_material(int16 step, uint8 playerid, uint32 lv, card* pcard, int32 min, int32 max);
......
......@@ -328,6 +328,20 @@ void field::change_position(card* target, effect* reason_effect, uint32 reason_p
target->position_param |= flag;
add_process(PROCESSOR_CHANGEPOS, 0, reason_effect, ng, reason_player, enable);
}
void field::operation_replace(int32 type, int32 step, group* targets) {
int32 is_destroy = (type == EFFECT_DESTROY_REPLACE) ? TRUE : FALSE;
auto pr = effects.continuous_effect.equal_range(type);
std::vector<effect*> opp_effects;
for(auto it = pr.first; it != pr.second; ++it) {
effect* reffect = it->second;
if(reffect->get_handler_player() == infos.turn_player)
add_process(PROCESSOR_OPERATION_REPLACE, step, reffect, targets, is_destroy, 0);
else
opp_effects.push_back(reffect);
}
for(auto eit = opp_effects.begin(); eit != opp_effects.end(); ++eit)
add_process(PROCESSOR_OPERATION_REPLACE, step, *eit, targets, is_destroy, 0);
}
int32 field::draw(uint16 step, effect* reason_effect, uint32 reason, uint8 reason_player, uint8 playerid, uint32 count) {
switch(step) {
case 0: {
......@@ -2968,7 +2982,7 @@ int32 field::special_summon(uint16 step, effect* reason_effect, uint8 reason_pla
}
// destroy: step version
// PROCESSOR_DESTROY_STEP goes here
int32 field::destroy(uint16 step, group * targets, card * target, uint8 battle) {
int32 field::destroy(uint16 step, group* targets, card* target, uint8 battle) {
if(target->current.location & (LOCATION_GRAVE | LOCATION_REMOVED)) {
target->current.reason = target->temp.reason;
target->current.reason_effect = target->temp.reason_effect;
......@@ -2984,10 +2998,10 @@ int32 field::destroy(uint16 step, group * targets, card * target, uint8 battle)
target->filter_single_continuous_effect(EFFECT_DESTROY_REPLACE, &eset);
if(!battle) {
for (int32 i = 0; i < eset.size(); ++i)
add_process(PROCESSOR_OPERATION_REPLACE, 0, eset[i], targets, 0, 1, 0, 0, target);
add_process(PROCESSOR_OPERATION_REPLACE, 0, eset[i], targets, 1, 0, 0, 0, target);
} else {
for (int32 i = 0; i < eset.size(); ++i)
add_process(PROCESSOR_OPERATION_REPLACE, 10, eset[i], targets, 0, 1, 0, 0, target);
add_process(PROCESSOR_OPERATION_REPLACE, 10, eset[i], targets, 1, 0, 0, 0, target);
}
return TRUE;
}
......@@ -3121,9 +3135,7 @@ int32 field::destroy(uint16 step, group * targets, effect * reason_effect, uint3
pduel->write_buffer8(0);
pduel->write_buffer32((*eit)->owner->data.code);
}
auto pr = effects.continuous_effect.equal_range(EFFECT_DESTROY_REPLACE);
for (; pr.first != pr.second; ++pr.first)
add_process(PROCESSOR_OPERATION_REPLACE, 5, pr.first->second, targets, 0, 1);
operation_replace(EFFECT_DESTROY_REPLACE, 5, targets);
return FALSE;
}
case 1: {
......@@ -3182,9 +3194,7 @@ int32 field::destroy(uint16 step, group * targets, effect * reason_effect, uint3
dest = LOCATION_GRAVE;
(*cit)->operation_param = ((*cit)->operation_param & 0xffff00ff) + (dest << 8);
}
auto pr = effects.continuous_effect.equal_range(EFFECT_SEND_REPLACE);
for (; pr.first != pr.second; ++pr.first)
add_process(PROCESSOR_OPERATION_REPLACE, 5, pr.first->second, sendtargets, 0, 0);
operation_replace(EFFECT_SEND_REPLACE, 5, sendtargets);
add_process(PROCESSOR_SENDTO, 1, reason_effect, sendtargets, reason | REASON_DESTROY, reason_player);
return FALSE;
}
......@@ -3310,9 +3320,7 @@ int32 field::destroy(uint16 step, group * targets, effect * reason_effect, uint3
}
}
if(targets->container.size()) {
auto pr = effects.continuous_effect.equal_range(EFFECT_DESTROY_REPLACE);
for (; pr.first != pr.second; ++pr.first)
add_process(PROCESSOR_OPERATION_REPLACE, 12, pr.first->second, targets, 0, 1);
operation_replace(EFFECT_DESTROY_REPLACE, 12, targets);
}
return FALSE;
}
......@@ -3332,7 +3340,7 @@ int32 field::destroy(uint16 step, group * targets, effect * reason_effect, uint3
return TRUE;
}
// PROCESSOR_RELEASE_STEP goes here
int32 field::release(uint16 step, group * targets, card * target) {
int32 field::release(uint16 step, group* targets, card* target) {
if(!(target->current.location & (LOCATION_ONFIELD | LOCATION_HAND))) {
target->current.reason = target->temp.reason;
target->current.reason_effect = target->temp.reason_effect;
......@@ -3371,9 +3379,7 @@ int32 field::release(uint16 step, group * targets, effect * reason_effect, uint3
}
if(reason & REASON_RULE)
return FALSE;
auto pr = effects.continuous_effect.equal_range(EFFECT_RELEASE_REPLACE);
for (; pr.first != pr.second; ++pr.first)
add_process(PROCESSOR_OPERATION_REPLACE, 5, pr.first->second, targets, 0, 0);
operation_replace(EFFECT_RELEASE_REPLACE, 5, targets);
return FALSE;
}
case 1: {
......@@ -3409,9 +3415,7 @@ int32 field::release(uint16 step, group * targets, effect * reason_effect, uint3
case 3: {
group* sendtargets = pduel->new_group(targets->container);
sendtargets->is_readonly = TRUE;
auto pr = effects.continuous_effect.equal_range(EFFECT_SEND_REPLACE);
for (; pr.first != pr.second; ++pr.first)
add_process(PROCESSOR_OPERATION_REPLACE, 5, pr.first->second, sendtargets, 0, 0);
operation_replace(EFFECT_SEND_REPLACE, 5, sendtargets);
add_process(PROCESSOR_SENDTO, 1, reason_effect, sendtargets, reason | REASON_RELEASE, reason_player);
return FALSE;
}
......@@ -3483,9 +3487,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
}
if(reason & REASON_RULE)
return FALSE;
auto pr = effects.continuous_effect.equal_range(EFFECT_SEND_REPLACE);
for (; pr.first != pr.second; ++pr.first)
add_process(PROCESSOR_OPERATION_REPLACE, 5, pr.first->second, targets, 0, 0);
operation_replace(EFFECT_SEND_REPLACE, 5, targets);
return FALSE;
}
case 1: {
......@@ -4348,14 +4350,13 @@ int32 field::change_position(uint16 step, group * targets, effect * reason_effec
}
return TRUE;
}
int32 field::operation_replace(uint16 step, effect * replace_effect, group * targets, card * arg1, ptr arg2) {
int32 field::operation_replace(uint16 step, effect* replace_effect, group* targets, card* target, int32 is_destroy) {
switch (step) {
case 0: {
if(returns.ivalue[0])
return TRUE;
if(!replace_effect->target)
return TRUE;
card* target = arg1;
tevent e;
e.event_cards = targets;
e.event_player = replace_effect->get_handler_player();
......@@ -4384,13 +4385,12 @@ int32 field::operation_replace(uint16 step, effect * replace_effect, group * tar
return FALSE;
}
case 1: {
card* target = arg1;
if (returns.ivalue[0]) {
targets->container.erase(target);
target->current.reason = target->temp.reason;
target->current.reason_effect = target->temp.reason_effect;
target->current.reason_player = target->temp.reason_player;
if(arg2)
if(is_destroy)
core.destroy_canceled.insert(target);
replace_effect->dec_count();
} else
......@@ -4448,7 +4448,6 @@ int32 field::operation_replace(uint16 step, effect * replace_effect, group * tar
}
case 6: {
if (returns.ivalue[0]) {
uint32 is_destroy = arg2;
for (auto cit = targets->container.begin(); cit != targets->container.end();) {
auto rm = cit++;
if (replace_effect->get_value(*rm)) {
......@@ -4488,7 +4487,6 @@ int32 field::operation_replace(uint16 step, effect * replace_effect, group * tar
return TRUE;
if(!replace_effect->target)
return TRUE;
card* target = arg1;
tevent e;
e.event_cards = targets;
e.event_player = replace_effect->get_handler_player();
......@@ -4516,13 +4514,12 @@ int32 field::operation_replace(uint16 step, effect * replace_effect, group * tar
return FALSE;
}
case 11: {
card* target = arg1;
if (returns.ivalue[0]) {
targets->container.erase(target);
target->current.reason = target->temp.reason;
target->current.reason_effect = target->temp.reason_effect;
target->current.reason_player = target->temp.reason_player;
if(arg2)
if(is_destroy)
core.destroy_canceled.insert(target);
replace_effect->dec_count();
core.desrep_chain.push_back(core.continuous_chain.front());
......@@ -4562,7 +4559,6 @@ int32 field::operation_replace(uint16 step, effect * replace_effect, group * tar
}
case 13: {
if (returns.ivalue[0]) {
uint32 is_destroy = arg2;
for (auto cit = targets->container.begin(); cit != targets->container.end();) {
auto rm = cit++;
if (replace_effect->get_value(*rm)) {
......
......@@ -345,7 +345,7 @@ int32 field::process() {
return pduel->bufferlen;
}
case PROCESSOR_OPERATION_REPLACE: {
if (operation_replace(it->step, it->peffect, it->ptarget, (card*)it->ptr1, it->arg2))
if (operation_replace(it->step, it->peffect, it->ptarget, (card*)it->ptr1, it->arg1))
core.units.pop_front();
else
it->step++;
......
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