diff options
author | Philipp Sehmisch <mana@crushnet.org> | 2010-07-09 15:21:50 +0200 |
---|---|---|
committer | Philipp Sehmisch <mana@crushnet.org> | 2010-07-09 15:22:11 +0200 |
commit | 26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (patch) | |
tree | 6d7ea0ebe8be228a61315f72122eed3f2f995a0b /src/scripting | |
parent | 2627acefebc688d9d9733abe23ba5aae79f66ea0 (diff) | |
download | manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.gz manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.bz2 manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.tar.xz manaserv-26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2.zip |
Added LUA script bindings for manipulating the specials available to a character.
Added script call for getting the cost of a special (recharge only for now)
Deleting specials works server-sided but the client isn't informed about it properly. Specials without recharge cost don't appear for the player. Both of these features require an additional netcode message.
Reviewed-by: Freeyorp
Diffstat (limited to 'src/scripting')
-rw-r--r-- | src/scripting/lua.cpp | 76 | ||||
-rw-r--r-- | src/scripting/luascript.cpp | 11 | ||||
-rw-r--r-- | src/scripting/luascript.hpp | 1 | ||||
-rw-r--r-- | src/scripting/script.cpp | 30 | ||||
-rw-r--r-- | src/scripting/script.hpp | 5 |
5 files changed, 122 insertions, 1 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index ca916248..2d9562ed 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1454,6 +1454,79 @@ static int chr_get_kill_count(lua_State *s) /** + * Enables a special for a character + * mana.chr_give_special (character, special) + */ +static int chr_give_special(lua_State *s) +{ + // cost_type is ignored until we have more than one cost type + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "chr_give_special called for nonexistent character."); + return 0; + } + if (!lua_isnumber(s, 2)) + { + raiseScriptError(s, "chr_give_special called with incorect parameters"); + return 0; + } + int special = lua_tointeger(s, 2); + + c->giveSpecial(special); + return 0; +} + +/** + * Checks if a character has a special and returns true or false + * mana.chr_has_special (character, special) + */ +static int chr_has_special(lua_State *s) +{ + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "chr_has_special called for nonexistent character."); + return 0; + } + if (!lua_isnumber(s, 2)) + { + raiseScriptError(s, "chr_has_special called with incorect parameters"); + return 0; + } + int special = lua_tointeger(s, 2); + + lua_pushboolean(s, c->hasSpecial(special)); + return 1; +} + +/** + * Removes a special from a character + * mana.chr_take_special (character, special) + */ +static int chr_take_special(lua_State *s) +{ + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "chr_take_special called for nonexistent character."); + return 0; + } + if (!lua_isnumber(s, 2)) + { + raiseScriptError(s, "chr_take_special called with incorect parameters"); + return 0; + } + int special = lua_tointeger(s, 2); + + lua_pushboolean(s, c->hasSpecial(special)); + c->takeSpecial(special); + return 1; +} + + + +/** * Returns the rights level of a character. * mana.chr_get_rights (being) */ @@ -1650,6 +1723,9 @@ LuaScript::LuaScript(): { "chr_set_hair_color", &chr_set_hair_color }, { "chr_get_hair_color", &chr_get_hair_color }, { "chr_get_kill_count", &chr_get_kill_count }, + { "chr_give_special", &chr_give_special }, + { "chr_has_special", &chr_has_special }, + { "chr_take_special", &chr_take_special }, { "exp_for_level", &exp_for_level }, { "monster_create", &monster_create }, { "monster_load_script", &monster_load_script }, diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp index b48ec511..33145b56 100644 --- a/src/scripting/luascript.cpp +++ b/src/scripting/luascript.cpp @@ -167,3 +167,14 @@ bool LuaScript::load_global_event_script(const std::string &file) } return true; } + +bool LuaScript::load_special_actions_script(const std::string &file) +{ + Script::special_actions_script = new LuaScript(); + if (!Script::special_actions_script->loadFile(file)) + { + Script::special_actions_script = NULL; + return false; + } + return true; +} diff --git a/src/scripting/luascript.hpp b/src/scripting/luascript.hpp index 315c759f..94851ac7 100644 --- a/src/scripting/luascript.hpp +++ b/src/scripting/luascript.hpp @@ -71,6 +71,7 @@ class LuaScript: public Script * Loads the global event script file */ static bool load_global_event_script(const std::string &file); + static bool load_special_actions_script(const std::string &file); private: diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index fe3c5d8d..359e94bd 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -33,6 +33,7 @@ typedef std::map< std::string, Script::Factory > Engines; static Engines *engines = NULL; Script *Script::global_event_script = NULL; +Script *Script::special_actions_script = NULL; Script::Script(): mMap(NULL), @@ -122,3 +123,32 @@ bool Script::execute_global_event_function(const std::string &function, Being* o } return isScriptHandled; } + + +void Script::addDataToSpecial(int id, Special* special) +{ + /* currently only gets the recharge cost. + TODO: get any other info in a similar way, but + first we have to agree on what other + info we actually want to provide. + */ + Script *script = Script::special_actions_script; + script->prepare("get_special_recharge_cost"); + script->push(id); + int scriptReturn = script->execute(); + special->neededMana = scriptReturn; + +} + +bool Script::perform_special_action(int specialId, Being* caster) +{ + Script *script = Script::special_actions_script; + if (script) + { + script->prepare("use_special"); + script->push(caster); + script->push(specialId); + script->execute(); + } + return true; +} diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp index 96df0859..0e874151 100644 --- a/src/scripting/script.hpp +++ b/src/scripting/script.hpp @@ -23,6 +23,7 @@ #include <string> +#include "game-server/character.hpp" #include "game-server/eventlistener.hpp" class MapComposite; @@ -135,11 +136,13 @@ class Script * Runs a function from the global event script file */ static bool execute_global_event_function(const std::string &function, Being *obj); - + static void addDataToSpecial(int specialId, Special *special); + static bool perform_special_action(int specialId, Being *caster); protected: static Script* global_event_script; // the global event script + static Script* special_actions_script; // the special actions script std::string mScriptFile; private: |