AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
FollowerAI Class Reference

#include "ScriptedFollowerAI.h"

Inheritance diagram for FollowerAI:
ScriptedAI CreatureAI UnitAI npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI npc_kerlonian::npc_kerlonianAI npc_rabid_thistle_bear::npc_rabid_thistle_bearAI npc_ringo::npc_ringoAI npc_tooga::npc_toogaAI

Public Member Functions

 FollowerAI (Creature *creature)
 
 ~FollowerAI () override
 
void MovementInform (uint32 motionType, uint32 pointId) override
 
void AttackStart (Unit *) override
 
void MoveInLineOfSight (Unit *) override
 
void EnterEvadeMode (EvadeReason=EVADE_REASON_OTHER) override
 
void JustDied (Unit *) override
 
void JustRespawned () override
 
void UpdateAI (uint32) override
 
virtual void UpdateFollowerAI (uint32)
 
void StartFollow (Player *player, uint32 factionForFollower=0, const Quest *quest=nullptr)
 
void SetFollowPaused (bool bPaused)
 
void SetFollowComplete (bool bWithEndEvent=false)
 
bool HasFollowState (uint32 uiFollowState)
 
- Public Member Functions inherited from ScriptedAI
 ScriptedAI (Creature *creature)
 
 ~ScriptedAI () override
 
void AttackStartNoMove (Unit *target)
 
void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask) override
 
void UpdateAI (uint32 diff) override
 
void JustDied (Unit *) override
 
void KilledUnit (Unit *) override
 
void JustSummoned (Creature *) override
 
void SummonedCreatureDespawn (Creature *) override
 
void SpellHit (Unit *, SpellInfo const *) override
 
void SpellHitTarget (Unit *, SpellInfo const *) override
 
void MovementInform (uint32, uint32) override
 
void OnPossess (bool)
 
bool IsInRoom (const Position *pos, Axis axis, bool above)
 
void Reset () override
 
void JustEngagedWith (Unit *) override
 Called for reaction when initially engaged.
 
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 DoPlayMusic (uint32 soundId, bool zone)
 
void DoAddThreat (Unit *unit, float amount)
 
void DoModifyThreatByPercent (Unit *unit, int32 pct)
 
void DoResetThreat (Unit *unit)
 
void DoResetThreatList ()
 
float DoGetThreat (Unit *unit)
 
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)
 
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, uint32 despawntime)
 
bool HealthBelowPct (uint32 pct) const
 
bool HealthAbovePct (uint32 pct) const
 
SpellInfo const * SelectSpell (Unit *target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, 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
 
virtual bool CheckEvadeIfOutOfCombatArea () const
 
bool IsHeroic () const
 
Difficulty GetDifficulty () const
 
bool Is25ManRaid () const
 
template<class T >
const T & DUNGEON_MODE (const T &normal5, const T &heroic10) const
 
template<class T >
const T & RAID_MODE (const T &normal10, const T &normal25) const
 
template<class T >
const T & RAID_MODE (const T &normal10, const T &normal25, const T &heroic10, const T &heroic25) const
 
PlayerSelectTargetFromPlayerList (float maxdist, uint32 excludeAura=0, bool mustBeInLOS=false) const
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr, Milliseconds delay=0s)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table.
 
void Talk (uint8 id, Milliseconds delay)
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual bool CanRespawn ()
 
virtual void EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
virtual void JustEngagedWith (Unit *)
 Called for reaction when initially engaged.
 
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 SummonedCreatureDespawnAll ()
 
virtual void SpellHit (Unit *, SpellInfo const *)
 
virtual void SpellHitTarget (Unit *, SpellInfo const *)
 
virtual void AttackedBy (Unit *)
 
virtual bool IsEscorted ()
 
virtual void JustRespawned ()
 
virtual void MovementInform (uint32, uint32)
 
virtual void PathEndReached (uint32)
 
void OnCharmed (bool apply) override
 
virtual void JustReachedHome ()
 
void DoZoneInCombat (Creature *creature=nullptr, float maxRangeToNearestTarget=250.0f)
 
virtual void ReceiveEmote (Player *, uint32)
 
virtual void OwnerAttackedBy (Unit *)
 
virtual void OwnerAttacked (Unit *)
 
virtual void CorpseRemoved (uint32 &)
 == Triggered Actions Requested ==================
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields =======================================
 
virtual bool BeforeSpellClick (Unit *)
 
virtual void OnSpellClick (Unit *, bool &)
 
virtual bool CanSeeAlways (WorldObject const *)
 
virtual bool CanBeSeen (Player const *)
 
virtual bool CanAlwaysBeDetectable (WorldObject const *)
 
virtual void PetStopAttack ()
 
virtual bool CheckInRoom ()
 
CreatureBoundary const * GetBoundary () const
 
void SetBoundary (CreatureBoundary const *boundary, bool negativeBoundaries=false)
 
bool IsInBoundary (Position const *who=nullptr) const
 
virtual void CalculateThreat (Unit *, float &, SpellInfo const *)
 
virtual bool OnTeleportUnreacheablePlayer (Player *)
 
- 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)=0
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool apply)=0
 
virtual void DoAction (int32)
 
virtual uint32 GetData (uint32) const
 
virtual void SetData (uint32, uint32)
 
virtual void SetGUID (ObjectGuid, int32=0)
 
virtual ObjectGuid GetGUID (int32=0) const
 
UnitSelectTarget (SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position=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 position, PREDICATE const &predicate)
 
virtual void JustEnteredCombat (Unit *)
 Called when the unit enters combat (NOTE: Creature engage logic should NOT be here, but in JustEngagedWith, which happens once threat is established!)
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat.
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 
virtual void HealReceived (Unit *, uint32 &)
 
virtual void HealDone (Unit *, uint32 &)
 
void AttackStartCaster (Unit *victim, float dist)
 
SpellCastResult DoAddAuraToAllHostilePlayers (uint32 spellid)
 
SpellCastResult DoCast (uint32 spellId)
 
SpellCastResult DoCast (Unit *victim, uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastSelf (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastToAllHostilePlayers (uint32 spellid, bool triggered=false)
 
SpellCastResult DoCastVictim (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastAOE (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastRandomTarget (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the max threat target, which may not always be the current victim.
 
float DoGetSpellMaxRange (uint32 spellId, bool positive=false)
 
void DoMeleeAttackIfReady ()
 
bool DoSpellAttackIfReady (uint32 spell)
 
void DoSpellAttackToRandomTargetIfReady (uint32 spell, uint32 threatTablePosition=0, float dist=0.f, bool playerOnly=true)
 
virtual void SummonMovementInform (Creature *, uint32, uint32)
 
virtual void sGossipHello (Player *)
 
virtual void sGossipSelect (Player *, uint32, uint32)
 
virtual void sGossipSelectCode (Player *, uint32, uint32, char const *)
 
virtual void sQuestAccept (Player *, Quest const *)
 
virtual void sQuestSelect (Player *, Quest const *)
 
virtual void sQuestComplete (Player *, Quest const *)
 
virtual void sQuestReward (Player *, Quest const *, uint32)
 
virtual void sOnGameEvent (bool, uint16)
 
virtual std::string GetDebugInfo () const
 

Protected Member Functions

PlayerGetLeaderForFollower ()
 
- Protected Member Functions inherited from CreatureAI
bool UpdateVictim ()
 
bool UpdateVictimWithGaze ()
 
void SetGazeOn (Unit *target)
 
CreatureDoSummon (uint32 entry, Position const &pos, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummon (uint32 entry, WorldObject *obj, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummonFlyer (uint32 entry, WorldObject *obj, float flightZ, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
virtual void MoveInLineOfSight (Unit *)
 
bool _EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 

Private Member Functions

void AddFollowState (uint32 uiFollowState)
 
void RemoveFollowState (uint32 uiFollowState)
 
bool AssistPlayerInCombatAgainst (Unit *who)
 

Private Attributes

ObjectGuid m_uiLeaderGUID
 
uint32 m_uiUpdateFollowTimer
 
uint32 m_uiFollowState
 
const Questm_pQuestForFollow
 

Additional Inherited Members

- Public Types inherited from ScriptedAI
enum class  Axis {
  AXIS_X ,
  AXIS_Y
}
 
- Public Types inherited from CreatureAI
enum  EvadeReason {
  EVADE_REASON_NO_HOSTILES ,
  EVADE_REASON_BOUNDARY ,
  EVADE_REASON_SEQUENCE_BREAK ,
  EVADE_REASON_NO_PATH ,
  EVADE_REASON_OTHER
}
 
- Static Public Member Functions inherited from CreatureAI
static bool IsInBounds (CreatureBoundary const &boundary, Position const *who)
 
- Static Public Member Functions inherited from UnitAI
static void FillAISpellInfo ()
 
- Public Attributes inherited from ScriptedAI
Creatureme
 
bool IsFleeing
 
- Static Public Attributes inherited from UnitAI
static AISpellInfoTypeAISpellInfo
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
EventMap events
 
CreatureBoundary const * _boundary
 
bool _negateBoundary
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Detailed Description

Constructor & Destructor Documentation

◆ FollowerAI()

FollowerAI::FollowerAI ( Creature creature)
explicit
37 : ScriptedAI(creature),
40 m_pQuestForFollow(nullptr)
41{}
@ STATE_FOLLOW_NONE
Definition: ScriptedFollowerAI.h:26
Definition: ScriptedCreature.h:192
uint32 m_uiUpdateFollowTimer
Definition: ScriptedFollowerAI.h:75
const Quest * m_pQuestForFollow
Definition: ScriptedFollowerAI.h:78
uint32 m_uiFollowState
Definition: ScriptedFollowerAI.h:76

◆ ~FollowerAI()

FollowerAI::~FollowerAI ( )
inlineoverride
39{ }

Member Function Documentation

◆ AddFollowState()

void FollowerAI::AddFollowState ( uint32  uiFollowState)
inlineprivate
69{ m_uiFollowState |= uiFollowState; }

References m_uiFollowState.

Referenced by MovementInform(), SetFollowComplete(), SetFollowPaused(), and StartFollow().

◆ AssistPlayerInCombatAgainst()

bool FollowerAI::AssistPlayerInCombatAgainst ( Unit who)
private
67{
68 if (!who || !who->GetVictim())
69 return false;
70
71 //experimental (unknown) flag not present
73 return false;
74
75 //not a player
77 return false;
78
79 //never attack friendly
80 if (me->IsFriendlyTo(who))
81 return false;
82
83 //too far away and no free sight?
85 {
86 AttackStart(who);
87 return true;
88 }
89
90 return false;
91}
const float MAX_PLAYER_DISTANCE
Definition: ScriptedFollowerAI.cpp:30
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition: SharedDefines.h:2679
Creature * me
Definition: ScriptedCreature.h:282
void AttackStart(Unit *) override
Definition: ScriptedFollowerAI.cpp:43
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:197
uint32 type_flags
Definition: CreatureData.h:216
bool IsWithinLOSInMap(WorldObject const *obj, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS, Optional< float > collisionHeight={ }, Optional< float > combatReach={ }) const
Definition: Object.cpp:1347
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool useBoundingRadius=true) const
Definition: Object.cpp:1321
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition: Unit.cpp:10576
Unit * GetVictim() const
Definition: Unit.h:1386
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:10214

References AttackStart(), CREATURE_TYPE_FLAG_CAN_ASSIST, Unit::GetCharmerOrOwnerPlayerOrPlayerItself(), Creature::GetCreatureTemplate(), Unit::GetVictim(), Unit::IsFriendlyTo(), WorldObject::IsWithinDistInMap(), WorldObject::IsWithinLOSInMap(), MAX_PLAYER_DISTANCE, ScriptedAI::me, and CreatureTemplate::type_flags.

Referenced by MoveInLineOfSight().

◆ AttackStart()

void FollowerAI::AttackStart ( Unit who)
overridevirtual

Reimplemented from ScriptedAI.

44{
45 if (!who)
46 return;
47
48 if (me->Attack(who, true))
49 {
50 // This is done in Unit::Attack function which wont bug npcs by not adding threat upon combat start...
51 //me->AddThreat(who, 0.0f);
52 //me->SetInCombatWith(who);
53 //who->SetInCombatWith(me);
54
57
60 }
61}
@ UNIT_STATE_FOLLOW
Definition: Unit.h:334
bool IsCombatMovementAllowed() const
Definition: ScriptedCreature.h:370
void ClearUnitState(uint32 f)
Definition: Unit.h:1399
MotionMaster * GetMotionMaster()
Definition: Unit.h:2262
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:10245
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1398
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Definition: MotionMaster.cpp:299

References Unit::Attack(), Unit::ClearUnitState(), Unit::GetMotionMaster(), Unit::HasUnitState(), ScriptedAI::IsCombatMovementAllowed(), ScriptedAI::me, MotionMaster::MoveChase(), and UNIT_STATE_FOLLOW.

Referenced by AssistPlayerInCombatAgainst(), and MoveInLineOfSight().

◆ EnterEvadeMode()

void FollowerAI::EnterEvadeMode ( EvadeReason  = EVADE_REASON_OTHER)
overridevirtual

Reimplemented from CreatureAI.

154{
157 me->CombatStop(true);
158 me->SetLootRecipient(nullptr);
159
161 {
162 LOG_DEBUG("scripts.ai", "FollowerAI left combat, returning to CombatStartPosition.");
163
165 {
166 float fPosX, fPosY, fPosZ;
167 me->GetPosition(fPosX, fPosY, fPosZ);
168 me->GetMotionMaster()->MovePoint(POINT_COMBAT_START, fPosX, fPosY, fPosZ);
169 }
170 }
171 else
172 {
175 }
176
177 Reset();
178}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
@ POINT_COMBAT_START
Definition: ScriptedFollowerAI.cpp:34
@ STATE_FOLLOW_INPROGRESS
Definition: ScriptedFollowerAI.h:27
@ CHASE_MOTION_TYPE
Definition: MotionMaster.h:43
void Reset() override
Definition: ScriptedCreature.h:292
bool HasFollowState(uint32 uiFollowState)
Definition: ScriptedFollowerAI.h:63
void ClearAllThreat()
Definition: ThreatMgr.cpp:418
void SetLootRecipient(Unit *unit, bool withGroup=true)
Definition: Creature.cpp:1292
void GetPosition(float &x, float &y) const
Definition: Position.h:122
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10401
void RemoveAllAuras()
Definition: Unit.cpp:5239
ThreatMgr & GetThreatMgr()
Definition: Unit.h:2145
void MoveTargetedHome(bool walk=false)
Definition: MotionMaster.cpp:251
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:817
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition: MotionMaster.h:210

References CHASE_MOTION_TYPE, ThreatMgr::ClearAllThreat(), Unit::CombatStop(), MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), Position::GetPosition(), Unit::GetThreatMgr(), HasFollowState(), LOG_DEBUG, ScriptedAI::me, MotionMaster::MovePoint(), MotionMaster::MoveTargetedHome(), POINT_COMBAT_START, Unit::RemoveAllAuras(), ScriptedAI::Reset(), Creature::SetLootRecipient(), and STATE_FOLLOW_INPROGRESS.

◆ GetLeaderForFollower()

Player * FollowerAI::GetLeaderForFollower ( )
protected
306{
308 {
309 if (player->IsAlive())
310 return player;
311 else
312 {
313 if (Group* group = player->GetGroup())
314 {
315 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
316 {
317 Player* member = groupRef->GetSource();
318
319 if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE) && member->IsAlive())
320 {
321 LOG_DEBUG("scripts.ai", "FollowerAI GetLeader changed and returned new leader.");
322 m_uiLeaderGUID = member->GetGUID();
323 return member;
324 }
325 }
326 }
327 }
328 }
329
330 LOG_DEBUG("scripts.ai", "FollowerAI GetLeader can not find suitable leader.");
331 return nullptr;
332}
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:225
ObjectGuid m_uiLeaderGUID
Definition: ScriptedFollowerAI.h:74
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
Definition: Player.h:1046
bool IsAlive() const
Definition: Unit.h:1808
Definition: Group.h:168
Definition: GroupReference.h:27
GroupReference * next()
Definition: GroupReference.h:36

References Object::GetGUID(), ObjectAccessor::GetPlayer(), Unit::IsAlive(), WorldObject::IsWithinDistInMap(), LOG_DEBUG, m_uiLeaderGUID, MAX_PLAYER_DISTANCE, ScriptedAI::me, and GroupReference::next().

Referenced by JustDied(), npc_kerlonian::npc_kerlonianAI::MoveInLineOfSight(), npc_tooga::npc_toogaAI::MoveInLineOfSight(), npc_ringo::npc_ringoAI::MoveInLineOfSight(), MovementInform(), SetFollowPaused(), and UpdateAI().

◆ HasFollowState()

◆ JustDied()

void FollowerAI::JustDied ( Unit )
overridevirtual

Reimplemented from ScriptedAI.

114{
116 return;
117
118 //TODO: need a better check for quests with time limit.
119 if (Player* player = GetLeaderForFollower())
120 {
121 if (Group* group = player->GetGroup())
122 {
123 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
124 {
125 if (Player* member = groupRef->GetSource())
126 {
127 if (member->IsInMap(player) && member->GetQuestStatus(m_pQuestForFollow->GetQuestId()) == QUEST_STATUS_INCOMPLETE)
128 member->FailQuest(m_pQuestForFollow->GetQuestId());
129 }
130 }
131 }
132 else
133 {
134 if (player->GetQuestStatus(m_pQuestForFollow->GetQuestId()) == QUEST_STATUS_INCOMPLETE)
135 player->FailQuest(m_pQuestForFollow->GetQuestId());
136 }
137 }
138}
@ QUEST_STATUS_INCOMPLETE
Definition: QuestDef.h:103
Player * GetLeaderForFollower()
Definition: ScriptedFollowerAI.cpp:305
uint32 GetQuestId() const
Definition: QuestDef.h:225

References GetLeaderForFollower(), Quest::GetQuestId(), HasFollowState(), m_pQuestForFollow, m_uiLeaderGUID, GroupReference::next(), QUEST_STATUS_INCOMPLETE, and STATE_FOLLOW_INPROGRESS.

◆ JustRespawned()

void FollowerAI::JustRespawned ( )
overridevirtual

Reimplemented from CreatureAI.

141{
143
145 SetCombatMovement(true);
146
149
150 Reset();
151}
void SetCombatMovement(bool allowMovement)
Definition: ScriptedCreature.cpp:513
uint32 faction
Definition: CreatureData.h:191
void SetFaction(uint32 faction)
Definition: Unit.cpp:10029
uint32 GetFaction() const
Definition: Unit.h:1495

References CreatureTemplate::faction, Creature::GetCreatureTemplate(), Unit::GetFaction(), ScriptedAI::IsCombatMovementAllowed(), m_uiFollowState, ScriptedAI::me, ScriptedAI::Reset(), ScriptedAI::SetCombatMovement(), Unit::SetFaction(), and STATE_FOLLOW_NONE.

◆ MoveInLineOfSight()

void FollowerAI::MoveInLineOfSight ( Unit who)
overridevirtual

Reimplemented from CreatureAI.

Reimplemented in npc_kerlonian::npc_kerlonianAI, npc_tooga::npc_toogaAI, npc_ringo::npc_ringoAI, and npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI.

94{
95 if (me->GetVictim())
96 return;
97
100 return;
101
103 {
105 {
108 }
109 AttackStart(who);
110 }
111}
@ REACT_AGGRESSIVE
Definition: Unit.h:1025
@ UNIT_STATE_DISTRACTED
Definition: Unit.h:337
@ UNIT_STATE_STUNNED
Definition: Unit.h:328
bool AssistPlayerInCombatAgainst(Unit *who)
Definition: ScriptedFollowerAI.cpp:66
bool CanStartAttack(Unit const *u) const
Definition: Creature.cpp:1887
bool HasReactState(ReactStates state) const
Definition: Creature.h:91
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:4133
bool isTargetableForAttack(bool checkFakeDeath=true, Unit const *byWho=nullptr) const
Definition: Unit.cpp:13759
void Clear(bool reset=true)
Definition: MotionMaster.h:165

References AssistPlayerInCombatAgainst(), AttackStart(), Creature::CanStartAttack(), MotionMaster::Clear(), Unit::ClearUnitState(), Unit::GetMotionMaster(), Unit::GetVictim(), HasFollowState(), Creature::HasReactState(), Unit::HasUnitState(), Unit::isInAccessiblePlaceFor(), Unit::isTargetableForAttack(), ScriptedAI::me, REACT_AGGRESSIVE, STATE_FOLLOW_INPROGRESS, UNIT_STATE_DISTRACTED, and UNIT_STATE_STUNNED.

Referenced by npc_kerlonian::npc_kerlonianAI::MoveInLineOfSight(), npc_tooga::npc_toogaAI::MoveInLineOfSight(), npc_ringo::npc_ringoAI::MoveInLineOfSight(), and npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI::MoveInLineOfSight().

◆ MovementInform()

void FollowerAI::MovementInform ( uint32  motionType,
uint32  pointId 
)
overridevirtual

Reimplemented from ScriptedAI.

Reimplemented in npc_tooga::npc_toogaAI.

251{
253 return;
254
255 if (pointId == POINT_COMBAT_START)
256 {
258 {
261 }
262 else
264 }
265}
@ STATE_FOLLOW_PAUSED
Definition: ScriptedFollowerAI.h:29
@ STATE_FOLLOW_RETURNING
Definition: ScriptedFollowerAI.h:28
@ POINT_MOTION_TYPE
Definition: MotionMaster.h:46
void AddFollowState(uint32 uiFollowState)
Definition: ScriptedFollowerAI.h:69
void DespawnOrUnsummon(Milliseconds msTimeToDespawn, Seconds forcedRespawnTimer)
Definition: Creature.cpp:2108

References AddFollowState(), Creature::DespawnOrUnsummon(), GetLeaderForFollower(), HasFollowState(), ScriptedAI::me, POINT_COMBAT_START, POINT_MOTION_TYPE, STATE_FOLLOW_INPROGRESS, STATE_FOLLOW_PAUSED, and STATE_FOLLOW_RETURNING.

Referenced by npc_tooga::npc_toogaAI::MovementInform().

◆ RemoveFollowState()

void FollowerAI::RemoveFollowState ( uint32  uiFollowState)
inlineprivate
70{ m_uiFollowState &= ~uiFollowState; }

References m_uiFollowState.

Referenced by SetFollowComplete(), SetFollowPaused(), and UpdateAI().

◆ SetFollowComplete()

void FollowerAI::SetFollowComplete ( bool  bWithEndEvent = false)
335{
337 {
339
340 me->StopMoving();
343 }
344
345 if (bWithEndEvent)
347 else
348 {
351 }
352
354}
@ STATE_FOLLOW_COMPLETE
Definition: ScriptedFollowerAI.h:30
@ STATE_FOLLOW_POSTEVENT
Definition: ScriptedFollowerAI.h:32
void RemoveFollowState(uint32 uiFollowState)
Definition: ScriptedFollowerAI.h:70
void StopMoving()
Definition: Unit.cpp:16824
void MoveIdle()
Definition: MotionMaster.cpp:231

References AddFollowState(), MotionMaster::Clear(), Unit::ClearUnitState(), Unit::GetMotionMaster(), HasFollowState(), Unit::HasUnitState(), ScriptedAI::me, MotionMaster::MoveIdle(), RemoveFollowState(), STATE_FOLLOW_COMPLETE, STATE_FOLLOW_POSTEVENT, Unit::StopMoving(), and UNIT_STATE_FOLLOW.

Referenced by npc_kerlonian::npc_kerlonianAI::MoveInLineOfSight(), npc_tooga::npc_toogaAI::MoveInLineOfSight(), npc_ringo::npc_ringoAI::MoveInLineOfSight(), npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI::MoveInLineOfSight(), npc_tooga::npc_toogaAI::MovementInform(), npc_tooga::npc_toogaAI::UpdateFollowerAI(), and npc_ringo::npc_ringoAI::UpdateFollowerAI().

◆ SetFollowPaused()

void FollowerAI::SetFollowPaused ( bool  bPaused)

◆ StartFollow()

void FollowerAI::StartFollow ( Player player,
uint32  factionForFollower = 0,
const Quest quest = nullptr 
)
268{
269 if (me->GetVictim())
270 {
271 LOG_DEBUG("scripts.ai", "FollowerAI attempt to StartFollow while in combat.");
272 return;
273 }
274
276 {
277 LOG_ERROR("entities.unit.ai", "FollowerAI attempt to StartFollow while already following.");
278 return;
279 }
280
281 //set variables
282 m_uiLeaderGUID = player->GetGUID();
283
284 if (factionForFollower)
285 me->SetFaction(factionForFollower);
286
287 m_pQuestForFollow = quest;
288
290 {
293 LOG_DEBUG("scripts.ai", "FollowerAI start with WAYPOINT_MOTION_TYPE, set to MoveIdle.");
294 }
295
297
299
301
302 LOG_DEBUG("scripts.ai", "FollowerAI start follow {} ({})", player->GetName(), m_uiLeaderGUID.ToString());
303}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
@ UNIT_NPC_FLAG_NONE
Definition: Unit.h:515
@ WAYPOINT_MOTION_TYPE
Definition: MotionMaster.h:39
std::string const & GetName() const
Definition: Object.h:446
std::string ToString() const
Definition: ObjectGuid.cpp:47
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:1649

References AddFollowState(), MotionMaster::Clear(), MotionMaster::GetCurrentMovementGeneratorType(), Object::GetGUID(), Unit::GetMotionMaster(), WorldObject::GetName(), Unit::GetVictim(), HasFollowState(), LOG_DEBUG, LOG_ERROR, m_pQuestForFollow, m_uiLeaderGUID, ScriptedAI::me, MotionMaster::MoveFollow(), MotionMaster::MoveIdle(), PET_FOLLOW_ANGLE, PET_FOLLOW_DIST, Unit::ReplaceAllNpcFlags(), Unit::SetFaction(), STATE_FOLLOW_INPROGRESS, ObjectGuid::ToString(), UNIT_NPC_FLAG_NONE, and WAYPOINT_MOTION_TYPE.

Referenced by npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI::UpdateAI().

◆ UpdateAI()

void FollowerAI::UpdateAI ( uint32  uiDiff)
overridevirtual

Reimplemented from ScriptedAI.

Reimplemented in npc_rabid_thistle_bear::npc_rabid_thistle_bearAI, and npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI.

181{
183 {
184 if (m_uiUpdateFollowTimer <= uiDiff)
185 {
187 {
188 LOG_DEBUG("scripts.ai", "FollowerAI is set completed, despawns.");
190 return;
191 }
192
193 bool bIsMaxRangeExceeded = true;
194
195 if (Player* player = GetLeaderForFollower())
196 {
198 {
199 LOG_DEBUG("scripts.ai", "FollowerAI is returning to leader.");
200
203 return;
204 }
205
206 if (Group* group = player->GetGroup())
207 {
208 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
209 {
210 Player* member = groupRef->GetSource();
211
212 if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE, true, false))
213 {
214 bIsMaxRangeExceeded = false;
215 break;
216 }
217 }
218 }
219 else
220 {
221 if (me->IsWithinDistInMap(player, MAX_PLAYER_DISTANCE, true, false))
222 bIsMaxRangeExceeded = false;
223 }
224 }
225
226 if (bIsMaxRangeExceeded)
227 {
228 LOG_DEBUG("scripts.ai", "FollowerAI failed because player/group was to far away or not found");
230 return;
231 }
232
234 }
235 else
236 m_uiUpdateFollowTimer -= uiDiff;
237 }
238
239 UpdateFollowerAI(uiDiff);
240}
virtual void UpdateFollowerAI(uint32)
Definition: ScriptedFollowerAI.cpp:242

References Creature::DespawnOrUnsummon(), GetLeaderForFollower(), Unit::GetMotionMaster(), Unit::GetVictim(), HasFollowState(), WorldObject::IsWithinDistInMap(), LOG_DEBUG, m_uiUpdateFollowTimer, MAX_PLAYER_DISTANCE, ScriptedAI::me, MotionMaster::MoveFollow(), GroupReference::next(), PET_FOLLOW_ANGLE, PET_FOLLOW_DIST, RemoveFollowState(), STATE_FOLLOW_COMPLETE, STATE_FOLLOW_INPROGRESS, STATE_FOLLOW_POSTEVENT, STATE_FOLLOW_RETURNING, and UpdateFollowerAI().

◆ UpdateFollowerAI()

void FollowerAI::UpdateFollowerAI ( uint32  )
virtual

Reimplemented in npc_kerlonian::npc_kerlonianAI, npc_tooga::npc_toogaAI, and npc_ringo::npc_ringoAI.

243{
244 if (!UpdateVictim())
245 return;
246
248}
void DoMeleeAttackIfReady()
Definition: UnitAI.cpp:40
bool UpdateVictim()
Definition: CreatureAI.cpp:269

References UnitAI::DoMeleeAttackIfReady(), and CreatureAI::UpdateVictim().

Referenced by UpdateAI().

Member Data Documentation

◆ m_pQuestForFollow

const Quest* FollowerAI::m_pQuestForFollow
private

Referenced by JustDied(), and StartFollow().

◆ m_uiFollowState

uint32 FollowerAI::m_uiFollowState
private

◆ m_uiLeaderGUID

ObjectGuid FollowerAI::m_uiLeaderGUID
private

◆ m_uiUpdateFollowTimer

uint32 FollowerAI::m_uiUpdateFollowTimer
private

Referenced by UpdateAI().