Commit d2cbf8a7 authored by nanahira's avatar nanahira

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

parents 987fd9da a9b84ac6
......@@ -73,6 +73,28 @@ bool card_state::is_location(int32 loc) const {
return true;
return false;
}
void card_state::init_state() {
code = 0xffffffff;
code2 = 0xffffffff;
type = 0xffffffff;
level = 0xffffffff;
rank = 0xffffffff;
link = 0xffffffff;
lscale = 0xffffffff;
rscale = 0xffffffff;
attribute = 0xffffffff;
race = 0xffffffff;
attack = 0xffffffff;
defense = 0xffffffff;
base_attack = 0xffffffff;
base_defense = 0xffffffff;
controler = 0xff;
location = 0xff;
sequence = 0xff;
position = 0xff;
reason = 0xffffffff;
reason_player = 0xff;
}
bool card::card_operation_sort(card* c1, card* c2) {
duel* pduel = c1->pduel;
int32 cp1 = c1->overlay_target ? c1->overlay_target->current.controler : c1->current.controler;
......@@ -132,9 +154,9 @@ card::card(duel* pd) {
equiping_target = 0;
pre_equip_target = 0;
overlay_target = 0;
std::memset(&current, 0, sizeof(card_state));
std::memset(&previous, 0, sizeof(card_state));
std::memset(&temp, 0xff, sizeof(card_state));
current = {};
previous = {};
temp.init_state();
unique_pos[0] = unique_pos[1] = 0;
spsummon_counter[0] = spsummon_counter[1] = 0;
unique_code = 0;
......@@ -425,9 +447,10 @@ int32 card::is_pre_set_card(uint32 set_code) {
setcode = setcode >> 16;
}
//add set code
setcode = previous.setcode;
if (setcode && (setcode & 0xfff) == settype && (setcode & 0xf000 & setsubtype) == setsubtype)
for(auto& presetcode : previous.setcode) {
if (presetcode && (presetcode & 0xfff) == settype && (presetcode & 0xf000 & setsubtype) == setsubtype)
return TRUE;
}
//another code
uint32 code2 = previous.code2;
uint64 setcode2;
......@@ -1681,7 +1704,7 @@ int32 card::add_effect(effect* peffect) {
if (peffect->type & EFFECT_TYPE_SINGLE && !peffect->is_flag(EFFECT_FLAG_SINGLE_RANGE) && peffect->owner == this
&& get_status(STATUS_DISABLED) && (peffect->reset_flag & RESET_DISABLE))
return 0;
if (!(peffect->type & EFFECT_TYPE_CONTINUOUS) && is_continuous_event(peffect->code))
if (peffect->type & EFFECT_TYPES_TRIGGER_LIKE && is_continuous_event(peffect->code))
return 0;
// the trigger effect in phase is "once per turn" by default
if (peffect->get_code_type() == CODE_PHASE && peffect->code & (PHASE_DRAW | PHASE_STANDBY | PHASE_END) && peffect->type & (EFFECT_TYPE_TRIGGER_O | EFFECT_TYPE_TRIGGER_F)
......@@ -3492,6 +3515,15 @@ int32 card::is_affect_by_effect(effect* reason_effect) {
return FALSE;
return TRUE;
}
int32 card::is_can_be_disabled_by_effect(effect* reason_effect) {
if (is_status(STATUS_DISABLED))
return FALSE;
if (is_affected_by_effect(EFFECT_CANNOT_DISABLE))
return FALSE;
if (!is_affect_by_effect(reason_effect))
return FALSE;
return TRUE;
}
int32 card::is_destructable() {
if(overlay_target)
return FALSE;
......
......@@ -41,12 +41,12 @@ struct card_data {
struct card_state {
card_state()
: code(0), code2(0), setcode(0), type(0), level(0), rank(0), link(0), lscale(0), rscale(0), attribute(0), race(0), attack(0), defense(0), base_attack(0), base_defense(0),
: code(0), code2(0), type(0), level(0), rank(0), link(0), lscale(0), rscale(0), attribute(0), race(0), attack(0), defense(0), base_attack(0), base_defense(0),
controler(PLAYER_NONE), location(0), sequence(0), position(0), reason(0), pzone(false), reason_card(nullptr), reason_player(PLAYER_NONE), reason_effect(nullptr) {}
uint32 code;
uint32 code2;
uint16 setcode;
std::vector<uint32> setcode;
uint32 type;
uint32 level;
uint32 rank;
......@@ -69,6 +69,7 @@ struct card_state {
uint8 reason_player;
effect* reason_effect;
bool is_location(int32 loc) const;
void init_state();
};
struct query_cache {
......@@ -358,6 +359,7 @@ public:
int32 is_setable_mzone(uint8 playerid, uint8 ignore_count, effect* peffect, uint8 min_tribute, uint32 zone = 0x1f);
int32 is_setable_szone(uint8 playerid, uint8 ignore_fd = 0, uint8 toplayer = 2, uint32 zone = 0xff);
int32 is_affect_by_effect(effect* reason_effect);
int32 is_can_be_disabled_by_effect(effect* reason_effect);
int32 is_destructable();
int32 is_destructable_by_battle(card* pcard);
effect* check_indestructable_by_effect(effect* reason_effect, uint8 playerid);
......
......@@ -183,6 +183,8 @@ public:
#define EFFECT_TYPE_GRANT 0x2000 //
#define EFFECT_TYPE_TARGET 0x4000 //
#define EFFECT_TYPES_TRIGGER_LIKE (EFFECT_TYPE_ACTIVATE | EFFECT_TYPE_TRIGGER_O | EFFECT_TYPE_TRIGGER_F | EFFECT_TYPE_QUICK_O | EFFECT_TYPE_QUICK_F)
//========== Flags ==========
enum effect_flag : uint32 {
EFFECT_FLAG_INITIAL = 0x0001,
......@@ -486,7 +488,7 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define EFFECT_ACTIVATION_COUNT_LIMIT 367
#define EFFECT_LIMIT_SPECIAL_SUMMON_POSITION 368
#define EVENT_STARTUP 1000
//#define EVENT_STARTUP 1000
#define EVENT_FLIP 1001
#define EVENT_FREE_CHAIN 1002
#define EVENT_DESTROY 1010
......@@ -563,7 +565,7 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define DOUBLE_DAMAGE 0x80000000
#define HALF_DAMAGE 0x80000001
// The type of bit field in code
// The type of event in code
#define CODE_CUSTOM 1 // header + id (28 bits)
#define CODE_COUNTER 2 // header + counter_id (16 bits)
#define CODE_PHASE 3 // header + phase_id (12 bits)
......
......@@ -3128,6 +3128,15 @@ int32 scriptlib::card_is_immune_to_effect(lua_State *L) {
lua_pushboolean(L, !pcard->is_affect_by_effect(peffect));
return 1;
}
int32 scriptlib::card_is_can_be_disabled_by_effect(lua_State* L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_CARD, 1);
check_param(L, PARAM_TYPE_EFFECT, 2);
card* pcard = *(card**)lua_touserdata(L, 1);
effect* peffect = *(effect**)lua_touserdata(L, 2);
lua_pushboolean(L, pcard->is_can_be_disabled_by_effect(peffect));
return 1;
}
int32 scriptlib::card_is_can_be_effect_target(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
......@@ -3642,6 +3651,7 @@ static const struct luaL_Reg cardlib[] = {
{ "CheckFusionMaterial", scriptlib::card_check_fusion_material },
{ "CheckFusionSubstitute", scriptlib::card_check_fusion_substitute },
{ "IsImmuneToEffect", scriptlib::card_is_immune_to_effect },
{ "IsCanBeDisabledByEffect", scriptlib::card_is_can_be_disabled_by_effect },
{ "IsCanBeEffectTarget", scriptlib::card_is_can_be_effect_target },
{ "IsCanBeBattleTarget", scriptlib::card_is_can_be_battle_target },
{ "AddMonsterAttribute", scriptlib::card_add_monster_attribute },
......
......@@ -3908,7 +3908,16 @@ int32 scriptlib::duel_select_field(lua_State* L) {
uint32 location1 = (uint32)lua_tointeger(L, 3);
uint32 location2 = (uint32)lua_tointeger(L, 4);
uint32 filter = (uint32)lua_tointeger(L, 5);
uint16 type = PROCESSOR_SELECT_DISFIELD;
duel* pduel = interpreter::get_duel_info(L);
if(lua_gettop(L) >= 6) {
type = PROCESSOR_SELECT_PLACE;
uint32 code = (uint32)lua_tointeger(L, 6);
pduel->write_buffer8(MSG_HINT);
pduel->write_buffer8(HINT_SELECTMSG);
pduel->write_buffer8(playerid);
pduel->write_buffer32(code);
}
uint32 flag = 0xffffffff;
if(location1 & LOCATION_MZONE) {
flag &= 0xffffffe0;
......@@ -3926,7 +3935,7 @@ int32 scriptlib::duel_select_field(lua_State* L) {
flag &= 0xffffff9f;
}
flag |= filter | 0x00800080;
pduel->game_field->add_process(PROCESSOR_SELECT_DISFIELD, 0, 0, 0, playerid, flag, count);
pduel->game_field->add_process(type, 0, 0, 0, playerid, flag, count);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State* L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
int32 playerid = (int32)lua_tointeger(L, 1);
......
......@@ -18,7 +18,7 @@ int32 field::negate_chain(uint8 chaincount) {
if(chaincount > core.current_chain.size() || chaincount < 1)
chaincount = (uint8)core.current_chain.size();
chain& pchain = core.current_chain[chaincount - 1];
card* phandler = pchain.triggering_effect->handler;
card* phandler = pchain.triggering_effect->get_handler();
if(!(pchain.flag & CHAIN_DISABLE_ACTIVATE) && is_chain_negatable(pchain.chain_count)
&& (!phandler->is_has_relation(pchain) || phandler->is_affect_by_effect(core.reason_effect))) {
pchain.flag |= CHAIN_DISABLE_ACTIVATE;
......@@ -43,7 +43,7 @@ int32 field::disable_chain(uint8 chaincount, uint8 forced) {
if(chaincount > core.current_chain.size() || chaincount < 1)
chaincount = (uint8)core.current_chain.size();
chain& pchain = core.current_chain[chaincount - 1];
card* phandler = pchain.triggering_effect->handler;
card* phandler = pchain.triggering_effect->get_handler();
if(!(pchain.flag & CHAIN_DISABLE_EFFECT) && is_chain_disablable(pchain.chain_count)
&& (!phandler->is_has_relation(pchain) || phandler->is_affect_by_effect(core.reason_effect))
&& !(phandler->is_has_relation(pchain) && phandler->is_status(STATUS_DISABLED) && !forced)) {
......@@ -3921,12 +3921,12 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
pcard->previous.attack = pcard->data.attack;
pcard->previous.defense = pcard->data.defense;
}
pcard->previous.setcode.clear();
effect_set eset;
pcard->filter_effect(EFFECT_ADD_SETCODE, &eset);
if(eset.size())
pcard->previous.setcode = eset.get_last()->get_value(pcard);
else
pcard->previous.setcode = 0;
for(int32 i = 0; i < eset.size(); ++i) {
pcard->previous.setcode.push_back((uint32)eset[i]->get_value(pcard));
}
}
}
if(leave_p.size())
......
......@@ -289,6 +289,7 @@ public:
static int32 card_check_fusion_material(lua_State *L);
static int32 card_check_fusion_substitute(lua_State *L);
static int32 card_is_immune_to_effect(lua_State *L);
static int32 card_is_can_be_disabled_by_effect(lua_State* L);
static int32 card_is_can_be_effect_target(lua_State *L);
static int32 card_is_can_be_battle_target(lua_State *L);
static int32 card_add_monster_attribute(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