Skip to content

Commit

Permalink
Created function to check titles of player.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Apr 26, 2024
1 parent c78f2ce commit 1298faf
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 10 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10685,3 +10685,13 @@ Title Game::getTitleByIdOrName(uint8_t id, const std::string &name /*= ""*/) {
}
return {};
}

std::vector<Title> 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;
}
3 changes: 2 additions & 1 deletion src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1298faf

Please sign in to comment.