Skip to content

Commit

Permalink
Enhanced Quests
Browse files Browse the repository at this point in the history
Enhanced Quest Log - add possibility to use more than one quest state
  • Loading branch information
SaiyansKing committed May 3, 2020
1 parent 7b23b35 commit 63503e1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
5 changes: 3 additions & 2 deletions data/XML/quests.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<quests>
<quest name="Example Quest I" startstorageid="1001" startstoragevalue="1">
<mission id="1" name="Example Mission 1" storageid="1001" startvalue="1" endvalue="3" ignoreendvalue="true">
<mission id="1" name="Example Mission 1" storageid="1001" startvalue="1" endvalue="1" description="Test mission: kill |STATE0|/250 rats and |STATE1|/500 rabbits" state0="1002" state1="1003" ignoreendvalue="true" />
<mission id="2" name="Example Mission 2" storageid="1001" startvalue="2" endvalue="3" ignoreendvalue="true">
<missionstate id="1" description="Example description 1" />
<missionstate id="2" description="Example description 2" />
<missionstate id="3" description="Example description 3" />
</mission>
<mission id="2" name="Example Mission 2" storageid="1001" startvalue="4" endvalue="5">
<mission id="3" name="Example Mission 3" storageid="1001" startvalue="4" endvalue="5">
<missionstate id="4" description="Example description 1" />
<missionstate id="5" description="Example description 2" />
</mission>
Expand Down
1 change: 1 addition & 0 deletions src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static constexpr auto STATUS_SERVER_DEVELOPERS = "Mark Samman and Saiyans King";
static constexpr auto AUTHENTICATOR_DIGITS = 6U;
static constexpr auto AUTHENTICATOR_PERIOD = 30U;

//
#define CLIENT_VERSION 1231
#define CLIENT_VERSION_UPPER (CLIENT_VERSION / 100)
#define CLIENT_VERSION_LOWER (CLIENT_VERSION % 100)
Expand Down
1 change: 1 addition & 0 deletions src/otserv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void mainLoader(int, char*[], ServiceManager* services)

std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << std::endl;
std::cout << "Visit our forum for updates, support, and resources: http://otland.net/." << std::endl;
std::cout << "Server protocol: " << CLIENT_VERSION_UPPER << "." << CLIENT_VERSION_LOWER << std::endl;
std::cout << std::endl;

// check if config.lua or config.lua.dist exist
Expand Down
10 changes: 6 additions & 4 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,12 @@ void Player::addStorageValue(const uint32_t key, const int32_t value, const bool
sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your questlog has been updated.");
}
#if GAME_FEATURE_QUEST_TRACKER > 0
auto missions = g_game.quests.getMissions(key);
for (auto mission : missions) {
if (hasTrackingQuest(mission->getMissionId())) {
sendUpdateTrackedQuest(mission);
if (!trackedQuests.empty()) {
auto missions = g_game.quests.getMissions(key);
for (auto mission : missions) {
if (hasTrackingQuest(mission->getMissionId())) {
sendUpdateTrackedQuest(mission);
}
}
}
#endif
Expand Down
24 changes: 22 additions & 2 deletions src/quests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ std::string Mission::getDescription(Player* player) const
if (!mainDescription.empty()) {
std::string desc = mainDescription;
replaceString(desc, "|STATE|", std::to_string(value));

for (const auto& missionState : states) {
player->getStorageValue(missionState.second, value);
replaceString(desc, (std::string("|STATE") + std::to_string(missionState.first) + std::string("|")), std::to_string(std::max<int32_t>(value, 0)));
}

replaceString(desc, "\\n", "\n");
return desc;
}
Expand Down Expand Up @@ -186,6 +192,17 @@ bool Quests::loadFromXml()
mission.mainDescription = mainDescription;
}

int32_t stateId = 0;
while (true) {
pugi::xml_attribute stateAttribute = missionNode.attribute((std::string("state") + std::to_string(stateId)).c_str());
if (stateAttribute) {
mission.states.emplace_back(stateId, pugi::cast<uint32_t>(stateAttribute.value()));
} else if (stateId > 0) {
break;
}
++stateId;
}

#if GAME_FEATURE_QUEST_TRACKER > 0
pugi::xml_attribute idAttribute = missionNode.attribute("id");
if (idAttribute) {
Expand All @@ -211,9 +228,12 @@ void Quests::makeCache()

for (const Quest& quest : quests) {
cachedLogQuests[quest.getStartStorageId()].push_back(&quest);

for (const Mission& mission : quest.getMissions()) {
cachedLogMissions[mission.getStorageId()].push_back(&mission);
for (const auto& missionState : mission.states) {
cachedLogMissions[missionState.second].push_back(&mission);
}

#if GAME_FEATURE_QUEST_TRACKER > 0
cachedMissions[mission.getMissionId()] = &mission;
#endif
Expand Down Expand Up @@ -278,7 +298,7 @@ bool Quests::isQuestStorage(const uint32_t key, const int32_t value, const int32
auto mit = cachedLogMissions.find(key);
if (mit != cachedLogMissions.end()) {
for (const Mission* mission : mit->second) {
if (value >= mission->getStartStorageValue() && value <= mission->getEndStorageValue()) {
if (mission->getStorageId() == key && value >= mission->getStartStorageValue() && value <= mission->getEndStorageValue()) {
return mission->mainDescription.empty() || oldValue < mission->getStartStorageValue() || oldValue > mission->getEndStorageValue();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/quests.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Mission
return endValue;
}

std::vector<std::pair<int32_t, uint32_t>> states;
std::map<int32_t, std::string> descriptions;
std::string mainDescription;

Expand Down

0 comments on commit 63503e1

Please sign in to comment.