Skip to content

Commit

Permalink
Code format - (Clang-format)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 12, 2024
1 parent 45ed0c6 commit 0c148ac
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 517 deletions.
2 changes: 1 addition & 1 deletion src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void CanaryServer::loadModules() {
modulesLoadHelper((g_npcs().load(false, true)), "npc");

g_game().loadBoostedCreature();
// TODO: g_game().initializeCyclopedia();
// TODO: g_game().initializeCyclopedia();
// TODO: verify g_game().initializeGameWorldHighscores();
g_ioBosstiary().loadBoostedBoss();
g_ioprey().initializeTaskHuntOptions();
Expand Down
72 changes: 36 additions & 36 deletions src/creatures/players/cyclopedia/player_badge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ PlayerBadge::PlayerBadge(Player &player) :
m_player(player) { }

bool PlayerBadge::hasBadge(uint8_t id) const {
if (id == 0) {
return false;
}
if (id == 0) {
return false;
}

if (auto it = std::find_if(m_badgesUnlocked.begin(), m_badgesUnlocked.end(), [id](auto badge_it) {
return badge_it.first == id;
Expand All @@ -34,47 +34,47 @@ bool PlayerBadge::hasBadge(uint8_t id) const {
}

bool PlayerBadge::add(uint8_t id, uint32_t timestamp /* = 0*/) {
if (hasBadge(id)) {
return false;
}

const Badge &badge = g_game().getBadgeById(id);
if (badge.m_id == 0) {
return false;
}

int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000);
getUnlockedKV()->set(badge.m_name, toSaveTimeStamp);
m_badgesUnlocked.push_back({badge.m_id, toSaveTimeStamp});
m_badgesUnlocked.shrink_to_fit();
return true;
if (hasBadge(id)) {
return false;
}

const Badge &badge = g_game().getBadgeById(id);
if (badge.m_id == 0) {
return false;
}

int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000);
getUnlockedKV()->set(badge.m_name, toSaveTimeStamp);
m_badgesUnlocked.push_back({ badge.m_id, toSaveTimeStamp });
m_badgesUnlocked.shrink_to_fit();
return true;
}

std::vector<std::pair<uint8_t, uint32_t>> PlayerBadge::getUnlockedBadges() const {
return m_badgesUnlocked;
return m_badgesUnlocked;
}

void PlayerBadge::loadUnlockedBadges() {
const auto &unlockedBadges = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked badges: {}", __FUNCTION__, unlockedBadges.size());
for (const auto &uBadge: unlockedBadges) {
auto id = static_cast<uint8_t>(std::stoul(uBadge));
const Badge &badge = g_game().getBadgeById(static_cast<uint8_t>(id));
if (badge.m_id == 0) {
g_logger().error("[{}] - Badge {} not found.", __FUNCTION__, uBadge);
continue;
}

g_logger().debug("[{}] - Badge {} found for player {}.", __FUNCTION__, badge.m_name, m_player.getName());

m_badgesUnlocked.push_back({badge.m_id, getUnlockedKV()->get(uBadge)->getNumber()});
}
const auto &unlockedBadges = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked badges: {}", __FUNCTION__, unlockedBadges.size());
for (const auto &uBadge : unlockedBadges) {
auto id = static_cast<uint8_t>(std::stoul(uBadge));
const Badge &badge = g_game().getBadgeById(static_cast<uint8_t>(id));
if (badge.m_id == 0) {
g_logger().error("[{}] - Badge {} not found.", __FUNCTION__, uBadge);
continue;
}

g_logger().debug("[{}] - Badge {} found for player {}.", __FUNCTION__, badge.m_name, m_player.getName());

m_badgesUnlocked.push_back({ badge.m_id, getUnlockedKV()->get(uBadge)->getNumber() });
}
}

const std::shared_ptr<KV> &PlayerBadge::getUnlockedKV() {
if (m_badgeUnlockedKV == nullptr) {
m_badgeUnlockedKV = m_player.kv()->scoped("badges")->scoped("unlocked");
}
if (m_badgeUnlockedKV == nullptr) {
m_badgeUnlockedKV = m_player.kv()->scoped("badges")->scoped("unlocked");
}

return m_badgeUnlockedKV;
return m_badgeUnlockedKV;
}
46 changes: 23 additions & 23 deletions src/creatures/players/cyclopedia/player_badge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@ class Player;
class KV;

struct Badge {
uint8_t m_id = 0;
CyclopediaBadgeType_t m_type;
std::string m_name;
uint16_t m_amount = 0;
uint8_t m_id = 0;
CyclopediaBadgeType_t m_type;
std::string m_name;
uint16_t m_amount = 0;

Badge() = default;
Badge() = default;

Badge(uint8_t id, CyclopediaBadgeType_t type, const std::string &name, uint16_t amount) :
m_id(id), m_type(type), m_name(name), m_amount(amount) {}
Badge(uint8_t id, CyclopediaBadgeType_t type, const std::string &name, uint16_t amount) :
m_id(id), m_type(type), m_name(name), m_amount(amount) { }

bool operator==(const Badge &other) const {
return m_id == other.m_id;
}
bool operator==(const Badge &other) const {
return m_id == other.m_id;
}
};

namespace std {
template<>
struct hash<Badge> {
std::size_t operator()(const Badge &b) const {
return hash<uint8_t>()(b.m_id); // Use o ID como base para o hash
}
};
template <>
struct hash<Badge> {
std::size_t operator()(const Badge &b) const {
return hash<uint8_t>()(b.m_id); // Use o ID como base para o hash
}
};
}

class PlayerBadge {
public:
explicit PlayerBadge(Player &player);

bool hasBadge(uint8_t id) const;
bool add(uint8_t id, uint32_t timestamp = 0);
std::vector<std::pair<uint8_t, uint32_t>> getUnlockedBadges() const;
void loadUnlockedBadges();
const std::shared_ptr<KV> &getUnlockedKV();
bool add(uint8_t id, uint32_t timestamp = 0);
std::vector<std::pair<uint8_t, uint32_t>> getUnlockedBadges() const;
void loadUnlockedBadges();
const std::shared_ptr<KV> &getUnlockedKV();

private:
// {badge ID, time when it was unlocked}
std::shared_ptr<KV> m_badgeUnlockedKV;
std::vector<std::pair<uint8_t, uint32_t>> m_badgesUnlocked;
// {badge ID, time when it was unlocked}
std::shared_ptr<KV> m_badgeUnlockedKV;
std::vector<std::pair<uint8_t, uint32_t>> m_badgesUnlocked;
Player &m_player;
};
2 changes: 1 addition & 1 deletion src/creatures/players/cyclopedia/player_cyclopedia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ class PlayerCyclopedia {

std::vector<RecentDeathEntry> m_deathHistory;
std::vector<RecentPvPKillEntry> m_pvpKillsHistory;
// std::map<uint8_t, std::vector<uint16_t>> m_accountLevelSummary;
// std::map<uint8_t, std::vector<uint16_t>> m_accountLevelSummary;
};
90 changes: 45 additions & 45 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@ PlayerTitle::PlayerTitle(Player &player) :
m_player(player) { }

bool PlayerTitle::isTitleUnlocked(uint8_t id) const {
if (id == 0) {
return false;
}

if (auto it = std::find_if(m_titlesUnlocked.begin(), m_titlesUnlocked.end(), [id](auto title_it) {
return title_it == id;
});
it != m_titlesUnlocked.end()) {
return true;
}

return false;
if (id == 0) {
return false;
}

if (auto it = std::find_if(m_titlesUnlocked.begin(), m_titlesUnlocked.end(), [id](auto title_it) {
return title_it == id;
});
it != m_titlesUnlocked.end()) {
return true;
}

return false;
}

bool PlayerTitle::add(uint8_t id, uint32_t timestamp /* = 0*/) {
if (isTitleUnlocked(id)) {
return false;
}

const Title &title = g_game().getTitleById(id);
if (title.m_id == 0) {
return false;
}

int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000);
getUnlockedKV()->set(title.m_maleName, toSaveTimeStamp);
m_titlesUnlocked.push_back({title.m_id, toSaveTimeStamp});
m_titlesUnlocked.shrink_to_fit();
return true;
if (isTitleUnlocked(id)) {
return false;
}

const Title &title = g_game().getTitleById(id);
if (title.m_id == 0) {
return false;
}

int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000);
getUnlockedKV()->set(title.m_maleName, toSaveTimeStamp);
m_titlesUnlocked.push_back({ title.m_id, toSaveTimeStamp });
m_titlesUnlocked.shrink_to_fit();
return true;
}

std::vector<std::pair<uint8_t, uint32_t>> PlayerTitle::getUnlockedTitles() const {
return m_titlesUnlocked;
return m_titlesUnlocked;
}

uint8_t PlayerTitle::getCurrentTitle() const {
Expand All @@ -77,26 +77,26 @@ void PlayerTitle::setCurrentTitle(uint8_t id) {
}

void PlayerTitle::loadUnlockedTitles() {
const auto &unlockedTitles = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked titles: {}", __FUNCTION__, unlockedTitles.size());
for (const auto &uTitle: unlockedTitles) {
auto id = static_cast<uint8_t>(std::stoul(uTitle));
const Title &title = g_game().getTitleById(static_cast<uint8_t>(id));
if (title.m_id == 0) {
g_logger().error("[{}] - Title {} not found.", __FUNCTION__, uTitle);
continue;
}

g_logger().debug("[{}] - Title {} found for player {}.", __FUNCTION__, title.m_maleName, m_player.getName());

m_titlesUnlocked.push_back({title.m_id, getUnlockedKV()->get(uTitle)->getNumber()});
}
const auto &unlockedTitles = getUnlockedKV()->keys();
g_logger().debug("[{}] - Loading unlocked titles: {}", __FUNCTION__, unlockedTitles.size());
for (const auto &uTitle : unlockedTitles) {
auto id = static_cast<uint8_t>(std::stoul(uTitle));
const Title &title = g_game().getTitleById(static_cast<uint8_t>(id));
if (title.m_id == 0) {
g_logger().error("[{}] - Title {} not found.", __FUNCTION__, uTitle);
continue;
}

g_logger().debug("[{}] - Title {} found for player {}.", __FUNCTION__, title.m_maleName, m_player.getName());

m_titlesUnlocked.push_back({ title.m_id, getUnlockedKV()->get(uTitle)->getNumber() });
}
}

const std::shared_ptr<KV> &PlayerTitle::getUnlockedKV() {
if (m_titleUnlockedKV == nullptr) {
m_titleUnlockedKV = m_player.kv()->scoped("titles")->scoped("unlocked");
}
if (m_titleUnlockedKV == nullptr) {
m_titleUnlockedKV = m_player.kv()->scoped("titles")->scoped("unlocked");
}

return m_titleUnlockedKV;
return m_titleUnlockedKV;
}
Loading

0 comments on commit 0c148ac

Please sign in to comment.