summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2010-03-22 21:55:34 +0100
committerPhilipp Sehmisch <mana@crushnet.org>2010-04-11 18:27:20 +0200
commitf3ad48f5ce2b3b584870674e58a7265779b3836b (patch)
tree73323079c2accbdf20f4617be21506c556e66329 /src
parente0669e4025e3772590cbde835d79fb06efea04fa (diff)
downloadmanaserv-f3ad48f5ce2b3b584870674e58a7265779b3836b.tar.gz
manaserv-f3ad48f5ce2b3b584870674e58a7265779b3836b.tar.xz
manaserv-f3ad48f5ce2b3b584870674e58a7265779b3836b.zip
Added global lua event script (only on_being_death_accept for now)
Reviewed-by: Jared Adams <Jaxad0127@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/game-server/character.cpp35
-rw-r--r--src/game-server/main-game.cpp7
-rw-r--r--src/scripting/script.cpp1
-rw-r--r--src/scripting/script.hpp2
4 files changed, 36 insertions, 9 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index 266a9b9..60b767a 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -185,19 +185,36 @@ void Character::respawn()
return;
}
- //warp back to spawn point
- int spawnMap = Configuration::getValue("respawnMap", 1);
- int spawnX = Configuration::getValue("respawnX", 1024);
- int spawnY = Configuration::getValue("respawnY", 1024);
- GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY);
-
//make alive again
setAction(STAND);
- mAttributes[BASE_ATTR_HP].mod = -mAttributes[BASE_ATTR_HP].base + 1;
- modifiedAttribute(BASE_ATTR_HP);
-
// reset target
mTarget = NULL;
+
+ // execute respawn script
+ bool isScriptHandled = false;
+ Script *script = Script::global_event_script;
+ if (script)
+ {
+ script->setMap(getMap());
+ script->prepare("on_chr_death_accept");
+ script->push(this);
+ script->execute();
+ isScriptHandled = true; // TODO: don't set to true when execution failed
+ script->setMap(NULL);
+ }
+
+ if (!isScriptHandled)
+ {
+ // script-controlled respawning didn't work - fall back to
+ // hardcoded logic
+ mAttributes[BASE_ATTR_HP].mod = -mAttributes[BASE_ATTR_HP].base + 1;
+ modifiedAttribute(BASE_ATTR_HP); //warp back to spawn point
+ int spawnMap = Configuration::getValue("respawnMap", 1);
+ int spawnX = Configuration::getValue("respawnX", 1024);
+ int spawnY = Configuration::getValue("respawnY", 1024);
+ GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY);
+ }
+
}
void Character::useSpecial(int id)
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index cb6ea41..3ad265f 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -50,6 +50,7 @@
#include "net/bandwidth.hpp"
#include "net/connectionhandler.hpp"
#include "net/messageout.hpp"
+#include "scripting/luascript.hpp"
#include "utils/logger.h"
#include "utils/processorutils.hpp"
#include "utils/stringfilter.h"
@@ -172,6 +173,12 @@ void initialize()
MonsterManager::initialize(DEFAULT_MONSTERSDB_FILE);
StatusManager::initialize(DEFAULT_STATUSDB_FILE);
PermissionManager::initialize(DEFAULT_PERMISSION_FILE);
+ // Initialize global event script
+ Script::global_event_script = new LuaScript();
+ if (!Script::global_event_script->loadFile("scripts/global_events.lua"))
+ {
+ Script::global_event_script = NULL;
+ }
// --- Initialize the global handlers
// FIXME: Make the global handlers global vars or part of a bigger
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index 8c3b2af..12c4417 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -29,6 +29,7 @@
typedef std::map< std::string, Script::Factory > Engines;
static Engines *engines = NULL;
+Script *Script::global_event_script = NULL;
Script::Script():
mMap(NULL),
diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp
index e11e5cc..74925e8 100644
--- a/src/scripting/script.hpp
+++ b/src/scripting/script.hpp
@@ -131,6 +131,8 @@ class Script
virtual void processRemoveEvent(Thing* thing) = 0;
+ static Script* global_event_script; // the global event script
+
protected:
std::string mScriptFile;