From 1298faf172849f3232da30da7e0b4058c377aa77 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Fri, 26 Apr 2024 16:28:07 -0300 Subject: [PATCH] Created function to check titles of player. --- .../players/cyclopedia/player_title.cpp | 81 +++++++++++++++++++ src/game/game.cpp | 10 +++ src/game/game.hpp | 3 +- 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/creatures/players/cyclopedia/player_title.cpp b/src/creatures/players/cyclopedia/player_title.cpp index e0b63a8d989..57d08307fc6 100644 --- a/src/creatures/players/cyclopedia/player_title.cpp +++ b/src/creatures/players/cyclopedia/player_title.cpp @@ -76,6 +76,87 @@ std::string PlayerTitle::getCurrentTitleName() const { } void PlayerTitle::checkAndUpdateNewTitles() { + Benchmark bm_checkTitles; + + // CyclopediaTitleType_t::GOLD + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::GOLD)) { + if (checkGold(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::MOUNTS + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::MOUNTS)) { + if (checkMount(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::OUTFITS + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::OUTFITS)) { + if (checkOutfit(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::LEVEL + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::LEVEL)) { + if (checkLevel(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::HIGHSCORES + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::HIGHSCORES)) { + if (checkHighscore(title.m_skill)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::BESTIARY + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::BESTIARY)) { + if (checkBestiary(title.m_race)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::LOGIN + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::LOGIN)) { + if (checkLoginStreak(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::TASK + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::TASK)) { + if (checkTask(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::MAP + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::MAP)) { + if (checkMap(title.m_amount)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::QUEST + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::QUEST)) { + if (checkQuest(title.m_storage)) { + add(title.m_id); + } + } + + // CyclopediaTitleType_t::OTHERS + for (const auto &title : g_game().getTitlesByType(CyclopediaTitleType_t::OTHERS)) { + if (checkOther(title.m_maleName)) { + add(title.m_id); + } + } + + auto duration = bm_checkTitles.duration(); + g_logger().debug("Checking and updating titles of player {} took {} milliseconds.", m_player.getName(), duration); loadUnlockedTitles(); } diff --git a/src/game/game.cpp b/src/game/game.cpp index 20f2506c764..f4278501f0c 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -10685,3 +10685,13 @@ Title Game::getTitleByIdOrName(uint8_t id, const std::string &name /*= ""*/) { } return {}; } + +std::vector Game::getTitlesByType(CyclopediaTitleType_t type) { + std::vector<Title> titlesFound; + for (const auto &title : getTitles()) { + if (title.m_type == type) { + titlesFound.push_back(title); + } + } + return titlesFound; +} diff --git a/src/game/game.hpp b/src/game/game.hpp index 8691fbdd733..031f9c6051f 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -729,7 +729,8 @@ class Game { std::unordered_set<Title> getTitles(); Title getTitleByIdOrName(uint8_t id, const std::string &name = ""); - + std::vector<Title> getTitlesByType(CyclopediaTitleType_t type); + private: std::map<uint16_t, Achievement> m_achievements; std::map<std::string, uint16_t> m_achievementsNameToId;