Breaking change: rework of talents.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-11-15 12:04:45 +01:00
parent 33d384c464
commit 59313e6da8
15 changed files with 152 additions and 67 deletions

View File

@@ -9,16 +9,17 @@ namespace CreatureLib::Library {
uint32_t _baseExperience;
ArbUt::List<uint8_t> _types;
Library::StatisticSet<uint16_t> _baseStatistics;
ArbUt::List<ArbUt::StringView> _talents;
ArbUt::List<ArbUt::StringView> _secretTalents;
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> _talents;
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> _secretTalents;
std::unique_ptr<const LearnableAttacks> _attacks;
std::unordered_set<uint32_t> _flags;
public:
impl(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
ArbUt::List<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
ArbUt::List<ArbUt::StringView> talents, ArbUt::List<ArbUt::StringView> secretTalents,
const LearnableAttacks* attacks, std::unordered_set<uint32_t> flags)
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> talents,
ArbUt::List<ArbUt::BorrowedPtr<const Talent>> secretTalents, const LearnableAttacks* attacks,
std::unordered_set<uint32_t> flags)
: _name(name), _height(height), _weight(weight), _baseExperience(baseExperience),
_types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)),
_secretTalents(std::move(secretTalents)), _attacks(attacks), _flags(std::move(flags)){};
@@ -36,7 +37,7 @@ namespace CreatureLib::Library {
}
[[nodiscard]] inline size_t GetTalentCount() const noexcept { return _talents.Count(); }
[[nodiscard]] inline size_t GetSecretTalentCount() const noexcept { return _secretTalents.Count(); }
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const {
[[nodiscard]] const ArbUt::BorrowedPtr<const Talent>& GetTalent(const TalentIndex& index) const {
if (index.IsSecret() && _secretTalents.Count() > 0) {
auto i = index.GetIndex();
if (i > _secretTalents.Count()) {
@@ -50,7 +51,7 @@ namespace CreatureLib::Library {
}
return _talents.At(i);
}
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const {
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::BorrowedPtr<Talent>& talent) const {
for (size_t i = 0; i < _talents.Count(); i++) {
if (_talents.At(i) == talent) {
return TalentIndex(false, i);
@@ -63,6 +64,19 @@ namespace CreatureLib::Library {
}
THROW("The given talent is not a valid talent for this creature.");
}
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talentName) const {
for (size_t i = 0; i < _talents.Count(); i++) {
if (_talents.At(i)->GetName() == talentName) {
return TalentIndex(false, i);
}
}
for (size_t i = 0; i < _secretTalents.Count(); i++) {
if (_secretTalents.At(i)->GetName() == talentName) {
return TalentIndex(true, i);
}
}
THROW("The given talent name is not a valid talent for this creature.");
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::LearnableAttacks>
GetLearnableAttacks() const {
@@ -71,8 +85,12 @@ 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::StringView>& GetTalents() const { return _talents; }
[[nodiscard]] inline const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const { return _secretTalents; }
[[nodiscard]] inline const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& GetTalents() const {
return _talents;
}
[[nodiscard]] inline const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& GetSecretTalents() const {
return _secretTalents;
}
inline bool HasFlag(const ArbUt::StringView& key) const noexcept {
return this->_flags.find(key) != this->_flags.end();
@@ -84,9 +102,9 @@ namespace CreatureLib::Library {
SpeciesVariant::SpeciesVariant(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
const ArbUt::List<uint8_t>& types, StatisticSet<uint16_t> baseStats,
const ArbUt::List<ArbUt::StringView>& talents,
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks,
const std::unordered_set<uint32_t>& flags)
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags)
: _impl(new impl(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
flags)) {}
SpeciesVariant::~SpeciesVariant() = default;
@@ -105,18 +123,21 @@ namespace CreatureLib::Library {
ImplGetter(size_t, GetTalentCount);
ImplGetter(size_t, GetSecretTalentCount);
const ArbUt::StringView& SpeciesVariant::GetTalent(const TalentIndex& index) const {
const ArbUt::BorrowedPtr<const Talent>& SpeciesVariant::GetTalent(const TalentIndex& index) const {
return _impl->GetTalent(index);
}
TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talent) const {
TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::BorrowedPtr<Talent>& talent) const {
return _impl->GetTalentIndex(talent);
}
TalentIndex SpeciesVariant::GetTalentIndex(const ArbUt::StringView& talentName) const {
return _impl->GetTalentIndex(talentName);
}
ImplGetter(ArbUt::BorrowedPtr<const LearnableAttacks>, GetLearnableAttacks);
TalentIndex SpeciesVariant::GetRandomTalent(ArbUt::Random& rand) const noexcept {
return _impl->GetRandomTalent(rand);
}
ImplGetter(const ArbUt::List<ArbUt::StringView>&, GetTalents);
ImplGetter(const ArbUt::List<ArbUt::StringView>&, GetSecretTalents);
ImplGetter(const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>&, GetTalents);
ImplGetter(const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>&, GetSecretTalents);
bool SpeciesVariant::HasFlag(const ArbUt::StringView& key) const noexcept { return _impl->HasFlag(key); }
bool SpeciesVariant::HasFlag(uint32_t keyHash) const noexcept { return _impl->HasFlag(keyHash); }

View File

@@ -3,6 +3,7 @@
#include "../StatisticSet.hpp"
#include "LearnableAttacks.hpp"
#include "Talent.hpp"
#include "TalentIndex.hpp"
namespace CreatureLib::Library {
@@ -28,9 +29,9 @@ namespace CreatureLib::Library {
/// @param flags A set of flags for use by the developer. These can be used for easy grouping.
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,
const std::unordered_set<uint32_t>& flags = {});
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags = {});
virtual ~SpeciesVariant();
/// @brief Returns the unique name of the variant.
@@ -70,11 +71,15 @@ namespace CreatureLib::Library {
/// @brief Returns a talent name at a specified TalentIndex.
/// @param index Whether it's a secret talent, and which index to get.
/// @return The name of the talent at the given TalentIndex.
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const;
/// @brief Search for the index of a talent with a name.
/// @param talent The name that's being looked for.
[[nodiscard]] const ArbUt::BorrowedPtr<const Talent>& GetTalent(const TalentIndex& index) const;
/// @brief Search for the index of a specific talent.
/// @param talent The talent that's being looked for.
/// @return The index of the talent.
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const;
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::BorrowedPtr<Talent>& talent) const;
/// @brief Search for the index of a talent with a name.
/// @param talentName The name that's being looked for.
/// @return The index of the talent.
[[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talentName) const;
/// @brief Returns the attacks the variant can learn.
/// @return The attacks the variant can learn.
@@ -85,10 +90,10 @@ namespace CreatureLib::Library {
[[nodiscard]] TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept;
/// @brief Returns a list of talents of the variant.
/// @return A list of talents of the variant.
[[nodiscard]] const ArbUt::List<ArbUt::StringView>& GetTalents() const noexcept;
[[nodiscard]] const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& GetTalents() const noexcept;
/// @brief Returns a list of secret talents of the variant.
/// @return A list of secret talents of the variant.
[[nodiscard]] const ArbUt::List<ArbUt::StringView>& GetSecretTalents() const noexcept;
[[nodiscard]] const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& GetSecretTalents() const noexcept;
/// @brief Checks whether the species has a specific flag.
/// @param key The flag to check for.

View File

@@ -0,0 +1,25 @@
#ifndef CREATURELIB_TALENT_HPP
#define CREATURELIB_TALENT_HPP
#include <Arbutils/Collections/List.hpp>
#include <Arbutils/StringView.hpp>
#include <utility>
#include "../EffectParameter.hpp"
namespace CreatureLib::Library {
class Talent {
public:
Talent(const ArbUt::StringView& name, const ArbUt::StringView& effect, ArbUt::List<EffectParameter*> parameters)
: _name(name), _effect(effect), _parameters(std::move(parameters)) {}
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
[[nodiscard]] inline const ArbUt::StringView& GetEffect() const noexcept { return _effect; }
[[nodiscard]] inline const ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
private:
ArbUt::StringView _name;
ArbUt::StringView _effect;
ArbUt::List<EffectParameter*> _parameters;
};
}
#endif // CREATURELIB_TALENT_HPP

View File

@@ -4,13 +4,14 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, Creatu
CreatureLib::Library::AttackLibrary* attacks,
CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates,
TypeLibrary* typeLibrary)
TypeLibrary* typeLibrary, TalentLibrary* talentLibrary)
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
_typeLibrary(typeLibrary) {
_typeLibrary(typeLibrary), _talentLibrary(talentLibrary) {
EnsureNotNull(_settings)
EnsureNotNull(_species)
EnsureNotNull(_attacks)
EnsureNotNull(_items)
EnsureNotNull(_growthRates)
EnsureNotNull(_typeLibrary)
EnsureNotNull(_talentLibrary)
}

View File

@@ -6,6 +6,7 @@
#include "ItemLibrary.hpp"
#include "LibrarySettings.hpp"
#include "SpeciesLibrary.hpp"
#include "TalentLibrary.hpp"
#include "TypeLibrary.hpp"
namespace CreatureLib::Library {
@@ -20,11 +21,13 @@ namespace CreatureLib::Library {
std::unique_ptr<const ItemLibrary> _items;
std::unique_ptr<const GrowthRateLibrary> _growthRates;
std::unique_ptr<const TypeLibrary> _typeLibrary;
std::unique_ptr<const TalentLibrary> _talentLibrary;
public:
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary,
TalentLibrary* talentLibrary);
virtual ~DataLibrary() {}
@@ -46,6 +49,9 @@ namespace CreatureLib::Library {
[[nodiscard]] inline const std::unique_ptr<const TypeLibrary>& GetTypeLibrary() const noexcept {
return _typeLibrary;
}
[[nodiscard]] inline const std::unique_ptr<const TalentLibrary>& GetTalentLibrary() const noexcept {
return _talentLibrary;
}
};
}

View File

@@ -0,0 +1,14 @@
#ifndef CREATURELIB_TALENTLIBRARY_HPP
#define CREATURELIB_TALENTLIBRARY_HPP
#include "BaseLibrary.hpp"
#include "CreatureData/Talent.hpp"
namespace CreatureLib::Library {
class TalentLibrary : public BaseLibrary<Talent> {
public:
explicit TalentLibrary(size_t initialCapacity = 32) : BaseLibrary(initialCapacity){};
};
}
#endif // CREATURELIB_TALENTLIBRARY_HPP