Skip to content

Commit

Permalink
fix card::xyz_remove (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
salix5 authored Oct 24, 2024
1 parent 8da5c41 commit b579cda
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b579cda

Please sign in to comment.