From b579cda9adc48f42f279372ecb11e8bfac02d0cc Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 25 Oct 2024 00:27:56 +0800 Subject: [PATCH] fix card::xyz_remove (#645) --- card.cpp | 11 ++++++----- field.cpp | 10 +++++++--- libduel.cpp | 4 ++-- operations.cpp | 8 +++----- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/card.cpp b/card.cpp index d5ba136a5..d678b0635 100644 --- a/card.cpp +++ b/card.cpp @@ -1570,12 +1570,11 @@ int32 card::get_old_union_count() { return count; } void card::xyz_overlay(card_set* materials) { - if(materials->size() == 0) + if(materials->empty()) return; card_set des, leave_grave, leave_deck; card_vector cv; - for(auto& pcard : *materials) - cv.push_back(pcard); + cv.assign(materials->begin(), materials->end()); std::sort(cv.begin(), cv.end(), card::card_operation_sort); if(pduel->game_field->core.global_flag & GLOBALFLAG_DECK_REVERSE_CHECK) { int32 d0 = (int32)pduel->game_field->player[0].list_main.size() - 1, s0 = d0; @@ -1622,9 +1621,9 @@ void card::xyz_overlay(card_set* materials) { pduel->game_field->remove_unique_card(pcard); if(pcard->equiping_target) pcard->unequip(); + des.insert(pcard->equiping_cards.begin(), pcard->equiping_cards.end()); for(auto cit = pcard->equiping_cards.begin(); cit != pcard->equiping_cards.end();) { card* equipc = *cit++; - des.insert(equipc); equipc->unequip(); } pcard->clear_card_target(); @@ -1681,7 +1680,9 @@ void card::xyz_add(card* mat) { void card::xyz_remove(card* mat) { if(mat->overlay_target != this) return; - xyz_materials.erase(xyz_materials.begin() + mat->current.sequence); + if (std::find(xyz_materials.begin(), xyz_materials.end(), mat) == xyz_materials.end()) + return; + xyz_materials.erase(std::remove(xyz_materials.begin(), xyz_materials.end(), mat), xyz_materials.end()); mat->previous.controler = mat->current.controler; mat->previous.location = mat->current.location; mat->previous.sequence = mat->current.sequence; diff --git a/field.cpp b/field.cpp index a62b367b2..e60db1b39 100644 --- a/field.cpp +++ b/field.cpp @@ -1963,11 +1963,13 @@ void field::get_xyz_material(lua_State* L, card* scard, int32 findex, uint32 lv, } } void field::get_overlay_group(uint8 self, uint8 s, uint8 o, card_set* pset) { + if (!check_playerid(self)) + return; uint8 c = s; for(int32 p = 0; p < 2; ++p) { if(c) { for(auto& pcard : player[self].list_mzone) { - if(pcard && !pcard->get_status(STATUS_SUMMONING | STATUS_SPSUMMON_STEP) && pcard->xyz_materials.size()) + if(pcard && !pcard->is_treated_as_not_on_field() && pcard->xyz_materials.size()) pset->insert(pcard->xyz_materials.begin(), pcard->xyz_materials.end()); } } @@ -1976,12 +1978,14 @@ void field::get_overlay_group(uint8 self, uint8 s, uint8 o, card_set* pset) { } } int32 field::get_overlay_count(uint8 self, uint8 s, uint8 o) { + if (!check_playerid(self)) + return 0; uint8 c = s; int32 count = 0; for(int32 p = 0; p < 2; ++p) { if(c) { for(auto& pcard : player[self].list_mzone) { - if(pcard && !pcard->get_status(STATUS_SUMMONING | STATUS_SPSUMMON_STEP)) + if(pcard && !pcard->is_treated_as_not_on_field()) count += (int32)pcard->xyz_materials.size(); } } @@ -3283,7 +3287,7 @@ int32 field::is_player_can_remove_counter(uint8 playerid, card * pcard, uint8 s, return FALSE; } int32 field::is_player_can_remove_overlay_card(uint8 playerid, card * pcard, uint8 s, uint8 o, uint16 min, uint32 reason) { - if((pcard && pcard->xyz_materials.size() >= min) || (!pcard && get_overlay_count(playerid, s, o) >= min)) + if((pcard && (int32)pcard->xyz_materials.size() >= min) || (!pcard && get_overlay_count(playerid, s, o) >= min)) return TRUE; auto pr = effects.continuous_effect.equal_range(EFFECT_OVERLAY_REMOVE_REPLACE); tevent e; diff --git a/libduel.cpp b/libduel.cpp index 0212595e0..70552964c 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -1610,7 +1610,7 @@ int32 scriptlib::duel_shuffle_setcard(lua_State *L) { pduel->write_buffer8(MSG_SHUFFLE_SET_CARD); pduel->write_buffer8(loc); pduel->write_buffer8(ct); - for(uint32 i = 0; i < ct; ++i) { + for(int32 i = 0; i < ct; ++i) { card* pcard = ms[i]; pduel->write_buffer32(pcard->get_info_location()); if(loc == LOCATION_MZONE) @@ -1623,7 +1623,7 @@ int32 scriptlib::duel_shuffle_setcard(lua_State *L) { pduel->game_field->raise_event(&pgroup->container, EVENT_MOVE, pduel->game_field->core.reason_effect, 0, pduel->game_field->core.reason_player, tp, 0); pduel->game_field->process_single_event(); pduel->game_field->process_instant_event(); - for(uint32 i = 0; i < ct; ++i) { + for(int32 i = 0; i < ct; ++i) { if(ms[i]->xyz_materials.size()) pduel->write_buffer32(ms[i]->get_info_location()); else diff --git a/operations.cpp b/operations.cpp index 327b64c81..d1399a21f 100644 --- a/operations.cpp +++ b/operations.cpp @@ -784,7 +784,7 @@ int32 field::remove_overlay_card(uint16 step, uint32 reason, card* pcard, uint8 case 0: { core.select_options.clear(); core.select_effects.clear(); - if((pcard && pcard->xyz_materials.size() >= min) || (!pcard && get_overlay_count(rplayer, s, o) >= min)) { + if((pcard && (int32)pcard->xyz_materials.size() >= min) || (!pcard && get_overlay_count(rplayer, s, o) >= min)) { core.select_options.push_back(12); core.select_effects.push_back(0); } @@ -845,13 +845,11 @@ int32 field::remove_overlay_card(uint16 step, uint32 reason, card* pcard, uint8 } core.select_cards.clear(); if(pcard) { - for(auto& mcard : pcard->xyz_materials) - core.select_cards.push_back(mcard); + core.select_cards.assign(pcard->xyz_materials.begin(), pcard->xyz_materials.end()); } else { card_set cset; get_overlay_group(rplayer, s, o, &cset); - for(auto& xcard : cset) - core.select_cards.push_back(xcard); + core.select_cards.assign(cset.begin(), cset.end()); } pduel->write_buffer8(MSG_HINT); pduel->write_buffer8(HINT_SELECTMSG);