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
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
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
 Called at any Damage from any attacker (before damage apply) More...
 
void UpdateAI (uint32 diff) override
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
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. More...
 
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
 
- 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. More...
 
void Talk (uint8 id, Milliseconds delay)
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At ================================= More...
 
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. More...
 
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 SummonedCreatureEvade (Creature *)
 
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
 Called when unit is charmed. More...
 
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 ================== More...
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields ======================================= More...
 
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 *)
 
virtual void OnAuraRemove (AuraApplication *, AuraRemoveMode)
 
- 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
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool apply)=0
 Called when unit is charmed. More...
 
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: More...
 
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. More...
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat. More...
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 Called at any Damage to any victim (before damage apply) More...
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 Called at any Damage from any attacker (before damage apply) More...
 
virtual void HealReceived (Unit *, uint32 &)
 Called when the creature receives heal. More...
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 Called when the creature power updates. More...
 
virtual void HealDone (Unit *, uint32 &)
 Called when the unit heals. More...
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 Called during damage calculations. More...
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 Called during calculation when receiving periodic healing or damage (DoT or HoT) More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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
 
- 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
37 : ScriptedAI(creature),
40 m_pQuestForFollow(nullptr)
41{}
@ STATE_FOLLOW_NONE
Definition: ScriptedFollowerAI.h:26
Definition: ScriptedCreature.h:190
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:2707
Creature * me
Definition: ScriptedCreature.h:280
void AttackStart(Unit *) override
Definition: ScriptedFollowerAI.cpp:43
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:206
uint32 type_flags
Definition: CreatureData.h:226
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:10578
Unit * GetVictim() const
Definition: Unit.h:789
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:10203

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: UnitDefines.h:158
bool IsCombatMovementAllowed() const
Definition: Creature.h:427
void ClearUnitState(uint32 f)
Definition: Unit.h:674
MotionMaster * GetMotionMaster()
Definition: Unit.h:1601
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:10234
bool HasUnitState(const uint32 f) const
Definition: Unit.h:673
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

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.

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:168
@ 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:287
bool HasFollowState(uint32 uiFollowState)
Definition: ScriptedFollowerAI.h:63
void ClearAllThreat()
Definition: ThreatMgr.cpp:417
void SetLootRecipient(Unit *unit, bool withGroup=true)
Definition: Creature.cpp:1315
void GetPosition(float &x, float &y) const
Definition: Position.h:122
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10398
void RemoveAllAuras()
Definition: Unit.cpp:5290
ThreatMgr & GetThreatMgr()
Definition: Unit.h:839
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:910
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition: MotionMaster.h:211

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:223
ObjectGuid m_uiLeaderGUID
Definition: ScriptedFollowerAI.h:74
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
Definition: Player.h:1064
bool IsAlive() const
Definition: Unit.h:1204
Definition: Group.h:169
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:228

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 me->SetCombatMovement(true);
146
149
150 Reset();
151}
void SetCombatMovement(bool allowMovement)
Definition: Creature.cpp:3833
uint32 faction
Definition: CreatureData.h:201
void SetFaction(uint32 faction)
Definition: Unit.cpp:10018
uint32 GetFaction() const
Definition: Unit.h:755

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, 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:550
@ UNIT_STATE_DISTRACTED
Definition: UnitDefines.h:161
@ UNIT_STATE_STUNNED
Definition: UnitDefines.h:152
bool AssistPlayerInCombatAgainst(Unit *who)
Definition: ScriptedFollowerAI.cpp:66
bool CanStartAttack(Unit const *u) const
Definition: Creature.cpp:1903
bool HasReactState(ReactStates state) const
Definition: Creature.h:99
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:4175
bool isTargetableForAttack(bool checkFakeDeath=true, Unit const *byWho=nullptr) const
Definition: Unit.cpp:13811
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:2173

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:16606
void MoveIdle()
Definition: MotionMaster.cpp:232

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)
357{
359 return;
360
361 if (paused)
362 {
364
366 {
368
369 me->StopMoving();
372 }
373 }
374 else
375 {
377
378 if (Player* leader = GetLeaderForFollower())
380 }
381}
#define PET_FOLLOW_ANGLE
Definition: PetDefines.h:199
#define PET_FOLLOW_DIST
Definition: PetDefines.h:198
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE, bool inheritWalkState=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 
)
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:156
@ WAYPOINT_MOTION_TYPE
Definition: MotionMaster.h:39
@ UNIT_NPC_FLAG_NONE
Definition: UnitDefines.h:293
std::string const & GetName() const
Definition: Object.h:458
std::string ToString() const
Definition: ObjectGuid.cpp:47
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:697

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  )
overridevirtual

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

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