From 6f0e664e749c38d4a6c7e1d98e85509a008289a8 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 28 May 2022 11:24:16 +0200 Subject: [PATCH] Adds support for removing volatile script by its hash, checking if Creature has attack by hash. --- src/Battling/Models/Battle.hpp | 2 +- src/Battling/Models/BattleSide.hpp | 2 +- src/Battling/Models/Creature.cpp | 1 + src/Battling/Models/Creature.hpp | 11 +++++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index b63e11f..a8d6bd1 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -99,7 +99,7 @@ namespace CreatureLib::Battling { BattleScript* non_null AddVolatileScript(const ArbUt::StringView& key); BattleScript* non_null AddVolatileScript(BattleScript* non_null script); void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); } - void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); } + void RemoveVolatileScriptByHash(u32 keyHash) { _volatile.Remove(keyHash); } void RemoveVolatileScript(BattleScript* non_null script); bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); } bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); } diff --git a/src/Battling/Models/BattleSide.hpp b/src/Battling/Models/BattleSide.hpp index 24420eb..a530e49 100644 --- a/src/Battling/Models/BattleSide.hpp +++ b/src/Battling/Models/BattleSide.hpp @@ -116,7 +116,7 @@ namespace CreatureLib::Battling { BattleScript* non_null AddVolatileScript(const ArbUt::StringView& key); BattleScript* non_null AddVolatileScript(BattleScript* non_null script); void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); } - void RemoveVolatileScript(u32 keyHash) { _volatile.Remove(keyHash); } + void RemoveVolatileScriptByHash(u32 keyHash) { _volatile.Remove(keyHash); } void RemoveVolatileScript(BattleScript* non_null script); bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); } bool HasVolatileScript(u32 keyHash) const { return _volatile.Has(keyHash); } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 5e97902..c6eab66 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -400,6 +400,7 @@ namespace CreatureLib::Battling { BattleScript* Creature::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); } void Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); } + void Creature::RemoveVolatileScriptByHash(u32 nameHash) { _volatile.Remove(nameHash); } void Creature::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); } bool Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); } void Creature::AddAttack(LearnedAttack* attack) { diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 5b942ad..48970ef 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -177,6 +177,7 @@ namespace CreatureLib::Battling { BattleScript* non_null AddVolatileScript(const ArbUt::StringView& name); BattleScript* non_null AddVolatileScript(BattleScript* non_null script); void RemoveVolatileScript(const ArbUt::BasicStringView& name); + void RemoveVolatileScriptByHash(u32 nameHash); void RemoveVolatileScript(BattleScript* non_null script); bool HasVolatileScript(const ArbUt::BasicStringView& name) const; @@ -191,6 +192,16 @@ namespace CreatureLib::Battling { return false; } + bool HasAttackByHash(u32 nameHash) { + for (auto& a : _attacks) { + if (a == nullptr) + continue; + if (a->GetAttack()->GetName().GetHash() == nameHash) + return true; + } + return false; + } + ArbUt::OptionalBorrowedPtr GetDisplaySpecies() const noexcept; ArbUt::OptionalBorrowedPtr GetDisplayVariant() const noexcept;