Added functions for battle to manipulate volatile scripts.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-16 17:44:41 +01:00
parent 428483e73d
commit 65f054bfab
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 14 additions and 0 deletions

View File

@ -75,6 +75,11 @@ namespace CreatureLib::Battling {
inline const BattleResult& GetResult() const { return _battleResult; }
const std::vector<BattleSide*>& 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); }

View File

@ -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()) {