Breaking change: rework of talents.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
33d384c464
commit
59313e6da8
|
@ -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_GetRealTalentIndex(const Creature* p) { return p->GetRealTalent().GetIndex(); }
|
||||
|
||||
export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const char*& out) {
|
||||
Try(out = p->GetActiveTalent().c_str();)
|
||||
export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const CreatureLib::Library::Talent*& out) {
|
||||
Try(out = p->GetActiveTalent().GetRaw();)
|
||||
}
|
||||
export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
|
||||
Try(p->OverrideActiveTalent(ArbUt::StringView(talent));)
|
||||
|
|
|
@ -4,8 +4,9 @@ using namespace CreatureLib::Library;
|
|||
|
||||
export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, LibrarySettings* settings,
|
||||
SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items,
|
||||
GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) {
|
||||
Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);)
|
||||
GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary,
|
||||
TalentLibrary* talentLibrary) {
|
||||
Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary, talentLibrary);)
|
||||
}
|
||||
|
||||
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
|
||||
|
@ -16,3 +17,4 @@ SMART_GET_FUNC(DataLibrary, GetAttackLibrary, const AttackLibrary*);
|
|||
SMART_GET_FUNC(DataLibrary, GetItemLibrary, const ItemLibrary*);
|
||||
SMART_GET_FUNC(DataLibrary, GetGrowthRates, const GrowthRateLibrary*);
|
||||
SMART_GET_FUNC(DataLibrary, GetTypeLibrary, const TypeLibrary*);
|
||||
SMART_GET_FUNC(DataLibrary, GetTalentLibrary, const TalentLibrary*);
|
|
@ -7,8 +7,8 @@ export SpeciesVariant*
|
|||
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,
|
||||
uint16_t baseDefense, uint16_t baseMagicalAttack, uint16_t baseMagicalDefense,
|
||||
uint16_t baseSpeed, const char* talents[], size_t talentsLength,
|
||||
const char* secretTalents[], size_t secretTalentsLength,
|
||||
uint16_t baseSpeed, const Talent* talents[], size_t talentsLength,
|
||||
const Talent* secretTalents[], size_t secretTalentsLength,
|
||||
const LearnableAttacks* attacks, const char* flags[], size_t 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]));
|
||||
}
|
||||
|
||||
auto talentsWrapped = ArbUt::List<ArbUt::StringView>(talentsLength);
|
||||
auto talentsWrapped = ArbUt::List<ArbUt::BorrowedPtr<const Talent>>(talentsLength);
|
||||
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++) {
|
||||
secretTalentsWrapped.Append(ArbUt::StringView(secretTalents[i]));
|
||||
secretTalentsWrapped.Append(secretTalents[i]);
|
||||
}
|
||||
|
||||
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, GetSecretTalentCount, size_t);
|
||||
export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, uint8_t index, const char*& out) {
|
||||
Try(out = p->GetTalent(TalentIndex(secret, index)).c_str();)
|
||||
export uint8_t CreatureLib_SpeciesVariant_GetTalent(SpeciesVariant* p, bool secret, uint8_t index, const Talent*& out) {
|
||||
Try(out = p->GetTalent(TalentIndex(secret, index)).GetRaw();)
|
||||
}
|
||||
export const LearnableAttacks* CreatureLib_SpeciesVariant_GetLearnableAttacks(SpeciesVariant* p) {
|
||||
return p->GetLearnableAttacks().GetRaw();
|
||||
|
|
|
@ -20,8 +20,11 @@ namespace CreatureLib::Battling {
|
|||
_weight(variant->GetWeight()), _height(variant->GetHeight()), _nickname(std::move(nickname)),
|
||||
_talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks),
|
||||
_allowedExperienceGain(allowedExperienceGain) {
|
||||
_activeTalent =
|
||||
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()));
|
||||
_activeTalent = std::unique_ptr<BattleScript>(
|
||||
_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect()));
|
||||
if (_activeTalent != nullptr) {
|
||||
_activeTalent->OnInitialize(GetActiveTalent()->GetParameters());
|
||||
}
|
||||
for (auto t : _variant->GetTypes()) {
|
||||
_types.push_back(t);
|
||||
}
|
||||
|
@ -65,8 +68,11 @@ namespace CreatureLib::Battling {
|
|||
_height = variant->GetHeight();
|
||||
|
||||
// Grab the new active talent.
|
||||
_activeTalent =
|
||||
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()));
|
||||
_activeTalent = std::unique_ptr<BattleScript>(
|
||||
_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.
|
||||
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
|
||||
|
@ -96,9 +102,9 @@ namespace CreatureLib::Battling {
|
|||
RecalculateFlatStats();
|
||||
}
|
||||
|
||||
const ArbUt::StringView& Creature::GetActiveTalent() const {
|
||||
if (_hasOverridenTalent) {
|
||||
return _overridenTalentName;
|
||||
ArbUt::BorrowedPtr<const Library::Talent> Creature::GetActiveTalent() const {
|
||||
if (_hasOverridenTalent && _overridenTalent.HasValue()) {
|
||||
return _overridenTalent.GetValue();
|
||||
}
|
||||
return _variant->GetTalent(_talentIndex);
|
||||
}
|
||||
|
@ -233,7 +239,7 @@ namespace CreatureLib::Battling {
|
|||
_activeTalent->OnRemove();
|
||||
_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; }
|
||||
|
@ -384,7 +390,7 @@ namespace CreatureLib::Battling {
|
|||
c->_activeTalent = std::unique_ptr<BattleScript>(_activeTalent->Clone(c));
|
||||
}
|
||||
c->_hasOverridenTalent = _hasOverridenTalent;
|
||||
c->_overridenTalentName = _overridenTalentName;
|
||||
c->_overridenTalent = _overridenTalent;
|
||||
if (_status != nullptr) {
|
||||
c->_status = std::unique_ptr<BattleScript>(_status->Clone(c));
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace CreatureLib::Battling {
|
|||
std::unique_ptr<BattleScript> _activeTalent = {};
|
||||
|
||||
bool _hasOverridenTalent = false;
|
||||
ArbUt::StringView _overridenTalentName = {};
|
||||
ArbUt::OptionalBorrowedPtr<const Library::Talent> _overridenTalent = {};
|
||||
|
||||
ArbUt::OptionalUniquePtrList<LearnedAttack> _attacks = {};
|
||||
bool _allowedExperienceGain = {};
|
||||
|
@ -144,7 +144,7 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; }
|
||||
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?
|
||||
[[nodiscard]] virtual bool IsUsable() const noexcept;
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -51,7 +51,7 @@ TEST_CASE("Override Creature talent") {
|
|||
auto library = TestLibrary::Get();
|
||||
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
||||
creature->OverrideActiveTalent("foobar");
|
||||
REQUIRE(creature->GetActiveTalent() == "foobar");
|
||||
REQUIRE(creature->GetActiveTalent()->GetName() == "foobar"_cnc);
|
||||
delete creature;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
#include "../../extern/doctest.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") {
|
||||
auto l = TestLibrary::BuildAttackLibrary();
|
||||
REQUIRE(l != nullptr);
|
||||
|
|
|
@ -9,8 +9,9 @@ BattleLibrary* TestLibrary::_library = nullptr;
|
|||
|
||||
BattleLibrary* TestLibrary::Get() {
|
||||
if (TestLibrary::_library == nullptr) {
|
||||
auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
|
||||
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
|
||||
auto talentLibrary = BuildTalentLibrary();
|
||||
auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(talentLibrary), BuildAttackLibrary(),
|
||||
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary(), talentLibrary);
|
||||
auto statCalc = new BattleStatCalculator();
|
||||
auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new ExperienceLibrary(),
|
||||
new ScriptResolver(), new MiscLibrary());
|
||||
|
@ -19,13 +20,14 @@ BattleLibrary* TestLibrary::Get() {
|
|||
return TestLibrary::_library;
|
||||
}
|
||||
|
||||
SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||
SpeciesLibrary* TestLibrary::BuildSpeciesLibrary(const TalentLibrary* talentLibrary) {
|
||||
auto l = new SpeciesLibrary();
|
||||
l->Insert("testSpecies1"_cnc.GetHash(),
|
||||
new CreatureSpecies(0, "testSpecies1"_cnc,
|
||||
new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1},
|
||||
StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10), {"testTalent"_cnc},
|
||||
{"testSecretTalent"_cnc}, new LearnableAttacks(100)),
|
||||
new CreatureSpecies(
|
||||
0, "testSpecies1"_cnc,
|
||||
new SpeciesVariant("default"_cnc, 1, 1, 10, {0, 1}, StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10),
|
||||
{talentLibrary->Get("testTalent"_cnc)},
|
||||
{talentLibrary->Get("testSecretTalent"_cnc)}, new LearnableAttacks(100)),
|
||||
0.5f, "testGrowthRate"_cnc, 5));
|
||||
return l;
|
||||
}
|
||||
|
@ -75,4 +77,12 @@ TypeLibrary* TestLibrary::BuildTypeLibrary() {
|
|||
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
|
|
@ -12,11 +12,12 @@ class TestLibrary {
|
|||
static BattleLibrary* _library;
|
||||
|
||||
public:
|
||||
static SpeciesLibrary* BuildSpeciesLibrary();
|
||||
static SpeciesLibrary* BuildSpeciesLibrary(const TalentLibrary*);
|
||||
static AttackLibrary* BuildAttackLibrary();
|
||||
static ItemLibrary* BuildItemLibrary();
|
||||
static GrowthRateLibrary* BuildGrowthRateLibrary();
|
||||
static TypeLibrary* BuildTypeLibrary();
|
||||
static TalentLibrary* BuildTalentLibrary();
|
||||
|
||||
static BattleLibrary* Get();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue