Implements ConstString in several core places in the library, improving performance.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
CreateCreature* CreateCreature::WithVariant(std::string variant) {
|
||||
this->_variant = std::move(variant);
|
||||
CreateCreature* CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) {
|
||||
this->_variant = variant;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@ CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
|
||||
return this;
|
||||
}
|
||||
|
||||
CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
|
||||
CreateCreature* CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||
AttackLearnMethod learnMethod) {
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves())
|
||||
throw CreatureException("You have already set the maximum amount of allowed moves.");
|
||||
|
||||
auto attackData = _library->GetAttackLibrary()->Get(attackName.c_str());
|
||||
auto attackData = _library->GetAttackLibrary()->Get(attackName);
|
||||
_attacks.emplace_back(attackData, learnMethod);
|
||||
return this;
|
||||
}
|
||||
|
||||
Creature* CreateCreature::Create() {
|
||||
auto rand = Arbutils::Random();
|
||||
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.c_str());
|
||||
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species);
|
||||
auto variant = species->GetVariant(this->_variant);
|
||||
int8_t talent;
|
||||
if (this->_talent.empty()) {
|
||||
@@ -48,8 +49,8 @@ Creature* CreateCreature::Create() {
|
||||
gender = species->GetRandomGender(rand);
|
||||
}
|
||||
const Library::Item* heldItem = nullptr;
|
||||
if (!this->_heldItem.empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.c_str(), heldItem)) {
|
||||
if (!this->_heldItem.Empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
|
||||
throw CreatureException("Invalid held item.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class CreateCreature {
|
||||
const BattleLibrary* _library;
|
||||
std::string _species;
|
||||
std::string _variant = "default";
|
||||
Arbutils::CaseInsensitiveConstString _species;
|
||||
Arbutils::CaseInsensitiveConstString _variant = "default"_cnc;
|
||||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
std::string _talent = "";
|
||||
Library::Gender _gender = static_cast<Library::Gender>(-1);
|
||||
uint8_t _coloring = 0;
|
||||
std::string _heldItem = "";
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
uint32_t _identifier = 0;
|
||||
std::vector<std::tuple<const Library::AttackData*, AttackLearnMethod>> _attacks = {};
|
||||
|
||||
@@ -23,10 +23,11 @@ namespace CreatureLib::Battling {
|
||||
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
|
||||
: _library(library), _species(std::move(species)), _level(level) {}
|
||||
|
||||
CreateCreature* WithVariant(std::string variant);
|
||||
CreateCreature* WithVariant(const Arbutils::CaseInsensitiveConstString& variant);
|
||||
CreateCreature* WithNickname(std::string nickname);
|
||||
CreateCreature* WithGender(Library::Gender gender);
|
||||
CreateCreature* WithAttack(const std::string& attackName, AttackLearnMethod learnMethod);
|
||||
CreateCreature* WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||
AttackLearnMethod learnMethod);
|
||||
|
||||
Creature* Create();
|
||||
};
|
||||
|
||||
@@ -13,7 +13,11 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu
|
||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||
_talentIndex(talent), _hasOverridenTalent(false), _attacks(std::move(attacks)) {
|
||||
|
||||
_activeTalent = _library->LoadScript(ScriptCategory::Talent, GetActiveTalent());
|
||||
if (_nickname.empty()) {
|
||||
_nickname = species->GetName().std_str();
|
||||
}
|
||||
}
|
||||
|
||||
void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||
@@ -21,12 +25,6 @@ void Battling::Creature::ChangeLevel(int8_t amount) {
|
||||
RecalculateFlatStats();
|
||||
}
|
||||
|
||||
const std::string& Battling::Creature::GetNickname() const {
|
||||
if (_nickname.empty())
|
||||
return _species->GetName();
|
||||
return _nickname;
|
||||
}
|
||||
|
||||
const std::string& Battling::Creature::GetActiveTalent() const {
|
||||
if (_hasOverridenTalent) {
|
||||
return _overridenTalentName;
|
||||
@@ -178,7 +176,7 @@ const Library::SpeciesVariant* Battling::Creature::GetDisplayVariant() const {
|
||||
variant = _variant;
|
||||
return variant;
|
||||
}
|
||||
void Battling::Creature::SetHeldItem(const std::string& itemName) {
|
||||
void Battling::Creature::SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName) {
|
||||
const Library::Item* item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemName, item)) {
|
||||
throw CreatureException("Item not found.");
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace CreatureLib::Battling {
|
||||
return _heldItem != nullptr && _heldItem->GetName() == name;
|
||||
}
|
||||
inline const Library::Item* GetHeldItem() const { return _heldItem; }
|
||||
void SetHeldItem(const std::string& itemName);
|
||||
void SetHeldItem(const Arbutils::CaseInsensitiveConstString& itemName);
|
||||
inline void SetHeldItem(const Library::Item* item) { _heldItem = item; };
|
||||
|
||||
inline uint32_t GetCurrentHealth() const { return _currentHealth; }
|
||||
@@ -97,7 +97,7 @@ namespace CreatureLib::Battling {
|
||||
void SetOnBattleField(bool value) { _onBattleField = value; }
|
||||
bool IsOnBattleField() const { return _onBattleField; }
|
||||
|
||||
const std::string& GetNickname() const;
|
||||
const std::string& GetNickname() const { return _nickname; }
|
||||
const std::string& GetActiveTalent() const;
|
||||
|
||||
[[nodiscard]] bool IsFainted() const;
|
||||
|
||||
@@ -5,10 +5,10 @@ CreatureLib::Library::AttackData::AttackData(std::string name, uint8_t type,
|
||||
CreatureLib::Library::AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage,
|
||||
CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||
std::unordered_set<std::string> flags)
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
|
||||
: _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy),
|
||||
_baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {}
|
||||
|
||||
bool CreatureLib::Library::AttackData::HasFlag(const std::string& key) const {
|
||||
bool CreatureLib::Library::AttackData::HasFlag(const Arbutils::CaseInsensitiveConstString& key) const {
|
||||
return this->_flags.find(key) != this->_flags.end();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_ATTACKDATA_HPP
|
||||
#define CREATURELIB_ATTACKDATA_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "AttackCategory.hpp"
|
||||
@@ -17,11 +18,12 @@ namespace CreatureLib::Library {
|
||||
uint8_t _baseUsages;
|
||||
AttackTarget _target;
|
||||
int8_t _priority;
|
||||
std::unordered_set<std::string> _flags;
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> _flags;
|
||||
|
||||
public:
|
||||
AttackData(std::string name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
||||
uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set<std::string> flags);
|
||||
uint8_t baseUsage, AttackTarget target, int8_t priority,
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags);
|
||||
virtual ~AttackData() = default;
|
||||
|
||||
inline const std::string& GetName() const { return _name; }
|
||||
@@ -33,7 +35,7 @@ namespace CreatureLib::Library {
|
||||
inline AttackTarget GetTarget() const { return _target; }
|
||||
inline int8_t GetPriority() const { return _priority; }
|
||||
|
||||
bool HasFlag(const std::string& key) const;
|
||||
bool HasFlag(const Arbutils::CaseInsensitiveConstString& key) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
#ifndef CREATURELIB_BASELIBRARY_HPP
|
||||
#define CREATURELIB_BASELIBRARY_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
template <class T> class BaseLibrary {
|
||||
inline static constexpr char charToLower(const char c) { return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; }
|
||||
inline static uint32_t constexpr Hash(char const* input) {
|
||||
return charToLower(*input) ? static_cast<uint32_t>(charToLower(*input)) + 33 * Hash(input + 1) : 5381;
|
||||
}
|
||||
|
||||
std::unordered_map<uint32_t, const T*> _values;
|
||||
|
||||
public:
|
||||
@@ -23,14 +20,13 @@ namespace CreatureLib::Library {
|
||||
_values.clear();
|
||||
}
|
||||
|
||||
inline void Insert(const char* key, const T* value) { _values.insert({Hash(key), value}); }
|
||||
inline void Insert(const std::string& key, const T* value) { Insert(key.c_str(), value); }
|
||||
inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) {
|
||||
_values.insert({key.GetHash(), value});
|
||||
}
|
||||
inline void Delete(const Arbutils::CaseInsensitiveConstString& key) { _values.erase(key.GetHash()); }
|
||||
|
||||
inline void Delete(const char* key) { _values.erase(Hash(key)); }
|
||||
inline void Delete(const std::string& key) { Delete(key.c_str()); }
|
||||
|
||||
bool TryGet(const char* name, const T*& out) const {
|
||||
auto find = this->_values.find(Hash(name));
|
||||
bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const T*& out) const {
|
||||
auto find = this->_values.find(name.GetHash());
|
||||
if (find == this->_values.end()) {
|
||||
out = nullptr;
|
||||
return false;
|
||||
@@ -38,16 +34,10 @@ namespace CreatureLib::Library {
|
||||
out = find->second;
|
||||
return true;
|
||||
}
|
||||
bool TryGet(const std::string& name, const T*& out) const {
|
||||
return TryGet(name.c_str(), out);
|
||||
inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return _values.at(name.GetHash());
|
||||
}
|
||||
|
||||
inline const T* Get(const char* name) const { return _values.at(Hash(name)); }
|
||||
inline const T* Get(const std::string& name) const { return Get(name.c_str()); }
|
||||
|
||||
inline const T* operator[](const char* name) const { return Get(name); }
|
||||
inline const T* operator[](const std::string& name) const { return Get(name.c_str()); }
|
||||
|
||||
inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const { return Get(name); }
|
||||
inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
||||
|
||||
size_t GetCount() const { return _values.size(); }
|
||||
|
||||
@@ -2,21 +2,19 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
std::string growthRate, uint8_t captureRate)
|
||||
: _id(id), _genderRate(genderRatio), _growthRate(std::move(growthRate)), _captureRate(captureRate),
|
||||
_variants({{"default", defaultVariant}}), _name(std::move(name)) {}
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
|
||||
: _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||
_variants({{"default"_cnc, defaultVariant}}), _name(name) {}
|
||||
|
||||
bool CreatureSpecies::HasVariant(const std::string& name) const {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
return _variants.find(key) != _variants.end();
|
||||
bool CreatureSpecies::HasVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return _variants.find(name) != _variants.end();
|
||||
}
|
||||
|
||||
bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVariant*& out) const {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
auto find = _variants.find(key);
|
||||
bool CreatureSpecies::TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant*& out) const {
|
||||
auto find = _variants.find(name);
|
||||
if (find != _variants.end()) {
|
||||
out = find->second;
|
||||
return true;
|
||||
@@ -24,20 +22,17 @@ bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVarian
|
||||
return false;
|
||||
}
|
||||
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& name) const {
|
||||
const SpeciesVariant* CreatureSpecies::GetVariant(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
return _variants.at(key);
|
||||
}
|
||||
|
||||
void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* variant) {
|
||||
auto key = name;
|
||||
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||
auto find = _variants.find(key);
|
||||
void CreatureSpecies::SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
|
||||
auto find = _variants.find(name);
|
||||
if (find != _variants.end()) {
|
||||
delete find->second;
|
||||
}
|
||||
_variants[key] = variant;
|
||||
_variants[name] = variant;
|
||||
}
|
||||
|
||||
Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||
@@ -46,6 +41,4 @@ Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||
if (val >= this->_genderRate)
|
||||
return Gender ::Female;
|
||||
return Gender ::Male;
|
||||
}
|
||||
|
||||
const std::string& CreatureSpecies::GetName() const { return _name; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_CREATURESPECIES_HPP
|
||||
#define CREATURELIB_CREATURESPECIES_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "../Gender.hpp"
|
||||
@@ -14,16 +15,17 @@ namespace CreatureLib::Library {
|
||||
class CreatureSpecies {
|
||||
uint16_t _id;
|
||||
float _genderRate;
|
||||
std::string _growthRate;
|
||||
const Arbutils::CaseInsensitiveConstString _growthRate;
|
||||
uint8_t _captureRate;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, const SpeciesVariant*> _variants;
|
||||
std::string _name;
|
||||
std::unordered_map<Arbutils::CaseInsensitiveConstString, const SpeciesVariant*> _variants;
|
||||
Arbutils::CaseInsensitiveConstString _name;
|
||||
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
std::string growthRate, uint8_t captureRate);
|
||||
CreatureSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
|
||||
|
||||
virtual ~CreatureSpecies() {
|
||||
for (auto v : _variants)
|
||||
@@ -33,18 +35,22 @@ namespace CreatureLib::Library {
|
||||
|
||||
inline uint16_t GetId() const { return _id; }
|
||||
inline float GetGenderRate() const { return _genderRate; }
|
||||
inline const std::string& GetGrowthRate() const { return _growthRate; }
|
||||
inline const Arbutils::CaseInsensitiveConstString& GetGrowthRate() const { return _growthRate; }
|
||||
inline uint8_t GetCaptureRate() const { return _captureRate; }
|
||||
|
||||
[[nodiscard]] bool HasVariant(const std::string& key) const;
|
||||
[[nodiscard]] bool TryGetVariant(const std::string& name, const SpeciesVariant*& out) const;
|
||||
[[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const;
|
||||
[[nodiscard]] bool HasVariant(const Arbutils::CaseInsensitiveConstString& key) const;
|
||||
[[nodiscard]] bool TryGetVariant(const Arbutils::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant*& out) const;
|
||||
[[nodiscard]] const SpeciesVariant* GetVariant(const Arbutils::CaseInsensitiveConstString& key) const;
|
||||
[[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const;
|
||||
[[nodiscard]] const std::string& GetName() const;
|
||||
[[nodiscard]] const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||
|
||||
void SetVariant(const std::string& name, const SpeciesVariant* variant);
|
||||
void SetVariant(const Arbutils::CaseInsensitiveConstString& name, const SpeciesVariant* variant);
|
||||
|
||||
const std::unordered_map<std::string, const SpeciesVariant*>& GetVariantsIterator() const { return _variants; }
|
||||
const std::unordered_map<Arbutils::CaseInsensitiveConstString, const SpeciesVariant*>&
|
||||
GetVariantsIterator() const {
|
||||
return _variants;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,25 @@
|
||||
#include <algorithm>
|
||||
#include "../../Core/Exceptions/CreatureException.hpp"
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate,
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||
uint32_t experience) const {
|
||||
auto g = growthRate;
|
||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
||||
auto find = _growthRates.find(g);
|
||||
auto find = _growthRates.find(growthRate);
|
||||
if (find == _growthRates.end()) {
|
||||
throw CreatureException("Invalid growth rate was requested.");
|
||||
}
|
||||
return find->second->CalculateLevel(experience);
|
||||
}
|
||||
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate,
|
||||
uint8_t level) const {
|
||||
auto g = growthRate;
|
||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
||||
auto find = _growthRates.find(g);
|
||||
uint32_t
|
||||
CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const Arbutils::CaseInsensitiveConstString& 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 std::string& name,
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name,
|
||||
CreatureLib::Library::GrowthRate* rate) {
|
||||
auto g = name;
|
||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
||||
_growthRates.insert({g, rate});
|
||||
_growthRates.insert({name, rate});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||
#define CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -9,11 +10,11 @@
|
||||
namespace CreatureLib::Library {
|
||||
class GrowthRateLibrary {
|
||||
private:
|
||||
std::unordered_map<std::string, GrowthRate*> _growthRates;
|
||||
std::unordered_map<Arbutils::CaseInsensitiveConstString, GrowthRate*> _growthRates;
|
||||
|
||||
public:
|
||||
GrowthRateLibrary(size_t initialCapacity = 10)
|
||||
: _growthRates(std::unordered_map<std::string, GrowthRate*>(initialCapacity)) {}
|
||||
: _growthRates(std::unordered_map<Arbutils::CaseInsensitiveConstString, GrowthRate*>(initialCapacity)) {}
|
||||
|
||||
virtual ~GrowthRateLibrary() {
|
||||
for (auto gr : _growthRates) {
|
||||
@@ -21,10 +22,12 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const;
|
||||
[[nodiscard]] uint8_t CalculateLevel(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||
uint32_t experience) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(const Arbutils::CaseInsensitiveConstString& growthRate,
|
||||
uint8_t level) const;
|
||||
|
||||
void AddGrowthRate(const std::string& name, GrowthRate* rate);
|
||||
void AddGrowthRate(const Arbutils::CaseInsensitiveConstString& name, GrowthRate* rate);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "Item.hpp"
|
||||
|
||||
bool CreatureLib::Library::Item::HasFlag(const std::string& flag) const {
|
||||
bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const {
|
||||
return this->_flags.find(flag) != this->_flags.end();
|
||||
}
|
||||
CreatureLib::Library::Item::Item(std::string name, CreatureLib::Library::ItemCategory category,
|
||||
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
||||
std::unordered_set<std::string> flags)
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
|
||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CREATURELIB_ITEM_HPP
|
||||
#define CREATURELIB_ITEM_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "BattleItemCategory.hpp"
|
||||
@@ -13,18 +14,18 @@ namespace CreatureLib::Library {
|
||||
ItemCategory _category;
|
||||
BattleItemCategory _battleCategory;
|
||||
int32_t _price;
|
||||
std::unordered_set<std::string> _flags;
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> _flags;
|
||||
|
||||
public:
|
||||
Item(std::string name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
|
||||
std::unordered_set<std::string> flags);
|
||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags);
|
||||
|
||||
inline const std::string& GetName() const { return _name; }
|
||||
inline ItemCategory GetCategory() const { return _category; }
|
||||
inline BattleItemCategory GetBattleCategory() const { return _battleCategory; }
|
||||
inline const int32_t GetPrice() const { return _price; }
|
||||
|
||||
bool HasFlag(const std::string& flag) const;
|
||||
bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user