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 SetCombatMove (bool on, float chaseRange=0.0f)
 
bool CanCombatMove ()
 
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 MoveAway (float distance)
 
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 SetChaseOnInterrupt (bool apply)
 
bool CanChaseOnInterrupt () const
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr, Milliseconds delay=0s)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table.
 
void Talk (uint8 id, Milliseconds delay)
 
WorldObjectGetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon.
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual void SummonedCreatureDespawnAll ()
 
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)
 
- 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 mCanCombatMove
 
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
 

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
46{};

◆ 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 mCanCombatMove = true;
53
54 mForcedPaused = false;
55
57
58 mDespawnTime = 0;
59 mDespawnState = 0;
60
62 mFollowDist = 0;
63 mFollowAngle = 0;
64 mFollowCredit = 0;
70
71 mJustReset = false;
72
73 mcanSpawn = true;
74
75 _chaseOnInterrupt = false;
76
77 aiDataSet.clear();
78
79 // Xinef: Vehicle conditions
81 if (me->GetVehicleKit())
83}
#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:70
Creature *const me
Definition CreatureAI.h:72
uint32 GetEntry() const
Definition Object.h:116
uint32 mDespawnTime
Definition SmartAI.h:251
uint32 mEscortState
Definition SmartAI.h:233
WayPoint * mLastWP
Definition SmartAI.h:238
WPPath * mWayPoints
Definition SmartAI.h:232
uint32 mEscortInvokerCheckTimer
Definition SmartAI.h:254
uint32 mDespawnState
Definition SmartAI.h:252
bool mOOCReached
Definition SmartAI.h:236
uint32 mWPPauseTimer
Definition SmartAI.h:237
bool _chaseOnInterrupt
Definition SmartAI.h:264
uint32 mCurrentWPID
Definition SmartAI.h:234
uint32 m_ConditionsTimer
Definition SmartAI.h:262
bool mIsCharmed
Definition SmartAI.h:219
bool mWPReached
Definition SmartAI.h:235
uint32 mFollowArrivedTimer
Definition SmartAI.h:221
float mFollowAngle
Definition SmartAI.h:227
uint32 mEscortQuestID
Definition SmartAI.h:196
bool mRun
Definition SmartAI.h:242
uint32 mEscortNPCFlags
Definition SmartAI.h:239
ConditionList conditions
Definition SmartAI.h:261
uint32 mFollowCreditType
Definition SmartAI.h:220
bool mFollowArrivedAlive
Definition SmartAI.h:224
bool mcanSpawn
Definition SmartAI.h:257
uint32 mInvincibilityHpLevel
Definition SmartAI.h:247
bool mCanAutoAttack
Definition SmartAI.h:244
bool mJustReset
Definition SmartAI.h:255
bool mCanRepeatPath
Definition SmartAI.h:241
bool mEvadeDisabled
Definition SmartAI.h:243
bool mCanCombatMove
Definition SmartAI.h:245
bool mForcedPaused
Definition SmartAI.h:246
uint32 mFollowCredit
Definition SmartAI.h:222
uint32 mFollowArrivedEntry
Definition SmartAI.h:223
float mFollowDist
Definition SmartAI.h:226
std::unordered_map< uint32, uint32 > aiDataSet
Definition SmartAI.h:265
Vehicle * GetVehicleKit() const
Definition Unit.h:1838

References _chaseOnInterrupt, aiDataSet, CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, conditions, Object::GetEntry(), Unit::GetVehicleKit(), m_ConditionsTimer, mCanAutoAttack, mCanCombatMove, 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
62{ mEscortState |= uiEscortState; }

References mEscortState.

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

◆ AssistPlayerInCombatAgainst()

bool SmartAI::AssistPlayerInCombatAgainst ( Unit who)
private
734{
735 if (!IsAIControlled())
736 return false;
737
738 // Xinef: if unit has no victim, or victim is player controlled thing
739 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
740 return false;
741
742 //experimental (unknown) flag not present
744 return false;
745
746 // Xinef: victim of unit has to be a player controlled unit
748 return false;
749
750 // Xinef: Check if victim can be assisted
751 if (!me->IsValidAssistTarget(who->GetVictim()))
752 return false;
753
754 //too far away and no free sight?
756 {
757 AttackStart(who);
758 return true;
759 }
760
761 return false;
762}
@ 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:837
bool IsAIControlled() const
Definition SmartAI.cpp:85
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition Unit.h:1223
Unit * GetVictim() const
Definition Unit.h:848
bool IsValidAssistTarget(Unit const *target) const
Definition Unit.cpp:14096
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.

838{
839 // xinef: dont allow charmed npcs to act on their own
841 {
842 if (who)
843 me->Attack(who, mCanAutoAttack);
844 return;
845 }
846
847 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
848 {
849 if (mCanCombatMove)
850 {
851 SetRun(mRun);
853 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
854 {
856 me->StopMoving();
857 me->GetMotionMaster()->Clear(false);
858 }
859
861 }
862 }
863}
@ 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_FLAG_POSSESSED
Definition UnitDefines.h:274
MovementGeneratorType GetMotionSlotType(int slot) const
Definition MotionMaster.cpp:921
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:1003
MotionMaster * GetMotionMaster()
Definition Unit.h:1673
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:702
void StopMoving()
Definition Unit.cpp:16734
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:666
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:10343

References Unit::Attack(), MotionMaster::Clear(), ESCORT_MOTION_TYPE, Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), Unit::HasUnitFlag(), Unit::IsWithinMeleeRange(), mCanAutoAttack, mCanCombatMove, CreatureAI::me, MOTION_SLOT_ACTIVE, MotionMaster::MoveChase(), MotionMaster::MovementExpired(), mRun, POINT_MOTION_TYPE, SetRun(), Unit::StopMoving(), and UNIT_FLAG_POSSESSED.

Referenced by AssistPlayerInCombatAgainst(), MoveInLineOfSight(), and OnCharmed().

◆ CanAIAttack()

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

Reimplemented from UnitAI.

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

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

◆ CanChaseOnInterrupt()

bool SmartAI::CanChaseOnInterrupt ( ) const
inline
216{ return _chaseOnInterrupt; }

References _chaseOnInterrupt.

◆ CanCombatMove()

bool SmartAI::CanCombatMove ( )
inline
67{ return mCanCombatMove; }

References mCanCombatMove.

◆ CanRespawn()

bool SmartAI::CanRespawn ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

209{ return mcanSpawn; };

References mcanSpawn.

◆ CheckConditions()

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

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

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

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

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

◆ DoAction()

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

Reimplemented from UnitAI.

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

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

◆ EndPath()

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

655{
656 if (mEvadeDisabled)
657 {
659 return;
660 }
661
663 {
664 me->AttackStop();
666 return;
667 }
668
669 if (!_EnterEvadeMode())
670 return;
671
673
674 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
675
676 SetRun(mRun);
678 {
681 }
682 else if (mFollowGuid)
683 {
687
688 // xinef: do not forget to reset scripts as we wont call reached home
689 GetScript()->OnReset();
690 }
691 else
692 {
694
695 // xinef: do not forget to reset scripts as we wont call reached home
697 GetScript()->OnReset();
698 }
699}
@ SMART_EVENT_EVADE
Definition SmartScriptMgr.h:125
@ UNIT_STATE_EVADE
Definition UnitDefines.h:191
@ UNIT_FLAG_IN_COMBAT
Definition UnitDefines.h:269
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition CreatureAI.cpp:309
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:409
bool HasEscortState(uint32 uiEscortState)
Definition SmartAI.h:61
void ReturnToLastOOCPos()
Definition SmartAI.cpp:385
void AddEscortState(uint32 uiEscortState)
Definition SmartAI.h:62
ObjectGuid mFollowGuid
Definition SmartAI.h:225
void OnReset()
Definition SmartScript.cpp:109
void ClearUnitState(uint32 f)
Definition Unit.h:692
void AddUnitState(uint32 f)
Definition Unit.h:690
bool HasUnitState(const uint32 f) const
Definition Unit.h:691
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:10499
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)
129{
130 if (!mWayPoints || mWayPoints->empty())
131 return;
132
133 // Flying unit, just fill array
135 {
136 // xinef: first point in vector is unit real position
137 points->clear();
138 points->push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
139 uint32 wpCounter = mCurrentWPID;
140 WPPath::const_iterator itr;
141 while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end())
142 {
143 WayPoint* wp = (*itr).second;
144 points->push_back(G3D::Vector3(wp->x, wp->y, wp->z));
145 }
146 }
147 else
148 {
149 for (float size = 1.0f; size; size *= 0.5f)
150 {
151 std::vector<G3D::Vector3> pVector;
152 // xinef: first point in vector is unit real position
153 pVector.push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
154 uint32 length = (mWayPoints->size() - mCurrentWPID) * size;
155
156 uint32 cnt = 0;
157 uint32 wpCounter = mCurrentWPID;
158 WPPath::const_iterator itr;
159 while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end() && cnt++ <= length)
160 {
161 WayPoint* wp = (*itr).second;
162 pVector.push_back(G3D::Vector3(wp->x, wp->y, wp->z));
163 }
164
165 if (pVector.size() > 2) // more than source + dest
166 {
167 G3D::Vector3 middle = (pVector[0] + pVector[pVector.size() - 1]) / 2.f;
168 G3D::Vector3 offset;
169
170 bool continueLoop = false;
171 for (uint32 i = 1; i < pVector.size() - 1; ++i)
172 {
173 offset = middle - pVector[i];
174 if (std::fabs(offset.x) >= 0xFF || std::fabs(offset.y) >= 0xFF || std::fabs(offset.z) >= 0x7F)
175 {
176 // offset is too big, split points
177 continueLoop = true;
178 break;
179 }
180 }
181 if (continueLoop)
182 continue;
183 }
184 // everything ok
185 *points = pVector;
186 break;
187 }
188 }
189}
std::uint32_t uint32
Definition Define.h:107
MovementFlags
Definition UnitDefines.h:363
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition UnitDefines.h:375
@ MOVEMENTFLAG_CAN_FLY
Definition UnitDefines.h:389
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.

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

References aiDataSet.

◆ GetGUID()

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

Reimplemented from UnitAI.

999{
1000 return ObjectGuid::Empty;
1001}
static ObjectGuid const Empty
Definition ObjectGuid.h:120

References ObjectGuid::Empty.

◆ GetNextWayPoint()

WayPoint * SmartAI::GetNextWayPoint ( )
111{
112 if (!mWayPoints || mWayPoints->empty())
113 return nullptr;
114
115 mCurrentWPID++;
116 WPPath::const_iterator itr = mWayPoints->find(mCurrentWPID);
117 if (itr != mWayPoints->end())
118 {
119 mLastWP = (*itr).second;
120 if (mLastWP->id != mCurrentWPID)
121 LOG_ERROR("scripts.ai.sai", "SmartAI::GetNextWayPoint: Got not expected waypoint id {}, expected {}", mLastWP->id, mCurrentWPID);
122
123 return (*itr).second;
124 }
125 return nullptr;
126}
#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
240{ 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.

889{
891}
@ 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.

929{
931 if (!me->isDead())
932 {
933 mJustReset = true;
936 }
937}
@ SMART_EVENT_RESPAWN
Definition SmartScriptMgr.h:129
void JustReachedHome() override
Definition SmartAI.cpp:786
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition SmartScript.cpp:5154
bool isDead() const
Definition Unit.h:1709

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

899{
900 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
901}
@ 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.

810{
813 EndPath(true);
814}
@ 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.

802{
803 // Xinef: Interrupt channeled spells
804 if (IsAIControlled())
807}
@ 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:4108

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

787{
788 GetScript()->OnReset();
789
790 if (!mJustReset)
791 {
793
796 }
797
798 mJustReset = false;
799}
@ IDLE_MOTION_TYPE
Definition MotionMaster.h:39
@ SMART_EVENT_REACHED_HOME
Definition SmartScriptMgr.h:139
bool UpdateVictim()
Definition CreatureAI.cpp:286
uint32 GetWaypointPath() const
Definition Creature.h:350
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:913
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:852

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.

765{
766 mDespawnTime = 0;
767 mDespawnState = 0;
769 me->SetVisible(true);
772 mJustReset = true;
775 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
776 mFollowDist = 0;
777 mFollowAngle = 0;
778 mFollowCredit = 0;
779 mFollowArrivedTimer = 1000;
782 mFollowArrivedAlive = true;
783 aiDataSet.clear();
784}
void Clear()
Definition ObjectGuid.h:138
void SetVisible(bool x)
Definition Unit.cpp:14334
void RestoreFaction()
Definition Unit.cpp:18793
uint32 GetFaction() const
Definition Unit.h:801
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.

822{
824 GetScript()->AddCreatureSummon(creature->GetGUID());
825}
@ 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:5426

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

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

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

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

◆ LoadPath()

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

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

Referenced by StartPath().

◆ MoveAway()

void SmartAI::MoveAway ( float  distance)
1134{
1136 return;
1137
1138 mCanCombatMove = false;
1139
1140 if (!IsAIControlled())
1141 return;
1142
1144 {
1145 if (me->GetVictim())
1146 {
1147 me->StopMoving();
1149 me->GetMotionMaster()->Clear(false);
1150
1151 float x, y, z;
1152 me->GetClosePoint(x, y, z, me->GetObjectSize(), distance, M_PI);
1153 if (me->GetVictim()->IsWithinLOS(x, y, z))
1155 }
1156 }
1157}
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45
@ SMART_RANDOM_POINT
Definition SmartScriptMgr.h:58
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition MotionMaster.h:213
bool GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0, WorldObject const *forWho=nullptr, bool force=false) const
Definition Object.cpp:2692
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition Object.cpp:1331
float GetObjectSize() const
Definition Object.cpp:2764

References CHASE_MOTION_TYPE, MotionMaster::Clear(), WorldObject::GetClosePoint(), MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), WorldObject::GetObjectSize(), Unit::GetVictim(), HasEscortState(), IsAIControlled(), WorldObject::IsWithinLOS(), mCanCombatMove, CreatureAI::me, MotionMaster::MovePoint(), POINT_MOTION_TYPE, SMART_ESCORT_ESCORTING, SMART_RANDOM_POINT, and Unit::StopMoving().

◆ MoveInLineOfSight()

void SmartAI::MoveInLineOfSight ( Unit who)
overridevirtual

Reimplemented from CreatureAI.

702{
703 if (!who)
704 return;
705
707
708 if (!IsAIControlled())
709 return;
710
711 if (me->GetVictim())
712 return;
713
715 return;
716
718 {
720 {
723 }
724 AttackStart(who);
725 }
726}
@ 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:733
void OnMoveInLineOfSight(Unit *who)
Definition SmartScript.cpp:5197

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.

639{
640 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
642
643 if (MovementType == WAYPOINT_MOTION_TYPE)
644 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_REACHED, nullptr, Data + 1); // Data + 1 to align smart_scripts and waypoint_data Id rows
645
646 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
648 return;
649
650 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
652}
@ 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:593

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)
594{
595 // override the id, path can be resumed any time and counter will reset
596 // mCurrentWPID holds proper id
597
598 // xinef: both point movement and escort generator can enter this function
600 {
601 mOOCReached = true;
602 return;
603 }
604
605 mWPReached = true;
607
608 if (mLastWP)
609 {
612 }
613
615 {
618
621 }
622 // Xinef: Can be unset in ProcessEvents
624 {
625 mWPReached = false;
626 if (mCurrentWPID == GetWPCount())
627 EndPath();
628 else if (GetNextWayPoint())
629 {
630 SetRun(mRun);
631 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
632 if (me->movespline->Finalized())
633 ResumePath();
634 }
635 }
636}
@ SMART_EVENT_WAYPOINT_REACHED
Definition SmartScriptMgr.h:158
void SetHomePosition(float x, float y, float z, float o)
Definition Creature.h:340
void SetPosition(float x, float y, float z, float o)
Definition Creature.cpp:3167
void MoveIdle()
Definition MotionMaster.cpp:232
bool Finalized() const
Definition MoveSpline.h:116
WayPoint * GetNextWayPoint()
Definition SmartAI.cpp:110
uint32 GetWPCount()
Definition SmartAI.h:240
void ResumePath()
Definition SmartAI.cpp:372
Movement::MoveSpline * movespline
Definition Unit.h:2029
void StopMovingOnCurrentPos()
Definition Unit.cpp:16773
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.

940{
941 bool const charmed = me->IsCharmed();
942 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
943 {
945 EndPath(true);
946 }
947
948 mIsCharmed = charmed;
949
950 if (!charmed && !me->IsInEvadeMode())
951 {
952 if (mCanRepeatPath)
953 StartPath(mRun, GetScript()->GetPathId(), true);
954 else
955 me->SetWalk(!mRun);
956
957 if (Unit* charmer = me->GetCharmer())
958 AttackStart(charmer);
959 }
960
961 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
962}
@ 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:3204
bool IsInEvadeMode() const
Definition Creature.h:135
bool IsCharmed() const
Definition Unit.h:1237
Unit * GetCharmer() const
Definition Unit.cpp:10704

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.

1172{
1173 // Xinef: i dont think this is necessery (can be made as event parameter)
1174 //if (!result)
1175 // return;
1176
1178}
@ 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.

924{
926}
@ 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.

1181{
1183 me->LoadPath(0);
1184}
@ SMART_EVENT_WAYPOINT_DATA_ENDED
Definition SmartScriptMgr.h:217
void LoadPath(uint32 pathid)
Definition Creature.h:351

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 
)
242{
244 return;
245
247 {
248 LOG_ERROR("scripts.ai.sai", "SmartAI::StartPath: Creature entry {} wanted to pause waypoint movement while already paused, ignoring.", me->GetEntry());
249 return;
250 }
251
253 mWPPauseTimer = delay;
254 if (forced && !mWPReached)
255 {
256 mForcedPaused = forced;
257 SetRun(mRun);
260
261 me->StopMoving();
262 me->GetMotionMaster()->MoveIdle();//force stop
263
264 auto waypoint = mWayPoints->find(mCurrentWPID);
265 if (waypoint->second->o.has_value())
266 {
267 me->SetFacingTo(waypoint->second->o.has_value());
268 }
269 }
271}
@ SMART_EVENT_WAYPOINT_PAUSED
Definition SmartScriptMgr.h:173
void SetFacingTo(float ori)
Definition Unit.cpp:20370

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
171{ return PERMIT_BASE_NO; }
@ PERMIT_BASE_NO
Definition CreatureAI.h:244

References PERMIT_BASE_NO.

◆ ReceiveEmote()

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

Reimplemented from CreatureAI.

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

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

◆ RemoveEscortState()

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

References mEscortState.

Referenced by EndPath(), and UpdatePath().

◆ ResumePath()

void SmartAI::ResumePath ( )
373{
374 SetRun(mRun);
375
376 if (mLastWP)
377 {
378 Movement::PointsArray pathPoints;
379 GenerateWayPointArray(&pathPoints);
380
381 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
382 }
383}
void MoveSplinePath(Movement::PointsArray *path)
Definition MotionMaster.cpp:454
void GenerateWayPointArray(Movement::PointsArray *points)
Definition SmartAI.cpp:128
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
386{
387 if (!IsAIControlled())
388 return;
389
390 me->SetWalk(false);
391 float x, y, z, o;
392 me->GetHomePosition(x, y, z, o);
394}
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition Creature.h:342

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
65{ mCanAutoAttack = on; }

References mCanAutoAttack.

◆ SetCanRespawn()

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

References mcanSpawn.

◆ SetChaseOnInterrupt()

void SmartAI::SetChaseOnInterrupt ( bool  apply)
inline

References _chaseOnInterrupt.

◆ SetCombatMove()

void SmartAI::SetCombatMove ( bool  on,
float  chaseRange = 0.0f 
)
1051{
1052 if (mCanCombatMove == on)
1053 return;
1054
1055 mCanCombatMove = on;
1056
1057 if (!IsAIControlled())
1058 return;
1059
1061 {
1062 if (on && me->GetVictim())
1063 {
1065 {
1066 SetRun(mRun);
1067 me->GetMotionMaster()->MoveChase(me->GetVictim(), chaseRange);
1068 me->CastStop();
1069 }
1070 }
1071 else
1072 {
1073 me->StopMoving();
1075 me->GetMotionMaster()->Clear(false);
1077 }
1078 }
1079}
void CastStop(uint32 except_spellid=0, bool withInstant=true)
Interrupt the unit cast for all the current spells.
Definition Unit.cpp:1187

References Unit::CastStop(), CHASE_MOTION_TYPE, MotionMaster::Clear(), MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), Unit::GetVictim(), HasEscortState(), IDLE_MOTION_TYPE, IsAIControlled(), mCanCombatMove, CreatureAI::me, MotionMaster::MoveChase(), MotionMaster::MoveIdle(), mRun, SetRun(), SMART_ESCORT_ESCORTING, and Unit::StopMoving().

◆ SetData() [1/2]

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

Reimplemented from UnitAI.

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

References SetData().

Referenced by SetData().

◆ SetData() [2/2]

void SmartAI::SetData ( uint32  id,
uint32  value,
WorldObject invoker 
)
979{
980 Unit* unit = nullptr;
981 GameObject* gob = nullptr;
982
983 if (invoker)
984 {
985 unit = invoker->ToUnit();
986 if (!unit)
987 gob = invoker->ToGameObject();
988 }
989
990 aiDataSet[id] = value;
991 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, unit, id, value, false, nullptr, gob);
992}
@ 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
199 {
200 mDespawnTime = t;
201 mDespawnState = t ? 1 : 0;
202 }

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

void SmartAI::SetEvadeDisabled ( bool  disable = true)
1022{
1023 mEvadeDisabled = disable;
1024}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
1010{
1011 // xinef: set proper flag!
1012 //me->SetDisableGravity(fly);
1013 me->SetCanFly(fly);
1014}
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:3303

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 
)
1082{
1083 if (!target)
1084 {
1085 StopFollow(false);
1086 return;
1087 }
1088
1089 mFollowGuid = target->GetGUID();
1090 mFollowDist = dist;
1091 mFollowAngle = angle;
1092 mFollowArrivedTimer = 1000;
1093 mFollowCredit = credit;
1094 mFollowArrivedEntry = end;
1095 mFollowArrivedAlive = !aliveState; // negate - 0 is alive
1096 mFollowCreditType = creditType;
1097 SetRun(mRun);
1099}
void StopFollow(bool complete)
Definition SmartAI.cpp:1101

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.

995{
996}

◆ SetInvincibilityHpLevel()

void SmartAI::SetInvincibilityHpLevel ( uint32  level)
inline
185{ 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 
)
1160{
1161 if (invoker)
1162 GetScript()->mLastInvoker = invoker->GetGUID();
1163 GetScript()->SetScript9(e, entry);
1164}
ObjectGuid mLastInvoker
Definition SmartScript.h:200
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition SmartScript.cpp:5309

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

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
1017{
1018 me->SetSwim(swim);
1019}
bool SetSwim(bool enable) override
Definition Creature.cpp:3255

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

◆ SetWPPauseTimer()

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

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player player)
overridevirtual

Reimplemented from UnitAI.

1027{
1029}
@ 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.

1032{
1033 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1034}
@ 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.

1037{
1038}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

1167{
1169}
@ 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.

866{
867 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
868}
@ 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.

871{
872 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
873}
@ 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.

1041{
1042 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1043}
@ 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.

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

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

◆ StartDespawn()

void SmartAI::StartDespawn ( )
inline
203{ 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 
)
192{
194 StopPath();
195
196 if (path)
197 {
198 if (!LoadPath(path))
199 return;
200 }
201
202 if (!mWayPoints || mWayPoints->empty())
203 return;
204
205 if (WayPoint* wp = GetNextWayPoint())
206 {
208 mCanRepeatPath = repeat;
209 SetRun(run);
210
211 if (invoker && invoker->IsPlayer())
212 {
215 }
216
217 Movement::PointsArray pathPoints;
218 GenerateWayPointArray(&pathPoints);
219
220 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
221 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
222 }
223}
@ SMART_EVENT_WAYPOINT_START
Definition SmartScriptMgr.h:157
@ UNIT_NPC_FLAG_NONE
Definition UnitDefines.h:314
bool IsPlayer() const
Definition Object.h:201
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition SmartAI.cpp:273
bool LoadPath(uint32 entry)
Definition SmartAI.cpp:225
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)
1102{
1104 mFollowDist = 0;
1105 mFollowAngle = 0;
1106 mFollowCredit = 0;
1107 mFollowArrivedTimer = 1000;
1110
1111 me->GetMotionMaster()->Clear(false);
1112 me->StopMoving();
1114
1115 if (!complete)
1116 return;
1117
1119 if (player)
1120 {
1121 if (!mFollowCreditType)
1123 else
1125 }
1126
1127 SetDespawnTime(5000);
1128 StartDespawn();
1129
1131}
@ 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:198
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.

909{
912}
@ SMART_EVENT_SUMMON_DESPAWNED
Definition SmartScriptMgr.h:153
void RemoveCreatureSummon(ObjectGuid const &guid)
Definition SmartScript.cpp:5431

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.

828{
830}
@ 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.

833{
835}
@ 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.

508{
509 bool hasVictim = UpdateVictim();
510 CheckConditions(diff);
511 GetScript()->OnUpdate(diff);
512 UpdatePath(diff);
513 UpdateDespawn(diff);
514
515 //TODO move to void
516 if (mFollowGuid)
517 {
518 if (mFollowArrivedTimer < diff)
519 {
521 {
522 StopFollow(true);
523 return;
524 }
525
526 mFollowArrivedTimer = 1000;
527 }
528 else
529 mFollowArrivedTimer -= diff;
530 }
531
532 if (!IsAIControlled())
533 {
534 if (CharmInfo* charmInfo = me->GetCharmInfo())
535 {
536 if (charmInfo->IsCommandAttack() && mCanAutoAttack)
537 {
539 }
540 }
541
542 return;
543 }
544
545 if (!hasVictim)
546 return;
547
548 if (mCanAutoAttack)
550}
#define INTERACTION_DISTANCE
Definition ObjectDefines.h:24
void UpdatePath(const uint32 diff)
Definition SmartAI.cpp:396
void CheckConditions(const uint32 diff)
Definition SmartAI.cpp:478
void UpdateDespawn(const uint32 diff)
Definition SmartAI.cpp:90
void OnUpdate(const uint32 diff)
Definition SmartScript.cpp:4990
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:39
CharmInfo * GetCharmInfo()
Definition Unit.h:1208
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
91{
92 if (mDespawnState <= 1 || mDespawnState > 3)
93 return;
94
95 if (mDespawnTime < diff)
96 {
97 if (mDespawnState == 2)
98 {
99 me->SetVisible(false);
100 mDespawnTime = 5000;
102 }
103 else
105 }
106 else
107 mDespawnTime -= diff;
108}
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
397{
399 return;
400
401 if (mEscortInvokerCheckTimer < diff)
402 {
403 // Xinef: Escort failed - no players in range
404 // Xinef: Despawn immediately
406 {
407 StopPath(0, mEscortQuestID, true);
408
409 // Xinef: allow to properly hook out of range despawn action, which in most cases should perform the same operation as dying
412 return;
413 }
415 }
416 else
418
419 // handle pause
421 {
422 if (mWPPauseTimer < diff)
423 {
425 {
428 if (mForcedPaused)// if paused between 2 wps resend movement
429 {
430 mWPReached = false;
431 mForcedPaused = false;
432 ResumePath();
433 }
434
435 mWPPauseTimer = 0;
436 }
437 }
438 else
439 mWPPauseTimer -= diff;
440 }
441
443 {
444 if (mOOCReached)//reached OOC WP
445 {
446 mOOCReached = false;
449 ResumePath();
450 }
451 }
452
454 return;
455
456 // handle next wp
457 if (!me->HasUnitState(UNIT_STATE_NOT_MOVE) && me->movespline->Finalized())//reached WP
458 {
459 if (!mWPReached)
460 {
461 ResumePath();
462 return;
463 }
464
465 mWPReached = false;
466 if (mCurrentWPID == GetWPCount())
467 EndPath();
468 else if (GetNextWayPoint())
469 {
470 SetRun(mRun);
471 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
472 if (me->movespline->Finalized())
473 ResumePath();
474 }
475 }
476}
@ SMART_EVENT_WAYPOINT_RESUMED
Definition SmartScriptMgr.h:174
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:218
bool IsEscortInvokerInRange()
Definition SmartAI.cpp:552
bool IsInCombat() const
Definition Unit.h:879

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

◆ _chaseOnInterrupt

bool SmartAI::_chaseOnInterrupt
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

◆ mCanCombatMove

bool SmartAI::mCanCombatMove
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: