Breaking change: rework of talents.
continuous-integration/drone/push Build is passing Details

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

View File

@ -79,8 +79,8 @@ export uint8_t CreatureLib_Creature_RestoreAllAttackUses(Creature* p) { Try(p->R
export bool CreatureLib_Creature_GetRealTalentIsSecret(const Creature* p) { return p->GetRealTalent().IsSecret(); } export bool CreatureLib_Creature_GetRealTalentIsSecret(const Creature* p) { return p->GetRealTalent().IsSecret(); }
export bool CreatureLib_Creature_GetRealTalentIndex(const Creature* p) { return p->GetRealTalent().GetIndex(); } export bool CreatureLib_Creature_GetRealTalentIndex(const Creature* p) { return p->GetRealTalent().GetIndex(); }
export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const char*& out) { export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const CreatureLib::Library::Talent*& out) {
Try(out = p->GetActiveTalent().c_str();) Try(out = p->GetActiveTalent().GetRaw();)
} }
export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) { export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
Try(p->OverrideActiveTalent(ArbUt::StringView(talent));) Try(p->OverrideActiveTalent(ArbUt::StringView(talent));)

View File

@ -4,8 +4,9 @@ using namespace CreatureLib::Library;
export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, LibrarySettings* settings, export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, LibrarySettings* settings,
SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items, SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items,
GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) { GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary,
Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);) TalentLibrary* talentLibrary) {
Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary, talentLibrary);)
} }
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; } export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
@ -15,4 +16,5 @@ SMART_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
SMART_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*); SMART_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*);
SMART_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*); SMART_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*);
SMART_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*); SMART_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*);
SMART_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*); SMART_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*);
SMART_GET_FUNC(DataLibrary, GetTalentLibrary, const TalentLibrary*);

View File

@ -7,8 +7,8 @@ export SpeciesVariant*
CreatureLib_SpeciesVariant_Construct(const char* name, float height, float weight, uint32_t baseExperience, CreatureLib_SpeciesVariant_Construct(const char* name, float height, float weight, uint32_t baseExperience,
uint8_t types[], size_t typeLength, uint16_t baseHealth, uint16_t baseAttack, uint8_t types[], size_t typeLength, uint16_t baseHealth, uint16_t baseAttack,
uint16_t baseDefense, uint16_t baseMagicalAttack, uint16_t baseMagicalDefense, uint16_t baseDefense, uint16_t baseMagicalAttack, uint16_t baseMagicalDefense,
uint16_t baseSpeed, const char* talents[], size_t talentsLength, uint16_t baseSpeed, const Talent* talents[], size_t talentsLength,
const char* secretTalents[], size_t secretTalentsLength, const Talent* secretTalents[], size_t secretTalentsLength,
const LearnableAttacks* attacks, const char* flags[], size_t flagsCount) { const LearnableAttacks* attacks, const char* flags[], size_t flagsCount) {
std::unordered_set<uint32_t> conversedFlags(flagsCount); std::unordered_set<uint32_t> conversedFlags(flagsCount);
@ -16,13 +16,13 @@ CreatureLib_SpeciesVariant_Construct(const char* name, float height, float weigh
conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i]));
} }
auto talentsWrapped = ArbUt::List<ArbUt::StringView>(talentsLength); auto talentsWrapped = ArbUt::List<ArbUt::BorrowedPtr<const Talent>>(talentsLength);
for (size_t i = 0; i < talentsLength; i++) { for (size_t i = 0; i < talentsLength; i++) {
talentsWrapped.Append(ArbUt::StringView(talents[i])); talentsWrapped.Append(talents[i]);
} }
auto secretTalentsWrapped = ArbUt::List<ArbUt::StringView>(secretTalentsLength); auto secretTalentsWrapped = ArbUt::List<ArbUt::BorrowedPtr<const Talent>>(secretTalentsLength);
for (size_t i = 0; i < secretTalentsLength; i++) { for (size_t i = 0; i < secretTalentsLength; i++) {
secretTalentsWrapped.Append(ArbUt::StringView(secretTalents[i])); secretTalentsWrapped.Append(secretTalents[i]);
} }
return new SpeciesVariant( return new SpeciesVariant(
@ -45,8 +45,8 @@ export uint16_t CreatureLib_SpeciesVariant_GetStatistic(SpeciesVariant* p, Creat
} }
SIMPLE_GET_FUNC(SpeciesVariant, GetTalentCount, size_t); SIMPLE_GET_FUNC(SpeciesVariant, GetTalentCount, size_t);
SIMPLE_GET_FUNC(SpeciesVariant, GetSecretTalentCount, size_t); SIMPLE_GET_FUNC(SpeciesVariant, GetSecretTalentCount, size_t);
export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, uint8_t index, const char*& out) { export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, uint8_t index, const Talent*& out) {
Try(out = p->GetTalent(TalentIndex(secret, index)).c_str();) Try(out = p->GetTalent(TalentIndex(secret, index)).GetRaw();)
} }
export const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(SpeciesVariant* p) { export const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(SpeciesVariant* p) {
return p->GetLearnableAttacks().GetRaw(); return p->GetLearnableAttacks().GetRaw();

View File

@ -20,8 +20,11 @@ namespace CreatureLib::Battling {
_weight(variant->GetWeight()), _height(variant->GetHeight()), _nickname(std::move(nickname)), _weight(variant->GetWeight()), _height(variant->GetHeight()), _nickname(std::move(nickname)),
_talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks), _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks),
_allowedExperienceGain(allowedExperienceGain) { _allowedExperienceGain(allowedExperienceGain) {
_activeTalent = _activeTalent = std::unique_ptr<BattleScript>(
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent())); _library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect()));
if (_activeTalent != nullptr) {
_activeTalent->OnInitialize(GetActiveTalent()->GetParameters());
}
for (auto t : _variant->GetTypes()) { for (auto t : _variant->GetTypes()) {
_types.push_back(t); _types.push_back(t);
} }
@ -65,8 +68,11 @@ namespace CreatureLib::Battling {
_height = variant->GetHeight(); _height = variant->GetHeight();
// Grab the new active talent. // Grab the new active talent.
_activeTalent = _activeTalent = std::unique_ptr<BattleScript>(
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent())); _library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect()));
if (_activeTalent != nullptr) {
_activeTalent->OnInitialize(GetActiveTalent()->GetParameters());
}
// We modify the health of the creature by the change in its max health. // We modify the health of the creature by the change in its max health.
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health); auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
@ -96,9 +102,9 @@ namespace CreatureLib::Battling {
RecalculateFlatStats(); RecalculateFlatStats();
} }
const ArbUt::StringView& Creature::GetActiveTalent() const { ArbUt::BorrowedPtr<const Library::Talent> Creature::GetActiveTalent() const {
if (_hasOverridenTalent) { if (_hasOverridenTalent && _overridenTalent.HasValue()) {
return _overridenTalentName; return _overridenTalent.GetValue();
} }
return _variant->GetTalent(_talentIndex); return _variant->GetTalent(_talentIndex);
} }
@ -233,7 +239,7 @@ namespace CreatureLib::Battling {
_activeTalent->OnRemove(); _activeTalent->OnRemove();
_activeTalent.reset(this->_library->LoadScript(this, ScriptCategory::Talent, talent)); _activeTalent.reset(this->_library->LoadScript(this, ScriptCategory::Talent, talent));
} }
_overridenTalentName = talent; _overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent);
} }
const std::vector<uint8_t>& Creature::GetTypes() const noexcept { return _types; } const std::vector<uint8_t>& Creature::GetTypes() const noexcept { return _types; }
@ -384,7 +390,7 @@ namespace CreatureLib::Battling {
c->_activeTalent = std::unique_ptr<BattleScript>(_activeTalent->Clone(c)); c->_activeTalent = std::unique_ptr<BattleScript>(_activeTalent->Clone(c));
} }
c->_hasOverridenTalent = _hasOverridenTalent; c->_hasOverridenTalent = _hasOverridenTalent;
c->_overridenTalentName = _overridenTalentName; c->_overridenTalent = _overridenTalent;
if (_status != nullptr) { if (_status != nullptr) {
c->_status = std::unique_ptr<BattleScript>(_status->Clone(c)); c->_status = std::unique_ptr<BattleScript>(_status->Clone(c));
} }

View File

@ -56,7 +56,7 @@ namespace CreatureLib::Battling {
std::unique_ptr<BattleScript> _activeTalent = {}; std::unique_ptr<BattleScript> _activeTalent = {};
bool _hasOverridenTalent = false; bool _hasOverridenTalent = false;
ArbUt::StringView _overridenTalentName = {}; ArbUt::OptionalBorrowedPtr<const Library::Talent> _overridenTalent = {};
ArbUt::OptionalUniquePtrList<LearnedAttack> _attacks = {}; ArbUt::OptionalUniquePtrList<LearnedAttack> _attacks = {};
bool _allowedExperienceGain = {}; bool _allowedExperienceGain = {};
@ -144,7 +144,7 @@ namespace CreatureLib::Battling {
} }
inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; } inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; }
const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; } const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; }
const ArbUt::StringView& GetActiveTalent() const; ArbUt::BorrowedPtr<const Library::Talent> GetActiveTalent() const;
/// Are we allowed to use this creature in a battle? /// Are we allowed to use this creature in a battle?
[[nodiscard]] virtual bool IsUsable() const noexcept; [[nodiscard]] virtual bool IsUsable() const noexcept;

View File

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

View File

@ -3,6 +3,7 @@
#include "../StatisticSet.hpp" #include "../StatisticSet.hpp"
#include "LearnableAttacks.hpp" #include "LearnableAttacks.hpp"
#include "Talent.hpp"
#include "TalentIndex.hpp" #include "TalentIndex.hpp"
namespace CreatureLib::Library { 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. /// @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, 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<uint8_t>& types, Library::StatisticSet<uint16_t> baseStats,
const ArbUt::List<ArbUt::StringView>& talents, const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& talents,
const ArbUt::List<ArbUt::StringView>& secretTalents, const LearnableAttacks* attacks, const ArbUt::List<ArbUt::BorrowedPtr<const Talent>>& secretTalents,
const std::unordered_set<uint32_t>& flags = {}); const LearnableAttacks* attacks, const std::unordered_set<uint32_t>& flags = {});
virtual ~SpeciesVariant(); virtual ~SpeciesVariant();
/// @brief Returns the unique name of the variant. /// @brief Returns the unique name of the variant.
@ -70,11 +71,15 @@ namespace CreatureLib::Library {
/// @brief Returns a talent name at a specified TalentIndex. /// @brief Returns a talent name at a specified TalentIndex.
/// @param index Whether it's a secret talent, and which index to get. /// @param index Whether it's a secret talent, and which index to get.
/// @return The name of the talent at the given TalentIndex. /// @return The name of the talent at the given TalentIndex.
[[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const; [[nodiscard]] const ArbUt::BorrowedPtr<const Talent>& GetTalent(const TalentIndex& index) const;
/// @brief Search for the index of a talent with a name. /// @brief Search for the index of a specific talent.
/// @param talent The name that's being looked for. /// @param talent The talent that's being looked for.
/// @return The index of the talent. /// @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. /// @brief Returns the attacks the variant can learn.
/// @return 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; [[nodiscard]] TalentIndex GetRandomTalent(ArbUt::Random& rand) const noexcept;
/// @brief Returns a list of talents of the variant. /// @brief Returns a list of talents of the variant.
/// @return 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. /// @brief Returns a list of secret talents of the variant.
/// @return 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. /// @brief Checks whether the species has a specific flag.
/// @param key The flag to check for. /// @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::AttackLibrary* attacks,
CreatureLib::Library::ItemLibrary* items, CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates, CreatureLib::Library::GrowthRateLibrary* growthRates,
TypeLibrary* typeLibrary) TypeLibrary* typeLibrary, TalentLibrary* talentLibrary)
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates), : _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
_typeLibrary(typeLibrary) { _typeLibrary(typeLibrary), _talentLibrary(talentLibrary) {
EnsureNotNull(_settings) EnsureNotNull(_settings)
EnsureNotNull(_species) EnsureNotNull(_species)
EnsureNotNull(_attacks) EnsureNotNull(_attacks)
EnsureNotNull(_items) EnsureNotNull(_items)
EnsureNotNull(_growthRates) EnsureNotNull(_growthRates)
EnsureNotNull(_typeLibrary) EnsureNotNull(_typeLibrary)
EnsureNotNull(_talentLibrary)
} }

View File

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

View File

@ -51,7 +51,7 @@ TEST_CASE("Override Creature talent") {
auto library = TestLibrary::Get(); auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create(); auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
creature->OverrideActiveTalent("foobar"); creature->OverrideActiveTalent("foobar");
REQUIRE(creature->GetActiveTalent() == "foobar"); REQUIRE(creature->GetActiveTalent()->GetName() == "foobar"_cnc);
delete creature; delete creature;
} }

View File

@ -4,12 +4,6 @@
#include "../../extern/doctest.hpp" #include "../../extern/doctest.hpp"
#include "../TestLibrary/TestLibrary.hpp" #include "../TestLibrary/TestLibrary.hpp"
TEST_CASE("Can Create Species Library") {
auto l = TestLibrary::BuildSpeciesLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE("Can Create Attack Library") { TEST_CASE("Can Create Attack Library") {
auto l = TestLibrary::BuildAttackLibrary(); auto l = TestLibrary::BuildAttackLibrary();
REQUIRE(l != nullptr); REQUIRE(l != nullptr);

View File

@ -9,8 +9,9 @@ BattleLibrary* TestLibrary::_library = nullptr;
BattleLibrary* TestLibrary::Get() { BattleLibrary* TestLibrary::Get() {
if (TestLibrary::_library == nullptr) { if (TestLibrary::_library == nullptr) {
auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), auto talentLibrary = BuildTalentLibrary();
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary()); auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(talentLibrary), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary(), talentLibrary);
auto statCalc = new BattleStatCalculator(); auto statCalc = new BattleStatCalculator();
auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new ExperienceLibrary(), auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new ExperienceLibrary(),
new ScriptResolver(), new MiscLibrary()); new ScriptResolver(), new MiscLibrary());
@ -19,14 +20,15 @@ BattleLibrary* TestLibrary::Get() {
return TestLibrary::_library; return TestLibrary::_library;
} }
SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { SpeciesLibrary* TestLibrary::BuildSpeciesLibrary(const TalentLibrary* talentLibrary) {
auto l = new SpeciesLibrary(); auto l = new SpeciesLibrary();
l->Insert("testSpecies1"_cnc.GetHash(), l->Insert("testSpecies1"_cnc.GetHash(),
new CreatureSpecies(0, "testSpecies1"_cnc, new CreatureSpecies(
new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1}, 0, "testSpecies1"_cnc,
StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10), {"testTalent"_cnc}, new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1}, StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10),
{"testSecretTalent"_cnc}, new LearnableAttacks(100)), {talentLibrary->Get("testTalent"_cnc)},
0.5f, "testGrowthRate"_cnc, 5)); {talentLibrary->Get("testSecretTalent"_cnc)}, new LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 5));
return l; return l;
} }
@ -75,4 +77,12 @@ TypeLibrary* TestLibrary::BuildTypeLibrary() {
return l; return l;
} }
TalentLibrary* TestLibrary::BuildTalentLibrary() {
auto* lib = new TalentLibrary();
lib->Insert("testTalent", new Talent("testTalent", "", {}));
lib->Insert("testSecretTalent", new Talent("testTalent", "", {}));
lib->Insert("foobar", new Talent("foobar", "", {}));
return lib;
}
#endif #endif

View File

@ -12,11 +12,12 @@ class TestLibrary {
static BattleLibrary* _library; static BattleLibrary* _library;
public: public:
static SpeciesLibrary* BuildSpeciesLibrary(); static SpeciesLibrary* BuildSpeciesLibrary(const TalentLibrary*);
static AttackLibrary* BuildAttackLibrary(); static AttackLibrary* BuildAttackLibrary();
static ItemLibrary* BuildItemLibrary(); static ItemLibrary* BuildItemLibrary();
static GrowthRateLibrary* BuildGrowthRateLibrary(); static GrowthRateLibrary* BuildGrowthRateLibrary();
static TypeLibrary* BuildTypeLibrary(); static TypeLibrary* BuildTypeLibrary();
static TalentLibrary* BuildTalentLibrary();
static BattleLibrary* Get(); static BattleLibrary* Get();
}; };