diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index eff0b92..855511a 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -153,11 +153,11 @@ void Battle::ValidateBattleState() { this->_battleResult = BattleResult::Conclusive(winningSide); EndBattle(); } -void Battle::AddVolatileScript(const ArbUt::StringView& key) { +BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) { auto script = _volatile.Get(key); if (script.has_value()) { script.value()->Stack(); - return; + return script.value(); } script = _library->LoadScript(ScriptCategory::Battle, key); if (!script.has_value()) { @@ -165,6 +165,6 @@ void Battle::AddVolatileScript(const ArbUt::StringView& key) { } return _volatile.Add(script.value().GetRaw()); } -void Battle::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); } +BattleScript* Battle::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); } void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); } void Battle::DisplayText(const ArbUt::StringView& text) { TriggerEventListener(text); } diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index 972cabd..2cb59d2 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -92,8 +92,8 @@ namespace CreatureLib::Battling { std::optional> GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); } - void AddVolatileScript(const ArbUt::StringView& key); - void AddVolatileScript(BattleScript* script); + BattleScript* AddVolatileScript(const ArbUt::StringView& key); + BattleScript* AddVolatileScript(BattleScript* script); void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); } void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); } void RemoveVolatileScript(BattleScript* script); diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index bccd525..d8b11df 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -279,20 +279,20 @@ namespace CreatureLib::Battling { _heldItem = v.value(); } - void Creature::AddVolatileScript(const ArbUt::StringView& name) { + BattleScript* Creature::AddVolatileScript(const ArbUt::StringView& name) { auto script = _volatile.Get(name); if (script.has_value()) { script.value()->Stack(); - return; + return script.value(); } script = this->_library->LoadScript(ScriptCategory::Creature, name); if (!script.has_value()) { THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'."); } - _volatile.Add(script.value().GetRaw()); + return _volatile.Add(script.value().GetRaw()); } - void Creature::AddVolatileScript(BattleScript* script) { _volatile.Add(script); } + BattleScript* Creature::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); } void Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); } void Creature::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); } bool 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 22bdafd..1da863a 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -134,8 +134,8 @@ namespace CreatureLib::Battling { size_t ScriptCount() const override; void GetActiveScripts(ArbUt::List& scripts) override; void ClearVolatileScripts(); - void AddVolatileScript(const ArbUt::StringView& name); - void AddVolatileScript(BattleScript* script); + BattleScript* AddVolatileScript(const ArbUt::StringView& name); + BattleScript* AddVolatileScript(BattleScript* script); void RemoveVolatileScript(const ArbUt::BasicStringView& name); void RemoveVolatileScript(BattleScript* script); bool HasVolatileScript(const ArbUt::BasicStringView& name) const; diff --git a/src/Battling/ScriptHandling/ScriptSet.hpp b/src/Battling/ScriptHandling/ScriptSet.hpp index 633fa76..54e411e 100644 --- a/src/Battling/ScriptHandling/ScriptSet.hpp +++ b/src/Battling/ScriptHandling/ScriptSet.hpp @@ -15,16 +15,17 @@ namespace CreatureLib::Battling { static constexpr size_t defaultCapacity = 8; ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){}; - void Add(BattleScript* script) { + BattleScript* Add(BattleScript* script) { auto v = _lookup.TryGet(script->GetName()); if (v.has_value()) { _scripts[v.value()]->Stack(); delete script; - return; + return _scripts[v.value()]; } _scripts.Append(script); _lookup.Insert(script->GetName(), _scripts.Count() - 1); + return script; } std::optional> Get(const ArbUt::BasicStringView& key) const {