TrinityCore
Loading...
Searching...
No Matches
CreatureAI.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_CREATUREAI_H
19#define TRINITY_CREATUREAI_H
20
21#include "Common.h"
22#include "ObjectDefines.h"
23#include "Optional.h"
24#include "QuestDef.h"
25#include "UnitAI.h"
26
27class AreaBoundary;
28class AuraApplication;
29class Creature;
30class DynamicObject;
31class GameObject;
32class PlayerAI;
33class WorldObject;
34struct Position;
35
36typedef std::vector<AreaBoundary const*> CreatureBoundary;
37
38#define TIME_INTERVAL_LOOK 5000
39#define VISIBILITY_RANGE 10000
40
50
51// Spell targets used by SelectSpell
53{
54 SELECT_TARGET_DONTCARE = 0, // All target types allowed
55 SELECT_TARGET_SELF, // Only Self casting
56 SELECT_TARGET_SINGLE_ENEMY, // Only Single Enemy
57 SELECT_TARGET_AOE_ENEMY, // Only AoE Enemy
58 SELECT_TARGET_ANY_ENEMY, // AoE or Single Enemy
59 SELECT_TARGET_SINGLE_FRIEND, // Only Single Friend
60 SELECT_TARGET_AOE_FRIEND, // Only AoE Friend
61 SELECT_TARGET_ANY_FRIEND // AoE or Single Friend
62};
63
64// Spell Effects used by SelectSpell
66{
67 SELECT_EFFECT_DONTCARE = 0, // All spell effects allowed
68 SELECT_EFFECT_DAMAGE, // Spell does damage
69 SELECT_EFFECT_HEALING, // Spell does healing
70 SELECT_EFFECT_AURA // Spell applies an aura
71};
72
78
80{
81 protected:
82 Creature* const me;
83
84 bool UpdateVictim();
85
86 Creature* DoSummon(uint32 entry, Position const& pos, Milliseconds despawnTime = 30s, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
87 Creature* DoSummon(uint32 entry, WorldObject* obj, float radius = 5.0f, Milliseconds despawnTime = 30s, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
88 Creature* DoSummonFlyer(uint32 entry, WorldObject* obj, float flightZ, float radius = 5.0f, Milliseconds despawnTime = 30s, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
89
90 public:
91 // EnumUtils: DESCRIBE THIS (in CreatureAI::)
93 {
94 EVADE_REASON_NO_HOSTILES, // the creature's threat list is empty
95 EVADE_REASON_BOUNDARY, // the creature has moved outside its evade boundary
96 EVADE_REASON_NO_PATH, // the creature was unable to reach its target for over 5 seconds
97 EVADE_REASON_SEQUENCE_BREAK, // this is a boss and the pre-requisite encounters for engaging it are not defeated yet
98 EVADE_REASON_OTHER, // anything else
99 };
100
101 explicit CreatureAI(Creature* creature);
102
103 virtual ~CreatureAI();
104
105 bool IsEngaged() const { return _isEngaged; }
106
107 void Talk(uint8 id, WorldObject const* whisperTarget = nullptr);
108
110
111 // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter
112 void MoveInLineOfSight_Safe(Unit* who);
113
114 // Trigger Creature "Alert" state (creature can see stealthed unit)
115 void TriggerAlert(Unit const* who) const;
116
117 // Called for reaction at stopping attack at no attackers or targets
118 virtual void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
119
120 // Called for reaction whenever we start being in combat (overridden from base UnitAI)
121 void JustEnteredCombat(Unit* /*who*/) override;
122
123 // Called for reaction whenever a new non-offline unit is added to the threat list
124 virtual void JustStartedThreateningMe(Unit* who) { if (!IsEngaged()) EngagementStart(who); }
125
126 // Called for reaction when initially engaged - this will always happen _after_ JustEnteredCombat
127 virtual void JustEngagedWith(Unit* /*who*/) { }
128
129 // Called when the creature is killed
130 virtual void JustDied(Unit* /*killer*/) { }
131
132 // Called when the creature kills a unit
133 virtual void KilledUnit(Unit* /*victim*/) { }
134
135 // Called when the creature summon successfully other creature
136 virtual void JustSummoned(Creature* /*summon*/) { }
137 virtual void IsSummonedBy(WorldObject* /*summoner*/) { }
138
139 virtual void SummonedCreatureDespawn(Creature* /*summon*/) { }
140 virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { }
141
142 // Called when hit by a spell
143 virtual void SpellHit(WorldObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
144
145 // Called when spell hits a target
146 virtual void SpellHitTarget(WorldObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
147
148 // Called when a spell finishes
149 virtual void OnSpellCast(SpellInfo const* /*spell*/) { }
150
151 // Called when a spell fails
152 virtual void OnSpellFailed(SpellInfo const* /*spell*/) { }
153
154 // Called when a spell starts
155 virtual void OnSpellStart(SpellInfo const* /*spell*/) { }
156
157 // Called when a channeled spell finishes
158 virtual void OnChannelFinished(SpellInfo const* /*spell*/) { }
159
160 // Called when aura is applied
161 virtual void OnAuraApplied(AuraApplication const* /*aurApp*/) { }
162
163 // Called when aura is removed
164 virtual void OnAuraRemoved(AuraApplication const* /*aurApp*/) { }
165
166 // Should return true if the NPC is currently being escorted
167 virtual bool IsEscorted() const { return false; }
168
169 // Called when creature appears in the world (spawn, respawn, grid load etc...)
170 virtual void JustAppeared();
171
172 // Called at waypoint reached or point movement finished
173 virtual void MovementInform(uint32 /*type*/, uint32 /*id*/) { }
174
175 void OnCharmed(bool isNew) override;
176
177 // Called at reaching home after evade
178 virtual void JustReachedHome() { }
179
180 void DoZoneInCombat(Creature* creature = nullptr);
181
182 // Called at text emote receive from player
183 virtual void ReceiveEmote(Player* /*player*/, uint32 /*emoteId*/) { }
184
185 // Called when owner takes damage
186 virtual void OwnerAttackedBy(Unit* attacker) { OnOwnerCombatInteraction(attacker); }
187
188 // Called when owner attacks something
189 virtual void OwnerAttacked(Unit* target) { OnOwnerCombatInteraction(target); }
190
192
193 // Called when creature attack expected (if creature can and no have current victim)
194 //virtual void AttackStart(Unit*) { }
195
196 // Called at World update tick
197 //virtual void UpdateAI(const uint32 /*diff*/) { }
198
200
201 // Is unit visible for MoveInLineOfSight
202 //virtual bool IsVisible(Unit*) const { return false; }
203
204 // called when the corpse of this creature gets removed
205 virtual void CorpseRemoved(uint32& /*respawnDelay*/) { }
206
207 // Called when victim entered water and creature can not enter water
208 //virtual bool CanReachByRangeAttack(Unit*) { return false; }
209
211
212 // Called when the dialog status between a player and the creature is requested.
213 virtual Optional<QuestGiverStatus> GetDialogStatus(Player* /*player*/) { return {}; }
214
215 // Called when a player opens a gossip dialog with the creature.
216 virtual bool OnGossipHello(Player* /*player*/) { return false; }
217
218 // Called when a player selects a gossip item in the creature's gossip menu.
219 virtual bool OnGossipSelect(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/) { return false; }
220
221 // Called when a player selects a gossip with a code in the creature's gossip menu.
222 virtual bool OnGossipSelectCode(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/, char const* /*code*/) { return false; }
223
224 // Called when a player accepts a quest from the creature.
225 virtual void OnQuestAccept(Player* /*player*/, Quest const* /*quest*/) { }
226
227 // Called when a player completes a quest and is rewarded, opt is the selected item's index or 0
228 virtual void OnQuestReward(Player* /*player*/, Quest const* /*quest*/, uint32 /*opt*/) { }
229
231
232 virtual void WaypointStarted(uint32 /*nodeId*/, uint32 /*pathId*/) { }
233 virtual void WaypointReached(uint32 /*nodeId*/, uint32 /*pathId*/) { }
234 virtual void WaypointPathEnded(uint32 /*nodeId*/, uint32 /*pathId*/) { }
235
237
238 virtual void PassengerBoarded(Unit* /*passenger*/, int8 /*seatId*/, bool /*apply*/) { }
239
240 virtual void OnSpellClick(Unit* /*clicker*/, bool /*spellClickHandled*/) { }
241
242 virtual bool CanSeeAlways(WorldObject const* /*obj*/) { return false; }
243
244 // Called when a player is charmed by the creature
245 // If a PlayerAI* is returned, that AI is placed on the player instead of the default charm AI
246 // Object destruction is handled by Unit::RemoveCharmedBy
247 virtual PlayerAI* GetAIForCharmedPlayer(Player* /*who*/) { return nullptr; }
248
249 // intended for encounter design/debugging. do not use for other purposes. expensive.
250 int32 VisualizeBoundary(Seconds duration, Unit* owner = nullptr, bool fill = false) const;
251
252 // boundary system methods
253 virtual bool CheckInRoom();
254 CreatureBoundary const* GetBoundary() const { return _boundary; }
255 void SetBoundary(CreatureBoundary const* boundary, bool negativeBoundaries = false);
256
257 static bool IsInBounds(CreatureBoundary const& boundary, Position const* who);
258 bool IsInBoundary(Position const* who = nullptr) const;
259
260 protected:
261 void EngagementStart(Unit* who);
262 void EngagementOver();
263 virtual void MoveInLineOfSight(Unit* /*who*/);
264
265 bool _EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
266
269
270 private:
271 void OnOwnerCombatInteraction(Unit* target);
272
275};
276
277#endif
SelectTargetType
Definition CreatureAI.h:53
@ SELECT_TARGET_ANY_FRIEND
Definition CreatureAI.h:61
@ SELECT_TARGET_AOE_FRIEND
Definition CreatureAI.h:60
@ SELECT_TARGET_ANY_ENEMY
Definition CreatureAI.h:58
@ SELECT_TARGET_SINGLE_FRIEND
Definition CreatureAI.h:59
@ SELECT_TARGET_SINGLE_ENEMY
Definition CreatureAI.h:56
@ SELECT_TARGET_DONTCARE
Definition CreatureAI.h:54
@ SELECT_TARGET_SELF
Definition CreatureAI.h:55
@ SELECT_TARGET_AOE_ENEMY
Definition CreatureAI.h:57
std::vector< AreaBoundary const * > CreatureBoundary
Definition CreatureAI.h:36
SCEquip
Definition CreatureAI.h:74
@ EQUIP_UNEQUIP
Definition CreatureAI.h:76
@ EQUIP_NO_CHANGE
Definition CreatureAI.h:75
SelectEffect
Definition CreatureAI.h:66
@ SELECT_EFFECT_DONTCARE
Definition CreatureAI.h:67
@ SELECT_EFFECT_AURA
Definition CreatureAI.h:70
@ SELECT_EFFECT_HEALING
Definition CreatureAI.h:69
@ SELECT_EFFECT_DAMAGE
Definition CreatureAI.h:68
Permitions
Definition CreatureAI.h:42
@ PERMIT_BASE_SPECIAL
Definition CreatureAI.h:48
@ PERMIT_BASE_PROACTIVE
Definition CreatureAI.h:46
@ PERMIT_BASE_NO
Definition CreatureAI.h:43
@ PERMIT_BASE_REACTIVE
Definition CreatureAI.h:45
@ PERMIT_BASE_FACTION_SPECIFIC
Definition CreatureAI.h:47
@ PERMIT_BASE_IDLE
Definition CreatureAI.h:44
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int8_t int8
Definition Define.h:131
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:27
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
TempSummonType
@ TEMPSUMMON_CORPSE_TIMED_DESPAWN
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
virtual bool OnGossipHello(Player *)
Definition CreatureAI.h:216
virtual void OnQuestReward(Player *, Quest const *, uint32)
Definition CreatureAI.h:228
virtual bool CanSeeAlways(WorldObject const *)
Definition CreatureAI.h:242
virtual void WaypointPathEnded(uint32, uint32)
Definition CreatureAI.h:234
virtual void WaypointReached(uint32, uint32)
Definition CreatureAI.h:233
virtual void JustEngagedWith(Unit *)
Definition CreatureAI.h:127
virtual void OnChannelFinished(SpellInfo const *)
Definition CreatureAI.h:158
bool IsEngaged() const
Definition CreatureAI.h:105
virtual void JustSummoned(Creature *)
Definition CreatureAI.h:136
CreatureBoundary const * _boundary
Definition CreatureAI.h:267
virtual PlayerAI * GetAIForCharmedPlayer(Player *)
Definition CreatureAI.h:247
virtual void OnAuraApplied(AuraApplication const *)
Definition CreatureAI.h:161
virtual void OnAuraRemoved(AuraApplication const *)
Definition CreatureAI.h:164
virtual void OwnerAttacked(Unit *target)
Definition CreatureAI.h:189
@ EVADE_REASON_OTHER
Definition CreatureAI.h:98
@ EVADE_REASON_BOUNDARY
Definition CreatureAI.h:95
@ EVADE_REASON_NO_HOSTILES
Definition CreatureAI.h:94
@ EVADE_REASON_SEQUENCE_BREAK
Definition CreatureAI.h:97
@ EVADE_REASON_NO_PATH
Definition CreatureAI.h:96
CreatureBoundary const * GetBoundary() const
Definition CreatureAI.h:254
virtual void OnSpellClick(Unit *, bool)
Definition CreatureAI.h:240
virtual void OnSpellStart(SpellInfo const *)
Definition CreatureAI.h:155
virtual bool OnGossipSelectCode(Player *, uint32, uint32, char const *)
Definition CreatureAI.h:222
virtual void JustStartedThreateningMe(Unit *who)
Definition CreatureAI.h:124
virtual void SpellHitTarget(WorldObject *, SpellInfo const *)
Definition CreatureAI.h:146
bool _isEngaged
Definition CreatureAI.h:273
bool _negateBoundary
Definition CreatureAI.h:268
virtual void JustReachedHome()
Definition CreatureAI.h:178
virtual bool IsEscorted() const
Definition CreatureAI.h:167
virtual void JustDied(Unit *)
Definition CreatureAI.h:130
virtual void SpellHit(WorldObject *, SpellInfo const *)
Definition CreatureAI.h:143
virtual void OnSpellFailed(SpellInfo const *)
Definition CreatureAI.h:152
virtual void OnSpellCast(SpellInfo const *)
Definition CreatureAI.h:149
virtual void SummonedCreatureDies(Creature *, Unit *)
Definition CreatureAI.h:140
virtual void MovementInform(uint32, uint32)
Definition CreatureAI.h:173
virtual void OwnerAttackedBy(Unit *attacker)
Definition CreatureAI.h:186
virtual void KilledUnit(Unit *)
Definition CreatureAI.h:133
virtual bool OnGossipSelect(Player *, uint32, uint32)
Definition CreatureAI.h:219
virtual void WaypointStarted(uint32, uint32)
== Waypoints system =============================
Definition CreatureAI.h:232
virtual void ReceiveEmote(Player *, uint32)
Definition CreatureAI.h:183
virtual Optional< QuestGiverStatus > GetDialogStatus(Player *)
== Gossip system ================================
Definition CreatureAI.h:213
virtual void PassengerBoarded(Unit *, int8, bool)
== Fields =======================================
Definition CreatureAI.h:238
virtual void SummonedCreatureDespawn(Creature *)
Definition CreatureAI.h:139
virtual void CorpseRemoved(uint32 &)
== Triggered Actions Requested ==================
Definition CreatureAI.h:205
virtual void OnQuestAccept(Player *, Quest const *)
Definition CreatureAI.h:225
virtual void IsSummonedBy(WorldObject *)
Definition CreatureAI.h:137
Creature *const me
Definition CreatureAI.h:82
bool _moveInLOSLocked
Definition CreatureAI.h:274
virtual void JustEnteredCombat(Unit *)
Definition UnitAI.h:212
virtual void OnCharmed(bool isNew)
Definition UnitAI.cpp:42
Definition Unit.h:769