From b6171ebdc1ef7892a8e948e28b66581e63a470d5 Mon Sep 17 00:00:00 2001 From: gsemaj Date: Tue, 25 Jul 2023 10:41:45 -0400 Subject: [PATCH] Add `clearBuffs` --- src/Combat.cpp | 14 ++++++++++++++ src/Entities.hpp | 2 ++ src/Player.hpp | 1 + 3 files changed, 17 insertions(+) diff --git a/src/Combat.cpp b/src/Combat.cpp index b83583a..93e3542 100644 --- a/src/Combat.cpp +++ b/src/Combat.cpp @@ -54,6 +54,7 @@ void Player::removeBuff(int buffId) { void Player::removeBuff(int buffId, int buffClass) { if(hasBuff(buffId)) { buffs[buffId]->clear((BuffClass)buffClass); + // buff might not be stale since another buff class might remain if(buffs[buffId]->isStale()) { delete buffs[buffId]; buffs.erase(buffId); @@ -61,6 +62,17 @@ void Player::removeBuff(int buffId, int buffClass) { } } +void Player::clearBuffs(bool force) { + for(auto buff : buffs) { + if(!force) { + removeBuff(buff.first); + } else { + delete buff.second; + } + } + buffs.clear(); +} + bool Player::hasBuff(int buffId) { auto buff = buffs.find(buffId); return buff != buffs.end() && !buff->second->isStale(); @@ -176,6 +188,8 @@ void CombatNPC::removeBuff(int buffId) { /* stubbed */ } void CombatNPC::removeBuff(int buffId, int buffClass) { /* stubbed */ } +void CombatNPC::clearBuffs(bool force) { /* stubbed */ } + bool CombatNPC::hasBuff(int buffId) { /* stubbed */ return false; } diff --git a/src/Entities.hpp b/src/Entities.hpp index 28a47c0..816fbbe 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -48,6 +48,7 @@ public: virtual Buff* getBuff(int) = 0; virtual void removeBuff(int) = 0; virtual void removeBuff(int, int) = 0; + virtual void clearBuffs(bool) = 0; virtual bool hasBuff(int) = 0; virtual int getCompositeCondition() = 0; virtual int takeDamage(EntityRef, int) = 0; @@ -123,6 +124,7 @@ struct CombatNPC : public BaseNPC, public ICombatant { virtual Buff* getBuff(int buffId) override; virtual void removeBuff(int buffId) override; virtual void removeBuff(int buffId, int buffClass) override; + virtual void clearBuffs(bool force) override; virtual bool hasBuff(int buffId) override; virtual int getCompositeCondition() override; virtual int takeDamage(EntityRef src, int amt) override; diff --git a/src/Player.hpp b/src/Player.hpp index 224ea90..5ca112c 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -93,6 +93,7 @@ struct Player : public Entity, public ICombatant { virtual Buff* getBuff(int buffId) override; virtual void removeBuff(int buffId) override; virtual void removeBuff(int buffId, int buffClass) override; + virtual void clearBuffs(bool force) override; virtual bool hasBuff(int buffId) override; virtual int getCompositeCondition() override; virtual int takeDamage(EntityRef src, int amt) override;