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 (bool run=false, uint32 path=0, bool repeat=false, Unit *invoker=nullptr)
 
bool LoadPath (uint32 entry)
 
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 ()
 
WayPointGetNextWayPoint ()
 
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 guid, int32 id=0) override
 
ObjectGuid GetGUID (int32 id=0) const override
 
void MovepointReached (uint32 id)
 
void SetRun (bool run=true)
 
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=0s)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table.
 
void Talk (uint8 id, Milliseconds delay)
 
WorldObjectGetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon.
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual 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
 
WPPathmWayPoints
 
uint32 mEscortState
 
uint32 mCurrentWPID
 
bool mWPReached
 
bool mOOCReached
 
uint32 mWPPauseTimer
 
WayPointmLastWP
 
uint32 mEscortNPCFlags
 
bool mCanRepeatPath
 
bool mRun
 
bool mEvadeDisabled
 
bool mCanAutoAttack
 
bool mForcedPaused
 
uint32 mInvincibilityHpLevel
 
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 // spawn in run mode
47 // Xinef: spawn in run mode and set mRun to run... this overrides SetWalk EVERYWHERE
48 mRun = true;
49 mEvadeDisabled = false;
50
51 mCanAutoAttack = true;
52
53 mForcedPaused = false;
54
56
57 mDespawnTime = 0;
58 mDespawnState = 0;
59
61 mFollowDist = 0;
62 mFollowAngle = 0;
63 mFollowCredit = 0;
69
70 mJustReset = false;
71
72 mcanSpawn = true;
73
74 _chaseOnInterrupt = false;
75
76 aiDataSet.clear();
77
78 // Xinef: Vehicle conditions
80 if (me->GetVehicleKit())
82
83 _currentRangeMode = false;
84 _attackDistance = 0.f;
85}
#define sConditionMgr
Definition ConditionMgr.h:291
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
Definition ConditionMgr.h:140
@ 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:251
uint32 mEscortState
Definition SmartAI.h:234
WayPoint * mLastWP
Definition SmartAI.h:239
WPPath * mWayPoints
Definition SmartAI.h:233
uint32 mEscortInvokerCheckTimer
Definition SmartAI.h:254
uint32 mDespawnState
Definition SmartAI.h:252
bool mOOCReached
Definition SmartAI.h:237
uint32 mWPPauseTimer
Definition SmartAI.h:238
bool _chaseOnInterrupt
Definition SmartAI.h:264
uint32 mCurrentWPID
Definition SmartAI.h:235
uint32 m_ConditionsTimer
Definition SmartAI.h:262
bool mIsCharmed
Definition SmartAI.h:220
bool mWPReached
Definition SmartAI.h:236
uint32 mFollowArrivedTimer
Definition SmartAI.h:222
float mFollowAngle
Definition SmartAI.h:228
uint32 mEscortQuestID
Definition SmartAI.h:198
bool _currentRangeMode
Definition SmartAI.h:267
float _attackDistance
Definition SmartAI.h:268
bool mRun
Definition SmartAI.h:243
uint32 mEscortNPCFlags
Definition SmartAI.h:240
ConditionList conditions
Definition SmartAI.h:261
uint32 mFollowCreditType
Definition SmartAI.h:221
bool mFollowArrivedAlive
Definition SmartAI.h:225
bool mcanSpawn
Definition SmartAI.h:257
uint32 mInvincibilityHpLevel
Definition SmartAI.h:247
bool mCanAutoAttack
Definition SmartAI.h:245
bool mJustReset
Definition SmartAI.h:255
bool mCanRepeatPath
Definition SmartAI.h:242
bool mEvadeDisabled
Definition SmartAI.h:244
bool mForcedPaused
Definition SmartAI.h:246
uint32 mFollowCredit
Definition SmartAI.h:223
uint32 mFollowArrivedEntry
Definition SmartAI.h:224
float mFollowDist
Definition SmartAI.h:227
std::unordered_map< uint32, uint32 > aiDataSet
Definition SmartAI.h:265
Vehicle * GetVehicleKit() const
Definition Unit.h:1841

References _attackDistance, _chaseOnInterrupt, _currentRangeMode, aiDataSet, CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, conditions, 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, mForcedPaused, mInvincibilityHpLevel, mIsCharmed, mJustReset, mLastWP, mOOCReached, mRun, 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
736{
737 if (!IsAIControlled())
738 return false;
739
740 // Xinef: if unit has no victim, or victim is player controlled thing
741 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
742 return false;
743
744 //experimental (unknown) flag not present
746 return false;
747
748 // Xinef: victim of unit has to be a player controlled unit
750 return false;
751
752 // Xinef: Check if victim can be assisted
753 if (!me->IsValidAssistTarget(who->GetVictim()))
754 return false;
755
756 //too far away and no free sight?
758 {
759 AttackStart(who);
760 return true;
761 }
762
763 return false;
764}
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition SharedDefines.h:2718
@ SMART_MAX_AID_DIST
Definition SmartAI.h:40
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:209
bool IsPlayer() const
Definition ObjectGuid.h:168
void AttackStart(Unit *who) override
Definition SmartAI.cpp:839
bool IsAIControlled() const
Definition SmartAI.cpp:87
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition Unit.h:1225
Unit * GetVictim() const
Definition Unit.h:850
bool IsValidAssistTarget(Unit const *target) const
Definition Unit.cpp:14095
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:1352
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool useBoundingRadius=true) const
Definition Object.cpp:1326
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.

840{
841 // xinef: dont allow charmed npcs to act on their own
843 {
844 if (who)
845 me->Attack(who, mCanAutoAttack);
846 return;
847 }
848
849 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
850 {
852 {
853 SetRun(mRun);
855 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
856 {
858 me->StopMoving();
859 me->GetMotionMaster()->Clear(false);
860 }
861
863 }
864 }
865}
@ 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:200
@ UNIT_FLAG_POSSESSED
Definition UnitDefines.h:276
MovementGeneratorType GetMotionSlotType(int slot) const
Definition MotionMaster.cpp:956
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Force the unit to chase this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:313
void MovementExpired(bool reset=true)
Definition MotionMaster.h:180
void Clear(bool reset=true)
Definition MotionMaster.h:167
void SetRun(bool run=true)
Definition SmartAI.cpp:1005
MotionMaster * GetMotionMaster()
Definition Unit.h:1676
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:702
void StopMoving()
Definition Unit.cpp:16733
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:666
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:10342
bool HasUnitState(const uint32 f) const
Definition Unit.h:691

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(), mRun, POINT_MOTION_TYPE, SetRun(), 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.

731{
732 return !(me->GetReactState() == REACT_PASSIVE);
733}
@ REACT_PASSIVE
Definition Unit.h:549
ReactStates GetReactState() const
Definition Creature.h:96

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

◆ CanRespawn()

bool SmartAI::CanRespawn ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

211{ return mcanSpawn; };

References mcanSpawn.

◆ CheckConditions()

void SmartAI::CheckConditions ( const uint32  diff)
private
481{
482 Vehicle* vehicle = me->GetVehicleKit();
483 if (!vehicle)
484 return;
485
486 if (m_ConditionsTimer < diff)
487 {
488 if (!conditions.empty())
489 {
490 for (SeatMap::iterator itr = vehicle->Seats.begin(); itr != vehicle->Seats.end(); ++itr)
491 if (Unit* passenger = ObjectAccessor::GetUnit(*me, itr->second.Passenger.Guid))
492 {
493 if (Player* player = passenger->ToPlayer())
494 {
495 if (!sConditionMgr->IsObjectMeetToConditions(player, me, conditions))
496 {
497 player->ExitVehicle();
498 return;//check other pessanger in next tick
499 }
500 }
501 }
502 }
503 m_ConditionsTimer = 1000;
504 }
505 else
506 m_ConditionsTimer -= diff;
507}
Player * ToPlayer()
Definition Object.h:202
Definition Player.h:1072
Definition Unit.h:620
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.

917{
918 GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
919
920 // xinef: end escort upon corpse remove, safe check in case of immediate despawn
921 if (IsEscorted())
922 EndPath(true);
923}
@ SMART_EVENT_CORPSE_REMOVED
Definition SmartScriptMgr.h:154
void EndPath(bool fail=false)
Definition SmartAI.cpp:294
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.

906{
908}
@ SMART_EVENT_DAMAGED_TARGET
Definition SmartScriptMgr.h:151

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.

878{
879 if (doneBy)
881
882 if (!IsAIControlled()) // don't allow players to use unkillable units
883 return;
884
885 // Xinef: skip nodamage type (eg. instakill effect)
886 if (damagetype != NODAMAGE && mInvincibilityHpLevel && (damage >= me->GetHealth() - mInvincibilityHpLevel))
887 damage = me->GetHealth() - mInvincibilityHpLevel; // damage should not be nullified, because of player damage req.
888}
@ SMART_EVENT_DAMAGED
Definition SmartScriptMgr.h:150
@ NODAMAGE
Definition Unit.h:253
uint32 GetHealth() const
Definition Unit.h:1033

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

◆ DistanceYourself()

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

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.

1175{
1177 _pendingDistancing = 0.f;
1178}
void SetCurrentRangeMode(bool on, float range=0.f)
Definition SmartAI.cpp:1074

References _pendingDistancing, and SetCurrentRangeMode().

◆ DoAction()

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

Reimplemented from UnitAI.

967{
969}
@ SMART_EVENT_ACTION_DONE
Definition SmartScriptMgr.h:190

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

◆ EndPath()

void SmartAI::EndPath ( bool  fail = false)
295{
297 mWayPoints = nullptr;
298 mLastWP = nullptr;
299 mWPPauseTimer = 0;
300
301 if (mEscortNPCFlags)
302 {
304 mEscortNPCFlags = 0;
305 }
306
308 if (targets && mEscortQuestID)
309 {
310 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
311 {
312 Player* player = targets->front()->ToPlayer();
313 if (Group* group = player->GetGroup())
314 {
315 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
316 {
317 Player* groupGuy = groupRef->GetSource();
318 if (!groupGuy || !player->IsInMap(groupGuy))
319 continue;
320
321 if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
323 else if (fail && groupGuy->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
324 groupGuy->FailQuest(mEscortQuestID);
325 }
326 }
327 else
328 {
329 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
331 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
332 player->FailQuest(mEscortQuestID);
333 }
334 }
335 else
336 {
337 for (WorldObject* target : *targets)
338 {
339 if (GetScript()->IsPlayer(target))
340 {
341 Player* player = target->ToPlayer();
342 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
344 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
345 player->FailQuest(mEscortQuestID);
346 }
347 }
348 }
349 }
350
351 // Xinef: if the escort failed - DO NOT PROCESS ANYTHING
352 // Xinef: End Path events should be only processed if it was SUCCESSFUL stop or stop called by SMART_ACTION_WAYPOINT_STOP
353 if (fail)
354 {
355 mCurrentWPID = 0;
356 return;
357 }
358
360 mCurrentWPID = 0;
361
362 if (mCanRepeatPath)
363 {
364 if (IsAIControlled())
365 StartPath(mRun, GetScript()->GetPathId(), true);
366 }
367 else
368 GetScript()->SetPathId(0);
369
370 if (mDespawnState == 1)
371 StartDespawn();
372}
@ 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:2015
@ SMART_EVENT_WAYPOINT_ENDED
Definition SmartScriptMgr.h:176
@ SMART_ESCORT_TARGETS
Definition SmartScriptMgr.h:59
NPCFlags
Non Player Character flags.
Definition UnitDefines.h:315
Definition GroupReference.h:27
Definition Group.h:169
bool HasCorpse() const
Definition Player.h:2044
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition PlayerQuest.cpp:1818
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition Player.cpp:12786
Group * GetGroup()
Definition Player.h:2478
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 StartPath(bool run=false, uint32 path=0, bool repeat=false, Unit *invoker=nullptr)
Definition SmartAI.cpp:193
void StartDespawn()
Definition SmartAI.h:205
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:721
Definition Object.h:472
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1290

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, mLastWP, mRun, 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_WAYPOINT_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.

657{
658 if (mEvadeDisabled)
659 {
661 return;
662 }
663
665 {
666 me->AttackStop();
668 return;
669 }
670
671 if (!_EnterEvadeMode())
672 return;
673
675
676 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
677
678 SetRun(mRun);
680 {
683 }
684 else if (mFollowGuid)
685 {
689
690 // xinef: do not forget to reset scripts as we wont call reached home
691 GetScript()->OnReset();
692 }
693 else
694 {
696
697 // xinef: do not forget to reset scripts as we wont call reached home
699 GetScript()->OnReset();
700 }
701}
@ SMART_EVENT_EVADE
Definition SmartScriptMgr.h:125
@ UNIT_STATE_EVADE
Definition UnitDefines.h:191
@ UNIT_FLAG_IN_COMBAT
Definition UnitDefines.h:271
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:259
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:444
bool HasEscortState(uint32 uiEscortState)
Definition SmartAI.h:63
void ReturnToLastOOCPos()
Definition SmartAI.cpp:387
void AddEscortState(uint32 uiEscortState)
Definition SmartAI.h:64
ObjectGuid mFollowGuid
Definition SmartAI.h:226
void OnReset()
Definition SmartScript.cpp:109
void ClearUnitState(uint32 f)
Definition Unit.h:692
void AddUnitState(uint32 f)
Definition Unit.h:690
ObjectGuid GetCharmerGUID() const
Definition Unit.h:674
bool AttackStop()
Force the unit to stop attacking. This will clear UNIT_STATE_MELEE_ATTACKING, Interrupt current spell...
Definition Unit.cpp:10498
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:704

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(), mRun, SmartScript::OnReset(), SmartScript::ProcessEventsFor(), Unit::RemoveUnitFlag(), ReturnToLastOOCPos(), SetRun(), 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)
131{
132 if (!mWayPoints || mWayPoints->empty())
133 return;
134
135 // Flying unit, just fill array
137 {
138 // xinef: first point in vector is unit real position
139 points->clear();
140 points->push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
141 uint32 wpCounter = mCurrentWPID;
142 WPPath::const_iterator itr;
143 while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end())
144 {
145 WayPoint* wp = (*itr).second;
146 points->push_back(G3D::Vector3(wp->x, wp->y, wp->z));
147 }
148 }
149 else
150 {
151 for (float size = 1.0f; size; size *= 0.5f)
152 {
153 std::vector<G3D::Vector3> pVector;
154 // xinef: first point in vector is unit real position
155 pVector.push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
156 uint32 length = (mWayPoints->size() - mCurrentWPID) * size;
157
158 uint32 cnt = 0;
159 uint32 wpCounter = mCurrentWPID;
160 WPPath::const_iterator itr;
161 while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end() && cnt++ <= length)
162 {
163 WayPoint* wp = (*itr).second;
164 pVector.push_back(G3D::Vector3(wp->x, wp->y, wp->z));
165 }
166
167 if (pVector.size() > 2) // more than source + dest
168 {
169 G3D::Vector3 middle = (pVector[0] + pVector[pVector.size() - 1]) / 2.f;
170 G3D::Vector3 offset;
171
172 bool continueLoop = false;
173 for (uint32 i = 1; i < pVector.size() - 1; ++i)
174 {
175 offset = middle - pVector[i];
176 if (std::fabs(offset.x) >= 0xFF || std::fabs(offset.y) >= 0xFF || std::fabs(offset.z) >= 0x7F)
177 {
178 // offset is too big, split points
179 continueLoop = true;
180 break;
181 }
182 }
183 if (continueLoop)
184 continue;
185 }
186 // everything ok
187 *points = pVector;
188 break;
189 }
190 }
191}
std::uint32_t uint32
Definition Define.h:107
MovementFlags
Definition UnitDefines.h:365
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition UnitDefines.h:377
@ MOVEMENTFLAG_CAN_FLY
Definition UnitDefines.h:391
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 SmartScriptMgr.h:33
float z
Definition SmartScriptMgr.h:47
float y
Definition SmartScriptMgr.h:46
float x
Definition SmartScriptMgr.h:45

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

Referenced by ResumePath(), and StartPath().

◆ GetData()

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

Reimplemented from UnitAI.

972{
973 auto const& itr = aiDataSet.find(id);
974 if (itr != aiDataSet.end())
975 return itr->second;
976
977 return 0;
978}

References aiDataSet.

◆ GetGUID()

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

Reimplemented from UnitAI.

1001{
1002 return ObjectGuid::Empty;
1003}
static ObjectGuid const Empty
Definition ObjectGuid.h:120

References ObjectGuid::Empty.

◆ GetNextWayPoint()

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

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

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

◆ GetScript()

◆ GetWPCount()

uint32 SmartAI::GetWPCount ( )
inlineprivate
241{ 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.

891{
893}
@ SMART_EVENT_RECEIVE_HEAL
Definition SmartScriptMgr.h:171

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

◆ InitializeAI()

void SmartAI::InitializeAI ( )
overridevirtual

Reimplemented from UnitAI.

931{
933 if (!me->isDead())
934 {
935 mJustReset = true;
938 }
939}
@ SMART_EVENT_RESPAWN
Definition SmartScriptMgr.h:129
void JustReachedHome() override
Definition SmartAI.cpp:788
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition SmartScript.cpp:5152
bool isDead() const
Definition Unit.h:1712

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 ( )
555{
556 if (ObjectVector const* targets = GetScript()->GetStoredTargetVector(SMART_ESCORT_TARGETS, *me))
557 {
559 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
560 {
561 Player* player = (*targets->begin())->ToPlayer();
562 if (me->GetDistance(player) <= checkDist)
563 return true;
564
565 if (Group* group = player->GetGroup())
566 {
567 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
568 {
569 Player* groupGuy = groupRef->GetSource();
570
571 if (groupGuy && me->IsInMap(groupGuy) && me->GetDistance(groupGuy) <= checkDist)
572 return true;
573 }
574 }
575 }
576 else
577 {
578 for (WorldObject* target : *targets)
579 {
580 if (GetScript()->IsPlayer(target))
581 {
582 if (me->GetDistance(target->ToPlayer()) <= checkDist)
583 return true;
584 }
585 }
586 }
587
588 // Xinef: no valid target found
589 return false;
590 }
591 // Xinef: no player invoker was stored, just ignore range check
592 return true;
593}
@ SMART_ESCORT_MAX_PLAYER_DIST
Definition SmartAI.h:39
GroupReference * next()
Definition GroupReference.h:36
InstanceScript * GetInstanceScript() const
Definition Object.cpp:1197
float GetDistance(WorldObject const *obj) const
Definition Object.cpp:1250

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.

901{
902 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
903}
@ SMART_EVENT_JUST_SUMMONED
Definition SmartScriptMgr.h:172
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.

812{
815 EndPath(true);
816}
@ SMART_EVENT_DEATH
Definition SmartScriptMgr.h:124

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.

804{
805 // Xinef: Interrupt channeled spells
806 if (IsAIControlled())
809}
@ SMART_EVENT_AGGRO
Definition SmartScriptMgr.h:122
@ CURRENT_CHANNELED_SPELL
Definition Unit.h:540
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, bool bySelf=false)
Definition Unit.cpp:4113

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

789{
790 GetScript()->OnReset();
791
792 if (!mJustReset)
793 {
795
798 }
799
800 mJustReset = false;
801}
@ IDLE_MOTION_TYPE
Definition MotionMaster.h:39
@ SMART_EVENT_REACHED_HOME
Definition SmartScriptMgr.h:139
bool UpdateVictim()
Definition CreatureAI.cpp:287
uint32 GetWaypointPath() const
Definition Creature.h:351
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:948
void MovePath(uint32 path_id, bool repeatable)
Move the unit following a specific path. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:887

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

Referenced by InitializeAI(), and JustRespawned().

◆ JustRespawned()

void SmartAI::JustRespawned ( )
overridevirtual

Reimplemented from CreatureAI.

767{
768 mDespawnTime = 0;
769 mDespawnState = 0;
771 me->SetVisible(true);
774 mJustReset = true;
777 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
778 mFollowDist = 0;
779 mFollowAngle = 0;
780 mFollowCredit = 0;
781 mFollowArrivedTimer = 1000;
784 mFollowArrivedAlive = true;
785 aiDataSet.clear();
786}
void Clear()
Definition ObjectGuid.h:138
void SetVisible(bool x)
Definition Unit.cpp:14333
void RestoreFaction()
Definition Unit.cpp:18792
uint32 GetFaction() const
Definition Unit.h:803
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.

824{
826 GetScript()->AddCreatureSummon(creature->GetGUID());
827}
@ SMART_EVENT_SUMMONED_UNIT
Definition SmartScriptMgr.h:135
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
void AddCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5424

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

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

819{
821}
@ SMART_EVENT_KILL
Definition SmartScriptMgr.h:123

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

◆ LoadPath()

bool SmartAI::LoadPath ( uint32  entry)
228{
230 return false;
231
232 mWayPoints = sSmartWaypointMgr->GetPath(entry);
233 if (!mWayPoints)
234 {
235 GetScript()->SetPathId(0);
236 return false;
237 }
238
239 GetScript()->SetPathId(entry);
240 return true;
241}
#define sSmartWaypointMgr
Definition SmartScriptMgr.h:2251

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

Referenced by StartPath().

◆ MoveInLineOfSight()

void SmartAI::MoveInLineOfSight ( Unit who)
overridevirtual

Reimplemented from CreatureAI.

704{
705 if (!who)
706 return;
707
709
710 if (!IsAIControlled())
711 return;
712
713 if (me->GetVictim())
714 return;
715
717 return;
718
720 {
722 {
725 }
726 AttackStart(who);
727 }
728}
@ UNIT_STATE_DISTRACTED
Definition UnitDefines.h:182
@ REACT_AGGRESSIVE
Definition Unit.h:551
bool CanStartAttack(Unit const *u) const
Definition Creature.cpp:1919
bool HasReactState(ReactStates state) const
Definition Creature.h:97
bool AssistPlayerInCombatAgainst(Unit *who)
Definition SmartAI.cpp:735
void OnMoveInLineOfSight(Unit *who)
Definition SmartScript.cpp:5195

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.

641{
642 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
644
645 if (MovementType == WAYPOINT_MOTION_TYPE)
646 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_REACHED, nullptr, Data + 1); // Data + 1 to align smart_scripts and waypoint_data Id rows
647
648 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
650 return;
651
652 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
654}
@ WAYPOINT_MOTION_TYPE
Definition MotionMaster.h:41
@ SMART_EVENT_MOVEMENTINFORM
Definition SmartScriptMgr.h:152
@ SMART_EVENT_WAYPOINT_DATA_REACHED
Definition SmartScriptMgr.h:216
@ SMART_ESCORT_LAST_OOC_POINT
Definition SmartScriptMgr.h:57
Data
Definition blackfathom_deeps.h:24
void MovepointReached(uint32 id)
Definition SmartAI.cpp:595

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_DATA_REACHED, UNIT_STATE_EVADE, and WAYPOINT_MOTION_TYPE.

◆ MovepointReached()

void SmartAI::MovepointReached ( uint32  id)
596{
597 // override the id, path can be resumed any time and counter will reset
598 // mCurrentWPID holds proper id
599
600 // xinef: both point movement and escort generator can enter this function
602 {
603 mOOCReached = true;
604 return;
605 }
606
607 mWPReached = true;
609
610 if (mLastWP)
611 {
614 }
615
617 {
620
623 }
624 // Xinef: Can be unset in ProcessEvents
626 {
627 mWPReached = false;
628 if (mCurrentWPID == GetWPCount())
629 EndPath();
630 else if (GetNextWayPoint())
631 {
632 SetRun(mRun);
633 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
634 if (me->movespline->Finalized())
635 ResumePath();
636 }
637 }
638}
@ SMART_EVENT_WAYPOINT_REACHED
Definition SmartScriptMgr.h:158
void SetHomePosition(float x, float y, float z, float o)
Definition Creature.h:341
void SetPosition(float x, float y, float z, float o)
Definition Creature.cpp:3170
void MoveIdle()
Definition MotionMaster.cpp:232
bool Finalized() const
Definition MoveSpline.h:116
WayPoint * GetNextWayPoint()
Definition SmartAI.cpp:112
uint32 GetWPCount()
Definition SmartAI.h:241
void ResumePath()
Definition SmartAI.cpp:374
Movement::MoveSpline * movespline
Definition Unit.h:2032
void StopMovingOnCurrentPos()
Definition Unit.cpp:16772
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, mRun, mWPReached, SmartScript::ProcessEventsFor(), ResumePath(), Creature::SetHomePosition(), Creature::SetPosition(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_LAST_OOC_POINT, SMART_ESCORT_PAUSED, SMART_EVENT_WAYPOINT_REACHED, Unit::StopMovingOnCurrentPos(), WayPoint::x, WayPoint::y, and WayPoint::z.

Referenced by MovementInform().

◆ OnCharmed()

void SmartAI::OnCharmed ( bool  apply)
overridevirtual

Called when unit is charmed.

Reimplemented from CreatureAI.

942{
943 bool const charmed = me->IsCharmed();
944 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
945 {
947 EndPath(true);
948 }
949
950 mIsCharmed = charmed;
951
952 if (!charmed && !me->IsInEvadeMode())
953 {
954 if (mCanRepeatPath)
955 StartPath(mRun, GetScript()->GetPathId(), true);
956 else
957 me->SetWalk(!mRun);
958
959 if (Unit* charmer = me->GetCharmer())
960 AttackStart(charmer);
961 }
962
963 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
964}
@ SMART_EVENT_CHARMED
Definition SmartScriptMgr.h:147
bool SetWalk(bool enable) override
Enable or disable the creature's walk mode by removing: MOVEMENTFLAG_WALKING. Infom also the client.
Definition Creature.cpp:3207
bool IsInEvadeMode() const
Definition Creature.h:135
bool IsCharmed() const
Definition Unit.h:1239
Unit * GetCharmer() const
Definition Unit.cpp:10703

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

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

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

◆ PassengerBoarded()

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

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

Reimplemented from CreatureAI.

926{
928}
@ SMART_EVENT_PASSENGER_REMOVED
Definition SmartScriptMgr.h:146
@ SMART_EVENT_PASSENGER_BOARDED
Definition SmartScriptMgr.h:145
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.

1169{
1171 me->LoadPath(0);
1172}
@ SMART_EVENT_WAYPOINT_DATA_ENDED
Definition SmartScriptMgr.h:217
void LoadPath(uint32 pathid)
Definition Creature.h:352

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

◆ PausePath()

void SmartAI::PausePath ( uint32  delay,
bool  forced = false 
)
244{
246 return;
247
249 {
250 LOG_ERROR("scripts.ai.sai", "SmartAI::StartPath: Creature entry {} wanted to pause waypoint movement while already paused, ignoring.", me->GetEntry());
251 return;
252 }
253
255 mWPPauseTimer = delay;
256 if (forced && !mWPReached)
257 {
258 mForcedPaused = forced;
259 SetRun(mRun);
262
263 me->StopMoving();
264 me->GetMotionMaster()->MoveIdle();//force stop
265
266 auto waypoint = mWayPoints->find(mCurrentWPID);
267 if (waypoint->second->o.has_value())
268 {
269 me->SetFacingTo(waypoint->second->o.has_value());
270 }
271 }
273}
@ SMART_EVENT_WAYPOINT_PAUSED
Definition SmartScriptMgr.h:173
void SetFacingTo(float ori)
Definition Unit.cpp:20369

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(), mRun, mWayPoints, mWPPauseTimer, mWPReached, SmartScript::ProcessEventsFor(), Unit::SetFacingTo(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_EVENT_WAYPOINT_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.

896{
898}
@ SMART_EVENT_RECEIVE_EMOTE
Definition SmartScriptMgr.h:140

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 ( )
375{
376 SetRun(mRun);
377
378 if (mLastWP)
379 {
380 Movement::PointsArray pathPoints;
381 GenerateWayPointArray(&pathPoints);
382
383 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
384 }
385}
void MoveSplinePath(Movement::PointsArray *path)
Definition MotionMaster.cpp:489
void GenerateWayPointArray(Movement::PointsArray *points)
Definition SmartAI.cpp:130
std::vector< Vector3 > PointsArray
Definition MoveSplineInitArgs.h:28

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

Referenced by MovepointReached(), and UpdatePath().

◆ ReturnToLastOOCPos()

void SmartAI::ReturnToLastOOCPos ( )
private
388{
389 if (!IsAIControlled())
390 return;
391
392 me->SetWalk(false);
393 float x, y, z, o;
394 me->GetHomePosition(x, y, z, o);
396}
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition Creature.h:343
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition MotionMaster.h:213

References Creature::GetHomePosition(), Unit::GetMotionMaster(), IsAIControlled(), CreatureAI::me, MotionMaster::MovePoint(), Creature::SetWalk(), 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
212{ mcanSpawn = canSpawn; }

References mcanSpawn.

◆ SetCombatMovement()

void SmartAI::SetCombatMovement ( bool  on,
bool  stopOrStartMovement 
)
1053{
1054 if (on)
1056 else
1058
1060 return;
1061
1062 if (stopOrStartMovement && me->GetVictim()) // Only change current movement while in combat
1063 {
1064 if (!me->IsCrowdControlled())
1065 {
1066 if (on)
1069 me->StopMoving();
1070 }
1071 }
1072}
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45
bool IsCrowdControlled() const
Definition Unit.h:739

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 
)
981{
982 Unit* unit = nullptr;
983 GameObject* gob = nullptr;
984
985 if (invoker)
986 {
987 unit = invoker->ToUnit();
988 if (!unit)
989 gob = invoker->ToGameObject();
990 }
991
992 aiDataSet[id] = value;
993 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, unit, id, value, false, nullptr, gob);
994}
@ SMART_EVENT_DATA_SET
Definition SmartScriptMgr.h:156
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
201 {
202 mDespawnTime = t;
203 mDespawnState = t ? 1 : 0;
204 }

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

void SmartAI::SetEvadeDisabled ( bool  disable = true)
1024{
1025 mEvadeDisabled = disable;
1026}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
1012{
1013 // xinef: set proper flag!
1014 //me->SetDisableGravity(fly);
1015 me->SetCanFly(fly);
1016}
bool SetCanFly(bool enable, bool packetOnly=false) override
Add the movement flag: MOVEMENTFLAGCAN_FLY. Generaly only use by players, allowing them to fly by pre...
Definition Creature.cpp:3306

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

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

◆ SetGUID()

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

Reimplemented from UnitAI.

997{
998}

◆ SetInvincibilityHpLevel()

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

References mInvincibilityHpLevel.

Referenced by SmartScript::ProcessAction().

◆ SetRun()

void SmartAI::SetRun ( bool  run = true)

◆ SetScript9()

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

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

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
1019{
1020 me->SetSwim(swim);
1021}
bool SetSwim(bool enable) override
Definition Creature.cpp:3258

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

◆ SetWPPauseTimer()

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

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player player)
overridevirtual

Reimplemented from UnitAI.

1029{
1031}
@ SMART_EVENT_GOSSIP_HELLO
Definition SmartScriptMgr.h:182

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

◆ sGossipSelect()

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

Reimplemented from UnitAI.

1034{
1035 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1036}
@ SMART_EVENT_GOSSIP_SELECT
Definition SmartScriptMgr.h:180

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.

1039{
1040}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

1155{
1157}
@ SMART_EVENT_GAME_EVENT_START
Definition SmartScriptMgr.h:186
@ SMART_EVENT_GAME_EVENT_END
Definition SmartScriptMgr.h:187

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.

868{
869 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
870}
@ SMART_EVENT_SPELLHIT
Definition SmartScriptMgr.h:126

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

◆ SpellHitTarget()

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

Reimplemented from CreatureAI.

873{
874 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
875}
@ SMART_EVENT_SPELLHIT_TARGET
Definition SmartScriptMgr.h:149

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

◆ sQuestAccept()

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

Reimplemented from UnitAI.

1043{
1044 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1045}
@ SMART_EVENT_ACCEPTED_QUEST
Definition SmartScriptMgr.h:137

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.

1048{
1049 GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
1050}
@ SMART_EVENT_REWARD_QUEST
Definition SmartScriptMgr.h:138

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

◆ StartDespawn()

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

References mDespawnState.

Referenced by EndPath(), and StopFollow().

◆ StartPath()

void SmartAI::StartPath ( bool  run = false,
uint32  path = 0,
bool  repeat = false,
Unit invoker = nullptr 
)
194{
196 StopPath();
197
198 if (path)
199 {
200 if (!LoadPath(path))
201 return;
202 }
203
204 if (!mWayPoints || mWayPoints->empty())
205 return;
206
207 if (WayPoint* wp = GetNextWayPoint())
208 {
210 mCanRepeatPath = repeat;
211 SetRun(run);
212
213 if (invoker && invoker->IsPlayer())
214 {
217 }
218
219 Movement::PointsArray pathPoints;
220 GenerateWayPointArray(&pathPoints);
221
222 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
223 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
224 }
225}
@ SMART_EVENT_WAYPOINT_START
Definition SmartScriptMgr.h:157
@ UNIT_NPC_FLAG_NONE
Definition UnitDefines.h:316
bool IsPlayer() const
Definition Object.h:201
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition SmartAI.cpp:275
bool LoadPath(uint32 entry)
Definition SmartAI.cpp:227
NPCFlags GetNpcFlags() const
Clears emote state (looping emote)
Definition Unit.h:717

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

Referenced by EndPath(), and OnCharmed().

◆ StopFollow()

void SmartAI::StopFollow ( bool  complete)
1116{
1118 mFollowDist = 0;
1119 mFollowAngle = 0;
1120 mFollowCredit = 0;
1121 mFollowArrivedTimer = 1000;
1124
1125 me->GetMotionMaster()->Clear(false);
1126 me->StopMoving();
1128
1129 if (!complete)
1130 return;
1131
1133 if (player)
1134 {
1135 if (!mFollowCreditType)
1137 else
1139 }
1140
1141 SetDespawnTime(5000);
1142 StartDespawn();
1143
1145}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition SmartScriptMgr.h:183
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition Player.cpp:12758
void SetDespawnTime(uint32 t)
Definition SmartAI.h:200
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.

911{
914}
@ SMART_EVENT_SUMMON_DESPAWNED
Definition SmartScriptMgr.h:153
void RemoveCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5429

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.

830{
832}
@ SMART_EVENT_SUMMONED_UNIT_DIES
Definition SmartScriptMgr.h:202

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

◆ SummonedCreatureEvade()

void SmartAI::SummonedCreatureEvade ( Creature summon)
overridevirtual

Reimplemented from CreatureAI.

835{
837}
@ SMART_EVENT_SUMMONED_UNIT_EVADE
Definition SmartScriptMgr.h:215

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.

510{
511 bool hasVictim = UpdateVictim();
512 CheckConditions(diff);
513 GetScript()->OnUpdate(diff);
514 UpdatePath(diff);
515 UpdateDespawn(diff);
516
517 //TODO move to void
518 if (mFollowGuid)
519 {
520 if (mFollowArrivedTimer < diff)
521 {
523 {
524 StopFollow(true);
525 return;
526 }
527
528 mFollowArrivedTimer = 1000;
529 }
530 else
531 mFollowArrivedTimer -= diff;
532 }
533
534 if (!IsAIControlled())
535 {
536 if (CharmInfo* charmInfo = me->GetCharmInfo())
537 {
538 if (charmInfo->IsCommandAttack() && mCanAutoAttack)
539 {
541 }
542 }
543
544 return;
545 }
546
547 if (!hasVictim)
548 return;
549
550 if (mCanAutoAttack)
552}
#define INTERACTION_DISTANCE
Definition ObjectDefines.h:24
void UpdatePath(const uint32 diff)
Definition SmartAI.cpp:398
void CheckConditions(const uint32 diff)
Definition SmartAI.cpp:480
void UpdateDespawn(const uint32 diff)
Definition SmartAI.cpp:92
void OnUpdate(const uint32 diff)
Definition SmartScript.cpp:4988
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:39
CharmInfo * GetCharmInfo()
Definition Unit.h:1210
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition Object.cpp:2425
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
93{
94 if (mDespawnState <= 1 || mDespawnState > 3)
95 return;
96
97 if (mDespawnTime < diff)
98 {
99 if (mDespawnState == 2)
100 {
101 me->SetVisible(false);
102 mDespawnTime = 5000;
104 }
105 else
107 }
108 else
109 mDespawnTime -= diff;
110}
void DespawnOrUnsummon(Milliseconds msTimeToDespawn, Seconds forcedRespawnTimer)
Definition Creature.cpp:2180

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

Referenced by UpdateAI().

◆ UpdatePath()

void SmartAI::UpdatePath ( const uint32  diff)
private
399{
401 return;
402
403 if (mEscortInvokerCheckTimer < diff)
404 {
405 // Xinef: Escort failed - no players in range
406 // Xinef: Despawn immediately
408 {
409 StopPath(0, mEscortQuestID, true);
410
411 // Xinef: allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
414 return;
415 }
417 }
418 else
420
421 // handle pause
423 {
424 if (mWPPauseTimer < diff)
425 {
427 {
430 if (mForcedPaused)// if paused between 2 wps resend movement
431 {
432 mWPReached = false;
433 mForcedPaused = false;
434 ResumePath();
435 }
436
437 mWPPauseTimer = 0;
438 }
439 }
440 else
441 mWPPauseTimer -= diff;
442 }
443
445 {
446 if (mOOCReached)//reached OOC WP
447 {
448 mOOCReached = false;
451 ResumePath();
452 }
453 }
454
456 return;
457
458 // handle next wp
459 if (!me->HasUnitState(UNIT_STATE_NOT_MOVE) && me->movespline->Finalized())//reached WP
460 {
461 if (!mWPReached)
462 {
463 ResumePath();
464 return;
465 }
466
467 mWPReached = false;
468 if (mCurrentWPID == GetWPCount())
469 EndPath();
470 else if (GetNextWayPoint())
471 {
472 SetRun(mRun);
473 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
474 if (me->movespline->Finalized())
475 ResumePath();
476 }
477 }
478}
@ SMART_EVENT_WAYPOINT_RESUMED
Definition SmartScriptMgr.h:174
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:220
bool IsEscortInvokerInRange()
Definition SmartAI.cpp:554
bool IsInCombat() const
Definition Unit.h:881

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, mRun, mWPPauseTimer, mWPReached, SmartScript::ProcessEventsFor(), RemoveEscortState(), ResumePath(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_ESCORT_RETURNING, SMART_EVENT_DEATH, SMART_EVENT_WAYPOINT_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

◆ 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

WayPoint* SmartAI::mLastWP
private

◆ mOOCReached

bool SmartAI::mOOCReached
private

◆ mRun

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