summaryrefslogtreecommitdiff
path: root/src/scripting
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-05-19 11:40:50 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-08-26 22:56:47 +0200
commit4d46079cd147e05513473860cb2e92fec0c31b8f (patch)
tree0f115a91debb6be766a174e8042ff800aff3a0ec /src/scripting
parent6d14024f3df86c05e94f2b4161faf8f5d97c2c0f (diff)
downloadmanaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.tar.gz
manaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.tar.bz2
manaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.tar.xz
manaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.zip
Allow names instead of ids for attributes + cleanup
I did not adapt the scripts yet since we need some special handling for the attributes which are required by the server directly. So you still have to use the ids for those. I will change that later. In the future I want to use the AttributeInfo class instead of the int id everywhere possible. So I did a small start on that too.
Diffstat (limited to 'src/scripting')
-rw-r--r--src/scripting/lua.cpp10
-rw-r--r--src/scripting/luautil.cpp12
-rw-r--r--src/scripting/luautil.h26
3 files changed, 31 insertions, 17 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 6d1adb74..a76c9399 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1727,7 +1727,7 @@ static int entity_get_y(lua_State *s)
static int entity_get_base_attribute(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- int attr = luaL_checkint(s, 2);
+ int attr = checkAttribute(s, 2)->id;
luaL_argcheck(s, attr > 0, 2, "invalid attribute id");
lua_pushinteger(s, being->getComponent<BeingComponent>()->getAttributeBase(attr));
@@ -1745,7 +1745,7 @@ static int entity_get_base_attribute(lua_State *s)
static int entity_set_base_attribute(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- int attr = luaL_checkint(s, 2);
+ int attr = checkAttribute(s, 2)->id;
double value = luaL_checknumber(s, 3);
being->getComponent<BeingComponent>()->setAttribute(*being, attr, value);
@@ -1775,7 +1775,7 @@ static int entity_set_base_attribute(lua_State *s)
static int entity_get_modified_attribute(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- int attr = luaL_checkint(s, 2);
+ int attr = checkAttribute(s, 2)->id;
luaL_argcheck(s, attr > 0, 2, "invalid attribute id");
const double value =
@@ -1805,7 +1805,7 @@ static int entity_get_modified_attribute(lua_State *s)
static int entity_apply_attribute_modifier(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- int attr = luaL_checkint(s,2);
+ int attr = checkAttribute(s, 2)->id;
double value = luaL_checknumber(s, 3);
int layer = luaL_checkint(s, 4);
int duration = luaL_optint(s, 5, 0);
@@ -1828,7 +1828,7 @@ static int entity_apply_attribute_modifier(lua_State *s)
static int entity_remove_attribute_modifier(lua_State *s)
{
Entity *being = checkBeing(s, 1);
- int attr = luaL_checkint(s, 2);
+ int attr = checkAttribute(s, 2)->id;
double value = luaL_checknumber(s, 3);
int layer = luaL_checkint(s, 4);
int effectId = luaL_optint(s, 5, 0);
diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp
index 7dd2b199..8d166469 100644
--- a/src/scripting/luautil.cpp
+++ b/src/scripting/luautil.cpp
@@ -237,6 +237,18 @@ AbilityManager::AbilityInfo *checkAbility(lua_State *s, int p)
return abilityInfo;
}
+const AttributeManager::AttributeInfo *checkAttribute(lua_State *s, int p)
+{
+ const AttributeManager::AttributeInfo *attributeInfo;
+ if (lua_isnumber(s, p))
+ attributeInfo = attributeManager->getAttributeInfo(luaL_checkint(s, p));
+ else
+ attributeInfo = attributeManager->getAttributeInfo(luaL_checkstring(s, p));
+
+ luaL_argcheck(s, attributeInfo != nullptr, p, "invalid attribute");
+ return attributeInfo;
+}
+
unsigned char checkWalkMask(lua_State *s, int p)
{
const char *stringMask = luaL_checkstring(s, p);
diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h
index c747d2a1..fc198310 100644
--- a/src/scripting/luautil.h
+++ b/src/scripting/luautil.h
@@ -35,6 +35,7 @@ extern "C" {
#include <vector>
#include "game-server/abilitymanager.h"
+#include "game-server/attributemanager.h"
class CharacterComponent;
class Entity;
@@ -165,21 +166,22 @@ typedef LuaUserData<MonsterClass> LuaMonsterClass;
typedef LuaUserData<StatusEffect> LuaStatusEffect;
typedef LuaUserData<AbilityManager::AbilityInfo> LuaAbilityInfo;
-Script * getScript(lua_State *s);
+Script * getScript(lua_State *s);
-ItemClass * getItemClass(lua_State *s, int p);
-MonsterClass * getMonsterClass(lua_State *s, int p);
+ItemClass * getItemClass(lua_State *s, int p);
+MonsterClass * getMonsterClass(lua_State *s, int p);
-Entity * checkActor(lua_State *s, int p);
-Entity * checkBeing(lua_State *s, int p);
-Entity * checkCharacter(lua_State *s, int p);
-ItemClass * checkItemClass(lua_State *s, int p);
-Entity * checkMonster(lua_State *s, int p);
-MonsterClass * checkMonsterClass(lua_State *s, int p);
-Entity * checkNpc(lua_State *s, int p);
+Entity * checkActor(lua_State *s, int p);
+Entity * checkBeing(lua_State *s, int p);
+Entity * checkCharacter(lua_State *s, int p);
+ItemClass * checkItemClass(lua_State *s, int p);
+Entity * checkMonster(lua_State *s, int p);
+MonsterClass * checkMonsterClass(lua_State *s, int p);
+Entity * checkNpc(lua_State *s, int p);
int checkSkill(lua_State *s, int p);
-AbilityManager::AbilityInfo *checkAbility(lua_State *s, int p);
-unsigned char checkWalkMask(lua_State *s, int p);
+AbilityManager::AbilityInfo * checkAbility(lua_State *s, int p);
+const AttributeManager::AttributeInfo *checkAttribute(lua_State *s, int p);
+unsigned char checkWalkMask(lua_State *s, int p);
MapComposite * checkCurrentMap(lua_State *s, Script *script = 0);
Script::Thread* checkCurrentThread(lua_State *s, Script *script = 0);