diff --git a/src/Battling/Library/BattleLibrary.cpp b/src/Battling/Library/BattleLibrary.cpp index 2b8f7fd..6e5b083 100644 --- a/src/Battling/Library/BattleLibrary.cpp +++ b/src/Battling/Library/BattleLibrary.cpp @@ -1,7 +1,10 @@ +#include #include "BattleLibrary.hpp" -CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib, - CreatureLib::Battling::BattleStatCalculator *statCalculator, +using namespace CreatureLib::Battling; + +BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib, + BattleStatCalculator *statCalculator, DamageLibrary* damageLibrary, CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver) : _staticLib(staticLib), _statCalculator(statCalculator), @@ -9,48 +12,48 @@ CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLi _scriptResolver(scriptResolver) {} -CreatureLib::Battling::BattleLibrary::~BattleLibrary() { +BattleLibrary::~BattleLibrary() { delete _staticLib; delete _statCalculator; delete _damageLibrary; delete _criticalLibrary; + delete _scriptResolver; } -const CreatureLib::Library::LibrarySettings& CreatureLib::Battling::BattleLibrary::GetSettings() const { +const CreatureLib::Library::LibrarySettings& BattleLibrary::GetSettings() const { return _staticLib->GetSettings(); } -const CreatureLib::Battling::BattleStatCalculator *CreatureLib::Battling::BattleLibrary::GetStatCalculator() const { +const BattleStatCalculator *BattleLibrary::GetStatCalculator() const { return _statCalculator; } -const CreatureLib::Library::SpeciesLibrary* CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary() const { +const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const { return _staticLib->GetSpeciesLibrary(); } -const CreatureLib::Library::ItemLibrary* CreatureLib::Battling::BattleLibrary::GetItemLibrary() const { +const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const { return _staticLib->GetItemLibrary(); } -const CreatureLib::Library::AttackLibrary *CreatureLib::Battling::BattleLibrary::GetAttackLibrary() const { +const CreatureLib::Library::AttackLibrary *BattleLibrary::GetAttackLibrary() const { return _staticLib->GetAttackLibrary(); } -const CreatureLib::Library::TypeLibrary *CreatureLib::Battling::BattleLibrary::GetTypeLibrary() const { +const CreatureLib::Library::TypeLibrary *BattleLibrary::GetTypeLibrary() const { return _staticLib->GetTypeLibrary(); } -const CreatureLib::Battling::DamageLibrary *CreatureLib::Battling::BattleLibrary::GetDamageLibrary() const { +const DamageLibrary *BattleLibrary::GetDamageLibrary() const { return _damageLibrary; } -const CreatureLib::Battling::CriticalLibrary *CreatureLib::Battling::BattleLibrary::GetCriticalLibrary() const { +const CriticalLibrary *BattleLibrary::GetCriticalLibrary() const { return _criticalLibrary; } -CreatureLib::Battling::Script * -CreatureLib::Battling::BattleLibrary::LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory category, - const std::string &scriptName) { +Script* BattleLibrary::LoadScript(ScriptResolver::ScriptCategory category, const std::string &scriptName) { + assert(this->_scriptResolver != nullptr); return _scriptResolver->LoadScript(category, scriptName); } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 9a633c2..509e703 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -23,8 +23,11 @@ Battling::Creature::Creature(const Library::CreatureSpecies* species, const Libr __HeldItem(heldItem), _nickname(std::move(nickname)), _talentIndex(talent), + _hasOverridenTalent(false), _attacks(std::move(attacks)) - {} +{ + __CurrentHealth = GetBoostedStat(Core::Statistic::Health); +} @@ -39,6 +42,7 @@ void Battling::Creature::SetBattle(Battling::Battle *battle) { void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary *library) { this->_library = library; + _activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent()); } const std::string &Battling::Creature::GetNickname() const { @@ -47,7 +51,10 @@ const std::string &Battling::Creature::GetNickname() const { return _nickname; } -const std::string &Battling::Creature::GetTalent() const { +const std::string &Battling::Creature::GetActiveTalent() const { + if (_hasOverridenTalent){ + return _overridenTalentName; + } return __Variant->GetTalent(_talentIndex); } @@ -131,6 +138,12 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source) __CurrentHealth -= damage; } +void Battling::Creature::OverrideActiveTalent(const std::string& talent){ + _hasOverridenTalent = true; + _overridenTalentName = talent; + _activeTalent = this->_library->LoadScript(ScriptResolver::ScriptCategory::Talent, talent); +} + const std::vector& Battling::Creature::GetTypes() const { //HOOK: override types. return this->__Variant->GetTypes(); diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 87b64ee..358b4f6 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -44,6 +44,9 @@ namespace CreatureLib::Battling{ int8_t _talentIndex; Script* _activeTalent = nullptr; + bool _hasOverridenTalent; + std::string _overridenTalentName = ""; + std::vector _attacks; Script* _status = nullptr; @@ -57,19 +60,22 @@ namespace CreatureLib::Battling{ virtual ~Creature() = default; - const std::string& GetNickname() const; - const std::string& GetTalent() const; - void ChangeLevel(int8_t amount); - void Damage(uint32_t damage, DamageSource source); - void SetBattleData(Battle* battle, BattleSide* side); Battle* GetBattle() const; BattleSide* GetBattleSide() const; + const std::string& GetNickname() const; + const std::string& GetActiveTalent() const; + [[nodiscard]] bool IsFainted() const; [[nodiscard]] const std::vector& GetTypes() const; [[nodiscard]] bool HasType(uint8_t type) const; + void ChangeLevel(int8_t amount); + void Damage(uint32_t damage, DamageSource source); + void OverrideActiveTalent(const std::string& talent); + + void GetActiveScripts(std::vector &scripts) override; //region Stat APIs