Commit 9142ceb4 authored by fallenstardust's avatar fallenstardust

sync ocgcore

parent 3fd7a373
...@@ -484,8 +484,6 @@ uint32 card::get_link_type() { ...@@ -484,8 +484,6 @@ uint32 card::get_link_type() {
return data.type; return data.type;
return get_type(); return get_type();
} }
// Atk and def are sepcial cases since text atk/def ? are involved.
// Asuumption: we can only change the atk/def of cards in LOCATION_MZONE.
int32 card::get_base_attack() { int32 card::get_base_attack() {
if(!(data.type & TYPE_MONSTER) && !(get_type() & TYPE_MONSTER) && !is_affected_by_effect(EFFECT_PRE_MONSTER)) if(!(data.type & TYPE_MONSTER) && !(get_type() & TYPE_MONSTER) && !is_affected_by_effect(EFFECT_PRE_MONSTER))
return 0; return 0;
...@@ -870,10 +868,22 @@ int32 card::get_defense() { ...@@ -870,10 +868,22 @@ int32 card::get_defense() {
temp.defense = -1; temp.defense = -1;
return def; return def;
} }
// Level/Attribute/Race is available for: int32 card::get_battle_attack() {
// 1. cards with original type TYPE_MONSTER or effect_set eset;
// 2. cards with current type TYPE_MONSTER or filter_effect(EFFECT_SET_BATTLE_ATTACK, &eset);
// 3. cards with EFFECT_PRE_MONSTER if(eset.size())
return eset.get_last()->get_value(this);
else
return get_attack();
}
int32 card::get_battle_defense() {
effect_set eset;
filter_effect(EFFECT_SET_BATTLE_DEFENSE, &eset);
if(eset.size())
return eset.get_last()->get_value(this);
else
return get_defense();
}
uint32 card::get_level() { uint32 card::get_level() {
if((data.type & (TYPE_XYZ | TYPE_LINK)) || (status & STATUS_NO_LEVEL) if((data.type & (TYPE_XYZ | TYPE_LINK)) || (status & STATUS_NO_LEVEL)
|| (!(data.type & TYPE_MONSTER) && !(get_type() & TYPE_MONSTER) && !is_affected_by_effect(EFFECT_PRE_MONSTER))) || (!(data.type & TYPE_MONSTER) && !(get_type() & TYPE_MONSTER) && !is_affected_by_effect(EFFECT_PRE_MONSTER)))
...@@ -990,7 +1000,6 @@ uint32 card::check_xyz_level(card* pcard, uint32 lv) { ...@@ -990,7 +1000,6 @@ uint32 card::check_xyz_level(card* pcard, uint32 lv) {
} }
return 0; return 0;
} }
// see get_level()
uint32 card::get_attribute() { uint32 card::get_attribute() {
if(assume_type == ASSUME_ATTRIBUTE) if(assume_type == ASSUME_ATTRIBUTE)
return assume_value; return assume_value;
...@@ -1041,7 +1050,6 @@ uint32 card::get_link_attribute(uint8 playerid) { ...@@ -1041,7 +1050,6 @@ uint32 card::get_link_attribute(uint8 playerid) {
} }
return attribute; return attribute;
} }
// see get_level()
uint32 card::get_race() { uint32 card::get_race() {
if(assume_type == ASSUME_RACE) if(assume_type == ASSUME_RACE)
return assume_value; return assume_value;
......
...@@ -210,6 +210,8 @@ public: ...@@ -210,6 +210,8 @@ public:
int32 get_attack(); int32 get_attack();
int32 get_base_defense(); int32 get_base_defense();
int32 get_defense(); int32 get_defense();
int32 get_battle_attack();
int32 get_battle_defense();
uint32 get_level(); uint32 get_level();
uint32 get_rank(); uint32 get_rank();
uint32 get_link(); uint32 get_link();
......
...@@ -447,7 +447,7 @@ int32 effect::is_target(card* pcard) { ...@@ -447,7 +447,7 @@ int32 effect::is_target(card* pcard) {
if((type & EFFECT_TYPE_TARGET) && !(type & EFFECT_TYPE_FIELD)) { if((type & EFFECT_TYPE_TARGET) && !(type & EFFECT_TYPE_FIELD)) {
return is_fit_target_function(pcard); return is_fit_target_function(pcard);
} }
if(pcard && !is_flag(EFFECT_FLAG_SET_AVAILABLE) && (pcard->current.location & LOCATION_ONFIELD) if(!is_flag(EFFECT_FLAG_SET_AVAILABLE) && (pcard->current.location & LOCATION_ONFIELD)
&& !pcard->is_position(POS_FACEUP)) && !pcard->is_position(POS_FACEUP))
return FALSE; return FALSE;
if(!is_flag(EFFECT_FLAG_IGNORE_RANGE)) { if(!is_flag(EFFECT_FLAG_IGNORE_RANGE)) {
......
...@@ -448,6 +448,8 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2) ...@@ -448,6 +448,8 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define EFFECT_QP_ACT_IN_SET_TURN 359 #define EFFECT_QP_ACT_IN_SET_TURN 359
#define EFFECT_EXTRA_PENDULUM_SUMMON 360 #define EFFECT_EXTRA_PENDULUM_SUMMON 360
#define EFFECT_MATERIAL_LIMIT 361 #define EFFECT_MATERIAL_LIMIT 361
#define EFFECT_SET_BATTLE_ATTACK 362
#define EFFECT_SET_BATTLE_DEFENSE 363
#define EVENT_STARTUP 1000 #define EVENT_STARTUP 1000
#define EVENT_FLIP 1001 #define EVENT_FLIP 1001
...@@ -514,7 +516,6 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2) ...@@ -514,7 +516,6 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define EVENT_LEVEL_UP 1200 #define EVENT_LEVEL_UP 1200
#define EVENT_PAY_LPCOST 1201 #define EVENT_PAY_LPCOST 1201
#define EVENT_DETACH_MATERIAL 1202 #define EVENT_DETACH_MATERIAL 1202
#define EVENT_RETURN_TO_GRAVE 1203
#define EVENT_TURN_END 1210 #define EVENT_TURN_END 1210
#define EVENT_PHASE 0x1000 #define EVENT_PHASE 0x1000
#define EVENT_PHASE_START 0x2000 #define EVENT_PHASE_START 0x2000
......
...@@ -3344,16 +3344,17 @@ int32 field::check_cteffect_hint(effect* peffect, uint8 playerid) { ...@@ -3344,16 +3344,17 @@ int32 field::check_cteffect_hint(effect* peffect, uint8 playerid) {
} }
return FALSE; return FALSE;
} }
int32 field::check_hand_trigger(chain& ch) { int32 field::check_nonpublic_trigger(chain& ch) {
effect* peffect = ch.triggering_effect; effect* peffect = ch.triggering_effect;
card* phandler = peffect->get_handler(); card* phandler = peffect->get_handler();
if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY) if(!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)
&& ((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE) && ((peffect->type & EFFECT_TYPE_SINGLE) && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE)
&& phandler->is_has_relation(ch) && ch.triggering_location == LOCATION_HAND && phandler->is_has_relation(ch) && (ch.triggering_location & (LOCATION_HAND | LOCATION_DECK))
|| (peffect->range & LOCATION_HAND))) { || (peffect->range & (LOCATION_HAND | LOCATION_DECK)))) {
ch.flag |= CHAIN_HAND_TRIGGER; ch.flag |= CHAIN_HAND_TRIGGER;
core.new_ochain_h.push_back(ch); core.new_ochain_h.push_back(ch);
if(ch.triggering_location == LOCATION_HAND && phandler->is_position(POS_FACEDOWN) if(ch.triggering_location == LOCATION_HAND && phandler->is_position(POS_FACEDOWN)
|| ch.triggering_location == LOCATION_DECK
|| peffect->range && !peffect->in_range(ch)) || peffect->range && !peffect->in_range(ch))
return FALSE; return FALSE;
} }
......
...@@ -481,7 +481,7 @@ public: ...@@ -481,7 +481,7 @@ 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_hand_trigger(chain& ch); int32 check_nonpublic_trigger(chain& ch);
int32 check_trigger_effect(const chain& ch) const; int32 check_trigger_effect(const chain& ch) const;
int32 check_spself_from_hand_trigger(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();
......
...@@ -268,6 +268,8 @@ void field::send_to(card_set* targets, effect* reason_effect, uint32 reason, uin ...@@ -268,6 +268,8 @@ void field::send_to(card_set* targets, effect* reason_effect, uint32 reason, uin
p = reason_player; p = reason_player;
if(destination & (LOCATION_GRAVE | LOCATION_REMOVED) || p == PLAYER_NONE) if(destination & (LOCATION_GRAVE | LOCATION_REMOVED) || p == PLAYER_NONE)
p = pcard->owner; p = pcard->owner;
if(destination == LOCATION_GRAVE && pcard->current.location == LOCATION_REMOVED)
pcard->current.reason |= REASON_RETURN;
uint32 pos = position; uint32 pos = position;
if(destination != LOCATION_REMOVED) if(destination != LOCATION_REMOVED)
pos = POS_FACEUP; pos = POS_FACEUP;
...@@ -3768,7 +3770,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 ...@@ -3768,7 +3770,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
pduel->delete_group(targets); pduel->delete_group(targets);
return TRUE; return TRUE;
} }
card_set leave_p, destroying; card_set leave_p;
for(auto& pcard : targets->container) { for(auto& pcard : targets->container) {
if((pcard->current.location & LOCATION_ONFIELD) && !pcard->is_status(STATUS_SUMMON_DISABLED) && !pcard->is_status(STATUS_ACTIVATE_DISABLED)) { if((pcard->current.location & LOCATION_ONFIELD) && !pcard->is_status(STATUS_SUMMON_DISABLED) && !pcard->is_status(STATUS_ACTIVATE_DISABLED)) {
raise_single_event(pcard, 0, EVENT_LEAVE_FIELD_P, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0); raise_single_event(pcard, 0, EVENT_LEAVE_FIELD_P, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
...@@ -3816,8 +3818,6 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 ...@@ -3816,8 +3818,6 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
} }
if(leave_p.size()) if(leave_p.size())
raise_event(&leave_p, EVENT_LEAVE_FIELD_P, reason_effect, reason, reason_player, 0, 0); raise_event(&leave_p, EVENT_LEAVE_FIELD_P, reason_effect, reason, reason_player, 0, 0);
if(destroying.size())
raise_event(&destroying, EVENT_DESTROY, reason_effect, reason, reason_player, 0, 0);
process_single_event(); process_single_event();
process_instant_event(); process_instant_event();
return FALSE; return FALSE;
...@@ -4128,7 +4128,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 ...@@ -4128,7 +4128,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
core.units.begin()->ptarget = param->targets; core.units.begin()->ptarget = param->targets;
targets = param->targets; targets = param->targets;
delete param; delete param;
card_set tohand, todeck, tograve, remove, discard, released, destroyed, retgrave; card_set tohand, todeck, tograve, remove, discard, released, destroyed;
card_set equipings, overlays; card_set equipings, overlays;
for(auto& pcard : targets->container) { for(auto& pcard : targets->container) {
uint8 nloc = pcard->current.location; uint8 nloc = pcard->current.location;
...@@ -4161,14 +4161,9 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 ...@@ -4161,14 +4161,9 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
todeck.insert(pcard); todeck.insert(pcard);
raise_single_event(pcard, 0, EVENT_TO_DECK, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0); raise_single_event(pcard, 0, EVENT_TO_DECK, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
} }
if(nloc == LOCATION_GRAVE) { if(nloc == LOCATION_GRAVE && !(pcard->current.reason & REASON_RETURN)) {
if(pcard->current.reason & REASON_RETURN) { tograve.insert(pcard);
retgrave.insert(pcard); raise_single_event(pcard, 0, EVENT_TO_GRAVE, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
raise_single_event(pcard, 0, EVENT_RETURN_TO_GRAVE, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
} else {
tograve.insert(pcard);
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)) { if(nloc == LOCATION_REMOVED || ((pcard->data.type & TYPE_TOKEN) && pcard->sendto_param.location == LOCATION_REMOVED)) {
remove.insert(pcard); remove.insert(pcard);
...@@ -4207,8 +4202,6 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 ...@@ -4207,8 +4202,6 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
raise_event(&released, EVENT_RELEASE, reason_effect, reason, reason_player, 0, 0); raise_event(&released, EVENT_RELEASE, reason_effect, reason, reason_player, 0, 0);
if(destroyed.size()) if(destroyed.size())
raise_event(&destroyed, EVENT_DESTROYED, reason_effect, reason, reason_player, 0, 0); raise_event(&destroyed, EVENT_DESTROYED, reason_effect, reason, reason_player, 0, 0);
if(retgrave.size())
raise_event(&retgrave, EVENT_RETURN_TO_GRAVE, reason_effect, reason, reason_player, 0, 0);
raise_event(&targets->container, EVENT_MOVE, reason_effect, reason, reason_player, 0, 0); raise_event(&targets->container, EVENT_MOVE, reason_effect, reason, reason_player, 0, 0);
process_single_event(); process_single_event();
process_instant_event(); process_instant_event();
......
...@@ -1367,7 +1367,7 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free ...@@ -1367,7 +1367,7 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
clit->set_triggering_state(phandler); clit->set_triggering_state(phandler);
} }
uint8 tp = clit->triggering_player; uint8 tp = clit->triggering_player;
if(check_hand_trigger(*clit) && check_trigger_effect(*clit) if(check_nonpublic_trigger(*clit) && check_trigger_effect(*clit)
&& peffect->is_chainable(tp) && peffect->is_activateable(tp, clit->evt, TRUE) && peffect->is_chainable(tp) && peffect->is_activateable(tp, clit->evt, TRUE)
&& check_spself_from_hand_trigger(*clit)) { && check_spself_from_hand_trigger(*clit)) {
if(tp == core.current_player) if(tp == core.current_player)
...@@ -1666,9 +1666,9 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori ...@@ -1666,9 +1666,9 @@ 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_state(phandler); ch.set_triggering_state(phandler);
} }
if(ch.triggering_player == priority && ch.triggering_location == LOCATION_HAND if(ch.triggering_player == priority && !phandler->is_status(STATUS_CHAINING)
&& phandler->is_position(POS_FACEDOWN) && !phandler->is_status(STATUS_CHAINING) && phandler->is_has_relation(ch) && (ch.triggering_location == LOCATION_HAND && phandler->is_position(POS_FACEDOWN) || ch.triggering_location == LOCATION_DECK)
&& peffect->is_chainable(priority) && peffect->is_activateable(priority, ch.evt, TRUE) && phandler->is_has_relation(ch) && peffect->is_chainable(priority) && peffect->is_activateable(priority, ch.evt, TRUE)
&& check_spself_from_hand_trigger(ch)) && check_spself_from_hand_trigger(ch))
core.select_chains.push_back(ch); core.select_chains.push_back(ch);
} }
...@@ -3288,7 +3288,7 @@ int32 field::process_damage_step(uint16 step, uint32 new_attack) { ...@@ -3288,7 +3288,7 @@ int32 field::process_damage_step(uint16 step, uint32 new_attack) {
return TRUE; return TRUE;
} }
void field::calculate_battle_damage(effect** pdamchange, card** preason_card, uint8* battle_destroyed) { void field::calculate_battle_damage(effect** pdamchange, card** preason_card, uint8* battle_destroyed) {
uint32 aa = core.attacker->get_attack(), ad = core.attacker->get_defense(); uint32 aa = core.attacker->get_battle_attack(), ad = core.attacker->get_battle_defense();
uint32 da = 0, dd = 0, a = aa, d; uint32 da = 0, dd = 0, a = aa, d;
uint8 pa = core.attacker->current.controler, pd; uint8 pa = core.attacker->current.controler, pd;
uint8 damp = 0; uint8 damp = 0;
...@@ -3303,8 +3303,8 @@ void field::calculate_battle_damage(effect** pdamchange, card** preason_card, ui ...@@ -3303,8 +3303,8 @@ void field::calculate_battle_damage(effect** pdamchange, card** preason_card, ui
a = ad; a = ad;
} }
if(core.attack_target) { if(core.attack_target) {
da = core.attack_target->get_attack(); da = core.attack_target->get_battle_attack();
dd = core.attack_target->get_defense(); dd = core.attack_target->get_battle_defense();
pd = core.attack_target->current.controler; pd = core.attack_target->current.controler;
if(core.attack_target->is_position(POS_ATTACK)) { if(core.attack_target->is_position(POS_ATTACK)) {
d = da; d = da;
...@@ -3935,7 +3935,6 @@ int32 field::add_chain(uint16 step) { ...@@ -3935,7 +3935,6 @@ int32 field::add_chain(uint16 step) {
} }
} }
if(peffect->type & EFFECT_TYPE_ACTIVATE) { if(peffect->type & EFFECT_TYPE_ACTIVATE) {
break_effect();
int32 ecode = 0; int32 ecode = 0;
if(phandler->current.location == LOCATION_HAND) { if(phandler->current.location == LOCATION_HAND) {
if(phandler->data.type & TYPE_TRAP) if(phandler->data.type & TYPE_TRAP)
...@@ -4009,7 +4008,6 @@ int32 field::add_chain(uint16 step) { ...@@ -4009,7 +4008,6 @@ int32 field::add_chain(uint16 step) {
pduel->write_buffer8(clit.triggering_sequence); pduel->write_buffer8(clit.triggering_sequence);
pduel->write_buffer32(peffect->description); pduel->write_buffer32(peffect->description);
pduel->write_buffer8((uint8)core.current_chain.size() + 1); pduel->write_buffer8((uint8)core.current_chain.size() + 1);
break_effect();
for(auto& ch_lim : core.chain_limit) for(auto& ch_lim : core.chain_limit)
luaL_unref(pduel->lua->lua_state, LUA_REGISTRYINDEX, ch_lim.function); luaL_unref(pduel->lua->lua_state, LUA_REGISTRYINDEX, ch_lim.function);
core.chain_limit.clear(); core.chain_limit.clear();
......
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