Commit 21e46a9a authored by VanillaSalt's avatar VanillaSalt

Merge pull request #31 from DailyShana/replace-effect

add ReplaceEffect
parents ddcefde6 1b0913cd
...@@ -1170,6 +1170,13 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) { ...@@ -1170,6 +1170,13 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) {
if (peffect->is_disable_related()) if (peffect->is_disable_related())
pduel->game_field->add_to_disable_check_list(check_target); pduel->game_field->add_to_disable_check_list(check_target);
} }
if (peffect->is_flag(EFFECT_FLAG_INITIAL) && peffect->copy_id && is_status(STATUS_EFFECT_REPLACED)) {
set_status(STATUS_EFFECT_REPLACED, FALSE);
set_status(STATUS_INITIALIZING, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_card_function(this, (char*) "initial_effect", 1, 0);
set_status(STATUS_INITIALIZING, FALSE);
}
indexer.erase(peffect); indexer.erase(peffect);
if(peffect->is_flag(EFFECT_FLAG_OATH)) if(peffect->is_flag(EFFECT_FLAG_OATH))
pduel->game_field->effects.oath.erase(peffect); pduel->game_field->effects.oath.erase(peffect);
...@@ -1225,6 +1232,35 @@ int32 card::copy_effect(uint32 code, uint32 reset, uint32 count) { ...@@ -1225,6 +1232,35 @@ int32 card::copy_effect(uint32 code, uint32 reset, uint32 count) {
pduel->uncopy.clear(); pduel->uncopy.clear();
return pduel->game_field->infos.copy_id - 1; return pduel->game_field->infos.copy_id - 1;
} }
int32 card::replace_effect(uint32 code, uint32 reset, uint32 count) {
card_data cdata;
read_card(code, &cdata);
if(cdata.type & TYPE_NORMAL)
return -1;
for(auto i = indexer.begin(); i != indexer.end();) {
auto rm = i++;
effect* peffect = rm->first;
auto it = rm->second;
if(peffect->is_flag(EFFECT_FLAG_INITIAL))
remove_effect(peffect, it);
}
uint32 cr = pduel->game_field->core.copy_reset;
uint8 crc = pduel->game_field->core.copy_reset_count;
pduel->game_field->core.copy_reset = reset;
pduel->game_field->core.copy_reset_count = count;
set_status(STATUS_INITIALIZING | STATUS_COPYING_EFFECT, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_code_function(code, (char*) "initial_effect", 1, 0);
set_status(STATUS_INITIALIZING | STATUS_COPYING_EFFECT, FALSE);
pduel->game_field->infos.copy_id++;
pduel->game_field->core.copy_reset = cr;
pduel->game_field->core.copy_reset_count = crc;
set_status(STATUS_EFFECT_REPLACED, TRUE);
for(auto eit = pduel->uncopy.begin(); eit != pduel->uncopy.end(); ++eit)
pduel->delete_effect(*eit);
pduel->uncopy.clear();
return pduel->game_field->infos.copy_id - 1;
}
// add EFFECT_SET_CONTROL // add EFFECT_SET_CONTROL
void card::reset(uint32 id, uint32 reset_type) { void card::reset(uint32 id, uint32 reset_type) {
effect* peffect; effect* peffect;
......
...@@ -183,6 +183,7 @@ public: ...@@ -183,6 +183,7 @@ public:
void remove_effect(effect* peffect); void remove_effect(effect* peffect);
void remove_effect(effect* peffect, effect_container::iterator it); void remove_effect(effect* peffect, effect_container::iterator it);
int32 copy_effect(uint32 code, uint32 reset, uint32 count); int32 copy_effect(uint32 code, uint32 reset, uint32 count);
int32 replace_effect(uint32 code, uint32 reset, uint32 count);
void reset(uint32 id, uint32 reset_type); void reset(uint32 id, uint32 reset_type);
void reset_effect_count(); void reset_effect_count();
int32 refresh_disable_status(); int32 refresh_disable_status();
...@@ -401,7 +402,7 @@ public: ...@@ -401,7 +402,7 @@ public:
#define STATUS_CHAINING 0x10000 // #define STATUS_CHAINING 0x10000 //
#define STATUS_SUMMON_DISABLED 0x20000 // #define STATUS_SUMMON_DISABLED 0x20000 //
#define STATUS_ACTIVATE_DISABLED 0x40000 // #define STATUS_ACTIVATE_DISABLED 0x40000 //
//#define STATUS_UNSUMMONABLE_CARD 0x80000 #define STATUS_EFFECT_REPLACED 0x80000
#define STATUS_UNION 0x100000 #define STATUS_UNION 0x100000
#define STATUS_ATTACK_CANCELED 0x200000 #define STATUS_ATTACK_CANCELED 0x200000
#define STATUS_INITIALIZING 0x400000 #define STATUS_INITIALIZING 0x400000
......
...@@ -138,6 +138,7 @@ static const struct luaL_Reg cardlib[] = { ...@@ -138,6 +138,7 @@ static const struct luaL_Reg cardlib[] = {
{ "IsRelateToCard", scriptlib::card_is_relate_to_card }, { "IsRelateToCard", scriptlib::card_is_relate_to_card },
{ "IsRelateToBattle", scriptlib::card_is_relate_to_battle }, { "IsRelateToBattle", scriptlib::card_is_relate_to_battle },
{ "CopyEffect", scriptlib::card_copy_effect }, { "CopyEffect", scriptlib::card_copy_effect },
{ "ReplaceEffect", scriptlib::card_replace_effect },
{ "EnableUnsummonable", scriptlib::card_enable_unsummonable }, { "EnableUnsummonable", scriptlib::card_enable_unsummonable },
{ "EnableReviveLimit", scriptlib::card_enable_revive_limit }, { "EnableReviveLimit", scriptlib::card_enable_revive_limit },
{ "CompleteProcedure", scriptlib::card_complete_procedure }, { "CompleteProcedure", scriptlib::card_complete_procedure },
......
...@@ -1182,6 +1182,20 @@ int32 scriptlib::card_copy_effect(lua_State *L) { ...@@ -1182,6 +1182,20 @@ int32 scriptlib::card_copy_effect(lua_State *L) {
lua_pushinteger(L, pcard->copy_effect(code, reset, count)); lua_pushinteger(L, pcard->copy_effect(code, reset, count));
return 1; return 1;
} }
int32 scriptlib::card_replace_effect(lua_State * L) {
check_param_count(L, 3);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**)lua_touserdata(L, 1);
uint32 code = lua_tointeger(L, 2);
uint32 reset = lua_tointeger(L, 3);
uint32 count = lua_tointeger(L, 4);
if(count == 0)
count = 1;
if(reset & RESET_PHASE && !(reset & (RESET_SELF_TURN | RESET_OPPO_TURN)))
reset |= (RESET_SELF_TURN | RESET_OPPO_TURN);
lua_pushinteger(L, pcard->replace_effect(code, reset, count));
return 1;
}
int32 scriptlib::card_enable_unsummonable(lua_State *L) { int32 scriptlib::card_enable_unsummonable(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 1);
......
...@@ -140,6 +140,7 @@ public: ...@@ -140,6 +140,7 @@ public:
static int32 card_is_relate_to_card(lua_State *L); static int32 card_is_relate_to_card(lua_State *L);
static int32 card_is_relate_to_battle(lua_State *L); static int32 card_is_relate_to_battle(lua_State *L);
static int32 card_copy_effect(lua_State *L); static int32 card_copy_effect(lua_State *L);
static int32 card_replace_effect(lua_State *L);
static int32 card_enable_unsummonable(lua_State *L); static int32 card_enable_unsummonable(lua_State *L);
static int32 card_enable_revive_limit(lua_State *L); static int32 card_enable_revive_limit(lua_State *L);
static int32 card_complete_procedure(lua_State *L); static int32 card_complete_procedure(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