From e3c997af31267d35c82ca7de366624c791e8dbbe Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 28 May 2022 11:00:31 +0200 Subject: [PATCH] Adds support for changing talent by its hash, adds support for loading scripts by their name hash. --- src/Battling/Library/BattleLibrary.cpp | 7 ++++++- src/Battling/Library/BattleLibrary.hpp | 3 +++ src/Battling/Models/Creature.cpp | 9 +++++++++ src/Battling/Models/Creature.hpp | 1 + src/Battling/ScriptHandling/ScriptResolver.hpp | 17 ++++++++++++++--- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Battling/Library/BattleLibrary.cpp b/src/Battling/Library/BattleLibrary.cpp index 57ceb59..497db41 100644 --- a/src/Battling/Library/BattleLibrary.cpp +++ b/src/Battling/Library/BattleLibrary.cpp @@ -48,4 +48,9 @@ ArbUt::OptionalUniquePtr BattleLibrary::LoadScript(const ArbUt::Op ScriptCategory category, const ArbUt::StringView& scriptName) const { return _scriptResolver->LoadScript(owner, category, scriptName).TakeOwnership(); -} \ No newline at end of file +} +ArbUt::OptionalUniquePtr BattleLibrary::LoadScriptByHash(const ArbUt::OptionalBorrowedPtr& owner, + ScriptCategory category, + u32 scriptNameHash) const { + return _scriptResolver->LoadScriptByHash(owner, category, scriptNameHash).TakeOwnership(); +} diff --git a/src/Battling/Library/BattleLibrary.hpp b/src/Battling/Library/BattleLibrary.hpp index d7b3e6d..d884e3d 100644 --- a/src/Battling/Library/BattleLibrary.hpp +++ b/src/Battling/Library/BattleLibrary.hpp @@ -47,6 +47,9 @@ namespace CreatureLib::Battling { [[nodiscard]] ArbUt::OptionalUniquePtr LoadScript(const ArbUt::OptionalBorrowedPtr& owner, ScriptCategory category, const ArbUt::StringView& scriptName) const; + [[nodiscard]] ArbUt::OptionalUniquePtr + LoadScriptByHash(const ArbUt::OptionalBorrowedPtr& owner, ScriptCategory category, + u32 scriptNameHash) const; }; } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 5e97902..626c1fa 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -273,6 +273,15 @@ namespace CreatureLib::Battling { _overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent); } + void Creature::OverrideActiveTalentByHash(u32 talentHash) { + _hasOverridenTalent = true; + if (_activeTalent.HasValue()) { + _activeTalent.GetValue()->OnRemove(); + _activeTalent = this->_library->LoadScriptByHash(this, ScriptCategory::Talent, talentHash).TakeOwnership(); + } + _overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->GetByHash(talentHash); + } + void Creature::SetType(u8 index, u8 type) noexcept { if (_types.Count() > index) { _types[index] = type; diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 5b942ad..e7ca551 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -163,6 +163,7 @@ namespace CreatureLib::Battling { void Heal(u32 amount, bool canRevive = false); void RestoreAllAttackUses() noexcept; void OverrideActiveTalent(const ArbUt::StringView& talent); + void OverrideActiveTalentByHash(u32 talentHash); void AddExperience(u32 amount); void MarkOpponentAsSeen(ArbUt::BorrowedPtr creature) { _battleData.SeenOpponents.insert(creature); } diff --git a/src/Battling/ScriptHandling/ScriptResolver.hpp b/src/Battling/ScriptHandling/ScriptResolver.hpp index 9d184f2..2554932 100644 --- a/src/Battling/ScriptHandling/ScriptResolver.hpp +++ b/src/Battling/ScriptHandling/ScriptResolver.hpp @@ -18,9 +18,20 @@ namespace CreatureLib::Battling { virtual ~ScriptResolver() = default; virtual void Initialize([[maybe_unused]] BattleLibrary* non_null library){}; - virtual ArbUt::OptionalUniquePtr - LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr& owner, - [[maybe_unused]] ScriptCategory category, [[maybe_unused]] const ArbUt::StringView& scriptName) { + virtual ArbUt::OptionalUniquePtr LoadScript(const ArbUt::OptionalBorrowedPtr& owner, + ScriptCategory category, + const ArbUt::StringView& scriptName) { + (void)owner; + (void)category; + (void)scriptName; + return nullptr; + }; + + virtual ArbUt::OptionalUniquePtr LoadScriptByHash(const ArbUt::OptionalBorrowedPtr& owner, + ScriptCategory category, u32 scriptNameHash) { + (void)owner; + (void)category; + (void)scriptNameHash; return nullptr; };