Skip to content

Commit

Permalink
add Effect.GetRange, IsHasRange
Browse files Browse the repository at this point in the history
  • Loading branch information
salix5 committed Nov 2, 2024
1 parent 08b1c5e commit a8dde30
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 55 deletions.
128 changes: 73 additions & 55 deletions libeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down
12 changes: 12 additions & 0 deletions scriptlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a8dde30

Please sign in to comment.