summaryrefslogtreecommitdiff
path: root/src/game-server/monster.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-02 23:17:07 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-03 21:24:45 +0100
commit84c87cc99be29a694f0ffe83ab7a06ae433bb0cd (patch)
tree9180b67970e62707ee0fe2fee19cbe2e0b829122 /src/game-server/monster.cpp
parentf872528771f0b71741fb36ddf70f2ae23f54c1e3 (diff)
downloadmanaserv-84c87cc99be29a694f0ffe83ab7a06ae433bb0cd.tar.gz
manaserv-84c87cc99be29a694f0ffe83ab7a06ae433bb0cd.tar.bz2
manaserv-84c87cc99be29a694f0ffe83ab7a06ae433bb0cd.tar.xz
manaserv-84c87cc99be29a694f0ffe83ab7a06ae433bb0cd.zip
Use callbacks for items, monsters and status effects
Previously, global function names were defined in the respective XML definitions of items, monsters and status effects. This was reasonable when they all had the same state, but now they're sharing the single global Lua state. Now the Lua API provides access to the ItemClass, MonsterClass and StatusEffect instances, on which callbacks for both standard and custom events can be explicitly set. Reviewed-by: Erik Schilling
Diffstat (limited to 'src/game-server/monster.cpp')
-rw-r--r--src/game-server/monster.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 21eeea7c..b82f4638 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -28,7 +28,6 @@
#include "game-server/item.h"
#include "game-server/mapcomposite.h"
#include "game-server/state.h"
-#include "scripting/script.h"
#include "scripting/scriptmanager.h"
#include "utils/logger.h"
#include "utils/speedconv.h"
@@ -140,16 +139,20 @@ void Monster::perform()
int hit = performAttack(mTarget, dmg);
- if (! mCurrentAttack->scriptFunction.empty()
+ if (! mCurrentAttack->scriptEvent.empty()
&& hit > -1)
{
- Script *script = ScriptManager::currentState();
- script->setMap(getMap());
- script->prepare(mCurrentAttack->scriptFunction);
- script->push(this);
- script->push(mTarget);
- script->push(hit);
- script->execute();
+ Script::Ref function = mSpecy->getEventCallback(mCurrentAttack->scriptEvent);
+ if (function.isValid())
+ {
+ Script *script = ScriptManager::currentState();
+ script->setMap(getMap());
+ script->prepare(function);
+ script->push(this);
+ script->push(mTarget);
+ script->push(hit);
+ script->execute();
+ }
}
}
}
@@ -180,11 +183,14 @@ void Monster::update()
return;
}
- Script *script = ScriptManager::currentState();
- script->setMap(getMap());
- script->prepare("update_monster");
- script->push(this);
- script->execute();
+ if (mSpecy->getUpdateCallback().isValid())
+ {
+ Script *script = ScriptManager::currentState();
+ script->setMap(getMap());
+ script->prepare(mSpecy->getUpdateCallback());
+ script->push(this);
+ script->execute();
+ }
// Cancel the rest when we are currently performing an attack
if (isTimerRunning(T_M_ATTACK_TIME))