From 4ef24dd122e58eb4ff80126e59b1d86efb0b24ed Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 8 Aug 2020 11:32:25 +0200 Subject: [PATCH] Helper method to restore all attack uses on a Creature. Signed-off-by: Deukhoofd --- CInterface/Battling/Creature.cpp | 1 + src/Battling/Models/Creature.cpp | 10 +++++++++- src/Battling/Models/Creature.hpp | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 265c901..59ee0f4 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -57,6 +57,7 @@ export uint8_t CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageS export uint8_t CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) { Try(p->Heal(health, canRevive);) } +export uint8_t CreatureLib_Creature_RestoreAllAttackUses(Creature* p) { Try(p->RestoreAllAttackUses();) } export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const char*& out) { Try(out = p->GetActiveTalent().c_str();) } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 479f6d2..5ad7eb1 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -171,6 +171,14 @@ void Battling::Creature::Heal(uint32_t amount, bool canRevive) { _currentHealth = newHealth; } +void Battling::Creature::RestoreAllAttackUses() noexcept { + for (auto& a : _attacks) { + if (a != nullptr) { + a->RestoreAllUses(); + } + } +} + void Battling::Creature::OverrideActiveTalent(const ArbUt::StringView& talent) { _hasOverridenTalent = true; if (_activeTalent != nullptr) { @@ -262,4 +270,4 @@ void Battling::Creature::AddVolatileScript(const ArbUt::StringView& name) { void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); } void Battling::Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); } void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); } -bool Battling::Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); } \ No newline at end of file +bool Battling::Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); } diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 813357b..89e56ab 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -120,6 +120,7 @@ namespace CreatureLib::Battling { void ChangeLevelBy(int8_t amount); void Damage(uint32_t damage, DamageSource source); void Heal(uint32_t amount, bool canRevive = false); + void RestoreAllAttackUses () noexcept; void OverrideActiveTalent(const ArbUt::StringView& talent); void AddExperience(uint32_t amount);