TrinityCore
EscortAI Struct Reference

#include <ScriptedEscortAI.h>

Public Member Functions

 EscortAI (Creature *creature)
 
 ~EscortAI ()
 
void InitializeAI () override
 
void MoveInLineOfSight (Unit *who) override
 
void JustDied (Unit *) override
 
void ReturnToLastPoint ()
 
void EnterEvadeMode (EvadeReason why) override
 
void MovementInform (uint32, uint32) override
 
void UpdateAI (uint32 diff) override
 
virtual void UpdateEscortAI (uint32 diff)
 
void AddWaypoint (uint32 id, float x, float y, float z, bool run)
 
void AddWaypoint (uint32 id, float x, float y, float z, float orientation=0.f, Milliseconds waitTime=0s, bool run=false)
 
void ResetPath ()
 
void LoadPath (uint32 pathId)
 
void Start (bool isActiveAttacker=true, ObjectGuid playerGUID=ObjectGuid::Empty, Quest const *quest=nullptr, bool instantRespawn=false, bool canLoopPath=false)
 
void SetEscortPaused (bool on)
 
void SetPauseTimer (Milliseconds timer)
 
bool HasEscortState (uint32 escortState)
 
bool IsEscorted () const override
 
void SetMaxPlayerDistance (float newMax)
 
float GetMaxPlayerDistance () const
 
void SetDespawnAtEnd (bool despawn)
 
void SetDespawnAtFar (bool despawn)
 
bool IsActiveAttacker () const
 
void SetActiveAttacker (bool enable)
 
ObjectGuid GetEventStarterGUID () const
 
- Public Member Functions inherited from ScriptedAI
 ScriptedAI (Creature *creature)
 
 ScriptedAI (Creature *creature, uint32 scriptId)
 
virtual ~ScriptedAI ()
 
void AttackStartNoMove (Unit *target)
 
virtual void UpdateAI (uint32 diff) override
 
void AttackStart (Unit *) override
 
void DoStartMovement (Unit *target, float distance=0.0f, float angle=0.0f)
 
void DoStartNoMovement (Unit *target)
 
void DoStopAttack ()
 
void DoCastSpell (Unit *target, SpellInfo const *spellInfo, bool triggered=false)
 
void DoPlaySoundToSet (WorldObject *source, uint32 soundId)
 
void AddThreat (Unit *victim, float amount, Unit *who=nullptr)
 
void ModifyThreatByPercent (Unit *victim, int32 pct, Unit *who=nullptr)
 
void ResetThreat (Unit *victim, Unit *who=nullptr)
 
void ResetThreatList (Unit *who=nullptr)
 
float GetThreat (Unit const *victim, Unit const *who=nullptr)
 
void ForceCombatStop (Creature *who, bool reset=true)
 
void ForceCombatStopForCreatureEntry (uint32 entry, float maxSearchRange=250.0f, bool samePhase=true, bool reset=true)
 
void ForceCombatStopForCreatureEntry (std::vector< uint32 > creatureEntries, float maxSearchRange=250.0f, bool samePhase=true, bool reset=true)
 
void DoTeleportTo (float x, float y, float z, uint32 time=0)
 
void DoTeleportTo (float const pos[4])
 
void DoTeleportPlayer (Unit *unit, float x, float y, float z, float o)
 
void DoTeleportAll (float x, float y, float z, float o)
 
UnitDoSelectLowestHpFriendly (float range, uint32 minHPDiff=1)
 
UnitDoSelectBelowHpPctFriendlyWithEntry (uint32 entry, float range, uint8 hpPct=1, bool excludeSelf=true)
 
std::list< Creature * > DoFindFriendlyCC (float range)
 
std::list< Creature * > DoFindFriendlyMissingBuff (float range, uint32 spellId)
 
PlayerGetPlayerAtMinimumRange (float minRange)
 
CreatureDoSpawnCreature (uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, Milliseconds despawntime)
 
bool HealthBelowPct (uint32 pct) const
 
bool HealthAbovePct (uint32 pct) const
 
SpellInfo const * SelectSpell (Unit *target, uint32 school, uint32 mechanic, SelectTargetType targets, float rangeMin, float rangeMax, SelectEffect effect)
 
void SetEquipmentSlots (bool loadDefault, int32 mainHand=EQUIP_NO_CHANGE, int32 offHand=EQUIP_NO_CHANGE, int32 ranged=EQUIP_NO_CHANGE)
 
void SetCombatMovement (bool allowMovement)
 
bool IsCombatMovementAllowed () const
 
bool IsLFR () const
 
bool IsNormal () const
 
bool IsHeroic () const
 
bool IsMythic () const
 
bool IsMythicPlus () const
 
bool IsHeroicOrHigher () const
 
bool IsTimewalking () const
 
Difficulty GetDifficulty () const
 
bool Is25ManRaid () const
 
template<class T >
T const & DUNGEON_MODE (T const &normal5, T const &heroic10) const
 
template<class T >
T const & RAID_MODE (T const &normal10, T const &normal25) const
 
template<class T >
T const & RAID_MODE (T const &normal10, T const &normal25, T const &heroic10, T const &heroic25) const
 
- Public Member Functions inherited from CreatureAI
 CreatureAI (Creature *creature, uint32 scriptId={})
 
virtual ~CreatureAI ()
 
uint32 GetId () const
 
bool IsEngaged () const
 
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr)
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At ================================= More...
 
void TriggerAlert (Unit const *who) const
 
virtual void EnterEvadeMode (EvadeReason why=EvadeReason::Other)
 
void JustEnteredCombat (Unit *) override
 
virtual void JustStartedThreateningMe (Unit *who)
 
virtual void JustEngagedWith (Unit *)
 
virtual void OnHealthDepleted (Unit *, bool)
 
virtual void JustDied (Unit *)
 
virtual void KilledUnit (Unit *)
 
virtual void JustSummoned (Creature *)
 
virtual void IsSummonedBy (WorldObject *)
 
virtual void SummonedCreatureDespawn (Creature *)
 
virtual void SummonedCreatureDies (Creature *, Unit *)
 
virtual void JustSummonedGameobject (GameObject *)
 
virtual void SummonedGameobjectDespawn (GameObject *)
 
virtual void JustRegisteredDynObject (DynamicObject *)
 
virtual void JustUnregisteredDynObject (DynamicObject *)
 
virtual void JustRegisteredAreaTrigger (AreaTrigger *)
 
virtual void JustUnregisteredAreaTrigger (AreaTrigger *)
 
virtual void SpellHit (WorldObject *, SpellInfo const *)
 
virtual void SpellHitTarget (WorldObject *, SpellInfo const *)
 
virtual void OnSpellCast (SpellInfo const *)
 
virtual void OnSpellFailed (SpellInfo const *)
 
virtual void OnSpellStart (SpellInfo const *)
 
virtual void OnChannelFinished (SpellInfo const *)
 
virtual bool IsEscorted () const
 
virtual void JustAppeared ()
 
virtual void MovementInform (uint32, uint32)
 
void OnCharmed (bool isNew) override
 
virtual void JustReachedHome ()
 
void DoZoneInCombat ()
 
virtual void ReceiveEmote (Player *, uint32)
 
virtual void OwnerAttackedBy (Unit *attacker)
 
virtual void OwnerAttacked (Unit *target)
 
virtual void CorpseRemoved (uint32 &)
 == Triggered Actions Requested ================== More...
 
virtual Optional< QuestGiverStatusGetDialogStatus (Player const *player)
 == Gossip system ================================ More...
 
virtual bool OnGossipHello (Player *)
 
virtual bool OnGossipSelect (Player *, uint32, uint32)
 
virtual bool OnGossipSelectCode (Player *, uint32, uint32, char const *)
 
virtual void OnQuestAccept (Player *, Quest const *)
 
virtual void OnQuestReward (Player *, Quest const *, LootItemType, uint32)
 
virtual void WaypointStarted (uint32, uint32)
 == Waypoints system ============================= More...
 
virtual void WaypointReached (uint32, uint32)
 
virtual void WaypointPathEnded (uint32, uint32)
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields ======================================= More...
 
virtual void OnSpellClick (Unit *, bool)
 
virtual bool CanSeeAlways (WorldObject const *)
 
virtual PlayerAIGetAIForCharmedPlayer (Player *)
 
int32 VisualizeBoundary (Seconds duration, Unit *owner=nullptr, bool fill=false) const
 
virtual bool CheckInRoom ()
 
CreatureBoundary const * GetBoundary () const
 
void SetBoundary (CreatureBoundary const *boundary, bool negativeBoundaries=false)
 
bool IsInBoundary (Position const *who=nullptr) const
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual bool CanAIAttack (Unit const *) const
 
virtual void AttackStart (Unit *)
 
virtual void UpdateAI (uint32 diff)=0
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool isNew)
 
virtual void DoAction (int32)
 
virtual uint32 GetData (uint32) const
 
virtual void SetData (uint32, uint32)
 
virtual void SetGUID (ObjectGuid const &, int32=0)
 
virtual ObjectGuid GetGUID (int32=0) const
 
UnitSelectTarget (SelectTargetMethod targetType, uint32 offset=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectTargetMethod targetType, uint32 offset, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 offset=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 offset, PREDICATE const &predicate)
 
virtual void JustEnteredCombat (Unit *)
 
virtual void JustExitedCombat ()
 
virtual void OnDespawn ()
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellInfo const *)
 
virtual void HealReceived (Unit *, uint32 &)
 
virtual void HealDone (Unit *, uint32 &)
 
virtual void SpellInterrupted (uint32, uint32)
 
void AttackStartCaster (Unit *victim, float dist)
 
SpellCastResult DoCast (uint32 spellId)
 
SpellCastResult DoCast (Unit *victim, uint32 spellId, CastSpellExtraArgs const &args={})
 
SpellCastResult DoCastSelf (uint32 spellId, CastSpellExtraArgs const &args={})
 
SpellCastResult DoCastVictim (uint32 spellId, CastSpellExtraArgs const &args={})
 
SpellCastResult DoCastAOE (uint32 spellId, CastSpellExtraArgs const &args={})
 
bool DoSpellAttackIfReady (uint32 spellId)
 
virtual void OnGameEvent (bool, uint16)
 
virtual std::string GetDebugInfo () const
 

Protected Member Functions

PlayerGetPlayerForEscort ()
 
- Protected Member Functions inherited from CreatureAI
bool UpdateVictim ()
 
CreatureDoSummon (uint32 entry, Position const &pos, Milliseconds despawnTime=30s, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummon (uint32 entry, WorldObject *obj, float radius=5.0f, Milliseconds despawnTime=30s, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummonFlyer (uint32 entry, WorldObject *obj, float flightZ, float radius=5.0f, Milliseconds despawnTime=30s, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
void EngagementStart (Unit *who)
 
void EngagementOver ()
 
virtual void MoveInLineOfSight (Unit *)
 
bool _EnterEvadeMode (EvadeReason why=EvadeReason::Other)
 

Private Member Functions

bool AssistPlayerInCombatAgainst (Unit *who)
 
bool IsPlayerOrGroupInRange ()
 
void AddEscortState (uint32 escortState)
 
void RemoveEscortState (uint32 escortState)
 

Private Attributes

ObjectGuid _playerGUID
 
Milliseconds _pauseTimer
 
uint32 _playerCheckTimer
 
uint32 _escortState
 
float _maxPlayerDistance
 
Quest const * _escortQuest
 
WaypointPath _path
 
bool _activeAttacker
 
bool _instantRespawn
 
bool _returnToStart
 
bool _despawnAtEnd
 
bool _despawnAtFar
 
bool _hasImmuneToNPCFlags
 
bool _started
 
bool _ended
 
bool _resume
 

Additional Inherited Members

- Static Public Member Functions inherited from CreatureAI
static void DoZoneInCombat (Creature *creature)
 
static bool IsInBounds (CreatureBoundary const &boundary, Position const *who)
 
- Static Public Member Functions inherited from UnitAI
static void FillAISpellInfo ()
 
- Public Attributes inherited from ScriptedAI
bool IsFleeing
 
- Static Public Attributes inherited from UnitAI
static std::unordered_map< std::pair< uint32, Difficulty >, AISpellInfoTypeAISpellInfo
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
CreatureBoundary const * _boundary
 
bool _negateBoundary
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Detailed Description

Definition at line 36 of file ScriptedEscortAI.h.

Constructor & Destructor Documentation

◆ EscortAI()

EscortAI::EscortAI ( Creature creature)
explicit

Definition at line 37 of file ScriptedEscortAI.cpp.

38 _escortQuest(nullptr), _activeAttacker(true), _instantRespawn(false), _returnToStart(false), _despawnAtEnd(true), _despawnAtFar(true),
39 _hasImmuneToNPCFlags(false), _started(false), _ended(false), _resume(false)
40{
41}
@ STATE_ESCORT_NONE
#define DEFAULT_MAX_PLAYER_DISTANCE
float _maxPlayerDistance
uint32 _escortState
Milliseconds _pauseTimer
Quest const * _escortQuest
bool _activeAttacker
bool _despawnAtEnd
bool _despawnAtFar
bool _hasImmuneToNPCFlags
uint32 _playerCheckTimer
bool _instantRespawn
bool _returnToStart
ScriptedAI(Creature *creature)

◆ ~EscortAI()

EscortAI::~EscortAI ( )
inline

Definition at line 40 of file ScriptedEscortAI.h.

40{ }

Member Function Documentation

◆ AddEscortState()

void EscortAI::AddEscortState ( uint32  escortState)
inlineprivate

Definition at line 76 of file ScriptedEscortAI.h.

76{ _escortState |= escortState; }
+ Here is the caller graph for this function:

◆ AddWaypoint() [1/2]

void EscortAI::AddWaypoint ( uint32  id,
float  x,
float  y,
float  z,
bool  run 
)

Definition at line 254 of file ScriptedEscortAI.cpp.

255{
256 AddWaypoint(id, x, y, z, 0.0f, 0s, run);
257}
void AddWaypoint(uint32 id, float x, float y, float z, bool run)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddWaypoint() [2/2]

void EscortAI::AddWaypoint ( uint32  id,
float  x,
float  y,
float  z,
float  orientation = 0.f,
Milliseconds  waitTime = 0s,
bool  run = false 
)

Definition at line 259 of file ScriptedEscortAI.cpp.

260{
263
264 WaypointNode waypoint(id, x, y, z, orientation, waitTime.count());
266 _path.Nodes.push_back(std::move(waypoint));
267}
static float waypoint[6][3]
Definition: boss_alar.cpp:54
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:223
WaypointPath _path
std::vector< WaypointNode > Nodes
+ Here is the call graph for this function:

◆ AssistPlayerInCombatAgainst()

bool EscortAI::AssistPlayerInCombatAgainst ( Unit who)
private

Definition at line 372 of file ScriptedEscortAI.cpp.

373{
374 if (!who || !who->GetVictim())
375 return false;
376
378 return false;
379
380 // experimental (unknown) flag not present
382 return false;
383
384 // not a player
386 return false;
387
388 if (!who->isInAccessiblePlaceFor(me))
389 return false;
390
391 if (!CanAIAttack(who))
392 return false;
393
394 // we cannot attack in evade mode
395 if (me->IsInEvadeMode())
396 return false;
397
398 // or if enemy is in evade mode
399 if (who->GetTypeId() == TYPEID_UNIT && who->ToCreature()->IsInEvadeMode())
400 return false;
401
402 if (!me->IsValidAssistTarget(who->GetVictim()))
403 return false;
404
405 // too far away and no free sight
407 {
408 me->EngageWithTarget(who);
409 return true;
410 }
411
412 return false;
413}
@ TYPEID_UNIT
Definition: ObjectGuid.h:40
@ CREATURE_TYPE_FLAG_CAN_ASSIST
@ REACT_PASSIVE
Definition: UnitDefines.h:506
Creature *const me
Definition: CreatureAI.h:61
CreatureDifficulty const * GetCreatureDifficulty() const
Definition: Creature.h:222
bool HasReactState(ReactStates state) const
Definition: Creature.h:142
bool IsInEvadeMode() const
Definition: Creature.h:179
static Creature * ToCreature(Object *o)
Definition: Object.h:206
TypeID GetTypeId() const
Definition: Object.h:172
virtual bool CanAIAttack(Unit const *) const
Definition: UnitAI.h:57
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:3162
Unit * EnsureVictim() const
Definition: Unit.h:712
void EngageWithTarget(Unit *who)
Definition: Unit.cpp:8050
Unit * GetVictim() const
Definition: Unit.h:710
bool IsWithinLOSInMap(WorldObject const *obj, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing) const
Definition: Object.cpp:1173
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition: Object.cpp:2240
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition: Object.cpp:1139
bool IsValidAssistTarget(WorldObject const *target, SpellInfo const *bySpell=nullptr) const
Definition: Object.cpp:3132
float GetMaxPlayerDistance() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EnterEvadeMode()

void EscortAI::EnterEvadeMode ( EvadeReason  why)
overridevirtual

Reimplemented from CreatureAI.

Reimplemented in npc_highlord_darion_mograine::npc_highlord_darion_mograineAI, hyjalAI, npc_ruul_snowhoof::npc_ruul_snowhoofAI, and npc_icefang.

Definition at line 94 of file ScriptedEscortAI.cpp.

95{
97 me->CombatStop(true);
99 me->SetTappedBy(nullptr);
100
102
104 {
107 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::EnterEvadeMode: left combat and is now returning to last point ({})", me->GetGUID().ToString());
108 }
109 else
110 {
113 me->SetImmuneToNPC(true);
114 Reset();
115 }
116}
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
@ STATE_ESCORT_ESCORTING
@ STATE_ESCORT_RETURNING
void EngagementOver()
Definition: CreatureAI.cpp:287
bool IsTapListNotClearedOnEvade() const
Definition: Creature.h:255
void SetTappedBy(Unit const *unit, bool withGroup=true)
Definition: Creature.cpp:1342
void SetImmuneToNPC(bool apply) override
Definition: Creature.h:153
void MoveTargetedHome()
std::string ToString() const
Definition: ObjectGuid.cpp:554
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:158
virtual void Reset()
Definition: UnitAI.h:63
MotionMaster * GetMotionMaster()
Definition: Unit.h:1637
void RemoveAllAuras()
Definition: Unit.cpp:4223
void CombatStop(bool includingCast=false, bool mutualPvP=true)
Definition: Unit.cpp:5808
void ReturnToLastPoint()
bool HasEscortState(uint32 escortState)
void AddEscortState(uint32 escortState)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetEventStarterGUID()

ObjectGuid EscortAI::GetEventStarterGUID ( ) const
inline

Definition at line 67 of file ScriptedEscortAI.h.

67{ return _playerGUID; }
ObjectGuid _playerGUID

◆ GetMaxPlayerDistance()

float EscortAI::GetMaxPlayerDistance ( ) const
inline

Definition at line 62 of file ScriptedEscortAI.h.

62{ return _maxPlayerDistance; }
+ Here is the caller graph for this function:

◆ GetPlayerForEscort()

Player * EscortAI::GetPlayerForEscort ( )
protected

Definition at line 366 of file ScriptedEscortAI.cpp.

367{
369}
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasEscortState()

bool EscortAI::HasEscortState ( uint32  escortState)
inline

Definition at line 59 of file ScriptedEscortAI.h.

59{ return (_escortState & escortState) != 0; }
+ Here is the caller graph for this function:

◆ InitializeAI()

void EscortAI::InitializeAI ( )
overridevirtual

Reimplemented from UnitAI.

Reimplemented in npc_thrall_old_hillsbrad.

Definition at line 73 of file ScriptedEscortAI.cpp.

74{
76
79
80 // add a small delay before going to first waypoint, normal in near all cases
81 _pauseTimer = 2s;
82
85
86 Reset();
87}
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:220
void RestoreFaction()
Definition: Unit.cpp:11340
uint32 GetFaction() const override
Definition: Unit.h:853
void SetCombatMovement(bool allowMovement)
bool IsCombatMovementAllowed() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsActiveAttacker()

bool EscortAI::IsActiveAttacker ( ) const
inline

Definition at line 65 of file ScriptedEscortAI.h.

65{ return _activeAttacker; } // obsolete

◆ IsEscorted()

bool EscortAI::IsEscorted ( ) const
inlineoverridevirtual

Reimplemented from CreatureAI.

Definition at line 60 of file ScriptedEscortAI.h.

60{ return !_playerGUID.IsEmpty(); }
bool IsEmpty() const
Definition: ObjectGuid.h:317

◆ IsPlayerOrGroupInRange()

bool EscortAI::IsPlayerOrGroupInRange ( )
private

Definition at line 415 of file ScriptedEscortAI.cpp.

416{
417 if (Player* player = GetPlayerForEscort())
418 {
419 if (Group* group = player->GetGroup())
420 {
421 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
422 if (Player* member = groupRef->GetSource())
424 return true;
425 }
426 else if (me->IsWithinDistInMap(player, GetMaxPlayerDistance()))
427 return true;
428 }
429
430 return false;
431}
GroupReference * next()
Definition: Group.h:196
Player * GetPlayerForEscort()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ JustDied()

void EscortAI::JustDied ( Unit )
overridevirtual

Reimplemented from CreatureAI.

Reimplemented in npc_lesser_doomguard::npc_lesser_doomguardAI, npc_frost_wyrm::npc_frost_wyrmAI, hyjal_trashAI, npc_willix::npc_willixAI, npc_disciple_of_naralex::npc_disciple_of_naralexAI, npc_muglash::npc_muglashAI, npc_argent_soldier::npc_argent_soldierAI, npc_engineer_helice, npc_icefang, boss_ambassador_hellmaw, npc_maghar_captive::npc_maghar_captiveAI, npc_kurenai_captive::npc_kurenai_captiveAI, boss_anetheron::boss_anetheronAI, boss_azgalor::boss_azgalorAI, boss_kazrogal::boss_kazrogalAI, boss_rage_winterchill::boss_rage_winterchillAI, npc_necromancer::npc_necromancerAI, npc_banshee::npc_bansheeAI, npc_gargoyle::npc_gargoyleAI, hyjalAI, and npc_thrall_old_hillsbrad.

Definition at line 54 of file ScriptedEscortAI.cpp.

55{
57 return;
58
59 if (Player* player = GetPlayerForEscort())
60 {
61 if (Group* group = player->GetGroup())
62 {
63 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
64 if (Player* member = groupRef->GetSource())
65 if (member->IsInMap(player))
66 member->FailQuest(_escortQuest->GetQuestId());
67 }
68 else
69 player->FailQuest(_escortQuest->GetQuestId());
70 }
71}
uint32 GetQuestId() const
Definition: QuestDef.h:586
+ Here is the call graph for this function:

◆ LoadPath()

void EscortAI::LoadPath ( uint32  pathId)

Definition at line 274 of file ScriptedEscortAI.cpp.

275{
276 WaypointPath const* path = sWaypointMgr->GetPath(pathId);
277 if (!path)
278 {
279 TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::LoadPath: (script: {}) path {} is invalid ({})", me->GetScriptName(), pathId, me->GetGUID().ToString());
280 return;
281 }
282 _path = *path;
283}
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:165
#define sWaypointMgr
std::string GetScriptName() const
Definition: Creature.cpp:3128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MoveInLineOfSight()

void EscortAI::MoveInLineOfSight ( Unit who)
overridevirtual

Reimplemented from CreatureAI.

Reimplemented in npc_highlord_darion_mograine::npc_highlord_darion_mograineAI, npc_lesser_doomguard::npc_lesser_doomguardAI, hyjalAI, and boss_ambassador_hellmaw.

Definition at line 43 of file ScriptedEscortAI.cpp.

44{
45 if (!who)
46 return;
47
49 return;
50
52}
virtual void MoveInLineOfSight(Unit *)
Definition: CreatureAI.cpp:122
bool AssistPlayerInCombatAgainst(Unit *who)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MovementInform()

void EscortAI::MovementInform ( uint32  type,
uint32  id 
)
overridevirtual

Reimplemented from CreatureAI.

Definition at line 118 of file ScriptedEscortAI.cpp.

119{
120 // no action allowed if there is no escort
122 return;
123
124 if (type == POINT_MOTION_TYPE)
125 {
126 if (_pauseTimer == 0s)
127 _pauseTimer = 2s;
128
129 // continue waypoint movement
130 if (id == POINT_LAST_POINT)
131 {
132 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::MovementInform: returned to before combat position ({})", me->GetGUID().ToString());
133 me->SetWalk(false);
135 }
136 else if (id == POINT_HOME)
137 {
138 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::MovementInform: returned to home location and restarting waypoint path ({})", me->GetGUID().ToString());
139 _started = false;
140 }
141 }
142 else if (type == WAYPOINT_MOTION_TYPE)
143 {
144 ASSERT(id < _path.Nodes.size(), "EscortAI::MovementInform: referenced movement id (%u) points to non-existing node in loaded path (%s)", id, me->GetGUID().ToString().c_str());
146
147 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::MovementInform: waypoint node {} reached ({})", waypoint.Id, me->GetGUID().ToString());
148
149 // last point
150 if (id == _path.Nodes.size() - 1)
151 {
152 _started = false;
153 _ended = true;
154 _pauseTimer = 1s;
155 }
156 }
157}
#define ASSERT
Definition: Errors.h:68
@ WAYPOINT_MOTION_TYPE
@ POINT_MOTION_TYPE
@ POINT_HOME
@ POINT_LAST_POINT
bool SetWalk(bool enable)
Definition: Unit.cpp:12620
void RemoveEscortState(uint32 escortState)
+ Here is the call graph for this function:

◆ RemoveEscortState()

void EscortAI::RemoveEscortState ( uint32  escortState)
inlineprivate

Definition at line 77 of file ScriptedEscortAI.h.

77{ _escortState &= ~escortState; }
+ Here is the caller graph for this function:

◆ ResetPath()

void EscortAI::ResetPath ( )

Definition at line 269 of file ScriptedEscortAI.cpp.

270{
271 _path.Nodes.clear();
272}

◆ ReturnToLastPoint()

void EscortAI::ReturnToLastPoint ( )

Definition at line 89 of file ScriptedEscortAI.cpp.

90{
92}
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:335
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< float > closeEnoughDistance={})
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetActiveAttacker()

void EscortAI::SetActiveAttacker ( bool  enable)
inline

Definition at line 66 of file ScriptedEscortAI.h.

66{ _activeAttacker = enable; }

◆ SetDespawnAtEnd()

void EscortAI::SetDespawnAtEnd ( bool  despawn)
inline

Definition at line 63 of file ScriptedEscortAI.h.

63{ _despawnAtEnd = despawn; }
+ Here is the caller graph for this function:

◆ SetDespawnAtFar()

void EscortAI::SetDespawnAtFar ( bool  despawn)
inline

Definition at line 64 of file ScriptedEscortAI.h.

64{ _despawnAtFar = despawn; }
+ Here is the caller graph for this function:

◆ SetEscortPaused()

void EscortAI::SetEscortPaused ( bool  on)

Definition at line 348 of file ScriptedEscortAI.cpp.

349{
351 return;
352
353 if (on)
354 {
357 movementGenerator->Pause(0);
358 }
359 else
360 {
362 _resume = true;
363 }
364}
@ MOTION_SLOT_DEFAULT
@ STATE_ESCORT_PAUSED
MovementGenerator * GetCurrentMovementGenerator() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetMaxPlayerDistance()

void EscortAI::SetMaxPlayerDistance ( float  newMax)
inline

Definition at line 61 of file ScriptedEscortAI.h.

61{ _maxPlayerDistance = newMax; }
+ Here is the caller graph for this function:

◆ SetPauseTimer()

void EscortAI::SetPauseTimer ( Milliseconds  timer)
inline

Definition at line 58 of file ScriptedEscortAI.h.

58{ _pauseTimer = timer; }

◆ Start()

void EscortAI::Start ( bool  isActiveAttacker = true,
ObjectGuid  playerGUID = ObjectGuid::Empty,
Quest const *  quest = nullptr,
bool  instantRespawn = false,
bool  canLoopPath = false 
)
Todo:
get rid of this many variables passed in function.

Definition at line 286 of file ScriptedEscortAI.cpp.

287{
288 if (_path.Nodes.empty())
289 {
290 TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) path is empty ({})", me->GetScriptName(), me->GetGUID().ToString());
291 return;
292 }
293
294 // Queue respawn from the point it starts
295 if (CreatureData const* cdata = me->GetCreatureData())
296 {
297 if (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (cdata->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC))
299 }
300
301 if (me->IsEngaged())
302 {
303 TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) attempts to Start while in combat ({})", me->GetScriptName(), me->GetGUID().ToString());
304 return;
305 }
306
308 {
309 TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) attempts to Start while already escorting ({})", me->GetScriptName(), me->GetGUID().ToString());
310 return;
311 }
312
313 if (_path.Nodes.empty())
314 {
315 TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn ({})", me->GetScriptName(), me->GetGUID().ToString());
316 return;
317 }
318
319 // set variables
320 _activeAttacker = isActiveAttacker;
321 _playerGUID = playerGUID;
322 _escortQuest = quest;
323 _instantRespawn = instantRespawn;
324 _returnToStart = canLoopPath;
325
327 TC_LOG_ERROR("scripts.ai.escortai", "EscortAI::Start: (script: {}) is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn ({})", me->GetScriptName(), me->GetGUID().ToString());
328
331
332 // disable npcflags
335 if (me->IsImmuneToNPC())
336 {
338 me->SetImmuneToNPC(false);
339 }
340
341 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::Start: (script: {}) started with {} waypoints. ActiveAttacker = {}, Player = {} ({})",
343
344 _started = false;
346}
uint32_t uint32
Definition: Define.h:143
@ MOTION_PRIORITY_NORMAL
@ SPAWNGROUP_FLAG_ESCORTQUESTNPC
Definition: SpawnData.h:58
@ UNIT_NPC_FLAG_NONE
Definition: UnitDefines.h:296
@ UNIT_NPC_FLAG_2_NONE
Definition: UnitDefines.h:336
bool IsEngaged() const override
Definition: Creature.cpp:3570
bool IsImmuneToNPC() const
Definition: Unit.h:1028
CreatureData const * GetCreatureData() const
Definition: Creature.h:221
uint32 GetRespawnDelay() const
Definition: Creature.h:304
void SaveRespawnTime(uint32 forceDelay=0)
Definition: Creature.cpp:2673
void ReplaceAllNpcFlags2(NPCFlags2 flags)
Definition: Unit.h:985
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:979
#define sWorld
Definition: World.h:931
@ CONFIG_RESPAWN_DYNAMIC_ESCORTNPC
Definition: World.h:195
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateAI()

void EscortAI::UpdateAI ( uint32  diff)
overridevirtual

Reimplemented from ScriptedAI.

Reimplemented in npc_grimstone::npc_grimstoneAI, npc_rocknot::npc_rocknotAI, npc_barnes::npc_barnesAI, npc_highlord_darion_mograine::npc_highlord_darion_mograineAI, npc_scarlet_trainee, boss_anetheron::boss_anetheronAI, boss_azgalor::boss_azgalorAI, npc_lesser_doomguard::npc_lesser_doomguardAI, boss_kazrogal::boss_kazrogalAI, boss_rage_winterchill::boss_rage_winterchillAI, npc_giant_infernal::npc_giant_infernalAI, npc_abomination::npc_abominationAI, npc_ghoul::npc_ghoulAI, npc_necromancer::npc_necromancerAI, npc_banshee::npc_bansheeAI, npc_crypt_fiend::npc_crypt_fiendAI, npc_fel_stalker::npc_fel_stalkerAI, npc_frost_wyrm::npc_frost_wyrmAI, npc_gargoyle::npc_gargoyleAI, hyjal_trashAI, hyjalAI, npc_thrall_old_hillsbrad, npc_disciple_of_naralex::npc_disciple_of_naralexAI, npc_ruul_snowhoof::npc_ruul_snowhoofAI, npc_muglash::npc_muglashAI, npc_demolitionist_legoso::npc_demolitionist_legosoAI, npc_mimirons_inferno::npc_mimirons_infernoAI, npc_icefang, npc_maghar_captive::npc_maghar_captiveAI, npc_kurenai_captive::npc_kurenai_captiveAI, npc_garments_of_quests::npc_garments_of_questsAI, npc_black_knight_skeletal_gryphon::npc_black_knight_skeletal_gryphonAI, generic_vehicleAI_toc5::generic_vehicleAI_toc5AI, and npc_earthmender_wilda::npc_earthmender_wildaAI.

Definition at line 159 of file ScriptedEscortAI.cpp.

160{
161 // Waypoint Updating
163 {
164 if (_pauseTimer.count() <= diff)
165 {
167 {
168 _pauseTimer = 0s;
169
170 if (_ended)
171 {
172 _ended = false;
174
175 if (_despawnAtEnd)
176 {
177 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::UpdateAI: reached end of waypoints, despawning at end ({})", me->GetGUID().ToString());
178 if (_returnToStart)
179 {
180 Position respawnPosition;
181 float orientation = 0.f;
182 me->GetRespawnPosition(respawnPosition.m_positionX, respawnPosition.m_positionY, respawnPosition.m_positionZ, &orientation);
183 respawnPosition.SetOrientation(orientation);
184 me->GetMotionMaster()->MovePoint(POINT_HOME, respawnPosition);
185 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::UpdateAI: returning to spawn location: {} ({})", respawnPosition.ToString(), me->GetGUID().ToString());
186 }
187 else if (_instantRespawn)
188 me->Respawn(true);
189 else
191 }
192 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::UpdateAI: reached end of waypoints ({})", me->GetGUID().ToString());
194 return;
195 }
196
197 if (!_started)
198 {
199 _started = true;
200 me->GetMotionMaster()->MovePath(_path, false);
201 }
202 else if (_resume)
203 {
204 _resume = false;
206 movementGenerator->Resume(0);
207 }
208 }
209 }
210 else
211 _pauseTimer -= Milliseconds(diff);
212 }
213
214 // Check if player or any member of his group is within range
216 {
217 if (_playerCheckTimer <= diff)
218 {
220 {
221 TC_LOG_DEBUG("scripts.ai.escortai", "EscortAI::UpdateAI: failed because player/group was to far away or not found ({})", me->GetGUID().ToString());
222
223 bool isEscort = false;
225 isEscort = (sWorld->getBoolConfig(CONFIG_RESPAWN_DYNAMIC_ESCORTNPC) && (creatureData->spawnGroupData->flags & SPAWNGROUP_FLAG_ESCORTQUESTNPC));
226
227 if (_instantRespawn)
228 {
229 if (!isEscort)
230 me->DespawnOrUnsummon(0s, 1s);
231 else
233 }
234 else
236
237 return;
238 }
239
240 _playerCheckTimer = 1000;
241 }
242 else
243 _playerCheckTimer -= diff;
244 }
245
246 UpdateEscortAI(diff);
247}
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
@ SPAWN_TYPE_CREATURE
Definition: SpawnData.h:34
void Respawn(bool force=false)
Definition: Creature.cpp:2310
void GetRespawnPosition(float &x, float &y, float &z, float *ori=nullptr, float *dist=nullptr) const
Definition: Creature.cpp:2855
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2422
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:101
void Respawn(RespawnInfo *info, CharacterDatabaseTransaction dbTrans=nullptr)
Definition: Map.cpp:2025
void MovePath(uint32 pathId, bool repeatable, Optional< Milliseconds > duration={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< std::pair< Milliseconds, Milliseconds > > waitTimeRangeAtPathEnd={}, Optional< float > wanderDistanceAtPathEnds={}, bool followPathBackwardsFromEndToStart=false, bool generatePath=true)
Map * GetMap() const
Definition: Object.h:604
ObjectData const creatureData[]
virtual void UpdateEscortAI(uint32 diff)
bool IsPlayerOrGroupInRange()
float m_positionZ
Definition: Position.h:55
std::string ToString() const
Definition: Position.cpp:128
float m_positionX
Definition: Position.h:53
float m_positionY
Definition: Position.h:54
void SetOrientation(float orientation)
Definition: Position.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateEscortAI()

void EscortAI::UpdateEscortAI ( uint32  diff)
virtual

Reimplemented in npc_magwin::npc_magwinAI, npc_wizzlecrank_shredder::npc_wizzlecrank_shredderAI, npc_ranshalla::npc_ranshallaAI, npc_crok_scourgebane, violet_hold_trashAI, boss_ambassador_hellmaw, npc_blastmaster_emi_shortfuse::npc_blastmaster_emi_shortfuseAI, and npc_brann_hos.

Definition at line 249 of file ScriptedEscortAI.cpp.

250{
251 UpdateVictim();
252}
bool UpdateVictim()
Definition: CreatureAI.cpp:245
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _activeAttacker

bool EscortAI::_activeAttacker
private

Definition at line 89 of file ScriptedEscortAI.h.

◆ _despawnAtEnd

bool EscortAI::_despawnAtEnd
private

Definition at line 92 of file ScriptedEscortAI.h.

◆ _despawnAtFar

bool EscortAI::_despawnAtFar
private

Definition at line 93 of file ScriptedEscortAI.h.

◆ _ended

bool EscortAI::_ended
private

Definition at line 96 of file ScriptedEscortAI.h.

◆ _escortQuest

Quest const* EscortAI::_escortQuest
private

Definition at line 85 of file ScriptedEscortAI.h.

◆ _escortState

uint32 EscortAI::_escortState
private

Definition at line 82 of file ScriptedEscortAI.h.

◆ _hasImmuneToNPCFlags

bool EscortAI::_hasImmuneToNPCFlags
private

Definition at line 94 of file ScriptedEscortAI.h.

◆ _instantRespawn

bool EscortAI::_instantRespawn
private

Definition at line 90 of file ScriptedEscortAI.h.

◆ _maxPlayerDistance

float EscortAI::_maxPlayerDistance
private

Definition at line 83 of file ScriptedEscortAI.h.

◆ _path

WaypointPath EscortAI::_path
private

Definition at line 87 of file ScriptedEscortAI.h.

◆ _pauseTimer

Milliseconds EscortAI::_pauseTimer
private

Definition at line 80 of file ScriptedEscortAI.h.

◆ _playerCheckTimer

uint32 EscortAI::_playerCheckTimer
private

Definition at line 81 of file ScriptedEscortAI.h.

◆ _playerGUID

ObjectGuid EscortAI::_playerGUID
private

Definition at line 79 of file ScriptedEscortAI.h.

◆ _resume

bool EscortAI::_resume
private

Definition at line 97 of file ScriptedEscortAI.h.

◆ _returnToStart

bool EscortAI::_returnToStart
private

Definition at line 91 of file ScriptedEscortAI.h.

◆ _started

bool EscortAI::_started
private

Definition at line 95 of file ScriptedEscortAI.h.


The documentation for this struct was generated from the following files: