summaryrefslogtreecommitdiff
path: root/src/scripting/scriptmanager.cpp
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-03-03 13:36:28 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2012-03-03 16:41:39 +0100
commitf872528771f0b71741fb36ddf70f2ae23f54c1e3 (patch)
tree9b3751cab7d9f58ae0b15acf061e428f18bc07db /src/scripting/scriptmanager.cpp
parentc0c208d4c29ff49f940e8a6c54adb26cc4e5eba3 (diff)
downloadmanaserv-f872528771f0b71741fb36ddf70f2ae23f54c1e3.tar.gz
manaserv-f872528771f0b71741fb36ddf70f2ae23f54c1e3.tar.bz2
manaserv-f872528771f0b71741fb36ddf70f2ae23f54c1e3.tar.xz
manaserv-f872528771f0b71741fb36ddf70f2ae23f54c1e3.zip
Added further missing callbacks
Reviewed-by: bjorn.
Diffstat (limited to 'src/scripting/scriptmanager.cpp')
-rw-r--r--src/scripting/scriptmanager.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/scripting/scriptmanager.cpp b/src/scripting/scriptmanager.cpp
index d58379f6..c133a5e2 100644
--- a/src/scripting/scriptmanager.cpp
+++ b/src/scripting/scriptmanager.cpp
@@ -25,6 +25,10 @@
static Script *_currentState;
+static Script::Ref _craftCallback;
+static Script::Ref _specialCallback;
+static Script::Ref _getSpecialRechargeCostCallback;
+
void ScriptManager::initialize()
{
const std::string engine = Configuration::getValue("script_engine", "lua");
@@ -56,9 +60,9 @@ void ScriptManager::addDataToSpecial(int id, Special *special)
first we have to agree on what other
info we actually want to provide.
*/
- if (special)
+ if (special && _getSpecialRechargeCostCallback.isValid())
{
- _currentState->prepare("get_special_recharge_cost");
+ _currentState->prepare(_getSpecialRechargeCostCallback);
_currentState->push(id);
int scriptReturn = _currentState->execute();
special->neededMana = scriptReturn;
@@ -67,7 +71,13 @@ void ScriptManager::addDataToSpecial(int id, Special *special)
bool ScriptManager::performSpecialAction(int specialId, Being *caster)
{
- _currentState->prepare("use_special");
+ if (!_specialCallback.isValid())
+ {
+ LOG_WARN("No callback for specials set! Specials disabled.");
+ return false;
+ }
+
+ _currentState->prepare(_specialCallback);
_currentState->push(caster);
_currentState->push(specialId);
_currentState->execute();
@@ -77,9 +87,23 @@ bool ScriptManager::performSpecialAction(int specialId, Being *caster)
bool ScriptManager::performCraft(Being *crafter,
const std::list<InventoryItem> &recipe)
{
- _currentState->prepare("on_craft");
+ if (!_craftCallback.isValid())
+ {
+ LOG_WARN("No crafting callback set! Crafting disabled.");
+ return false;
+ }
+ _currentState->prepare(_craftCallback);
_currentState->push(crafter);
_currentState->push(recipe);
_currentState->execute();
return true;
}
+
+void ScriptManager::setCraftCallback(Script *script)
+{ script->assignCallback(_craftCallback); }
+
+void ScriptManager::setSpecialCallback(Script *script)
+{ script->assignCallback(_specialCallback); }
+
+void ScriptManager::setGetSpecialRechargeCostCallback(Script *script)
+{ script->assignCallback(_getSpecialRechargeCostCallback); }