diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-06-26 12:57:31 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-07-02 09:48:58 +0200 |
commit | 8a882e630fd2a4db3e7df391278f2cd795dac5f6 (patch) | |
tree | 81e39b3d5afa5d9563e9f834a8443ef64b9f292b | |
parent | 72d937f176abaaca814fb8407cf1b911e52aaffa (diff) | |
download | mana-8a882e630fd2a4db3e7df391278f2cd795dac5f6.tar.gz mana-8a882e630fd2a4db3e7df391278f2cd795dac5f6.tar.bz2 mana-8a882e630fd2a4db3e7df391278f2cd795dac5f6.tar.xz mana-8a882e630fd2a4db3e7df391278f2cd795dac5f6.zip |
Implemented effects for new and completed quests
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 18 | ||||
-rw-r--r-- | src/resources/questdb.cpp | 42 | ||||
-rw-r--r-- | src/resources/questdb.h | 9 |
4 files changed, 70 insertions, 0 deletions
@@ -2,6 +2,7 @@ - Ported to SDL 2 - Added VSync and windowed fullscreen options - Added support for scaling the graphics +- Added NPC quest indicators and a Quests window - Added ability to open external links in news, chat and NPC dialogs - Added ability to mention assigned keys in NPC dialogs - Added support for text formatting to NPC dialogs diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index e590d6e0..a5de7619 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -25,6 +25,7 @@ #include "being.h" #include "client.h" #include "configuration.h" +#include "effectmanager.h" #include "game.h" #include "localplayer.h" #include "log.h" @@ -525,9 +526,26 @@ void PlayerHandler::handleMessage(MessageIn &msg) { int variable = msg.readInt16(); int value = msg.readInt32(); + int oldValue = mQuestVars.get(variable); + mQuestVars.set(variable, value); updateQuestStatusEffects(); Event::trigger(Event::QuestsChannel, Event::QuestVarsChanged); + + if (effectManager && local_player) + { + switch (QuestDB::questChange(variable, oldValue, value)) + { + case QuestChange::None: + break; + case QuestChange::New: + effectManager->trigger(paths.getIntValue("newQuestEffectId"), local_player); + break; + case QuestChange::Completed: + effectManager->trigger(paths.getIntValue("completeQuestEffectId"), local_player); + break; + } + } break; } diff --git a/src/resources/questdb.cpp b/src/resources/questdb.cpp index 93ee3225..b2b8402e 100644 --- a/src/resources/questdb.cpp +++ b/src/resources/questdb.cpp @@ -182,4 +182,46 @@ std::vector<QuestEntry> getQuestsEntries(const QuestVars &questVars, return activeQuests; } +static std::pair<int, int> countQuestEntries(const Quest &quest, int value) +{ + int totalEntries = 0; + int completedEntries = 0; + + for (const auto &state : quest.states) + { + bool matchesIncomplete = contains(state.incomplete, value); + bool matchesComplete = contains(state.complete, value); + + if (matchesIncomplete || matchesComplete) + { + totalEntries++; + if (matchesComplete) + completedEntries++; + } + } + + return { totalEntries, completedEntries }; +} + +QuestChange questChange(int varId, int oldValue, int newValue) +{ + if (newValue == oldValue) + return QuestChange::None; + + auto questIt = quests.find(varId); + if (questIt == quests.end()) + return QuestChange::None; + + const Quest &quest = questIt->second; + + auto [oldQuestEntries, oldCompletedEntries] = countQuestEntries(quest, oldValue); + auto [newQuestEntries, newCompletedEntries] = countQuestEntries(quest, newValue); + + if (newCompletedEntries > oldCompletedEntries) + return QuestChange::Completed; + if (newQuestEntries > oldQuestEntries) + return QuestChange::New; + return QuestChange::None; +} + } // namespace QuestDB diff --git a/src/resources/questdb.h b/src/resources/questdb.h index e57655f8..5e943e76 100644 --- a/src/resources/questdb.h +++ b/src/resources/questdb.h @@ -114,6 +114,13 @@ struct QuestEntry const std::vector<QuestRow> &rows() const { return state->rows; } }; +enum class QuestChange +{ + None, + New, + Completed +}; + namespace QuestDB { void readQuestVarNode(XML::Node node, const std::string &filename); @@ -126,4 +133,6 @@ namespace QuestDB std::vector<QuestEntry> getQuestsEntries(const QuestVars &questVars, bool skipCompleted = false); + + QuestChange questChange(int varId, int oldValue, int newValue); }; |