From bf2339ce96152b6825c5a4064ac669def6caf976 Mon Sep 17 00:00:00 2001 From: Chrono-Genex <79453236+chronogenexx@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:14:29 +0900 Subject: [PATCH] add EFFECT_COUNT_CODE_CHAIN (#485) --- effect.cpp | 4 ++-- effect.h | 6 ++++-- field.cpp | 28 ++++++++++++++++++++-------- field.h | 1 + libeffect.cpp | 2 ++ processor.cpp | 2 ++ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/effect.cpp b/effect.cpp index 5ea6d76bf..444f16cfc 100644 --- a/effect.cpp +++ b/effect.cpp @@ -201,7 +201,7 @@ int32 effect::check_count_limit(uint8 playerid) { if(count_code) { uint32 code = count_code & 0xfffffff; uint32 count = count_limit_max; - if(code == 1) { + if(code == EFFECT_COUNT_CODE_SINGLE) { if(pduel->game_field->get_effect_code((count_code & 0xf0000000) | get_handler()->fieldid, PLAYER_NONE) >= count) return FALSE; } else { @@ -666,7 +666,7 @@ void effect::dec_count(uint32 playerid) { count_limit -= 1; if(count_code) { uint32 code = count_code & 0xfffffff; - if(code == 1) + if(code == EFFECT_COUNT_CODE_SINGLE) pduel->game_field->add_effect_code((count_code & 0xf0000000) | get_handler()->fieldid, PLAYER_NONE); else pduel->game_field->add_effect_code(count_code, playerid); diff --git a/effect.h b/effect.h index 59ac4fe92..753f64dac 100644 --- a/effect.h +++ b/effect.h @@ -123,8 +123,10 @@ class effect { //#define EFFECT_STATUS_ACTIVATED 0x0002 #define EFFECT_STATUS_SPSELF 0x0004 -#define EFFECT_COUNT_CODE_OATH 0x10000000 -#define EFFECT_COUNT_CODE_DUEL 0x20000000 +#define EFFECT_COUNT_CODE_OATH 0x10000000 +#define EFFECT_COUNT_CODE_DUEL 0x20000000 +#define EFFECT_COUNT_CODE_CHAIN 0x40000000 +#define EFFECT_COUNT_CODE_SINGLE 0x1 //========== Reset ========== #define RESET_SELF_TURN 0x10000000 diff --git a/field.cpp b/field.cpp index b17535e83..15c1ef737 100644 --- a/field.cpp +++ b/field.cpp @@ -1316,20 +1316,32 @@ void field::reset_chain() { } } void field::add_effect_code(uint32 code, uint32 playerid) { - auto& count_map = (code & EFFECT_COUNT_CODE_DUEL) ? core.effect_count_code_duel : core.effect_count_code; - count_map[code + (playerid << 30)]++; + auto* count_map = &core.effect_count_code; + if(code & EFFECT_COUNT_CODE_DUEL) + count_map = &core.effect_count_code_duel; + else if(code & EFFECT_COUNT_CODE_CHAIN) + count_map = &core.effect_count_code_chain; + (*count_map)[code + (playerid << 30)]++; } uint32 field::get_effect_code(uint32 code, uint32 playerid) { - auto& count_map = (code & EFFECT_COUNT_CODE_DUEL) ? core.effect_count_code_duel : core.effect_count_code; - auto iter = count_map.find(code + (playerid << 30)); - if(iter == count_map.end()) + auto* count_map = &core.effect_count_code; + if(code & EFFECT_COUNT_CODE_DUEL) + count_map = &core.effect_count_code_duel; + else if(code & EFFECT_COUNT_CODE_CHAIN) + count_map = &core.effect_count_code_chain; + auto iter = count_map->find(code + (playerid << 30)); + if(iter == count_map->end()) return 0; return iter->second; } void field::dec_effect_code(uint32 code, uint32 playerid) { - auto& count_map = (code & EFFECT_COUNT_CODE_DUEL) ? core.effect_count_code_duel : core.effect_count_code; - auto iter = count_map.find(code + (playerid << 30)); - if(iter == count_map.end()) + auto* count_map = &core.effect_count_code; + if(code & EFFECT_COUNT_CODE_DUEL) + count_map = &core.effect_count_code_duel; + else if(code & EFFECT_COUNT_CODE_CHAIN) + count_map = &core.effect_count_code_chain; + auto iter = count_map->find(code + (playerid << 30)); + if(iter == count_map->end()) return; if(iter->second > 0) iter->second--; diff --git a/field.h b/field.h index 5d72b43be..4600d7979 100644 --- a/field.h +++ b/field.h @@ -263,6 +263,7 @@ struct processor { std::unordered_set unique_cards[2]; std::unordered_map effect_count_code; std::unordered_map effect_count_code_duel; + std::unordered_map effect_count_code_chain; std::unordered_map spsummon_once_map[2]; std::multimap> xmaterial_lst; diff --git a/libeffect.cpp b/libeffect.cpp index 328afc8c4..680480cc9 100644 --- a/libeffect.cpp +++ b/libeffect.cpp @@ -120,6 +120,8 @@ int32 scriptlib::effect_set_count_limit(lua_State *L) { code = (uint32)lua_tointeger(L, 3); if(v == 0) v = 1; + if(code == EFFECT_COUNT_CODE_CHAIN) + code = EFFECT_COUNT_CODE_CHAIN + EFFECT_COUNT_CODE_SINGLE; peffect->flag[0] |= EFFECT_FLAG_COUNT_LIMIT; peffect->count_limit = v; peffect->count_limit_max = v; diff --git a/processor.cpp b/processor.cpp index 2de6885c0..e707edd56 100644 --- a/processor.cpp +++ b/processor.cpp @@ -1492,6 +1492,7 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free for(auto& ch_lim_p : core.chain_limit_p) luaL_unref(pduel->lua->lua_state, LUA_REGISTRYINDEX, ch_lim_p.function); core.chain_limit_p.clear(); + core.effect_count_code_chain.clear(); reset_chain(); returns.ivalue[0] = FALSE; } @@ -4485,6 +4486,7 @@ int32 field::solve_chain(uint16 step, uint32 chainend_arg1, uint32 chainend_arg2 for(auto& ch_lim_p : core.chain_limit_p) luaL_unref(pduel->lua->lua_state, LUA_REGISTRYINDEX, ch_lim_p.function); core.chain_limit_p.clear(); + core.effect_count_code_chain.clear(); reset_chain(); if(core.summoning_card || core.effect_damage_step == 1) core.subunits.push_back(core.reserved);