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

#include "SmartAI.h"

Inheritance diagram for SmartAI:
CreatureAI UnitAI npc_black_morass_summoned_add npc_pos_freed_slave::npc_pos_freed_slaveAI npc_stable_master::npc_stable_masterAI

Public Member Functions

 ~SmartAI () override
 
 SmartAI (Creature *c)
 
bool IsAIControlled () const
 
void StartPath (ForcedMovement forcedMovement=FORCED_MOVEMENT_NONE, uint32 path=0, bool repeat=false, Unit *invoker=nullptr, PathSource pathSource=PathSource::SMART_WAYPOINT_MGR)
 
bool LoadPath (uint32 entry, PathSource pathSource)
 
void PausePath (uint32 delay, bool forced=false)
 
void StopPath (uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
 
void EndPath (bool fail=false)
 
void ResumePath ()
 
WaypointNode const * GetNextWayPoint ()
 
void GenerateWayPointArray (Movement::PointsArray *points)
 
bool HasEscortState (uint32 uiEscortState)
 
void AddEscortState (uint32 uiEscortState)
 
bool IsEscorted () override
 
void RemoveEscortState (uint32 uiEscortState)
 
void SetAutoAttack (bool on)
 
void SetCombatMovement (bool on, bool stopOrStartMovement)
 
void SetCurrentRangeMode (bool on, float range=0.f)
 
void SetMainSpell (uint32 spellId)
 
void DistanceYourself (float range)
 
void SetFollow (Unit *target, float dist=0.0f, float angle=0.0f, uint32 credit=0, uint32 end=0, uint32 creditType=0, bool aliveState=true)
 
void StopFollow (bool complete)
 
void SetScript9 (SmartScriptHolder &e, uint32 entry, WorldObject *invoker)
 
SmartScript * GetScript ()
 
bool IsEscortInvokerInRange ()
 
void JustRespawned () override
 
void JustReachedHome () override
 
void JustEngagedWith (Unit *enemy) override
 Called for reaction when initially engaged - this happens after JustEnteredCombat.
 
void JustExitedCombat () override
 Called when the unit leaves combat.
 
void EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER) override
 
void JustDied (Unit *killer) override
 
void KilledUnit (Unit *victim) override
 
void JustSummoned (Creature *creature) override
 
void SummonedCreatureDies (Creature *summon, Unit *killer) override
 
void SummonedCreatureEvade (Creature *summon) override
 
void AttackStart (Unit *who) override
 
void MoveInLineOfSight (Unit *who) override
 
void SpellHit (Unit *unit, SpellInfo const *spellInfo) override
 
void SpellHitTarget (Unit *target, SpellInfo const *spellInfo) override
 
void DamageTaken (Unit *done_by, uint32 &damage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask) override
 Called at any Damage from any attacker (before damage apply)
 
void HealReceived (Unit *doneBy, uint32 &addhealth) override
 Called when the creature receives heal.
 
void UpdateAI (uint32 diff) override
 Use to start attacking a target. Called just before JustEngagedWith()
 
void ReceiveEmote (Player *player, uint32 textEmote) override
 
void MovementInform (uint32 MovementType, uint32 Data) override
 
void IsSummonedBy (WorldObject *summoner) override
 
void DamageDealt (Unit *doneTo, uint32 &damage, DamageEffectType damagetyp, SpellSchoolMask damageSchoolMask) override
 Called at any Damage to any victim (before damage apply)
 
void SummonedCreatureDespawn (Creature *unit) override
 
void CorpseRemoved (uint32 &respawnDelay) override
 == Triggered Actions Requested ==================
 
void PassengerBoarded (Unit *who, int8 seatId, bool apply) override
 == Fields =======================================
 
void InitializeAI () override
 
void OnCharmed (bool apply) override
 Called when unit is charmed.
 
bool CanAIAttack (Unit const *who) const override
 
void DoAction (int32 param=0) override
 
uint32 GetData (uint32 id=0) const override
 
void SetData (uint32 id, uint32 value) override
 
void SetData (uint32 id, uint32 value, WorldObject *invoker)
 
void SetGUID (ObjectGuid const &guid, int32 id=0) override
 
ObjectGuid GetGUID (int32 id=0) const override
 
void MovepointReached (uint32 id)
 
void SetFly (bool fly=true)
 
void SetSwim (bool swim=true)
 
void SetEvadeDisabled (bool disable=true)
 
void SetSuppressEvade (bool suppress)
 
void SetInvincibilityHpLevel (uint32 level)
 
void sGossipHello (Player *player) override
 
void sGossipSelect (Player *player, uint32 sender, uint32 action) override
 
void sGossipSelectCode (Player *player, uint32 sender, uint32 action, char const *code) override
 
void sQuestAccept (Player *player, Quest const *quest) override
 
void sQuestReward (Player *player, Quest const *quest, uint32 opt) override
 
void sOnGameEvent (bool start, uint16 eventId) override
 
void SetDespawnTime (uint32 t)
 
void StartDespawn ()
 
void OnSpellClick (Unit *clicker, bool &result) override
 
void PathEndReached (uint32 pathId) override
 
void WaypointPathStarted (uint32 pathId) override
 == Waypoints system =============================
 
void WaypointStarted (uint32 nodeId, uint32 pathId) override
 
void WaypointReached (uint32 nodeId, uint32 pathId) override
 
void WaypointPathEnded (uint32 nodeId, uint32 pathId) override
 
bool CanRespawn () override
 
void SetCanRespawn (bool canSpawn)
 
void SetWPPauseTimer (uint32 time)
 
void DistancingEnded () override
 
bool IsMainSpellPrevented (SpellInfo const *spellInfo) const
 
void OnSpellFailed (SpellInfo const *spell) override
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr, Milliseconds delay=0ms)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table.
 
void Talk (uint8 id, Milliseconds delay)
 
WorldObject * GetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon.
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
bool IsEngaged () const
 Check if creature is currently engaged in combat.
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual bool IsEscortNPC (bool=true) const
 
void JustEnteredCombat (Unit *who) override
 Called when the unit enters combat.
 
virtual void JustStartedThreateningMe (Unit *who)
 
void EngagementStart (Unit *who)
 
void EngagementOver ()
 
virtual void SummonedCreatureDespawnAll ()
 
virtual void OnSpellStart (SpellInfo const *)
 
virtual void OnSpellCast (SpellInfo const *)
 
virtual void OnChannelFinished (SpellInfo const *)
 
virtual void AttackedBy (Unit *)
 
void DoZoneInCombat (Creature *creature=nullptr, float maxRangeToNearestTarget=250.0f)
 
virtual void OwnerAttackedBy (Unit *attacker)
 
virtual void OwnerAttacked (Unit *target)
 
void OnOwnerCombatInteraction (Unit *target)
 
virtual bool BeforeSpellClick (Unit *)
 
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)
 
virtual void DistancingStarted ()
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual void Reset ()
 
Unit * SelectTarget (SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
Unit * SelectTarget (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 OnDespawn ()
 Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing, player logging out etc.)
 
virtual void EvadeTimerExpired ()
 Called when evade timer expires (target unreachable for too long)
 
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, int32 aura=0)
 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 sQuestSelect (Player *, Quest const *)
 
virtual void sQuestComplete (Player *, Quest const *)
 
virtual std::string GetDebugInfo () const
 

Static Public Member Functions

static int32 Permissible (Creature const *)
 
- 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

uint32 mEscortQuestID
 

Private Member Functions

void ReturnToLastOOCPos ()
 
void UpdatePath (const uint32 diff)
 
uint32 GetWPCount ()
 
bool AssistPlayerInCombatAgainst (Unit *who)
 
void UpdateDespawn (const uint32 diff)
 
void UpdateFollow (const uint32 diff)
 
void UpdateMeleeStance ()
 
void CheckConditions (const uint32 diff)
 

Private Attributes

bool mIsCharmed
 
uint32 mFollowCreditType
 
uint32 mFollowArrivedTimer
 
uint32 _followCheckTimer
 
uint32 mFollowCredit
 
uint32 mFollowArrivedEntry
 
bool mFollowArrivedAlive
 
ObjectGuid mFollowGuid
 
float mFollowDist
 
float mFollowAngle
 
SmartScript mScript
 
WaypointPath const * mWayPoints
 
uint32 mEscortState
 
uint32 mCurrentWPID
 
bool mWPReached
 
bool mOOCReached
 
uint32 mWPPauseTimer
 
WaypointNode const * mLastWP
 
uint32 mEscortNPCFlags
 
bool mCanRepeatPath
 
bool mEvadeDisabled
 
bool mSuppressEvade
 
bool mCanAutoAttack
 
bool mForcedPaused
 
uint32 mInvincibilityHpLevel
 
ForcedMovement mForcedMovement
 
uint32 mDespawnTime
 
uint32 mDespawnState
 
uint32 mEscortInvokerCheckTimer
 
bool mJustReset
 
bool mcanSpawn
 
ConditionList conditions
 
uint32 m_ConditionsTimer
 
bool _chaseOnInterrupt
 
std::unordered_map< uint32, uint32 > aiDataSet
 
bool _currentRangeMode
 
float _attackDistance
 
float _pendingDistancing
 
uint32 _mainSpellId
 

Additional Inherited Members

- 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 Attributes inherited from UnitAI
static AISpellInfoType * AISpellInfo
 
- Protected Member Functions inherited from CreatureAI
bool UpdateVictim ()
 
bool UpdateVictimWithGaze ()
 
void SetGazeOn (Unit *target)
 
Creature * DoSummon (uint32 entry, Position const &pos, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
Creature * DoSummon (uint32 entry, WorldObject *obj, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
Creature * DoSummonFlyer (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)
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
EventMap events
 
TaskScheduler scheduler
 
CreatureBoundary const * _boundary
 
bool _negateBoundary
 
bool _isEngaged
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Detailed Description

Constructor & Destructor Documentation

◆ ~SmartAI()

SmartAI::~SmartAI ( )
inlineoverride
48{};

◆ SmartAI()

SmartAI::SmartAI ( Creature *  c)
explicit
31 : CreatureAI(c)
32{
33 mIsCharmed = false;
34 // copy script to local (protection for table reload)
35
36 mWayPoints = nullptr;
38 mCurrentWPID = 0;//first wp id is 1 !!
39 mWPReached = false;
40 mOOCReached = false;
41 mWPPauseTimer = 0;
42 mLastWP = nullptr;
44
45 mCanRepeatPath = false;
46
47 mEvadeDisabled = false;
48 mSuppressEvade = false;
49
50 mCanAutoAttack = true;
51
52 mForcedPaused = false;
53
55
57
58 mDespawnTime = 0;
59 mDespawnState = 0;
60
62 mFollowDist = 0;
63 mFollowAngle = 0;
64 mFollowCredit = 0;
71
72 mJustReset = false;
73
74 mcanSpawn = true;
75
76 _chaseOnInterrupt = false;
77
78 aiDataSet.clear();
79
80 // Xinef: Vehicle conditions
82 if (me->GetVehicleKit())
84
85 _currentRangeMode = false;
86 _attackDistance = 0.f;
87 _mainSpellId = 0;
88}
#define sConditionMgr
Definition ConditionMgr.h:296
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
Definition ConditionMgr.h:142
@ FORCED_MOVEMENT_NONE
Definition MotionMaster.h:86
@ SMART_ESCORT_NONE
Definition SmartAI.h:31
Definition CreatureAI.h:69
Creature *const me
Definition CreatureAI.h:71
uint32 GetEntry() const
Definition Object.h:123
uint32 mDespawnTime
Definition SmartAI.h:264
uint32 mEscortState
Definition SmartAI.h:246
uint32 _followCheckTimer
Definition SmartAI.h:234
uint32 mEscortInvokerCheckTimer
Definition SmartAI.h:269
uint32 mDespawnState
Definition SmartAI.h:265
bool mOOCReached
Definition SmartAI.h:249
uint32 mWPPauseTimer
Definition SmartAI.h:250
uint32 _mainSpellId
Definition SmartAI.h:285
bool _chaseOnInterrupt
Definition SmartAI.h:279
uint32 mCurrentWPID
Definition SmartAI.h:247
uint32 m_ConditionsTimer
Definition SmartAI.h:277
bool mIsCharmed
Definition SmartAI.h:231
bool mWPReached
Definition SmartAI.h:248
uint32 mFollowArrivedTimer
Definition SmartAI.h:233
float mFollowAngle
Definition SmartAI.h:240
uint32 mEscortQuestID
Definition SmartAI.h:200
bool _currentRangeMode
Definition SmartAI.h:282
float _attackDistance
Definition SmartAI.h:283
WaypointPath const * mWayPoints
Definition SmartAI.h:245
ForcedMovement mForcedMovement
Definition SmartAI.h:260
uint32 mEscortNPCFlags
Definition SmartAI.h:252
ConditionList conditions
Definition SmartAI.h:276
uint32 mFollowCreditType
Definition SmartAI.h:232
bool mFollowArrivedAlive
Definition SmartAI.h:237
bool mcanSpawn
Definition SmartAI.h:272
uint32 mInvincibilityHpLevel
Definition SmartAI.h:259
bool mCanAutoAttack
Definition SmartAI.h:257
bool mJustReset
Definition SmartAI.h:270
bool mSuppressEvade
Definition SmartAI.h:256
bool mCanRepeatPath
Definition SmartAI.h:254
bool mEvadeDisabled
Definition SmartAI.h:255
bool mForcedPaused
Definition SmartAI.h:258
uint32 mFollowCredit
Definition SmartAI.h:235
uint32 mFollowArrivedEntry
Definition SmartAI.h:236
float mFollowDist
Definition SmartAI.h:239
WaypointNode const * mLastWP
Definition SmartAI.h:251
std::unordered_map< uint32, uint32 > aiDataSet
Definition SmartAI.h:280
Vehicle * GetVehicleKit() const
Definition Unit.h:1931

References _attackDistance, _chaseOnInterrupt, _currentRangeMode, _followCheckTimer, _mainSpellId, aiDataSet, CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, conditions, FORCED_MOVEMENT_NONE, Object::GetEntry(), Unit::GetVehicleKit(), m_ConditionsTimer, mCanAutoAttack, mCanRepeatPath, mcanSpawn, mCurrentWPID, mDespawnState, mDespawnTime, CreatureAI::me, mEscortInvokerCheckTimer, mEscortNPCFlags, mEscortQuestID, mEscortState, mEvadeDisabled, mFollowAngle, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mForcedMovement, mForcedPaused, mInvincibilityHpLevel, mIsCharmed, mJustReset, mLastWP, mOOCReached, mSuppressEvade, mWayPoints, mWPPauseTimer, mWPReached, sConditionMgr, and SMART_ESCORT_NONE.

Member Function Documentation

◆ AddEscortState()

void SmartAI::AddEscortState ( uint32  uiEscortState)
inline
64{ mEscortState |= uiEscortState; }

References mEscortState.

Referenced by EnterEvadeMode(), PausePath(), and StartPath().

◆ AssistPlayerInCombatAgainst()

bool SmartAI::AssistPlayerInCombatAgainst ( Unit *  who)
private
827{
828 if (!IsAIControlled())
829 return false;
830
831 // Xinef: if unit has no victim, or victim is player controlled thing
832 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
833 return false;
834
835 //experimental (unknown) flag not present
837 return false;
838
839 // Xinef: victim of unit has to be a player controlled unit
841 return false;
842
843 // Xinef: Check if victim can be assisted
844 if (!me->IsValidAssistTarget(who->GetVictim()))
845 return false;
846
847 // Do not engage if we cannot actually attack the attacker (e.g. neutral faction)
848 if (!me->IsValidAttackTarget(who))
849 return false;
850
851 //too far away and no free sight?
853 {
854 AttackStart(who);
855 return true;
856 }
857
858 return false;
859}
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition SharedDefines.h:2701
@ SMART_MAX_AID_DIST
Definition SmartAI.h:40
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:207
bool IsPlayer() const
Definition ObjectGuid.h:172
void AttackStart(Unit *who) override
Definition SmartAI.cpp:947
bool IsAIControlled() const
Definition SmartAI.cpp:90
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition Unit.h:1301
Unit * GetVictim() const
Definition Unit.h:904
bool IsValidAttackTarget(Unit const *target, SpellInfo const *bySpell=nullptr) const
Definition Unit.cpp:10487
bool IsValidAssistTarget(Unit const *target) const
Definition Unit.cpp:10625
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:1412
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:1386
uint32 type_flags
Definition CreatureData.h:219

References AttackStart(), CREATURE_TYPE_FLAG_CAN_ASSIST, Unit::GetCharmerOrOwnerOrOwnGUID(), Creature::GetCreatureTemplate(), Unit::GetVictim(), IsAIControlled(), ObjectGuid::IsPlayer(), Unit::IsValidAssistTarget(), Unit::IsValidAttackTarget(), WorldObject::IsWithinDistInMap(), WorldObject::IsWithinLOSInMap(), CreatureAI::me, SMART_MAX_AID_DIST, and CreatureTemplate::type_flags.

Referenced by MoveInLineOfSight().

◆ AttackStart()

void SmartAI::AttackStart ( Unit *  who)
overridevirtual

Reimplemented from UnitAI.

948{
949 // xinef: dont allow charmed npcs to act on their own
951 {
952 if (who)
953 me->Attack(who, mCanAutoAttack);
954 return;
955 }
956
957 if (who && me->Attack(who, mCanAutoAttack && !_currentRangeMode))
958 {
960 {
962 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
963 {
965 me->StopMoving();
966 me->GetMotionMaster()->Clear(false);
967 }
968
970 }
971 }
972}
@ MOTION_SLOT_ACTIVE
Definition MotionMaster.h:65
MovementGeneratorType
Definition MotionMaster.h:38
@ ESCORT_MOTION_TYPE
Definition MotionMaster.h:57
@ POINT_MOTION_TYPE
Definition MotionMaster.h:48
@ UNIT_STATE_NO_COMBAT_MOVEMENT
Definition UnitDefines.h:204
@ UNIT_FLAG_POSSESSED
Definition UnitDefines.h:281
MovementGeneratorType GetMotionSlotType(int slot) const
Definition MotionMaster.cpp:1093
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:316
void MovementExpired(bool reset=true)
Definition MotionMaster.h:207
void Clear(bool reset=true)
Definition MotionMaster.h:194
MotionMaster * GetMotionMaster()
Definition Unit.h:1761
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:748
void StopMoving()
Definition Unit.cpp:12639
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:7074
bool HasUnitState(const uint32 f) const
Definition Unit.h:737

References _attackDistance, _currentRangeMode, Unit::Attack(), MotionMaster::Clear(), ESCORT_MOTION_TYPE, Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), Unit::HasUnitFlag(), Unit::HasUnitState(), mCanAutoAttack, CreatureAI::me, MOTION_SLOT_ACTIVE, MotionMaster::MoveChase(), MotionMaster::MovementExpired(), POINT_MOTION_TYPE, Unit::StopMoving(), UNIT_FLAG_POSSESSED, and UNIT_STATE_NO_COMBAT_MOVEMENT.

Referenced by AssistPlayerInCombatAgainst(), and MoveInLineOfSight().

◆ CanAIAttack()

bool SmartAI::CanAIAttack ( Unit const *  who) const
overridevirtual

Reimplemented from UnitAI.

822{
823 return true;
824}

◆ CanRespawn()

bool SmartAI::CanRespawn ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

218{ return mcanSpawn; };

References mcanSpawn.

◆ CheckConditions()

void SmartAI::CheckConditions ( const uint32  diff)
private
538{
539 Vehicle* vehicle = me->GetVehicleKit();
540 if (!vehicle)
541 return;
542
543 if (m_ConditionsTimer < diff)
544 {
545 if (!conditions.empty())
546 {
547 for (SeatMap::iterator itr = vehicle->Seats.begin(); itr != vehicle->Seats.end(); ++itr)
548 if (Unit* passenger = ObjectAccessor::GetUnit(*me, itr->second.Passenger.Guid))
549 {
550 if (Player* player = passenger->ToPlayer())
551 {
552 if (!sConditionMgr->IsObjectMeetToConditions(player, me, conditions))
553 {
554 player->ExitVehicle();
555 return;//check other pessanger in next tick
556 }
557 }
558 }
559 }
560 m_ConditionsTimer = 1000;
561 }
562 else
563 m_ConditionsTimer -= diff;
564}
Player * ToPlayer()
Definition Object.h:208
Definition Player.h:1086
Definition Unit.h:665
Definition Vehicle.h:28
SeatMap Seats
Definition Vehicle.h:57
Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:223

References conditions, ObjectAccessor::GetUnit(), Unit::GetVehicleKit(), m_ConditionsTimer, CreatureAI::me, sConditionMgr, Vehicle::Seats, and Object::ToPlayer().

Referenced by UpdateAI().

◆ CorpseRemoved()

void SmartAI::CorpseRemoved ( uint32 &  )
overridevirtual

== Triggered Actions Requested ==================

== State checks =================================

Reimplemented from CreatureAI.

1024{
1025 GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
1026
1027 // xinef: end escort upon corpse remove, safe check in case of immediate despawn
1028 if (IsEscorted())
1029 EndPath(true);
1030}
@ SMART_EVENT_CORPSE_REMOVED
Definition SmartScriptMgr.h:135
void EndPath(bool fail=false)
Definition SmartAI.cpp:355
bool IsEscorted() override
Definition SmartAI.h:65
SmartScript * GetScript()
Definition SmartAI.h:76
void ProcessEventsFor(SMART_EVENT e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
Definition SmartScript.cpp:157

References EndPath(), GetScript(), IsEscorted(), SmartScript::ProcessEventsFor(), and SMART_EVENT_CORPSE_REMOVED.

◆ DamageDealt()

void SmartAI::DamageDealt ( Unit *  ,
uint32 &  ,
DamageEffectType  ,
SpellSchoolMask   
)
overridevirtual

Called at any Damage to any victim (before damage apply)

Reimplemented from UnitAI.

1013{
1015}
@ SMART_EVENT_DAMAGED_TARGET
Definition SmartScriptMgr.h:132

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_DAMAGED_TARGET.

◆ DamageTaken()

void SmartAI::DamageTaken ( Unit *  ,
uint32 &  ,
DamageEffectType  ,
SpellSchoolMask   
)
overridevirtual

Called at any Damage from any attacker (before damage apply)

Note
It use for recalculation damage or special reaction at damage for attack reaction use AttackedBy called for non DOT damage in Unit::DealDamage also

Reimplemented from UnitAI.

985{
986 if (doneBy)
988
989 if (!IsAIControlled()) // don't allow players to use unkillable units
990 return;
991
992 // Xinef: skip nodamage type (eg. instakill effect)
993 if (damagetype != NODAMAGE && mInvincibilityHpLevel && (damage >= me->GetHealth() - mInvincibilityHpLevel))
994 damage = me->GetHealth() - mInvincibilityHpLevel; // damage should not be nullified, because of player damage req.
995}
@ SMART_EVENT_DAMAGED
Definition SmartScriptMgr.h:131
@ NODAMAGE
Definition Unit.h:259
uint32 GetHealth() const
Definition Unit.h:1114

References Unit::GetHealth(), GetScript(), IsAIControlled(), CreatureAI::me, mInvincibilityHpLevel, NODAMAGE, SmartScript::ProcessEventsFor(), and SMART_EVENT_DAMAGED.

◆ DistanceYourself()

void SmartAI::DistanceYourself ( float  range)
1280{
1281 Unit* victim = me->GetVictim();
1282 if (!victim || !victim->IsWithinMeleeRange(me))
1283 return;
1284
1285 float combatReach = me->GetMeleeRange(victim);
1286 float distance = DISTANCING_CONSTANT + std::max(combatReach * 1.5f, combatReach + range);
1287 me->GetMotionMaster()->DistanceYourself(distance);
1288 _pendingDistancing = distance;
1289}
#define DISTANCING_CONSTANT
Definition SmartAI.h:43
void DistanceYourself(float range)
Definition MotionMaster.cpp:354
float _pendingDistancing
Definition SmartAI.h:284
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:790
float GetMeleeRange(Unit const *target) const
Definition Unit.cpp:807

References _pendingDistancing, MotionMaster::DistanceYourself(), DISTANCING_CONSTANT, Unit::GetMeleeRange(), Unit::GetMotionMaster(), Unit::GetVictim(), Unit::IsWithinMeleeRange(), and CreatureAI::me.

◆ DistancingEnded()

void SmartAI::DistancingEnded ( )
overridevirtual

Reimplemented from CreatureAI.

1397{
1399 _pendingDistancing = 0.f;
1400}
void SetCurrentRangeMode(bool on, float range=0.f)
Definition SmartAI.cpp:1248

References _pendingDistancing, and SetCurrentRangeMode().

◆ DoAction()

void SmartAI::DoAction ( int32  param = 0)
overridevirtual

Reimplemented from UnitAI.

1147{
1149}
@ SMART_EVENT_ACTION_DONE
Definition SmartScriptMgr.h:171

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_ACTION_DONE.

◆ EndPath()

void SmartAI::EndPath ( bool  fail = false)
356{
358 mWayPoints = nullptr;
359 mLastWP = nullptr;
360 mWPPauseTimer = 0;
361
362 if (mEscortNPCFlags)
363 {
365 mEscortNPCFlags = 0;
366 }
367
369 if (targets && mEscortQuestID)
370 {
371 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
372 {
373 Player* player = targets->front()->ToPlayer();
374 if (Group* group = player->GetGroup())
375 {
376 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
377 {
378 Player* groupGuy = groupRef->GetSource();
379 if (!groupGuy || !player->IsInMap(groupGuy))
380 continue;
381
382 if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
384 else if (fail && groupGuy->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
385 groupGuy->FailQuest(mEscortQuestID);
386 }
387 }
388 else
389 {
390 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
392 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
393 player->FailQuest(mEscortQuestID);
394 }
395 }
396 else
397 {
398 for (WorldObject* target : *targets)
399 {
400 if (GetScript()->IsPlayer(target))
401 {
402 Player* player = target->ToPlayer();
403 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
405 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
406 player->FailQuest(mEscortQuestID);
407 }
408 }
409 }
410 }
411
412 // Xinef: if the escort failed - DO NOT PROCESS ANYTHING
413 // Xinef: End Path events should be only processed if it was SUCCESSFUL stop or stop called by SMART_ACTION_WAYPOINT_STOP
414 if (fail)
415 {
416 mCurrentWPID = 0;
417 return;
418 }
419
421 mCurrentWPID = 0;
422
423 if (mCanRepeatPath)
424 {
425 if (IsAIControlled())
426 StartPath(mForcedMovement, GetScript()->GetPathId(), true);
427 }
428 else
429 GetScript()->SetPathId(0);
430
431 if (mDespawnState == 1)
432 StartDespawn();
433}
@ QUEST_STATUS_INCOMPLETE
Definition QuestDef.h:103
@ SMART_ESCORT_ESCORTING
Definition SmartAI.h:32
@ SMART_ESCORT_PAUSED
Definition SmartAI.h:34
@ SMART_ESCORT_RETURNING
Definition SmartAI.h:33
std::vector< WorldObject * > ObjectVector
Definition SmartScriptMgr.h:2045
@ SMART_EVENT_ESCORT_ENDED
Definition SmartScriptMgr.h:157
@ SMART_ESCORT_TARGETS
Definition SmartScriptMgr.h:40
NPCFlags
Non Player Character flags.
Definition UnitDefines.h:320
Definition GroupReference.h:27
Definition Group.h:177
bool HasCorpse() const
Definition Player.h:2070
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition PlayerQuest.cpp:1892
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition Player.cpp:13076
Group * GetGroup()
Definition Player.h:2517
void AreaExploredOrEventHappens(uint32 questId)
Definition PlayerQuest.cpp:1865
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition PlayerQuest.cpp:1504
void FailQuest(uint32 quest_id)
Definition PlayerQuest.cpp:912
void RemoveEscortState(uint32 uiEscortState)
Definition SmartAI.h:66
void StartDespawn()
Definition SmartAI.h:207
void StartPath(ForcedMovement forcedMovement=FORCED_MOVEMENT_NONE, uint32 path=0, bool repeat=false, Unit *invoker=nullptr, PathSource pathSource=PathSource::SMART_WAYPOINT_MGR)
Definition SmartAI.cpp:235
ObjectVector const * GetStoredTargetVector(uint32 id, WorldObject const &ref) const
Definition SmartScript.h:100
void SetPathId(uint32 id)
Definition SmartScript.h:62
void ReplaceAllNpcFlags(NPCFlags flags)
Definition Unit.h:767
Definition Object.h:482
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1344

References Player::AreaExploredOrEventHappens(), Player::FailQuest(), Player::GetGroup(), Player::GetQuestStatus(), GetScript(), SmartScript::GetStoredTargetVector(), Player::GroupEventHappens(), Player::HasCorpse(), IsAIControlled(), Player::IsAtGroupRewardDistance(), WorldObject::IsInMap(), SmartScript::IsPlayer(), mCanRepeatPath, mCurrentWPID, mDespawnState, CreatureAI::me, mEscortNPCFlags, mEscortQuestID, mForcedMovement, mLastWP, mWayPoints, mWPPauseTimer, SmartScript::ProcessEventsFor(), QUEST_STATUS_INCOMPLETE, RemoveEscortState(), Unit::ReplaceAllNpcFlags(), SmartScript::SetPathId(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_ESCORT_RETURNING, SMART_ESCORT_TARGETS, SMART_EVENT_ESCORT_ENDED, StartDespawn(), StartPath(), and Object::ToPlayer().

Referenced by CorpseRemoved(), JustDied(), MovepointReached(), OnCharmed(), StopPath(), and UpdatePath().

◆ EnterEvadeMode()

void SmartAI::EnterEvadeMode ( EvadeReason  why = EVADE_REASON_OTHER)
overridevirtual

Reimplemented from CreatureAI.

737{
738 if (mSuppressEvade)
739 return;
740
741 if (mEvadeDisabled)
742 {
744 return;
745 }
746
748 {
749 me->AttackStop();
751 return;
752 }
753
754 if (!_EnterEvadeMode())
755 return;
756
758
759 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
760
761 if (Unit* owner = me->GetCharmerOrOwner())
762 {
763 if (!me->IsVehicle()) // vehicles should not follow their owner (passenger)
765
767 }
769 {
772 }
773 else if (mFollowGuid)
774 {
778
779 // xinef: do not forget to reset scripts as we wont call reached home
780 GetScript()->OnReset();
781 }
782 else
783 {
785
786 // xinef: do not forget to reset scripts as we wont call reached home
788 GetScript()->OnReset();
789 }
790
791 sScriptMgr->OnUnitEnterEvadeMode(me, why);
792}
constexpr float PET_FOLLOW_DIST
Definition PetDefines.h:206
#define sScriptMgr
Definition ScriptMgr.h:766
@ SMART_EVENT_EVADE
Definition SmartScriptMgr.h:106
@ UNIT_STATE_EVADE
Definition UnitDefines.h:194
@ UNIT_FLAG_IN_COMBAT
Definition UnitDefines.h:276
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition CreatureAI.cpp:383
void MoveTargetedHome(bool walk=false)
The unit will return this initial position (owner for pets and summoned creatures)....
Definition MotionMaster.cpp:262
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:448
bool HasEscortState(uint32 uiEscortState)
Definition SmartAI.h:63
void ReturnToLastOOCPos()
Definition SmartAI.cpp:446
void AddEscortState(uint32 uiEscortState)
Definition SmartAI.h:64
ObjectGuid mFollowGuid
Definition SmartAI.h:238
void OnReset()
Definition SmartScript.cpp:131
void ClearUnitState(uint32 f)
Definition Unit.h:738
bool IsVehicle() const
Definition Unit.h:801
void AddUnitState(uint32 f)
Definition Unit.h:736
Unit * GetCharmerOrOwner() const
Definition Unit.h:1291
virtual float GetFollowAngle() const
Definition Unit.h:1901
ObjectGuid GetCharmerGUID() const
Definition Unit.h:720
bool AttackStop()
Force the unit to stop attacking. This will clear UNIT_STATE_MELEE_ATTACKING, Interrupt current spell...
Definition Unit.cpp:7240
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:750

References CreatureAI::_EnterEvadeMode(), AddEscortState(), Unit::AddUnitState(), Unit::AttackStop(), Unit::ClearUnitState(), Unit::GetCharmerGUID(), Unit::GetCharmerOrOwner(), Unit::GetFollowAngle(), Unit::GetMotionMaster(), GetScript(), ObjectAccessor::GetUnit(), HasEscortState(), Unit::HasUnitFlag(), Unit::HasUnitState(), ObjectGuid::IsPlayer(), Unit::IsVehicle(), CreatureAI::me, mEvadeDisabled, mFollowAngle, mFollowDist, mFollowGuid, MotionMaster::MoveFollow(), MotionMaster::MoveTargetedHome(), mSuppressEvade, SmartScript::OnReset(), PET_FOLLOW_DIST, SmartScript::ProcessEventsFor(), Unit::RemoveUnitFlag(), ReturnToLastOOCPos(), SMART_ESCORT_ESCORTING, SMART_ESCORT_RETURNING, SMART_EVENT_EVADE, sScriptMgr, UNIT_FLAG_IN_COMBAT, UNIT_FLAG_POSSESSED, and UNIT_STATE_EVADE.

Referenced by npc_black_morass_summoned_add::EnterEvadeMode(), and OnCharmed().

◆ GenerateWayPointArray()

void SmartAI::GenerateWayPointArray ( Movement::PointsArray *  points)
174{
175 if (!mWayPoints || mWayPoints->Nodes.empty())
176 return;
177
178 // Flying unit, just fill array
180 {
181 // xinef: first point in vector is unit real position
182 points->clear();
183 points->push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
184 // mCurrentWPID is 1-based
185 for (uint32 i = mCurrentWPID > 0 ? mCurrentWPID - 1 : 0; i < mWayPoints->Nodes.size(); ++i)
186 {
187 WaypointNode const& wp = mWayPoints->Nodes[i];
188 points->push_back(G3D::Vector3(wp.X, wp.Y, wp.Z));
189 }
190 }
191 else
192 {
193 for (float size = 1.0f; size; size *= 0.5f)
194 {
195 std::vector<G3D::Vector3> pVector;
196 // xinef: first point in vector is unit real position
197 pVector.push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
198
199 uint32 startIdx = mCurrentWPID > 0 ? mCurrentWPID - 1 : 0;
200 uint32 length = (uint32)((mWayPoints->Nodes.size() - startIdx) * size);
201
202 uint32 cnt = 0;
203 for (uint32 i = startIdx; i < mWayPoints->Nodes.size() && cnt++ <= length; ++i)
204 {
205 WaypointNode const& wp = mWayPoints->Nodes[i];
206 pVector.push_back(G3D::Vector3(wp.X, wp.Y, wp.Z));
207 }
208
209 if (pVector.size() > 2) // more than source + dest
210 {
211 G3D::Vector3 middle = (pVector[0] + pVector[pVector.size() - 1]) / 2.f;
212 G3D::Vector3 offset;
213
214 bool continueLoop = false;
215 for (uint32 i = 1; i < pVector.size() - 1; ++i)
216 {
217 offset = middle - pVector[i];
218 if (std::fabs(offset.x) >= 0xFF || std::fabs(offset.y) >= 0xFF || std::fabs(offset.z) >= 0x7F)
219 {
220 // offset is too big, split points
221 continueLoop = true;
222 break;
223 }
224 }
225 if (continueLoop)
226 continue;
227 }
228 // everything ok
229 *points = pVector;
230 break;
231 }
232 }
233}
std::uint32_t uint32
Definition Define.h:107
MovementFlags
Definition UnitDefines.h:370
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition UnitDefines.h:382
@ MOVEMENTFLAG_CAN_FLY
Definition UnitDefines.h:396
MovementInfo m_movementInfo
Definition Object.h:711
bool HasMovementFlag(uint32 flag) const
Definition Object.h:353
float GetPositionZ() const
Definition Position.h:123
float GetPositionX() const
Definition Position.h:121
float GetPositionY() const
Definition Position.h:122
Definition WaypointDefines.h:37
float X
Definition WaypointDefines.h:48
float Z
Definition WaypointDefines.h:48
float Y
Definition WaypointDefines.h:48
std::vector< WaypointNode > Nodes
Definition WaypointDefines.h:68

References Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), MovementInfo::HasMovementFlag(), WorldObject::m_movementInfo, mCurrentWPID, CreatureAI::me, MOVEMENTFLAG_CAN_FLY, MOVEMENTFLAG_DISABLE_GRAVITY, mWayPoints, WaypointPath::Nodes, WaypointNode::X, WaypointNode::Y, and WaypointNode::Z.

Referenced by ResumePath(), and StartPath().

◆ GetData()

uint32 SmartAI::GetData ( uint32  id = 0) const
overridevirtual

Reimplemented from UnitAI.

1152{
1153 auto const& itr = aiDataSet.find(id);
1154 if (itr != aiDataSet.end())
1155 return itr->second;
1156
1157 return 0;
1158}

References aiDataSet.

◆ GetGUID()

ObjectGuid SmartAI::GetGUID ( int32  id = 0) const
overridevirtual

Reimplemented from UnitAI.

1181{
1182 return ObjectGuid::Empty;
1183}
static ObjectGuid const Empty
Definition ObjectGuid.h:123

References ObjectGuid::Empty.

◆ GetNextWayPoint()

WaypointNode const * SmartAI::GetNextWayPoint ( )
155{
156 if (!mWayPoints || mWayPoints->Nodes.empty())
157 return nullptr;
158
159 mCurrentWPID++;
160 // mCurrentWPID is 1-based for SmartAI escort paths
161 if (mCurrentWPID > mWayPoints->Nodes.size())
162 return nullptr;
163
164 // Nodes are 0-indexed, mCurrentWPID is 1-based
165 WaypointNode const& node = mWayPoints->Nodes[mCurrentWPID - 1];
166 mLastWP = &node;
167 if (mLastWP->Id != mCurrentWPID)
168 LOG_ERROR("scripts.ai.sai", "SmartAI::GetNextWayPoint: Got not expected waypoint id {}, expected {}", mLastWP->Id, mCurrentWPID);
169
170 return mLastWP;
171}
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
uint32 Id
Definition WaypointDefines.h:47

References WaypointNode::Id, LOG_ERROR, mCurrentWPID, mLastWP, mWayPoints, and WaypointPath::Nodes.

Referenced by MovepointReached(), StartPath(), and UpdatePath().

◆ GetScript()

◆ GetWPCount()

uint32 SmartAI::GetWPCount ( )
inlineprivate
253{ return mWayPoints ? mWayPoints->Nodes.size() : 0; }

References mWayPoints, and WaypointPath::Nodes.

Referenced by MovepointReached(), and UpdatePath().

◆ HasEscortState()

bool SmartAI::HasEscortState ( uint32  uiEscortState)
inline

◆ HealReceived()

void SmartAI::HealReceived ( Unit *  ,
uint32 &   
)
overridevirtual

Called when the creature receives heal.

Reimplemented from UnitAI.

998{
1000}
@ SMART_EVENT_RECEIVE_HEAL
Definition SmartScriptMgr.h:152

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_RECEIVE_HEAL.

◆ InitializeAI()

void SmartAI::InitializeAI ( )
overridevirtual

Reimplemented from UnitAI.

1038{
1040
1041 auto getSpellAndFlags = [](SmartScriptHolder const& event, uint32& spellId, uint32& flags) -> bool
1042 {
1043 if (event.GetActionType() == SMART_ACTION_CAST)
1044 {
1045 spellId = event.action.cast.spell;
1046 flags = event.action.cast.castFlags;
1047 return true;
1048 }
1049 else if (event.GetActionType() == SMART_ACTION_CUSTOM_CAST)
1050 {
1051 spellId = event.action.castCustom.spell;
1052 flags = event.action.castCustom.flags;
1053 return true;
1054 }
1055 return false;
1056 };
1057
1058 for (SmartScriptHolder const& event : GetScript()->GetEvents())
1059 {
1060 uint32 spellId = 0;
1061 uint32 flags = 0;
1062 if (!getSpellAndFlags(event, spellId, flags))
1063 continue;
1064
1065 if (!(flags & SMARTCAST_MAIN_SPELL))
1066 continue;
1067
1068 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
1069 if (spellInfo && spellInfo->IsPositive())
1070 {
1071 LOG_WARN("scripts.ai",
1072 "SmartAI: Creature {} has SMARTCAST_MAIN_SPELL on positive spell {} - "
1073 "positive spells should not be used as main spell", me->GetEntry(), spellId);
1074 continue;
1075 }
1076
1077 SetMainSpell(spellId);
1078 break;
1079 }
1080
1081 // Fallback: use first SMARTCAST_COMBAT_MOVE if no MAIN_SPELL found
1082 if (!_currentRangeMode)
1083 {
1084 for (SmartScriptHolder const& event : GetScript()->GetEvents())
1085 {
1086 uint32 spellId = 0;
1087 uint32 flags = 0;
1088 if (!getSpellAndFlags(event, spellId, flags))
1089 continue;
1090
1091 if (!(flags & SMARTCAST_COMBAT_MOVE))
1092 continue;
1093
1094 // Don't use positive (healing/buff) spells to determine attack distance
1095 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
1096 if (spellInfo && spellInfo->IsPositive())
1097 continue;
1098
1099 SetMainSpell(spellId);
1100 break;
1101 }
1102 }
1103
1104 if (!me->isDead())
1105 {
1106 mJustReset = true;
1109 }
1110}
#define LOG_WARN(filterType__,...)
Definition Log.h:149
@ SMART_ACTION_CAST
Definition SmartScriptMgr.h:553
@ SMART_ACTION_CUSTOM_CAST
Definition SmartScriptMgr.h:705
@ SMART_EVENT_RESPAWN
Definition SmartScriptMgr.h:110
@ SMARTCAST_MAIN_SPELL
Definition SmartScriptMgr.h:1991
@ SMARTCAST_COMBAT_MOVE
Definition SmartScriptMgr.h:1987
#define sSpellMgr
Definition SpellMgr.h:847
void SetMainSpell(uint32 spellId)
Definition SmartAI.cpp:1264
void JustReachedHome() override
Definition SmartAI.cpp:883
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition SmartScript.cpp:5440
Definition SpellInfo.h:340
bool IsPositive() const
Definition SpellInfo.cpp:1282
bool isDead() const
Definition Unit.h:1798
Definition SmartScriptMgr.h:2008
uint32 GetActionType() const
Definition SmartScriptMgr.h:2025

References _currentRangeMode, SmartScriptHolder::GetActionType(), Object::GetEntry(), SmartScript::GetEvents(), GetScript(), Unit::isDead(), SpellInfo::IsPositive(), JustReachedHome(), LOG_WARN, CreatureAI::me, mJustReset, SmartScript::OnInitialize(), SmartScript::ProcessEventsFor(), SetMainSpell(), SMART_ACTION_CAST, SMART_ACTION_CUSTOM_CAST, SMART_EVENT_RESPAWN, SMARTCAST_COMBAT_MOVE, SMARTCAST_MAIN_SPELL, and sSpellMgr.

◆ IsAIControlled()

bool SmartAI::IsAIControlled ( ) const

◆ IsEscorted()

bool SmartAI::IsEscorted ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

References mEscortState, and SMART_ESCORT_ESCORTING.

Referenced by CorpseRemoved().

◆ IsEscortInvokerInRange()

bool SmartAI::IsEscortInvokerInRange ( )
622{
623 if (ObjectVector const* targets = GetScript()->GetStoredTargetVector(SMART_ESCORT_TARGETS, *me))
624 {
626 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
627 {
628 Player* player = (*targets->begin())->ToPlayer();
629 if (me->GetDistance(player) <= checkDist)
630 return true;
631
632 if (Group* group = player->GetGroup())
633 {
634 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
635 {
636 Player* groupGuy = groupRef->GetSource();
637
638 if (groupGuy && me->IsInMap(groupGuy) && me->GetDistance(groupGuy) <= checkDist)
639 return true;
640 }
641 }
642 }
643 else
644 {
645 for (WorldObject* target : *targets)
646 {
647 if (GetScript()->IsPlayer(target))
648 {
649 if (me->GetDistance(target->ToPlayer()) <= checkDist)
650 return true;
651 }
652 }
653 }
654
655 // Xinef: no valid target found
656 return false;
657 }
658 // Xinef: no player invoker was stored, just ignore range check
659 return true;
660}
@ SMART_ESCORT_MAX_PLAYER_DIST
Definition SmartAI.h:39
GroupReference * next()
Definition GroupReference.h:36
InstanceScript * GetInstanceScript() const
Definition Object.cpp:1247
float GetDistance(WorldObject const *obj) const
Definition Object.cpp:1304

References WorldObject::GetDistance(), Player::GetGroup(), WorldObject::GetInstanceScript(), GetScript(), WorldObject::IsInMap(), SmartScript::IsPlayer(), CreatureAI::me, GroupReference::next(), SMART_ESCORT_MAX_PLAYER_DIST, and SMART_ESCORT_TARGETS.

Referenced by UpdatePath().

◆ IsMainSpellPrevented()

bool SmartAI::IsMainSpellPrevented ( SpellInfo const *  spellInfo) const
1403{
1404 if (me->IsSpellProhibited(spellInfo->GetSchoolMask()))
1405 return true;
1406
1407 if (spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE && me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED))
1408 return true;
1409
1410 if (spellInfo->PreventionType == SPELL_PREVENTION_TYPE_PACIFY && me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED))
1411 return true;
1412
1413 int32 powerCost = spellInfo->CalcPowerCost(me, spellInfo->GetSchoolMask());
1414 if (spellInfo->PowerType == POWER_HEALTH)
1415 {
1416 if ((int32)me->GetHealth() <= powerCost)
1417 return true;
1418 }
1419 else
1420 {
1421 Powers power = (spellInfo->PowerType < MAX_POWERS)
1422 ? Powers(spellInfo->PowerType)
1423 : me->getPowerType();
1424 if ((int32)me->GetPower(power) < powerCost)
1425 return true;
1426 }
1427
1428 return false;
1429}
std::int32_t int32
Definition Define.h:103
Powers
Definition SharedDefines.h:256
@ MAX_POWERS
Definition SharedDefines.h:264
@ POWER_HEALTH
Definition SharedDefines.h:266
@ SPELL_PREVENTION_TYPE_SILENCE
Definition SharedDefines.h:1558
@ SPELL_PREVENTION_TYPE_PACIFY
Definition SharedDefines.h:1559
@ UNIT_FLAG_PACIFIED
Definition UnitDefines.h:274
@ UNIT_FLAG_SILENCED
Definition UnitDefines.h:270
@ UNIT_FIELD_FLAGS
Definition UpdateFields.h:117
bool IsSpellProhibited(SpellSchoolMask idSchoolMask) const
Definition Creature.cpp:2976
bool HasFlag(uint16 index, uint32 flag) const
Definition Object.cpp:880
Powers getPowerType() const
Definition Unit.h:1137
uint32 GetPower(Powers power) const
Definition Unit.h:1141

References SpellInfo::CalcPowerCost(), Unit::GetHealth(), Unit::GetPower(), Unit::getPowerType(), SpellInfo::GetSchoolMask(), Object::HasFlag(), Creature::IsSpellProhibited(), MAX_POWERS, CreatureAI::me, POWER_HEALTH, SpellInfo::PowerType, SpellInfo::PreventionType, SPELL_PREVENTION_TYPE_PACIFY, SPELL_PREVENTION_TYPE_SILENCE, UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED, and UNIT_FLAG_SILENCED.

Referenced by OnSpellFailed().

◆ IsSummonedBy()

void SmartAI::IsSummonedBy ( WorldObject *  summoner)
overridevirtual

Reimplemented from CreatureAI.

1008{
1009 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
1010}
@ SMART_EVENT_JUST_SUMMONED
Definition SmartScriptMgr.h:153
GameObject * ToGameObject()
Definition Object.h:220
Unit * ToUnit()
Definition Object.h:216

References GetScript(), SmartScript::ProcessEventsFor(), SMART_EVENT_JUST_SUMMONED, Object::ToGameObject(), and Object::ToUnit().

◆ JustDied()

void SmartAI::JustDied ( Unit *  killer)
overridevirtual

Reimplemented from CreatureAI.

920{
923 EndPath(true);
924}
@ SMART_EVENT_DEATH
Definition SmartScriptMgr.h:105

References EndPath(), GetScript(), HasEscortState(), SmartScript::ProcessEventsFor(), SMART_ESCORT_ESCORTING, and SMART_EVENT_DEATH.

◆ JustEngagedWith()

void SmartAI::JustEngagedWith ( Unit *  )
overridevirtual

Called for reaction when initially engaged - this happens after JustEnteredCombat.

Reimplemented from CreatureAI.

905{
906 // Xinef: Interrupt channeled spells
907 if (IsAIControlled())
908 {
910 {
911 if (!spell->GetSpellInfo()->IsActionAllowedChannel())
913 }
914 }
915
917}
@ SMART_EVENT_AGGRO
Definition SmartScriptMgr.h:103
@ CURRENT_CHANNELED_SPELL
Definition Unit.h:558
Definition Spell.h:298
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, bool bySelf=false)
Definition Unit.cpp:3975
Spell * GetCurrentSpell(CurrentSpellTypes spellType) const
Definition Unit.h:1581

References CURRENT_CHANNELED_SPELL, Unit::GetCurrentSpell(), GetScript(), Unit::InterruptSpell(), IsAIControlled(), CreatureAI::me, SmartScript::ProcessEventsFor(), and SMART_EVENT_AGGRO.

◆ JustExitedCombat()

void SmartAI::JustExitedCombat ( )
overridevirtual

Called when the unit leaves combat.

Reimplemented from CreatureAI.

723{
724 // When evade is suppressed or disabled, don't auto-evade on combat exit.
725 // This prevents scripted encounters (e.g. Mograine/Whitemane) from resetting
726 // when bosses temporarily stop fighting during scripted phases.
728 {
730 return;
731 }
732
734}
void JustExitedCombat() override
Called when the unit leaves combat.
Definition CreatureAI.cpp:310
void EngagementOver()
Definition CreatureAI.cpp:298

References CreatureAI::EngagementOver(), CreatureAI::JustExitedCombat(), mEvadeDisabled, and mSuppressEvade.

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

884{
885 GetScript()->OnReset();
886
887 if (!mJustReset)
888 {
890
893 }
894
895 if (_mainSpellId)
896 {
898 SetCombatMovement(true, false);
899 }
900
901 mJustReset = false;
902}
@ IDLE_MOTION_TYPE
Definition MotionMaster.h:39
@ SMART_EVENT_REACHED_HOME
Definition SmartScriptMgr.h:120
bool UpdateVictim()
Definition CreatureAI.cpp:350
uint32 GetWaypointPath() const
Definition Creature.h:357
void MoveWaypoint(uint32 path_id, bool repeatable, PathSource pathSource=PathSource::WAYPOINT_MGR)
Move the unit following a specific path. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:1014
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:1085
void SetCombatMovement(bool on, bool stopOrStartMovement)
Definition SmartAI.cpp:1226

References _mainSpellId, MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), GetScript(), Creature::GetWaypointPath(), IDLE_MOTION_TYPE, CreatureAI::me, mJustReset, MotionMaster::MoveWaypoint(), SmartScript::OnReset(), SmartScript::ProcessEventsFor(), SetCombatMovement(), SetMainSpell(), SMART_EVENT_REACHED_HOME, and CreatureAI::UpdateVictim().

Referenced by InitializeAI(), and JustRespawned().

◆ JustRespawned()

void SmartAI::JustRespawned ( )
overridevirtual

Reimplemented from CreatureAI.

862{
863 mDespawnTime = 0;
864 mDespawnState = 0;
866 me->SetVisible(true);
869 mJustReset = true;
872 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
873 mFollowDist = 0;
874 mFollowAngle = 0;
875 mFollowCredit = 0;
876 mFollowArrivedTimer = 1000;
879 mFollowArrivedAlive = true;
880 aiDataSet.clear();
881}
void Clear()
Definition ObjectGuid.h:141
void SetVisible(bool x)
Definition Unit.cpp:10854
void RestoreFaction()
Definition Unit.cpp:14579
uint32 GetFaction() const override
Definition Unit.h:852
uint32 faction
Definition CreatureData.h:199

References aiDataSet, ObjectGuid::Clear(), CreatureTemplate::faction, Creature::GetCreatureTemplate(), Unit::GetFaction(), GetScript(), JustReachedHome(), mDespawnState, mDespawnTime, CreatureAI::me, mEscortState, mFollowAngle, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mFollowGuid, mJustReset, SmartScript::ProcessEventsFor(), Unit::RestoreFaction(), Unit::SetVisible(), SMART_ESCORT_NONE, and SMART_EVENT_RESPAWN.

◆ JustSummoned()

void SmartAI::JustSummoned ( Creature *  creature)
overridevirtual

Reimplemented from CreatureAI.

932{
934 GetScript()->AddCreatureSummon(creature->GetGUID());
935}
@ SMART_EVENT_SUMMONED_UNIT
Definition SmartScriptMgr.h:116
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
void AddCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5712

References SmartScript::AddCreatureSummon(), Object::GetGUID(), GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_SUMMONED_UNIT.

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit *  victim)
overridevirtual

Reimplemented from CreatureAI.

927{
929}
@ SMART_EVENT_KILL
Definition SmartScriptMgr.h:104

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_KILL.

◆ LoadPath()

bool SmartAI::LoadPath ( uint32  entry,
PathSource  pathSource 
)
270{
272 return false;
273
274 switch (pathSource)
275 {
277 {
278 mWayPoints = sSmartWaypointMgr->GetPath(entry);
279 if (!mWayPoints)
280 {
281 GetScript()->SetPathId(0);
282 return false;
283 }
284 break;
285 }
287 {
288 mWayPoints = sWaypointMgr->GetPath(entry);
289 if (!mWayPoints)
290 {
291 GetScript()->SetPathId(0);
292 return false;
293 }
294 break;
295 }
296 }
297
298 GetScript()->SetPathId(entry);
299 return true;
300}
@ SMART_WAYPOINT_MGR
#define sSmartWaypointMgr
Definition SmartScriptMgr.h:2282
#define sWaypointMgr
Definition WaypointMgr.h:54

References GetScript(), HasEscortState(), mWayPoints, SmartScript::SetPathId(), SMART_ESCORT_ESCORTING, SMART_WAYPOINT_MGR, sSmartWaypointMgr, sWaypointMgr, and WAYPOINT_MGR.

Referenced by StartPath().

◆ MoveInLineOfSight()

void SmartAI::MoveInLineOfSight ( Unit *  who)
overridevirtual

Reimplemented from CreatureAI.

795{
796 if (!who)
797 return;
798
800
801 if (!IsAIControlled())
802 return;
803
804 if (me->GetVictim())
805 return;
806
808 return;
809
811 {
813 {
816 }
817 AttackStart(who);
818 }
819}
@ UNIT_STATE_DISTRACTED
Definition UnitDefines.h:185
@ REACT_PASSIVE
Definition Unit.h:567
@ REACT_AGGRESSIVE
Definition Unit.h:569
bool HasReactState(ReactStates state) const
Definition Creature.h:102
bool CanStartAttack(Unit const *u, bool force=false) const
Definition Creature.cpp:1922
bool AssistPlayerInCombatAgainst(Unit *who)
Definition SmartAI.cpp:826
void OnMoveInLineOfSight(Unit *who)
Definition SmartScript.cpp:5483

References AssistPlayerInCombatAgainst(), AttackStart(), Creature::CanStartAttack(), MotionMaster::Clear(), Unit::ClearUnitState(), Unit::GetMotionMaster(), GetScript(), Unit::GetVictim(), Creature::HasReactState(), Unit::HasUnitState(), IsAIControlled(), CreatureAI::me, SmartScript::OnMoveInLineOfSight(), REACT_AGGRESSIVE, REACT_PASSIVE, and UNIT_STATE_DISTRACTED.

◆ MovementInform()

void SmartAI::MovementInform ( uint32  MovementType,
uint32  Data 
)
overridevirtual

Reimplemented from CreatureAI.

707{
708 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
710
711 if (MovementType == WAYPOINT_MOTION_TYPE)
712 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, Data); // data now corresponds to columns
713
714 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
716 return;
717
718 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
720}
@ WAYPOINT_MOTION_TYPE
Definition MotionMaster.h:41
@ SMART_EVENT_MOVEMENTINFORM
Definition SmartScriptMgr.h:133
@ SMART_EVENT_WAYPOINT_REACHED
Definition SmartScriptMgr.h:197
@ SMART_ESCORT_LAST_OOC_POINT
Definition SmartScriptMgr.h:38
Data
Definition blackfathom_deeps.h:24
void MovepointReached(uint32 id)
Definition SmartAI.cpp:662

References Unit::ClearUnitState(), ESCORT_MOTION_TYPE, GetScript(), HasEscortState(), CreatureAI::me, MovepointReached(), POINT_MOTION_TYPE, SmartScript::ProcessEventsFor(), SMART_ESCORT_ESCORTING, SMART_ESCORT_LAST_OOC_POINT, SMART_EVENT_MOVEMENTINFORM, SMART_EVENT_WAYPOINT_REACHED, UNIT_STATE_EVADE, and WAYPOINT_MOTION_TYPE.

◆ MovepointReached()

void SmartAI::MovepointReached ( uint32  id)
663{
664 // override the id, path can be resumed any time and counter will reset
665 // mCurrentWPID holds proper id
666
667 // xinef: both point movement and escort generator can enter this function
669 {
670 mOOCReached = true;
671 return;
672 }
673
674 mWPReached = true;
676
677 if (mLastWP)
678 {
681 }
682
684 {
687
690 }
691 // Xinef: Can be unset in ProcessEvents
693 {
694 mWPReached = false;
695 if (mCurrentWPID == GetWPCount())
696 EndPath();
697 else if (GetNextWayPoint())
698 {
699 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
700 if (me->movespline->Finalized())
701 ResumePath();
702 }
703 }
704}
@ SMART_EVENT_ESCORT_REACHED
Definition SmartScriptMgr.h:139
void SetHomePosition(float x, float y, float z, float o)
Definition Creature.h:347
void SetPosition(float x, float y, float z, float o)
Definition Creature.cpp:3343
void MoveIdle()
Definition MotionMaster.cpp:235
bool Finalized() const
Definition MoveSpline.h:118
WaypointNode const * GetNextWayPoint()
Definition SmartAI.cpp:154
uint32 GetWPCount()
Definition SmartAI.h:253
void ResumePath()
Definition SmartAI.cpp:435
Movement::MoveSpline * movespline
Definition Unit.h:2119
void StopMovingOnCurrentPos()
Definition Unit.cpp:12678
float GetOrientation() const
Definition Position.h:124
void GetPosition(float &x, float &y) const
Definition Position.h:126

References EndPath(), ESCORT_MOTION_TYPE, Movement::MoveSpline::Finalized(), MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), GetNextWayPoint(), Position::GetOrientation(), Position::GetPosition(), GetScript(), GetWPCount(), HasEscortState(), mCurrentWPID, CreatureAI::me, mLastWP, mOOCReached, MOTION_SLOT_ACTIVE, MotionMaster::MoveIdle(), MotionMaster::MovementExpired(), Unit::movespline, mWPReached, SmartScript::ProcessEventsFor(), ResumePath(), Creature::SetHomePosition(), Creature::SetPosition(), SMART_ESCORT_ESCORTING, SMART_ESCORT_LAST_OOC_POINT, SMART_ESCORT_PAUSED, SMART_EVENT_ESCORT_REACHED, Unit::StopMovingOnCurrentPos(), WaypointNode::X, WaypointNode::Y, and WaypointNode::Z.

Referenced by MovementInform().

◆ OnCharmed()

void SmartAI::OnCharmed ( bool  apply)
overridevirtual

Called when unit is charmed.

Reimplemented from CreatureAI.

1113{
1114 bool const charmed = me->IsCharmed();
1115 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
1116 {
1118 EndPath(true);
1119 }
1120
1121 mIsCharmed = charmed;
1122
1123 if (charmed && !me->isPossessed() && !me->IsVehicle())
1125
1126 if (!charmed && !me->IsInEvadeMode())
1127 {
1128 if (mCanRepeatPath)
1129 StartPath(mForcedMovement, GetScript()->GetPathId(), true);
1130
1131 if (!me->LastCharmerGUID.IsEmpty())
1132 {
1134 if (Unit* lastCharmer = ObjectAccessor::GetUnit(*me, me->LastCharmerGUID))
1135 me->EngageWithTarget(lastCharmer);
1137
1138 if (!me->IsInCombat())
1140 }
1141 }
1142
1143 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
1144}
@ SMART_EVENT_CHARMED
Definition SmartScriptMgr.h:128
@ EVADE_REASON_NO_HOSTILES
Definition CreatureAI.h:88
bool IsInEvadeMode() const
Definition Creature.h:138
bool IsEmpty() const
Definition ObjectGuid.h:165
void EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER) override
Definition SmartAI.cpp:736
bool IsCharmed() const
Definition Unit.h:1315
Unit * GetCharmer() const
Definition Unit.cpp:7495
bool isPossessed() const
Definition Unit.h:1316
void EngageWithTarget(Unit *who)
Definition Unit.cpp:7306
ObjectGuid LastCharmerGUID
Definition Unit.h:2101
bool IsInCombat() const
Definition Unit.h:941

References ObjectGuid::Clear(), EndPath(), Unit::EngageWithTarget(), EnterEvadeMode(), CreatureAI::EVADE_REASON_NO_HOSTILES, Unit::GetCharmer(), Unit::GetFollowAngle(), Unit::GetMotionMaster(), GetScript(), ObjectAccessor::GetUnit(), HasEscortState(), Creature::HasReactState(), Unit::IsCharmed(), ObjectGuid::IsEmpty(), Unit::IsInCombat(), Creature::IsInEvadeMode(), Unit::isPossessed(), Unit::IsVehicle(), Unit::LastCharmerGUID, mCanRepeatPath, CreatureAI::me, mForcedMovement, mIsCharmed, MotionMaster::MoveFollow(), PET_FOLLOW_DIST, SmartScript::ProcessEventsFor(), REACT_PASSIVE, SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_ESCORT_RETURNING, SMART_EVENT_CHARMED, and StartPath().

◆ OnSpellClick()

void SmartAI::OnSpellClick ( Unit *  clicker,
bool &  result 
)
overridevirtual

Reimplemented from CreatureAI.

1356{
1357 // Xinef: i dont think this is necessery (can be made as event parameter)
1358 //if (!result)
1359 // return;
1360
1362}
@ SMART_EVENT_ON_SPELLCLICK
Definition SmartScriptMgr.h:172

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_ON_SPELLCLICK.

◆ OnSpellFailed()

void SmartAI::OnSpellFailed ( SpellInfo const *  spell)
overridevirtual

Reimplemented from CreatureAI.

1432{
1434
1435 // If another cast or channel is still active, do not resume combat movement
1437 return;
1438
1439 if (_mainSpellId == spell->Id)
1440 {
1442 {
1443 SetCombatMovement(true, false);
1444 SetCurrentRangeMode(false, 0.f);
1445 }
1446 }
1447}
virtual void OnSpellFailed(SpellInfo const *)
Definition CreatureAI.h:174
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3708
bool IsMainSpellPrevented(SpellInfo const *spellInfo) const
Definition SmartAI.cpp:1402

References _currentRangeMode, _mainSpellId, SpellInfo::Id, IsMainSpellPrevented(), Creature::IsMovementPreventedByCasting(), CreatureAI::me, CreatureAI::OnSpellFailed(), SetCombatMovement(), and SetCurrentRangeMode().

◆ PassengerBoarded()

void SmartAI::PassengerBoarded ( Unit *  ,
int8  ,
bool   
)
overridevirtual

== Fields =======================================

Reimplemented from CreatureAI.

1033{
1035}
@ SMART_EVENT_PASSENGER_REMOVED
Definition SmartScriptMgr.h:127
@ SMART_EVENT_PASSENGER_BOARDED
Definition SmartScriptMgr.h:126
void apply(T *val)
Definition ByteConverter.h:40

References GetScript(), SmartScript::ProcessEventsFor(), SMART_EVENT_PASSENGER_BOARDED, and SMART_EVENT_PASSENGER_REMOVED.

◆ PathEndReached()

void SmartAI::PathEndReached ( uint32  pathId)
overridevirtual

Reimplemented from CreatureAI.

1365{
1367 me->LoadPath(0);
1368}
@ SMART_EVENT_WAYPOINT_ENDED
Definition SmartScriptMgr.h:198
void LoadPath(uint32 pathid)
Definition Creature.h:358

References GetScript(), Creature::GetWaypointPath(), Creature::LoadPath(), CreatureAI::me, SmartScript::ProcessEventsFor(), and SMART_EVENT_WAYPOINT_ENDED.

◆ PausePath()

void SmartAI::PausePath ( uint32  delay,
bool  forced = false 
)
303{
305 return;
306
308 {
309 LOG_ERROR("scripts.ai.sai", "SmartAI::StartPath: Creature entry {} wanted to pause waypoint movement while already paused, ignoring.", me->GetEntry());
310 return;
311 }
312
314 mWPPauseTimer = delay;
315 if (forced && !mWPReached)
316 {
317 mForcedPaused = forced;
320
321 me->StopMoving();
322 me->GetMotionMaster()->MoveIdle();//force stop
323
324 if (mCurrentWPID > 0 && mCurrentWPID <= mWayPoints->Nodes.size())
325 {
326 WaypointNode const& waypoint = mWayPoints->Nodes[mCurrentWPID - 1];
327 if (waypoint.Orientation.has_value())
328 me->SetFacingTo(*waypoint.Orientation);
329 }
330 }
332}
@ SMART_EVENT_ESCORT_PAUSED
Definition SmartScriptMgr.h:154
void SetFacingTo(float ori)
Definition Unit.cpp:16068
std::optional< float > Orientation
Definition WaypointDefines.h:49

References AddEscortState(), ESCORT_MOTION_TYPE, Object::GetEntry(), Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), GetScript(), HasEscortState(), LOG_ERROR, mCurrentWPID, CreatureAI::me, mForcedPaused, MOTION_SLOT_ACTIVE, MotionMaster::MoveIdle(), MotionMaster::MovementExpired(), mWayPoints, mWPPauseTimer, mWPReached, WaypointPath::Nodes, WaypointNode::Orientation, SmartScript::ProcessEventsFor(), Unit::SetFacingTo(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_EVENT_ESCORT_PAUSED, and Unit::StopMoving().

◆ Permissible()

static int32 SmartAI::Permissible ( Creature const *  )
inlinestatic
177{ return PERMIT_BASE_NO; }
@ PERMIT_BASE_NO
Definition CreatureAI.h:288

References PERMIT_BASE_NO.

◆ ReceiveEmote()

void SmartAI::ReceiveEmote ( Player *  player,
uint32  textEmote 
)
overridevirtual

Reimplemented from CreatureAI.

1003{
1005}
@ SMART_EVENT_RECEIVE_EMOTE
Definition SmartScriptMgr.h:121

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_RECEIVE_EMOTE.

◆ RemoveEscortState()

void SmartAI::RemoveEscortState ( uint32  uiEscortState)
inline
66{ mEscortState &= ~uiEscortState; }

References mEscortState.

Referenced by EndPath(), and UpdatePath().

◆ ResumePath()

void SmartAI::ResumePath ( )
436{
437 if (mLastWP)
438 {
439 Movement::PointsArray pathPoints;
440 GenerateWayPointArray(&pathPoints);
441
443 }
444}
void MoveSplinePath(Movement::PointsArray *path, ForcedMovement forcedMovement=FORCED_MOVEMENT_NONE)
Definition MotionMaster.cpp:504
void GenerateWayPointArray(Movement::PointsArray *points)
Definition SmartAI.cpp:173
std::vector< Vector3 > PointsArray
Definition MoveSplineInitArgs.h:28

References GenerateWayPointArray(), Unit::GetMotionMaster(), CreatureAI::me, mForcedMovement, mLastWP, and MotionMaster::MoveSplinePath().

Referenced by MovepointReached(), and UpdatePath().

◆ ReturnToLastOOCPos()

void SmartAI::ReturnToLastOOCPos ( )
private
447{
448 if (!IsAIControlled())
449 return;
450
451 float x, y, z, o;
452 me->GetHomePosition(x, y, z, o);
454}
@ FORCED_MOVEMENT_RUN
Definition MotionMaster.h:88
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition Creature.h:349
void MovePoint(uint32 id, Position const &pos, ForcedMovement forcedMovement=FORCED_MOVEMENT_NONE, float speed=0.f, bool generatePath=true, bool forceDestination=true, std::optional< AnimTier > animTier=std::nullopt)
Definition MotionMaster.h:241

References FORCED_MOVEMENT_RUN, Creature::GetHomePosition(), Unit::GetMotionMaster(), IsAIControlled(), CreatureAI::me, MotionMaster::MovePoint(), and SMART_ESCORT_LAST_OOC_POINT.

Referenced by EnterEvadeMode().

◆ SetAutoAttack()

void SmartAI::SetAutoAttack ( bool  on)
inline
67{ mCanAutoAttack = on; }

References mCanAutoAttack.

◆ SetCanRespawn()

void SmartAI::SetCanRespawn ( bool  canSpawn)
inline
219{ mcanSpawn = canSpawn; }

References mcanSpawn.

◆ SetCombatMovement()

void SmartAI::SetCombatMovement ( bool  on,
bool  stopOrStartMovement 
)

◆ SetCurrentRangeMode()

void SmartAI::SetCurrentRangeMode ( bool  on,
float  range = 0.f 
)

◆ SetData() [1/2]

void SmartAI::SetData ( uint32  id,
uint32  value 
)
inlineoverridevirtual

Reimplemented from UnitAI.

167{ SetData(id, value, nullptr); }
void SetData(uint32 id, uint32 value) override
Definition SmartAI.h:167

References SetData().

Referenced by SetData().

◆ SetData() [2/2]

void SmartAI::SetData ( uint32  id,
uint32  value,
WorldObject *  invoker 
)
1161{
1162 Unit* unit = nullptr;
1163 GameObject* gob = nullptr;
1164
1165 if (invoker)
1166 {
1167 unit = invoker->ToUnit();
1168 if (!unit)
1169 gob = invoker->ToGameObject();
1170 }
1171
1172 aiDataSet[id] = value;
1173 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, unit, id, value, false, nullptr, gob);
1174}
@ SMART_EVENT_DATA_SET
Definition SmartScriptMgr.h:137
Definition GameObject.h:120

References aiDataSet, GetScript(), SmartScript::ProcessEventsFor(), SMART_EVENT_DATA_SET, Object::ToGameObject(), and Object::ToUnit().

◆ SetDespawnTime()

void SmartAI::SetDespawnTime ( uint32  t)
inline
203 {
204 mDespawnTime = t;
205 mDespawnState = t ? 1 : 0;
206 }

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

void SmartAI::SetEvadeDisabled ( bool  disable = true)
1198{
1199 mEvadeDisabled = disable;
1200}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
1186{
1187 // xinef: set proper flag!
1188 //me->SetDisableGravity(fly);
1189 me->SetCanFly(fly);
1190}
void SetCanFly(bool enable)
Add the movement flag: MOVEMENTFLAGCAN_FLY. Generaly only use by players, allowing them to fly by pre...
Definition Unit.cpp:16179

References CreatureAI::me, and Unit::SetCanFly().

◆ SetFollow()

void SmartAI::SetFollow ( Unit *  target,
float  dist = 0.0f,
float  angle = 0.0f,
uint32  credit = 0,
uint32  end = 0,
uint32  creditType = 0,
bool  aliveState = true 
)
1292{
1293 if (!target)
1294 {
1295 StopFollow(false);
1296 return;
1297 }
1298
1299 mFollowGuid = target->GetGUID();
1300 mFollowDist = dist;
1301 mFollowAngle = angle;
1302 mFollowArrivedTimer = 1000;
1304 mFollowCredit = credit;
1305 mFollowArrivedEntry = end;
1306 mFollowArrivedAlive = !aliveState; // negate - 0 is alive
1307 mFollowCreditType = creditType;
1309}
void StopFollow(bool complete)
Definition SmartAI.cpp:1311

References _followCheckTimer, Object::GetGUID(), Unit::GetMotionMaster(), CreatureAI::me, mFollowAngle, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mFollowGuid, MOTION_SLOT_ACTIVE, MotionMaster::MoveFollow(), and StopFollow().

◆ SetGUID()

void SmartAI::SetGUID ( ObjectGuid const &  guid,
int32  id = 0 
)
overridevirtual

Reimplemented from UnitAI.

1177{
1178}

◆ SetInvincibilityHpLevel()

void SmartAI::SetInvincibilityHpLevel ( uint32  level)
inline
189{ mInvincibilityHpLevel = level; }

References mInvincibilityHpLevel.

Referenced by SmartScript::ProcessAction().

◆ SetMainSpell()

void SmartAI::SetMainSpell ( uint32  spellId)
1265{
1266 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
1267 if (!spellInfo)
1268 return;
1269
1270 float maxRange = spellInfo->GetMaxRange(false);
1271 if (maxRange <= NOMINAL_MELEE_RANGE)
1272 return;
1273
1274 _mainSpellId = spellId;
1275 _attackDistance = std::max(maxRange - NOMINAL_MELEE_RANGE, 0.0f);
1276 _currentRangeMode = true;
1277}
#define NOMINAL_MELEE_RANGE
Definition ObjectDefines.h:47
float GetMaxRange(bool positive=false, WorldObject *caster=nullptr, Spell *spell=nullptr) const
Definition SpellInfo.cpp:2750

References _attackDistance, _currentRangeMode, _mainSpellId, SpellInfo::GetMaxRange(), NOMINAL_MELEE_RANGE, and sSpellMgr.

Referenced by InitializeAI(), and JustReachedHome().

◆ SetScript9()

void SmartAI::SetScript9 ( SmartScriptHolder &  e,
uint32  entry,
WorldObject *  invoker 
)
1344{
1345 if (invoker)
1346 GetScript()->mLastInvoker = invoker->GetGUID();
1347 GetScript()->SetScript9(e, entry);
1348}
ObjectGuid mLastInvoker
Definition SmartScript.h:200
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition SmartScript.cpp:5595

References Object::GetGUID(), GetScript(), SmartScript::mLastInvoker, and SmartScript::SetScript9().

◆ SetSuppressEvade()

void SmartAI::SetSuppressEvade ( bool  suppress)
inline
187{ mSuppressEvade = suppress; }

References mSuppressEvade.

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
1193{
1194 me->SetSwim(swim);
1195}
bool SetSwim(bool enable) override
Definition Creature.cpp:3404

References CreatureAI::me, and Creature::SetSwim().

◆ SetWPPauseTimer()

void SmartAI::SetWPPauseTimer ( uint32  time)
inline
222{ mWPPauseTimer = time; }

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player *  player)
overridevirtual

Reimplemented from UnitAI.

1203{
1205}
@ SMART_EVENT_GOSSIP_HELLO
Definition SmartScriptMgr.h:163

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_GOSSIP_HELLO.

◆ sGossipSelect()

void SmartAI::sGossipSelect ( Player *  player,
uint32  sender,
uint32  action 
)
overridevirtual

Reimplemented from UnitAI.

1208{
1209 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1210}
@ SMART_EVENT_GOSSIP_SELECT
Definition SmartScriptMgr.h:161

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_GOSSIP_SELECT.

Referenced by npc_stable_master::npc_stable_masterAI::sGossipSelect().

◆ sGossipSelectCode()

void SmartAI::sGossipSelectCode ( Player *  player,
uint32  sender,
uint32  action,
char const *  code 
)
overridevirtual

Reimplemented from UnitAI.

1213{
1214}

◆ sOnGameEvent()

void SmartAI::sOnGameEvent ( bool  start,
uint16  eventId 
)
overridevirtual

Reimplemented from UnitAI.

1351{
1353}
@ SMART_EVENT_GAME_EVENT_START
Definition SmartScriptMgr.h:167
@ SMART_EVENT_GAME_EVENT_END
Definition SmartScriptMgr.h:168

References GetScript(), SmartScript::ProcessEventsFor(), SMART_EVENT_GAME_EVENT_END, and SMART_EVENT_GAME_EVENT_START.

◆ SpellHit()

void SmartAI::SpellHit ( Unit *  unit,
SpellInfo const *  spellInfo 
)
overridevirtual

Reimplemented from CreatureAI.

975{
976 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
977}
@ SMART_EVENT_SPELLHIT
Definition SmartScriptMgr.h:107

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_SPELLHIT.

◆ SpellHitTarget()

void SmartAI::SpellHitTarget ( Unit *  target,
SpellInfo const *  spellInfo 
)
overridevirtual

Reimplemented from CreatureAI.

980{
981 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
982}
@ SMART_EVENT_SPELLHIT_TARGET
Definition SmartScriptMgr.h:130

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_SPELLHIT_TARGET.

◆ sQuestAccept()

void SmartAI::sQuestAccept ( Player *  player,
Quest const *  quest 
)
overridevirtual

Reimplemented from UnitAI.

1217{
1218 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1219}
@ SMART_EVENT_ACCEPTED_QUEST
Definition SmartScriptMgr.h:118

References Quest::GetQuestId(), GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_ACCEPTED_QUEST.

◆ sQuestReward()

void SmartAI::sQuestReward ( Player *  player,
Quest const *  quest,
uint32  opt 
)
overridevirtual

Reimplemented from UnitAI.

1222{
1223 GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
1224}
@ SMART_EVENT_REWARD_QUEST
Definition SmartScriptMgr.h:119

References Quest::GetQuestId(), GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_REWARD_QUEST.

◆ StartDespawn()

void SmartAI::StartDespawn ( )
inline
207{ mDespawnState = 2; }

References mDespawnState.

Referenced by EndPath(), and StopFollow().

◆ StartPath()

void SmartAI::StartPath ( ForcedMovement  forcedMovement = FORCED_MOVEMENT_NONE,
uint32  path = 0,
bool  repeat = false,
Unit *  invoker = nullptr,
PathSource  pathSource = PathSource::SMART_WAYPOINT_MGR 
)
236{
238 StopPath();
239
240 if (path)
241 {
242 if (!LoadPath(path, pathSource))
243 return;
244 }
245
246 if (!mWayPoints || mWayPoints->Nodes.empty())
247 return;
248
249 if (WaypointNode const* wp = GetNextWayPoint())
250 {
252 mCanRepeatPath = repeat;
253 mForcedMovement = forcedMovement;
254
255 if (invoker && invoker->IsPlayer())
256 {
259 }
260
261 Movement::PointsArray pathPoints;
262 GenerateWayPointArray(&pathPoints);
263
265 GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_START, nullptr, wp->Id, GetScript()->GetPathId());
266 }
267}
@ SMART_EVENT_ESCORT_START
Definition SmartScriptMgr.h:138
@ UNIT_NPC_FLAG_NONE
Definition UnitDefines.h:321
bool IsPlayer() const
Definition Object.h:207
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition SmartAI.cpp:334
bool LoadPath(uint32 entry, PathSource pathSource)
Definition SmartAI.cpp:269
NPCFlags GetNpcFlags() const
Clears emote state (looping emote)
Definition Unit.h:763

References AddEscortState(), GenerateWayPointArray(), Unit::GetMotionMaster(), GetNextWayPoint(), Unit::GetNpcFlags(), GetScript(), HasEscortState(), Object::IsPlayer(), LoadPath(), mCanRepeatPath, CreatureAI::me, mEscortNPCFlags, mForcedMovement, MotionMaster::MoveSplinePath(), mWayPoints, WaypointPath::Nodes, SmartScript::ProcessEventsFor(), Unit::ReplaceAllNpcFlags(), SMART_ESCORT_ESCORTING, SMART_EVENT_ESCORT_START, StopPath(), and UNIT_NPC_FLAG_NONE.

Referenced by EndPath(), and OnCharmed().

◆ StopFollow()

void SmartAI::StopFollow ( bool  complete)
1312{
1313 if (complete)
1314 {
1316 if (player && mFollowCredit > 0)
1317 {
1318 if (!mFollowCreditType)
1320 else
1322 }
1323
1324 SetDespawnTime(5000);
1325 StartDespawn();
1326
1328 }
1329
1331 mFollowDist = 0;
1332 mFollowAngle = 0;
1333 mFollowCredit = 0;
1334 mFollowArrivedTimer = 1000;
1337
1338 me->GetMotionMaster()->Clear(false);
1339 me->StopMoving();
1341}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition SmartScriptMgr.h:164
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition Player.cpp:13046
void SetDespawnTime(uint32 t)
Definition SmartAI.h:202
Player * GetPlayer(Map const *, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:244

References ObjectGuid::Clear(), MotionMaster::Clear(), Unit::GetMotionMaster(), ObjectAccessor::GetPlayer(), GetScript(), Player::GroupEventHappens(), CreatureAI::me, mFollowAngle, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mFollowGuid, MotionMaster::MoveIdle(), SmartScript::ProcessEventsFor(), Player::RewardPlayerAndGroupAtEvent(), SetDespawnTime(), SMART_EVENT_FOLLOW_COMPLETED, StartDespawn(), and Unit::StopMoving().

Referenced by SetFollow(), and UpdateFollow().

◆ StopPath()

◆ SummonedCreatureDespawn()

void SmartAI::SummonedCreatureDespawn ( Creature *  unit)
overridevirtual

Reimplemented from CreatureAI.

1018{
1021}
@ SMART_EVENT_SUMMON_DESPAWNED
Definition SmartScriptMgr.h:134
void RemoveCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5717

References Object::GetGUID(), GetScript(), SmartScript::ProcessEventsFor(), SmartScript::RemoveCreatureSummon(), and SMART_EVENT_SUMMON_DESPAWNED.

◆ SummonedCreatureDies()

void SmartAI::SummonedCreatureDies ( Creature *  summon,
Unit *  killer 
)
overridevirtual

Reimplemented from CreatureAI.

938{
940}
@ SMART_EVENT_SUMMONED_UNIT_DIES
Definition SmartScriptMgr.h:183

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_SUMMONED_UNIT_DIES.

◆ SummonedCreatureEvade()

void SmartAI::SummonedCreatureEvade ( Creature *  summon)
overridevirtual

Reimplemented from CreatureAI.

943{
945}
@ SMART_EVENT_SUMMONED_UNIT_EVADE
Definition SmartScriptMgr.h:196

References GetScript(), SmartScript::ProcessEventsFor(), and SMART_EVENT_SUMMONED_UNIT_EVADE.

◆ UpdateAI()

void SmartAI::UpdateAI ( uint32  )
overridevirtual

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

Implements UnitAI.

567{
568 if (!me->IsAlive())
569 {
570 if (IsEngaged())
572 return;
573 }
574
575 CheckConditions(diff);
576
577 bool hasVictim = UpdateVictim();
578 GetScript()->OnUpdate(diff);
579 UpdatePath(diff);
580 UpdateDespawn(diff);
581 UpdateFollow(diff);
582
583 if (!IsAIControlled())
584 {
585 if (CharmInfo* charmInfo = me->GetCharmInfo())
586 {
587 if (charmInfo->IsCommandAttack() && mCanAutoAttack)
588 {
590 }
591 }
592
593 return;
594 }
595
596 if (!hasVictim)
597 return;
598
599 if (mCanAutoAttack)
600 {
603 }
604}
bool IsEngaged() const
Check if creature is currently engaged in combat.
Definition CreatureAI.h:105
void UpdatePath(const uint32 diff)
Definition SmartAI.cpp:456
void UpdateFollow(const uint32 diff)
Definition SmartAI.cpp:115
void UpdateMeleeStance()
Definition SmartAI.cpp:606
void CheckConditions(const uint32 diff)
Definition SmartAI.cpp:537
void UpdateDespawn(const uint32 diff)
Definition SmartAI.cpp:95
void OnUpdate(const uint32 diff)
Definition SmartScript.cpp:5268
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:41
bool IsAlive() const
Definition Unit.h:1796
CharmInfo * GetCharmInfo()
Definition Unit.h:1286
Definition CharmInfo.h:127

References CheckConditions(), UnitAI::DoMeleeAttackIfReady(), CreatureAI::EngagementOver(), Unit::GetCharmInfo(), GetScript(), IsAIControlled(), Unit::IsAlive(), CreatureAI::IsEngaged(), mCanAutoAttack, CreatureAI::me, SmartScript::OnUpdate(), UpdateDespawn(), UpdateFollow(), UpdateMeleeStance(), UpdatePath(), and CreatureAI::UpdateVictim().

◆ UpdateDespawn()

void SmartAI::UpdateDespawn ( const uint32  diff)
private
96{
97 if (mDespawnState <= 1 || mDespawnState > 3)
98 return;
99
100 if (mDespawnTime < diff)
101 {
102 if (mDespawnState == 2)
103 {
104 me->SetVisible(false);
105 mDespawnTime = 5000;
107 }
108 else
110 }
111 else
112 mDespawnTime -= diff;
113}
void DespawnOrUnsummon(Milliseconds msTimeToDespawn=0ms, Seconds forcedRespawnTimer=0s)
Definition Creature.cpp:2216

References Creature::DespawnOrUnsummon(), mDespawnState, mDespawnTime, CreatureAI::me, and Unit::SetVisible().

Referenced by UpdateAI().

◆ UpdateFollow()

void SmartAI::UpdateFollow ( const uint32  diff)
private
116{
117 if (!mFollowGuid)
118 return;
119
120 if (mFollowArrivedTimer < diff)
121 {
123 StopFollow(true);
124 else
125 mFollowArrivedTimer = 1000;
126 }
127 else
128 mFollowArrivedTimer -= diff;
129
130 if (mFollowGuid.IsPlayer())
131 {
132 if (_followCheckTimer < diff)
133 {
134 bool shouldDespawn = false;
136 {
138 if (!me->IsWithinDistInMap(player, checkDist))
139 shouldDespawn = true;
140 }
141 else
142 shouldDespawn = true;
143
144 if (shouldDespawn)
146
147 _followCheckTimer = 1000;
148 }
149 else
150 _followCheckTimer -= diff;
151 }
152}
#define INTERACTION_DISTANCE
Definition ObjectDefines.h:24
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition Object.cpp:2558
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:269

References _followCheckTimer, Creature::DespawnOrUnsummon(), WorldObject::FindNearestCreature(), ObjectAccessor::FindPlayer(), WorldObject::GetInstanceScript(), INTERACTION_DISTANCE, ObjectGuid::IsPlayer(), WorldObject::IsWithinDistInMap(), CreatureAI::me, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowGuid, SMART_ESCORT_MAX_PLAYER_DIST, and StopFollow().

Referenced by UpdateAI().

◆ UpdateMeleeStance()

void SmartAI::UpdateMeleeStance ( )
private
607{
608 // Ranged creatures should not switch to melee stance at distance
610 return;
611
612 Unit* victim = me->GetVictim();
613 if (!victim)
614 return;
615
616 bool const canMelee = me->IsWithinMeleeRange(victim);
618 me->Attack(victim, canMelee);
619}

References _currentRangeMode, Unit::Attack(), Unit::GetVictim(), Unit::HasUnitState(), Unit::IsCrowdControlled(), Unit::IsWithinMeleeRange(), CreatureAI::me, and UNIT_STATE_MELEE_ATTACKING.

Referenced by UpdateAI().

◆ UpdatePath()

void SmartAI::UpdatePath ( const uint32  diff)
private
457{
459 return;
460
461 if (mEscortInvokerCheckTimer < diff)
462 {
463 // Xinef: Escort failed - no players in range
464 // Xinef: Despawn immediately
466 {
467 StopPath(0, mEscortQuestID, true);
468
469 // Xinef: allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
471 me->DespawnOrUnsummon(1ms);
472 return;
473 }
475 }
476 else
478
479 // handle pause
481 {
482 if (mWPPauseTimer < diff)
483 {
485 {
488 if (mForcedPaused)// if paused between 2 wps resend movement
489 {
490 mWPReached = false;
491 mForcedPaused = false;
492 ResumePath();
493 }
494
495 mWPPauseTimer = 0;
496 }
497 }
498 else
499 mWPPauseTimer -= diff;
500 }
501
503 {
504 if (mOOCReached)//reached OOC WP
505 {
506 mOOCReached = false;
509 ResumePath();
510 }
511 }
512
514 return;
515
516 // handle next wp
517 if (!me->HasUnitState(UNIT_STATE_NOT_MOVE) && me->movespline->Finalized())//reached WP
518 {
519 if (!mWPReached)
520 {
521 ResumePath();
522 return;
523 }
524
525 mWPReached = false;
526 if (mCurrentWPID == GetWPCount())
527 EndPath();
528 else if (GetNextWayPoint())
529 {
530 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
531 if (me->movespline->Finalized())
532 ResumePath();
533 }
534 }
535}
@ SMART_EVENT_ESCORT_RESUMED
Definition SmartScriptMgr.h:155
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool IsEscortInvokerInRange()
Definition SmartAI.cpp:621

References Creature::DespawnOrUnsummon(), EndPath(), Movement::MoveSpline::Finalized(), GetNextWayPoint(), GetScript(), Unit::GetVictim(), GetWPCount(), HasEscortState(), Unit::HasUnitState(), IsEscortInvokerInRange(), Unit::IsInCombat(), mCurrentWPID, CreatureAI::me, mEscortInvokerCheckTimer, mEscortQuestID, mForcedPaused, mOOCReached, Unit::movespline, mWPPauseTimer, mWPReached, SmartScript::ProcessEventsFor(), RemoveEscortState(), ResumePath(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_ESCORT_RETURNING, SMART_EVENT_DEATH, SMART_EVENT_ESCORT_RESUMED, StopPath(), and UNIT_STATE_NOT_MOVE.

Referenced by UpdateAI().

◆ WaypointPathEnded()

void SmartAI::WaypointPathEnded ( uint32  nodeId,
uint32  pathId 
)
overridevirtual

Reimplemented from CreatureAI.

1388{
1390 {
1391 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, nodeId, pathId);
1392 return;
1393 }
1394}

References GetScript(), HasEscortState(), SmartScript::ProcessEventsFor(), SMART_ESCORT_ESCORTING, and SMART_EVENT_WAYPOINT_ENDED.

◆ WaypointPathStarted()

void SmartAI::WaypointPathStarted ( uint32  )
overridevirtual

== Waypoints system =============================

Reimplemented from CreatureAI.

1371{
1372}

◆ WaypointReached()

void SmartAI::WaypointReached ( uint32  nodeId,
uint32  pathId 
)
overridevirtual

Reimplemented from CreatureAI.

1379{
1381 {
1382 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, nodeId, pathId);
1383 return;
1384 }
1385}

References GetScript(), HasEscortState(), SmartScript::ProcessEventsFor(), SMART_ESCORT_ESCORTING, and SMART_EVENT_WAYPOINT_REACHED.

◆ WaypointStarted()

void SmartAI::WaypointStarted ( uint32  nodeId,
uint32  pathId 
)
overridevirtual

Reimplemented from CreatureAI.

1375{
1376}

Member Data Documentation

◆ _attackDistance

float SmartAI::_attackDistance
private

◆ _chaseOnInterrupt

bool SmartAI::_chaseOnInterrupt
private

Referenced by SmartAI().

◆ _currentRangeMode

◆ _followCheckTimer

uint32 SmartAI::_followCheckTimer
private

Referenced by SetFollow(), SmartAI(), and UpdateFollow().

◆ _mainSpellId

uint32 SmartAI::_mainSpellId
private

◆ _pendingDistancing

float SmartAI::_pendingDistancing
private

◆ aiDataSet

std::unordered_map<uint32, uint32> SmartAI::aiDataSet
private

◆ conditions

ConditionList SmartAI::conditions
private

Referenced by CheckConditions(), and SmartAI().

◆ m_ConditionsTimer

uint32 SmartAI::m_ConditionsTimer
private

Referenced by CheckConditions(), and SmartAI().

◆ mCanAutoAttack

bool SmartAI::mCanAutoAttack
private

◆ mCanRepeatPath

bool SmartAI::mCanRepeatPath
private

◆ mcanSpawn

bool SmartAI::mcanSpawn
private

Referenced by CanRespawn(), SetCanRespawn(), and SmartAI().

◆ mCurrentWPID

◆ mDespawnState

uint32 SmartAI::mDespawnState
private

◆ mDespawnTime

uint32 SmartAI::mDespawnTime
private

◆ mEscortInvokerCheckTimer

uint32 SmartAI::mEscortInvokerCheckTimer
private

Referenced by SmartAI(), and UpdatePath().

◆ mEscortNPCFlags

uint32 SmartAI::mEscortNPCFlags
private

Referenced by EndPath(), SmartAI(), and StartPath().

◆ mEscortQuestID

uint32 SmartAI::mEscortQuestID

Referenced by EndPath(), SmartAI(), StopPath(), and UpdatePath().

◆ mEscortState

uint32 SmartAI::mEscortState
private

◆ mEvadeDisabled

bool SmartAI::mEvadeDisabled
private

◆ mFollowAngle

float SmartAI::mFollowAngle
private

◆ mFollowArrivedAlive

bool SmartAI::mFollowArrivedAlive
private

◆ mFollowArrivedEntry

uint32 SmartAI::mFollowArrivedEntry
private

◆ mFollowArrivedTimer

uint32 SmartAI::mFollowArrivedTimer
private

◆ mFollowCredit

uint32 SmartAI::mFollowCredit
private

◆ mFollowCreditType

uint32 SmartAI::mFollowCreditType
private

◆ mFollowDist

float SmartAI::mFollowDist
private

◆ mFollowGuid

ObjectGuid SmartAI::mFollowGuid
private

◆ mForcedMovement

ForcedMovement SmartAI::mForcedMovement
private

◆ mForcedPaused

bool SmartAI::mForcedPaused
private

Referenced by PausePath(), SmartAI(), and UpdatePath().

◆ mInvincibilityHpLevel

uint32 SmartAI::mInvincibilityHpLevel
private

◆ mIsCharmed

bool SmartAI::mIsCharmed
private

Referenced by IsAIControlled(), OnCharmed(), and SmartAI().

◆ mJustReset

bool SmartAI::mJustReset
private

◆ mLastWP

WaypointNode const* SmartAI::mLastWP
private

◆ mOOCReached

bool SmartAI::mOOCReached
private

◆ mScript

SmartScript SmartAI::mScript
private

Referenced by GetScript().

◆ mSuppressEvade

bool SmartAI::mSuppressEvade
private

◆ mWayPoints

◆ mWPPauseTimer

uint32 SmartAI::mWPPauseTimer
private

◆ mWPReached

bool SmartAI::mWPReached
private

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