Adds support for changing talent by its hash, adds support for loading scripts by their name hash.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-05-28 11:00:31 +02:00
parent 782e9b90a8
commit e3c997af31
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 33 additions and 4 deletions

View File

@ -48,4 +48,9 @@ ArbUt::OptionalUniquePtr<BattleScript> BattleLibrary::LoadScript(const ArbUt::Op
ScriptCategory category, ScriptCategory category,
const ArbUt::StringView& scriptName) const { const ArbUt::StringView& scriptName) const {
return _scriptResolver->LoadScript(owner, category, scriptName).TakeOwnership(); return _scriptResolver->LoadScript(owner, category, scriptName).TakeOwnership();
} }
ArbUt::OptionalUniquePtr<BattleScript> BattleLibrary::LoadScriptByHash(const ArbUt::OptionalBorrowedPtr<void>& owner,
ScriptCategory category,
u32 scriptNameHash) const {
return _scriptResolver->LoadScriptByHash(owner, category, scriptNameHash).TakeOwnership();
}

View File

@ -47,6 +47,9 @@ namespace CreatureLib::Battling {
[[nodiscard]] ArbUt::OptionalUniquePtr<BattleScript> LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, [[nodiscard]] ArbUt::OptionalUniquePtr<BattleScript> LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner,
ScriptCategory category, ScriptCategory category,
const ArbUt::StringView& scriptName) const; const ArbUt::StringView& scriptName) const;
[[nodiscard]] ArbUt::OptionalUniquePtr<BattleScript>
LoadScriptByHash(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
u32 scriptNameHash) const;
}; };
} }

View File

@ -273,6 +273,15 @@ namespace CreatureLib::Battling {
_overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent); _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 { void Creature::SetType(u8 index, u8 type) noexcept {
if (_types.Count() > index) { if (_types.Count() > index) {
_types[index] = type; _types[index] = type;

View File

@ -163,6 +163,7 @@ namespace CreatureLib::Battling {
void Heal(u32 amount, bool canRevive = false); void Heal(u32 amount, bool canRevive = false);
void RestoreAllAttackUses() noexcept; void RestoreAllAttackUses() noexcept;
void OverrideActiveTalent(const ArbUt::StringView& talent); void OverrideActiveTalent(const ArbUt::StringView& talent);
void OverrideActiveTalentByHash(u32 talentHash);
void AddExperience(u32 amount); void AddExperience(u32 amount);
void MarkOpponentAsSeen(ArbUt::BorrowedPtr<Creature> creature) { _battleData.SeenOpponents.insert(creature); } void MarkOpponentAsSeen(ArbUt::BorrowedPtr<Creature> creature) { _battleData.SeenOpponents.insert(creature); }

View File

@ -18,9 +18,20 @@ namespace CreatureLib::Battling {
virtual ~ScriptResolver() = default; virtual ~ScriptResolver() = default;
virtual void Initialize([[maybe_unused]] BattleLibrary* non_null library){}; virtual void Initialize([[maybe_unused]] BattleLibrary* non_null library){};
virtual ArbUt::OptionalUniquePtr<BattleScript> virtual ArbUt::OptionalUniquePtr<BattleScript> LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner,
LoadScript([[maybe_unused]] const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
[[maybe_unused]] ScriptCategory category, [[maybe_unused]] const ArbUt::StringView& scriptName) { const ArbUt::StringView& scriptName) {
(void)owner;
(void)category;
(void)scriptName;
return nullptr;
};
virtual ArbUt::OptionalUniquePtr<BattleScript> LoadScriptByHash(const ArbUt::OptionalBorrowedPtr<void>& owner,
ScriptCategory category, u32 scriptNameHash) {
(void)owner;
(void)category;
(void)scriptNameHash;
return nullptr; return nullptr;
}; };