Commit d7dc36c5 authored by nekrozar's avatar nekrozar Committed by mercury233

add function (#92)

parent 3865e448
...@@ -1293,6 +1293,22 @@ uint32 card::get_mutual_linked_zone() { ...@@ -1293,6 +1293,22 @@ uint32 card::get_mutual_linked_zone() {
} }
return zones; return zones;
} }
int32 card::is_link_state() {
if(!(get_type() & TYPE_MONSTER))
return FALSE;
card::card_set cset1;
this->get_linked_cards(&cset1);
if(cset1.size() > 0)
return TRUE;
field::card_set cset2;
int32 p = current.controler;
uint32 linked_zone = pduel->game_field->get_linked_zone(p) | pduel->game_field->get_linked_zone(1 - p);
pduel->game_field->get_cards_in_zone(&cset2, linked_zone, p);
pduel->game_field->get_cards_in_zone(&cset2, linked_zone, 1 - p);
if(cset2.find(this) != cset2.end())
return TRUE;
return FALSE;
}
int32 card::is_position(int32 pos) { int32 card::is_position(int32 pos) {
return current.position & pos; return current.position & pos;
} }
...@@ -1997,7 +2013,7 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) { ...@@ -1997,7 +2013,7 @@ int32 card::destination_redirect(uint8 destination, uint32 reason) {
filter_effect(EFFECT_TO_GRAVE_REDIRECT, &es); filter_effect(EFFECT_TO_GRAVE_REDIRECT, &es);
else if(destination == LOCATION_REMOVED) else if(destination == LOCATION_REMOVED)
filter_effect(EFFECT_REMOVE_REDIRECT, &es); filter_effect(EFFECT_REMOVE_REDIRECT, &es);
else else
return 0; return 0;
for(int32 i = 0; i < es.size(); ++i) { for(int32 i = 0; i < es.size(); ++i) {
redirect = es[i]->get_value(this, 0); redirect = es[i]->get_value(this, 0);
...@@ -2235,7 +2251,7 @@ void card::filter_immune_effect() { ...@@ -2235,7 +2251,7 @@ void card::filter_immune_effect() {
} }
immune_effect.sort(); immune_effect.sort();
} }
// for all disable-related peffect of this, // for all disable-related peffect of this,
// 1. put all cards in the target of peffect into effects.disable_check_set, effects.disable_check_list // 1. put all cards in the target of peffect into effects.disable_check_set, effects.disable_check_list
// 2. add equiping_target of peffect into effects.disable_check_set, effects.disable_check_list // 2. add equiping_target of peffect into effects.disable_check_set, effects.disable_check_list
void card::filter_disable_related_cards() { void card::filter_disable_related_cards() {
......
...@@ -199,6 +199,7 @@ public: ...@@ -199,6 +199,7 @@ public:
uint32 get_linked_zone(); uint32 get_linked_zone();
void get_linked_cards(card_set* cset); void get_linked_cards(card_set* cset);
uint32 get_mutual_linked_zone(); uint32 get_mutual_linked_zone();
int32 is_link_state();
int32 is_position(int32 pos); int32 is_position(int32 pos);
void set_status(uint32 status, int32 enabled); void set_status(uint32 status, int32 enabled);
int32 get_status(uint32 status); int32 get_status(uint32 status);
......
...@@ -704,6 +704,18 @@ uint32 field::get_linked_zone(int32 playerid) { ...@@ -704,6 +704,18 @@ uint32 field::get_linked_zone(int32 playerid) {
} }
return zones; return zones;
} }
void field::get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset) {
cset->clear();
uint8 c = s;
for(int32 p = 0; p < 2; ++p) {
if(c) {
uint32 linked_zone = get_linked_zone(self);
get_cards_in_zone(cset, linked_zone, self);
}
self = 1 - self;
c = o;
}
}
int32 field::check_extra_link(int32 playerid) { int32 field::check_extra_link(int32 playerid) {
if(!player[playerid].list_mzone[5] || !player[playerid].list_mzone[6]) if(!player[playerid].list_mzone[5] || !player[playerid].list_mzone[6])
return FALSE; return FALSE;
...@@ -2150,7 +2162,7 @@ int32 field::get_attack_target(card* pcard, card_vector* v, uint8 chain_attack) ...@@ -2150,7 +2162,7 @@ int32 field::get_attack_target(card* pcard, card_vector* v, uint8 chain_attack)
// effects with target limit // effects with target limit
if((peffect = pcard->is_affected_by_effect(EFFECT_ATTACK_ALL)) if((peffect = pcard->is_affected_by_effect(EFFECT_ATTACK_ALL))
&& pcard->announced_cards.find(0) == pcard->announced_cards.end() && pcard->battled_cards.find(0) == pcard->battled_cards.end() && pcard->announced_cards.find(0) == pcard->announced_cards.end() && pcard->battled_cards.find(0) == pcard->battled_cards.end()
&& pcard->attack_all_target) { && pcard->attack_all_target) {
for(auto cit = pv->begin(); cit != pv->end(); ++cit) { for(auto cit = pv->begin(); cit != pv->end(); ++cit) {
card* atarget = *cit; card* atarget = *cit;
if(!atarget) if(!atarget)
...@@ -2190,7 +2202,7 @@ int32 field::get_attack_target(card* pcard, card_vector* v, uint8 chain_attack) ...@@ -2190,7 +2202,7 @@ int32 field::get_attack_target(card* pcard, card_vector* v, uint8 chain_attack)
dir = false; dir = false;
else { else {
// effects with target limit // effects with target limit
if((peffect = pcard->is_affected_by_effect(EFFECT_ATTACK_ALL)) && pcard->attack_all_target) { if((peffect = pcard->is_affected_by_effect(EFFECT_ATTACK_ALL)) && pcard->attack_all_target) {
for(auto cit = pv->begin(); cit != pv->end(); ++cit) { for(auto cit = pv->begin(); cit != pv->end(); ++cit) {
card* atarget = *cit; card* atarget = *cit;
if(!atarget) if(!atarget)
...@@ -2201,7 +2213,7 @@ int32 field::get_attack_target(card* pcard, card_vector* v, uint8 chain_attack) ...@@ -2201,7 +2213,7 @@ int32 field::get_attack_target(card* pcard, card_vector* v, uint8 chain_attack)
continue; continue;
// enough effect count // enough effect count
auto it = pcard->announced_cards.find(atarget->fieldid_r); auto it = pcard->announced_cards.find(atarget->fieldid_r);
if(it != pcard->announced_cards.end() if(it != pcard->announced_cards.end()
&& (atarget == core.attack_target ? (int32)it->second.second > peffect->get_value(atarget) : (int32)it->second.second >= peffect->get_value(atarget))) { && (atarget == core.attack_target ? (int32)it->second.second > peffect->get_value(atarget) : (int32)it->second.second >= peffect->get_value(atarget))) {
continue; continue;
} }
...@@ -2257,7 +2269,7 @@ bool field::confirm_attack_target() { ...@@ -2257,7 +2269,7 @@ bool field::confirm_attack_target() {
card_vector must_be_attack; card_vector must_be_attack;
card_vector only_be_attack; card_vector only_be_attack;
effect_set eset; effect_set eset;
// find the universal set // find the universal set
for(auto cit = player[1 - p].list_mzone.begin(); cit != player[1 - p].list_mzone.end(); ++cit) { for(auto cit = player[1 - p].list_mzone.begin(); cit != player[1 - p].list_mzone.end(); ++cit) {
card* atarget = *cit; card* atarget = *cit;
...@@ -2320,7 +2332,7 @@ bool field::confirm_attack_target() { ...@@ -2320,7 +2332,7 @@ bool field::confirm_attack_target() {
dir = false; dir = false;
else { else {
// effects with target limit // effects with target limit
if((peffect = pcard->is_affected_by_effect(EFFECT_ATTACK_ALL)) && pcard->attack_all_target && core.attack_target) { if((peffect = pcard->is_affected_by_effect(EFFECT_ATTACK_ALL)) && pcard->attack_all_target && core.attack_target) {
// valid target // valid target
pduel->lua->add_param(core.attack_target, PARAM_TYPE_CARD); pduel->lua->add_param(core.attack_target, PARAM_TYPE_CARD);
if(!peffect->check_value_condition(1)) if(!peffect->check_value_condition(1))
...@@ -2353,7 +2365,7 @@ bool field::confirm_attack_target() { ...@@ -2353,7 +2365,7 @@ bool field::confirm_attack_target() {
if(core.attack_target) if(core.attack_target)
return std::find(pv->begin(), pv->end(), core.attack_target) != pv->end(); return std::find(pv->begin(), pv->end(), core.attack_target) != pv->end();
else else
return (mcount == 0 || pcard->is_affected_by_effect(EFFECT_DIRECT_ATTACK) || core.attack_player) return (mcount == 0 || pcard->is_affected_by_effect(EFFECT_DIRECT_ATTACK) || core.attack_player)
&& !pcard->is_affected_by_effect(EFFECT_CANNOT_DIRECT_ATTACK) && dir; && !pcard->is_affected_by_effect(EFFECT_CANNOT_DIRECT_ATTACK) && dir;
} }
// update the validity for EFFECT_ATTACK_ALL (approximate solution) // update the validity for EFFECT_ATTACK_ALL (approximate solution)
......
...@@ -351,6 +351,7 @@ public: ...@@ -351,6 +351,7 @@ public:
int32 get_mzone_limit(uint8 playerid, uint8 uplayer, uint32 reason); int32 get_mzone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason); int32 get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
uint32 get_linked_zone(int32 playerid); uint32 get_linked_zone(int32 playerid);
void get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset);
int32 check_extra_link(int32 playerid); int32 check_extra_link(int32 playerid);
int32 check_extra_link(int32 playerid, card* pcard, int32 sequence); int32 check_extra_link(int32 playerid, card* pcard, int32 sequence);
void get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid); void get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid);
......
...@@ -45,6 +45,7 @@ static const struct luaL_Reg cardlib[] = { ...@@ -45,6 +45,7 @@ static const struct luaL_Reg cardlib[] = {
{ "GetLinkedGroup", scriptlib::card_get_linked_group }, { "GetLinkedGroup", scriptlib::card_get_linked_group },
{ "GetLinkedGroupCount", scriptlib::card_get_linked_group_count }, { "GetLinkedGroupCount", scriptlib::card_get_linked_group_count },
{ "GetLinkedZone", scriptlib::card_get_linked_zone }, { "GetLinkedZone", scriptlib::card_get_linked_zone },
{ "IsLinkState", scriptlib::card_is_link_state },
{ "GetAttribute", scriptlib::card_get_attribute }, { "GetAttribute", scriptlib::card_get_attribute },
{ "GetOriginalAttribute", scriptlib::card_get_origin_attribute }, { "GetOriginalAttribute", scriptlib::card_get_origin_attribute },
{ "GetFusionAttribute", scriptlib::card_get_fusion_attribute }, { "GetFusionAttribute", scriptlib::card_get_fusion_attribute },
...@@ -413,6 +414,8 @@ static const struct luaL_Reg duellib[] = { ...@@ -413,6 +414,8 @@ static const struct luaL_Reg duellib[] = {
{ "GetLocationCount", scriptlib::duel_get_location_count }, { "GetLocationCount", scriptlib::duel_get_location_count },
{ "GetLocationCountFromEx", scriptlib::duel_get_location_count_fromex }, { "GetLocationCountFromEx", scriptlib::duel_get_location_count_fromex },
{ "GetUsableMZoneCount", scriptlib::duel_get_usable_mzone_count }, { "GetUsableMZoneCount", scriptlib::duel_get_usable_mzone_count },
{ "GetLinkedGroup", scriptlib::duel_get_linked_group },
{ "GetLinkedGroupCount", scriptlib::duel_get_linked_group_count },
{ "GetLinkedZone", scriptlib::duel_get_linked_zone }, { "GetLinkedZone", scriptlib::duel_get_linked_zone },
{ "GetFieldCard", scriptlib::duel_get_field_card }, { "GetFieldCard", scriptlib::duel_get_field_card },
{ "CheckLocation", scriptlib::duel_check_location }, { "CheckLocation", scriptlib::duel_check_location },
......
...@@ -297,6 +297,13 @@ int32 scriptlib::card_get_linked_zone(lua_State *L) { ...@@ -297,6 +297,13 @@ int32 scriptlib::card_get_linked_zone(lua_State *L) {
lua_pushinteger(L, pcard->get_linked_zone()); lua_pushinteger(L, pcard->get_linked_zone());
return 1; return 1;
} }
int32 scriptlib::card_is_link_state(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
lua_pushboolean(L, pcard->is_link_state());
return 1;
}
int32 scriptlib::card_get_attribute(lua_State *L) { int32 scriptlib::card_get_attribute(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 1);
......
...@@ -1588,6 +1588,33 @@ int32 scriptlib::duel_get_usable_mzone_count(lua_State *L) { ...@@ -1588,6 +1588,33 @@ int32 scriptlib::duel_get_usable_mzone_count(lua_State *L) {
lua_pushinteger(L, pduel->game_field->get_useable_count(playerid, LOCATION_MZONE, uplayer, LOCATION_REASON_TOFIELD, zone)); lua_pushinteger(L, pduel->game_field->get_useable_count(playerid, LOCATION_MZONE, uplayer, LOCATION_REASON_TOFIELD, zone));
return 1; return 1;
} }
int32 scriptlib::duel_get_linked_group(lua_State *L) {
check_param_count(L, 3);
uint32 rplayer = lua_tointeger(L, 1);
if(rplayer != 0 && rplayer != 1)
return 0;
uint32 s = lua_tointeger(L, 2);
uint32 o = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
field::card_set cset;
pduel->game_field->get_linked_cards(rplayer, s, o, &cset);
group* pgroup = pduel->new_group(cset);
interpreter::group2value(L, pgroup);
return 1;
}
int32 scriptlib::duel_get_linked_group_count(lua_State *L) {
check_param_count(L, 3);
uint32 rplayer = lua_tointeger(L, 1);
if(rplayer != 0 && rplayer != 1)
return 0;
uint32 s = lua_tointeger(L, 2);
uint32 o = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
field::card_set cset;
pduel->game_field->get_linked_cards(rplayer, s, o, &cset);
lua_pushinteger(L, cset.size());
return 1;
}
int32 scriptlib::duel_get_linked_zone(lua_State *L) { int32 scriptlib::duel_get_linked_zone(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
uint32 playerid = lua_tointeger(L, 1); uint32 playerid = lua_tointeger(L, 1);
......
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
static int32 card_get_linked_group(lua_State *L); static int32 card_get_linked_group(lua_State *L);
static int32 card_get_linked_group_count(lua_State *L); static int32 card_get_linked_group_count(lua_State *L);
static int32 card_get_linked_zone(lua_State *L); static int32 card_get_linked_zone(lua_State *L);
static int32 card_is_link_state(lua_State *L);
static int32 card_get_attribute(lua_State *L); static int32 card_get_attribute(lua_State *L);
static int32 card_get_origin_attribute(lua_State *L); static int32 card_get_origin_attribute(lua_State *L);
static int32 card_get_fusion_attribute(lua_State *L); static int32 card_get_fusion_attribute(lua_State *L);
...@@ -410,6 +411,8 @@ public: ...@@ -410,6 +411,8 @@ public:
static int32 duel_get_location_count(lua_State *L); static int32 duel_get_location_count(lua_State *L);
static int32 duel_get_location_count_fromex(lua_State *L); static int32 duel_get_location_count_fromex(lua_State *L);
static int32 duel_get_usable_mzone_count(lua_State *L); static int32 duel_get_usable_mzone_count(lua_State *L);
static int32 duel_get_linked_group(lua_State *L);
static int32 duel_get_linked_group_count(lua_State *L);
static int32 duel_get_linked_zone(lua_State *L); static int32 duel_get_linked_zone(lua_State *L);
static int32 duel_get_field_card(lua_State *L); static int32 duel_get_field_card(lua_State *L);
static int32 duel_check_location(lua_State *L); static int32 duel_check_location(lua_State *L);
......
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