Commit 554f5f8e authored by Chen Bill's avatar Chen Bill

add lua_State* to filter_matching_card

parent e631d73f
...@@ -1444,7 +1444,7 @@ void field::filter_player_effect(uint8 playerid, uint32 code, effect_set* eset, ...@@ -1444,7 +1444,7 @@ void field::filter_player_effect(uint8 playerid, uint32 code, effect_set* eset,
if(sort) if(sort)
eset->sort(); eset->sort();
} }
int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret, int32 fcount, int32 is_target) { int32 field::filter_matching_card(lua_State* L, int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret, int32 fcount, int32 is_target) {
if(self != 0 && self != 1) if(self != 0 && self != 1)
return FALSE; return FALSE;
card_set result; card_set result;
...@@ -1454,7 +1454,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1454,7 +1454,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
for(auto& pcard : player[self].list_mzone) { for(auto& pcard : player[self].list_mzone) {
if(pcard && !pcard->is_treated_as_not_on_field() if(pcard && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_matching(pcard, findex, extraargs) && pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = pcard; *pret = pcard;
...@@ -1470,7 +1470,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1470,7 +1470,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
for(auto& pcard : player[self].list_szone) { for(auto& pcard : player[self].list_szone) {
if(pcard && !pcard->is_treated_as_not_on_field() if(pcard && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_matching(pcard, findex, extraargs) && pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = pcard; *pret = pcard;
...@@ -1486,7 +1486,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1486,7 +1486,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
card* pcard = player[self].list_szone[5]; card* pcard = player[self].list_szone[5];
if(pcard && !pcard->is_treated_as_not_on_field() if(pcard && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_matching(pcard, findex, extraargs) && pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = pcard; *pret = pcard;
...@@ -1502,7 +1502,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1502,7 +1502,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
card* pcard = player[self].list_szone[core.duel_rule >= 4 ? i * 4 : i + 6]; card* pcard = player[self].list_szone[core.duel_rule >= 4 ? i * 4 : i + 6];
if(pcard && pcard->current.pzone && !pcard->is_treated_as_not_on_field() if(pcard && pcard->current.pzone && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_matching(pcard, findex, extraargs) && pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = pcard; *pret = pcard;
...@@ -1517,7 +1517,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1517,7 +1517,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
if(location & LOCATION_DECK) { if(location & LOCATION_DECK) {
for(auto cit = player[self].list_main.rbegin(); cit != player[self].list_main.rend(); ++cit) { for(auto cit = player[self].list_main.rbegin(); cit != player[self].list_main.rend(); ++cit) {
if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit))
&& pduel->lua->check_matching(*cit, findex, extraargs) && pduel->lua->check_filter(L, *cit, findex, extraargs)
&& (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = *cit; *pret = *cit;
...@@ -1532,7 +1532,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1532,7 +1532,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
if(location & LOCATION_EXTRA) { if(location & LOCATION_EXTRA) {
for(auto cit = player[self].list_extra.rbegin(); cit != player[self].list_extra.rend(); ++cit) { for(auto cit = player[self].list_extra.rbegin(); cit != player[self].list_extra.rend(); ++cit) {
if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit))
&& pduel->lua->check_matching(*cit, findex, extraargs) && pduel->lua->check_filter(L, *cit, findex, extraargs)
&& (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = *cit; *pret = *cit;
...@@ -1547,7 +1547,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1547,7 +1547,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
if(location & LOCATION_HAND) { if(location & LOCATION_HAND) {
for(auto& pcard : player[self].list_hand) { for(auto& pcard : player[self].list_hand) {
if(pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) if(pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_matching(pcard, findex, extraargs) && pduel->lua->check_filter(L, pcard, findex, extraargs)
&& (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = pcard; *pret = pcard;
...@@ -1562,7 +1562,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1562,7 +1562,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
if(location & LOCATION_GRAVE) { if(location & LOCATION_GRAVE) {
for(auto cit = player[self].list_grave.rbegin(); cit != player[self].list_grave.rend(); ++cit) { for(auto cit = player[self].list_grave.rbegin(); cit != player[self].list_grave.rend(); ++cit) {
if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit))
&& pduel->lua->check_matching(*cit, findex, extraargs) && pduel->lua->check_filter(L, *cit, findex, extraargs)
&& (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = *cit; *pret = *cit;
...@@ -1577,7 +1577,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui ...@@ -1577,7 +1577,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui
if(location & LOCATION_REMOVED) { if(location & LOCATION_REMOVED) {
for(auto cit = player[self].list_remove.rbegin(); cit != player[self].list_remove.rend(); ++cit) { for(auto cit = player[self].list_remove.rbegin(); cit != player[self].list_remove.rend(); ++cit) {
if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit))
&& pduel->lua->check_matching(*cit, findex, extraargs) && pduel->lua->check_filter(L, *cit, findex, extraargs)
&& (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) {
if(pret) { if(pret) {
*pret = *cit; *pret = *cit;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "common.h" #include "common.h"
#include "card.h" #include "card.h"
#include "effectset.h" #include "effectset.h"
#include "interpreter.h"
#include <vector> #include <vector>
#include <set> #include <set>
#include <map> #include <map>
...@@ -432,7 +433,7 @@ public: ...@@ -432,7 +433,7 @@ public:
void filter_affected_cards(effect* peffect, card_set* cset); void filter_affected_cards(effect* peffect, card_set* cset);
void filter_inrange_cards(effect* peffect, card_set* cset); void filter_inrange_cards(effect* peffect, card_set* cset);
void filter_player_effect(uint8 playerid, uint32 code, effect_set* eset, uint8 sort = TRUE); void filter_player_effect(uint8 playerid, uint32 code, effect_set* eset, uint8 sort = TRUE);
int32 filter_matching_card(int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret = nullptr, int32 fcount = 0, int32 is_target = FALSE); int32 filter_matching_card(lua_State* L, int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret = nullptr, int32 fcount = 0, int32 is_target = FALSE);
int32 filter_field_card(uint8 self, uint32 location, uint32 location2, group* pgroup); int32 filter_field_card(uint8 self, uint32 location, uint32 location2, group* pgroup);
effect* is_player_affected_by_effect(uint8 playerid, uint32 code); effect* is_player_affected_by_effect(uint8 playerid, uint32 code);
......
...@@ -1517,7 +1517,7 @@ int32 scriptlib::duel_discard_hand(lua_State *L) { ...@@ -1517,7 +1517,7 @@ int32 scriptlib::duel_discard_hand(lua_State *L) {
uint32 max = (uint32)lua_tointeger(L, 4); uint32 max = (uint32)lua_tointeger(L, 4);
uint32 reason = (uint32)lua_tointeger(L, 5); uint32 reason = (uint32)lua_tointeger(L, 5);
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(2, playerid, LOCATION_HAND, 0, pgroup, pexception, pexgroup, extraargs); pduel->game_field->filter_matching_card(L, 2, playerid, LOCATION_HAND, 0, pgroup, pexception, pexgroup, extraargs);
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end()); pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
if(pduel->game_field->core.select_cards.size() == 0) { if(pduel->game_field->core.select_cards.size() == 0) {
lua_pushinteger(L, 0); lua_pushinteger(L, 0);
...@@ -2564,7 +2564,7 @@ int32 scriptlib::duel_get_matching_group(lua_State *L) { ...@@ -2564,7 +2564,7 @@ int32 scriptlib::duel_get_matching_group(lua_State *L) {
uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location1 = (uint32)lua_tointeger(L, 3);
uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 location2 = (uint32)lua_tointeger(L, 4);
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs);
interpreter::group2value(L, pgroup); interpreter::group2value(L, pgroup);
return 1; return 1;
} }
...@@ -2589,7 +2589,7 @@ int32 scriptlib::duel_get_matching_count(lua_State *L) { ...@@ -2589,7 +2589,7 @@ int32 scriptlib::duel_get_matching_count(lua_State *L) {
uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location1 = (uint32)lua_tointeger(L, 3);
uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 location2 = (uint32)lua_tointeger(L, 4);
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs);
uint32 count = (uint32)pgroup->container.size(); uint32 count = (uint32)pgroup->container.size();
lua_pushinteger(L, count); lua_pushinteger(L, count);
return 1; return 1;
...@@ -2615,7 +2615,7 @@ int32 scriptlib::duel_get_first_matching_card(lua_State *L) { ...@@ -2615,7 +2615,7 @@ int32 scriptlib::duel_get_first_matching_card(lua_State *L) {
uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location1 = (uint32)lua_tointeger(L, 3);
uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 location2 = (uint32)lua_tointeger(L, 4);
card* pret = nullptr; card* pret = nullptr;
pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, &pret); pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, &pret);
if(pret) if(pret)
interpreter::card2value(L, pret); interpreter::card2value(L, pret);
else lua_pushnil(L); else lua_pushnil(L);
...@@ -2642,7 +2642,7 @@ int32 scriptlib::duel_is_existing_matching_card(lua_State *L) { ...@@ -2642,7 +2642,7 @@ int32 scriptlib::duel_is_existing_matching_card(lua_State *L) {
uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location1 = (uint32)lua_tointeger(L, 3);
uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 location2 = (uint32)lua_tointeger(L, 4);
uint32 fcount = (uint32)lua_tointeger(L, 5); uint32 fcount = (uint32)lua_tointeger(L, 5);
lua_pushboolean(L, pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, fcount)); lua_pushboolean(L, pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, fcount));
return 1; return 1;
} }
/** /**
...@@ -2672,7 +2672,7 @@ int32 scriptlib::duel_select_matching_cards(lua_State *L) { ...@@ -2672,7 +2672,7 @@ int32 scriptlib::duel_select_matching_cards(lua_State *L) {
uint32 min = (uint32)lua_tointeger(L, 6); uint32 min = (uint32)lua_tointeger(L, 6);
uint32 max = (uint32)lua_tointeger(L, 7); uint32 max = (uint32)lua_tointeger(L, 7);
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); pduel->game_field->filter_matching_card(L, 2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs);
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end()); pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16)); pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
...@@ -2990,7 +2990,7 @@ int32 scriptlib::duel_get_target_count(lua_State *L) { ...@@ -2990,7 +2990,7 @@ int32 scriptlib::duel_get_target_count(lua_State *L) {
uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 location2 = (uint32)lua_tointeger(L, 4);
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
uint32 count = 0; uint32 count = 0;
pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE); pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE);
count = (uint32)pgroup->container.size(); count = (uint32)pgroup->container.size();
lua_pushinteger(L, count); lua_pushinteger(L, count);
return 1; return 1;
...@@ -3016,7 +3016,7 @@ int32 scriptlib::duel_is_existing_target(lua_State *L) { ...@@ -3016,7 +3016,7 @@ int32 scriptlib::duel_is_existing_target(lua_State *L) {
uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location1 = (uint32)lua_tointeger(L, 3);
uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 location2 = (uint32)lua_tointeger(L, 4);
uint32 count = (uint32)lua_tointeger(L, 5); uint32 count = (uint32)lua_tointeger(L, 5);
lua_pushboolean(L, pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, count, TRUE)); lua_pushboolean(L, pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, count, TRUE));
return 1; return 1;
} }
/** /**
...@@ -3048,7 +3048,7 @@ int32 scriptlib::duel_select_target(lua_State *L) { ...@@ -3048,7 +3048,7 @@ int32 scriptlib::duel_select_target(lua_State *L) {
if(pduel->game_field->core.current_chain.size() == 0) if(pduel->game_field->core.current_chain.size() == 0)
return 0; return 0;
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
pduel->game_field->filter_matching_card(2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE); pduel->game_field->filter_matching_card(L, 2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE);
pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end()); pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end());
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16)); pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
......
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