Skip to content

Commit 0ab2263

Browse files
authored
Add SpellScript & AuraScript hooks (#524)
1 parent 37280da commit 0ab2263

21 files changed

Lines changed: 7569 additions & 33 deletions

ElunaIncludes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "ScriptMgr.h"
4141
#include "Spell.h"
4242
#include "SpellAuras.h"
43+
#include "SpellAuraEffects.h"
4344
#include "SpellMgr.h"
4445
#include "TemporarySummon.h"
4546
#include "WorldPacket.h"

ElunaMgr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ void ElunaMgr::Destroy(ElunaInfo const& info)
5757

5858
ElunaInfo::~ElunaInfo()
5959
{
60-
if (IsValid() && sElunaMgr)
61-
sElunaMgr->Destroy(key);
6260
}
6361

6462
bool ElunaInfo::IsValid() const

ElunaSpellWrapper.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
3+
* This program is free software licensed under GPL version 3
4+
* Please see the included DOCS/LICENSE.md for more information
5+
*/
6+
#include "ElunaSpellWrapper.h"
7+
#include "ElunaIncludes.h"
8+
#include "ElunaTemplate.h"
9+
10+
ElunaProcInfo::ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask,
11+
uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask,
12+
Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map)
13+
: _actor(actor), _actionTarget(actionTarget), _typeMask(typeMask), _spellTypeMask(spellTypeMask), _spellPhaseMask(spellPhaseMask)
14+
, _hitMask(hitMask), _spell(spell), _spellInfo(spellInfo), _schoolMask(schoolMask), _damage(0)
15+
, _damageType(DIRECT_DAMAGE), _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0)
16+
, _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map)
17+
#ifdef TRACKABLE_PTR_NAMESPACE
18+
, m_scriptRef(this, NoopAuraDeleter())
19+
#endif
20+
{
21+
}
22+
23+
ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map)
24+
: _actor(procInfo.GetActor()), _actionTarget(procInfo.GetActionTarget()), _typeMask(procInfo.GetTypeMask()), _spellTypeMask(procInfo.GetSpellTypeMask()), _spellPhaseMask(procInfo.GetSpellPhaseMask())
25+
, _hitMask(procInfo.GetHitMask()), _spell(const_cast<Spell*>(procInfo.GetProcSpell())), _spellInfo(procInfo.GetSpellInfo()), _schoolMask(procInfo.GetSchoolMask()), _damage(0)
26+
, _damageType(DIRECT_DAMAGE), _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0)
27+
, _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map)
28+
#ifdef TRACKABLE_PTR_NAMESPACE
29+
, m_scriptRef(this, NoopAuraDeleter())
30+
#endif
31+
{
32+
if (DamageInfo* damageInfo = procInfo.GetDamageInfo())
33+
{
34+
_damage = damageInfo->GetDamage();
35+
_damageType = damageInfo->GetDamageType();
36+
_attackType = damageInfo->GetAttackType();
37+
_damageAbsorb = damageInfo->GetAbsorb();
38+
_resist = damageInfo->GetResist();
39+
_block = damageInfo->GetBlock();
40+
41+
if (damageInfo->GetSpellInfo())
42+
{
43+
_spellInfo = damageInfo->GetSpellInfo();
44+
_schoolMask = damageInfo->GetSchoolMask();
45+
}
46+
}
47+
48+
if (HealInfo* healInfo = procInfo.GetHealInfo())
49+
{
50+
_heal = healInfo->GetHeal();
51+
_effectiveHeal = healInfo->GetEffectiveHeal();
52+
_healAbsorb = healInfo->GetAbsorb();
53+
54+
if (healInfo->GetSpellInfo() && !_spellInfo)
55+
{
56+
_spellInfo = healInfo->GetSpellInfo();
57+
_schoolMask = healInfo->GetSchoolMask();
58+
}
59+
}
60+
}
61+
62+
SpellInfo const* ElunaProcInfo::GetSpellInfo() const
63+
{
64+
if (_spellInfo)
65+
return _spellInfo;
66+
if (_spell)
67+
return _spell->GetSpellInfo();
68+
return nullptr;
69+
}
70+
71+
void ElunaProcInfo::SetDamage(uint32 damage, DamageEffectType damageType, WeaponAttackType attackType)
72+
{
73+
_damage = damage;
74+
_damageType = damageType;
75+
_attackType = attackType;
76+
}
77+
78+
void ElunaProcInfo::SetHeal(uint32 heal)
79+
{
80+
_heal = heal;
81+
_effectiveHeal = heal;
82+
}
83+
84+
void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const
85+
{
86+
if (DamageInfo* damageInfo = procInfo.GetDamageInfo())
87+
{
88+
if (HasDamage())
89+
{
90+
int32 damageDiff = static_cast<int32>(_damage) - static_cast<int32>(damageInfo->GetDamage());
91+
if (damageDiff != 0)
92+
damageInfo->ModifyDamage(damageDiff);
93+
94+
uint32 currentAbsorb = damageInfo->GetAbsorb();
95+
uint32 currentResist = damageInfo->GetResist();
96+
uint32 currentBlock = damageInfo->GetBlock();
97+
98+
uint32 absorbToAdd = (_damageAbsorb > currentAbsorb) ? (_damageAbsorb - currentAbsorb) : 0;
99+
uint32 resistToAdd = (_resist > currentResist) ? (_resist - currentResist) : 0;
100+
uint32 blockToAdd = (_block > currentBlock) ? (_block - currentBlock) : 0;
101+
102+
if (absorbToAdd > 0)
103+
damageInfo->AbsorbDamage(absorbToAdd);
104+
if (resistToAdd > 0)
105+
damageInfo->ResistDamage(resistToAdd);
106+
if (blockToAdd > 0)
107+
damageInfo->BlockDamage(blockToAdd);
108+
}
109+
}
110+
111+
if (HealInfo* healInfo = procInfo.GetHealInfo())
112+
{
113+
if (HasHeal())
114+
{
115+
uint32 currentAbsorb = healInfo->GetAbsorb();
116+
uint32 absorbToAdd = (_healAbsorb > currentAbsorb) ? (_healAbsorb - currentAbsorb) : 0;
117+
118+
if (absorbToAdd > 0)
119+
healInfo->AbsorbHeal(absorbToAdd);
120+
121+
healInfo->SetEffectiveHeal(_effectiveHeal);
122+
}
123+
}
124+
}
125+
126+
ElunaSpellInfo::ElunaSpellInfo(uint32 spellId) : _spellInfo(sSpellMgr->GetSpellInfo(spellId))
127+
{
128+
#ifdef ELUNA_TRINITY
129+
if (_spellInfo)
130+
m_scriptRef = Trinity::unique_trackable_ptr<ElunaSpellInfo>(this, NoopAuraDeleter());
131+
#endif
132+
}

ElunaSpellWrapper.h

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
3+
* This program is free software licensed under GPL version 3
4+
* Please see the included DOCS/LICENSE.md for more information
5+
*/
6+
#ifndef _ELUNA_PROCINFO_H
7+
#define _ELUNA_PROCINFO_H
8+
#include "LuaEngine.h"
9+
class Unit;
10+
class Spell;
11+
class Map;
12+
class SpellInfo;
13+
class ProcEventInfo;
14+
class DamageInfo;
15+
class HealInfo;
16+
#ifdef ELUNA_TRINITY
17+
enum SpellSchoolMask : uint32;
18+
#else
19+
enum SpellSchoolMask;
20+
#endif
21+
enum DamageEffectType : uint8;
22+
enum WeaponAttackType : uint8;
23+
#ifdef ELUNA_TRINITY
24+
namespace Trinity
25+
{
26+
template<typename T>
27+
class unique_trackable_ptr;
28+
29+
template<typename T>
30+
class unique_weak_ptr;
31+
}
32+
#endif
33+
34+
class ElunaProcInfo
35+
{
36+
private:
37+
Unit* _actor;
38+
Unit* _actionTarget;
39+
uint32 _typeMask;
40+
uint32 _spellTypeMask;
41+
uint32 _spellPhaseMask;
42+
uint32 _hitMask;
43+
Spell* _spell;
44+
45+
SpellInfo const* _spellInfo;
46+
SpellSchoolMask _schoolMask;
47+
48+
uint32 _damage;
49+
DamageEffectType _damageType;
50+
WeaponAttackType _attackType;
51+
uint32 _damageAbsorb;
52+
uint32 _resist;
53+
uint32 _block;
54+
55+
uint32 _heal;
56+
uint32 _effectiveHeal;
57+
uint32 _healAbsorb;
58+
Map* _map;
59+
60+
struct NoopAuraDeleter { void operator()(ElunaProcInfo*) const { } };
61+
#ifdef ELUNA_TRINITY
62+
Trinity::unique_trackable_ptr<ElunaProcInfo> m_scriptRef;
63+
#endif
64+
65+
public:
66+
ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask,
67+
uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask,
68+
Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map);
69+
70+
explicit ElunaProcInfo(ProcEventInfo& procInfo, Map* map);
71+
~ElunaProcInfo()
72+
{
73+
#ifdef TRACKABLE_PTR_NAMESPACE
74+
m_scriptRef = nullptr;
75+
#endif
76+
}
77+
Unit* GetActor() const { return _actor; }
78+
Unit* GetActionTarget() const { return _actionTarget; }
79+
uint32 GetTypeMask() const { return _typeMask; }
80+
uint32 GetSpellTypeMask() const { return _spellTypeMask; }
81+
uint32 GetSpellPhaseMask() const { return _spellPhaseMask; }
82+
uint32 GetHitMask() const { return _hitMask; }
83+
Spell const* GetProcSpell() const { return _spell; }
84+
85+
SpellInfo const* GetSpellInfo() const;
86+
SpellSchoolMask GetSchoolMask() const { return _schoolMask; }
87+
88+
uint32 GetDamage() const { return _damage; }
89+
DamageEffectType GetDamageType() const { return _damageType; }
90+
WeaponAttackType GetAttackType() const { return _attackType; }
91+
uint32 GetDamageAbsorb() const { return _damageAbsorb; }
92+
uint32 GetResist() const { return _resist; }
93+
uint32 GetBlock() const { return _block; }
94+
95+
uint32 GetHeal() const { return _heal; }
96+
uint32 GetEffectiveHeal() const { return _effectiveHeal; }
97+
uint32 GetHealAbsorb() const { return _healAbsorb; }
98+
99+
bool HasDamage() const { return _damage > 0; }
100+
bool HasHeal() const { return _heal > 0; }
101+
102+
void SetDamage(int32 amount) { _damage = amount; }
103+
void SetAbsorbDamage(uint32 amount) { _damageAbsorb = amount; }
104+
void SetResistDamage(uint32 amount) { _resist = amount; }
105+
void SetBlockDamage(uint32 amount) { _block = amount; }
106+
107+
void SetAbsorbHeal(uint32 amount) { _healAbsorb = amount; }
108+
void SetEffectiveHeal(uint32 amount) { _effectiveHeal = amount; }
109+
void SetHeal(int32 amount) { _heal = amount; }
110+
111+
void SetDamage(uint32 damage, DamageEffectType damageType, WeaponAttackType attackType);
112+
void SetHeal(uint32 heal);
113+
114+
const Map* GetMap() const { return _map; }
115+
#ifdef ELUNA_TRINITY
116+
Trinity::unique_weak_ptr<ElunaProcInfo> GetWeakPtr() const { return m_scriptRef; }
117+
#endif
118+
void ApplyToProcEventInfo(ProcEventInfo& procInfo) const;
119+
};
120+
121+
class ElunaSpellInfo
122+
{
123+
private:
124+
SpellInfo const* _spellInfo;
125+
struct NoopAuraDeleter { void operator()(ElunaSpellInfo*) const {} };
126+
#ifdef ELUNA_TRINITY
127+
Trinity::unique_trackable_ptr<ElunaSpellInfo> m_scriptRef;
128+
#endif
129+
public:
130+
ElunaSpellInfo(uint32 spellId);
131+
~ElunaSpellInfo()
132+
{
133+
#ifdef TRACKABLE_PTR_NAMESPACE
134+
m_scriptRef = nullptr;
135+
#endif
136+
}
137+
SpellInfo const* GetSpellInfo() const { return _spellInfo; }
138+
#ifdef ELUNA_TRINITY
139+
Trinity::unique_weak_ptr<ElunaSpellInfo> GetWeakPtr() const { return m_scriptRef; }
140+
#endif
141+
};
142+
143+
#endif

ElunaTemplate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ ElunaConstrainedObjectRef<Aura> GetWeakPtrFor(Aura const* obj)
2020
#endif
2121
return { obj->GetWeakPtr(), map };
2222
}
23+
24+
ElunaConstrainedObjectRef<AuraEffect> GetWeakPtrFor(AuraEffect const* obj)
25+
{
26+
Map* map = obj->GetBase()->GetOwner()->GetMap();
27+
return { obj->GetWeakPtr(), map };
28+
}
29+
30+
ElunaConstrainedObjectRef<ElunaProcInfo> GetWeakPtrFor(ElunaProcInfo const* obj)
31+
{
32+
return { obj->GetWeakPtr(), obj->GetMap()};
33+
}
2334
ElunaConstrainedObjectRef<BattleGround> GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; }
2435
ElunaConstrainedObjectRef<Group> GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; }
2536
ElunaConstrainedObjectRef<Guild> GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; }
@@ -38,6 +49,7 @@ ElunaConstrainedObjectRef<Object> GetWeakPtrForObjectImpl(Object const* obj)
3849
}
3950
ElunaConstrainedObjectRef<Quest> GetWeakPtrFor(Quest const* obj) { return { obj->GetWeakPtr(), nullptr }; }
4051
ElunaConstrainedObjectRef<Spell> GetWeakPtrFor(Spell const* obj) { return { obj->GetWeakPtr(), obj->GetCaster()->GetMap() }; }
52+
ElunaConstrainedObjectRef<ElunaSpellInfo> GetWeakPtrFor(ElunaSpellInfo const* obj) { return { obj->GetWeakPtr(), nullptr }; }
4153
#if ELUNA_EXPANSION >= EXP_WOTLK
4254
ElunaConstrainedObjectRef<Vehicle> GetWeakPtrFor(Vehicle const* obj)
4355
{

ElunaTemplate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C"
1717
#include "ElunaUtility.h"
1818
#include "ElunaCompat.h"
1919
#include "ElunaConfig.h"
20+
#include "ElunaSpellWrapper.h"
2021
#if !defined ELUNA_CMANGOS
2122
#include "SharedDefines.h"
2223
#else
@@ -62,13 +63,16 @@ struct ElunaConstrainedObjectRef
6263
};
6364

6465
ElunaConstrainedObjectRef<Aura> GetWeakPtrFor(Aura const* obj);
66+
ElunaConstrainedObjectRef<AuraEffect> GetWeakPtrFor(AuraEffect const* obj);
67+
ElunaConstrainedObjectRef<ElunaProcInfo> GetWeakPtrFor(ElunaProcInfo const* obj);
6568
ElunaConstrainedObjectRef<BattleGround> GetWeakPtrFor(BattleGround const* obj);
6669
ElunaConstrainedObjectRef<Group> GetWeakPtrFor(Group const* obj);
6770
ElunaConstrainedObjectRef<Guild> GetWeakPtrFor(Guild const* obj);
6871
ElunaConstrainedObjectRef<Map> GetWeakPtrFor(Map const* obj);
6972
ElunaConstrainedObjectRef<Object> GetWeakPtrForObjectImpl(Object const* obj);
7073
ElunaConstrainedObjectRef<Quest> GetWeakPtrFor(Quest const* obj);
7174
ElunaConstrainedObjectRef<Spell> GetWeakPtrFor(Spell const* obj);
75+
ElunaConstrainedObjectRef<ElunaSpellInfo> GetWeakPtrFor(ElunaSpellInfo const* obj);
7276
#if ELUNA_EXPANSION >= EXP_WOTLK
7377
ElunaConstrainedObjectRef<Vehicle> GetWeakPtrFor(Vehicle const* obj);
7478
#endif

0 commit comments

Comments
 (0)