Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
SmartAI.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRE_SMARTAI_H
7#define SKYFIRE_SMARTAI_H
8
9#include "Common.h"
10#include "Creature.h"
11#include "CreatureAI.h"
12#include "Spell.h"
13#include "Unit.h"
14
15#include "GameObjectAI.h"
16#include "SmartScript.h"
17
19{
20 SMART_ESCORT_NONE = 0x000, //nothing in progress
21 SMART_ESCORT_ESCORTING = 0x001, //escort is in progress
22 SMART_ESCORT_RETURNING = 0x002, //escort is returning after being in combat
23 SMART_ESCORT_PAUSED = 0x004 //will not proceed with waypoints before state is removed
24};
25
31
32class SmartAI : public CreatureAI
33{
34public:
36 explicit SmartAI(Creature* c);
37
38 // Start moving to the desired MovePoint
39 void StartPath(bool run = false, uint32 path = 0, bool repeat = false, Unit* invoker = NULL);
40 bool LoadPath(uint32 entry);
41 void PausePath(uint32 delay, bool forced = false);
42 void StopPath(uint32 DespawnTime = 0, uint32 quest = 0, bool fail = false);
43 void EndPath(bool fail = false);
44 void ResumePath();
46 bool HasEscortState(uint32 uiEscortState) const { return (mEscortState & uiEscortState); }
47 void AddEscortState(uint32 uiEscortState) { mEscortState |= uiEscortState; }
48 void RemoveEscortState(uint32 uiEscortState) { mEscortState &= ~uiEscortState; }
49 void SetAutoAttack(bool on) { mCanAutoAttack = on; }
50 void SetCombatMove(bool on);
51 bool CanCombatMove() const { return mCanCombatMove; }
52 void SetFollow(Unit* target, float dist = 0.0f, float angle = 0.0f, uint32 credit = 0, uint32 end = 0, uint32 creditType = 0);
53
54 void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker);
57
58 // Called when creature is spawned or respawned
60
61 // Called after InitializeAI(), EnterEvadeMode() for resetting variables
62 void Reset() OVERRIDE;
63
64 // Called at reaching home after evade
66
67 // Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
68 void EnterCombat(Unit* enemy) OVERRIDE;
69
70 // Called for reaction at stopping attack at no attackers or targets
72
73 // Called when the creature is killed
74 void JustDied(Unit* killer) OVERRIDE;
75
76 // Called when the creature kills a unit
77 void KilledUnit(Unit* victim) OVERRIDE;
78
79 // Called when the creature summon successfully other creature
80 void JustSummoned(Creature* creature) OVERRIDE;
81
82 // Tell creature to attack and follow the victim
83 void AttackStart(Unit* who) OVERRIDE;
84
85 // Called if IsVisible(Unit* who) is true at each *who move, reaction at visibility zone enter
87
88 // Called when hit by a spell
89 void SpellHit(Unit* unit, const SpellInfo* spellInfo) OVERRIDE;
90
91 // Called when spell hits a target
92 void SpellHitTarget(Unit* target, const SpellInfo* spellInfo) OVERRIDE;
93
94 // Called at any Damage from any attacker (before damage apply)
95 void DamageTaken(Unit* doneBy, uint32& damage) OVERRIDE;
96
97 // Called when the creature receives heal
98 void HealReceived(Unit* doneBy, uint32& addhealth) OVERRIDE;
99
100 // Called at World update tick
101 void UpdateAI(uint32 diff) OVERRIDE;
102
103 // Called at text emote receive from player
104 void ReceiveEmote(Player* player, uint32 textEmote) OVERRIDE;
105
106 // Called at waypoint reached or point movement finished
107 void MovementInform(uint32 MovementType, uint32 Data) OVERRIDE;
108
109 // Called when creature is summoned by another unit
110 void IsSummonedBy(Unit* summoner) OVERRIDE;
111
112 // Called at any Damage to any victim (before damage apply)
113 void DamageDealt(Unit* doneTo, uint32& damage, DamageEffectType /*damagetype*/) OVERRIDE;
114
115 // Called when a summoned creature dissapears (UnSommoned)
117
118 // called when the corpse of this creature gets removed
119 void CorpseRemoved(uint32& respawnDelay) OVERRIDE;
120
121 // Called at World update tick if creature is charmed
122 void UpdateAIWhileCharmed(const uint32 diff);
123
124 // Called when a Player/Creature enters the creature (vehicle)
125 void PassengerBoarded(Unit* who, int8 seatId, bool apply) OVERRIDE;
126
127 // Called when gets initialized, when creature is added to world
128 void InitializeAI() OVERRIDE;
129
130 // Called when creature gets charmed by another unit
131 void OnCharmed(bool apply) OVERRIDE;
132
133 // Called when victim is in line of sight
134 bool CanAIAttack(const Unit* who) const OVERRIDE;
135
136 // Used in scripts to share variables
137 void DoAction(int32 param = 0) OVERRIDE;
138
139 // Used in scripts to share variables
140 uint32 GetData(uint32 id = 0) const OVERRIDE;
141
142 // Used in scripts to share variables
143 void SetData(uint32 id, uint32 value) OVERRIDE;
144
145 // Used in scripts to share variables
146 void SetGUID(uint64 guid, int32 id = 0) OVERRIDE;
147
148 // Used in scripts to share variables
149 uint64 GetGUID(int32 id = 0) const OVERRIDE;
150
151 //core related
152 static int Permissible(const Creature*);
153
154 // Called at movepoint reached
155 void MovepointReached(uint32 id);
156
157 // Makes the creature run/walk
158 void SetRun(bool run = true);
159
160 void SetFly(bool fly = true);
161
162 void SetSwim(bool swim = true);
163
165
166 bool OnGossipHello(Player* player) OVERRIDE;
167 void sGossipHello(Player* player) OVERRIDE;
168 void sGossipSelect(Player* player, uint32 sender, uint32 action) OVERRIDE;
169 void sGossipSelectCode(Player* player, uint32 sender, uint32 action, const char* code) OVERRIDE;
170 void sQuestAccept(Player* player, Quest const* quest) OVERRIDE;
171 //void sQuestSelect(Player* player, Quest const* quest) OVERRIDE;
172 //void sQuestComplete(Player* player, Quest const* quest) OVERRIDE;
173 void sQuestReward(Player* player, Quest const* quest, uint32 opt) OVERRIDE;
174 bool sOnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effIndex) OVERRIDE;
175 void sOnGameEvent(bool start, uint16 eventId) OVERRIDE;
176
178
180 {
181 mDespawnTime = t;
182 mDespawnState = t ? 1 : 0;
183 }
185
186 void RemoveAuras();
187
188 void OnSpellClick(Unit* clicker, bool& result) OVERRIDE;
189
190 void SetGossipReturn(bool value) { _gossipReturn = value; }
191
192private:
200
201 void ReturnToLastOOCPos();
202 void UpdatePath(const uint32 diff);
211 Position mLastOOCPos;//set on enter combat
212 uint32 GetWPCount() { return mWayPoints ? mWayPoints->size() : 0; }
214 bool mRun;
219 bool AssistPlayerInCombat(Unit* who);
220
223 void UpdateDespawn(const uint32 diff);
226};
227
229{
230public:
233
234 void UpdateAI(uint32 diff) OVERRIDE;
235 void InitializeAI() OVERRIDE;
236 void Reset() OVERRIDE;
238 static int Permissible(const GameObject* g);
239
240 bool GossipHello(Player* player) OVERRIDE;
241 bool GossipSelect(Player* player, uint32 sender, uint32 action) OVERRIDE;
242 bool GossipSelectCode(Player* /*player*/, uint32 /*sender*/, uint32 /*action*/, const char* /*code*/) OVERRIDE;
243 void SetGossipReturn(bool value) { _gossipReturn = value; }
244 bool QuestAccept(Player* player, Quest const* quest) OVERRIDE;
245 bool QuestReward(Player* player, Quest const* quest, uint32 opt) OVERRIDE;
247 void Destroyed(Player* player, uint32 eventId) OVERRIDE;
248 void SetData(uint32 id, uint32 value) OVERRIDE;
249 void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker);
250 void OnGameEvent(bool start, uint16 eventId) OVERRIDE;
251 void OnStateChanged(uint32 state, Unit* unit) OVERRIDE;
252 void EventInform(uint32 eventId) OVERRIDE;
253
254protected:
258};
259#endif
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
std::int8_t int8
Definition Define.h:75
#define OVERRIDE
Definition Define.h:60
std::uint64_t uint64
Definition Define.h:76
std::uint16_t uint16
Definition Define.h:78
SpellEffIndex
SmartEscortState
Definition SmartAI.h:19
@ SMART_ESCORT_ESCORTING
Definition SmartAI.h:21
@ SMART_ESCORT_PAUSED
Definition SmartAI.h:23
@ SMART_ESCORT_RETURNING
Definition SmartAI.h:22
@ SMART_ESCORT_NONE
Definition SmartAI.h:20
SmartEscortVars
Definition SmartAI.h:27
@ SMART_ESCORT_MAX_PLAYER_DIST
Definition SmartAI.h:28
@ SMART_MAX_AID_DIST
Definition SmartAI.h:29
UNORDERED_MAP< uint32, WayPoint * > WPPath
DamageEffectType
Definition Unit.h:613
CreatureAI(Creature *creature)
Definition CreatureAI.h:69
GameObjectAI(GameObject *g)
uint32 mDespawnTime
Definition SmartAI.h:221
uint32 mEscortState
Definition SmartAI.h:205
WayPoint * mLastWP
Definition SmartAI.h:210
bool OnGossipHello(Player *player) OVERRIDE
Definition SmartAI.cpp:718
WPPath * mWayPoints
Definition SmartAI.h:204
uint32 mEscortInvokerCheckTimer
Definition SmartAI.h:224
void OnSpellClick(Unit *clicker, bool &result) OVERRIDE
Definition SmartAI.cpp:799
void RemoveEscortState(uint32 uiEscortState)
Definition SmartAI.h:48
uint32 mDespawnState
Definition SmartAI.h:222
uint32 mWPPauseTimer
Definition SmartAI.h:209
void UpdatePath(const uint32 diff)
Definition SmartAI.cpp:230
void JustReachedHome() OVERRIDE
Definition SmartAI.cpp:552
void IsSummonedBy(Unit *summoner) OVERRIDE
Definition SmartAI.cpp:631
void StartPath(bool run=false, uint32 path=0, bool repeat=false, Unit *invoker=NULL)
Definition SmartAI.cpp:76
uint32 mCurrentWPID
Definition SmartAI.h:206
void PausePath(uint32 delay, bool forced=false)
Definition SmartAI.cpp:118
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================
Definition SmartAI.cpp:296
void MoveInLineOfSight(Unit *who) OVERRIDE
Definition SmartAI.cpp:447
~SmartAI()
Definition SmartAI.h:35
void sGossipSelect(Player *player, uint32 sender, uint32 action) OVERRIDE
Definition SmartAI.cpp:725
void RemoveAuras()
Definition SmartAI.cpp:400
void SetSwim(bool swim=true)
Definition SmartAI.cpp:708
void AttackStart(Unit *who) OVERRIDE
Definition SmartAI.cpp:581
bool mWPReached
Definition SmartAI.h:208
uint32 mLastWPIDReached
Definition SmartAI.h:207
uint32 mFollowArrivedTimer
Definition SmartAI.h:194
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition SmartAI.cpp:140
void PassengerBoarded(Unit *who, int8 seatId, bool apply) OVERRIDE
== Fields =======================================
Definition SmartAI.cpp:653
void UpdateAIWhileCharmed(const uint32 diff)
Definition SmartAI.cpp:646
void InitializeAI() OVERRIDE
Definition SmartAI.cpp:658
void SetDespawnTime(uint32 t)
Definition SmartAI.h:179
void StartDespawn()
Definition SmartAI.h:184
bool AssistPlayerInCombat(Unit *who)
Definition SmartAI.cpp:489
void EndPath(bool fail=false)
Definition SmartAI.cpp:157
void SetFollow(Unit *target, float dist=0.0f, float angle=0.0f, uint32 credit=0, uint32 end=0, uint32 creditType=0)
Definition SmartAI.cpp:772
SmartAI(Creature *c)
Definition SmartAI.cpp:21
void SetAutoAttack(bool on)
Definition SmartAI.h:49
void sQuestAccept(Player *player, Quest const *quest) OVERRIDE
Definition SmartAI.cpp:732
void sGossipHello(Player *player) OVERRIDE
Definition SmartAI.cpp:713
float mFollowAngle
Definition SmartAI.h:199
bool LoadPath(uint32 entry)
Definition SmartAI.cpp:104
void DamageDealt(Unit *doneTo, uint32 &damage, DamageEffectType) OVERRIDE
Definition SmartAI.cpp:636
WayPoint * GetNextWayPoint()
Definition SmartAI.cpp:57
uint32 mEscortQuestID
Definition SmartAI.h:177
void MovepointReached(uint32 id)
Definition SmartAI.cpp:380
void JustRespawned() OVERRIDE
Definition SmartAI.cpp:526
bool CanCombatMove() const
Definition SmartAI.h:51
void MovementInform(uint32 MovementType, uint32 Data) OVERRIDE
Definition SmartAI.cpp:389
bool CanAIAttack(const Unit *who) const OVERRIDE
Definition SmartAI.cpp:482
void CorpseRemoved(uint32 &respawnDelay) OVERRIDE
== State checks =================================
Definition SmartAI.cpp:648
void SetGUID(uint64 guid, int32 id=0) OVERRIDE
Definition SmartAI.cpp:690
bool _gossipReturn
Definition SmartAI.h:225
SmartScript mScript
Definition SmartAI.h:203
bool mRun
Definition SmartAI.h:214
void SpellHitTarget(Unit *target, const SpellInfo *spellInfo) OVERRIDE
Definition SmartAI.cpp:606
uint32 mFollowCreditType
Definition SmartAI.h:193
uint32 GetData(uint32 id=0) const OVERRIDE
Definition SmartAI.cpp:680
void OnCharmed(bool apply) OVERRIDE
Definition SmartAI.cpp:666
void sQuestReward(Player *player, Quest const *quest, uint32 opt) OVERRIDE
Definition SmartAI.cpp:737
void KilledUnit(Unit *victim) OVERRIDE
Definition SmartAI.cpp:571
void Reset() OVERRIDE
Definition SmartAI.cpp:50
uint32 mInvincibilityHpLevel
Definition SmartAI.h:218
bool mCanAutoAttack
Definition SmartAI.h:215
void DamageTaken(Unit *doneBy, uint32 &damage) OVERRIDE
Definition SmartAI.cpp:611
void sGossipSelectCode(Player *player, uint32 sender, uint32 action, const char *code) OVERRIDE
Definition SmartAI.cpp:730
uint64 GetGUID(int32 id=0) const OVERRIDE
Definition SmartAI.cpp:692
bool mCanRepeatPath
Definition SmartAI.h:213
bool sOnDummyEffect(Unit *caster, uint32 spellId, SpellEffIndex effIndex) OVERRIDE
Definition SmartAI.cpp:742
void SetFly(bool fly=true)
Definition SmartAI.cpp:703
bool mCanCombatMove
Definition SmartAI.h:216
void ReturnToLastOOCPos()
Definition SmartAI.cpp:224
void EnterEvadeMode() OVERRIDE
Definition SmartAI.cpp:414
void JustSummoned(Creature *creature) OVERRIDE
Definition SmartAI.cpp:576
void EnterCombat(Unit *enemy) OVERRIDE
Definition SmartAI.cpp:557
bool mForcedPaused
Definition SmartAI.h:217
bool HasEscortState(uint32 uiEscortState) const
Definition SmartAI.h:46
void AddEscortState(uint32 uiEscortState)
Definition SmartAI.h:47
uint32 mFollowCredit
Definition SmartAI.h:195
uint32 mFollowArrivedEntry
Definition SmartAI.h:196
float mFollowDist
Definition SmartAI.h:198
void SummonedCreatureDespawn(Creature *unit) OVERRIDE
Definition SmartAI.cpp:641
void SetGossipReturn(bool value)
Definition SmartAI.h:190
uint64 mFollowGuid
Definition SmartAI.h:197
void DoAction(int32 param=0) OVERRIDE
Definition SmartAI.cpp:675
void SpellHit(Unit *unit, const SpellInfo *spellInfo) OVERRIDE
Definition SmartAI.cpp:601
void SetCombatMove(bool on)
Definition SmartAI.cpp:748
void SetScript9(SmartScriptHolder &e, uint32 entry, Unit *invoker)
Definition SmartAI.cpp:787
SmartScript * GetScript()
Definition SmartAI.h:55
void ReceiveEmote(Player *player, uint32 textEmote) OVERRIDE
Definition SmartAI.cpp:626
void SetInvincibilityHpLevel(uint32 level)
Definition SmartAI.h:164
uint32 GetWPCount()
Definition SmartAI.h:212
void SetRun(bool run=true)
Definition SmartAI.cpp:697
void UpdateDespawn(const uint32 diff)
Definition SmartAI.cpp:31
Position mLastOOCPos
Definition SmartAI.h:211
void JustDied(Unit *killer) OVERRIDE
Definition SmartAI.cpp:564
void ResumePath()
Definition SmartAI.cpp:216
void HealReceived(Unit *doneBy, uint32 &addhealth) OVERRIDE
Definition SmartAI.cpp:621
bool IsEscortInvokerInRange()
Definition SmartAI.cpp:343
void sOnGameEvent(bool start, uint16 eventId) OVERRIDE
Definition SmartAI.cpp:794
void SetGossipReturn(bool value)
Definition SmartAI.h:243
SmartGameObjectAI(GameObject *g)
Definition SmartAI.h:231
bool GossipHello(Player *player) OVERRIDE
Definition SmartAI.cpp:832
bool GossipSelect(Player *player, uint32 sender, uint32 action) OVERRIDE
Definition SmartAI.cpp:841
GameObject *const go
Definition SmartAI.h:255
bool QuestAccept(Player *player, Quest const *quest) OVERRIDE
Definition SmartAI.cpp:854
void SetScript9(SmartScriptHolder &e, uint32 entry, Unit *invoker)
Definition SmartAI.cpp:881
void OnStateChanged(uint32 state, Unit *unit) OVERRIDE
Definition SmartAI.cpp:893
void EventInform(uint32 eventId) OVERRIDE
Definition SmartAI.cpp:898
void Reset() OVERRIDE
Definition SmartAI.cpp:826
SmartScript * GetScript()
Definition SmartAI.h:237
void UpdateAI(uint32 diff) OVERRIDE
Definition SmartAI.cpp:814
uint32 GetDialogStatus(Player *) OVERRIDE
Definition SmartAI.cpp:868
static int Permissible(const GameObject *g)
Definition SmartAI.cpp:807
SmartScript mScript
Definition SmartAI.h:256
void OnGameEvent(bool start, uint16 eventId) OVERRIDE
Definition SmartAI.cpp:888
void InitializeAI() OVERRIDE
Definition SmartAI.cpp:819
void Destroyed(Player *player, uint32 eventId) OVERRIDE
Definition SmartAI.cpp:871
bool GossipSelectCode(Player *, uint32, uint32, const char *) OVERRIDE
Definition SmartAI.cpp:848
bool QuestReward(Player *player, Quest const *quest, uint32 opt) OVERRIDE
Definition SmartAI.cpp:861
Definition Unit.h:1367
Data
Definition molten_core.h:55