add new quest Lua bindings to player
This commit is contained in:
parent
be884c33b4
commit
8aedf51957
@ -73,7 +73,11 @@ void QuestManager::setUniverseClient(UniverseClient* client) {
|
|||||||
|
|
||||||
void QuestManager::init(World* world) {
|
void QuestManager::init(World* world) {
|
||||||
m_world = world;
|
m_world = world;
|
||||||
serverQuests().exec([this, world](QuestPtr const& quest) { quest->init(m_player, world, m_client); });
|
for (auto& quest : m_quests) {
|
||||||
|
if (!questValidOnServer(quest.second))
|
||||||
|
continue;
|
||||||
|
quest.second->init(m_player, world, m_client);
|
||||||
|
}
|
||||||
m_trackOnWorldQuests = true;
|
m_trackOnWorldQuests = true;
|
||||||
|
|
||||||
// untrack tracked quest if it's not cross-server, and we're on a different server
|
// untrack tracked quest if it's not cross-server, and we're on a different server
|
||||||
@ -124,6 +128,21 @@ void QuestManager::offer(QuestPtr const& quest) {
|
|||||||
quest->offer();
|
quest->offer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringMap<QuestPtr> QuestManager::quests() const {
|
||||||
|
return m_quests;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringMap<QuestPtr> QuestManager::serverQuests() const {
|
||||||
|
StringMap<QuestPtr> filtered;
|
||||||
|
for (auto& pair : m_quests) {
|
||||||
|
QuestPtr q = pair.second;
|
||||||
|
if (!questValidOnServer(q))
|
||||||
|
continue;
|
||||||
|
filtered.insert(pair.first, q);
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
QuestPtr QuestManager::getQuest(String const& questId) const {
|
QuestPtr QuestManager::getQuest(String const& questId) const {
|
||||||
return m_quests.get(questId);
|
return m_quests.get(questId);
|
||||||
}
|
}
|
||||||
@ -184,33 +203,33 @@ bool QuestManager::canTurnIn(String const& questId) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Maybe<QuestPtr> QuestManager::getFirstNewQuest() {
|
Maybe<QuestPtr> QuestManager::getFirstNewQuest() {
|
||||||
for (auto& q : serverQuests()) {
|
for (auto& q : m_quests) {
|
||||||
if (q->state() == QuestState::Offer)
|
if (questValidOnServer(q.second) && q.second->state() == QuestState::Offer)
|
||||||
return q;
|
return q.second;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe<QuestPtr> QuestManager::getFirstCompletableQuest() {
|
Maybe<QuestPtr> QuestManager::getFirstCompletableQuest() {
|
||||||
for (auto& q : serverQuests()) {
|
for (auto& q : m_quests) {
|
||||||
if (q->state() == QuestState::Complete && q->showDialog())
|
if (questValidOnServer(q.second) && q.second->state() == QuestState::Complete && q.second->showDialog())
|
||||||
return q;
|
return q.second;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe<QuestPtr> QuestManager::getFirstFailableQuest() {
|
Maybe<QuestPtr> QuestManager::getFirstFailableQuest() {
|
||||||
for (auto& q : serverQuests()) {
|
for (auto& q : m_quests) {
|
||||||
if (q->state() == QuestState::Failed&& q->showDialog())
|
if (questValidOnServer(q.second) && q.second->state() == QuestState::Failed && q.second->showDialog())
|
||||||
return q;
|
return q.second;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe<QuestPtr> QuestManager::getFirstMainQuest() {
|
Maybe<QuestPtr> QuestManager::getFirstMainQuest() {
|
||||||
for (auto& q : serverQuests()) {
|
for (auto& q : m_quests) {
|
||||||
if (q->state() == QuestState::Active && q->mainQuest())
|
if (questValidOnServer(q.second) && q.second->state() == QuestState::Active && q.second->mainQuest())
|
||||||
return q;
|
return q.second;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -228,7 +247,7 @@ void sortQuests(List<QuestPtr>& quests) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<QuestPtr> QuestManager::listActiveQuests() const {
|
List<QuestPtr> QuestManager::listActiveQuests() const {
|
||||||
List<QuestPtr> result = serverQuests();
|
List<QuestPtr> result = serverQuests().values();
|
||||||
result.filter([&](QuestPtr quest) {
|
result.filter([&](QuestPtr quest) {
|
||||||
return quest->state() == QuestState::Active && quest->showInLog();
|
return quest->state() == QuestState::Active && quest->showInLog();
|
||||||
});
|
});
|
||||||
@ -237,7 +256,7 @@ List<QuestPtr> QuestManager::listActiveQuests() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<QuestPtr> QuestManager::listCompletedQuests() const {
|
List<QuestPtr> QuestManager::listCompletedQuests() const {
|
||||||
List<QuestPtr> result = serverQuests();
|
List<QuestPtr> result = serverQuests().values();
|
||||||
result.filter([](QuestPtr quest) {
|
result.filter([](QuestPtr quest) {
|
||||||
return quest->state() == QuestState::Complete && quest->showInLog();
|
return quest->state() == QuestState::Complete && quest->showInLog();
|
||||||
});
|
});
|
||||||
@ -246,7 +265,7 @@ List<QuestPtr> QuestManager::listCompletedQuests() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<QuestPtr> QuestManager::listFailedQuests() const {
|
List<QuestPtr> QuestManager::listFailedQuests() const {
|
||||||
List<QuestPtr> result = serverQuests();
|
List<QuestPtr> result = serverQuests().values();
|
||||||
result.filter([](QuestPtr quest) {
|
result.filter([](QuestPtr quest) {
|
||||||
return quest->state() == QuestState::Failed && quest->showInLog();
|
return quest->state() == QuestState::Failed && quest->showInLog();
|
||||||
});
|
});
|
||||||
@ -381,15 +400,10 @@ void QuestManager::update(float dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serverQuests().exec([dt](QuestPtr const& quest) { quest->update(dt); });
|
for (auto& q : m_quests) {
|
||||||
}
|
if (questValidOnServer(q.second))
|
||||||
|
q.second->update(dt);
|
||||||
List<QuestPtr> QuestManager::serverQuests() const {
|
}
|
||||||
return m_quests.values().filtered([this](QuestPtr const& q) -> bool {
|
|
||||||
if (q->hideCrossServer() && q->serverUuid().isValid() && *q->serverUuid() != m_player->clientContext()->serverUuid())
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuestManager::startInitialQuests() {
|
void QuestManager::startInitialQuests() {
|
||||||
@ -408,4 +422,8 @@ void QuestManager::setMostRecentQuestCurrent() {
|
|||||||
setAsTracked(sortedActiveQuests.last()->questId());
|
setAsTracked(sortedActiveQuests.last()->questId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QuestManager::questValidOnServer(QuestPtr q) const {
|
||||||
|
return !(q->hideCrossServer() && q->serverUuid().isValid() && *q->serverUuid() != m_player->clientContext()->serverUuid());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,9 @@ public:
|
|||||||
// Show a dialog offering the player a quest, and later start it if they
|
// Show a dialog offering the player a quest, and later start it if they
|
||||||
// accept it.
|
// accept it.
|
||||||
void offer(QuestPtr const& quest);
|
void offer(QuestPtr const& quest);
|
||||||
|
StringMap<QuestPtr> quests() const;
|
||||||
|
// Only returns quests that are exclusive to the current server.
|
||||||
|
StringMap<QuestPtr> serverQuests() const;
|
||||||
QuestPtr getQuest(String const& questId) const;
|
QuestPtr getQuest(String const& questId) const;
|
||||||
|
|
||||||
bool hasQuest(String const& questId) const;
|
bool hasQuest(String const& questId) const;
|
||||||
@ -60,9 +63,9 @@ public:
|
|||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
List<QuestPtr> serverQuests() const;
|
|
||||||
void startInitialQuests();
|
void startInitialQuests();
|
||||||
void setMostRecentQuestCurrent();
|
void setMostRecentQuestCurrent();
|
||||||
|
bool questValidOnServer(QuestPtr quest) const;
|
||||||
|
|
||||||
Player* m_player;
|
Player* m_player;
|
||||||
World* m_world;
|
World* m_world;
|
||||||
|
@ -453,6 +453,21 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
|
|||||||
return followUp->questId();
|
return followUp->questId();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("questIds", [player]() {
|
||||||
|
return player->questManager()->quests().keys();
|
||||||
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("serverQuestIds", [player]() {
|
||||||
|
return player->questManager()->serverQuests().keys();
|
||||||
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("quest", [player](String const& questId) -> Json {
|
||||||
|
if (!player->questManager()->hasQuest(questId))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return player->questManager()->getQuest(questId)->diskStore();
|
||||||
|
});
|
||||||
|
|
||||||
callbacks.registerCallback("hasQuest", [player](String const& questId) {
|
callbacks.registerCallback("hasQuest", [player](String const& questId) {
|
||||||
return player->questManager()->hasQuest(questId);
|
return player->questManager()->hasQuest(questId);
|
||||||
});
|
});
|
||||||
@ -469,11 +484,26 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
|
|||||||
return player->questManager()->hasCompleted(questId);
|
return player->questManager()->hasCompleted(questId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("setTrackedQuest", [player](Maybe<String> const& questId) {
|
||||||
|
return player->questManager()->setAsTracked(questId);
|
||||||
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("canTurnInQuest", [player](String const& questId) {
|
||||||
|
return player->questManager()->canTurnIn(questId);
|
||||||
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallback("currentQuest", [player]() -> Json {
|
||||||
|
auto maybeQuest = player->questManager()->currentQuest();
|
||||||
|
if (maybeQuest) {
|
||||||
|
return (*maybeQuest)->diskStore();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
callbacks.registerCallback("currentQuestWorld", [player]() -> Maybe<String> {
|
callbacks.registerCallback("currentQuestWorld", [player]() -> Maybe<String> {
|
||||||
auto maybeQuest = player->questManager()->currentQuest();
|
auto maybeQuest = player->questManager()->currentQuest();
|
||||||
if (maybeQuest) {
|
if (maybeQuest) {
|
||||||
auto quest = *maybeQuest;
|
if (auto worldId = (*maybeQuest)->worldId())
|
||||||
if (auto worldId = quest->worldId())
|
|
||||||
return printWorldId(*worldId);
|
return printWorldId(*worldId);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user