aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Spells/Spell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Spells/Spell.cpp')
-rw-r--r--src/server/game/Spells/Spell.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index e825900a545..69163ed6066 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -60,6 +60,7 @@
#include "TemporarySummon.h"
#include "TradeData.h"
#include "TraitPackets.h"
+#include "UniqueTrackablePtr.h"
#include "Util.h"
#include "VMapFactory.h"
#include "Vehicle.h"
@@ -484,18 +485,19 @@ SpellValue::SpellValue(SpellInfo const* proto, WorldObject const* caster)
class TC_GAME_API SpellEvent : public BasicEvent
{
public:
- SpellEvent(Spell* spell);
+ explicit SpellEvent(Spell* spell);
~SpellEvent();
bool Execute(uint64 e_time, uint32 p_time) override;
void Abort(uint64 e_time) override;
bool IsDeletable() const override;
- Spell const* GetSpell() const { return m_Spell; }
+ Spell const* GetSpell() const { return m_Spell.get(); }
+ Trinity::unique_weak_ptr<Spell> GetSpellWeakPtr() const { return m_Spell; }
std::string GetDebugInfo() const { return m_Spell->GetDebugInfo(); }
protected:
- Spell* m_Spell;
+ Trinity::unique_trackable_ptr<Spell> m_Spell;
};
Spell::Spell(WorldObject* caster, SpellInfo const* info, TriggerCastFlags triggerFlags, ObjectGuid originalCasterGUID /*= ObjectGuid::Empty*/,
@@ -8201,9 +8203,8 @@ Unit* Spell::GetUnitCasterForEffectHandlers() const
return m_originalCaster ? m_originalCaster : m_caster->ToUnit();
}
-SpellEvent::SpellEvent(Spell* spell) : BasicEvent()
+SpellEvent::SpellEvent(Spell* spell) : BasicEvent(), m_Spell(spell)
{
- m_Spell = spell;
}
SpellEvent::~SpellEvent()
@@ -8211,11 +8212,7 @@ SpellEvent::~SpellEvent()
if (m_Spell->getState() != SPELL_STATE_FINISHED)
m_Spell->cancel();
- if (m_Spell->IsDeletable())
- {
- delete m_Spell;
- }
- else
+ if (!m_Spell->IsDeletable())
{
TC_LOG_ERROR("spells", "~SpellEvent: {} {} tried to delete non-deletable spell {}. Was not deleted, causes memory leak.",
(m_Spell->GetCaster()->GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature"), m_Spell->GetCaster()->GetGUID().ToString(), m_Spell->m_spellInfo->Id);
@@ -9043,6 +9040,11 @@ std::string Spell::GetDebugInfo() const
return sstr.str();
}
+Trinity::unique_weak_ptr<Spell> Spell::GetWeakPtr() const
+{
+ return _spellEvent->GetSpellWeakPtr();
+}
+
bool Spell::IsWithinLOS(WorldObject const* source, WorldObject const* target, bool targetAsSourceLocation, VMAP::ModelIgnoreFlags ignoreFlags) const
{
if (m_spellInfo->HasAttribute(SPELL_ATTR2_IGNORE_LINE_OF_SIGHT))