-
Notifications
You must be signed in to change notification settings - Fork 366
/
ElunaCreatureAI.h
285 lines (252 loc) · 7.97 KB
/
ElunaCreatureAI.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
* 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 _ELUNA_CREATURE_AI_H
#define _ELUNA_CREATURE_AI_H
#include "LuaEngine.h"
#if defined TRINITY || AZEROTHCORE
struct ScriptedAI;
#else
class AggressorAI;
typedef AggressorAI ScriptedAI;
#endif
struct ElunaCreatureAI : ScriptedAI
{
// used to delay the spawn hook triggering on AI creation
bool justSpawned;
// used to delay movementinform hook (WP hook)
std::vector< std::pair<uint32, uint32> > movepoints;
#if defined MANGOS || defined CMANGOS
#define me m_creature
#endif
ElunaCreatureAI(Creature* creature) : ScriptedAI(creature), justSpawned(true)
{
}
~ElunaCreatureAI() { }
//Called at World update tick
#ifndef TRINITY
void UpdateAI(const uint32 diff) override
#else
void UpdateAI(uint32 diff) override
#endif
{
#ifdef TRINITY
//Spawns are handled by Creature.cpp - in function Creature::Update()
#else
if (justSpawned)
{
justSpawned = false;
JustRespawned();
}
#endif
if (!movepoints.empty())
{
for (auto& point : movepoints)
{
if (!sEluna->MovementInform(me, point.first, point.second))
ScriptedAI::MovementInform(point.first, point.second);
}
movepoints.clear();
}
if (!sEluna->UpdateAI(me, diff))
{
#if defined TRINITY || AZEROTHCORE
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
ScriptedAI::UpdateAI(diff);
#else
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
ScriptedAI::UpdateAI(diff);
#endif
}
}
#ifdef TRINITY
// Called for reaction when initially engaged - this will always happen _after_ JustEnteredCombat
// Called at creature aggro either by MoveInLOS or Attack Start
void JustEngagedWith(Unit* target) override
{
if (!sEluna->EnterCombat(me, target))
ScriptedAI::JustEngagedWith(target);
}
#else
//Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
//Called at creature aggro either by MoveInLOS or Attack Start
void EnterCombat(Unit* target) override
{
if (!sEluna->EnterCombat(me, target))
ScriptedAI::EnterCombat(target);
}
#endif
// Called at any Damage from any attacker (before damage apply)
#if AZEROTHCORE
void DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask) override
#else
void DamageTaken(Unit* attacker, uint32& damage) override
#endif
{
if (!sEluna->DamageTaken(me, attacker, damage))
{
#if AZEROTHCORE
ScriptedAI::DamageTaken(attacker, damage, damagetype, damageSchoolMask);
#else
ScriptedAI::DamageTaken(attacker, damage);
#endif
}
}
//Called at creature death
void JustDied(Unit* killer) override
{
if (!sEluna->JustDied(me, killer))
ScriptedAI::JustDied(killer);
}
//Called at creature killing another unit
void KilledUnit(Unit* victim) override
{
if (!sEluna->KilledUnit(me, victim))
ScriptedAI::KilledUnit(victim);
}
// Called when the creature summon successfully other creature
void JustSummoned(Creature* summon) override
{
if (!sEluna->JustSummoned(me, summon))
ScriptedAI::JustSummoned(summon);
}
// Called when a summoned creature is despawned
void SummonedCreatureDespawn(Creature* summon) override
{
if (!sEluna->SummonedCreatureDespawn(me, summon))
ScriptedAI::SummonedCreatureDespawn(summon);
}
//Called at waypoint reached or PointMovement end
void MovementInform(uint32 type, uint32 id) override
{
// delayed since hook triggers before actually reaching the point
// and starting new movement would bug
movepoints.push_back(std::make_pair(type, id));
}
// Called before EnterCombat even before the creature is in combat.
void AttackStart(Unit* target) override
{
if (!sEluna->AttackStart(me, target))
ScriptedAI::AttackStart(target);
}
#ifdef TRINITY
// Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode(EvadeReason /*why*/) override
{
if (!sEluna->EnterEvadeMode(me))
ScriptedAI::EnterEvadeMode();
}
#else
// Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode() override
{
if (!sEluna->EnterEvadeMode(me))
ScriptedAI::EnterEvadeMode();
}
#endif
#ifdef TRINITY
// Called when creature appears in the world (spawn, respawn, grid load etc...)
void JustAppeared() override
{
if (!sEluna->JustRespawned(me))
ScriptedAI::JustAppeared();
}
#else
// Called when creature is spawned or respawned (for reseting variables)
void JustRespawned() override
{
if (!sEluna->JustRespawned(me))
ScriptedAI::JustRespawned();
}
#endif
// Called at reaching home after evade
void JustReachedHome() override
{
if (!sEluna->JustReachedHome(me))
ScriptedAI::JustReachedHome();
}
// Called at text emote receive from player
void ReceiveEmote(Player* player, uint32 emoteId) override
{
if (!sEluna->ReceiveEmote(me, player, emoteId))
ScriptedAI::ReceiveEmote(player, emoteId);
}
// called when the corpse of this creature gets removed
void CorpseRemoved(uint32& respawnDelay) override
{
if (!sEluna->CorpseRemoved(me, respawnDelay))
ScriptedAI::CorpseRemoved(respawnDelay);
}
#if !defined TRINITY && !AZEROTHCORE
// Enables use of MoveInLineOfSight
bool IsVisible(Unit* who) const override
{
return true;
}
#endif
void MoveInLineOfSight(Unit* who) override
{
if (!sEluna->MoveInLineOfSight(me, who))
ScriptedAI::MoveInLineOfSight(who);
}
// Called when hit by a spell
#if defined TRINITY
void SpellHit(WorldObject* caster, SpellInfo const* spell) override
#else
void SpellHit(Unit* caster, SpellInfo const* spell) override
#endif
{
if (!sEluna->SpellHit(me, caster, spell))
ScriptedAI::SpellHit(caster, spell);
}
// Called when spell hits a target
#if defined TRINITY
void SpellHitTarget(WorldObject* target, SpellInfo const* spell) override
#else
void SpellHitTarget(Unit* target, SpellInfo const* spell) override
#endif
{
if (!sEluna->SpellHitTarget(me, target, spell))
ScriptedAI::SpellHitTarget(target, spell);
}
#if defined TRINITY || AZEROTHCORE
#if defined TRINITY
// Called when the creature is summoned successfully by other creature
void IsSummonedBy(WorldObject* summoner) override
{
if (!summoner->ToUnit() || !sEluna->OnSummoned(me, summoner->ToUnit()))
ScriptedAI::IsSummonedBy(summoner);
}
#else
// Called when the creature is summoned successfully by other creature
void IsSummonedBy(Unit* summoner) override
{
if (!sEluna->OnSummoned(me, summoner))
ScriptedAI::IsSummonedBy(summoner);
}
#endif
void SummonedCreatureDies(Creature* summon, Unit* killer) override
{
if (!sEluna->SummonedCreatureDies(me, summon, killer))
ScriptedAI::SummonedCreatureDies(summon, killer);
}
// Called when owner takes damage
void OwnerAttackedBy(Unit* attacker) override
{
if (!sEluna->OwnerAttackedBy(me, attacker))
ScriptedAI::OwnerAttackedBy(attacker);
}
// Called when owner attacks something
void OwnerAttacked(Unit* target) override
{
if (!sEluna->OwnerAttacked(me, target))
ScriptedAI::OwnerAttacked(target);
}
#endif
#if defined MANGOS || defined CMANGOS
#undef me
#endif
};
#endif