Update to new Arbutils
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:
@@ -1,7 +1,7 @@
|
||||
#include "AttackData.hpp"
|
||||
#include <utility>
|
||||
|
||||
CreatureLib::Library::AttackData::AttackData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type,
|
||||
CreatureLib::Library::AttackData::AttackData(const ArbUt::StringView& name, uint8_t type,
|
||||
CreatureLib::Library::AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage,
|
||||
CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CREATURELIB_ATTACKDATA_HPP
|
||||
#define CREATURELIB_ATTACKDATA_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace CreatureLib::Library {
|
||||
class AttackData {
|
||||
protected:
|
||||
ArbUt::CaseInsensitiveConstString _name;
|
||||
ArbUt::StringView _name;
|
||||
uint8_t _type;
|
||||
AttackCategory _category;
|
||||
uint8_t _basePower;
|
||||
@@ -24,12 +24,12 @@ namespace CreatureLib::Library {
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
AttackData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type, AttackCategory category, uint8_t power,
|
||||
AttackData(const ArbUt::StringView& name, uint8_t type, AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority,
|
||||
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags);
|
||||
virtual ~AttackData() = default;
|
||||
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
|
||||
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||
inline const uint8_t GetType() const noexcept { return _type; }
|
||||
inline AttackCategory GetCategory() const noexcept { return _category; }
|
||||
inline uint8_t GetBasePower() const noexcept { return _basePower; }
|
||||
@@ -42,7 +42,7 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
inline const std::unique_ptr<const SecondaryEffect>& GetSecondaryEffect() const noexcept { return _effect; }
|
||||
|
||||
inline bool HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept {
|
||||
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
|
||||
return this->_flags.find(key) != this->_flags.end();
|
||||
}
|
||||
inline bool HasFlag(uint32_t keyHash) const noexcept {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CREATURELIB_SECONDARYEFFECT_HPP
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <any>
|
||||
#include "../EffectParameter.hpp"
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace CreatureLib::Library {
|
||||
class SecondaryEffect {
|
||||
private:
|
||||
float _chance;
|
||||
ArbUt::CaseInsensitiveConstString _effectName;
|
||||
ArbUt::StringView _effectName;
|
||||
ArbUt::List<EffectParameter*> _parameters;
|
||||
|
||||
public:
|
||||
SecondaryEffect() noexcept : _chance(0), _effectName() {}
|
||||
SecondaryEffect(float chance, const ArbUt::CaseInsensitiveConstString& effectName,
|
||||
SecondaryEffect(float chance, const ArbUt::StringView& effectName,
|
||||
const ArbUt::List<EffectParameter*>& parameters) noexcept
|
||||
: _chance(chance), _effectName(effectName), _parameters(parameters) {}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
|
||||
constexpr inline float GetChance() const noexcept { return _chance; }
|
||||
constexpr inline const ArbUt::CaseInsensitiveConstString& GetEffectName() const noexcept { return _effectName; }
|
||||
constexpr inline const ArbUt::StringView& GetEffectName() const noexcept { return _effectName; }
|
||||
const inline ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -22,7 +22,7 @@ namespace CreatureLib::Library {
|
||||
|
||||
virtual ~BaseLibrary() noexcept { _values.Clear(); }
|
||||
|
||||
inline void Insert(const ArbUt::CaseInsensitiveConstString& key, const T* value) {
|
||||
inline void Insert(const ArbUt::StringView& key, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(key);
|
||||
@@ -33,7 +33,7 @@ namespace CreatureLib::Library {
|
||||
_listValues.Append(hashedKey);
|
||||
}
|
||||
|
||||
inline void Delete(const ArbUt::CaseInsensitiveConstString& key) noexcept {
|
||||
inline void Delete(const ArbUt::StringView& key) noexcept {
|
||||
_values.erase(key.GetHash());
|
||||
auto k = _listValues.IndexOf(key);
|
||||
_listValues.Remove(k);
|
||||
@@ -44,7 +44,7 @@ namespace CreatureLib::Library {
|
||||
_listValues.Remove(k);
|
||||
}
|
||||
|
||||
bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr<const T>& out) const noexcept {
|
||||
bool TryGet(const ArbUt::BasicStringView& name, ArbUt::BorrowedPtr<const T>& out) const noexcept {
|
||||
return TryGet(name.GetHash(), out);
|
||||
}
|
||||
bool TryGet(uint32_t hashedKey, ArbUt::BorrowedPtr<const T>& out) const noexcept {
|
||||
@@ -55,15 +55,14 @@ namespace CreatureLib::Library {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::BasicStringView& name) const {
|
||||
return _values.Get(name.GetHash());
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(uint32_t hashedKey) const {
|
||||
return _values.Get(hashedKey);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T>
|
||||
operator[](const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](const ArbUt::BasicStringView& name) const {
|
||||
return Get(name);
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
|
||||
@@ -3,18 +3,13 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate)
|
||||
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate), _variants(1) {
|
||||
AssertNotNull(defaultVariant)
|
||||
SetVariant("default"_cnc, defaultVariant);
|
||||
}
|
||||
|
||||
bool CreatureSpecies::TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
|
||||
return TryGetVariant(name.GetHash(), out);
|
||||
}
|
||||
bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
|
||||
auto find = _variants.GetStdMap().find(hash);
|
||||
if (find == _variants.end())
|
||||
@@ -23,7 +18,7 @@ bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const Spec
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreatureSpecies::SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
|
||||
void CreatureSpecies::SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
|
||||
_variants.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define CREATURELIB_CREATURESPECIES_HPP
|
||||
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -16,43 +16,44 @@ namespace CreatureLib::Library {
|
||||
creatures with.
|
||||
*/
|
||||
class CreatureSpecies {
|
||||
const ArbUt::CaseInsensitiveConstString _name;
|
||||
const ArbUt::StringView _name;
|
||||
uint16_t _id;
|
||||
float _genderRate;
|
||||
const ArbUt::CaseInsensitiveConstString _growthRate;
|
||||
const ArbUt::StringView _growthRate;
|
||||
uint8_t _captureRate;
|
||||
ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variants;
|
||||
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
|
||||
CreatureSpecies(uint16_t id, const ArbUt::StringView& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ArbUt::StringView& growthRate, uint8_t captureRate);
|
||||
|
||||
virtual ~CreatureSpecies() noexcept { _variants.Clear(); }
|
||||
|
||||
inline uint16_t GetId() const noexcept { return _id; }
|
||||
inline float GetGenderRate() const noexcept { return _genderRate; }
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetGrowthRate() const noexcept { return _growthRate; }
|
||||
inline const ArbUt::StringView& GetGrowthRate() const noexcept { return _growthRate; }
|
||||
inline uint8_t GetCaptureRate() const noexcept { return _captureRate; }
|
||||
|
||||
[[nodiscard]] inline bool HasVariant(const ArbUt::CaseInsensitiveConstString& key) const noexcept {
|
||||
[[nodiscard]] inline bool HasVariant(const ArbUt::BasicStringView& key) const noexcept {
|
||||
return _variants.Has(key);
|
||||
}
|
||||
[[nodiscard]] inline bool HasVariant(uint32_t hash) const noexcept { return _variants.Has(hash); }
|
||||
[[nodiscard]] bool TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
|
||||
[[nodiscard]] inline bool TryGetVariant(const ArbUt::BasicStringView& name,
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept {
|
||||
return TryGetVariant(name.GetHash(), out);
|
||||
}
|
||||
[[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const noexcept;
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant>
|
||||
GetVariant(const ArbUt::CaseInsensitiveConstString& key) const {
|
||||
GetVariant(const ArbUt::BasicStringView& key) const {
|
||||
return _variants.Get(key);
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const {
|
||||
return _variants.Get(key);
|
||||
}
|
||||
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept;
|
||||
[[nodiscard]] inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||
[[nodiscard]] inline const ArbUt::StringView& GetName() const { return _name; }
|
||||
|
||||
void SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant);
|
||||
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant);
|
||||
|
||||
inline const ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>& GetVariantsIterator() const {
|
||||
return _variants;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
const CreatureLib::Library::TalentIndex
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const {
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talent) const {
|
||||
for (size_t i = 0; i < _talents.Count(); i++) {
|
||||
if (_talents.At(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace CreatureLib::Library {
|
||||
*/
|
||||
class SpeciesVariant {
|
||||
protected:
|
||||
ArbUt::CaseInsensitiveConstString _name;
|
||||
ArbUt::StringView _name;
|
||||
float _height;
|
||||
float _weight;
|
||||
uint32_t _baseExperience;
|
||||
@@ -24,22 +24,20 @@ namespace CreatureLib::Library {
|
||||
private:
|
||||
ArbUt::List<uint8_t> _types;
|
||||
Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> _talents;
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> _secretTalents;
|
||||
ArbUt::List<ArbUt::StringView> _talents;
|
||||
ArbUt::List<ArbUt::StringView> _secretTalents;
|
||||
std::unique_ptr<const LearnableAttacks> _attacks;
|
||||
|
||||
public:
|
||||
SpeciesVariant(const ArbUt::CaseInsensitiveConstString& name, float height, float weight,
|
||||
uint32_t baseExperience, const ArbUt::List<uint8_t>& types,
|
||||
Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& talents,
|
||||
const ArbUt::List<ArbUt::CaseInsensitiveConstString>& secretTalents,
|
||||
const LearnableAttacks* attacks)
|
||||
SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents,
|
||||
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks)
|
||||
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)),
|
||||
_baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks){};
|
||||
virtual ~SpeciesVariant() = default;
|
||||
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||
inline const ArbUt::StringView& GetName() const { return _name; }
|
||||
inline float GetHeight() const { return _height; }
|
||||
inline float GetWeight() const { return _weight; }
|
||||
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
||||
@@ -52,7 +50,7 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
[[nodiscard]] inline const size_t GetTalentCount() const noexcept { return _talents.Count(); }
|
||||
[[nodiscard]] inline const size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
|
||||
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetTalent(const TalentIndex& index) const {
|
||||
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const {
|
||||
if (index.IsSecret() && _secretTalents.Count() > 0) {
|
||||
auto i = index.GetIndex();
|
||||
if (i > _secretTalents.Count())
|
||||
@@ -64,7 +62,7 @@ namespace CreatureLib::Library {
|
||||
i = _talents.Count();
|
||||
return _talents.At(i);
|
||||
}
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const;
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const;
|
||||
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
|
||||
GetLearnableAttacks() const {
|
||||
@@ -73,12 +71,8 @@ namespace CreatureLib::Library {
|
||||
[[nodiscard]] inline TalentIndex GetRandomTalent(ArbUt::Random* rand) const noexcept {
|
||||
return TalentIndex(false, rand->Get(_talents.Count()));
|
||||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetTalents() const {
|
||||
return _talents;
|
||||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetSecretTalents() const {
|
||||
return _secretTalents;
|
||||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CREATURELIB_EFFECTPARAMETER_HPP
|
||||
#define CREATURELIB_EFFECTPARAMETER_HPP
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Enum.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <variant>
|
||||
#include "Exceptions/CreatureException.hpp"
|
||||
|
||||
@@ -11,15 +11,14 @@ namespace CreatureLib::Library {
|
||||
class EffectParameter {
|
||||
private:
|
||||
EffectParameterType _type = EffectParameterType::None;
|
||||
std::variant<bool, int64_t, float, ArbUt::CaseInsensitiveConstString> _value;
|
||||
std::variant<bool, int64_t, float, ArbUt::StringView> _value;
|
||||
|
||||
public:
|
||||
inline EffectParameter() : _type(EffectParameterType::None){};
|
||||
inline explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){};
|
||||
inline explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){};
|
||||
inline explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
|
||||
inline explicit EffectParameter(const ArbUt::CaseInsensitiveConstString& s)
|
||||
: _type(EffectParameterType::String), _value(s){};
|
||||
inline explicit EffectParameter(const ArbUt::StringView& s) : _type(EffectParameterType::String), _value(s){};
|
||||
EffectParameter(const EffectParameter& other) = delete;
|
||||
EffectParameter& operator=(const EffectParameter& other) = delete;
|
||||
|
||||
@@ -54,13 +53,13 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
return std::get<float>(_value);
|
||||
}
|
||||
const ArbUt::CaseInsensitiveConstString& AsString() const {
|
||||
const ArbUt::StringView& AsString() const {
|
||||
if (_type != EffectParameterType::String) {
|
||||
std::stringstream ss;
|
||||
ss << "Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type);
|
||||
throw CreatureException(ss.str());
|
||||
}
|
||||
return std::get<ArbUt::CaseInsensitiveConstString>(_value);
|
||||
return std::get<ArbUt::StringView>(_value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "GrowthRateLibrary.hpp"
|
||||
#include "../Exceptions/CreatureException.hpp"
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ConstString& growthRate,
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::BasicStringView& growthRate,
|
||||
uint32_t experience) const {
|
||||
auto find = _growthRates.find(growthRate);
|
||||
if (find == _growthRates.end()) {
|
||||
@@ -18,7 +18,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, u
|
||||
return find->second->CalculateLevel(experience);
|
||||
}
|
||||
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ConstString& growthRate,
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbUt::BasicStringView& growthRate,
|
||||
uint8_t level) const {
|
||||
auto find = _growthRates.find(growthRate);
|
||||
if (find == _growthRates.end()) {
|
||||
@@ -35,7 +35,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t h
|
||||
return find->second->CalculateExperience(level);
|
||||
}
|
||||
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ConstString& name,
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const ArbUt::StringView& name,
|
||||
CreatureLib::Library::GrowthRate* rate) {
|
||||
_growthRates.insert({name, std::unique_ptr<const GrowthRate>(rate)});
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#ifndef CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||
#define CREATURELIB_GROWTHRATELIBRARY_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "GrowthRate.hpp"
|
||||
|
||||
using ConstString = ArbUt::CaseInsensitiveConstString;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class GrowthRateLibrary {
|
||||
private:
|
||||
@@ -21,13 +19,13 @@ namespace CreatureLib::Library {
|
||||
|
||||
virtual ~GrowthRateLibrary() = default;
|
||||
|
||||
[[nodiscard]] uint8_t CalculateLevel(const ConstString& growthRate, uint32_t experience) const;
|
||||
[[nodiscard]] uint8_t CalculateLevel(const ArbUt::BasicStringView& 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(const ArbUt::BasicStringView& growthRate, uint8_t level) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(uint32_t hash, uint8_t level) const;
|
||||
|
||||
void AddGrowthRate(uint32_t hash, GrowthRate* rate);
|
||||
void AddGrowthRate(const ConstString& name, GrowthRate* rate);
|
||||
void AddGrowthRate(const ArbUt::StringView& name, GrowthRate* rate);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CREATURELIB_ITEM_HPP
|
||||
#define CREATURELIB_ITEM_HPP
|
||||
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include "BattleItemCategory.hpp"
|
||||
@@ -10,27 +10,24 @@
|
||||
namespace CreatureLib::Library {
|
||||
class Item {
|
||||
protected:
|
||||
ArbUt::CaseInsensitiveConstString _name;
|
||||
ArbUt::StringView _name;
|
||||
ItemCategory _category;
|
||||
BattleItemCategory _battleCategory;
|
||||
int32_t _price;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
inline Item(const ArbUt::CaseInsensitiveConstString& name, ItemCategory category,
|
||||
BattleItemCategory battleCategory, int32_t price,
|
||||
const std::unordered_set<uint32_t>& flags) noexcept
|
||||
inline Item(const ArbUt::StringView& name, ItemCategory category, BattleItemCategory battleCategory,
|
||||
int32_t price, const std::unordered_set<uint32_t>& flags) noexcept
|
||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
||||
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
|
||||
inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||
inline ItemCategory GetCategory() const noexcept { return _category; }
|
||||
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
|
||||
inline const int32_t GetPrice() const noexcept { return _price; }
|
||||
|
||||
bool HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept {
|
||||
return this->_flags.find(flag) != this->_flags.end();
|
||||
}
|
||||
bool HasFlag(uint32_t flag) const noexcept { return this->_flags.find(flag) != this->_flags.end(); }
|
||||
bool HasFlag(const ArbUt::BasicStringView& flag) const noexcept { return this->_flags.contains(flag); }
|
||||
bool HasFlag(uint32_t flag) const noexcept { return this->_flags.contains(flag); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
uint8_t TypeLibrary::RegisterType(const ArbUt::CaseInsensitiveConstString& key) {
|
||||
uint8_t TypeLibrary::RegisterType(const ArbUt::StringView& key) {
|
||||
_types.Insert(key, _types.Count());
|
||||
_effectiveness.Resize(_types.Count());
|
||||
for (auto& eff : _effectiveness) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/StringView.hpp>
|
||||
#include <numeric>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@@ -16,7 +16,7 @@ namespace CreatureLib::Library {
|
||||
public:
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
|
||||
|
||||
inline uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& key) const { return _types.Get(key); }
|
||||
inline uint8_t GetTypeId(const ArbUt::BasicStringView& key) const { return _types.Get(key); }
|
||||
inline uint8_t GetTypeId(uint32_t s) const { return _types.Get(s); }
|
||||
[[nodiscard]] inline float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
|
||||
return _effectiveness[attacking][defensive];
|
||||
@@ -29,7 +29,7 @@ namespace CreatureLib::Library {
|
||||
});
|
||||
}
|
||||
|
||||
uint8_t RegisterType(const ArbUt::CaseInsensitiveConstString& typeName);
|
||||
uint8_t RegisterType(const ArbUt::StringView& typeName);
|
||||
uint8_t RegisterType(uint32_t typeHash);
|
||||
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user