diff --git a/src/Library/GrowthRates/GrowthRateLibrary.cpp b/src/Library/GrowthRates/GrowthRateLibrary.cpp index 6b6e7b0..6c1f36d 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.cpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.cpp @@ -1,8 +1,7 @@ #include "GrowthRateLibrary.hpp" -#include #include "../../Core/Exceptions/CreatureException.hpp" -uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate, +uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ConstString& growthRate, uint32_t experience) const { auto find = _growthRates.find(growthRate); if (find == _growthRates.end()) { @@ -11,16 +10,36 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const Arbutils:: return find->second->CalculateLevel(experience); } -uint32_t -CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate, - uint8_t level) const { +uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, uint32_t experience) const { + auto find = _growthRates.find(hash); + if (find == _growthRates.end()) { + throw CreatureException("Invalid growth rate was requested."); + } + return find->second->CalculateLevel(experience); +} + +uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ConstString& growthRate, + uint8_t level) const { auto find = _growthRates.find(growthRate); if (find == _growthRates.end()) { throw CreatureException("Invalid growth rate was requested."); } return find->second->CalculateExperience(level); } -void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name, + +uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, uint8_t level) const { + auto find = _growthRates.find(hash); + if (find == _growthRates.end()) { + throw CreatureException("Invalid growth rate was requested."); + } + return find->second->CalculateExperience(level); +} + +void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ConstString& name, CreatureLib::Library::GrowthRate* rate) { _growthRates.insert({name, rate}); } + +void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(uint32_t hash, CreatureLib::Library::GrowthRate* rate) { + _growthRates.insert({hash, rate}); +} diff --git a/src/Library/GrowthRates/GrowthRateLibrary.hpp b/src/Library/GrowthRates/GrowthRateLibrary.hpp index 5b10bc8..de74d93 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.hpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.hpp @@ -7,14 +7,16 @@ #include #include "GrowthRate.hpp" +using ConstString = Arbutils::CaseInsensitiveConstString; + namespace CreatureLib::Library { class GrowthRateLibrary { private: - std::unordered_map _growthRates; + std::unordered_map _growthRates; public: GrowthRateLibrary(size_t initialCapacity = 10) - : _growthRates(std::unordered_map(initialCapacity)) {} + : _growthRates(std::unordered_map(initialCapacity)) {} virtual ~GrowthRateLibrary() { for (auto gr : _growthRates) { @@ -22,12 +24,13 @@ namespace CreatureLib::Library { } } - [[nodiscard]] uint8_t CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate, - uint32_t experience) const; - [[nodiscard]] uint32_t CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate, - uint8_t level) const; + [[nodiscard]] uint8_t CalculateLevel(const ConstString& growthRate, uint32_t experience) const; + [[nodiscard]] uint8_t CalculateLevel(uint32_t hash, uint32_t experience) const; + [[nodiscard]] uint32_t CalculateExperience(const ConstString& growthRate, uint8_t level) const; + [[nodiscard]] uint32_t CalculateExperience(uint32_t hash, uint8_t level) const; - void AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name, GrowthRate* rate); + void AddGrowthRate(uint32_t hash, GrowthRate* rate); + void AddGrowthRate(const ConstString& name, GrowthRate* rate); }; }