Commit ae8adc53 authored by mercury233's avatar mercury233
parents fdc826fa 13e0a39e
......@@ -268,7 +268,7 @@ int32 effect::is_activateable(uint8 playerid, const tevent& e, int32 neglect_con
}
if(phandler->current.location == LOCATION_OVERLAY)
return FALSE;
if((type & EFFECT_TYPE_FIELD) && (phandler->current.controler != playerid) && !is_flag(EFFECT_FLAG_BOTH_SIDE))
if((type & EFFECT_TYPE_FIELD) && (phandler->current.controler != playerid) && !is_flag(EFFECT_FLAG_BOTH_SIDE | EFFECT_FLAG_EVENT_PLAYER))
return FALSE;
if(phandler->is_status(STATUS_FORBIDDEN))
return FALSE;
......
......@@ -184,14 +184,14 @@ enum effect_flag : uint32 {
EFFECT_FLAG_OWNER_RELATE = 0x1000000,
EFFECT_FLAG_AVAILABLE_BD = 0x2000000,
EFFECT_FLAG_CLIENT_HINT = 0x4000000,
EFFECT_FLAG_CHAIN_UNIQUE = 0x8000000,
// EFFECT_FLAG_CHAIN_UNIQUE = 0x8000000,
// EFFECT_FLAG_NAGA = 0x10000000,
// EFFECT_FLAG_COF = 0x20000000,
EFFECT_FLAG_CVAL_CHECK = 0x40000000,
// EFFECT_FLAG_CVAL_CHECK = 0x40000000,
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
};
enum effect_flag2 : uint32 {
EFFECT_FLAG2_NAGA = 0x0001,
// EFFECT_FLAG2_NAGA = 0x0001,
EFFECT_FLAG2_COF = 0x0002,
};
inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
......
......@@ -609,6 +609,8 @@ public:
#define CHAIN_HAND_EFFECT 0x04
#define CHAIN_CONTINUOUS_CARD 0x08
#define CHAIN_ACTIVATING 0x10
#define CHAIN_HAND_TRIGGER 0x20
#define CHAIN_DECK_EFFECT 0x40
#define CHAININFO_CHAIN_COUNT 0x01
#define CHAININFO_TRIGGERING_EFFECT 0x02
#define CHAININFO_TRIGGERING_PLAYER 0x04
......
......@@ -3619,44 +3619,30 @@ int32 scriptlib::duel_is_chain_negatable(lua_State * L) {
check_param_count(L, 1);
int32 chaincount = lua_tointeger(L, 1);
duel* pduel = interpreter::get_duel_info(L);
int32 res = 0;
if(chaincount < 0 || chaincount > (int32)pduel->game_field->core.current_chain.size())
res = FALSE;
else {
effect* peffect;
if(chaincount == 0)
peffect = pduel->game_field->core.current_chain.back().triggering_effect;
else
peffect = pduel->game_field->core.current_chain[chaincount - 1].triggering_effect;
if(peffect->is_flag(EFFECT_FLAG2_NAGA))
res = FALSE;
chain* ch = pduel->game_field->get_chain(chaincount);
if(!ch)
return 0;
if(ch->flag & CHAIN_DECK_EFFECT)
lua_pushboolean(L, 0);
else
res = TRUE;
}
lua_pushboolean(L, res);
lua_pushboolean(L, 1);
return 1;
}
int32 scriptlib::duel_is_chain_disablable(lua_State * L) {
check_param_count(L, 1);
int32 chaincount = lua_tointeger(L, 1);
duel* pduel = interpreter::get_duel_info(L);
int32 res = 0;
if(chaincount < 0 || chaincount > (int32)pduel->game_field->core.current_chain.size())
res = FALSE;
else {
effect* peffect;
if(chaincount == 0)
peffect = pduel->game_field->core.current_chain.back().triggering_effect;
else
peffect = pduel->game_field->core.current_chain[chaincount - 1].triggering_effect;
if(peffect->is_flag(EFFECT_FLAG2_NAGA))
res = FALSE;
else
res = TRUE;
if(pduel->game_field->core.chain_solving)
res = pduel->game_field->is_chain_disablable(chaincount);
if(pduel->game_field->core.chain_solving) {
lua_pushboolean(L, pduel->game_field->is_chain_disablable(chaincount));
return 1;
}
lua_pushboolean(L, res);
chain* ch = pduel->game_field->get_chain(chaincount);
if(!ch)
return 0;
if(ch->flag & CHAIN_DECK_EFFECT)
lua_pushboolean(L, 0);
else
lua_pushboolean(L, 1);
return 1;
}
int32 scriptlib::duel_check_chain_target(lua_State *L) {
......
......@@ -29,7 +29,7 @@ int32 field::negate_chain(uint8 chaincount) {
}
pduel->write_buffer8(MSG_CHAIN_NEGATED);
pduel->write_buffer8(chaincount);
if(pchain.triggering_effect->is_flag(EFFECT_FLAG2_NAGA))
if(pchain.flag & CHAIN_DECK_EFFECT)
return FALSE;
return TRUE;
}
......@@ -48,7 +48,7 @@ int32 field::disable_chain(uint8 chaincount) {
core.current_chain[chaincount - 1].disable_player = core.reason_player;
pduel->write_buffer8(MSG_CHAIN_DISABLED);
pduel->write_buffer8(chaincount);
if(pchain.triggering_effect->is_flag(EFFECT_FLAG2_NAGA))
if(pchain.flag & CHAIN_DECK_EFFECT)
return FALSE;
return TRUE;
}
......@@ -3984,12 +3984,14 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
}
for(auto cit = param->targets->container.begin(); cit != param->targets->container.end(); ++cit) {
card* pcard = *cit;
if(!(pcard->data.type & TYPE_TOKEN))
pcard->enable_field_effect(true);
uint8 nloc = pcard->current.location;
if(nloc == LOCATION_HAND)
pcard->reset(RESET_TOHAND, RESET_EVENT);
else if(nloc == LOCATION_DECK || nloc == LOCATION_EXTRA)
if(nloc == LOCATION_DECK || nloc == LOCATION_EXTRA)
pcard->reset(RESET_TODECK, RESET_EVENT);
else if(nloc == LOCATION_GRAVE)
if(nloc == LOCATION_GRAVE)
pcard->reset(RESET_TOGRAVE, RESET_EVENT);
if(nloc == LOCATION_REMOVED || ((pcard->data.type & TYPE_TOKEN) && pcard->sendto_param.location == LOCATION_REMOVED)) {
if(pcard->current.reason & REASON_TEMPORARY)
......@@ -4036,15 +4038,15 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
}
}
pcard->clear_card_target();
if(!(pcard->data.type & TYPE_TOKEN)) {
pcard->enable_field_effect(true);
if(nloc == LOCATION_HAND) {
tohand.insert(pcard);
raise_single_event(pcard, 0, EVENT_TO_HAND, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
} else if(nloc == LOCATION_DECK || nloc == LOCATION_EXTRA) {
}
if(nloc == LOCATION_DECK || nloc == LOCATION_EXTRA) {
todeck.insert(pcard);
raise_single_event(pcard, 0, EVENT_TO_DECK, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
} else if(nloc == LOCATION_GRAVE) {
}
if(nloc == LOCATION_GRAVE) {
if(pcard->current.reason & REASON_RETURN) {
retgrave.insert(pcard);
raise_single_event(pcard, 0, EVENT_RETURN_TO_GRAVE, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
......@@ -4053,7 +4055,6 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
raise_single_event(pcard, 0, EVENT_TO_GRAVE, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
}
}
}
if(nloc == LOCATION_REMOVED || ((pcard->data.type & TYPE_TOKEN) && pcard->sendto_param.location == LOCATION_REMOVED)) {
remove.insert(pcard);
raise_single_event(pcard, 0, EVENT_REMOVE, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
......@@ -4328,6 +4329,7 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret,
&& !(peffect && (peffect->value & TYPE_TRAP)) && ret != 2)
resetflag |= RESET_MSCHANGE;
target->reset(resetflag, RESET_EVENT);
target->clear_card_target();
}
if(!(target->current.location & LOCATION_ONFIELD))
target->clear_relate_effect();
......@@ -4404,7 +4406,6 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret,
}
if((target->previous.location == LOCATION_SZONE) && target->equiping_target)
target->unequip();
target->clear_card_target();
if(target->current.location == LOCATION_MZONE) {
effect_set eset;
filter_player_effect(0, EFFECT_MUST_USE_MZONE, &eset, FALSE);
......
......@@ -1691,25 +1691,22 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
for (auto clit = core.new_fchain_s.begin(); clit != core.new_fchain_s.end(); ) {
effect* peffect = clit->triggering_effect;
card* phandler = peffect->get_handler();
if(!peffect->is_flag(EFFECT_FLAG_EVENT_PLAYER | EFFECT_FLAG_BOTH_SIDE) && phandler->is_has_relation(*clit)) {
clit->triggering_player = phandler->current.controler;
clit->set_triggering_place(phandler);
}
uint8 tp = clit->triggering_player;
bool act = true;
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)
&& clit->triggering_location == LOCATION_DECK && (phandler->current.location & LOCATION_DECK)) {
if((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE)
&& peffect->code == EVENT_TO_DECK || (peffect->range & LOCATION_DECK))
clit->flag |= CHAIN_DECK_EFFECT;
else
act = false;
}
if(peffect->is_chainable(tp) && peffect->is_activateable(tp, clit->evt, TRUE)
&& (!(peffect->type & EFFECT_TYPE_FIELD) || phandler->is_has_relation(*clit))
&& (peffect->code == EVENT_FLIP && infos.phase == PHASE_DAMAGE
|| (clit->triggering_location & 0x43) && (clit->triggering_position & POS_FACEDOWN)
|| !(phandler->current.location & 0x43) || phandler->is_position(POS_FACEUP))) {
if(peffect->is_flag(EFFECT_FLAG_CHAIN_UNIQUE)) {
for(auto tpit = core.current_chain.begin(); tpit != core.current_chain.end(); ++tpit) {
if(tpit->triggering_effect->get_handler()->data.code == phandler->data.code && tpit->triggering_player == tp) {
act = false;
break;
}
}
}
} else
act = false;
if(act) {
......@@ -1757,9 +1754,8 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
for (auto clit = core.new_ochain_s.begin(); clit != core.new_ochain_s.end(); ) {
effect* peffect = clit->triggering_effect;
card* phandler = peffect->get_handler();
if((!peffect->is_flag(EFFECT_FLAG_EVENT_PLAYER | EFFECT_FLAG_BOTH_SIDE) && phandler->is_has_relation(*clit))
|| (!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && (peffect->type & EFFECT_TYPE_FIELD)
&& (peffect->range & LOCATION_HAND) && phandler->current.location == LOCATION_HAND)) {
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && (peffect->type & EFFECT_TYPE_FIELD)
&& (peffect->range & LOCATION_HAND) && phandler->current.location == LOCATION_HAND) {
if(!phandler->is_has_relation(*clit))
phandler->create_relation(*clit);
clit->triggering_player = phandler->current.controler;
......@@ -1767,20 +1763,34 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
}
uint8 tp = clit->triggering_player;
bool act = true;
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)
&& ((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE)
&& phandler->is_has_relation(*clit) && clit->triggering_location == LOCATION_HAND
|| (peffect->range & LOCATION_HAND))) {
clit->flag |= CHAIN_HAND_TRIGGER;
core.new_ochain_h.push_back(*clit);
if(clit->triggering_location == LOCATION_HAND && phandler->is_position(POS_FACEDOWN)
|| peffect->range && !peffect->in_range(*clit))
act = false;
}
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)
&& clit->triggering_location == LOCATION_DECK && (phandler->current.location & LOCATION_DECK)) {
if((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE)
&& peffect->code == EVENT_TO_DECK || (peffect->range & LOCATION_DECK))
clit->flag |= CHAIN_DECK_EFFECT;
else
act = false;
}
if(peffect->is_chainable(tp) && peffect->is_activateable(tp, clit->evt, TRUE)
&& (!(peffect->type & EFFECT_TYPE_FIELD) || phandler->is_has_relation(*clit))
&& (peffect->code == EVENT_FLIP && infos.phase == PHASE_DAMAGE
|| (clit->triggering_location & 0x43) && (clit->triggering_position & POS_FACEDOWN)
|| !(phandler->current.location & 0x43) || phandler->is_position(POS_FACEUP))) {
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && clit->triggering_location == LOCATION_HAND
&& (((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE) && phandler->is_has_relation(*clit))
|| (peffect->range & LOCATION_HAND))) {
core.new_ochain_h.push_back(*clit);
act = false;
} else if(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) || !(peffect->type & EFFECT_TYPE_FIELD) || peffect->in_range(*clit)) {
if(peffect->is_flag(EFFECT_FLAG_CHAIN_UNIQUE)) {
if(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) || !(peffect->type & EFFECT_TYPE_FIELD) || peffect->in_range(*clit)) {
if((peffect->status & EFFECT_STATUS_SPSELF) && (clit->flag & CHAIN_HAND_TRIGGER)) {
for(auto tpit = core.current_chain.begin(); tpit != core.current_chain.end(); ++tpit) {
if(tpit->triggering_effect->get_handler()->data.code == phandler->data.code && tpit->triggering_player == tp) {
if(tpit->triggering_player == tp
&& (tpit->triggering_effect->status & EFFECT_STATUS_SPSELF) && (tpit->flag & CHAIN_HAND_TRIGGER)) {
act = false;
break;
}
......@@ -1837,6 +1847,7 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
core.new_chains.push_back(newchain);
add_process(PROCESSOR_ADD_CHAIN, 0, 0, 0, 0, 0);
core.new_ochain_s.remove_if([=](chain ch) { return ch.chain_id == newchain.chain_id; });
core.new_ochain_h.remove_if([=](chain ch) { return ch.chain_id == newchain.chain_id; });
core.units.begin()->step = 3;
return FALSE;
}
......@@ -1987,59 +1998,22 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori
core.ntpchain.clear();
if(!core.quick_f_chain.size())
return FALSE;
bool act = true;
for(auto ifit = core.quick_f_chain.begin(); ifit != core.quick_f_chain.end(); ++ifit) {
effect* peffect = ifit->first;
card* phandler = peffect->get_handler();
if(peffect->is_chainable(ifit->second.triggering_player) && peffect->check_count_limit(ifit->second.triggering_player)
&& phandler->is_has_relation(ifit->second)) {
if(ifit->second.triggering_player == infos.turn_player) {
act = true;
if(peffect->is_flag(EFFECT_FLAG_CHAIN_UNIQUE)) {
for (auto cait = core.tpchain.begin(); cait != core.tpchain.end(); ++cait) {
if (cait->triggering_effect->get_handler()->data.code == phandler->data.code) {
act = false;
break;
}
}
for (auto cait = core.current_chain.begin(); cait != core.current_chain.end(); ++cait) {
if ((cait->triggering_effect->get_handler()->data.code == phandler->data.code)
&& (cait->triggering_player == infos.turn_player)) {
act = false;
break;
}
}
}
if(act) {
core.tpchain.push_back(ifit->second);
phandler->set_status(STATUS_CHAINING, TRUE);
peffect->dec_count(infos.turn_player);
}
} else {
act = true;
if(peffect->is_flag(EFFECT_FLAG_CHAIN_UNIQUE)) {
for (auto cait = core.ntpchain.begin(); cait != core.ntpchain.end(); ++cait) {
if (cait->triggering_effect->get_handler()->data.code == phandler->data.code) {
act = false;
break;
}
}
for (auto cait = core.current_chain.begin(); cait != core.current_chain.end(); ++cait) {
if ((cait->triggering_effect->get_handler()->data.code == phandler->data.code)
&& (cait->triggering_player != infos.turn_player)) {
act = false;
break;
}
}
}
if(act) {
core.ntpchain.push_back(ifit->second);
phandler->set_status(STATUS_CHAINING, TRUE);
peffect->dec_count(1 - infos.turn_player);
}
}
}
}
core.quick_f_chain.clear();
if(core.tpchain.size() > 1)
add_process(PROCESSOR_SORT_CHAIN, 0, 0, 0, 1, infos.turn_player);
......@@ -2100,17 +2074,21 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori
for(auto clit = core.new_ochain_h.begin(); clit != core.new_ochain_h.end(); ++clit) {
effect* peffect = clit->triggering_effect;
card* phandler = peffect->get_handler();
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && (peffect->type & EFFECT_TYPE_FIELD)
&& (peffect->range & LOCATION_HAND) && phandler->current.location == LOCATION_HAND) {
if(!phandler->is_has_relation(*clit))
phandler->create_relation(*clit);
clit->triggering_player = phandler->current.controler;
clit->set_triggering_place(phandler);
}
bool act = true;
if(clit->triggering_player == priority && !phandler->is_status(STATUS_CHAINING) && phandler->is_has_relation(*clit)
if(clit->triggering_player == priority && clit->triggering_location == LOCATION_HAND
&& phandler->is_position(POS_FACEDOWN) && !phandler->is_status(STATUS_CHAINING) && phandler->is_has_relation(*clit)
&& peffect->is_chainable(priority) && peffect->is_activateable(priority, clit->evt, TRUE)) {
if(peffect->status & EFFECT_STATUS_SPSELF) {
for(auto cait = core.current_chain.begin(); cait != core.current_chain.end(); ++cait) {
if(cait->triggering_player == priority) {
if((peffect->status & EFFECT_STATUS_SPSELF) && (cait->triggering_effect->status & EFFECT_STATUS_SPSELF)
&& std::any_of(core.new_ochain_h.begin(), core.new_ochain_h.end(), [=](chain ch) { return ch.chain_id == cait->chain_id; })) {
act = false;
break;
}
if(peffect->is_flag(EFFECT_FLAG_CHAIN_UNIQUE) && cait->triggering_effect->get_handler()->data.code == phandler->data.code) {
if(cait->triggering_player == priority
&& (cait->triggering_effect->status & EFFECT_STATUS_SPSELF) && (cait->flag & CHAIN_HAND_TRIGGER)) {
act = false;
break;
}
......
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