diff options
author | Philipp Sehmisch <mana@crushnet.org> | 2010-02-25 20:21:59 +0100 |
---|---|---|
committer | Philipp Sehmisch <mana@crushnet.org> | 2010-02-25 20:21:59 +0100 |
commit | c5252ab6c58a7680f5d8ab49fc7ecb17fa778c7c (patch) | |
tree | 36237d241f7ba778e480be9b704c580edafb616d | |
parent | e993ea11bfc211fa69a08838f0d9f1ca069e9e37 (diff) | |
download | manaserv-c5252ab6c58a7680f5d8ab49fc7ecb17fa778c7c.tar.gz manaserv-c5252ab6c58a7680f5d8ab49fc7ecb17fa778c7c.tar.xz manaserv-c5252ab6c58a7680f5d8ab49fc7ecb17fa778c7c.zip |
Added script bindings for healing characters and other beings.
Reviewed-by: Jared Adams <jaxad0127@gmail.com>
-rw-r--r-- | src/game-server/being.cpp | 15 | ||||
-rw-r--r-- | src/game-server/being.hpp | 6 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 34 |
3 files changed, 55 insertions, 0 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index e9fa42b..d1d4afe 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -100,6 +100,21 @@ int Being::damage(Actor *, const Damage &damage) return HPloss; } +void Being::heal() +{ + Attribute &HP = mAttributes[BASE_ATTR_HP]; + HP.mod = HP.base; + modifiedAttribute(BASE_ATTR_HP); +} + +void Being::heal(int hp) +{ + Attribute &HP = mAttributes[BASE_ATTR_HP]; + HP.mod += hp; + if (HP.mod > HP.base) HP.mod = HP.base; + modifiedAttribute(BASE_ATTR_HP); +} + void Being::died() { if (mAction == DEAD) diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp index 8bf23ff..ad9beb1 100644 --- a/src/game-server/being.hpp +++ b/src/game-server/being.hpp @@ -156,6 +156,12 @@ class Being : public Actor */ virtual int damage(Actor *source, const Damage &damage); + /** Restores all hit points of the being */ + void heal(); + + /** Restores a specific number of hit points of the being */ + void heal(int hp); + /** * Changes status and calls all the "died" listeners. */ diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 034e9b4..c386c35 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -660,6 +660,39 @@ static int being_damage(lua_State *s) } /** + * Restores hit points of a being + * mana.being_heal(being[, value]) + * Without a value it heals fully. + */ +static int being_heal(lua_State *s) +{ + Being *being = getBeing(s, 1); + if (!being) + { + raiseScriptError(s, + "being_heal called for nonexistent being."); + return 0; + } + + if (lua_gettop(s) == 1) // when there is only one argument + { + being->heal(); + } + else if (lua_isnumber(s, 2)) + { + being->heal(lua_tointeger(s, 2)); + } + else + { + raiseScriptError(s, + "being_heal called with illegal healing value."); + } + + return 0; +} + + +/** * Gets the attribute for a being * mana.being_get_attribute(being, attribute) */ @@ -1511,6 +1544,7 @@ LuaScript::LuaScript(): { "being_walk", &being_walk }, { "being_say", &being_say }, { "being_damage", &being_damage }, + { "being_heal", &being_heal }, { "being_get_attribute", &being_get_attribute }, { "being_get_name", &being_get_name }, { "being_get_action", &being_get_action }, |