diff --git a/source/game/StarQuestManager.cpp b/source/game/StarQuestManager.cpp index df8a19a..ee2c82b 100644 --- a/source/game/StarQuestManager.cpp +++ b/source/game/StarQuestManager.cpp @@ -144,7 +144,10 @@ StringMap QuestManager::serverQuests() const { } QuestPtr QuestManager::getQuest(String const& questId) const { - return m_quests.get(questId); + if (auto quest = m_quests.ptr(questId)) + return *quest; + + return {}; } bool QuestManager::hasQuest(String const& questId) const { diff --git a/source/game/StarQuests.cpp b/source/game/StarQuests.cpp index 6e1dba7..d0d9d99 100644 --- a/source/game/StarQuests.cpp +++ b/source/game/StarQuests.cpp @@ -216,6 +216,13 @@ Maybe Quest::receiveMessage(String const& message, bool localMessage, Json return m_scriptComponent.handleMessage(message, localMessage, args); } + +Maybe Quest::callScript(String const& func, LuaVariadic const& args) { + if (!m_inited) + return {}; + return m_scriptComponent.invoke(func, args); +} + void Quest::update(float dt) { if (!m_inited) return; @@ -599,12 +606,20 @@ void Quest::uninitScript() { LuaCallbacks Quest::makeQuestCallbacks(Player* player) { LuaCallbacks callbacks; + callbacks.registerCallback("context", [this]() { m_scriptComponent.context(); }); + callbacks.registerCallback("state", [this]() { return QuestStateNames.getRight(state()); }); callbacks.registerCallback("complete", [this](Maybe followup) { complete(followup); }); callbacks.registerCallback("fail", [this]() { fail(); }); + callbacks.registerCallback("abandon", [this]() { abandon(); }); + + callbacks.registerCallback("decline", [this]() { declineOffer(); }); + + callbacks.registerCallback("cancel", [this]() { cancelOffer(); }); + callbacks.registerCallback("setCanTurnIn", [this](bool value) { this->m_canTurnIn = value; }); callbacks.registerCallback("questId", [this]() { return questId(); }); diff --git a/source/game/StarQuests.hpp b/source/game/StarQuests.hpp index fc35f2b..6a4b128 100644 --- a/source/game/StarQuests.hpp +++ b/source/game/StarQuests.hpp @@ -45,6 +45,7 @@ public: void uninit(); Maybe receiveMessage(String const& message, bool localMessage, JsonArray const& args = {}); + Maybe callScript(String const& func, LuaVariadic const& args); void update(float dt); void offer(); diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index bf14c2c..7546567 100644 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -478,10 +478,17 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { }); callbacks.registerCallback("quest", [player](String const& questId) -> Json { - if (!player->questManager()->hasQuest(questId)) - return {}; + if (auto quest = player->questManager()->getQuest(questId)) + return quest->diskStore(); - return player->questManager()->getQuest(questId)->diskStore(); + return {}; + }); + + callbacks.registerCallback("callQuest", [player](String const& questId, String const& func, LuaVariadic const& args) -> Maybe { + if (auto quest = player->questManager()->getQuest(questId)) + return quest->callScript(func, args); + + return {}; }); callbacks.registerCallback("hasQuest", [player](String const& questId) {