Skip to content

Commit 0926b00

Browse files
committed
Add weakptr for auraeffect, add support new spell aura script hooks.
1 parent d499633 commit 0926b00

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

src/server/game/Spells/Auras/SpellAuraEffects.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ AuraEffect::AuraEffect(Aura* base, SpellEffectInfo const& spellEfffectInfo, int3
385385
m_base(base), m_spellInfo(base->GetSpellInfo()), m_spellEffectInfo(spellEfffectInfo),
386386
m_baseAmount(baseAmount ? *baseAmount : spellEfffectInfo.BasePoints),
387387
_amount(), m_spellmod(nullptr), _periodicTimer(0), _amplitude(0), _ticksDone(0),
388-
m_canBeRecalculated(true), m_isPeriodic(false)
388+
m_canBeRecalculated(true), m_isPeriodic(false), m_scriptRef(this, NoopAuraEffectDeleter())
389389
{
390390
CalculatePeriodic(caster, true, false);
391391

@@ -396,6 +396,7 @@ m_canBeRecalculated(true), m_isPeriodic(false)
396396

397397
AuraEffect::~AuraEffect()
398398
{
399+
m_scriptRef = nullptr;
399400
delete m_spellmod;
400401
}
401402

@@ -720,11 +721,6 @@ void AuraEffect::HandleEffect(AuraApplication * aurApp, uint8 mode, bool apply)
720721
ApplySpellMod(aurApp->GetTarget(), apply);
721722

722723
// call scripts helping/replacing effect handlers
723-
#ifdef ELUNA
724-
if (aurApp->GetTarget())
725-
if (Eluna* e = aurApp->GetTarget()->GetEluna())
726-
e->OnAuraApplication(GetBase(), uint8(GetEffIndex()), mode, apply);
727-
#endif
728724
bool prevented = false;
729725
if (apply)
730726
prevented = GetBase()->CallScriptEffectApplyHandlers(this, aurApp, (AuraEffectHandleModes)mode);

src/server/game/Spells/Auras/SpellAuraEffects.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class TC_GAME_API AuraEffect
9999

100100
SpellEffectInfo const& GetSpellEffectInfo() const { return m_spellEffectInfo; }
101101

102+
Trinity::unique_weak_ptr<AuraEffect> GetWeakPtr() const { return m_scriptRef; }
102103
private:
103104
Aura* const m_base;
104105

@@ -120,6 +121,8 @@ class TC_GAME_API AuraEffect
120121

121122
float GetCritChanceFor(Unit const* caster, Unit const* target) const;
122123

124+
struct NoopAuraEffectDeleter { void operator()(AuraEffect*) const { /*noop - not managed*/ } };
125+
Trinity::unique_trackable_ptr<AuraEffect> m_scriptRef;
123126
public:
124127
// aura effect apply/remove handlers
125128
void HandleNULL(AuraApplication const* /*aurApp*/, uint8 /*mode*/, bool /*apply*/) const

src/server/game/Spells/Auras/SpellAuras.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include "Vehicle.h"
3838
#include "World.h"
3939
#include "WorldPacket.h"
40+
#ifdef ELUNA
41+
#include "LuaEngine.h"
42+
#endif
4043

4144
AuraCreateInfo::AuraCreateInfo(SpellInfo const* spellInfo, uint8 auraEffMask, WorldObject* owner) :
4245
_spellInfo(spellInfo), _auraEffectMask(auraEffMask), _owner(owner)
@@ -2203,6 +2206,12 @@ void Aura::CallScriptDispel(DispelInfo* dispelInfo)
22032206

22042207
(*scritr)->_FinishScriptCall();
22052208
}
2209+
2210+
#ifdef ELUNA
2211+
if (GetCaster())
2212+
if (Eluna* e = GetCaster()->GetEluna())
2213+
e->OnAuraDispel(this, dispelInfo);
2214+
#endif
22062215
}
22072216

22082217
void Aura::CallScriptAfterDispel(DispelInfo* dispelInfo)
@@ -2235,6 +2244,15 @@ bool Aura::CallScriptEffectApplyHandlers(AuraEffect const* aurEff, AuraApplicati
22352244
(*scritr)->_FinishScriptCall();
22362245
}
22372246

2247+
#ifdef ELUNA
2248+
if (!preventDefault)
2249+
{
2250+
if (aurApp->GetTarget())
2251+
if (Eluna* e = aurApp->GetTarget()->GetEluna())
2252+
preventDefault = e->OnAuraApplication(aurApp->GetBase(), aurEff, aurApp->GetTarget(), mode, true);
2253+
}
2254+
#endif
2255+
22382256
return preventDefault;
22392257
}
22402258

@@ -2254,6 +2272,16 @@ bool Aura::CallScriptEffectRemoveHandlers(AuraEffect const* aurEff, AuraApplicat
22542272

22552273
(*scritr)->_FinishScriptCall();
22562274
}
2275+
2276+
#ifdef ELUNA
2277+
if (!preventDefault)
2278+
{
2279+
if (aurApp->GetTarget())
2280+
if (Eluna* e = aurApp->GetTarget()->GetEluna())
2281+
preventDefault = e->OnAuraApplication(aurApp->GetBase(), aurEff, aurApp->GetTarget(), mode, false);
2282+
}
2283+
#endif
2284+
22572285
return preventDefault;
22582286
}
22592287

@@ -2302,6 +2330,15 @@ bool Aura::CallScriptEffectPeriodicHandlers(AuraEffect const* aurEff, AuraApplic
23022330
(*scritr)->_FinishScriptCall();
23032331
}
23042332

2333+
#ifdef ELUNA
2334+
if (!preventDefault)
2335+
{
2336+
if (aurApp->GetTarget())
2337+
if (Eluna* e = aurApp->GetTarget()->GetEluna())
2338+
preventDefault = e->OnPerodicTick(aurApp->GetBase(), aurEff, aurApp->GetTarget());
2339+
}
2340+
#endif
2341+
23052342
return preventDefault;
23062343
}
23072344

@@ -2317,6 +2354,12 @@ void Aura::CallScriptEffectUpdatePeriodicHandlers(AuraEffect* aurEff)
23172354

23182355
(*scritr)->_FinishScriptCall();
23192356
}
2357+
2358+
#ifdef ELUNA
2359+
if (aurEff->GetCaster())
2360+
if (Eluna* e = aurEff->GetCaster()->GetEluna())
2361+
e->OnPerodicTick(aurEff->GetBase(), aurEff);
2362+
#endif
23202363
}
23212364

23222365
void Aura::CallScriptEffectCalcAmountHandlers(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated)
@@ -2331,6 +2374,11 @@ void Aura::CallScriptEffectCalcAmountHandlers(AuraEffect const* aurEff, int32& a
23312374

23322375
(*scritr)->_FinishScriptCall();
23332376
}
2377+
#ifdef ELUNA
2378+
if (aurEff->GetCaster())
2379+
if (Eluna* e = aurEff->GetCaster()->GetEluna())
2380+
e->OnAuraCalcAmount(aurEff->GetBase(), aurEff, amount, canBeRecalculated);
2381+
#endif
23342382
}
23352383

23362384
void Aura::CallScriptEffectCalcPeriodicHandlers(AuraEffect const* aurEff, bool& isPeriodic, int32& amplitude)
@@ -2345,6 +2393,11 @@ void Aura::CallScriptEffectCalcPeriodicHandlers(AuraEffect const* aurEff, bool&
23452393

23462394
(*scritr)->_FinishScriptCall();
23472395
}
2396+
#ifdef ELUNA
2397+
if (aurEff->GetCaster())
2398+
if (Eluna* e = aurEff->GetCaster()->GetEluna())
2399+
e->OnCalcPerodic(aurEff->GetBase(), aurEff, isPeriodic, amplitude);
2400+
#endif
23482401
}
23492402

23502403
void Aura::CallScriptEffectCalcSpellModHandlers(AuraEffect const* aurEff, SpellModifier*& spellMod)

0 commit comments

Comments
 (0)