Commit bf2339ce authored by Chrono-Genex's avatar Chrono-Genex Committed by GitHub

add EFFECT_COUNT_CODE_CHAIN (#485)

parent a42373cd
......@@ -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);
......
......@@ -123,8 +123,10 @@ public:
//#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
......
......@@ -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--;
......
......@@ -263,6 +263,7 @@ struct processor {
std::unordered_set<card*> unique_cards[2];
std::unordered_map<uint32, uint32> effect_count_code;
std::unordered_map<uint32, uint32> effect_count_code_duel;
std::unordered_map<uint32, uint32> effect_count_code_chain;
std::unordered_map<uint32, uint32> spsummon_once_map[2];
std::multimap<int32, card*, std::greater<int32>> xmaterial_lst;
......
......@@ -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;
......
......@@ -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);
......
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