Move Script ownership to script holder, added OnRemove script hook.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -42,6 +42,7 @@ namespace CreatureLib::Battling {
|
||||
for (auto s : _sides) {
|
||||
delete s;
|
||||
}
|
||||
delete _currentTurnQueue;
|
||||
}
|
||||
|
||||
[[nodiscard]] const BattleLibrary* GetLibrary() const;
|
||||
|
||||
@@ -114,6 +114,8 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||
|
||||
void Battling::Creature::OverrideActiveTalent(const std::string& talent) {
|
||||
_hasOverridenTalent = true;
|
||||
_activeTalent->OnRemove();
|
||||
delete _activeTalent;
|
||||
_overridenTalentName = talent;
|
||||
_activeTalent = this->_library->LoadScript(ScriptResolver::ScriptCategory::Talent, talent);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ namespace CreatureLib::Battling {
|
||||
for (auto attack : _attacks) {
|
||||
delete attack;
|
||||
}
|
||||
delete _activeTalent;
|
||||
delete _status;
|
||||
};
|
||||
|
||||
virtual void Initialize() {
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace CreatureLib::Battling {
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~ExecutingAttack() = default;
|
||||
virtual ~ExecutingAttack() { delete _script; };
|
||||
|
||||
TargetData& GetAttackDataForTarget(Creature* creature) { return _targets[creature]; }
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace CreatureLib::Battling {
|
||||
virtual ~Script() = default;
|
||||
|
||||
virtual void Stack(){};
|
||||
virtual void OnRemove(){};
|
||||
|
||||
const std::string& GetName() { return _name; }
|
||||
|
||||
|
||||
@@ -11,6 +11,12 @@ namespace CreatureLib::Battling {
|
||||
std::unordered_map<std::string, size_t> _lookup;
|
||||
|
||||
public:
|
||||
~ScriptSet() {
|
||||
for (auto s : _scripts) {
|
||||
delete s;
|
||||
}
|
||||
}
|
||||
|
||||
void Add(Script* script) {
|
||||
auto f = _lookup.find(script->GetName());
|
||||
if (f != _lookup.end()) {
|
||||
@@ -24,12 +30,18 @@ namespace CreatureLib::Battling {
|
||||
void Remove(const std::string& key) {
|
||||
auto find = _lookup.find(key);
|
||||
if (find != _lookup.end()) {
|
||||
auto script = _scripts[find->second];
|
||||
script->OnRemove();
|
||||
delete script;
|
||||
_scripts.erase(_scripts.begin() + find.operator*().second);
|
||||
_lookup.erase(key);
|
||||
}
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (auto s : _scripts) {
|
||||
delete s;
|
||||
}
|
||||
_scripts.clear();
|
||||
_lookup.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user