From a8dde304976b1f9a7668ee3634ff4594d81bfc3f Mon Sep 17 00:00:00 2001 From: salix5 Date: Mon, 28 Oct 2024 23:06:28 +0800 Subject: [PATCH] add Effect.GetRange, IsHasRange --- libeffect.cpp | 128 ++++++++++++++++++++++++++++---------------------- scriptlib.h | 12 +++++ 2 files changed, 85 insertions(+), 55 deletions(-) diff --git a/libeffect.cpp b/libeffect.cpp index 78bc3eea9..c6efbc2c0 100644 --- a/libeffect.cpp +++ b/libeffect.cpp @@ -12,6 +12,64 @@ #include "effect.h" #include "group.h" +int32 scriptlib::get_effect_property(lua_State* L, effect_member type) { + check_param_count(L, 1); + check_param(L, PARAM_TYPE_EFFECT, 1); + effect* peffect = *(effect**)lua_touserdata(L, 1); + lua_Integer value{}; + if (peffect) { + switch (type) { + case MEMBER_CATEGORY: + value = peffect->category; + break; + case MEMBER_CODE: + value = peffect->code; + break; + case MEMBER_DESCRIPTION: + value = peffect->description; + break; + case MEMBER_ID: + value = peffect->id; + break; + case MEMBER_RANGE: + value = peffect->range; + break; + case MEMBER_TYPE: + value = peffect->type; + break; + } + } + lua_pushinteger(L, value); + return 1; +} +int32 scriptlib::is_effect_property(lua_State* L, effect_member type) { + check_param_count(L, 2); + check_param(L, PARAM_TYPE_EFFECT, 1); + effect* peffect = *(effect**)lua_touserdata(L, 1); + uint32 value{}; + if (peffect) { + switch (type) { + case MEMBER_CATEGORY: + value = peffect->category; + break; + case MEMBER_CODE: + value = peffect->code; + break; + case MEMBER_RANGE: + value = peffect->range; + break; + case MEMBER_TYPE: + value = peffect->type; + break; + } + } + uint32 x = (uint32)lua_tointeger(L, 2); + if (value & x) + lua_pushboolean(L, 1); + else + lua_pushboolean(L, 0); + return 1; +} int32 scriptlib::effect_new(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); @@ -52,11 +110,7 @@ int32 scriptlib::effect_reset(lua_State *L) { return 0; } int32 scriptlib::effect_get_field_id(lua_State *L) { - check_param_count(L, 1); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - lua_pushinteger(L, peffect->id); - return 1; + return get_effect_property(L, MEMBER_ID); } int32 scriptlib::effect_set_description(lua_State *L) { check_param_count(L, 2); @@ -303,34 +357,13 @@ int32 scriptlib::effect_set_owner_player(lua_State *L) { return 0; } int32 scriptlib::effect_get_description(lua_State *L) { - check_param_count(L, 1); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - if (peffect) { - lua_pushinteger(L, peffect->description); - return 1; - } - return 0; + return get_effect_property(L, MEMBER_DESCRIPTION); } int32 scriptlib::effect_get_code(lua_State *L) { - check_param_count(L, 1); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - if (peffect) { - lua_pushinteger(L, peffect->code); - return 1; - } - return 0; + return get_effect_property(L, MEMBER_CODE); } int32 scriptlib::effect_get_type(lua_State *L) { - check_param_count(L, 1); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - if (peffect) { - lua_pushinteger(L, peffect->type); - return 1; - } - return 0; + return get_effect_property(L, MEMBER_TYPE); } int32 scriptlib::effect_get_property(lua_State *L) { check_param_count(L, 1); @@ -376,14 +409,10 @@ int32 scriptlib::effect_get_label_object(lua_State *L) { } } int32 scriptlib::effect_get_category(lua_State *L) { - check_param_count(L, 1); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - if (peffect) { - lua_pushinteger(L, peffect->category); - return 1; - } - return 0; + return get_effect_property(L, MEMBER_CATEGORY); +} +int32 scriptlib::effect_get_range(lua_State* L) { + return get_effect_property(L, MEMBER_RANGE); } int32 scriptlib::effect_get_owner(lua_State *L) { check_param_count(L, 1); @@ -482,26 +511,13 @@ int32 scriptlib::effect_is_has_property(lua_State *L) { return 1; } int32 scriptlib::effect_is_has_category(lua_State *L) { - check_param_count(L, 2); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - uint32 tcate = (uint32)lua_tointeger(L, 2); - if (peffect && (peffect->category & tcate)) - lua_pushboolean(L, 1); - else - lua_pushboolean(L, 0); - return 1; + return is_effect_property(L, MEMBER_CATEGORY); } int32 scriptlib::effect_is_has_type(lua_State *L) { - check_param_count(L, 2); - check_param(L, PARAM_TYPE_EFFECT, 1); - effect* peffect = *(effect**) lua_touserdata(L, 1); - uint32 ttype = (uint32)lua_tointeger(L, 2); - if (peffect && (peffect->type & ttype)) - lua_pushboolean(L, 1); - else - lua_pushboolean(L, 0); - return 1; + return is_effect_property(L, MEMBER_TYPE); +} +int32 scriptlib::effect_is_has_range(lua_State* L) { + return is_effect_property(L, MEMBER_RANGE); } int32 scriptlib::effect_is_activatable(lua_State *L) { check_param_count(L, 2); @@ -615,6 +631,7 @@ static const struct luaL_Reg effectlib[] = { { "GetLabel", scriptlib::effect_get_label }, { "GetLabelObject", scriptlib::effect_get_label_object }, { "GetCategory", scriptlib::effect_get_category }, + { "GetRange", scriptlib::effect_get_range }, { "GetOwner", scriptlib::effect_get_owner }, { "GetHandler", scriptlib::effect_get_handler }, { "GetCondition", scriptlib::effect_get_condition }, @@ -629,6 +646,7 @@ static const struct luaL_Reg effectlib[] = { { "IsHasProperty", scriptlib::effect_is_has_property }, { "IsHasCategory", scriptlib::effect_is_has_category }, { "IsHasType", scriptlib::effect_is_has_type }, + { "IsHasRange", scriptlib::effect_is_has_range }, { "IsActivatable", scriptlib::effect_is_activatable }, { "IsActivated", scriptlib::effect_is_activated }, { "IsCostChecked", scriptlib::effect_is_cost_checked }, diff --git a/scriptlib.h b/scriptlib.h index 9cfb2218c..7c6b6e74b 100644 --- a/scriptlib.h +++ b/scriptlib.h @@ -17,6 +17,14 @@ constexpr bool match_all(uint32 x, uint32 y) { class scriptlib { public: + enum effect_member : int32 { + MEMBER_CATEGORY, + MEMBER_CODE, + MEMBER_DESCRIPTION, + MEMBER_ID, + MEMBER_RANGE, + MEMBER_TYPE, + }; static int32 check_param(lua_State* L, int32 param_type, int32 index, int32 retfalse = FALSE); static int32 check_param_count(lua_State* L, int32 count); static int32 check_action_permission(lua_State* L); @@ -299,6 +307,8 @@ class scriptlib { static void open_cardlib(lua_State *L); //Effect functions + static int32 get_effect_property(lua_State* L, effect_member type); + static int32 is_effect_property(lua_State* L, effect_member type); static int32 effect_new(lua_State *L); static int32 effect_newex(lua_State *L); static int32 effect_clone(lua_State *L); @@ -330,6 +340,7 @@ class scriptlib { static int32 effect_get_label(lua_State *L); static int32 effect_get_label_object(lua_State *L); static int32 effect_get_category(lua_State *L); + static int32 effect_get_range(lua_State* L); static int32 effect_get_owner(lua_State *L); static int32 effect_get_handler(lua_State *L); static int32 effect_get_owner_player(lua_State *L); @@ -343,6 +354,7 @@ class scriptlib { static int32 effect_is_active_type(lua_State *L); static int32 effect_is_has_property(lua_State *L); static int32 effect_is_has_category(lua_State *L); + static int32 effect_is_has_range(lua_State* L); static int32 effect_is_has_type(lua_State *L); static int32 effect_is_activatable(lua_State *L); static int32 effect_is_activated(lua_State *L);