Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wind2009-Louse committed Nov 4, 2024
2 parents b30ab3f + 7a9fd22 commit de861f4
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 100 deletions.
129 changes: 68 additions & 61 deletions card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ int32 card::get_infos(byte* buf, uint32 query_flag, int32 use_cache) {
buffer_write<uint32_t>(finalize, query_flag);
return (int32)(p - buf);
}
uint32 card::get_info_location() {
uint32 card::get_info_location() const {
if(overlay_target) {
uint32 c = overlay_target->current.controler;
uint32 l = overlay_target->current.location | LOCATION_OVERLAY;
Expand Down 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 Expand Up @@ -1714,9 +1715,7 @@ void card::cancel_field_effect() {
if (current.controler == PLAYER_NONE)
return;
for (auto& it : field_effect) {
if (it.second->in_range(this) || it.second->is_hand_trigger()) {
pduel->game_field->remove_effect(it.second);
}
pduel->game_field->remove_effect(it.second);
}
if(unique_code && (current.location & unique_location))
pduel->game_field->remove_unique_card(this);
Expand Down Expand Up @@ -1881,12 +1880,6 @@ int32 card::add_effect(effect* peffect) {
peffect->reset_count = pduel->game_field->core.copy_reset_count;
}
effect* reason_effect = pduel->game_field->core.reason_effect;
if(peffect->is_flag(EFFECT_FLAG_COPY_INHERIT) && reason_effect && reason_effect->copy_id) {
peffect->copy_id = reason_effect->copy_id;
peffect->reset_flag |= reason_effect->reset_flag;
if(peffect->reset_count > reason_effect->reset_count)
peffect->reset_count = reason_effect->reset_count;
}
indexer.emplace(peffect, eit);
peffect->handler = this;
if((peffect->type & EFFECT_TYPE_FIELD)) {
Expand Down Expand Up @@ -1926,13 +1919,11 @@ int32 card::add_effect(effect* peffect) {
}
return peffect->id;
}
void card::remove_effect(effect* peffect) {
auto it = indexer.find(peffect);
if (it == indexer.end())
return;
remove_effect(peffect, it->second);
}
void card::remove_effect(effect* peffect, effect_container::iterator it) {
effect_indexer::iterator card::remove_effect(effect* peffect) {
auto index = indexer.find(peffect);
if (index == indexer.end())
return index;
auto& it = index->second;
card_set check_target = { this };
if (peffect->type & EFFECT_TYPE_SINGLE) {
single_effect.erase(it);
Expand Down Expand Up @@ -1960,25 +1951,14 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) {
pduel->game_field->update_disable_check_list(peffect);
}
field_effect.erase(it);
if(peffect->in_range(this) || current.controler != PLAYER_NONE && peffect->is_hand_trigger())
pduel->game_field->remove_effect(peffect);
}
if ((current.controler != PLAYER_NONE) && !get_status(STATUS_DISABLED | STATUS_FORBIDDEN) && !check_target.empty()) {
if (peffect->is_disable_related()) {
for (auto& target : check_target)
pduel->game_field->add_to_disable_check_list(target);
}
}
if (peffect->is_flag(EFFECT_FLAG_INITIAL) && peffect->copy_id && is_status(STATUS_EFFECT_REPLACED)) {
set_status(STATUS_EFFECT_REPLACED, FALSE);
if (interpreter::is_load_script(data)) {
set_status(STATUS_INITIALIZING, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_card_function(this, "initial_effect", 1, 0);
set_status(STATUS_INITIALIZING, FALSE);
}
}
indexer.erase(peffect);
auto ret = indexer.erase(index);
if(peffect->is_flag(EFFECT_FLAG_OATH))
pduel->game_field->effects.oath.erase(peffect);
if(peffect->reset_flag & RESET_PHASE)
Expand Down Expand Up @@ -2010,7 +1990,9 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) {
unique_pos[0] = unique_pos[1] = 0;
unique_code = 0;
}
pduel->game_field->remove_effect(peffect);
pduel->game_field->core.reseted_effects.insert(peffect);
return ret;
}
int32 card::copy_effect(uint32 code, uint32 reset, int32 count) {
card_data cdata;
Expand Down Expand Up @@ -2055,12 +2037,12 @@ int32 card::replace_effect(uint32 code, uint32 reset, int32 count) {
return -1;
if(is_status(STATUS_EFFECT_REPLACED))
set_status(STATUS_EFFECT_REPLACED, FALSE);
for(auto i = indexer.begin(); i != indexer.end();) {
auto rm = i++;
effect* peffect = rm->first;
auto& it = rm->second;
if (peffect->is_flag(EFFECT_FLAG_INITIAL | EFFECT_FLAG_COPY_INHERIT))
remove_effect(peffect, it);
for(auto it = indexer.begin(); it != indexer.end();) {
effect* const& peffect = it->first;
if (peffect->is_flag(EFFECT_FLAG_INITIAL))
it = remove_effect(peffect);
else
++it;
}
auto cr = pduel->game_field->core.copy_reset;
auto crc = pduel->game_field->core.copy_reset_count;
Expand Down Expand Up @@ -2159,17 +2141,34 @@ void card::reset(uint32 id, uint32 reset_type) {
}
}
}
for (auto i = indexer.begin(); i != indexer.end();) {
auto rm = i++;
effect* peffect = rm->first;
auto& it = rm->second;
if (peffect->reset(id, reset_type))
remove_effect(peffect, it);
else if (reset_type == RESET_COPY) {
delete_card_target(TRUE);
effect_target_cards.clear();
}
bool reload = false;
for (auto it = indexer.begin(); it != indexer.end();) {
effect* const& peffect = it->first;
if (peffect->reset(id, reset_type)) {
if (is_status(STATUS_EFFECT_REPLACED) && peffect->is_flag(EFFECT_FLAG_INITIAL) && peffect->copy_id)
reload = true;
it = remove_effect(peffect);
}
else
++it;
}
if (reload) {
set_status(STATUS_EFFECT_REPLACED, FALSE);
if (interpreter::is_load_script(data)) {
set_status(STATUS_INITIALIZING, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_card_function(this, "initial_effect", 1, 0);
set_status(STATUS_INITIALIZING, FALSE);
}
}
}
void card::reset_effect_count() {
for (auto& i : indexer) {
effect* peffect = i.first;
effect* const& peffect = i.first;
if (peffect->is_flag(EFFECT_FLAG_COUNT_LIMIT))
peffect->recharge();
}
Expand Down Expand Up @@ -2477,6 +2476,26 @@ void card::cancel_card_target(card* pcard) {
pduel->write_buffer32(pcard->get_info_location());
}
}
void card::delete_card_target(uint32 send_msg) {
for (auto& pcard : effect_target_cards) {
pcard->effect_target_owner.erase(this);
for (auto& it : target_effect) {
if (it.second->is_disable_related())
pduel->game_field->add_to_disable_check_list(pcard);
}
for (auto it = pcard->single_effect.begin(); it != pcard->single_effect.end();) {
auto rm = it++;
effect* const& peffect = rm->second;
if ((peffect->owner == this) && peffect->is_flag(EFFECT_FLAG_OWNER_RELATE))
pcard->remove_effect(peffect);
}
if (send_msg) {
pduel->write_buffer8(MSG_CANCEL_TARGET);
pduel->write_buffer32(get_info_location());
pduel->write_buffer32(pcard->get_info_location());
}
}
}
void card::clear_card_target() {
for(auto& pcard : effect_target_owner) {
pcard->effect_target_cards.erase(this);
Expand All @@ -2485,19 +2504,7 @@ void card::clear_card_target() {
pduel->game_field->add_to_disable_check_list(this);
}
}
for(auto& pcard : effect_target_cards) {
pcard->effect_target_owner.erase(this);
for(auto& it : target_effect) {
if(it.second->is_disable_related())
pduel->game_field->add_to_disable_check_list(pcard);
}
for(auto it = pcard->single_effect.begin(); it != pcard->single_effect.end();) {
auto rm = it++;
effect* peffect = rm->second;
if((peffect->owner == this) && peffect->is_flag(EFFECT_FLAG_OWNER_RELATE))
pcard->remove_effect(peffect, rm);
}
}
delete_card_target(FALSE);
effect_target_owner.clear();
effect_target_cards.clear();
}
Expand Down Expand Up @@ -2702,7 +2709,7 @@ void card::filter_immune_effect() {
// 4. Insert continuous target of this into it.
void card::filter_disable_related_cards() {
for (auto& it : indexer) {
effect* peffect = it.first;
effect* const& peffect = it.first;
if (peffect->is_disable_related()) {
if (peffect->type & EFFECT_TYPE_FIELD)
pduel->game_field->update_disable_check_list(peffect);
Expand Down
7 changes: 4 additions & 3 deletions card.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using card_set = std::set<card*, card_sort>;
using card_vector = std::vector<card*>;
using effect_container = std::multimap<uint32, effect*>;
using effect_indexer = std::unordered_map<effect*, effect_container::iterator>;
using effect_collection = std::unordered_set<effect*>;

struct card_state {
uint32 code{ 0 };
Expand Down Expand Up @@ -216,7 +217,7 @@ class card {
bool is_extra_deck_monster() const { return !!(data.type & TYPES_EXTRA_DECK); }

int32 get_infos(byte* buf, uint32 query_flag, int32 use_cache = TRUE);
uint32 get_info_location();
uint32 get_info_location() const;
uint32 get_original_code() const;
std::tuple<uint32, uint32> get_original_code_rule() const;
uint32 get_code();
Expand Down Expand Up @@ -286,8 +287,7 @@ class card {
void cancel_field_effect();
void enable_field_effect(bool enabled);
int32 add_effect(effect* peffect);
void remove_effect(effect* peffect);
void remove_effect(effect* peffect, effect_container::iterator it);
effect_indexer::iterator remove_effect(effect* peffect);
int32 copy_effect(uint32 code, uint32 reset, int32 count);
int32 replace_effect(uint32 code, uint32 reset, int32 count);
void reset(uint32 id, uint32 reset_type);
Expand Down Expand Up @@ -316,6 +316,7 @@ class card {
void set_material(card_set* materials);
void add_card_target(card* pcard);
void cancel_card_target(card* pcard);
void delete_card_target(uint32 send_msg);
void clear_card_target();
void set_special_summon_status(effect* peffect);

Expand Down
3 changes: 2 additions & 1 deletion effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class effect {
int32 operation{ 0 };
uint8 cost_checked{ FALSE };
effect_set required_handorset_effects;
LuaParamType object_type{ PARAM_TYPE_INT };

explicit effect(duel* pd);
~effect() = default;
Expand Down Expand Up @@ -190,7 +191,7 @@ enum effect_flag : uint32 {
EFFECT_FLAG_CANNOT_DISABLE = 0x0400,
EFFECT_FLAG_PLAYER_TARGET = 0x0800,
EFFECT_FLAG_BOTH_SIDE = 0x1000,
EFFECT_FLAG_COPY_INHERIT = 0x2000,
// EFFECT_FLAG_COPY_INHERIT = 0x2000,
EFFECT_FLAG_DAMAGE_STEP = 0x4000,
EFFECT_FLAG_DAMAGE_CAL = 0x8000,
EFFECT_FLAG_DELAY = 0x10000,
Expand Down
Loading

0 comments on commit de861f4

Please sign in to comment.