forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpellMethods.h
193 lines (180 loc) · 4.9 KB
/
SpellMethods.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef SPELLMETHODS_H
#define SPELLMETHODS_H
/***
* An instance of a spell, created when the spell is cast by a [Unit].
*
* Inherits all methods from: none
*/
namespace LuaSpell
{
/**
* Returns `true` if the [Spell] is automatically repeating, `false` otherwise.
*
* @return bool isAutoRepeating
*/
int IsAutoRepeat(lua_State* L, Spell* spell)
{
Eluna::Push(L, spell->IsAutoRepeat());
return 1;
}
/**
* Returns the [Unit] that casted the [Spell].
*
* @return [Unit] caster
*/
int GetCaster(lua_State* L, Spell* spell)
{
Eluna::Push(L, spell->GetCaster());
return 1;
}
/**
* Returns the cast time of the [Spell].
*
* @return int32 castTime
*/
int GetCastTime(lua_State* L, Spell* spell)
{
Eluna::Push(L, spell->GetCastTime());
return 1;
}
/**
* Returns the entry ID of the [Spell].
*
* @return uint32 entryId
*/
int GetEntry(lua_State* L, Spell* spell)
{
Eluna::Push(L, spell->m_spellInfo->Id);
return 1;
}
/**
* Returns the power cost of the [Spell].
*
* @return uint32 powerCost
*/
int GetPowerCost(lua_State* L, Spell* spell)
{
Eluna::Push(L, spell->GetPowerCost());
return 1;
}
/**
* Returns the spell duration of the [Spell].
*
* @return int32 duration
*/
int GetDuration(lua_State* L, Spell* spell)
{
#if defined TRINITY || AZEROTHCORE
Eluna::Push(L, spell->GetSpellInfo()->GetDuration());
#else
Eluna::Push(L, GetSpellDuration(spell->m_spellInfo));
#endif
return 1;
}
/**
* Returns the target destination coordinates of the [Spell].
*
* @return float x : x coordinate of the [Spell]
* @return float y : y coordinate of the [Spell]
* @return float z : z coordinate of the [Spell]
*/
int GetTargetDest(lua_State* L, Spell* spell)
{
#if defined TRINITY || AZEROTHCORE
if (!spell->m_targets.HasDst())
return 3;
float x, y, z;
spell->m_targets.GetDstPos()->GetPosition(x, y, z);
#else
if (!(spell->m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
return 3;
float x, y, z;
spell->m_targets.getDestination(x, y, z);
#endif
Eluna::Push(L, x);
Eluna::Push(L, y);
Eluna::Push(L, z);
return 3;
}
/**
* Returns the target [Object] of the [Spell].
*
* The target can be any of the following [Object] types:
* - [Player]
* - [Creature]
* - [GameObject]
* - [Item]
* - [Corpse]
*
* @return [Object] target
*/
int GetTarget(lua_State* L, Spell* spell)
{
#if defined TRINITY || AZEROTHCORE
if (GameObject* target = spell->m_targets.GetGOTarget())
Eluna::Push(L, target);
else if (Item* target = spell->m_targets.GetItemTarget())
Eluna::Push(L, target);
else if (Corpse* target = spell->m_targets.GetCorpseTarget())
Eluna::Push(L, target);
else if (Unit* target = spell->m_targets.GetUnitTarget())
Eluna::Push(L, target);
else if (WorldObject* target = spell->m_targets.GetObjectTarget())
Eluna::Push(L, target);
#else
if (GameObject* target = spell->m_targets.getGOTarget())
Eluna::Push(L, target);
else if (Item* target = spell->m_targets.getItemTarget())
Eluna::Push(L, target);
else if (Corpse* target = spell->GetCaster()->GetMap()->GetCorpse(spell->m_targets.getCorpseTargetGuid()))
Eluna::Push(L, target);
else if (Unit* target = spell->m_targets.getUnitTarget())
Eluna::Push(L, target);
#endif
return 1;
}
/**
* Sets the [Spell] to automatically repeat.
*
* @param bool repeat : set variable to 'true' for spell to automatically repeat
*/
int SetAutoRepeat(lua_State* L, Spell* spell)
{
bool repeat = Eluna::CHECKVAL<bool>(L, 2);
spell->SetAutoRepeat(repeat);
return 0;
}
/**
* Casts the [Spell].
*
* @param bool skipCheck = false : skips initial checks to see if the [Spell] can be casted or not, this is optional
*/
int Cast(lua_State* L, Spell* spell)
{
bool skipCheck = Eluna::CHECKVAL<bool>(L, 2, false);
spell->cast(skipCheck);
return 0;
}
/**
* Cancels the [Spell].
*/
int Cancel(lua_State* /*L*/, Spell* spell)
{
spell->cancel();
return 0;
}
/**
* Finishes the [Spell].
*/
int Finish(lua_State* /*L*/, Spell* spell)
{
spell->finish();
return 0;
}
};
#endif