CreatureLib/src/Library/GrowthRates/GrowthRateLibrary.cpp

47 lines
1.9 KiB
C++

#include "GrowthRateLibrary.hpp"
#include <Arbutils/Exception.hpp>
#include "../Exceptions/CreatureException.hpp"
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
uint32_t experience) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateLevel(experience);
}
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, uint32_t experience) const {
auto find = _growthRates.find(hash);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateLevel(experience);
}
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
level_int_t level) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateExperience(level);
}
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, level_int_t level) const {
auto find = _growthRates.find(hash);
if (find == _growthRates.end()) {
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateExperience(level);
}
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringView& name,
CreatureLib::Library::GrowthRate* rate) {
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
}
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(uint32_t hash, CreatureLib::Library::GrowthRate* rate) {
_growthRates.insert({hash, std::unique_ptr<const GrowthRate>(rate)});
}