summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-07-15 22:01:41 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2012-07-17 21:58:40 +0200
commit7a72ec38d336ed56d2759795d4b9db59b76868b8 (patch)
tree0bf377084dd44faaaae53b05a4b97af0829b6347 /src/game-server
parentf126afd524133f207c07d5eb52e3e774ab41604e (diff)
downloadmanaserv-7a72ec38d336ed56d2759795d4b9db59b76868b8.tar.gz
manaserv-7a72ec38d336ed56d2759795d4b9db59b76868b8.tar.bz2
manaserv-7a72ec38d336ed56d2759795d4b9db59b76868b8.tar.xz
manaserv-7a72ec38d336ed56d2759795d4b9db59b76868b8.zip
Added lua binds for issuing request of quest variable + bind for trying to read them
The difference to the old chr_get_quest bind is that this allows querying quest vars from non npc functions as well. Change is tested. Reviewed-by: bjorn.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/character.cpp1
-rw-r--r--src/game-server/quest.cpp22
-rw-r--r--src/game-server/quest.h55
3 files changed, 67 insertions, 11 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index 71427342..a053cd83 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -67,7 +67,6 @@ static bool executeCallback(Script::Ref function, Character *character)
script->prepare(function);
script->push(character);
script->execute();
- script->setMap(0);
return true;
}
diff --git a/src/game-server/quest.cpp b/src/game-server/quest.cpp
index c4cce8e4..4d659227 100644
--- a/src/game-server/quest.cpp
+++ b/src/game-server/quest.cpp
@@ -30,7 +30,7 @@
#include "game-server/eventlistener.h"
#include "utils/logger.h"
-typedef std::list< QuestCallback > QuestCallbacks;
+typedef std::list< QuestCallback * > QuestCallbacks;
typedef std::map< std::string, QuestCallbacks > PendingVariables;
struct PendingQuest
@@ -88,6 +88,21 @@ struct QuestDeathListener: EventDispatch
}
};
+void QuestRefCallback::triggerCallback(Character *ch,
+ const std::string &value) const
+{
+ if (!mRef.isValid())
+ return;
+
+ Script *s = ScriptManager::currentState();
+ s->setMap(ch->getMap());
+ s->prepare(mRef);
+ s->push(ch);
+ s->push(mQuestName);
+ s->push(value);
+ s->execute();
+}
+
static QuestDeathListener questDeathDummy;
static EventListener questDeathListener(&questDeathDummy);
@@ -112,7 +127,7 @@ void QuestDeathListener::fullRemove(const EventListener *, Character *ch)
}
void recoverQuestVar(Character *ch, const std::string &name,
- const QuestCallback &f)
+ QuestCallback *f)
{
assert(ch->questCache.find(name) == ch->questCache.end());
int id = ch->getDatabaseID();
@@ -153,7 +168,8 @@ void recoveredQuestVar(int id,
for (QuestCallbacks::const_iterator k = j->second.begin(),
k_end = j->second.end(); k != k_end; ++k)
{
- k->handler(ch, value, k->script);
+ (*k)->triggerCallback(ch, value);
+ delete (*k);
}
variables.erase(j);
diff --git a/src/game-server/quest.h b/src/game-server/quest.h
index 0125e84b..05caa6ab 100644
--- a/src/game-server/quest.h
+++ b/src/game-server/quest.h
@@ -23,16 +23,58 @@
#include <string>
+#include "scripting/scriptmanager.h"
+
class Character;
class Script;
-struct QuestCallback
+
+class QuestCallback
{
- void (*handler)(Character *,
- const std::string &value,
- Script *script);
+ public:
+ virtual ~QuestCallback()
+ { }
+
+ virtual void triggerCallback(Character *ch,
+ const std::string &value) const = 0;
+};
+
+class QuestThreadCallback : public QuestCallback
+{
+ public:
+ QuestThreadCallback(void (*handler)(Character *,
+ const std::string &value,
+ Script *mScript),
+ Script *script) :
+ mHandler(handler),
+ mScript(script)
+ { }
+
+ virtual void triggerCallback(Character *ch,
+ const std::string &value) const
+ { mHandler(ch, value, mScript); }
+
+ private:
+ void (*mHandler)(Character *,
+ const std::string &value,
+ Script *mScript);
+
+ Script *mScript;
+};
+
+class QuestRefCallback : public QuestCallback
+{
+ public:
+ QuestRefCallback(Script *script, const std::string &questName) :
+ mQuestName(questName)
+ { script->assignCallback(mRef); }
+
+ virtual void triggerCallback(Character *ch,
+ const std::string &value) const;
- Script *script;
+ private:
+ Script::Ref mRef;
+ std::string mQuestName;
};
/**
@@ -51,8 +93,7 @@ void setQuestVar(Character *, const std::string &name,
* Starts the recovery of a variable and returns immediatly. The callback will
* be called once the value has been recovered.
*/
-void recoverQuestVar(Character *, const std::string &name,
- const QuestCallback &);
+void recoverQuestVar(Character *, const std::string &name, QuestCallback *);
/**
* Called by the handler of the account server when a value is received.