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_jenny 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
 Use to start attacking a target. Called just before JustEngagedWith()
 
virtual void UpdateFollowerAI (uint32)
 
void StartFollow (Player *player, uint32 factionForFollower=0, const Quest *quest=nullptr, bool inheritWalkState=true, bool inheritSpeed=true)
 
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
 Called at any Damage from any attacker (before damage apply)
 
void UpdateAI (uint32 diff) override
 Use to start attacking a target. Called just before JustEngagedWith()
 
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 DoTeleportPlayer (Unit *unit, Position pos)
 
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 IsUniqueTimedEventDone (uint32 id) const
 
void SetUniqueTimedEventDone (uint32 id)
 
void ResetUniqueTimedEvent (uint32 id)
 
void ClearUniqueTimedEventsDone ()
 
void ScheduleTimedEvent (Milliseconds timerMin, Milliseconds timerMax, std::function< void()> exec, Milliseconds repeatMin, Milliseconds repeatMax=0s, uint32 uniqueId=0)
 
void ScheduleTimedEvent (Milliseconds timerMax, std::function< void()> exec, Milliseconds repeatMin, Milliseconds repeatMax=0s, uint32 uniqueId=0)
 
void ScheduleUniqueTimedEvent (Milliseconds timer, std::function< void()> exec, uint32 uniqueId)
 
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)
 
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
 
void SetInvincibility (bool apply)
 
bool IsInvincible () const
 
void SetAutoAttackAllowed (bool allow)
 
bool IsAutoAttackAllowed () 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)
 
WorldObjectGetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon.
 
 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 IsSummonedBy (WorldObject *)
 
virtual void SummonedCreatureDies (Creature *, Unit *)
 
virtual void SummonedCreatureDespawnAll ()
 
virtual void SummonedCreatureEvade (Creature *)
 
virtual void AttackedBy (Unit *)
 
virtual bool IsEscorted ()
 
virtual void PathEndReached (uint32)
 
void OnCharmed (bool apply) override
 Called when unit is charmed.
 
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 ()
 
int32 VisualizeBoundary (uint32 duration, Unit *owner=nullptr, bool fill=false, bool checkZ=false) const
 
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 *)
 
virtual void OnAuraRemove (AuraApplication *, AuraRemoveMode)
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual bool CanAIAttack (Unit const *) const
 
virtual void InitializeAI ()
 
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)
 Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following:
 
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.
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat.
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 Called at any Damage to any victim (before damage apply)
 
virtual void HealReceived (Unit *, uint32 &)
 Called when the creature receives heal.
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 Called when the creature power updates.
 
virtual void HealDone (Unit *, uint32 &)
 Called when the unit heals.
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 Called during damage calculations.
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 Called during calculation when receiving periodic healing or damage (DoT or HoT)
 
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)
 To specify the caster as target if the spell is self-cast.
 
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, bool withTank=true)
 Cast the spell on a random unit from the threat list.
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the top threat target, which may not 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)
 Called when a summon reaches a waypoint or point movement finished.
 
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)
 
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
 
- Static Public Attributes inherited from UnitAI
static AISpellInfoTypeAISpellInfo
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
EventMap events
 
TaskScheduler scheduler
 
CreatureBoundary const * _boundary
 
bool _negateBoundary
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Detailed Description

Constructor & Destructor Documentation

◆ FollowerAI()

FollowerAI::FollowerAI ( Creature creature)
explicit
30 : ScriptedAI(creature),
33 m_pQuestForFollow(nullptr)
34{}
@ STATE_FOLLOW_NONE
Definition ScriptedFollowerAI.h:26
uint32 m_uiUpdateFollowTimer
Definition ScriptedFollowerAI.h:75
const Quest * m_pQuestForFollow
Definition ScriptedFollowerAI.h:78
uint32 m_uiFollowState
Definition ScriptedFollowerAI.h:76
Definition ScriptedCreature.h:190

◆ ~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
60{
61 if (!who || !who->GetVictim())
62 return false;
63
64 //experimental (unknown) flag not present
66 return false;
67
68 //not a player
70 return false;
71
72 //never attack friendly
73 if (me->IsFriendlyTo(who))
74 return false;
75
76 //too far away and no free sight?
78 {
79 AttackStart(who);
80 return true;
81 }
82
83 return false;
84}
const float MAX_PLAYER_DISTANCE
Definition ScriptedFollowerAI.cpp:23
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition SharedDefines.h:2707
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:209
void AttackStart(Unit *) override
Definition ScriptedFollowerAI.cpp:36
Player * GetCharmerOrOwnerPlayerOrPlayerItself() const
Definition Unit.cpp:10660
Unit * GetVictim() const
Definition Unit.h:846
bool IsFriendlyTo(Unit const *unit) const
Definition Unit.cpp:10281
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:1358
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool useBoundingRadius=true) const
Definition Object.cpp:1332
uint32 type_flags
Definition CreatureData.h:223
Creature * me
Definition ScriptedCreature.h:280

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 UnitAI.

37{
38 if (!who)
39 return;
40
41 if (me->Attack(who, true))
42 {
43 // This is done in Unit::Attack function which wont bug npcs by not adding threat upon combat start...
44 //me->AddThreat(who, 0.0f);
45 //me->SetInCombatWith(who);
46 //who->SetInCombatWith(me);
47
50
53 }
54}
@ UNIT_STATE_FOLLOW
Definition UnitDefines.h:179
bool IsCombatMovementAllowed() const
Definition Creature.h:433
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Force the unit to chase this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:313
void ClearUnitState(uint32 f)
Definition Unit.h:692
MotionMaster * GetMotionMaster()
Definition Unit.h:1664
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:10312
bool HasUnitState(const uint32 f) const
Definition Unit.h:691

References Unit::Attack(), Unit::ClearUnitState(), Unit::GetMotionMaster(), Unit::HasUnitState(), Creature::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.

147{
150 me->CombatStop(true);
151 me->SetLootRecipient(nullptr);
152
154 {
155 LOG_DEBUG("scripts.ai", "FollowerAI left combat, returning to CombatStartPosition.");
156
158 {
159 float fPosX, fPosY, fPosZ;
160 me->GetPosition(fPosX, fPosY, fPosZ);
161 me->GetMotionMaster()->MovePoint(POINT_COMBAT_START, fPosX, fPosY, fPosZ);
162 }
163 }
164 else
165 {
168 }
169
170 Reset();
171}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:169
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45
@ POINT_COMBAT_START
Definition ScriptedFollowerAI.cpp:27
@ STATE_FOLLOW_INPROGRESS
Definition ScriptedFollowerAI.h:27
void SetLootRecipient(Unit *unit, bool withGroup=true)
Definition Creature.cpp:1326
bool HasFollowState(uint32 uiFollowState)
Definition ScriptedFollowerAI.h:63
void MoveTargetedHome(bool walk=false)
The unit will return this initial position (owner for pets and summoned creatures)....
Definition MotionMaster.cpp:259
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:913
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition MotionMaster.h:213
void ClearAllThreat()
Definition ThreatMgr.cpp:417
void CombatStop(bool includingCast=false)
Definition Unit.cpp:10480
void RemoveAllAuras()
Definition Unit.cpp:5352
ThreatMgr & GetThreatMgr()
Definition Unit.h:896
void GetPosition(float &x, float &y) const
Definition Position.h:126
void Reset() override
Definition ScriptedCreature.h:287

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
299{
301 {
302 if (player->IsAlive())
303 return player;
304 else
305 {
306 if (Group* group = player->GetGroup())
307 {
308 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
309 {
310 Player* member = groupRef->GetSource();
311
312 if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE) && member->IsAlive())
313 {
314 LOG_DEBUG("scripts.ai", "FollowerAI GetLeader changed and returned new leader.");
315 m_uiLeaderGUID = member->GetGUID();
316 return member;
317 }
318 }
319 }
320 }
321 }
322
323 LOG_DEBUG("scripts.ai", "FollowerAI GetLeader can not find suitable leader.");
324 return nullptr;
325}
ObjectGuid m_uiLeaderGUID
Definition ScriptedFollowerAI.h:74
Definition GroupReference.h:27
Definition Group.h:169
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
Definition Player.h:1082
bool IsAlive() const
Definition Unit.h:1698
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition ObjectAccessor.cpp:220

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

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 CreatureAI.

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

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

◆ JustRespawned()

void FollowerAI::JustRespawned ( )
overridevirtual

Reimplemented from CreatureAI.

134{
136
138 me->SetCombatMovement(true);
139
142
143 Reset();
144}
void SetCombatMovement(bool allowMovement)
Definition Creature.cpp:3871
void SetFaction(uint32 faction)
Definition Unit.cpp:10096
uint32 GetFaction() const
Definition Unit.h:801
uint32 faction
Definition CreatureData.h:198

References CreatureTemplate::faction, Creature::GetCreatureTemplate(), Unit::GetFaction(), Creature::IsCombatMovementAllowed(), m_uiFollowState, ScriptedAI::me, ScriptedAI::Reset(), Creature::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, npc_jenny, and npc_captured_beryl_sorcerer::npc_captured_beryl_sorcererAI.

87{
88 if (me->GetVictim())
89 return;
90
93 return;
94
96 {
98 {
101 }
102 AttackStart(who);
103 }
104}
@ UNIT_STATE_DISTRACTED
Definition UnitDefines.h:182
@ UNIT_STATE_STUNNED
Definition UnitDefines.h:173
@ REACT_AGGRESSIVE
Definition Unit.h:551
bool CanStartAttack(Unit const *u) const
Definition Creature.cpp:1914
bool HasReactState(ReactStates state) const
Definition Creature.h:97
bool AssistPlayerInCombatAgainst(Unit *who)
Definition ScriptedFollowerAI.cpp:59
void Clear(bool reset=true)
Definition MotionMaster.h:167
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4226
bool isTargetableForAttack(bool checkFakeDeath=true, Unit const *byWho=nullptr) const
Definition Unit.cpp:13905

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 CreatureAI.

Reimplemented in npc_tooga::npc_toogaAI.

244{
246 return;
247
248 if (pointId == POINT_COMBAT_START)
249 {
251 {
254 }
255 else
257 }
258}
@ POINT_MOTION_TYPE
Definition MotionMaster.h:48
@ STATE_FOLLOW_PAUSED
Definition ScriptedFollowerAI.h:29
@ STATE_FOLLOW_RETURNING
Definition ScriptedFollowerAI.h:28
void DespawnOrUnsummon(Milliseconds msTimeToDespawn, Seconds forcedRespawnTimer)
Definition Creature.cpp:2177
void AddFollowState(uint32 uiFollowState)
Definition ScriptedFollowerAI.h:69

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)
328{
330 {
332
333 me->StopMoving();
336 }
337
338 if (bWithEndEvent)
340 else
341 {
344 }
345
347}
@ STATE_FOLLOW_COMPLETE
Definition ScriptedFollowerAI.h:30
@ STATE_FOLLOW_POSTEVENT
Definition ScriptedFollowerAI.h:32
void RemoveFollowState(uint32 uiFollowState)
Definition ScriptedFollowerAI.h:70
void MoveIdle()
Definition MotionMaster.cpp:232
void StopMoving()
Definition Unit.cpp:16683

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_jenny::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)
350{
352 return;
353
354 if (paused)
355 {
357
359 {
361
362 me->StopMoving();
365 }
366 }
367 else
368 {
370
371 if (Player* leader = GetLeaderForFollower())
373 }
374}
#define PET_FOLLOW_ANGLE
Definition PetDefines.h:203
#define PET_FOLLOW_DIST
Definition PetDefines.h:202
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE, bool inheritWalkState=true, bool inheritSpeed=true)
The unit will follow this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:409

References AddFollowState(), MotionMaster::Clear(), Unit::ClearUnitState(), GetLeaderForFollower(), Unit::GetMotionMaster(), HasFollowState(), Unit::HasUnitState(), ScriptedAI::me, MotionMaster::MoveFollow(), MotionMaster::MoveIdle(), PET_FOLLOW_ANGLE, PET_FOLLOW_DIST, RemoveFollowState(), STATE_FOLLOW_COMPLETE, STATE_FOLLOW_INPROGRESS, STATE_FOLLOW_PAUSED, Unit::StopMoving(), and UNIT_STATE_FOLLOW.

Referenced by npc_ringo::npc_ringoAI::ClearFaint(), npc_kerlonian::npc_kerlonianAI::ClearSleeping(), npc_ringo::npc_ringoAI::SetFaint(), and npc_kerlonian::npc_kerlonianAI::SetSleeping().

◆ StartFollow()

void FollowerAI::StartFollow ( Player player,
uint32  factionForFollower = 0,
const Quest quest = nullptr,
bool  inheritWalkState = true,
bool  inheritSpeed = true 
)
261{
262 if (me->GetVictim())
263 {
264 LOG_DEBUG("scripts.ai", "FollowerAI attempt to StartFollow while in combat.");
265 return;
266 }
267
269 {
270 LOG_ERROR("entities.unit.ai", "FollowerAI attempt to StartFollow while already following.");
271 return;
272 }
273
274 //set variables
275 m_uiLeaderGUID = player->GetGUID();
276
277 if (factionForFollower)
278 me->SetFaction(factionForFollower);
279
280 m_pQuestForFollow = quest;
281
283 {
286 LOG_DEBUG("scripts.ai", "FollowerAI start with WAYPOINT_MOTION_TYPE, set to MoveIdle.");
287 }
288
290
292
293 me->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE, MOTION_SLOT_ACTIVE, inheritWalkState, inheritSpeed);
294
295 LOG_DEBUG("scripts.ai", "FollowerAI start follow {} ({})", player->GetName(), m_uiLeaderGUID.ToString());
296}
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
@ MOTION_SLOT_ACTIVE
Definition MotionMaster.h:64
@ WAYPOINT_MOTION_TYPE
Definition MotionMaster.h:41
@ UNIT_NPC_FLAG_NONE
Definition UnitDefines.h:314
std::string ToString() const
Definition ObjectGuid.cpp:47
void ReplaceAllNpcFlags(NPCFlags flags)
Definition Unit.h:721
std::string const & GetName() const
Definition Object.h:464

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, MOTION_SLOT_ACTIVE, 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(), and npc_jenny::UpdateFollowerAI().

◆ UpdateAI()

void FollowerAI::UpdateAI ( uint32  )
overridevirtual

Use to start attacking a target. Called just before JustEngagedWith()

Implements UnitAI.

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

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

References Creature::DespawnOrUnsummon(), GetLeaderForFollower(), Unit::GetMotionMaster(), Unit::GetVictim(), HasFollowState(), WorldObject::IsWithinDistInMap(), LOG_DEBUG, m_uiUpdateFollowTimer, MAX_PLAYER_DISTANCE, ScriptedAI::me, MotionMaster::MoveFollow(), 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, npc_ringo::npc_ringoAI, and npc_jenny.

236{
237 if (!UpdateVictim())
238 return;
239
241}
bool UpdateVictim()
Definition CreatureAI.cpp:282
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:39

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().


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