player.callQuest
This commit is contained in:
parent
250869e215
commit
73e9ab3b8e
@ -144,7 +144,10 @@ StringMap<QuestPtr> QuestManager::serverQuests() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QuestPtr QuestManager::getQuest(String const& questId) 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 {
|
bool QuestManager::hasQuest(String const& questId) const {
|
||||||
|
@ -216,6 +216,13 @@ Maybe<Json> Quest::receiveMessage(String const& message, bool localMessage, Json
|
|||||||
return m_scriptComponent.handleMessage(message, localMessage, args);
|
return m_scriptComponent.handleMessage(message, localMessage, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Maybe<LuaValue> Quest::callScript(String const& func, LuaVariadic<LuaValue> const& args) {
|
||||||
|
if (!m_inited)
|
||||||
|
return {};
|
||||||
|
return m_scriptComponent.invoke(func, args);
|
||||||
|
}
|
||||||
|
|
||||||
void Quest::update(float dt) {
|
void Quest::update(float dt) {
|
||||||
if (!m_inited)
|
if (!m_inited)
|
||||||
return;
|
return;
|
||||||
@ -599,12 +606,20 @@ void Quest::uninitScript() {
|
|||||||
LuaCallbacks Quest::makeQuestCallbacks(Player* player) {
|
LuaCallbacks Quest::makeQuestCallbacks(Player* player) {
|
||||||
LuaCallbacks callbacks;
|
LuaCallbacks callbacks;
|
||||||
|
|
||||||
|
callbacks.registerCallback("context", [this]() { m_scriptComponent.context(); });
|
||||||
|
|
||||||
callbacks.registerCallback("state", [this]() { return QuestStateNames.getRight(state()); });
|
callbacks.registerCallback("state", [this]() { return QuestStateNames.getRight(state()); });
|
||||||
|
|
||||||
callbacks.registerCallback("complete", [this](Maybe<size_t> followup) { complete(followup); });
|
callbacks.registerCallback("complete", [this](Maybe<size_t> followup) { complete(followup); });
|
||||||
|
|
||||||
callbacks.registerCallback("fail", [this]() { fail(); });
|
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("setCanTurnIn", [this](bool value) { this->m_canTurnIn = value; });
|
||||||
|
|
||||||
callbacks.registerCallback("questId", [this]() { return questId(); });
|
callbacks.registerCallback("questId", [this]() { return questId(); });
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
void uninit();
|
void uninit();
|
||||||
|
|
||||||
Maybe<Json> receiveMessage(String const& message, bool localMessage, JsonArray const& args = {});
|
Maybe<Json> receiveMessage(String const& message, bool localMessage, JsonArray const& args = {});
|
||||||
|
Maybe<LuaValue> callScript(String const& func, LuaVariadic<LuaValue> const& args);
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
void offer();
|
void offer();
|
||||||
|
@ -478,10 +478,17 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
callbacks.registerCallback("quest", [player](String const& questId) -> Json {
|
callbacks.registerCallback("quest", [player](String const& questId) -> Json {
|
||||||
if (!player->questManager()->hasQuest(questId))
|
if (auto quest = player->questManager()->getQuest(questId))
|
||||||
return {};
|
return quest->diskStore();
|
||||||
|
|
||||||
return player->questManager()->getQuest(questId)->diskStore();
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("callQuest", [player](String const& questId, String const& func, LuaVariadic<LuaValue> const& args) -> Maybe<LuaValue> {
|
||||||
|
if (auto quest = player->questManager()->getQuest(questId))
|
||||||
|
return quest->callScript(func, args);
|
||||||
|
|
||||||
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
callbacks.registerCallback("hasQuest", [player](String const& questId) {
|
callbacks.registerCallback("hasQuest", [player](String const& questId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user