diff --git a/src/game/Entities/Object.h b/src/game/Entities/Object.h index abfac0a7980..a38958b81af 100644 --- a/src/game/Entities/Object.h +++ b/src/game/Entities/Object.h @@ -628,6 +628,8 @@ class Object inline bool IsGameObject() const { return GetTypeId() == TYPEID_GAMEOBJECT; } inline bool IsCorpse() const { return GetTypeId() == TYPEID_CORPSE; } + MaNGOS::unique_weak_ptr GetWeakPtr() const { return m_scriptRef; } + protected: Object(); diff --git a/src/game/Entities/Vehicle.cpp b/src/game/Entities/Vehicle.cpp index a1707f9fb50..354424dd4e7 100644 --- a/src/game/Entities/Vehicle.cpp +++ b/src/game/Entities/Vehicle.cpp @@ -960,4 +960,10 @@ void VehicleInfo::RemoveSeatMods(Unit* passenger, uint32 seatFlags) } } +MaNGOS::unique_weak_ptr VehicleInfo::GetWeakPtr() const +{ + Unit* pVehicle = (Unit*)m_owner; + return pVehicle->GetVehicleInfoWeakPtr(); +} + /*! @} */ diff --git a/src/game/Entities/Vehicle.h b/src/game/Entities/Vehicle.h index 03c26b27e61..9d708bea1c1 100644 --- a/src/game/Entities/Vehicle.h +++ b/src/game/Entities/Vehicle.h @@ -107,6 +107,8 @@ class VehicleInfo : public TransportBase void RespawnAccessories(int32 seatIndex = -1); void RecallAccessories(float distance = 0.f, int32 seatIndex = -1); + MaNGOS::unique_weak_ptr GetWeakPtr() const; + private: // Internal use to calculate the boarding position void CalculateBoardingPositionOf(float gx, float gy, float gz, float go, float& lx, float& ly, float& lz, float& lo) const; diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index bf255bf5a0d..7b4bcfdf6dd 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -9980,3 +9980,7 @@ SpellCastResult Spell::CheckVehicle(Unit const* caster, SpellEntry const& spellI return SPELL_CAST_OK; } +MaNGOS::unique_weak_ptr Spell::GetWeakPtr() const +{ + return m_spellEvent->GetSpellWeakPtr(); +} diff --git a/src/game/Spells/Spell.h b/src/game/Spells/Spell.h index a2558119179..33a32915ce2 100644 --- a/src/game/Spells/Spell.h +++ b/src/game/Spells/Spell.h @@ -329,7 +329,9 @@ class SpellEvent : public BasicEvent virtual bool IsDeletable() const override; Spell* GetSpell() const { return m_Spell.get(); } - protected: + MaNGOS::unique_weak_ptr GetSpellWeakPtr() const { return m_Spell; } + + protected: MaNGOS::unique_trackable_ptr m_Spell; }; @@ -903,6 +905,9 @@ class Spell void SetDamageDoneModifier(float mod, SpellEffectIndex effIdx); void SetIgnoreOwnerLevel(bool state) { m_ignoreOwnerLevel = state; } void SetUsableWhileStunned(bool state) { m_usableWhileStunned = state; } + + MaNGOS::unique_weak_ptr GetWeakPtr() const; + protected: void SendLoot(ObjectGuid guid, LootType loottype, LockType lockType); bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data