Commit e7572c70 authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:Fluorohydride/ygopro-core

parents 5af3f8ab dcfb08ce
......@@ -1690,7 +1690,6 @@ void card::enable_field_effect(bool enabled) {
reset(RESET_DISABLE, RESET_EVENT);
} else
set_status(STATUS_EFFECT_ENABLED, FALSE);
filter_immune_effect();
if (get_status(STATUS_DISABLED | STATUS_FORBIDDEN))
return;
filter_disable_related_cards();
......@@ -2081,26 +2080,17 @@ void card::reset_effect_count() {
// refresh STATUS_DISABLED based on EFFECT_DISABLE and EFFECT_CANNOT_DISABLE
// refresh STATUS_FORBIDDEN based on EFFECT_FORBIDDEN
void card::refresh_disable_status() {
// forbidden
int32 pre_fb = is_status(STATUS_FORBIDDEN);
filter_immune_effect();
// forbidden
if (is_affected_by_effect(EFFECT_FORBIDDEN))
set_status(STATUS_FORBIDDEN, TRUE);
else
set_status(STATUS_FORBIDDEN, FALSE);
int32 cur_fb = is_status(STATUS_FORBIDDEN);
if(pre_fb != cur_fb)
filter_immune_effect();
// disabled
int32 pre_dis = is_status(STATUS_DISABLED);
filter_immune_effect();
if (!is_affected_by_effect(EFFECT_CANNOT_DISABLE) && is_affected_by_effect(EFFECT_DISABLE))
set_status(STATUS_DISABLED, TRUE);
else
set_status(STATUS_DISABLED, FALSE);
int32 cur_dis = is_status(STATUS_DISABLED);
if(pre_dis != cur_dis)
filter_immune_effect();
}
std::tuple<uint8, effect*> card::refresh_control_status() {
uint8 final = owner;
......@@ -2488,44 +2478,40 @@ void card::filter_single_continuous_effect(int32 code, effect_set* eset, uint8 s
}
// refresh this->immune_effect
void card::filter_immune_effect() {
effect* peffect;
immune_effect.clear();
auto rg = single_effect.equal_range(EFFECT_IMMUNE_EFFECT);
for (; rg.first != rg.second; ++rg.first) {
peffect = rg.first->second;
if (peffect->is_available())
effect* peffect = rg.first->second;
immune_effect.add_item(peffect);
}
for (auto& pcard : equiping_cards) {
rg = pcard->equip_effect.equal_range(EFFECT_IMMUNE_EFFECT);
for (; rg.first != rg.second; ++rg.first) {
peffect = rg.first->second;
if (peffect->is_available())
effect* peffect = rg.first->second;
immune_effect.add_item(peffect);
}
}
for (auto& pcard : effect_target_owner) {
rg = pcard->target_effect.equal_range(EFFECT_IMMUNE_EFFECT);
for (; rg.first != rg.second; ++rg.first) {
peffect = rg.first->second;
if(peffect->is_target(this) && peffect->is_available())
effect* peffect = rg.first->second;
if(peffect->is_target(this))
immune_effect.add_item(peffect);
}
}
for (auto& pcard : xyz_materials) {
rg = pcard->xmaterial_effect.equal_range(EFFECT_IMMUNE_EFFECT);
for (; rg.first != rg.second; ++rg.first) {
peffect = rg.first->second;
effect* peffect = rg.first->second;
if (peffect->type & EFFECT_TYPE_FIELD)
continue;
if (peffect->is_available())
immune_effect.add_item(peffect);
}
}
rg = pduel->game_field->effects.aura_effect.equal_range(EFFECT_IMMUNE_EFFECT);
for (; rg.first != rg.second; ++rg.first) {
peffect = rg.first->second;
if (peffect->is_target(this) && peffect->is_available())
effect* peffect = rg.first->second;
if (peffect->is_target(this))
immune_effect.add_item(peffect);
}
immune_effect.sort();
......@@ -2740,7 +2726,7 @@ void card::filter_spsummon_procedure(uint8 playerid, effect_set* peset, uint32 s
toplayer = playerid;
}
if(peffect->is_available() && peffect->check_count_limit(playerid) && is_spsummonable(peffect)
&& !pduel->game_field->check_unique_onfield(this, toplayer, LOCATION_MZONE)) {
&& ((topos & POS_FACEDOWN) || !pduel->game_field->check_unique_onfield(this, toplayer, LOCATION_MZONE))) {
effect* sumeffect = pduel->game_field->core.reason_effect;
if(!sumeffect)
sumeffect = peffect;
......@@ -3141,7 +3127,7 @@ int32 card::is_can_be_summoned(uint8 playerid, uint8 ignore_count, effect* peffe
effect_set proc;
int32 res = filter_summon_procedure(playerid, &proc, ignore_count, min_tribute, zone);
if(peffect) {
if(res < 0 || !pduel->game_field->is_player_can_summon(peffect->get_value(), playerid, this, playerid)) {
if(res < 0 || !check_summon_procedure(peffect, playerid, ignore_count, min_tribute, zone)) {
pduel->game_field->restore_lp_cost();
return FALSE;
}
......@@ -3279,7 +3265,9 @@ int32 card::is_can_be_special_summoned(effect* reason_effect, uint32 sumtype, ui
if((data.type & TYPE_PENDULUM) && current.location == LOCATION_EXTRA && (current.position & POS_FACEUP)
&& (sumtype == SUMMON_TYPE_FUSION || sumtype == SUMMON_TYPE_SYNCHRO || sumtype == SUMMON_TYPE_XYZ))
return FALSE;
if(((sumpos & POS_FACEDOWN) == 0) && pduel->game_field->check_unique_onfield(this, toplayer, LOCATION_MZONE))
if((sumpos & POS_FACEDOWN) && pduel->game_field->is_player_affected_by_effect(sumplayer, EFFECT_DEVINE_LIGHT))
sumpos = (sumpos & POS_FACEUP) | ((sumpos & POS_FACEDOWN) >> 1);
if(!(sumpos & POS_FACEDOWN) && pduel->game_field->check_unique_onfield(this, toplayer, LOCATION_MZONE))
return FALSE;
sumtype |= SUMMON_TYPE_SPECIAL;
if((sumplayer == 0 || sumplayer == 1) && !pduel->game_field->is_player_can_spsummon(reason_effect, sumtype, sumpos, sumplayer, toplayer, this))
......@@ -3339,7 +3327,7 @@ int32 card::is_setable_mzone(uint8 playerid, uint8 ignore_count, effect* peffect
effect_set eset;
int32 res = filter_set_procedure(playerid, &eset, ignore_count, min_tribute, zone);
if(peffect) {
if(res < 0 || !pduel->game_field->is_player_can_mset(peffect->get_value(), playerid, this, playerid)) {
if(res < 0 || !check_set_procedure(peffect, playerid, ignore_count, min_tribute, zone)) {
pduel->game_field->restore_lp_cost();
return FALSE;
}
......
......@@ -514,10 +514,10 @@ int32 effect::is_player_effect_target(card* pcard) {
return TRUE;
}
int32 effect::is_immuned(card* pcard) {
effect_set_v effects = pcard->immune_effect;
const effect_set_v& effects = pcard->immune_effect;
for (int32 i = 0; i < effects.size(); ++i) {
effect* peffect = effects.at(i);
if(peffect->value) {
effect* peffect = effects[i];
if(peffect->is_available() && peffect->value) {
pduel->lua->add_param(this, PARAM_TYPE_EFFECT);
pduel->lua->add_param(pcard, PARAM_TYPE_CARD);
if(peffect->check_value_condition(2))
......
......@@ -294,6 +294,7 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define EFFECT_DUAL_STATUS 75 //
#define EFFECT_EQUIP_LIMIT 76 //
#define EFFECT_DUAL_SUMMONABLE 77 //
#define EFFECT_UNION_LIMIT 78 //
#define EFFECT_REVERSE_DAMAGE 80 //
#define EFFECT_REVERSE_RECOVER 81 //
#define EFFECT_CHANGE_DAMAGE 82 //
......
......@@ -92,12 +92,21 @@ struct effect_set_v {
return;
std::sort(container.begin(), container.begin() + count, effect_sort_id);
}
effect* const& get_last() const {
return container[count - 1];
}
effect*& get_last() {
return container[count - 1];
}
effect* const& operator[] (int index) const {
return container[index];
}
effect*& operator[] (int index) {
return container[index];
}
effect* const& at(int index) const {
return container[index];
}
effect*& at(int index) {
return container[index];
}
......
......@@ -1949,38 +1949,35 @@ void field::update_disable_check_list(effect* peffect) {
add_to_disable_check_list(pcard);
}
void field::add_to_disable_check_list(card* pcard) {
auto result=effects.disable_check_set.insert(pcard);
auto result = effects.disable_check_set.insert(pcard);
if(!result.second)
return;
effects.disable_check_list.push_back(pcard);
}
void field::adjust_disable_check_list() {
card* checking;
int32 pre_disable, new_disable;
if (!effects.disable_check_list.size())
if(!effects.disable_check_list.size())
return;
card_set checked;
do {
checked.clear();
while (effects.disable_check_list.size()) {
checking = effects.disable_check_list.front();
card_set checked;
while(effects.disable_check_list.size()) {
card* checking = effects.disable_check_list.front();
effects.disable_check_list.pop_front();
effects.disable_check_set.erase(checking);
checked.insert(checking);
if (checking->is_status(STATUS_TO_ENABLE | STATUS_TO_DISABLE))
if(checking->is_status(STATUS_TO_ENABLE | STATUS_TO_DISABLE))
continue;
pre_disable = checking->get_status(STATUS_DISABLED | STATUS_FORBIDDEN);
int32 pre_disable = checking->get_status(STATUS_DISABLED | STATUS_FORBIDDEN);
checking->refresh_disable_status();
new_disable = checking->get_status(STATUS_DISABLED | STATUS_FORBIDDEN);
if (pre_disable != new_disable && checking->is_status(STATUS_EFFECT_ENABLED)) {
int32 new_disable = checking->get_status(STATUS_DISABLED | STATUS_FORBIDDEN);
if(pre_disable != new_disable && checking->is_status(STATUS_EFFECT_ENABLED)) {
checking->filter_disable_related_cards();
if (pre_disable)
if(pre_disable)
checking->set_status(STATUS_TO_ENABLE, TRUE);
else
checking->set_status(STATUS_TO_DISABLE, TRUE);
}
}
for (auto& pcard : checked) {
for(auto& pcard : checked) {
if(pcard->is_status(STATUS_DISABLED) && pcard->is_status(STATUS_TO_DISABLE) && !pcard->is_status(STATUS_TO_ENABLE))
pcard->reset(RESET_DISABLE, RESET_EVENT);
pcard->set_status(STATUS_TO_ENABLE | STATUS_TO_DISABLE, FALSE);
......
......@@ -1426,6 +1426,20 @@ int32 scriptlib::card_check_equip_target(lua_State *L) {
lua_pushboolean(L, 0);
return 1;
}
int32 scriptlib::card_check_union_target(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_CARD, 2);
card* pcard = *(card**) lua_touserdata(L, 1);
card* target = *(card**) lua_touserdata(L, 2);
if(pcard->is_affected_by_effect(EFFECT_UNION_LIMIT, target)
&& ((!pcard->is_affected_by_effect(EFFECT_OLDUNION_STATUS) || target->get_union_count() == 0)
&& (!pcard->is_affected_by_effect(EFFECT_UNION_STATUS) || target->get_old_union_count() == 0)))
lua_pushboolean(L, 1);
else
lua_pushboolean(L, 0);
return 1;
}
int32 scriptlib::card_get_union_count(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
......@@ -3389,6 +3403,7 @@ static const struct luaL_Reg cardlib[] = {
{ "GetEquipTarget", scriptlib::card_get_equip_target },
{ "GetPreviousEquipTarget", scriptlib::card_get_pre_equip_target },
{ "CheckEquipTarget", scriptlib::card_check_equip_target },
{ "CheckUnionTarget", scriptlib::card_check_union_target },
{ "GetUnionCount", scriptlib::card_get_union_count },
{ "GetOverlayGroup", scriptlib::card_get_overlay_group },
{ "GetOverlayCount", scriptlib::card_get_overlay_count },
......
......@@ -467,32 +467,33 @@ int32 field::damage(uint16 step, effect* reason_effect, uint32 reason, uint8 rea
}
}
}
uint32 val = amount;
eset.clear();
filter_player_effect(playerid, EFFECT_CHANGE_DAMAGE, &eset);
filter_player_effect(playerid, EFFECT_REFLECT_DAMAGE, &eset);
for(int32 i = 0; i < eset.size(); ++i) {
pduel->lua->add_param(reason_effect, PARAM_TYPE_EFFECT);
pduel->lua->add_param(amount, PARAM_TYPE_INT);
pduel->lua->add_param(reason, PARAM_TYPE_INT);
pduel->lua->add_param(reason_player, PARAM_TYPE_INT);
pduel->lua->add_param(reason_card, PARAM_TYPE_CARD);
val = eset[i]->get_value(5);
returns.ivalue[0] = val;
if(val == 0)
return TRUE;
if (eset[i]->check_value_condition(5)) {
playerid = 1 - playerid;
core.units.begin()->arg2 |= 1 << 29;
break;
}
}
uint32 val = amount;
eset.clear();
filter_player_effect(playerid, EFFECT_REFLECT_DAMAGE, &eset);
filter_player_effect(playerid, EFFECT_CHANGE_DAMAGE, &eset);
for(int32 i = 0; i < eset.size(); ++i) {
pduel->lua->add_param(reason_effect, PARAM_TYPE_EFFECT);
pduel->lua->add_param(val, PARAM_TYPE_INT);
pduel->lua->add_param(reason, PARAM_TYPE_INT);
pduel->lua->add_param(reason_player, PARAM_TYPE_INT);
pduel->lua->add_param(reason_card, PARAM_TYPE_CARD);
if(eset[i]->check_value_condition(5)) {
core.units.begin()->arg2 |= 1 << 29;
break;
}
val = eset[i]->get_value(5);
returns.ivalue[0] = val;
if(val == 0)
return TRUE;
}
core.units.begin()->arg2 = (core.units.begin()->arg2 & 0xff000000) | (val & 0xffffff);
if(is_step) {
......@@ -1390,6 +1391,10 @@ int32 field::self_destroy(uint16 step, card* ucard, int32 p) {
int32 field::trap_monster_adjust(uint16 step) {
switch(step) {
case 0: {
if(core.duel_rule <= 4) {
core.units.begin()->step = 3;
return FALSE;
}
card_set* to_grave_set = new card_set;
core.units.begin()->ptr1 = to_grave_set;
return FALSE;
......@@ -1444,14 +1449,17 @@ int32 field::trap_monster_adjust(uint16 step) {
for(uint8 p = 0; p < 2; ++p) {
for(auto& pcard : core.trap_monster_adjust_set[tp]) {
pcard->reset(RESET_TURN_SET, RESET_EVENT);
if(core.duel_rule <= 4)
refresh_location_info_instant();
move_to_field(pcard, tp, tp, LOCATION_SZONE, pcard->current.position, FALSE, 2);
}
tp = 1 - tp;
}
card_set* to_grave_set = (card_set*)core.units.begin()->ptr1;
if(card_set* to_grave_set = (card_set*)core.units.begin()->ptr1) {
if(to_grave_set->size())
send_to(to_grave_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
delete to_grave_set;
}
return TRUE;
}
}
......@@ -1572,7 +1580,7 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
effect_set eset;
int32 res = target->filter_summon_procedure(sumplayer, &eset, ignore_count, min_tribute, zone);
if(proc) {
if(res < 0)
if(res < 0 || !target->check_summon_procedure(proc, sumplayer, ignore_count, min_tribute, zone))
return TRUE;
} else {
if(res == -2)
......@@ -1613,23 +1621,10 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
core.units.begin()->ptr1 = 0;
return FALSE;
}
if(proc) {
core.units.begin()->step = 3;
if(!ignore_count && !core.extra_summon[sumplayer]) {
for(int32 i = 0; i < eset.size(); ++i) {
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
if(retval.size() < 2) {
core.units.begin()->ptr1 = eset[i];
return FALSE;
}
}
}
core.units.begin()->ptr1 = 0;
return FALSE;
}
effect* proc = core.select_effects[returns.ivalue[0]];
if(!proc) {
proc = core.select_effects[returns.ivalue[0]];
core.units.begin()->peffect = proc;
}
core.select_effects.clear();
core.select_options.clear();
if(ignore_count || core.summon_count[sumplayer] < get_summon_count_limit(sumplayer)) {
......@@ -2155,7 +2150,7 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint
effect_set eset;
int32 res = target->filter_set_procedure(setplayer, &eset, ignore_count, min_tribute, zone);
if(proc) {
if(res < 0)
if(res < 0 || !target->check_set_procedure(proc, setplayer, ignore_count, min_tribute, zone))
return TRUE;
} else {
if(res == -2)
......@@ -2181,23 +2176,10 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint
case 1: {
effect_set eset;
target->filter_effect(EFFECT_EXTRA_SET_COUNT, &eset);
if(proc) {
core.units.begin()->step = 3;
if(!ignore_count && !core.extra_summon[setplayer]) {
for(int32 i = 0; i < eset.size(); ++i) {
std::vector<int32> retval;
eset[i]->get_value(target, 0, &retval);
if(retval.size() < 2) {
core.units.begin()->ptr1 = eset[i];
return FALSE;
}
}
}
core.units.begin()->ptr1 = 0;
return FALSE;
}
effect* proc = core.select_effects[returns.ivalue[0]];
if(!proc) {
proc = core.select_effects[returns.ivalue[0]];
core.units.begin()->peffect = proc;
}
core.select_effects.clear();
core.select_options.clear();
if(ignore_count || core.summon_count[setplayer] < get_summon_count_limit(setplayer)) {
......@@ -3155,7 +3137,7 @@ int32 field::special_summon_step(uint16 step, group* targets, card* target, uint
}
}
if((target->current.location == LOCATION_MZONE)
|| check_unique_onfield(target, playerid, LOCATION_MZONE)
|| !(positions & POS_FACEDOWN) && check_unique_onfield(target, playerid, LOCATION_MZONE)
|| !is_player_can_spsummon(core.reason_effect, target->summon_info & 0xff00ffff, positions, target->summon_player, playerid, target)
|| (!nocheck && !(target->data.type & TYPE_MONSTER))) {
core.units.begin()->step = 4;
......@@ -4525,7 +4507,7 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret,
uint32 flag;
uint32 lreason = (target->current.location == LOCATION_MZONE) ? LOCATION_REASON_CONTROL : LOCATION_REASON_TOFIELD;
int32 ct = get_useable_count(target, playerid, location, move_player, lreason, zone, &flag);
if((ret == 1) && (ct <= 0 || target->is_status(STATUS_FORBIDDEN) || check_unique_onfield(target, playerid, location))) {
if((ret == 1) && (ct <= 0 || target->is_status(STATUS_FORBIDDEN) || !(positions & POS_FACEDOWN) && check_unique_onfield(target, playerid, location))) {
core.units.begin()->step = 3;
send_to(target, core.reason_effect, REASON_RULE, core.reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, 0);
return FALSE;
......
......@@ -158,6 +158,7 @@ public:
static int32 card_get_equip_target(lua_State *L);
static int32 card_get_pre_equip_target(lua_State *L);
static int32 card_check_equip_target(lua_State *L);
static int32 card_check_union_target(lua_State *L);
static int32 card_get_union_count(lua_State *L);
static int32 card_get_overlay_group(lua_State *L);
static int32 card_get_overlay_count(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