Skip to content

Commit

Permalink
check Kaiser Colosseum in Duel.GetMZoneCount & Duel.GetLocationCountF…
Browse files Browse the repository at this point in the history
…romEx (#600)

* check Kaiser Colosseum in Duel.GetMZoneCount & Duel.GetLocationCountFromEx

* format

* Update field.cpp

* Update libduel.cpp

* Update libduel.cpp

* Update field.cpp

* fix
  • Loading branch information
purerosefallen authored Jun 27, 2024
1 parent cbca8ce commit c667c12
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
23 changes: 23 additions & 0 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,29 @@ int32 field::get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason) {
int32 limit = max - field_used_count[used_flag];
return limit;
}
int32 field::get_kaiser_limit(uint8 playerid, card_set* using_cards) {
if(!is_player_affected_by_effect(playerid, EFFECT_KAISER_COLOSSEUM))
return 0xff;
auto oppo_monster_count = filter_field_card(playerid, 0, LOCATION_MZONE, 0);
if(!oppo_monster_count)
return 0xff;
auto limit = oppo_monster_count - filter_field_card(playerid, LOCATION_MZONE, 0, 0);
for(auto& pcard : *using_cards) {
if(pcard->current.is_location(LOCATION_MZONE)) {
if(pcard->current.controler == playerid)
++limit;
else
--limit;
}
}
return limit;
}
int32 field::get_kaiser_limit(uint8 playerid, card* using_card) {
card_set using_cards;
if(using_card)
using_cards.insert(using_card);
return get_kaiser_limit(playerid, &using_cards);
}
uint32 field::get_linked_zone(int32 playerid) {
uint32 zones = 0;
for(auto& pcard : player[playerid].list_mzone) {
Expand Down
2 changes: 2 additions & 0 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ class field {
int32 get_spsummonable_count_fromex_rule4(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone = 0xff, uint32* list = nullptr);
int32 get_mzone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_kaiser_limit(uint8 playerid, card_set* using_cards);
int32 get_kaiser_limit(uint8 playerid, card* using_card);
uint32 get_linked_zone(int32 playerid);
uint32 get_rule_zone_fromex(int32 playerid, card* pcard);
void filter_must_use_mzone(uint8 playerid, uint8 uplayer, uint32 reason, card* pcard, uint32* flag);
Expand Down
30 changes: 26 additions & 4 deletions libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,14 +2009,25 @@ int32 scriptlib::duel_get_mzone_count(lua_State *L) {
if(lua_gettop(L) >= 5)
zone = (uint32)lua_tointeger(L, 5);
uint32 list = 0;
lua_pushinteger(L, pduel->game_field->get_useable_count(nullptr, playerid, LOCATION_MZONE, uplayer, reason, zone, &list));
lua_pushinteger(L, list);
auto count = pduel->game_field->get_useable_count(nullptr, playerid, LOCATION_MZONE, uplayer, reason, zone, &list);
if(swapped) {
pduel->game_field->player[0].used_location = used_location[0];
pduel->game_field->player[1].used_location = used_location[1];
pduel->game_field->player[0].list_mzone.swap(list_mzone[0]);
pduel->game_field->player[1].list_mzone.swap(list_mzone[1]);
}
if(uplayer == playerid && reason == LOCATION_REASON_TOFIELD) {
int32 kaiser_limit = 0xff;
if(mcard) {
kaiser_limit = pduel->game_field->get_kaiser_limit(playerid, mcard);
} else if (mgroup) {
kaiser_limit = pduel->game_field->get_kaiser_limit(playerid, &mgroup->container);
}
if (kaiser_limit < count)
count = kaiser_limit;
}
lua_pushinteger(L, count);
lua_pushinteger(L, list);
return 2;
}
// Condition: uplayer moves scard or any card with type from Extra Deck to playerid's field
Expand Down Expand Up @@ -2079,14 +2090,25 @@ int32 scriptlib::duel_get_location_count_fromex(lua_State *L) {
if(lua_gettop(L) >= 5)
zone = (uint32)lua_tointeger(L, 5);
uint32 list = 0;
lua_pushinteger(L, pduel->game_field->get_useable_count_fromex(scard, playerid, uplayer, zone, &list));
lua_pushinteger(L, list);
auto count = pduel->game_field->get_useable_count_fromex(scard, playerid, uplayer, zone, &list);
if(swapped) {
pduel->game_field->player[0].used_location = used_location[0];
pduel->game_field->player[1].used_location = used_location[1];
pduel->game_field->player[0].list_mzone.swap(list_mzone[0]);
pduel->game_field->player[1].list_mzone.swap(list_mzone[1]);
}
if(uplayer == playerid) {
int32 kaiser_limit = 0xff;
if(mcard) {
kaiser_limit = pduel->game_field->get_kaiser_limit(playerid, mcard);
} else if (mgroup) {
kaiser_limit = pduel->game_field->get_kaiser_limit(playerid, &mgroup->container);
}
if (kaiser_limit < count)
count = kaiser_limit;
}
lua_pushinteger(L, count);
lua_pushinteger(L, list);
if(use_temp_card) {
scard->current.location = 0;
scard->data.type = 0;
Expand Down

0 comments on commit c667c12

Please sign in to comment.