diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index 1c85a15..cb74f10 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -75,6 +75,11 @@ namespace CreatureLib::Battling { inline const BattleResult& GetResult() const { return _battleResult; } const std::vector& GetSides() const { return _sides; } + Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); } + void AddVolatileScript(const std::string& key) { + auto script = _library->LoadScript(ScriptResolver::ScriptCategory::Battle, key); + return _volatile.Add(script); + } void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); } void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); } diff --git a/src/Battling/ScriptHandling/ScriptSet.hpp b/src/Battling/ScriptHandling/ScriptSet.hpp index 09a17d1..7055b57 100644 --- a/src/Battling/ScriptHandling/ScriptSet.hpp +++ b/src/Battling/ScriptHandling/ScriptSet.hpp @@ -21,12 +21,21 @@ namespace CreatureLib::Battling { auto f = _lookup.find(script->GetName()); if (f != _lookup.end()) { _scripts[f.operator*().second]->Stack(); + delete script; return; } _scripts.push_back(script); _lookup.insert({script->GetName(), _scripts.size() - 1}); } + Script* Get(const std::string& key) const { + auto f = _lookup.find(key); + if (f != _lookup.end()) { + return _scripts[f->second]; + } + return nullptr; + } + void Remove(const std::string& key) { auto find = _lookup.find(key); if (find != _lookup.end()) {