Skip to content

Commit 1e041a6

Browse files
committed
CMaNGOS: Add SpellScript & AuraScript hooks
Partial implementation. Still need to fix up method files.
1 parent 95e6738 commit 1e041a6

7 files changed

Lines changed: 283 additions & 14 deletions

File tree

ElunaSpellWrapper.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ElunaProcInfo::ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask,
1919
#endif
2020
{
2121
}
22-
22+
#if defined ELUNA_TRINITY
2323
ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map)
2424
: _actor(procInfo.GetActor()), _actionTarget(procInfo.GetActionTarget()), _typeMask(procInfo.GetTypeMask()), _spellTypeMask(procInfo.GetSpellTypeMask()), _spellPhaseMask(procInfo.GetSpellPhaseMask())
2525
, _hitMask(procInfo.GetHitMask()), _spell(const_cast<Spell*>(procInfo.GetProcSpell())), _spellInfo(procInfo.GetSpellInfo()), _schoolMask(procInfo.GetSchoolMask()), _damage(0)
@@ -58,13 +58,29 @@ ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map)
5858
}
5959
}
6060
}
61+
#elif defined ELUNA_CMANGOS
62+
ElunaProcInfo::ElunaProcInfo(ProcExecutionData& procInfo, Map* map)
63+
: _actor(procInfo.attacker), _actionTarget(procInfo.victim), _spell(const_cast<Spell*>(procInfo.spell))
64+
, _spellInfo(procInfo.spellInfo), _damage(0)
65+
, _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0)
66+
, _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map)
67+
#ifdef TRACKABLE_PTR_NAMESPACE
68+
,m_scriptRef(this, NoopAuraDeleter())
69+
#endif
70+
{
71+
}
72+
#endif
6173

6274
SpellInfo const* ElunaProcInfo::GetSpellInfo() const
6375
{
6476
if (_spellInfo)
6577
return _spellInfo;
6678
if (_spell)
79+
#if defined ELUNA_TRINITY
6780
return _spell->GetSpellInfo();
81+
#elif defined ELUNA_CMANGOS
82+
return _spell->GetSpellProto();
83+
#endif
6884
return nullptr;
6985
}
7086

@@ -80,7 +96,7 @@ void ElunaProcInfo::SetHeal(uint32 heal)
8096
_heal = heal;
8197
_effectiveHeal = heal;
8298
}
83-
99+
#if defined ELUNA_TRINITY
84100
void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const
85101
{
86102
if (DamageInfo* damageInfo = procInfo.GetDamageInfo())
@@ -122,11 +138,45 @@ void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const
122138
}
123139
}
124140
}
141+
#elif defined ELUNA_CMANGOS
142+
void ElunaProcInfo::ApplyToProcEventInfo(ProcExecutionData& procInfo) const
143+
{
144+
if (HasDamage())
145+
{
146+
int32 damageDiff = static_cast<int32>(_damage) - static_cast<int32>(procInfo.damage);
147+
if (damageDiff != 0)
148+
procInfo.damage = damageDiff;
149+
150+
uint32 currentAbsorb = procInfo.absorb;
151+
152+
uint32 absorbToAdd = (_damageAbsorb > currentAbsorb) ? (_damageAbsorb - currentAbsorb) : 0;
153+
154+
if (absorbToAdd > 0)
155+
procInfo.absorb = absorbToAdd;
156+
}
157+
158+
if (HasHeal())
159+
{
160+
uint32 currentAbsorb = procInfo.absorb;
161+
uint32 absorbToAdd = (_healAbsorb > currentAbsorb) ? (_healAbsorb - currentAbsorb) : 0;
162+
163+
if (absorbToAdd > 0)
164+
procInfo.absorb = absorbToAdd;
165+
166+
procInfo.healthGain = _effectiveHeal;
167+
}
168+
}
169+
#endif
125170

171+
#ifdef ELUNA_TRINITY
126172
ElunaSpellInfo::ElunaSpellInfo(uint32 spellId) : _spellInfo(sSpellMgr->GetSpellInfo(spellId))
127173
{
128-
#ifdef ELUNA_TRINITY
129174
if (_spellInfo)
130175
m_scriptRef = Trinity::unique_trackable_ptr<ElunaSpellInfo>(this, NoopAuraDeleter());
176+
#elif defined ELUNA_CMANGOS
177+
ElunaSpellInfo::ElunaSpellInfo(uint32 spellId) : _spellInfo(sSpellMgr.GetSpellEntry(spellId))
178+
{
179+
if (_spellInfo)
180+
m_scriptRef = MaNGOS::unique_trackable_ptr<ElunaSpellInfo>(this, NoopAuraDeleter());
131181
#endif
132182
}

ElunaSpellWrapper.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
class Unit;
1010
class Spell;
1111
class Map;
12+
#ifdef ELUNA_TRINITY
1213
class SpellInfo;
1314
class ProcEventInfo;
1415
class DamageInfo;
1516
class HealInfo;
16-
#ifdef ELUNA_TRINITY
17-
enum SpellSchoolMask : uint32;
18-
#else
19-
enum SpellSchoolMask;
20-
#endif
2117
enum DamageEffectType : uint8;
2218
enum WeaponAttackType : uint8;
19+
#else
20+
class SpellEntry;
21+
class ProcExecutionData;
22+
enum DamageEffectType;
23+
enum WeaponAttackType;
24+
typedef SpellEntry SpellInfo;
25+
#endif
26+
enum SpellSchoolMask : uint32;
2327
#ifdef ELUNA_TRINITY
2428
namespace Trinity
2529
{
@@ -29,6 +33,15 @@ namespace Trinity
2933
template<typename T>
3034
class unique_weak_ptr;
3135
}
36+
#elif defined ELUNA_CMANGOS
37+
namespace MaNGOS
38+
{
39+
template<typename T>
40+
class unique_trackable_ptr;
41+
42+
template<typename T>
43+
class unique_weak_ptr;
44+
}
3245
#endif
3346

3447
class ElunaProcInfo
@@ -60,14 +73,20 @@ class ElunaProcInfo
6073
struct NoopAuraDeleter { void operator()(ElunaProcInfo*) const { } };
6174
#ifdef ELUNA_TRINITY
6275
Trinity::unique_trackable_ptr<ElunaProcInfo> m_scriptRef;
76+
#elif defined ELUNA_CMANGOS
77+
MaNGOS::unique_trackable_ptr<ElunaProcInfo> m_scriptRef;
6378
#endif
6479

6580
public:
6681
ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask,
6782
uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask,
6883
Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map);
6984

85+
#if defined ELUNA_TRINITY
7086
explicit ElunaProcInfo(ProcEventInfo& procInfo, Map* map);
87+
#elif defined ELUNA_CMANGOS
88+
explicit ElunaProcInfo(ProcExecutionData& procInfo, Map* map);
89+
#endif
7190
~ElunaProcInfo()
7291
{
7392
#ifdef TRACKABLE_PTR_NAMESPACE
@@ -114,8 +133,11 @@ class ElunaProcInfo
114133
const Map* GetMap() const { return _map; }
115134
#ifdef ELUNA_TRINITY
116135
Trinity::unique_weak_ptr<ElunaProcInfo> GetWeakPtr() const { return m_scriptRef; }
117-
#endif
118136
void ApplyToProcEventInfo(ProcEventInfo& procInfo) const;
137+
#elif defined ELUNA_CMANGOS
138+
MaNGOS::unique_weak_ptr<ElunaProcInfo> GetWeakPtr() const { return m_scriptRef; }
139+
void ApplyToProcEventInfo(ProcExecutionData& procInfo) const;
140+
#endif
119141
};
120142

121143
class ElunaSpellInfo
@@ -125,6 +147,8 @@ class ElunaSpellInfo
125147
struct NoopAuraDeleter { void operator()(ElunaSpellInfo*) const {} };
126148
#ifdef ELUNA_TRINITY
127149
Trinity::unique_trackable_ptr<ElunaSpellInfo> m_scriptRef;
150+
#elif defined ELUNA_CMANGOS
151+
MaNGOS::unique_trackable_ptr<ElunaSpellInfo> m_scriptRef;
128152
#endif
129153
public:
130154
ElunaSpellInfo(uint32 spellId);
@@ -137,6 +161,8 @@ class ElunaSpellInfo
137161
SpellInfo const* GetSpellInfo() const { return _spellInfo; }
138162
#ifdef ELUNA_TRINITY
139163
Trinity::unique_weak_ptr<ElunaSpellInfo> GetWeakPtr() const { return m_scriptRef; }
164+
#elif defined ELUNA_CMANGOS
165+
MaNGOS::unique_weak_ptr<ElunaSpellInfo> GetWeakPtr() const { return m_scriptRef; }
140166
#endif
141167
};
142168

ElunaTemplate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ ElunaConstrainedObjectRef<Aura> GetWeakPtrFor(Aura const* obj)
2020
#endif
2121
return { obj->GetWeakPtr(), map };
2222
}
23-
23+
#if defined ELUNA_TRINITY
2424
ElunaConstrainedObjectRef<AuraEffect> GetWeakPtrFor(AuraEffect const* obj)
2525
{
2626
Map* map = obj->GetBase()->GetOwner()->GetMap();
2727
return { obj->GetWeakPtr(), map };
2828
}
29-
29+
#endif
3030
ElunaConstrainedObjectRef<ElunaProcInfo> GetWeakPtrFor(ElunaProcInfo const* obj)
3131
{
3232
return { obj->GetWeakPtr(), obj->GetMap()};

ElunaTemplate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ struct ElunaConstrainedObjectRef
6363
};
6464

6565
ElunaConstrainedObjectRef<Aura> GetWeakPtrFor(Aura const* obj);
66+
#if defined ELUNA_TRINITY
6667
ElunaConstrainedObjectRef<AuraEffect> GetWeakPtrFor(AuraEffect const* obj);
68+
#endif
6769
ElunaConstrainedObjectRef<ElunaProcInfo> GetWeakPtrFor(ElunaProcInfo const* obj);
6870
ElunaConstrainedObjectRef<BattleGround> GetWeakPtrFor(BattleGround const* obj);
6971
ElunaConstrainedObjectRef<Group> GetWeakPtrFor(Group const* obj);

LuaEngine.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ class ELUNA_GAME_API Eluna
639639
void OnBGDestroy(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
640640

641641
/* Spell */
642+
#ifdef ELUNA_TRINITY
642643
void OnSpellCast(Spell* pSpell, bool skipCheck);
643644
bool OnAuraApplication(Aura* aura, AuraEffect const* auraEff, Unit* target, uint8 mode, bool apply);
644645
void OnAuraDispel(Aura* aura, DispelInfo* dispelInfo);
@@ -662,6 +663,31 @@ class ELUNA_GAME_API Eluna
662663
void OnSpellHit(Spell* pSpell);
663664
void OnAfterSpellHit(Spell* pSpell);
664665
void OnEffectCalcAbsorb(Spell* pSpell, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount);
666+
#else
667+
void OnSpellCast(Spell* pSpell, bool skipCheck);
668+
bool OnAuraApplication(Aura* aura, Unit* target, uint8 mode, bool apply);
669+
void OnAuraDispel(Aura* aura, Unit* dispeller, uint32 dispellingSpellId, uint32 originalStacks);
670+
bool OnPeriodicTick(Aura* aura, Unit* target);
671+
void OnPeriodicUpdate(Aura* aura);
672+
void OnAuraCalcAmount(Aura* aura, int32& amount, bool& canBeRecalculated);
673+
void OnCalcPeriodic(Aura* aura, bool& isPeriodic, int32& amplitude);
674+
bool OnAuraCanProc(Aura* aura, ProcExecutionData& procInfo);
675+
bool OnAuraProc(Aura* aura, ProcExecutionData& procInfo);
676+
uint32 OnCheckCast(Spell* pSpell);
677+
void OnBeforeCast(Spell* pSpell);
678+
void OnAfterCast(Spell* pSpell);
679+
void OnObjectAreaTargetSelect(Spell* pSpell, uint8 effIndex, std::list<WorldObject*>& targets);
680+
void OnObjectTargetSelect(Spell* pSpell, uint8 effIndex, WorldObject*& target);
681+
void OnDestinationTargetSelect(Spell* pSpell, uint8 effIndex, SpellCastTargets& target);
682+
bool OnEffectLaunch(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
683+
bool OnEffectLaunchTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
684+
bool OnEffectHit(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
685+
bool OnEffectHitTarget(Spell* pSpell, uint8 effIndex, uint8 mode, bool preventDefault);
686+
void OnBeforeSpellHit(Spell* pSpell, uint8 missInfo);
687+
void OnSpellHit(Spell* pSpell);
688+
void OnAfterSpellHit(Spell* pSpell);
689+
void OnEffectCalcAbsorb(Spell* pSpell, SpellNonMeleeDamage const& damageInfo, uint32& resistAmount, int32& absorbAmount);
690+
#endif
665691
};
666692
template<> Unit* Eluna::CHECKOBJ<Unit>(int narg, bool error);
667693
template<> Object* Eluna::CHECKOBJ<Object>(int narg, bool error);

0 commit comments

Comments
 (0)