Commit d4e39064 authored by DailyShana's avatar DailyShana

refactor

parent 8ec990d5
...@@ -3281,6 +3281,60 @@ int32 field::check_cteffect_hint(effect* peffect, uint8 playerid) { ...@@ -3281,6 +3281,60 @@ int32 field::check_cteffect_hint(effect* peffect, uint8 playerid) {
} }
return FALSE; return FALSE;
} }
int32 field::check_deck_effect(chain& ch) const {
effect* peffect = ch.triggering_effect;
card* phandler = peffect->get_handler();
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)
&& ch.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)) {
ch.flag |= CHAIN_DECK_EFFECT;
} else
return FALSE;
}
return TRUE;
}
int32 field::check_hand_trigger(chain& ch) {
effect* peffect = ch.triggering_effect;
card* phandler = peffect->get_handler();
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)
&& ((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE)
&& phandler->is_has_relation(ch) && ch.triggering_location == LOCATION_HAND
|| (peffect->range & LOCATION_HAND))) {
ch.flag |= CHAIN_HAND_TRIGGER;
core.new_ochain_h.push_back(ch);
if(ch.triggering_location == LOCATION_HAND && phandler->is_position(POS_FACEDOWN)
|| peffect->range && !peffect->in_range(ch))
return FALSE;
}
return TRUE;
}
int32 field::check_trigger_effect(const chain& ch) const {
effect* peffect = ch.triggering_effect;
card* phandler = peffect->get_handler();
if((peffect->type & EFFECT_TYPE_FIELD) && !phandler->is_has_relation(ch))
return FALSE;
if(peffect->code == EVENT_FLIP && infos.phase == PHASE_DAMAGE)
return TRUE;
if((ch.triggering_location & (LOCATION_DECK | LOCATION_HAND | LOCATION_EXTRA))
&& (ch.triggering_position & POS_FACEDOWN))
return TRUE;
if(!(phandler->current.location & (LOCATION_DECK | LOCATION_HAND | LOCATION_EXTRA))
|| phandler->is_position(POS_FACEUP))
return TRUE;
return FALSE;
}
int32 field::check_spself_from_hand_trigger(const chain& ch) const {
effect* peffect = ch.triggering_effect;
uint8 tp = ch.triggering_player;
if((peffect->status & EFFECT_STATUS_SPSELF) && (ch.flag & CHAIN_HAND_TRIGGER)) {
return std::none_of(core.current_chain.begin(), core.current_chain.end(), [tp](chain ch) {
return ch.triggering_player == tp
&& (ch.triggering_effect->status & EFFECT_STATUS_SPSELF) && (ch.flag & CHAIN_HAND_TRIGGER);
});
}
return TRUE;
}
int32 field::is_able_to_enter_bp() { int32 field::is_able_to_enter_bp() {
return ((core.duel_options & DUEL_ATTACK_FIRST_TURN) || infos.turn_id != 1) return ((core.duel_options & DUEL_ATTACK_FIRST_TURN) || infos.turn_id != 1)
&& infos.phase < PHASE_BATTLE_START && infos.phase < PHASE_BATTLE_START
......
...@@ -469,6 +469,10 @@ public: ...@@ -469,6 +469,10 @@ public:
int32 get_cteffect(effect* peffect, int32 playerid, int32 store); int32 get_cteffect(effect* peffect, int32 playerid, int32 store);
int32 get_cteffect_evt(effect* feffect, int32 playerid, const tevent& e, int32 store); int32 get_cteffect_evt(effect* feffect, int32 playerid, const tevent& e, int32 store);
int32 check_cteffect_hint(effect* peffect, uint8 playerid); int32 check_cteffect_hint(effect* peffect, uint8 playerid);
int32 check_deck_effect(chain& ch) const;
int32 check_hand_trigger(chain& ch);
int32 check_trigger_effect(const chain& ch) const;
int32 check_spself_from_hand_trigger(const chain& ch) const;
int32 is_able_to_enter_bp(); int32 is_able_to_enter_bp();
void add_process(uint16 type, uint16 step, effect* peffect, group* target, ptr arg1, ptr arg2, ptr arg3 = 0, ptr arg4 = 0, void* ptr1 = NULL, void* ptr2 = NULL); void add_process(uint16 type, uint16 step, effect* peffect, group* target, ptr arg1, ptr arg2, ptr arg3 = 0, ptr arg4 = 0, void* ptr1 = NULL, void* ptr2 = NULL);
......
...@@ -1670,27 +1670,11 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free ...@@ -1670,27 +1670,11 @@ 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(); ) { for (auto clit = core.new_fchain_s.begin(); clit != core.new_fchain_s.end(); ) {
effect* peffect = clit->triggering_effect; effect* peffect = clit->triggering_effect;
card* phandler = peffect->get_handler(); card* phandler = peffect->get_handler();
if(phandler->is_has_relation(*clit)) if(phandler->is_has_relation(*clit)) //work around: position and control should be refreshed before raising event
clit->set_triggering_place(phandler); clit->set_triggering_place(phandler);
uint8 tp = clit->triggering_player; uint8 tp = clit->triggering_player;
bool act = true; if(check_deck_effect(*clit) && check_trigger_effect(*clit)
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && peffect->is_chainable(tp) && peffect->is_activateable(tp, clit->evt, TRUE)) {
&& 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))) {
} else
act = false;
if(act) {
if(tp == core.current_player) if(tp == core.current_player)
core.select_chains.push_back(*clit); core.select_chains.push_back(*clit);
} else { } else {
...@@ -1736,7 +1720,7 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free ...@@ -1736,7 +1720,7 @@ 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(); ) { for (auto clit = core.new_ochain_s.begin(); clit != core.new_ochain_s.end(); ) {
effect* peffect = clit->triggering_effect; effect* peffect = clit->triggering_effect;
card* phandler = peffect->get_handler(); card* phandler = peffect->get_handler();
if(phandler->is_has_relation(*clit)) if(phandler->is_has_relation(*clit)) //work around: position and control should be refreshed before raising event
clit->set_triggering_place(phandler); clit->set_triggering_place(phandler);
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && (peffect->type & EFFECT_TYPE_FIELD) if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && (peffect->type & EFFECT_TYPE_FIELD)
&& (peffect->range & LOCATION_HAND) && phandler->current.location == LOCATION_HAND) { && (peffect->range & LOCATION_HAND) && phandler->current.location == LOCATION_HAND) {
...@@ -1747,44 +1731,9 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free ...@@ -1747,44 +1731,9 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
clit->set_triggering_place(phandler); clit->set_triggering_place(phandler);
} }
uint8 tp = clit->triggering_player; uint8 tp = clit->triggering_player;
bool act = true; if(check_hand_trigger(*clit) && check_deck_effect(*clit) && check_trigger_effect(*clit)
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) && peffect->is_chainable(tp) && peffect->is_activateable(tp, clit->evt, TRUE)
&& ((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE) && check_spself_from_hand_trigger(*clit)) {
&& 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) || !(peffect->type & EFFECT_TYPE_FIELD) || peffect->in_range(*clit)) {
if((peffect->status & EFFECT_STATUS_SPSELF) && (clit->flag & CHAIN_HAND_TRIGGER)) {
for(const auto& cur_ch : core.current_chain) {
if(cur_ch.triggering_player == tp
&& (cur_ch.triggering_effect->status & EFFECT_STATUS_SPSELF) && (cur_ch.flag & CHAIN_HAND_TRIGGER)) {
act = false;
break;
}
}
}
} else
act = false;
} else act = false;
if(act) {
if(tp == core.current_player) if(tp == core.current_player)
core.select_chains.push_back(*clit); core.select_chains.push_back(*clit);
} else { } else {
...@@ -2082,22 +2031,10 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori ...@@ -2082,22 +2031,10 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori
ch.triggering_player = phandler->current.controler; ch.triggering_player = phandler->current.controler;
ch.set_triggering_place(phandler); ch.set_triggering_place(phandler);
} }
bool act = true;
if(ch.triggering_player == priority && ch.triggering_location == LOCATION_HAND if(ch.triggering_player == priority && ch.triggering_location == LOCATION_HAND
&& phandler->is_position(POS_FACEDOWN) && !phandler->is_status(STATUS_CHAINING) && phandler->is_has_relation(ch) && phandler->is_position(POS_FACEDOWN) && !phandler->is_status(STATUS_CHAINING) && phandler->is_has_relation(ch)
&& peffect->is_chainable(priority) && peffect->is_activateable(priority, ch.evt, TRUE)) { && peffect->is_chainable(priority) && peffect->is_activateable(priority, ch.evt, TRUE)
if(peffect->status & EFFECT_STATUS_SPSELF) { && check_spself_from_hand_trigger(ch))
for(const auto& cur_ch : core.current_chain) {
if(cur_ch.triggering_player == priority
&& (cur_ch.triggering_effect->status & EFFECT_STATUS_SPSELF) && (cur_ch.flag & CHAIN_HAND_TRIGGER)) {
act = false;
break;
}
}
}
} else
act = false;
if(act)
core.select_chains.push_back(ch); core.select_chains.push_back(ch);
} }
//delayed activate //delayed activate
......
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