forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ElunaCreatureAI.h
386 lines (354 loc) · 10.7 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
* 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"
#ifdef CMANGOS
#include "AI/BaseAI/CreatureAI.h"
#endif
#if defined TRINITY || AZEROTHCORE
struct ScriptedAI;
#elif defined CMANGOS
class CreatureAI;
#else
class AggressorAI;
typedef AggressorAI ScriptedAI;
#endif
#ifndef CMANGOS
struct ElunaCreatureAI : ScriptedAI
#else
struct ElunaCreatureAI : CreatureAI
#endif
{
// 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
#ifndef CMANGOS
ElunaCreatureAI(Creature* creature) : ScriptedAI(creature), justSpawned(true)
#else
ElunaCreatureAI(Creature* creature) : CreatureAI(creature), justSpawned(true)
#endif
{
}
~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)
{
#ifndef CMANGOS
if (!sEluna->MovementInform(me, point.first, point.second))
ScriptedAI::MovementInform(point.first, point.second);
#else
if (!sEluna->MovementInform(me, point.first, point.second))
CreatureAI::MovementInform(point.first, point.second);
#endif
}
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);
#elif defined CMANGOS
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC))
CreatureAI::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
{
#ifndef CMANGOS
if (!sEluna->EnterCombat(me, target))
ScriptedAI::EnterCombat(target);
#else
if (!sEluna->EnterCombat(me, target))
CreatureAI::EnterCombat(target);
#endif
}
#endif
// Called at any Damage from any attacker (before damage apply)
#if defined AZEROTHCORE
void DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask) override
#elif defined(TRINITY) || CMANGOS
void DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damageType, SpellInfo const* spellInfo) override
#else
void DamageTaken(Unit* attacker, uint32& damage) override
#endif
{
if (!sEluna->DamageTaken(me, attacker, damage))
{
#if defined AZEROTHCORE
ScriptedAI::DamageTaken(attacker, damage, damagetype, damageSchoolMask);
#elif defined TRINITY
ScriptedAI::DamageTaken(attacker, damage, damageType, spellInfo);
#elif defined CMANGOS
CreatureAI::DamageTaken(attacker, damage, damageType, spellInfo);
#else
ScriptedAI::DamageTaken(attacker, damage);
#endif
}
}
//Called at creature death
void JustDied(Unit* killer) override
{
#ifndef CMANGOS
if (!sEluna->JustDied(me, killer))
ScriptedAI::JustDied(killer);
#else
if (!sEluna->JustDied(me, killer))
CreatureAI::JustDied(killer);
#endif
}
//Called at creature killing another unit
void KilledUnit(Unit* victim) override
{
#ifndef CMANGOS
if (!sEluna->KilledUnit(me, victim))
ScriptedAI::KilledUnit(victim);
#else
if (!sEluna->KilledUnit(me, victim))
CreatureAI::KilledUnit(victim);
#endif
}
// Called when the creature summon successfully other creature
void JustSummoned(Creature* summon) override
{
#ifndef CMANGOS
if (!sEluna->JustSummoned(me, summon))
ScriptedAI::JustSummoned(summon);
#else
if (!sEluna->JustSummoned(me, summon))
CreatureAI::JustSummoned(summon);
#endif
}
// Called when a summoned creature is despawned
void SummonedCreatureDespawn(Creature* summon) override
{
#ifndef CMANGOS
if (!sEluna->SummonedCreatureDespawn(me, summon))
ScriptedAI::SummonedCreatureDespawn(summon);
#else
if (!sEluna->SummonedCreatureDespawn(me, summon))
CreatureAI::SummonedCreatureDespawn(summon);
#endif
}
//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
{
#ifndef CMANGOS
if (!sEluna->AttackStart(me, target))
ScriptedAI::AttackStart(target);
#else
if (!sEluna->AttackStart(me, target))
CreatureAI::AttackStart(target);
#endif
}
#ifdef TRINITY
// Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode(EvadeReason /*why*/) override
{
#ifndef CMANGOS
if (!sEluna->EnterEvadeMode(me))
ScriptedAI::EnterEvadeMode();
#else
if (!sEluna->EnterEvadeMode(me))
CreatureAI::EnterEvadeMode();
#endif
}
#else
// Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode() override
{
#ifndef CMANGOS
if (!sEluna->EnterEvadeMode(me))
ScriptedAI::EnterEvadeMode();
#else
if (!sEluna->EnterEvadeMode(me))
CreatureAI::EnterEvadeMode();
#endif
}
#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
{
#ifndef CMANGOS
if (!sEluna->JustRespawned(me))
ScriptedAI::JustRespawned();
#else
if (!sEluna->JustRespawned(me))
CreatureAI::JustRespawned();
#endif
}
#endif
// Called at reaching home after evade
void JustReachedHome() override
{
#ifndef CMANGOS
if (!sEluna->JustReachedHome(me))
ScriptedAI::JustReachedHome();
#else
if (!sEluna->JustReachedHome(me))
CreatureAI::JustReachedHome();
#endif
}
// Called at text emote receive from player
void ReceiveEmote(Player* player, uint32 emoteId) override
{
#ifndef CMANGOS
if (!sEluna->ReceiveEmote(me, player, emoteId))
ScriptedAI::ReceiveEmote(player, emoteId);
#else
if (!sEluna->ReceiveEmote(me, player, emoteId))
CreatureAI::ReceiveEmote(player, emoteId);
#endif
}
// called when the corpse of this creature gets removed
void CorpseRemoved(uint32& respawnDelay) override
{
#ifndef CMANGOS
if (!sEluna->CorpseRemoved(me, respawnDelay))
ScriptedAI::CorpseRemoved(respawnDelay);
#else
if (!sEluna->CorpseRemoved(me, respawnDelay))
CreatureAI::CorpseRemoved(respawnDelay);
#endif
}
#if !defined TRINITY && !AZEROTHCORE
// Enables use of MoveInLineOfSight
bool IsVisible(Unit* who) const override
{
return true;
}
#endif
void MoveInLineOfSight(Unit* who) override
{
#ifndef CMANGOS
if (!sEluna->MoveInLineOfSight(me, who))
ScriptedAI::MoveInLineOfSight(who);
#else
if (!sEluna->MoveInLineOfSight(me, who))
CreatureAI::MoveInLineOfSight(who);
#endif
}
// 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
{
#ifndef CMANGOS
if (!sEluna->SpellHit(me, caster, spell))
ScriptedAI::SpellHit(caster, spell);
#else
if (!sEluna->SpellHit(me, caster, spell))
CreatureAI::SpellHit(caster, spell);
#endif
}
// 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
{
#ifndef CMANGOS
if (!sEluna->SpellHitTarget(me, target, spell))
ScriptedAI::SpellHitTarget(target, spell);
#else
if (!sEluna->SpellHitTarget(me, target, spell))
CreatureAI::SpellHitTarget(target, spell);
#endif
}
#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