From 5c3f23831986dda46d1c41b8316dd901f1bf3164 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 18 Jul 2009 21:08:18 -0600 Subject: Change status effects to prevent duplication Also add some functions for manipulating status effects: * removeStatusEffect * getStatusEffectTime * setStatusEffectTime --- src/scripting/lua.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 230c8a3c..7361cea0 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -501,7 +501,23 @@ static int being_apply_status(lua_State *s) } /** - * Returns true if a being has a status effect + * Removes the given status effect + * tmw.being_remove_status(Being *being, int id) + */ +static int being_remove_status(lua_State *s) +{ + if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2)) + { + raiseScriptError(s, "being_remove_status called with incorrect parameters."); + return 0; + } + Being *being = getBeing(s, 1); + being->removeStatusEffect(lua_tointeger(s,2)); + return 1; +} + +/** + * Returns true if a being has the given status effect * tmw.being_has_status(Being *being, int id) */ static int being_has_status(lua_State *s) @@ -516,6 +532,38 @@ static int being_has_status(lua_State *s) return 1; } +/** + * Returns the time left on the given status effect + * tmw.being_get_status_time(Being *being, int id) + */ +static int being_get_status_time(lua_State *s) +{ + if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2)) + { + raiseScriptError(s, "being_time_status called with incorrect parameters."); + return 0; + } + Being *being = getBeing(s, 1); + lua_pushinteger(s, being->getStatusEffectTime(lua_tointeger(s,2))); + return 1; +} + +/** + * Sets the time left on the given status effect + * tmw.being_set_status_time(Being *being, int id) + */ +static int being_set_status_time(lua_State *s) +{ + if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2) || !lua_isnumber(s, 3)) + { + raiseScriptError(s, "being_time_status called with incorrect parameters."); + return 0; + } + Being *being = getBeing(s, 1); + being->setStatusEffectTime(lua_tointeger(s,2), lua_tointeger(s,3)); + return 1; +} + /** * Returns the Thing type of the given Being @@ -1283,7 +1331,10 @@ LuaScript::LuaScript(): { "exp_for_level", &exp_for_level }, { "monster_create", &monster_create }, { "being_apply_status", &being_apply_status }, + { "being_remove_status", &being_remove_status }, { "being_has_status", &being_has_status }, + { "being_set_status_time", &being_set_status_time}, + { "being_get_status_time", &being_get_status_time}, { "being_type", &being_type }, { "being_walk", &being_walk }, { "being_say", &being_say }, -- cgit v1.2.3-70-g09d2