From 79a0ef8d8192e04a89906823112ec110157ca8a0 Mon Sep 17 00:00:00 2001 From: Beats Date: Wed, 27 Mar 2024 20:45:39 -0300 Subject: [PATCH] improve --- data/XML/imbuements.xml | 2 +- src/creatures/players/imbuements/imbuements.cpp | 14 +++++++------- src/creatures/players/imbuements/imbuements.hpp | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/XML/imbuements.xml b/data/XML/imbuements.xml index e7093d60418..b0c5b26416c 100644 --- a/data/XML/imbuements.xml +++ b/data/XML/imbuements.xml @@ -439,7 +439,7 @@ - + diff --git a/src/creatures/players/imbuements/imbuements.cpp b/src/creatures/players/imbuements/imbuements.cpp index 910d83cb551..9ea73f3070a 100644 --- a/src/creatures/players/imbuements/imbuements.cpp +++ b/src/creatures/players/imbuements/imbuements.cpp @@ -16,7 +16,7 @@ SkillMapId skillMap = { { "sword", SKILL_SWORD }, { "axe", SKILL_AXE }, { "club", SKILL_CLUB }, { "dist", SKILL_DISTANCE }, { "distance", SKILL_DISTANCE }, { "fish", SKILL_FISHING }, { "shield", SKILL_SHIELD }, { "fist", SKILL_FIST }, { "magicpoints", STAT_MAGICPOINTS }, { "critical", SKILL_CRITICAL_HIT_DAMAGE }, { "lifeleech", SKILL_LIFE_LEECH_AMOUNT }, { "manaleech", SKILL_MANA_LEECH_AMOUNT } }; -std::shared_ptr Imbuements::getImbuement(uint16_t id) { +std::shared_ptr Imbuements::getImbuement(uint16_t id) const { if (id == 0) { return nullptr; } @@ -105,7 +105,7 @@ bool Imbuements::processImbuementNode(const pugi::xml_node &imbuementNode) { } uint16_t baseid = pugi::cast(base.value()); - auto groupBase = getBaseByID(baseid); + const auto &groupBase = getBaseByID(baseid); if (groupBase == nullptr) { g_logger().warn("Group base '{}' not exist", baseid); return false; @@ -152,7 +152,7 @@ bool Imbuements::processImbuementNode(const pugi::xml_node &imbuementNode) { } auto category = pugi::cast(categorybase.value()); - auto category_p = getCategoryByID(category); + const auto &category_p = getCategoryByID(category); if (category_p == nullptr) { g_logger().warn("Category imbuement {} not exist", category); return false; @@ -330,7 +330,7 @@ bool Imbuements::reload() { return loadFromXml(true); } -std::shared_ptr Imbuements::getBaseByID(uint16_t id) { +std::shared_ptr Imbuements::getBaseByID(uint16_t id) const { auto baseImbuements = std::find_if(basesImbuement.begin(), basesImbuement.end(), [id](const auto &groupImbuement) { return groupImbuement->id == id; }); @@ -338,7 +338,7 @@ std::shared_ptr Imbuements::getBaseByID(uint16_t id) { return baseImbuements != basesImbuement.end() ? *baseImbuements : nullptr; } -std::shared_ptr Imbuements::getCategoryByID(uint16_t id) { +std::shared_ptr Imbuements::getCategoryByID(uint16_t id) const { auto categoryImbuements = std::find_if(categoriesImbuement.begin(), categoriesImbuement.end(), [id](const auto &categoryImbuement) { return categoryImbuement->id == id; }); @@ -346,7 +346,7 @@ std::shared_ptr Imbuements::getCategoryByID(uint16_t id) { return categoryImbuements != categoriesImbuement.end() ? *categoryImbuements : nullptr; } -std::vector> Imbuements::getImbuements(const std::shared_ptr &player, const std::shared_ptr &item) { +std::vector> Imbuements::getImbuements(const std::shared_ptr &player, const std::shared_ptr &item) const { std::vector> imbuements; for (auto &[key, value] : imbuementMap) { @@ -364,7 +364,7 @@ std::vector> Imbuements::getImbuements(const std::sha } // Send only the imbuements registered on item (in items.xml) to the imbuement window - const std::shared_ptr categoryImbuement = getCategoryByID(imbuement->getCategory()); + const std::shared_ptr &categoryImbuement = getCategoryByID(imbuement->getCategory()); if (!item->hasImbuementType(static_cast(categoryImbuement->id), imbuement->getBaseID())) { continue; } diff --git a/src/creatures/players/imbuements/imbuements.hpp b/src/creatures/players/imbuements/imbuements.hpp index 222e600b3bc..8b4730e34c8 100644 --- a/src/creatures/players/imbuements/imbuements.hpp +++ b/src/creatures/players/imbuements/imbuements.hpp @@ -62,11 +62,11 @@ class Imbuements { return inject(); } - std::shared_ptr getImbuement(uint16_t id); - std::shared_ptr getBaseByID(uint16_t id); - std::shared_ptr getCategoryByID(uint16_t id); + std::shared_ptr getImbuement(uint16_t id) const; + std::shared_ptr getBaseByID(uint16_t id) const; + std::shared_ptr getCategoryByID(uint16_t id) const; - std::vector> getImbuements(const std::shared_ptr &player, const std::shared_ptr &item); + std::vector> getImbuements(const std::shared_ptr &player, const std::shared_ptr &item) const; protected: friend class Imbuement;