Skip to content

Commit

Permalink
add EFFECT_COUNT_CODE_CHAIN (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
465uytrewq authored Apr 15, 2023
1 parent a42373c commit bf2339c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down
1 change: 1 addition & 0 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions libeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bf2339c

Please sign in to comment.