forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathElunaCreatureAI.h
196 lines (166 loc) · 5.75 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
/*
* Copyright (C) 2010 - 2020 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"
struct ScriptedAI;
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;
ElunaCreatureAI(Creature* creature) : ScriptedAI(creature), justSpawned(true)
{
}
~ElunaCreatureAI() { }
//Called at World update tick
void UpdateAI(uint32 diff) override
{
if (justSpawned)
{
justSpawned = false;
// JustAppeared();
}
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 (!me->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_NPC))
ScriptedAI::UpdateAI(diff);
}
}
// 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);
// }
// Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* attacker, uint32& damage) override
{
if (!sEluna->DamageTaken(me, attacker, damage))
{
ScriptedAI::DamageTaken(attacker, damage);
}
}
//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);
}
// Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode(EvadeReason /*why*/) override
{
if (!sEluna->EnterEvadeMode(me))
ScriptedAI::EnterEvadeMode();
}
// Called when creature appears in the world (spawn, respawn, grid load etc...)
// void JustAppeared() override
// {
// if (!sEluna->JustRespawned(me))
// ScriptedAI::JustAppeared();
// }
// 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);
}
void MoveInLineOfSight(Unit* who) override
{
if (!sEluna->MoveInLineOfSight(me, who))
ScriptedAI::MoveInLineOfSight(who);
}
// Called when hit by a spell
void SpellHit(Unit* caster, SpellInfo const* spell) override
{
if (!sEluna->SpellHit(me, caster, spell))
ScriptedAI::SpellHit(caster, spell);
}
// Called when spell hits a target
void SpellHitTarget(Unit* target, SpellInfo const* spell) override
{
if (!sEluna->SpellHitTarget(me, target, spell))
ScriptedAI::SpellHitTarget(target, spell);
}
// 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);
// }
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