Skip to content

Commit

Permalink
Added more chain info options (#153)
Browse files Browse the repository at this point in the history
Added new flags for Duel.GetChainInfo:
TRIGGERING_STATUS: the status of the card
TRIGGERING_SUMMON_LOCATION: the summon location of the card
TRIGGERING_SUMMON_TYPE: its summon type
TRIGGERING_SUMMON_PROC_COMPLETE: if the card was properly summoned or not when it triggered the effect
TRIGGERING_SETCODES: the archetypes the card had when it activated the effect
  • Loading branch information
NaimSantos authored Dec 9, 2023
1 parent b85d41d commit a2a979a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void chain::set_triggering_state(card* pcard) {
}
triggering_sequence = pcard->current.sequence;
triggering_position = pcard->current.position;
triggering_status = pcard->status;
triggering_summon_type = pcard->summon.type & 0xff00ffff;
triggering_summon_location = pcard->summon.location;
triggering_summon_proc_complete = pcard->is_status(STATUS_PROC_COMPLETE);
triggering_state.code = pcard->get_code();
triggering_state.code2 = pcard->get_another_code();
triggering_state.level = pcard->get_level();
Expand All @@ -44,6 +48,10 @@ void chain::set_triggering_state(card* pcard) {
triggering_state.race = pcard->get_race();
triggering_state.attack = pcard->get_attack();
triggering_state.defense = pcard->get_defense();
//For the triggering archetypes:
auto& setcode = triggering_state.setcodes;
setcode.clear();
pcard->get_set_card(setcode);
}
bool tevent::operator< (const tevent& v) const {
return std::memcmp(this, &v, sizeof(tevent)) < 0;
Expand Down
9 changes: 9 additions & 0 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ struct chain {
uint16_t triggering_location;
uint32_t triggering_sequence;
uint8_t triggering_position;
uint32_t triggering_status{};
uint32_t triggering_summon_type{};
uint8_t triggering_summon_location{};
bool triggering_summon_proc_complete{}; //properly summoned or not
card_state triggering_state;
effect* triggering_effect;
group* target_cards;
Expand Down Expand Up @@ -733,6 +737,11 @@ enum class CHAININFO {
TRIGGERING_RACE,
TRIGGERING_ATTACK,
TRIGGERING_DEFENSE,
TRIGGERING_STATUS,
TRIGGERING_SUMMON_LOCATION,
TRIGGERING_SUMMON_TYPE,
TRIGGERING_SUMMON_PROC_COMPLETE,
TRIGGERING_SETCODES,
};

//Timing
Expand Down
29 changes: 25 additions & 4 deletions libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1907,11 +1907,9 @@ LUA_STATIC_FUNCTION(GetChainInfo) {
lua_pushinteger(L, 0);
else
lua_pushinteger(L, 1);
}
else if(ch->triggering_location & LOCATION_FZONE) {
} else if(ch->triggering_location & LOCATION_FZONE) {
lua_pushinteger(L, 0);
}
else if(ch->triggering_location & LOCATION_EMZONE) {
} else if(ch->triggering_location & LOCATION_EMZONE) {
lua_pushinteger(L, ch->triggering_sequence - 5);
} else
lua_pushinteger(L, ch->triggering_sequence);
Expand Down Expand Up @@ -1972,6 +1970,29 @@ LUA_STATIC_FUNCTION(GetChainInfo) {
case CHAININFO::EXTTYPE:
lua_pushinteger(L, ch->triggering_effect->card_type);
break;
case CHAININFO::TRIGGERING_STATUS:
lua_pushinteger(L, ch->triggering_status);
break;
case CHAININFO::TRIGGERING_SUMMON_LOCATION:
lua_pushinteger(L, ch->triggering_summon_location);
break;
case CHAININFO::TRIGGERING_SUMMON_TYPE:
lua_pushinteger(L, ch->triggering_summon_type);
break;
case CHAININFO::TRIGGERING_SUMMON_PROC_COMPLETE:
lua_pushboolean(L, ch->triggering_summon_proc_complete);
break;
case CHAININFO::TRIGGERING_SETCODES: {
const auto& setcodes = ch->triggering_state.setcodes;
lua_createtable(L, setcodes.size(), 0);
int i = 1;
for(const auto& setcode : setcodes) {
lua_pushinteger(L, i++);
lua_pushinteger(L, setcode);
lua_settable(L, -3);
}
break;
}
default:
lua_error(L, "Passed invalid CHAININFO flag.");
}
Expand Down

0 comments on commit a2a979a

Please sign in to comment.