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 ()
 
WaypointData 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 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)
 
SmartScriptGetScript ()
 
bool IsEscortInvokerInRange ()
 
void JustRespawned () override
 
void JustReachedHome () override
 
void JustEngagedWith (Unit *enemy) override
 Called for reaction when initially engaged.
 
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 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, const char *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
 
bool CanRespawn () override
 
void SetCanRespawn (bool canSpawn)
 
void SetWPPauseTimer (uint32 time)
 
void DistancingEnded () 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)
 
WorldObjectGetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon.
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual void SummonedCreatureDespawnAll ()
 
virtual void OnSpellCastFinished (SpellInfo const *, SpellFinishReason)
 
virtual void AttackedBy (Unit *)
 
void DoZoneInCombat (Creature *creature=nullptr, float maxRangeToNearestTarget=250.0f)
 
virtual void OwnerAttackedBy (Unit *)
 
virtual void OwnerAttacked (Unit *)
 
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 ()
 
UnitSelectTarget (SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following:
 
template<class PREDICATE >
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
virtual void JustEnteredCombat (Unit *)
 Called when the unit enters combat.
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat.
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 Called when the creature power updates.
 
virtual void HealDone (Unit *, uint32 &)
 Called when the unit heals.
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 Called during damage calculations.
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 Called during calculation when receiving periodic healing or damage (DoT or HoT)
 
void AttackStartCaster (Unit *victim, float dist)
 
SpellCastResult DoAddAuraToAllHostilePlayers (uint32 spellid)
 
SpellCastResult DoCast (uint32 spellId)
 
SpellCastResult DoCast (Unit *victim, uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastSelf (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastToAllHostilePlayers (uint32 spellid, bool triggered=false)
 To specify the caster as target if the spell is self-cast.
 
SpellCastResult DoCastVictim (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastAOE (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastRandomTarget (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false, bool withTank=true)
 Cast the spell on a random unit from the threat list.
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the top threat target, which may not be the current victim.
 
float DoGetSpellMaxRange (uint32 spellId, bool positive=false)
 
void DoMeleeAttackIfReady ()
 
bool DoSpellAttackIfReady (uint32 spell)
 
void DoSpellAttackToRandomTargetIfReady (uint32 spell, uint32 threatTablePosition=0, float dist=0.f, bool playerOnly=true)
 
virtual void SummonMovementInform (Creature *, uint32, uint32)
 Called when a summon reaches a waypoint or point movement finished.
 
virtual void 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 CheckConditions (const uint32 diff)
 

Private Attributes

bool mIsCharmed
 
uint32 mFollowCreditType
 
uint32 mFollowArrivedTimer
 
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
 
WaypointData const * mLastWP
 
uint32 mEscortNPCFlags
 
bool mCanRepeatPath
 
bool mEvadeDisabled
 
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, uint32aiDataSet
 
bool _currentRangeMode
 
float _attackDistance
 
float _pendingDistancing
 

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 AISpellInfoTypeAISpellInfo
 
- Protected Member Functions inherited from CreatureAI
bool UpdateVictim ()
 
bool UpdateVictimWithGaze ()
 
void SetGazeOn (Unit *target)
 
CreatureDoSummon (uint32 entry, Position const &pos, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummon (uint32 entry, WorldObject *obj, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummonFlyer (uint32 entry, WorldObject *obj, float flightZ, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
bool _EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
- 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

◆ ~SmartAI()

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

◆ SmartAI()

SmartAI::SmartAI ( Creature c)
explicit
30 : CreatureAI(c)
31{
32 mIsCharmed = false;
33 // copy script to local (protection for table reload)
34
35 mWayPoints = nullptr;
37 mCurrentWPID = 0;//first wp id is 1 !!
38 mWPReached = false;
39 mOOCReached = false;
40 mWPPauseTimer = 0;
41 mLastWP = nullptr;
43
44 mCanRepeatPath = false;
45
46 mEvadeDisabled = false;
47
48 mCanAutoAttack = true;
49
50 mForcedPaused = false;
51
53
55
56 mDespawnTime = 0;
57 mDespawnState = 0;
58
60 mFollowDist = 0;
61 mFollowAngle = 0;
62 mFollowCredit = 0;
68
69 mJustReset = false;
70
71 mcanSpawn = true;
72
73 _chaseOnInterrupt = false;
74
75 aiDataSet.clear();
76
77 // Xinef: Vehicle conditions
79 if (me->GetVehicleKit())
81
82 _currentRangeMode = false;
83 _attackDistance = 0.f;
84}
#define sConditionMgr
Definition ConditionMgr.h:291
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
Definition ConditionMgr.h:140
@ FORCED_MOVEMENT_NONE
Definition MotionMaster.h:85
@ SMART_ESCORT_NONE
Definition SmartAI.h:31
Definition CreatureAI.h:71
Creature *const me
Definition CreatureAI.h:73
uint32 GetEntry() const
Definition Object.h:116
uint32 mDespawnTime
Definition SmartAI.h:248
uint32 mEscortState
Definition SmartAI.h:231
uint32 mEscortInvokerCheckTimer
Definition SmartAI.h:251
uint32 mDespawnState
Definition SmartAI.h:249
bool mOOCReached
Definition SmartAI.h:234
uint32 mWPPauseTimer
Definition SmartAI.h:235
bool _chaseOnInterrupt
Definition SmartAI.h:261
uint32 mCurrentWPID
Definition SmartAI.h:232
uint32 m_ConditionsTimer
Definition SmartAI.h:259
bool mIsCharmed
Definition SmartAI.h:217
bool mWPReached
Definition SmartAI.h:233
uint32 mFollowArrivedTimer
Definition SmartAI.h:219
float mFollowAngle
Definition SmartAI.h:225
uint32 mEscortQuestID
Definition SmartAI.h:195
bool _currentRangeMode
Definition SmartAI.h:264
float _attackDistance
Definition SmartAI.h:265
WaypointPath const * mWayPoints
Definition SmartAI.h:230
WaypointData const * mLastWP
Definition SmartAI.h:236
ForcedMovement mForcedMovement
Definition SmartAI.h:244
uint32 mEscortNPCFlags
Definition SmartAI.h:237
ConditionList conditions
Definition SmartAI.h:258
uint32 mFollowCreditType
Definition SmartAI.h:218
bool mFollowArrivedAlive
Definition SmartAI.h:222
bool mcanSpawn
Definition SmartAI.h:254
uint32 mInvincibilityHpLevel
Definition SmartAI.h:243
bool mCanAutoAttack
Definition SmartAI.h:241
bool mJustReset
Definition SmartAI.h:252
bool mCanRepeatPath
Definition SmartAI.h:239
bool mEvadeDisabled
Definition SmartAI.h:240
bool mForcedPaused
Definition SmartAI.h:242
uint32 mFollowCredit
Definition SmartAI.h:220
uint32 mFollowArrivedEntry
Definition SmartAI.h:221
float mFollowDist
Definition SmartAI.h:224
std::unordered_map< uint32, uint32 > aiDataSet
Definition SmartAI.h:262
Vehicle * GetVehicleKit() const
Definition Unit.h:1879

References _attackDistance, _chaseOnInterrupt, _currentRangeMode, 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, 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
748{
749 if (!IsAIControlled())
750 return false;
751
752 // Xinef: if unit has no victim, or victim is player controlled thing
753 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
754 return false;
755
756 //experimental (unknown) flag not present
758 return false;
759
760 // Xinef: victim of unit has to be a player controlled unit
762 return false;
763
764 // Xinef: Check if victim can be assisted
765 if (!me->IsValidAssistTarget(who->GetVictim()))
766 return false;
767
768 //too far away and no free sight?
770 {
771 AttackStart(who);
772 return true;
773 }
774
775 return false;
776}
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition SharedDefines.h:2718
@ SMART_MAX_AID_DIST
Definition SmartAI.h:40
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:208
bool IsPlayer() const
Definition ObjectGuid.h:168
void AttackStart(Unit *who) override
Definition SmartAI.cpp:851
bool IsAIControlled() const
Definition SmartAI.cpp:86
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition Unit.h:1263
Unit * GetVictim() const
Definition Unit.h:886
bool IsValidAssistTarget(Unit const *target) const
Definition Unit.cpp:14082
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:1380
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:1354
uint32 type_flags
Definition CreatureData.h:223

References AttackStart(), CREATURE_TYPE_FLAG_CAN_ASSIST, Unit::GetCharmerOrOwnerOrOwnGUID(), Creature::GetCreatureTemplate(), Unit::GetVictim(), IsAIControlled(), ObjectGuid::IsPlayer(), Unit::IsValidAssistTarget(), 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.

852{
853 // xinef: dont allow charmed npcs to act on their own
855 {
856 if (who)
857 me->Attack(who, mCanAutoAttack);
858 return;
859 }
860
861 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
862 {
864 {
866 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
867 {
869 me->StopMoving();
870 me->GetMotionMaster()->Clear(false);
871 }
872
874 }
875 }
876}
@ MOTION_SLOT_ACTIVE
Definition MotionMaster.h:64
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:201
@ UNIT_FLAG_POSSESSED
Definition UnitDefines.h:278
MovementGeneratorType GetMotionSlotType(int slot) const
Definition MotionMaster.cpp:957
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:314
void MovementExpired(bool reset=true)
Definition MotionMaster.h:195
void Clear(bool reset=true)
Definition MotionMaster.h:182
MotionMaster * GetMotionMaster()
Definition Unit.h:1713
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:732
void StopMoving()
Definition Unit.cpp:16660
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:665
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:10323
bool HasUnitState(const uint32 f) const
Definition Unit.h:721

References Unit::Attack(), MotionMaster::Clear(), ESCORT_MOTION_TYPE, Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), Unit::HasUnitFlag(), Unit::HasUnitState(), Unit::IsWithinMeleeRange(), 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(), MoveInLineOfSight(), and OnCharmed().

◆ CanAIAttack()

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

Reimplemented from UnitAI.

743{
744 return !(me->GetReactState() == REACT_PASSIVE);
745}
@ REACT_PASSIVE
Definition Unit.h:550
ReactStates GetReactState() const
Definition Creature.h:100

References Creature::GetReactState(), CreatureAI::me, and REACT_PASSIVE.

◆ CanRespawn()

bool SmartAI::CanRespawn ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

208{ return mcanSpawn; };

References mcanSpawn.

◆ CheckConditions()

void SmartAI::CheckConditions ( const uint32  diff)
private
495{
496 Vehicle* vehicle = me->GetVehicleKit();
497 if (!vehicle)
498 return;
499
500 if (m_ConditionsTimer < diff)
501 {
502 if (!conditions.empty())
503 {
504 for (SeatMap::iterator itr = vehicle->Seats.begin(); itr != vehicle->Seats.end(); ++itr)
505 if (Unit* passenger = ObjectAccessor::GetUnit(*me, itr->second.Passenger.Guid))
506 {
507 if (Player* player = passenger->ToPlayer())
508 {
509 if (!sConditionMgr->IsObjectMeetToConditions(player, me, conditions))
510 {
511 player->ExitVehicle();
512 return;//check other pessanger in next tick
513 }
514 }
515 }
516 }
517 m_ConditionsTimer = 1000;
518 }
519 else
520 m_ConditionsTimer -= diff;
521}
Player * ToPlayer()
Definition Object.h:202
Definition Player.h:1071
Definition Unit.h:650
Definition Vehicle.h:28
SeatMap Seats
Definition Vehicle.h:56
Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:199

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.

928{
929 GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
930
931 // xinef: end escort upon corpse remove, safe check in case of immediate despawn
932 if (IsEscorted())
933 EndPath(true);
934}
@ SMART_EVENT_CORPSE_REMOVED
Definition SmartScriptMgr.h:135
void EndPath(bool fail=false)
Definition SmartAI.cpp:312
bool IsEscorted() override
Definition SmartAI.h:65
SmartScript * GetScript()
Definition SmartAI.h:75
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:135

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.

917{
919}
@ 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.

889{
890 if (doneBy)
892
893 if (!IsAIControlled()) // don't allow players to use unkillable units
894 return;
895
896 // Xinef: skip nodamage type (eg. instakill effect)
897 if (damagetype != NODAMAGE && mInvincibilityHpLevel && (damage >= me->GetHealth() - mInvincibilityHpLevel))
898 damage = me->GetHealth() - mInvincibilityHpLevel; // damage should not be nullified, because of player damage req.
899}
@ SMART_EVENT_DAMAGED
Definition SmartScriptMgr.h:131
@ NODAMAGE
Definition Unit.h:254
uint32 GetHealth() const
Definition Unit.h:1070

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

◆ DistanceYourself()

void SmartAI::DistanceYourself ( float  range)
1087{
1088 Unit* victim = me->GetVictim();
1089 if (!victim || !victim->IsWithinMeleeRange(me))
1090 return;
1091
1092 float combatReach = me->GetMeleeRange(victim);
1093 float distance = DISTANCING_CONSTANT + std::max(combatReach * 1.5f, combatReach + range);
1094 me->GetMotionMaster()->DistanceYourself(distance);
1095 _pendingDistancing = distance;
1096}
#define DISTANCING_CONSTANT
Definition SmartAI.h:43
void DistanceYourself(float range)
Definition MotionMaster.cpp:352
float _pendingDistancing
Definition SmartAI.h:266
float GetMeleeRange(Unit const *target) const
Definition Unit.cpp:683

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.

1177{
1179 _pendingDistancing = 0.f;
1180}
void SetCurrentRangeMode(bool on, float range=0.f)
Definition SmartAI.cpp:1077

References _pendingDistancing, and SetCurrentRangeMode().

◆ DoAction()

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

Reimplemented from UnitAI.

976{
978}
@ SMART_EVENT_ACTION_DONE
Definition SmartScriptMgr.h:171

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

◆ EndPath()

void SmartAI::EndPath ( bool  fail = false)
313{
315 mWayPoints = nullptr;
316 mLastWP = nullptr;
317 mWPPauseTimer = 0;
318
319 if (mEscortNPCFlags)
320 {
322 mEscortNPCFlags = 0;
323 }
324
326 if (targets && mEscortQuestID)
327 {
328 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
329 {
330 Player* player = targets->front()->ToPlayer();
331 if (Group* group = player->GetGroup())
332 {
333 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
334 {
335 Player* groupGuy = groupRef->GetSource();
336 if (!groupGuy || !player->IsInMap(groupGuy))
337 continue;
338
339 if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
341 else if (fail && groupGuy->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
342 groupGuy->FailQuest(mEscortQuestID);
343 }
344 }
345 else
346 {
347 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
349 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
350 player->FailQuest(mEscortQuestID);
351 }
352 }
353 else
354 {
355 for (WorldObject* target : *targets)
356 {
357 if (GetScript()->IsPlayer(target))
358 {
359 Player* player = target->ToPlayer();
360 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
362 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
363 player->FailQuest(mEscortQuestID);
364 }
365 }
366 }
367 }
368
369 // Xinef: if the escort failed - DO NOT PROCESS ANYTHING
370 // Xinef: End Path events should be only processed if it was SUCCESSFUL stop or stop called by SMART_ACTION_WAYPOINT_STOP
371 if (fail)
372 {
373 mCurrentWPID = 0;
374 return;
375 }
376
378 mCurrentWPID = 0;
379
380 if (mCanRepeatPath)
381 {
382 if (IsAIControlled())
383 StartPath(mForcedMovement, GetScript()->GetPathId(), true);
384 }
385 else
386 GetScript()->SetPathId(0);
387
388 if (mDespawnState == 1)
389 StartDespawn();
390}
@ 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:1996
@ SMART_EVENT_ESCORT_ENDED
Definition SmartScriptMgr.h:157
@ SMART_ESCORT_TARGETS
Definition SmartScriptMgr.h:40
NPCFlags
Non Player Character flags.
Definition UnitDefines.h:317
Definition GroupReference.h:27
Definition Group.h:169
bool HasCorpse() const
Definition Player.h:2037
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition PlayerQuest.cpp:1818
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition Player.cpp:12809
Group * GetGroup()
Definition Player.h:2472
void AreaExploredOrEventHappens(uint32 questId)
Definition PlayerQuest.cpp:1791
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition PlayerQuest.cpp:1430
void FailQuest(uint32 quest_id)
Definition PlayerQuest.cpp:886
void RemoveEscortState(uint32 uiEscortState)
Definition SmartAI.h:66
void StartDespawn()
Definition SmartAI.h:202
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:195
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:751
Definition Object.h:472
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1318

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.

670{
671 if (mEvadeDisabled)
672 {
674 return;
675 }
676
678 {
679 me->AttackStop();
681 return;
682 }
683
684 if (!_EnterEvadeMode())
685 return;
686
688
689 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
690
692 {
695 }
696 else if (mFollowGuid)
697 {
701
702 // xinef: do not forget to reset scripts as we wont call reached home
703 GetScript()->OnReset();
704 }
705 else
706 {
708
709 // xinef: do not forget to reset scripts as we wont call reached home
711 GetScript()->OnReset();
712 }
713}
@ SMART_EVENT_EVADE
Definition SmartScriptMgr.h:106
@ UNIT_STATE_EVADE
Definition UnitDefines.h:191
@ UNIT_FLAG_IN_COMBAT
Definition UnitDefines.h:273
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition CreatureAI.cpp:310
void MoveTargetedHome(bool walk=false)
The unit will return this initial position (owner for pets and summoned creatures)....
Definition MotionMaster.cpp:260
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:446
bool HasEscortState(uint32 uiEscortState)
Definition SmartAI.h:63
void ReturnToLastOOCPos()
Definition SmartAI.cpp:403
void AddEscortState(uint32 uiEscortState)
Definition SmartAI.h:64
ObjectGuid mFollowGuid
Definition SmartAI.h:223
void OnReset()
Definition SmartScript.cpp:109
void ClearUnitState(uint32 f)
Definition Unit.h:722
void AddUnitState(uint32 f)
Definition Unit.h:720
ObjectGuid GetCharmerGUID() const
Definition Unit.h:704
bool AttackStop()
Force the unit to stop attacking. This will clear UNIT_STATE_MELEE_ATTACKING, Interrupt current spell...
Definition Unit.cpp:10479
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:734

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

Referenced by npc_black_morass_summoned_add::EnterEvadeMode().

◆ GenerateWayPointArray()

void SmartAI::GenerateWayPointArray ( Movement::PointsArray points)
130{
131 if (!mWayPoints || mWayPoints->empty())
132 return;
133
134 // Flying unit, just fill array
136 {
137 // xinef: first point in vector is unit real position
138 points->clear();
139 points->push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
140 uint32 wpCounter = mCurrentWPID;
141 auto itr = mWayPoints->find(wpCounter++);
142 do
143 {
144 WaypointData const& wp = (*itr).second;
145 points->push_back(G3D::Vector3(wp.x, wp.y, wp.z));
146
147 itr = mWayPoints->find(wpCounter++);
148 }
149 while (itr != mWayPoints->end());
150 }
151 else
152 {
153 for (float size = 1.0f; size; size *= 0.5f)
154 {
155 std::vector<G3D::Vector3> pVector;
156 // xinef: first point in vector is unit real position
157 pVector.push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
158 uint32 wpCounter = mCurrentWPID;
159
160 uint32 length = (mWayPoints->size() - mCurrentWPID) * size;
161
162 uint32 cnt = 0;
163 for (auto itr = mWayPoints->find(wpCounter); itr != mWayPoints->end() && cnt++ <= length; ++itr)
164 {
165 WaypointData const& wp = (*itr).second;
166 pVector.push_back(G3D::Vector3(wp.x, wp.y, wp.z));
167 }
168
169 if (pVector.size() > 2) // more than source + dest
170 {
171 G3D::Vector3 middle = (pVector[0] + pVector[pVector.size() - 1]) / 2.f;
172 G3D::Vector3 offset;
173
174 bool continueLoop = false;
175 for (uint32 i = 1; i < pVector.size() - 1; ++i)
176 {
177 offset = middle - pVector[i];
178 if (std::fabs(offset.x) >= 0xFF || std::fabs(offset.y) >= 0xFF || std::fabs(offset.z) >= 0x7F)
179 {
180 // offset is too big, split points
181 continueLoop = true;
182 break;
183 }
184 }
185 if (continueLoop)
186 continue;
187 }
188 // everything ok
189 *points = pVector;
190 break;
191 }
192 }
193}
std::uint32_t uint32
Definition Define.h:107
MovementFlags
Definition UnitDefines.h:367
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition UnitDefines.h:379
@ MOVEMENTFLAG_CAN_FLY
Definition UnitDefines.h:393
MovementInfo m_movementInfo
Definition Object.h:693
bool HasMovementFlag(uint32 flag) const
Definition Object.h:346
float GetPositionZ() const
Definition Position.h:123
float GetPositionX() const
Definition Position.h:121
float GetPositionY() const
Definition Position.h:122
Definition WaypointMgr.h:38
float z
Definition WaypointMgr.h:40
float x
Definition WaypointMgr.h:40
float y
Definition WaypointMgr.h:40

References Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), MovementInfo::HasMovementFlag(), WorldObject::m_movementInfo, mCurrentWPID, CreatureAI::me, MOVEMENTFLAG_CAN_FLY, MOVEMENTFLAG_DISABLE_GRAVITY, mWayPoints, WaypointData::x, WaypointData::y, and WaypointData::z.

Referenced by ResumePath(), and StartPath().

◆ GetData()

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

Reimplemented from UnitAI.

981{
982 auto const& itr = aiDataSet.find(id);
983 if (itr != aiDataSet.end())
984 return itr->second;
985
986 return 0;
987}

References aiDataSet.

◆ GetGUID()

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

Reimplemented from UnitAI.

1010{
1011 return ObjectGuid::Empty;
1012}
static ObjectGuid const Empty
Definition ObjectGuid.h:120

References ObjectGuid::Empty.

◆ GetNextWayPoint()

WaypointData const * SmartAI::GetNextWayPoint ( )
112{
113 if (!mWayPoints || mWayPoints->empty())
114 return nullptr;
115
116 mCurrentWPID++;
117 auto itr = mWayPoints->find(mCurrentWPID);
118 if (itr != mWayPoints->end())
119 {
120 mLastWP = &(*itr).second;
121 if (mLastWP->id != mCurrentWPID)
122 LOG_ERROR("scripts.ai.sai", "SmartAI::GetNextWayPoint: Got not expected waypoint id {}, expected {}", mLastWP->id, mCurrentWPID);
123
124 return &(*itr).second;
125 }
126 return nullptr;
127}
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
uint32 id
Definition WaypointMgr.h:39

References WaypointData::id, LOG_ERROR, mCurrentWPID, mLastWP, and mWayPoints.

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

◆ GetScript()

◆ GetWPCount()

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

References mWayPoints.

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.

902{
904}
@ 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.

942{
944 if (!me->isDead())
945 {
946 mJustReset = true;
949 }
950}
@ SMART_EVENT_RESPAWN
Definition SmartScriptMgr.h:110
void JustReachedHome() override
Definition SmartAI.cpp:800
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition SmartScript.cpp:5150
bool isDead() const
Definition Unit.h:1750

References GetScript(), Unit::isDead(), JustReachedHome(), CreatureAI::me, mJustReset, SmartScript::OnInitialize(), SmartScript::ProcessEventsFor(), and SMART_EVENT_RESPAWN.

◆ 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 ( )
569{
570 if (ObjectVector const* targets = GetScript()->GetStoredTargetVector(SMART_ESCORT_TARGETS, *me))
571 {
573 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
574 {
575 Player* player = (*targets->begin())->ToPlayer();
576 if (me->GetDistance(player) <= checkDist)
577 return true;
578
579 if (Group* group = player->GetGroup())
580 {
581 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
582 {
583 Player* groupGuy = groupRef->GetSource();
584
585 if (groupGuy && me->IsInMap(groupGuy) && me->GetDistance(groupGuy) <= checkDist)
586 return true;
587 }
588 }
589 }
590 else
591 {
592 for (WorldObject* target : *targets)
593 {
594 if (GetScript()->IsPlayer(target))
595 {
596 if (me->GetDistance(target->ToPlayer()) <= checkDist)
597 return true;
598 }
599 }
600 }
601
602 // Xinef: no valid target found
603 return false;
604 }
605 // Xinef: no player invoker was stored, just ignore range check
606 return true;
607}
@ SMART_ESCORT_MAX_PLAYER_DIST
Definition SmartAI.h:39
GroupReference * next()
Definition GroupReference.h:36
InstanceScript * GetInstanceScript() const
Definition Object.cpp:1221
float GetDistance(WorldObject const *obj) const
Definition Object.cpp:1278

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

◆ IsSummonedBy()

void SmartAI::IsSummonedBy ( WorldObject summoner)
overridevirtual

Reimplemented from CreatureAI.

912{
913 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
914}
@ SMART_EVENT_JUST_SUMMONED
Definition SmartScriptMgr.h:153
GameObject * ToGameObject()
Definition Object.h:214
Unit * ToUnit()
Definition Object.h:210

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

◆ JustDied()

void SmartAI::JustDied ( Unit killer)
overridevirtual

Reimplemented from CreatureAI.

824{
827 EndPath(true);
828}
@ 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.

Reimplemented from CreatureAI.

816{
817 // Xinef: Interrupt channeled spells
818 if (IsAIControlled())
821}
@ SMART_EVENT_AGGRO
Definition SmartScriptMgr.h:103
@ CURRENT_CHANNELED_SPELL
Definition Unit.h:541
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, bool bySelf=false)
Definition Unit.cpp:4116

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

801{
802 GetScript()->OnReset();
803
804 if (!mJustReset)
805 {
807
810 }
811
812 mJustReset = false;
813}
@ IDLE_MOTION_TYPE
Definition MotionMaster.h:39
@ SMART_EVENT_REACHED_HOME
Definition SmartScriptMgr.h:120
bool UpdateVictim()
Definition CreatureAI.cpp:287
uint32 GetWaypointPath() const
Definition Creature.h:349
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:901
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:949

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

Referenced by InitializeAI(), and JustRespawned().

◆ JustRespawned()

void SmartAI::JustRespawned ( )
overridevirtual

Reimplemented from CreatureAI.

779{
780 mDespawnTime = 0;
781 mDespawnState = 0;
783 me->SetVisible(true);
786 mJustReset = true;
789 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
790 mFollowDist = 0;
791 mFollowAngle = 0;
792 mFollowCredit = 0;
793 mFollowArrivedTimer = 1000;
796 mFollowArrivedAlive = true;
797 aiDataSet.clear();
798}
void Clear()
Definition ObjectGuid.h:138
void SetVisible(bool x)
Definition Unit.cpp:14320
void RestoreFaction()
Definition Unit.cpp:18726
uint32 GetFaction() const
Definition Unit.h:834
uint32 faction
Definition CreatureData.h:198

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.

836{
838 GetScript()->AddCreatureSummon(creature->GetGUID());
839}
@ SMART_EVENT_SUMMONED_UNIT
Definition SmartScriptMgr.h:116
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
void AddCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5422

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

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

831{
833}
@ SMART_EVENT_KILL
Definition SmartScriptMgr.h:104

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

◆ LoadPath()

bool SmartAI::LoadPath ( uint32  entry,
PathSource  pathSource 
)
230{
232 return false;
233
234 switch (pathSource)
235 {
237 {
238 mWayPoints = sSmartWaypointMgr->GetPath(entry);
239 if (!mWayPoints)
240 {
241 GetScript()->SetPathId(0);
242 return false;
243 }
244 break;
245 }
247 {
248 mWayPoints = sWaypointMgr->GetPath(entry);
249 if (!mWayPoints)
250 {
251 GetScript()->SetPathId(0);
252 return false;
253 }
254 break;
255 }
256 }
257
258 GetScript()->SetPathId(entry);
259 return true;
260}
@ SMART_WAYPOINT_MGR
#define sSmartWaypointMgr
Definition SmartScriptMgr.h:2232
#define sWaypointMgr
Definition WaypointMgr.h:79

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.

716{
717 if (!who)
718 return;
719
721
722 if (!IsAIControlled())
723 return;
724
725 if (me->GetVictim())
726 return;
727
729 return;
730
732 {
734 {
737 }
738 AttackStart(who);
739 }
740}
@ UNIT_STATE_DISTRACTED
Definition UnitDefines.h:182
@ REACT_AGGRESSIVE
Definition Unit.h:552
bool CanStartAttack(Unit const *u) const
Definition Creature.cpp:1921
bool HasReactState(ReactStates state) const
Definition Creature.h:101
bool AssistPlayerInCombatAgainst(Unit *who)
Definition SmartAI.cpp:747
void OnMoveInLineOfSight(Unit *who)
Definition SmartScript.cpp:5193

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.

654{
655 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
657
658 if (MovementType == WAYPOINT_MOTION_TYPE)
659 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, Data); // data now corresponds to columns
660
661 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
663 return;
664
665 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
667}
@ 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:609

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)
610{
611 // override the id, path can be resumed any time and counter will reset
612 // mCurrentWPID holds proper id
613
614 // xinef: both point movement and escort generator can enter this function
616 {
617 mOOCReached = true;
618 return;
619 }
620
621 mWPReached = true;
623
624 if (mLastWP)
625 {
628 }
629
631 {
634
637 }
638 // Xinef: Can be unset in ProcessEvents
640 {
641 mWPReached = false;
642 if (mCurrentWPID == GetWPCount())
643 EndPath();
644 else if (GetNextWayPoint())
645 {
646 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
647 if (me->movespline->Finalized())
648 ResumePath();
649 }
650 }
651}
@ SMART_EVENT_ESCORT_REACHED
Definition SmartScriptMgr.h:139
void SetHomePosition(float x, float y, float z, float o)
Definition Creature.h:339
void SetPosition(float x, float y, float z, float o)
Definition Creature.cpp:3172
void MoveIdle()
Definition MotionMaster.cpp:233
bool Finalized() const
Definition MoveSpline.h:116
WaypointData const * GetNextWayPoint()
Definition SmartAI.cpp:111
uint32 GetWPCount()
Definition SmartAI.h:238
void ResumePath()
Definition SmartAI.cpp:392
Movement::MoveSpline * movespline
Definition Unit.h:2071
void StopMovingOnCurrentPos()
Definition Unit.cpp:16699
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(), WaypointData::x, WaypointData::y, and WaypointData::z.

Referenced by MovementInform().

◆ OnCharmed()

void SmartAI::OnCharmed ( bool  apply)
overridevirtual

Called when unit is charmed.

Reimplemented from CreatureAI.

953{
954 bool const charmed = me->IsCharmed();
955 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
956 {
958 EndPath(true);
959 }
960
961 mIsCharmed = charmed;
962
963 if (!charmed && !me->IsInEvadeMode())
964 {
965 if (mCanRepeatPath)
966 StartPath(mForcedMovement, GetScript()->GetPathId(), true);
967
968 if (Unit* charmer = me->GetCharmer())
969 AttackStart(charmer);
970 }
971
972 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
973}
@ SMART_EVENT_CHARMED
Definition SmartScriptMgr.h:128
bool IsInEvadeMode() const
Definition Creature.h:139
bool IsCharmed() const
Definition Unit.h:1277
Unit * GetCharmer() const
Definition Unit.cpp:10684

References AttackStart(), EndPath(), Unit::GetCharmer(), GetScript(), HasEscortState(), Unit::IsCharmed(), Creature::IsInEvadeMode(), mCanRepeatPath, CreatureAI::me, mForcedMovement, mIsCharmed, SmartScript::ProcessEventsFor(), 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.

1162{
1163 // Xinef: i dont think this is necessery (can be made as event parameter)
1164 //if (!result)
1165 // return;
1166
1168}
@ SMART_EVENT_ON_SPELLCLICK
Definition SmartScriptMgr.h:172

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

◆ PassengerBoarded()

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

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

Reimplemented from CreatureAI.

937{
939}
@ 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.

1171{
1173 me->LoadPath(0);
1174}
@ SMART_EVENT_WAYPOINT_ENDED
Definition SmartScriptMgr.h:198
void LoadPath(uint32 pathid)
Definition Creature.h:350

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

◆ PausePath()

void SmartAI::PausePath ( uint32  delay,
bool  forced = false 
)
263{
265 return;
266
268 {
269 LOG_ERROR("scripts.ai.sai", "SmartAI::StartPath: Creature entry {} wanted to pause waypoint movement while already paused, ignoring.", me->GetEntry());
270 return;
271 }
272
274 mWPPauseTimer = delay;
275 if (forced && !mWPReached)
276 {
277 mForcedPaused = forced;
280
281 me->StopMoving();
282 me->GetMotionMaster()->MoveIdle();//force stop
283
284 auto waypoint = mWayPoints->find(mCurrentWPID);
285 if (waypoint->second.orientation.has_value())
286 {
287 me->SetFacingTo(*waypoint->second.orientation);
288 }
289 }
291}
@ SMART_EVENT_ESCORT_PAUSED
Definition SmartScriptMgr.h:154
void SetFacingTo(float ori)
Definition Unit.cpp:20286

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, 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
173{ return PERMIT_BASE_NO; }
@ PERMIT_BASE_NO
Definition CreatureAI.h:251

References PERMIT_BASE_NO.

◆ ReceiveEmote()

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

Reimplemented from CreatureAI.

907{
909}
@ 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 ( )
393{
394 if (mLastWP)
395 {
396 Movement::PointsArray pathPoints;
397 GenerateWayPointArray(&pathPoints);
398
400 }
401}
void MoveSplinePath(Movement::PointsArray *path, ForcedMovement forcedMovement=FORCED_MOVEMENT_NONE)
Definition MotionMaster.cpp:491
void GenerateWayPointArray(Movement::PointsArray *points)
Definition SmartAI.cpp:129
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
404{
405 if (!IsAIControlled())
406 return;
407
408 float x, y, z, o;
409 me->GetHomePosition(x, y, z, o);
411}
@ FORCED_MOVEMENT_RUN
Definition MotionMaster.h:87
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition Creature.h:341
void MovePoint(uint32 id, const Position &pos, ForcedMovement forcedMovement=FORCED_MOVEMENT_NONE, float speed=0.f, bool generatePath=true, bool forceDestination=true)
Definition MotionMaster.h:228

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
209{ mcanSpawn = canSpawn; }

References mcanSpawn.

◆ SetCombatMovement()

void SmartAI::SetCombatMovement ( bool  on,
bool  stopOrStartMovement 
)
1056{
1057 if (on)
1059 else
1061
1063 return;
1064
1065 if (stopOrStartMovement && me->GetVictim()) // Only change current movement while in combat
1066 {
1067 if (!me->IsCrowdControlled())
1068 {
1069 if (on)
1072 me->StopMoving();
1073 }
1074 }
1075}
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45
bool IsCrowdControlled() const
Definition Unit.h:769

References Unit::AddUnitState(), CHASE_MOTION_TYPE, Unit::ClearUnitState(), MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), Unit::GetVictim(), HasEscortState(), IsAIControlled(), Unit::IsCrowdControlled(), CreatureAI::me, MotionMaster::MoveChase(), SMART_ESCORT_ESCORTING, Unit::StopMoving(), and UNIT_STATE_NO_COMBAT_MOVEMENT.

◆ SetCurrentRangeMode()

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

◆ SetData() [1/2]

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

Reimplemented from UnitAI.

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

References SetData().

Referenced by SetData().

◆ SetData() [2/2]

void SmartAI::SetData ( uint32  id,
uint32  value,
WorldObject invoker 
)
990{
991 Unit* unit = nullptr;
992 GameObject* gob = nullptr;
993
994 if (invoker)
995 {
996 unit = invoker->ToUnit();
997 if (!unit)
998 gob = invoker->ToGameObject();
999 }
1000
1001 aiDataSet[id] = value;
1002 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, unit, id, value, false, nullptr, gob);
1003}
@ 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
198 {
199 mDespawnTime = t;
200 mDespawnState = t ? 1 : 0;
201 }

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

void SmartAI::SetEvadeDisabled ( bool  disable = true)
1027{
1028 mEvadeDisabled = disable;
1029}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
1015{
1016 // xinef: set proper flag!
1017 //me->SetDisableGravity(fly);
1018 me->SetCanFly(fly);
1019}
void SetCanFly(bool enable)
Add the movement flag: MOVEMENTFLAGCAN_FLY. Generaly only use by players, allowing them to fly by pre...
Definition Unit.cpp:20397

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 
)
1099{
1100 if (!target)
1101 {
1102 StopFollow(false);
1103 return;
1104 }
1105
1106 mFollowGuid = target->GetGUID();
1107 mFollowDist = dist;
1108 mFollowAngle = angle;
1109 mFollowArrivedTimer = 1000;
1110 mFollowCredit = credit;
1111 mFollowArrivedEntry = end;
1112 mFollowArrivedAlive = !aliveState; // negate - 0 is alive
1113 mFollowCreditType = creditType;
1115}
void StopFollow(bool complete)
Definition SmartAI.cpp:1117

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

◆ SetGUID()

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

Reimplemented from UnitAI.

1006{
1007}

◆ SetInvincibilityHpLevel()

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

References mInvincibilityHpLevel.

Referenced by SmartScript::ProcessAction().

◆ SetScript9()

void SmartAI::SetScript9 ( SmartScriptHolder e,
uint32  entry,
WorldObject invoker 
)
1150{
1151 if (invoker)
1152 GetScript()->mLastInvoker = invoker->GetGUID();
1153 GetScript()->SetScript9(e, entry);
1154}
ObjectGuid mLastInvoker
Definition SmartScript.h:200
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition SmartScript.cpp:5305

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

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
1022{
1023 me->SetSwim(swim);
1024}
bool SetSwim(bool enable) override
Definition Creature.cpp:3233

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

◆ SetWPPauseTimer()

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

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player player)
overridevirtual

Reimplemented from UnitAI.

1032{
1034}
@ 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.

1037{
1038 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1039}
@ 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,
const char *  code 
)
overridevirtual

Reimplemented from UnitAI.

1042{
1043}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

1157{
1159}
@ 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.

879{
880 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
881}
@ 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.

884{
885 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
886}
@ 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.

1046{
1047 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1048}
@ 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.

1051{
1052 GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
1053}
@ SMART_EVENT_REWARD_QUEST
Definition SmartScriptMgr.h:119

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

◆ StartDespawn()

void SmartAI::StartDespawn ( )
inline
202{ 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 
)
196{
198 StopPath();
199
200 if (path)
201 {
202 if (!LoadPath(path, pathSource))
203 return;
204 }
205
206 if (!mWayPoints || mWayPoints->empty())
207 return;
208
209 if (WaypointData const* wp = GetNextWayPoint())
210 {
212 mCanRepeatPath = repeat;
213 mForcedMovement = forcedMovement;
214
215 if (invoker && invoker->IsPlayer())
216 {
219 }
220
221 Movement::PointsArray pathPoints;
222 GenerateWayPointArray(&pathPoints);
223
225 GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_START, nullptr, wp->id, GetScript()->GetPathId());
226 }
227}
@ SMART_EVENT_ESCORT_START
Definition SmartScriptMgr.h:138
@ UNIT_NPC_FLAG_NONE
Definition UnitDefines.h:318
bool IsPlayer() const
Definition Object.h:201
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition SmartAI.cpp:293
bool LoadPath(uint32 entry, PathSource pathSource)
Definition SmartAI.cpp:229
NPCFlags GetNpcFlags() const
Clears emote state (looping emote)
Definition Unit.h:747

References AddEscortState(), GenerateWayPointArray(), Unit::GetMotionMaster(), GetNextWayPoint(), Unit::GetNpcFlags(), GetScript(), HasEscortState(), Object::IsPlayer(), LoadPath(), mCanRepeatPath, CreatureAI::me, mEscortNPCFlags, mForcedMovement, MotionMaster::MoveSplinePath(), mWayPoints, 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)
1118{
1120 mFollowDist = 0;
1121 mFollowAngle = 0;
1122 mFollowCredit = 0;
1123 mFollowArrivedTimer = 1000;
1126
1127 me->GetMotionMaster()->Clear(false);
1128 me->StopMoving();
1130
1131 if (!complete)
1132 return;
1133
1135 if (player)
1136 {
1137 if (!mFollowCreditType)
1139 else
1141 }
1142
1143 SetDespawnTime(5000);
1144 StartDespawn();
1145
1147}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition SmartScriptMgr.h:164
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition Player.cpp:12781
void SetDespawnTime(uint32 t)
Definition SmartAI.h:197
Player * GetPlayer(Map const *, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:220

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

◆ StopPath()

◆ SummonedCreatureDespawn()

void SmartAI::SummonedCreatureDespawn ( Creature unit)
overridevirtual

Reimplemented from CreatureAI.

922{
925}
@ SMART_EVENT_SUMMON_DESPAWNED
Definition SmartScriptMgr.h:134
void RemoveCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5427

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.

842{
844}
@ 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.

847{
849}
@ 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.

524{
525 bool hasVictim = UpdateVictim();
526 CheckConditions(diff);
527 GetScript()->OnUpdate(diff);
528 UpdatePath(diff);
529 UpdateDespawn(diff);
530
531 //TODO move to void
532 if (mFollowGuid)
533 {
534 if (mFollowArrivedTimer < diff)
535 {
537 {
538 StopFollow(true);
539 return;
540 }
541
542 mFollowArrivedTimer = 1000;
543 }
544 else
545 mFollowArrivedTimer -= diff;
546 }
547
548 if (!IsAIControlled())
549 {
550 if (CharmInfo* charmInfo = me->GetCharmInfo())
551 {
552 if (charmInfo->IsCommandAttack() && mCanAutoAttack)
553 {
555 }
556 }
557
558 return;
559 }
560
561 if (!hasVictim)
562 return;
563
564 if (mCanAutoAttack)
566}
#define INTERACTION_DISTANCE
Definition ObjectDefines.h:24
void UpdatePath(const uint32 diff)
Definition SmartAI.cpp:413
void CheckConditions(const uint32 diff)
Definition SmartAI.cpp:494
void UpdateDespawn(const uint32 diff)
Definition SmartAI.cpp:91
void OnUpdate(const uint32 diff)
Definition SmartScript.cpp:4986
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:39
CharmInfo * GetCharmInfo()
Definition Unit.h:1248
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition Object.cpp:2450
Definition CharmInfo.h:127

References CheckConditions(), UnitAI::DoMeleeAttackIfReady(), WorldObject::FindNearestCreature(), Unit::GetCharmInfo(), GetScript(), INTERACTION_DISTANCE, IsAIControlled(), mCanAutoAttack, CreatureAI::me, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowGuid, SmartScript::OnUpdate(), StopFollow(), UpdateDespawn(), UpdatePath(), and CreatureAI::UpdateVictim().

◆ UpdateDespawn()

void SmartAI::UpdateDespawn ( const uint32  diff)
private
92{
93 if (mDespawnState <= 1 || mDespawnState > 3)
94 return;
95
96 if (mDespawnTime < diff)
97 {
98 if (mDespawnState == 2)
99 {
100 me->SetVisible(false);
101 mDespawnTime = 5000;
103 }
104 else
106 }
107 else
108 mDespawnTime -= diff;
109}
void DespawnOrUnsummon(Milliseconds msTimeToDespawn=0ms, Seconds forcedRespawnTimer=0s)
Definition Creature.cpp:2182

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

Referenced by UpdateAI().

◆ UpdatePath()

void SmartAI::UpdatePath ( const uint32  diff)
private
414{
416 return;
417
418 if (mEscortInvokerCheckTimer < diff)
419 {
420 // Xinef: Escort failed - no players in range
421 // Xinef: Despawn immediately
423 {
424 StopPath(0, mEscortQuestID, true);
425
426 // Xinef: allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
428 me->DespawnOrUnsummon(1ms);
429 return;
430 }
432 }
433 else
435
436 // handle pause
438 {
439 if (mWPPauseTimer < diff)
440 {
442 {
445 if (mForcedPaused)// if paused between 2 wps resend movement
446 {
447 mWPReached = false;
448 mForcedPaused = false;
449 ResumePath();
450 }
451
452 mWPPauseTimer = 0;
453 }
454 }
455 else
456 mWPPauseTimer -= diff;
457 }
458
460 {
461 if (mOOCReached)//reached OOC WP
462 {
463 mOOCReached = false;
466 ResumePath();
467 }
468 }
469
471 return;
472
473 // handle next wp
474 if (!me->HasUnitState(UNIT_STATE_NOT_MOVE) && me->movespline->Finalized())//reached WP
475 {
476 if (!mWPReached)
477 {
478 ResumePath();
479 return;
480 }
481
482 mWPReached = false;
483 if (mCurrentWPID == GetWPCount())
484 EndPath();
485 else if (GetNextWayPoint())
486 {
487 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
488 if (me->movespline->Finalized())
489 ResumePath();
490 }
491 }
492}
@ SMART_EVENT_ESCORT_RESUMED
Definition SmartScriptMgr.h:155
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:222
bool IsEscortInvokerInRange()
Definition SmartAI.cpp:568
bool IsInCombat() const
Definition Unit.h:917

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

Member Data Documentation

◆ _attackDistance

float SmartAI::_attackDistance
private

Referenced by SetCurrentRangeMode(), and SmartAI().

◆ _chaseOnInterrupt

bool SmartAI::_chaseOnInterrupt
private

Referenced by SmartAI().

◆ _currentRangeMode

bool SmartAI::_currentRangeMode
private

Referenced by SetCurrentRangeMode(), and SmartAI().

◆ _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

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

◆ 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

WaypointData const* SmartAI::mLastWP
private

◆ mOOCReached

bool SmartAI::mOOCReached
private

◆ mScript

SmartScript SmartAI::mScript
private

Referenced by GetScript().

◆ mWayPoints

◆ mWPPauseTimer

uint32 SmartAI::mWPPauseTimer
private

◆ mWPReached

bool SmartAI::mWPReached
private

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