Skip to content

Commit

Permalink
fix: move loading of achievements to player login
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Mar 12, 2024
1 parent 5ba510d commit a3180b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/creatures/players/achievement/player_achievement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@
#include "kv/kv.hpp"

PlayerAchievement::PlayerAchievement(Player &player) :
m_player(player) {
auto unlockedAchievements = getUnlockedKV()->keys();
for (const auto &achievementName : unlockedAchievements) {
const Achievement &achievement = g_game().getAchievementByName(achievementName);
if (achievement.id == 0) {
g_logger().error("[{}] - Achievement {} not found.", __FUNCTION__, achievementName);
continue;
}

m_achievementsUnlocked.push_back({ achievement.id, getUnlockedKV()->get(achievementName)->getNumber() });
}
}
m_player(player) { }

bool PlayerAchievement::add(uint16_t id, bool message /* = true*/, uint32_t timestamp /* = 0*/) {
if (isUnlocked(id)) {
Expand Down Expand Up @@ -108,6 +97,22 @@ std::vector<std::pair<uint16_t, uint32_t>> PlayerAchievement::getUnlockedAchieve
return m_achievementsUnlocked;
}

void PlayerAchievement::loadUnlockedAchievements() {
const auto &unlockedAchievements = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked achievements: {}", __FUNCTION__, unlockedAchievements.size());
for (const auto &achievementName : unlockedAchievements) {
const Achievement &achievement = g_game().getAchievementByName(achievementName);
if (achievement.id == 0) {
g_logger().error("[{}] - Achievement {} not found.", __FUNCTION__, achievementName);
continue;
}

g_logger().debug("[{}] - Achievement {} found for player {}.", __FUNCTION__, achievementName, m_player.getName());

m_achievementsUnlocked.push_back({ achievement.id, getUnlockedKV()->get(achievementName)->getNumber() });
}
}

void PlayerAchievement::sendUnlockedSecretAchievements() {
std::vector<std::pair<Achievement, uint32_t>> m_achievementsUnlocked;
uint16_t unlockedSecret = 0;
Expand Down
1 change: 1 addition & 0 deletions src/creatures/players/achievement/player_achievement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PlayerAchievement {
void addPoints(uint16_t toAddPoints);
void removePoints(uint16_t toRemovePoints);
std::vector<std::pair<uint16_t, uint32_t>> getUnlockedAchievements() const;
void loadUnlockedAchievements();
void sendUnlockedSecretAchievements();
const std::shared_ptr<KV> &getUnlockedKV();

Expand Down
3 changes: 3 additions & 0 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pch.hpp"

#include "creatures/players/wheel/player_wheel.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "io/functions/iologindata_load_player.hpp"
#include "game/game.hpp"
#include "enums/object_category.hpp"
Expand Down Expand Up @@ -887,6 +888,8 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr<Player> player)
player->wheel()->loadDBPlayerSlotPointsOnLogin();
player->wheel()->initializePlayerData();

player->achiev()->loadUnlockedAchievements();

player->initializePrey();
player->initializeTaskHunting();
}
Expand Down

0 comments on commit a3180b4

Please sign in to comment.