Added Remove Volatile functions for battle and creatures.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-23 11:11:47 +01:00
parent 645ba95bbc
commit 5f891cd4ed
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 20 additions and 9 deletions

View File

@ -119,3 +119,15 @@ void Battle::ValidateBattleState() {
this->_battleResult = BattleResult::Conclusive(winningSide); this->_battleResult = BattleResult::Conclusive(winningSide);
this->_hasEnded = true; this->_hasEnded = true;
} }
void Battle::AddVolatileScript(const std::string& key) {
auto script = _volatile.Get(key);
if (script != nullptr) {
script->Stack();
return;
}
script = _library->LoadScript(ScriptCategory::Battle, key);
return _volatile.Add(script);
}
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
void Battle::RemoveVolatileScript(const std::string& name) { _volatile.Remove(name); }
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }

View File

@ -76,15 +76,10 @@ namespace CreatureLib::Battling {
const std::vector<BattleSide*>& GetSides() const { return _sides; } const std::vector<BattleSide*>& GetSides() const { return _sides; }
Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); } Script* GetVolatileScript(const std::string& key) const { return _volatile.Get(key); }
void AddVolatileScript(const std::string& key) { void AddVolatileScript(const std::string& key);
auto script = _volatile.Get(key); void AddVolatileScript(Script* script);
if (script != nullptr) { void RemoveVolatileScript(const std::string& name);
script->Stack(); void RemoveVolatileScript(Script* script);
return;
}
script = _library->LoadScript(ScriptCategory::Battle, key);
return _volatile.Add(script);
}
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); } void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); } void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }

View File

@ -196,3 +196,5 @@ void Battling::Creature::AddVolatileScript(const std::string& name) {
} }
void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); } void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
void Battling::Creature::RemoveVolatileScript(const std::string& name) { _volatile.Remove(name); }
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }

View File

@ -118,6 +118,8 @@ namespace CreatureLib::Battling {
void ClearVolatileScripts(); void ClearVolatileScripts();
void AddVolatileScript(const std::string& name); void AddVolatileScript(const std::string& name);
void AddVolatileScript(Script* script); void AddVolatileScript(Script* script);
void RemoveVolatileScript(const std::string& name);
void RemoveVolatileScript(Script* script);
std::vector<LearnedAttack*>& GetAttacks() { return _attacks; } std::vector<LearnedAttack*>& GetAttacks() { return _attacks; }