TrinityCore
Loading...
Searching...
No Matches
SmartAI.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_SMARTAI_H
19#define TRINITY_SMARTAI_H
20
21#include "Define.h"
22#include "CreatureAI.h"
23#include "GameObjectAI.h"
24#include "Position.h"
25#include "SmartScript.h"
26#include "WaypointDefines.h"
27
29{
30 SMART_ESCORT_NONE = 0x00, // nothing in progress
31 SMART_ESCORT_ESCORTING = 0x01, // escort is in progress
32 SMART_ESCORT_RETURNING = 0x02, // escort is returning after being in combat
33 SMART_ESCORT_PAUSED = 0x04 // will not proceed with waypoints before state is removed
34};
35
36static float constexpr SMART_ESCORT_MAX_PLAYER_DIST = 60.f;
37static float constexpr SMART_MAX_AID_DIST = SMART_ESCORT_MAX_PLAYER_DIST / 2.f;
38
40{
41 public:
43 explicit SmartAI(Creature* creature);
44
45 // core related
46 static int32 Permissible(Creature const* /*creature*/) { return PERMIT_BASE_NO; }
47
48 // Check whether we are currently permitted to make the creature take action
49 bool IsAIControlled() const;
50
51 // Start moving to the desired MovePoint
52 void StartPath(uint32 pathId = 0, bool repeat = false, Unit* invoker = nullptr, uint32 nodeId = 1);
53 WaypointPath const* LoadPath(uint32 entry);
54 void PausePath(uint32 delay, bool forced = false);
55 bool CanResumePath();
56 void StopPath(uint32 DespawnTime = 0, uint32 quest = 0, bool fail = false);
57 void EndPath(bool fail = false);
58 void ResumePath();
59 bool HasEscortState(uint32 escortState) const
60 {
61 return (_escortState & escortState) != 0;
62 }
63 void AddEscortState(uint32 escortState)
64 {
65 _escortState |= escortState;
66 }
67 void RemoveEscortState(uint32 escortState)
68 {
69 _escortState &= ~escortState;
70 }
71 void SetAutoAttack(bool on)
72 {
73 _canAutoAttack = on;
74 }
75 void SetCombatMove(bool on, bool stopMoving = false);
77 {
78 return _canCombatMove;
79 }
80 void SetFollow(Unit* target, float dist = 0.0f, float angle = 0.0f, uint32 credit = 0, uint32 end = 0, uint32 creditType = 0);
81 void StopFollow(bool complete);
82 bool IsEscortInvokerInRange();
83
84 void WaypointReached(uint32 nodeId, uint32 pathId) override;
85 void WaypointPathEnded(uint32 nodeId, uint32 pathId) override;
86
87 void SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker);
89 {
90 return &_script;
91 }
92
93 // Called at reaching home after evade, InitializeAI(), EnterEvadeMode() for resetting variables
94 void JustReachedHome() override;
95
96 // Called for reaction at enter to combat if not in combat yet (enemy can be nullptr)
97 void JustEngagedWith(Unit* enemy) override;
98
99 // Called for reaction at stopping attack at no attackers or targets
100 void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER) override;
101
102 // Called when the creature is killed
103 void JustDied(Unit* killer) override;
104
105 // Called when the creature kills a unit
106 void KilledUnit(Unit* victim) override;
107
108 // Called when the creature summon successfully other creature
109 void JustSummoned(Creature* creature) override;
110
111 // Called when a summoned unit dies
112 void SummonedCreatureDies(Creature* summon, Unit* killer) override;
113
114 // Tell creature to attack and follow the victim
115 void AttackStart(Unit* who) override;
116
117 // Called if IsVisible(Unit* who) is true at each *who move, reaction at visibility zone enter
118 void MoveInLineOfSight(Unit* who) override;
119
120 // Called when hit by a spell
121 void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override;
122
123 // Called when spell hits a target
124 void SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo) override;
125
126 // Called when a spell finishes
127 void OnSpellCast(SpellInfo const* spellInfo) override;
128
129 // Called when a spell fails
130 void OnSpellFailed(SpellInfo const* spellInfo) override;
131
132 // Called when a spell starts
133 void OnSpellStart(SpellInfo const* spellInfo) override;
134
135 // Called when aura is applied
136 void OnAuraApplied(AuraApplication const* aurApp) override;
137
138 // Called when aura is removed
139 void OnAuraRemoved(AuraApplication const* aurApp) override;
140
141 // Called at any Damage from any attacker (before damage apply)
142 void DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override;
143
144 // Called when the creature receives heal
145 void HealReceived(Unit* doneBy, uint32& addhealth) override;
146
147 // Called at World update tick
148 void UpdateAI(uint32 diff) override;
149
150 // Called at text emote receive from player
151 void ReceiveEmote(Player* player, uint32 textEmote) override;
152
153 // Called at waypoint reached or point movement finished
154 void MovementInform(uint32 MovementType, uint32 Data) override;
155
156 // Called when creature is summoned by another unit
157 void IsSummonedBy(WorldObject* summoner) override;
158
159 // Called at any Damage to any victim (before damage apply)
160 void DamageDealt(Unit* doneTo, uint32& damage, DamageEffectType /*damagetype*/) override;
161
162 // Called when a summoned creature dissapears (UnSommoned)
163 void SummonedCreatureDespawn(Creature* unit) override;
164
165 // called when the corpse of this creature gets removed
166 void CorpseRemoved(uint32& respawnDelay) override;
167
168 // Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing)
169 void OnDespawn() override;
170
171 // Called when a Player/Creature enters the creature (vehicle)
172 void PassengerBoarded(Unit* who, int8 seatId, bool apply) override;
173
174 // Called when gets initialized
175 void InitializeAI() override;
176
177 // Called once creature is fully added to world
178 void JustAppeared() override;
179
180 // Called when creature gets charmed by another unit
181 void OnCharmed(bool isNew) override;
182
183 // Used in scripts to share variables
184 void DoAction(int32 param = 0) override;
185
186 // Used in scripts to share variables
187 uint32 GetData(uint32 id = 0) const override;
188
189 // Used in scripts to share variables
190 void SetData(uint32 id, uint32 value) override { SetData(id, value, nullptr); }
191 void SetData(uint32 id, uint32 value, Unit* invoker);
192
193 // Used in scripts to share variables
194 void SetGUID(ObjectGuid const& guid, int32 id = 0) override;
195
196 // Used in scripts to share variables
197 ObjectGuid GetGUID(int32 id = 0) const override;
198
199 // Makes the creature run/walk
200 void SetRun(bool run = true);
201
202 void SetDisableGravity(bool disable = true);
203
204 void SetEvadeDisabled(bool disable = true);
205
207 {
208 _invincibilityHPLevel = level;
209 }
210
211 bool OnGossipHello(Player* player) override;
212 bool OnGossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override;
213 bool OnGossipSelectCode(Player* player, uint32 menuId, uint32 gossipListId, char const* code) override;
214 void OnQuestAccept(Player* player, Quest const* quest) override;
215 void OnQuestReward(Player* player, Quest const* quest, uint32 opt) override;
216 void OnGameEvent(bool start, uint16 eventId) override;
217
219 {
220 _despawnTime = t;
221 _despawnState = t ? 1 : 0;
222 }
224 {
225 _despawnState = 2;
226 }
227
228 void OnSpellClick(Unit* clicker, bool spellClickHandled) override;
229
231 {
232 _waypointPauseTimer = time;
233 }
234
235 void SetGossipReturn(bool val)
236 {
237 _gossipReturn = val;
238 }
239
240 void SetEscortQuest(uint32 questID)
241 {
242 _escortQuestId = questID;
243 }
244
245 private:
246 bool AssistPlayerInCombatAgainst(Unit* who);
247 void ReturnToLastOOCPos();
248 void CheckConditions(uint32 diff);
249 void UpdatePath(uint32 diff);
250 void UpdateFollow(uint32 diff);
251 void UpdateDespawn(uint32 diff);
252
262
273
274 bool _run;
279
282
283 // Vehicle conditions
286
287 // Gossip
289
291};
292
294{
295 public:
296 SmartGameObjectAI(GameObject* go) : GameObjectAI(go), _gossipReturn(false) { }
298
299 void UpdateAI(uint32 diff) override;
300 void InitializeAI() override;
301 void Reset() override;
303 {
304 return &_script;
305 }
306 static int32 Permissible(GameObject const* /*go*/)
307 {
308 return PERMIT_BASE_NO;
309 }
310
311 bool OnGossipHello(Player* player) override;
312 bool OnGossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override;
313 bool OnGossipSelectCode(Player* player, uint32 menuId, uint32 gossipListId, char const* code) override;
314 void OnQuestAccept(Player* player, Quest const* quest) override;
315 void OnQuestReward(Player* player, Quest const* quest, uint32 opt) override;
316 bool OnReportUse(Player* player) override;
317 void Destroyed(WorldObject* attacker, uint32 eventId) override;
318 void SetData(uint32 id, uint32 value, Unit* invoker);
319 void SetData(uint32 id, uint32 value) override { SetData(id, value, nullptr); }
320 void SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker);
321 void OnGameEvent(bool start, uint16 eventId) override;
322 void OnLootStateChanged(uint32 state, Unit* unit) override;
323 void EventInform(uint32 eventId) override;
324
325 // Called when hit by a spell
326 void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override;
327
328 // Called when the gameobject summon successfully other creature
329 void JustSummoned(Creature* creature) override;
330
331 // Called when a summoned unit dies
332 void SummonedCreatureDies(Creature* summon, Unit* killer) override;
333
334 // Called when a summoned creature dissapears (UnSommoned)
335 void SummonedCreatureDespawn(Creature* unit) override;
336
337 void SetGossipReturn(bool val) { _gossipReturn = val; }
338
339 private:
341
342 // Gossip
344};
345
347void AddSC_SmartScripts();
348
349#endif
@ PERMIT_BASE_NO
Definition CreatureAI.h:43
#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
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
static float constexpr SMART_MAX_AID_DIST
Definition SmartAI.h:37
SmartEscortState
Definition SmartAI.h:29
@ SMART_ESCORT_ESCORTING
Definition SmartAI.h:31
@ SMART_ESCORT_PAUSED
Definition SmartAI.h:33
@ SMART_ESCORT_RETURNING
Definition SmartAI.h:32
@ SMART_ESCORT_NONE
Definition SmartAI.h:30
void AddSC_SmartScripts()
Registers scripts required by the SAI scripting system.
Definition SmartAI.cpp:1146
static float constexpr SMART_ESCORT_MAX_PLAYER_DIST
Definition SmartAI.h:36
DamageEffectType
Definition Unit.h:352
Data
virtual bool OnGossipHello(Player *)
Definition CreatureAI.h:216
virtual void OnQuestReward(Player *, Quest const *, uint32)
Definition CreatureAI.h:228
virtual void WaypointPathEnded(uint32, uint32)
Definition CreatureAI.h:234
virtual void WaypointReached(uint32, uint32)
Definition CreatureAI.h:233
virtual void MoveInLineOfSight(Unit *)
virtual void JustEngagedWith(Unit *)
Definition CreatureAI.h:127
virtual void JustSummoned(Creature *)
Definition CreatureAI.h:136
virtual void OnAuraApplied(AuraApplication const *)
Definition CreatureAI.h:161
virtual void OnAuraRemoved(AuraApplication const *)
Definition CreatureAI.h:164
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 SpellHitTarget(WorldObject *, SpellInfo const *)
Definition CreatureAI.h:146
virtual void JustReachedHome()
Definition CreatureAI.h:178
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 KilledUnit(Unit *)
Definition CreatureAI.h:133
virtual bool OnGossipSelect(Player *, uint32, uint32)
Definition CreatureAI.h:219
virtual void ReceiveEmote(Player *, uint32)
Definition CreatureAI.h:183
void OnCharmed(bool isNew) override
virtual void JustAppeared()
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
virtual void EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
uint32 _escortQuestId
Definition SmartAI.h:290
void AddEscortState(uint32 escortState)
Definition SmartAI.h:63
void SetEscortQuest(uint32 questID)
Definition SmartAI.h:240
bool _charmed
Definition SmartAI.h:254
bool HasEscortState(uint32 escortState) const
Definition SmartAI.h:59
SmartScript _script
Definition SmartAI.h:253
uint32 _followArrivedEntry
Definition SmartAI.h:258
float _followDistance
Definition SmartAI.h:260
~SmartAI()
Definition SmartAI.h:42
bool _run
Definition SmartAI.h:274
uint32 _vehicleConditionsTimer
Definition SmartAI.h:285
uint32 _escortInvokerCheckTimer
Definition SmartAI.h:265
bool _waypointPathEnded
Definition SmartAI.h:272
void SetDespawnTime(uint32 t)
Definition SmartAI.h:218
void StartDespawn()
Definition SmartAI.h:223
bool _canCombatMove
Definition SmartAI.h:277
bool _vehicleConditions
Definition SmartAI.h:284
bool _waypointReached
Definition SmartAI.h:267
void SetAutoAttack(bool on)
Definition SmartAI.h:71
bool CanCombatMove()
Definition SmartAI.h:76
uint32 _despawnTime
Definition SmartAI.h:280
uint32 _despawnState
Definition SmartAI.h:281
bool _gossipReturn
Definition SmartAI.h:288
float _followAngle
Definition SmartAI.h:261
void SetWPPauseTimer(uint32 time)
Definition SmartAI.h:230
void RemoveEscortState(uint32 escortState)
Definition SmartAI.h:67
uint32 _currentWaypointNode
Definition SmartAI.h:266
uint32 _escortNPCFlags
Definition SmartAI.h:264
bool _waypointPauseForced
Definition SmartAI.h:269
uint32 _followArrivedTimer
Definition SmartAI.h:256
ObjectGuid _followGUID
Definition SmartAI.h:259
void SetGossipReturn(bool val)
Definition SmartAI.h:235
bool _evadeDisabled
Definition SmartAI.h:275
uint32 _waypointPauseTimer
Definition SmartAI.h:268
bool _OOCReached
Definition SmartAI.h:271
uint32 _followCredit
Definition SmartAI.h:257
uint32 _followCreditType
Definition SmartAI.h:255
bool _canAutoAttack
Definition SmartAI.h:276
static int32 Permissible(Creature const *)
Definition SmartAI.h:46
SmartScript * GetScript()
Definition SmartAI.h:88
void SetInvincibilityHpLevel(uint32 level)
Definition SmartAI.h:206
void SetData(uint32 id, uint32 value) override
Definition SmartAI.h:190
uint32 _escortState
Definition SmartAI.h:263
uint32 _invincibilityHPLevel
Definition SmartAI.h:278
bool _repeatWaypointPath
Definition SmartAI.h:270
SmartGameObjectAI(GameObject *go)
Definition SmartAI.h:296
static int32 Permissible(GameObject const *)
Definition SmartAI.h:306
SmartScript * GetScript()
Definition SmartAI.h:302
void SetData(uint32 id, uint32 value) override
Definition SmartAI.h:319
SmartScript _script
Definition SmartAI.h:340
void SetGossipReturn(bool val)
Definition SmartAI.h:337
virtual void HealReceived(Unit *, uint32 &)
Definition UnitAI.h:228
virtual void SetData(uint32, uint32)
Definition UnitAI.h:156
virtual void DoAction(int32)
Definition UnitAI.h:154
virtual void Reset()
Definition UnitAI.h:145
virtual void InitializeAI()
Definition UnitAI.cpp:36
virtual uint32 GetData(uint32) const
Definition UnitAI.h:155
virtual ObjectGuid GetGUID(int32=0) const
Definition UnitAI.h:158
virtual void DamageTaken(Unit *, uint32 &, DamageEffectType, SpellInfo const *)
Definition UnitAI.h:225
virtual void OnGameEvent(bool, uint16)
Definition UnitAI.h:256
virtual void OnDespawn()
Definition UnitAI.h:218
virtual void DamageDealt(Unit *, uint32 &, DamageEffectType)
Definition UnitAI.h:221
virtual void UpdateAI(uint32 diff)=0
virtual void SetGUID(ObjectGuid const &, int32=0)
Definition UnitAI.h:157
virtual void AttackStart(Unit *)
Definition UnitAI.cpp:30
Definition Unit.h:769