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_fairbanks::npc_fairbanksAI 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. More...
 
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) More...
 
void HealReceived (Unit *doneBy, uint32 &addhealth) override
 Called when the creature receives heal. More...
 
void UpdateAI (uint32 diff) override
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
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) override
 Called at any Damage to any victim (before damage apply) More...
 
void SummonedCreatureDespawn (Creature *unit) override
 
void CorpseRemoved (uint32 &respawnDelay) override
 == Triggered Actions Requested ================== More...
 
void PassengerBoarded (Unit *who, int8 seatId, bool apply) override
 == Fields ======================================= More...
 
void InitializeAI () override
 
void OnCharmed (bool apply) override
 Called when unit is charmed. More...
 
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)
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr, Milliseconds delay=0s)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table. More...
 
void Talk (uint8 id, Milliseconds delay)
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At ================================= More...
 
void TriggerAlert (Unit const *who) const
 
virtual bool CanRespawn ()
 
virtual void EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
virtual void JustEngagedWith (Unit *)
 Called for reaction when initially engaged. More...
 
virtual void JustDied (Unit *)
 
virtual void KilledUnit (Unit *)
 
virtual void JustSummoned (Creature *)
 
virtual void IsSummonedBy (WorldObject *)
 
virtual void SummonedCreatureDespawn (Creature *)
 
virtual void SummonedCreatureDies (Creature *, Unit *)
 
virtual void SummonedCreatureDespawnAll ()
 
virtual void SummonedCreatureEvade (Creature *)
 
virtual void SpellHit (Unit *, SpellInfo const *)
 
virtual void SpellHitTarget (Unit *, SpellInfo const *)
 
virtual void AttackedBy (Unit *)
 
virtual bool IsEscorted ()
 
virtual void JustRespawned ()
 
virtual void MovementInform (uint32, uint32)
 
virtual void PathEndReached (uint32)
 
void OnCharmed (bool apply) override
 Called when unit is charmed. More...
 
virtual void JustReachedHome ()
 
void DoZoneInCombat (Creature *creature=nullptr, float maxRangeToNearestTarget=250.0f)
 
virtual void ReceiveEmote (Player *, uint32)
 
virtual void OwnerAttackedBy (Unit *)
 
virtual void OwnerAttacked (Unit *)
 
virtual void CorpseRemoved (uint32 &)
 == Triggered Actions Requested ================== More...
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields ======================================= More...
 
virtual bool BeforeSpellClick (Unit *)
 
virtual void OnSpellClick (Unit *, bool &)
 
virtual bool CanSeeAlways (WorldObject const *)
 
virtual bool CanBeSeen (Player const *)
 
virtual bool CanAlwaysBeDetectable (WorldObject const *)
 
virtual void PetStopAttack ()
 
virtual bool CheckInRoom ()
 
CreatureBoundary const * GetBoundary () const
 
void SetBoundary (CreatureBoundary const *boundary, bool negativeBoundaries=false)
 
bool IsInBoundary (Position const *who=nullptr) const
 
virtual void CalculateThreat (Unit *, float &, SpellInfo const *)
 
virtual bool OnTeleportUnreacheablePlayer (Player *)
 
virtual void OnAuraRemove (AuraApplication *, AuraRemoveMode)
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual bool CanAIAttack (Unit const *) const
 
virtual void AttackStart (Unit *)
 
virtual void UpdateAI (uint32)=0
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool apply)=0
 Called when unit is charmed. More...
 
virtual void DoAction (int32)
 
virtual uint32 GetData (uint32) const
 
virtual void SetData (uint32, uint32)
 
virtual void SetGUID (ObjectGuid, int32=0)
 
virtual ObjectGuid GetGUID (int32=0) const
 
UnitSelectTarget (SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following: More...
 
template<class PREDICATE >
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
virtual void JustEnteredCombat (Unit *)
 Called when the unit enters combat. More...
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat. More...
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 Called at any Damage to any victim (before damage apply) More...
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 Called at any Damage from any attacker (before damage apply) More...
 
virtual void HealReceived (Unit *, uint32 &)
 Called when the creature receives heal. More...
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 Called when the creature power updates. More...
 
virtual void HealDone (Unit *, uint32 &)
 Called when the unit heals. More...
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 Called during damage calculations. More...
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 Called during calculation when receiving periodic healing or damage (DoT or HoT) More...
 
void AttackStartCaster (Unit *victim, float dist)
 
SpellCastResult DoAddAuraToAllHostilePlayers (uint32 spellid)
 
SpellCastResult DoCast (uint32 spellId)
 
SpellCastResult DoCast (Unit *victim, uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastSelf (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastToAllHostilePlayers (uint32 spellid, bool triggered=false)
 To specify the caster as target if the spell is self-cast. More...
 
SpellCastResult DoCastVictim (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastAOE (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastRandomTarget (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false, bool withTank=true)
 Cast the spell on a random unit from the threat list. More...
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the top threat target, which may not be the current victim. More...
 
float DoGetSpellMaxRange (uint32 spellId, bool positive=false)
 
void DoMeleeAttackIfReady ()
 
bool DoSpellAttackIfReady (uint32 spell)
 
void DoSpellAttackToRandomTargetIfReady (uint32 spell, uint32 threatTablePosition=0, float dist=0.f, bool playerOnly=true)
 
virtual void SummonMovementInform (Creature *, uint32, uint32)
 Called when a summon reaches a waypoint or point movement finished. More...
 
virtual void sGossipHello (Player *)
 
virtual void sGossipSelect (Player *, uint32, uint32)
 
virtual void sGossipSelectCode (Player *, uint32, uint32, char const *)
 
virtual void sQuestAccept (Player *, Quest const *)
 
virtual void sQuestSelect (Player *, Quest const *)
 
virtual void sQuestComplete (Player *, Quest const *)
 
virtual void sQuestReward (Player *, Quest const *, uint32)
 
virtual void sOnGameEvent (bool, uint16)
 
virtual std::string GetDebugInfo () const
 

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
 

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)
 
virtual void MoveInLineOfSight (Unit *)
 
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
47{};

◆ 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 // Xinef: Vehicle conditions
77 if (me->GetVehicleKit())
79}
#define sConditionMgr
Definition: ConditionMgr.h:289
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
Definition: ConditionMgr.h:138
@ SMART_ESCORT_NONE
Definition: SmartAI.h:32
Definition: CreatureAI.h:71
Creature *const me
Definition: CreatureAI.h:73
uint32 mDespawnTime
Definition: SmartAI.h:249
uint32 mEscortState
Definition: SmartAI.h:231
WayPoint * mLastWP
Definition: SmartAI.h:236
WPPath * mWayPoints
Definition: SmartAI.h:230
uint32 mEscortInvokerCheckTimer
Definition: SmartAI.h:252
uint32 mDespawnState
Definition: SmartAI.h:250
bool mOOCReached
Definition: SmartAI.h:234
uint32 mWPPauseTimer
Definition: SmartAI.h:235
uint32 mCurrentWPID
Definition: SmartAI.h:232
uint32 m_ConditionsTimer
Definition: SmartAI.h:260
bool mIsCharmed
Definition: SmartAI.h:217
bool mWPReached
Definition: SmartAI.h:233
uint32 mFollowArrivedTimer
Definition: SmartAI.h:219
float mFollowAngle
Definition: SmartAI.h:225
uint32 mEscortQuestID
Definition: SmartAI.h:197
bool mRun
Definition: SmartAI.h:240
uint32 mEscortNPCFlags
Definition: SmartAI.h:237
ConditionList conditions
Definition: SmartAI.h:259
uint32 mFollowCreditType
Definition: SmartAI.h:218
bool mFollowArrivedAlive
Definition: SmartAI.h:222
bool mcanSpawn
Definition: SmartAI.h:255
uint32 mInvincibilityHpLevel
Definition: SmartAI.h:245
bool mCanAutoAttack
Definition: SmartAI.h:242
bool mJustReset
Definition: SmartAI.h:253
bool mCanRepeatPath
Definition: SmartAI.h:239
bool mEvadeDisabled
Definition: SmartAI.h:241
bool mCanCombatMove
Definition: SmartAI.h:243
bool mForcedPaused
Definition: SmartAI.h:244
uint32 mFollowCredit
Definition: SmartAI.h:220
uint32 mFollowArrivedEntry
Definition: SmartAI.h:221
float mFollowDist
Definition: SmartAI.h:224
uint32 GetEntry() const
Definition: Object.h:112
Vehicle * GetVehicleKit() const
Definition: Unit.h:1672

References 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
63{ mEscortState |= uiEscortState; }

References mEscortState.

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

◆ AssistPlayerInCombatAgainst()

bool SmartAI::AssistPlayerInCombatAgainst ( Unit who)
private
729{
730 if (!IsAIControlled())
731 return false;
732
733 // Xinef: if unit has no victim, or victim is player controlled thing
734 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
735 return false;
736
737 //experimental (unknown) flag not present
739 return false;
740
741 // Xinef: victim of unit has to be a player controlled unit
743 return false;
744
745 // Xinef: Check if victim can be assisted
746 if (!me->IsValidAssistTarget(who->GetVictim()))
747 return false;
748
749 //too far away and no free sight?
751 {
752 AttackStart(who);
753 return true;
754 }
755
756 return false;
757}
@ SMART_MAX_AID_DIST
Definition: SmartAI.h:41
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition: SharedDefines.h:2707
void AttackStart(Unit *who) override
Definition: SmartAI.cpp:831
bool IsAIControlled() const
Definition: SmartAI.cpp:81
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:206
uint32 type_flags
Definition: CreatureData.h:226
bool IsWithinLOSInMap(WorldObject const *obj, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS, Optional< float > collisionHeight={ }, Optional< float > combatReach={ }) const
Definition: Object.cpp:1347
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool useBoundingRadius=true) const
Definition: Object.cpp:1321
bool IsPlayer() const
Definition: ObjectGuid.h:168
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition: Unit.h:1227
Unit * GetVictim() const
Definition: Unit.h:789
bool IsValidAssistTarget(Unit const *target) const
Definition: Unit.cpp:13951

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.

832{
833 // xinef: dont allow charmed npcs to act on their own
835 {
836 if (who)
837 me->Attack(who, mCanAutoAttack);
838 return;
839 }
840
841 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
842 {
843 if (mCanCombatMove)
844 {
845 SetRun(mRun);
847 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
848 {
850 me->StopMoving();
851 }
852
854 }
855 }
856}
@ MOTION_SLOT_ACTIVE
Definition: MotionMaster.h:62
MovementGeneratorType
Definition: MotionMaster.h:36
@ ESCORT_MOTION_TYPE
Definition: MotionMaster.h:55
@ POINT_MOTION_TYPE
Definition: MotionMaster.h:46
@ UNIT_FLAG_POSSESSED
Definition: UnitDefines.h:253
void SetRun(bool run=true)
Definition: SmartAI.cpp:991
MotionMaster * GetMotionMaster()
Definition: Unit.h:1601
bool HasUnitFlag(UnitFlags flags) const
Definition: Unit.h:682
void StopMoving()
Definition: Unit.cpp:16606
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition: Unit.cpp:665
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:10234
MovementGeneratorType GetMotionSlotType(int slot) const
Definition: MotionMaster.cpp:918
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:178

References Unit::Attack(), 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.

Reimplemented in npc_pos_freed_slave::npc_pos_freed_slaveAI.

724{
725 return !(me->GetReactState() == REACT_PASSIVE);
726}
@ REACT_PASSIVE
Definition: Unit.h:548
ReactStates GetReactState() const
Definition: Creature.h:98

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

◆ CanCombatMove()

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

References mCanCombatMove.

◆ CanRespawn()

bool SmartAI::CanRespawn ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

210{ return mcanSpawn; };

References mcanSpawn.

◆ CheckConditions()

void SmartAI::CheckConditions ( const uint32  diff)
private
475{
476 Vehicle* vehicle = me->GetVehicleKit();
477 if (!vehicle)
478 return;
479
480 if (m_ConditionsTimer < diff)
481 {
482 if (!conditions.empty())
483 {
484 for (SeatMap::iterator itr = vehicle->Seats.begin(); itr != vehicle->Seats.end(); ++itr)
485 if (Unit* passenger = ObjectAccessor::GetUnit(*me, itr->second.Passenger.Guid))
486 {
487 if (Player* player = passenger->ToPlayer())
488 {
489 if (!sConditionMgr->IsObjectMeetToConditions(player, me, conditions))
490 {
491 player->ExitVehicle();
492 return;//check other pessanger in next tick
493 }
494 }
495 }
496 }
497 m_ConditionsTimer = 1000;
498 }
499 else
500 m_ConditionsTimer -= diff;
501}
Unit * GetUnit(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:202
Player * ToPlayer()
Definition: Object.h:198
Definition: Player.h:1064
Definition: Unit.h:630
Definition: Vehicle.h:28
SeatMap Seats
Definition: Vehicle.h:55

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.

908{
909 GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
910
911 // xinef: end escort upon corpse remove, safe check in case of immediate despawn
912 if (IsEscorted())
913 EndPath(true);
914}
@ SMART_EVENT_CORPSE_REMOVED
Definition: SmartScriptMgr.h:155
void EndPath(bool fail=false)
Definition: SmartAI.cpp:288
bool IsEscorted() override
Definition: SmartAI.h:64
SmartScript * GetScript()
Definition: SmartAI.h:74
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:134

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

◆ DamageDealt()

void SmartAI::DamageDealt ( Unit ,
uint32 ,
DamageEffectType   
)
overridevirtual

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

Reimplemented from UnitAI.

897{
899}
@ SMART_EVENT_DAMAGED_TARGET
Definition: SmartScriptMgr.h:152

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.

869{
870 if (doneBy)
872
873 if (!IsAIControlled()) // don't allow players to use unkillable units
874 return;
875
876 // Xinef: skip nodamage type (eg. instakill effect)
877 if (damagetype != NODAMAGE && mInvincibilityHpLevel && (damage >= me->GetHealth() - mInvincibilityHpLevel))
878 damage = me->GetHealth() - mInvincibilityHpLevel; // damage should not be nullified, because of player damage req.
879}
@ SMART_EVENT_DAMAGED
Definition: SmartScriptMgr.h:151
@ NODAMAGE
Definition: Unit.h:252
uint32 GetHealth() const
Definition: Unit.h:869

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.

958{
960}
@ SMART_EVENT_ACTION_DONE
Definition: SmartScriptMgr.h:191

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

◆ EndPath()

void SmartAI::EndPath ( bool  fail = false)
289{
291 mWayPoints = nullptr;
292 mLastWP = nullptr;
293 mWPPauseTimer = 0;
294
295 if (mEscortNPCFlags)
296 {
298 mEscortNPCFlags = 0;
299 }
300
302 if (targets && mEscortQuestID)
303 {
304 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
305 {
306 Player* player = targets->front()->ToPlayer();
307 if (Group* group = player->GetGroup())
308 {
309 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
310 {
311 Player* groupGuy = groupRef->GetSource();
312 if (!groupGuy || !player->IsInMap(groupGuy))
313 continue;
314
315 if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
317 else if (fail && groupGuy->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
318 groupGuy->FailQuest(mEscortQuestID);
319 }
320 }
321 else
322 {
323 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
325 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
326 player->FailQuest(mEscortQuestID);
327 }
328 }
329 else
330 {
331 for (WorldObject* target : *targets)
332 {
333 if (GetScript()->IsPlayer(target))
334 {
335 Player* player = target->ToPlayer();
336 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
338 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
339 player->FailQuest(mEscortQuestID);
340 }
341 }
342 }
343 }
344
345 // Xinef: if the escort failed - DO NOT PROCESS ANYTHING
346 // Xinef: End Path events should be only processed if it was SUCCESSFUL stop or stop called by SMART_ACTION_WAYPOINT_STOP
347 if (fail)
348 {
349 mCurrentWPID = 0;
350 return;
351 }
352
354 mCurrentWPID = 0;
355
356 if (mCanRepeatPath)
357 {
358 if (IsAIControlled())
359 StartPath(mRun, GetScript()->GetPathId(), true);
360 }
361 else
362 GetScript()->SetPathId(0);
363
364 if (mDespawnState == 1)
365 StartDespawn();
366}
@ QUEST_STATUS_INCOMPLETE
Definition: QuestDef.h:103
std::vector< WorldObject * > ObjectVector
Definition: SmartScriptMgr.h:1971
@ SMART_EVENT_WAYPOINT_ENDED
Definition: SmartScriptMgr.h:177
@ SMART_ESCORT_TARGETS
Definition: SmartScriptMgr.h:60
@ SMART_ESCORT_ESCORTING
Definition: SmartAI.h:33
@ SMART_ESCORT_PAUSED
Definition: SmartAI.h:35
@ SMART_ESCORT_RETURNING
Definition: SmartAI.h:34
NPCFlags
Non Player Character flags.
Definition: UnitDefines.h:292
void RemoveEscortState(uint32 uiEscortState)
Definition: SmartAI.h:65
void StartPath(bool run=false, uint32 path=0, bool repeat=false, Unit *invoker=nullptr)
Definition: SmartAI.cpp:187
void StartDespawn()
Definition: SmartAI.h:204
ObjectVector const * GetStoredTargetVector(uint32 id, WorldObject const &ref) const
Definition: SmartScript.h:90
void SetPathId(uint32 id)
Definition: SmartScript.h:52
Definition: Object.h:405
bool IsInMap(WorldObject const *obj) const
Definition: Object.cpp:1285
bool HasCorpse() const
Definition: Player.h:2018
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition: PlayerQuest.cpp:1812
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition: Player.cpp:12761
Group * GetGroup()
Definition: Player.h:2448
void AreaExploredOrEventHappens(uint32 questId)
Definition: PlayerQuest.cpp:1785
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition: PlayerQuest.cpp:1424
void FailQuest(uint32 quest_id)
Definition: PlayerQuest.cpp:880
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:697
Definition: Group.h:169
Definition: GroupReference.h:27
GroupReference * next()
Definition: GroupReference.h:36

References Player::AreaExploredOrEventHappens(), Player::FailQuest(), Player::GetGroup(), Player::GetQuestStatus(), GetScript(), SmartScript::GetStoredTargetVector(), Player::GroupEventHappens(), Player::HasCorpse(), IsAIControlled(), Player::IsAtGroupRewardDistance(), WorldObject::IsInMap(), mCanRepeatPath, mCurrentWPID, mDespawnState, CreatureAI::me, mEscortNPCFlags, mEscortQuestID, mLastWP, mRun, mWayPoints, mWPPauseTimer, GroupReference::next(), 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.

Reimplemented in npc_black_morass_summoned_add, and npc_pos_freed_slave::npc_pos_freed_slaveAI.

651{
652 if (mEvadeDisabled)
653 {
655 return;
656 }
657
659 {
660 me->AttackStop();
661 return;
662 }
663
664 if (!_EnterEvadeMode())
665 return;
666
668
669 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
670
671 SetRun(mRun);
673 {
676 }
677 else if (mFollowGuid)
678 {
682
683 // xinef: do not forget to reset scripts as we wont call reached home
684 GetScript()->OnReset();
685 }
686 else
687 {
689
690 // xinef: do not forget to reset scripts as we wont call reached home
692 GetScript()->OnReset();
693 }
694}
@ SMART_EVENT_EVADE
Definition: SmartScriptMgr.h:126
@ UNIT_STATE_EVADE
Definition: UnitDefines.h:170
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition: CreatureAI.cpp:292
bool HasEscortState(uint32 uiEscortState)
Definition: SmartAI.h:62
void ReturnToLastOOCPos()
Definition: SmartAI.cpp:381
void AddEscortState(uint32 uiEscortState)
Definition: SmartAI.h:63
ObjectGuid mFollowGuid
Definition: SmartAI.h:223
void OnReset()
Definition: SmartScript.cpp:108
void ClearUnitState(uint32 f)
Definition: Unit.h:674
void AddUnitState(uint32 f)
Definition: Unit.h:672
bool HasUnitState(const uint32 f) const
Definition: Unit.h:673
ObjectGuid GetCharmerGUID() const
Definition: Unit.h:1216
bool AttackStop()
Force the unit to stop attacking. This will clear UNIT_STATE_MELEE_ATTACKING, Interrupt current spell...
Definition: Unit.cpp:10365
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)
The unit will follow this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition: MotionMaster.cpp:409

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(), ReturnToLastOOCPos(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_RETURNING, SMART_EVENT_EVADE, UNIT_FLAG_POSSESSED, and UNIT_STATE_EVADE.

Referenced by npc_black_morass_summoned_add::EnterEvadeMode().

◆ GenerateWayPointArray()

void SmartAI::GenerateWayPointArray ( Movement::PointsArray points)
125{
126 if (!mWayPoints || mWayPoints->empty())
127 return;
128
129 // Flying unit, just fill array
131 {
132 // xinef: first point in vector is unit real position
133 points->clear();
134 points->push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
135 uint32 wpCounter = mCurrentWPID;
136 WPPath::const_iterator itr;
137 while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end())
138 {
139 WayPoint* wp = (*itr).second;
140 points->push_back(G3D::Vector3(wp->x, wp->y, wp->z));
141 }
142 }
143 else
144 {
145 for (float size = 1.0f; size; size *= 0.5f)
146 {
147 std::vector<G3D::Vector3> pVector;
148 // xinef: first point in vector is unit real position
149 pVector.push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
150 uint32 length = (mWayPoints->size() - mCurrentWPID) * size;
151
152 uint32 cnt = 0;
153 uint32 wpCounter = mCurrentWPID;
154 WPPath::const_iterator itr;
155 while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end() && cnt++ <= length)
156 {
157 WayPoint* wp = (*itr).second;
158 pVector.push_back(G3D::Vector3(wp->x, wp->y, wp->z));
159 }
160
161 if (pVector.size() > 2) // more than source + dest
162 {
163 G3D::Vector3 middle = (pVector[0] + pVector[pVector.size() - 1]) / 2.f;
164 G3D::Vector3 offset;
165
166 bool continueLoop = false;
167 for (uint32 i = 1; i < pVector.size() - 1; ++i)
168 {
169 offset = middle - pVector[i];
170 if (std::fabs(offset.x) >= 0xFF || std::fabs(offset.y) >= 0xFF || std::fabs(offset.z) >= 0x7F)
171 {
172 // offset is too big, split points
173 continueLoop = true;
174 break;
175 }
176 }
177 if (continueLoop)
178 continue;
179 }
180 // everything ok
181 *points = pVector;
182 break;
183 }
184 }
185}
std::uint32_t uint32
Definition: Define.h:107
MovementFlags
Definition: UnitDefines.h:342
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition: UnitDefines.h:354
@ MOVEMENTFLAG_CAN_FLY
Definition: UnitDefines.h:368
Definition: SmartScriptMgr.h:34
float z
Definition: SmartScriptMgr.h:48
float y
Definition: SmartScriptMgr.h:47
float x
Definition: SmartScriptMgr.h:46
bool HasMovementFlag(uint32 flag) const
Definition: Object.h:334
MovementInfo m_movementInfo
Definition: Object.h:609
float GetPositionZ() const
Definition: Position.h:119
float GetPositionX() const
Definition: Position.h:117
float GetPositionY() const
Definition: Position.h:118

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.

963{
964 return 0;
965}

◆ GetGUID()

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

Reimplemented from UnitAI.

987{
988 return ObjectGuid::Empty;
989}
static ObjectGuid const Empty
Definition: ObjectGuid.h:120

References ObjectGuid::Empty.

◆ GetNextWayPoint()

WayPoint * SmartAI::GetNextWayPoint ( )
107{
108 if (!mWayPoints || mWayPoints->empty())
109 return nullptr;
110
111 mCurrentWPID++;
112 WPPath::const_iterator itr = mWayPoints->find(mCurrentWPID);
113 if (itr != mWayPoints->end())
114 {
115 mLastWP = (*itr).second;
116 if (mLastWP->id != mCurrentWPID)
117 LOG_ERROR("scripts.ai.sai", "SmartAI::GetNextWayPoint: Got not expected waypoint id {}, expected {}", mLastWP->id, mCurrentWPID);
118
119 return (*itr).second;
120 }
121 return nullptr;
122}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
uint32 id
Definition: SmartScriptMgr.h:45

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

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

◆ GetScript()

◆ GetWPCount()

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

References mWayPoints.

Referenced by MovepointReached(), and UpdatePath().

◆ HasEscortState()

bool SmartAI::HasEscortState ( uint32  uiEscortState)
inline

◆ HealReceived()

void SmartAI::HealReceived ( Unit ,
uint32  
)
overridevirtual

Called when the creature receives heal.

Reimplemented from UnitAI.

882{
884}
@ SMART_EVENT_RECEIVE_HEAL
Definition: SmartScriptMgr.h:172

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

◆ InitializeAI()

void SmartAI::InitializeAI ( )
overridevirtual

Reimplemented from UnitAI.

922{
924 if (!me->isDead())
925 {
926 mJustReset = true;
929 }
930}
@ SMART_EVENT_RESPAWN
Definition: SmartScriptMgr.h:130
void JustReachedHome() override
Definition: SmartAI.cpp:780
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition: SmartScript.cpp:5069
bool isDead() const
Definition: Unit.h:1206

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

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.

892{
893 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
894}
@ SMART_EVENT_JUST_SUMMONED
Definition: SmartScriptMgr.h:173
GameObject * ToGameObject()
Definition: Object.h:210
Unit * ToUnit()
Definition: Object.h:206

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

◆ JustDied()

void SmartAI::JustDied ( Unit killer)
overridevirtual

Reimplemented from CreatureAI.

804{
807 EndPath(true);
808}
@ SMART_EVENT_DEATH
Definition: SmartScriptMgr.h:125

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.

796{
797 // Xinef: Interrupt channeled spells
798 if (IsAIControlled())
801}
@ SMART_EVENT_AGGRO
Definition: SmartScriptMgr.h:123
@ CURRENT_CHANNELED_SPELL
Definition: Unit.h:539
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, bool bySelf=false)
Definition: Unit.cpp:4044

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

781{
782 GetScript()->OnReset();
783
784 if (!mJustReset)
785 {
787
790 }
791
792 mJustReset = false;
793}
@ SMART_EVENT_REACHED_HOME
Definition: SmartScriptMgr.h:140
@ IDLE_MOTION_TYPE
Definition: MotionMaster.h:37
bool UpdateVictim()
Definition: CreatureAI.cpp:269
uint32 GetWaypointPath() const
Definition: Creature.h:347
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:910
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:849

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.

760{
761 mDespawnTime = 0;
762 mDespawnState = 0;
764 me->SetVisible(true);
767 mJustReset = true;
770 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
771 mFollowDist = 0;
772 mFollowAngle = 0;
773 mFollowCredit = 0;
774 mFollowArrivedTimer = 1000;
777 mFollowArrivedAlive = true;
778}
uint32 faction
Definition: CreatureData.h:201
void Clear()
Definition: ObjectGuid.h:138
void SetVisible(bool x)
Definition: Unit.cpp:14189
void RestoreFaction()
Definition: Unit.cpp:18651
uint32 GetFaction() const
Definition: Unit.h:755

References 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.

816{
818 GetScript()->AddCreatureSummon(creature->GetGUID());
819}
@ SMART_EVENT_SUMMONED_UNIT
Definition: SmartScriptMgr.h:136
void AddCreatureSummon(ObjectGuid const &guid)
Definition: SmartScript.cpp:5341
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109

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

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

811{
813}
@ SMART_EVENT_KILL
Definition: SmartScriptMgr.h:124

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

◆ LoadPath()

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

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

Referenced by StartPath().

◆ MoveAway()

void SmartAI::MoveAway ( float  distance)
1122{
1124 return;
1125
1126 mCanCombatMove = false;
1127
1128 if (!IsAIControlled())
1129 return;
1130
1132 {
1133 if (me->GetVictim())
1134 {
1135 me->StopMoving();
1137 me->GetMotionMaster()->Clear(false);
1138
1139 float x, y, z;
1140 me->GetClosePoint(x, y, z, me->GetObjectSize(), distance, M_PI);
1141 if (me->GetVictim()->IsWithinLOS(x, y, z))
1143 }
1144 }
1145}
@ SMART_RANDOM_POINT
Definition: SmartScriptMgr.h:59
@ CHASE_MOTION_TYPE
Definition: MotionMaster.h:43
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:2699
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition: Object.cpp:1326
float GetObjectSize() const
Definition: Object.cpp:2771
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition: MotionMaster.h:211
void Clear(bool reset=true)
Definition: MotionMaster.h:165

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.

Reimplemented in npc_fairbanks::npc_fairbanksAI.

697{
698 if (!who)
699 return;
700
702
703 if (!IsAIControlled())
704 return;
705
706 if (me->GetVictim())
707 return;
708
710 return;
711
713 {
715 {
718 }
719 AttackStart(who);
720 }
721}
@ REACT_AGGRESSIVE
Definition: Unit.h:550
@ UNIT_STATE_DISTRACTED
Definition: UnitDefines.h:161
bool AssistPlayerInCombatAgainst(Unit *who)
Definition: SmartAI.cpp:728
void OnMoveInLineOfSight(Unit *who)
Definition: SmartScript.cpp:5112
bool CanStartAttack(Unit const *u) const
Definition: Creature.cpp:1903
bool HasReactState(ReactStates state) const
Definition: Creature.h:99

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.

Referenced by npc_fairbanks::npc_fairbanksAI::MoveInLineOfSight().

◆ MovementInform()

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

Reimplemented from CreatureAI.

635{
636 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
638
639 if (MovementType == WAYPOINT_MOTION_TYPE)
640 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_REACHED, nullptr, Data + 1); // Data + 1 to align smart_scripts and waypoint_data Id rows
641
642 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
644 return;
645
646 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
648}
@ SMART_EVENT_MOVEMENTINFORM
Definition: SmartScriptMgr.h:153
@ SMART_EVENT_WAYPOINT_DATA_REACHED
Definition: SmartScriptMgr.h:217
@ SMART_ESCORT_LAST_OOC_POINT
Definition: SmartScriptMgr.h:58
@ WAYPOINT_MOTION_TYPE
Definition: MotionMaster.h:39
Data
Definition: blackfathom_deeps.h:24
void MovepointReached(uint32 id)
Definition: SmartAI.cpp:589

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)
590{
591 // override the id, path can be resumed any time and counter will reset
592 // mCurrentWPID holds proper id
593
594 // xinef: both point movement and escort generator can enter this function
596 {
597 mOOCReached = true;
598 return;
599 }
600
601 mWPReached = true;
603
604 if (mLastWP)
605 {
608 }
609
611 {
614
617 }
618 // Xinef: Can be unset in ProcessEvents
620 {
621 mWPReached = false;
622 if (mCurrentWPID == GetWPCount())
623 EndPath();
624 else if (GetNextWayPoint())
625 {
626 SetRun(mRun);
627 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
628 if (me->movespline->Finalized())
629 ResumePath();
630 }
631 }
632}
@ SMART_EVENT_WAYPOINT_REACHED
Definition: SmartScriptMgr.h:159
WayPoint * GetNextWayPoint()
Definition: SmartAI.cpp:106
uint32 GetWPCount()
Definition: SmartAI.h:238
void ResumePath()
Definition: SmartAI.cpp:368
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:337
void SetPosition(float x, float y, float z, float o)
Definition: Creature.cpp:3149
float GetOrientation() const
Definition: Position.h:120
void GetPosition(float &x, float &y) const
Definition: Position.h:122
Movement::MoveSpline * movespline
Definition: Unit.h:1818
void StopMovingOnCurrentPos()
Definition: Unit.cpp:16645
void MoveIdle()
Definition: MotionMaster.cpp:232
bool Finalized() const
Definition: MoveSpline.h:116

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.

933{
934 bool const charmed = me->IsCharmed();
935 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
936 {
938 EndPath(true);
939 }
940
941 mIsCharmed = charmed;
942
943 if (!charmed && !me->IsInEvadeMode())
944 {
945 if (mCanRepeatPath)
946 StartPath(mRun, GetScript()->GetPathId(), true);
947 else
948 me->SetWalk(!mRun);
949
950 if (Unit* charmer = me->GetCharmer())
951 AttackStart(charmer);
952 }
953
954 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
955}
@ SMART_EVENT_CHARMED
Definition: SmartScriptMgr.h:148
bool SetWalk(bool enable) override
Enable or disable the creature's walk mode by removing: MOVEMENTFLAG_WALKING. Infom also the client.
Definition: Creature.cpp:3178
bool IsInEvadeMode() const
Definition: Creature.h:137
bool IsCharmed() const
Definition: Unit.h:1266
Unit * GetCharmer() const
Definition: Unit.cpp:10570

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

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

◆ PassengerBoarded()

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

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

Reimplemented from CreatureAI.

917{
919}
@ SMART_EVENT_PASSENGER_REMOVED
Definition: SmartScriptMgr.h:147
@ SMART_EVENT_PASSENGER_BOARDED
Definition: SmartScriptMgr.h:146

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:218
void LoadPath(uint32 pathid)
Definition: Creature.h:348

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

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

References PERMIT_BASE_NO.

◆ ReceiveEmote()

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

Reimplemented from CreatureAI.

887{
889}
@ SMART_EVENT_RECEIVE_EMOTE
Definition: SmartScriptMgr.h:141

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

◆ RemoveEscortState()

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

References mEscortState.

Referenced by EndPath(), and UpdatePath().

◆ ResumePath()

void SmartAI::ResumePath ( )
369{
370 SetRun(mRun);
371
372 if (mLastWP)
373 {
374 Movement::PointsArray pathPoints;
375 GenerateWayPointArray(&pathPoints);
376
377 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
378 }
379}
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:28
void GenerateWayPointArray(Movement::PointsArray *points)
Definition: SmartAI.cpp:124
void MoveSplinePath(Movement::PointsArray *path)
Definition: MotionMaster.cpp:454

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

Referenced by MovepointReached(), and UpdatePath().

◆ ReturnToLastOOCPos()

void SmartAI::ReturnToLastOOCPos ( )
private
382{
383 if (!IsAIControlled())
384 return;
385
386 me->SetWalk(false);
387 float x, y, z, o;
388 me->GetHomePosition(x, y, z, o);
390}
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:339

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

References mCanAutoAttack.

◆ SetCanRespawn()

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

References mcanSpawn.

◆ SetCombatMove()

void SmartAI::SetCombatMove ( bool  on,
float  chaseRange = 0.0f 
)
1039{
1040 if (mCanCombatMove == on)
1041 return;
1042
1043 mCanCombatMove = on;
1044
1045 if (!IsAIControlled())
1046 return;
1047
1049 {
1050 if (on && me->GetVictim())
1051 {
1053 {
1054 SetRun(mRun);
1055 me->GetMotionMaster()->MoveChase(me->GetVictim(), chaseRange);
1056 me->CastStop();
1057 }
1058 }
1059 else
1060 {
1061 me->StopMoving();
1063 me->GetMotionMaster()->Clear(false);
1065 }
1066 }
1067}
void CastStop(uint32 except_spellid=0, bool withInstant=true)
Interrupt the unit cast for all the current spells.
Definition: Unit.cpp:1161

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.

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

References SetData().

Referenced by SetData().

◆ SetData() [2/2]

void SmartAI::SetData ( uint32  id,
uint32  value,
WorldObject invoker 
)
968{
969 Unit* unit = nullptr;
970 GameObject* gob = nullptr;
971
972 if (invoker)
973 {
974 unit = invoker->ToUnit();
975 if (!unit)
976 gob = invoker->ToGameObject();
977 }
978
979 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, unit, id, value, false, nullptr, gob);
980}
@ SMART_EVENT_DATA_SET
Definition: SmartScriptMgr.h:157
Definition: GameObject.h:121

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

◆ SetDespawnTime()

void SmartAI::SetDespawnTime ( uint32  t)
inline
200 {
201 mDespawnTime = t;
202 mDespawnState = t ? 1 : 0;
203 }

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

void SmartAI::SetEvadeDisabled ( bool  disable = true)
1010{
1011 mEvadeDisabled = disable;
1012}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
998{
999 // xinef: set proper flag!
1000 //me->SetDisableGravity(fly);
1001 me->SetCanFly(fly);
1002}
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:3277

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 
)
1070{
1071 if (!target)
1072 {
1073 StopFollow(false);
1074 return;
1075 }
1076
1077 mFollowGuid = target->GetGUID();
1078 mFollowDist = dist;
1079 mFollowAngle = angle;
1080 mFollowArrivedTimer = 1000;
1081 mFollowCredit = credit;
1082 mFollowArrivedEntry = end;
1083 mFollowArrivedAlive = !aliveState; // negate - 0 is alive
1084 mFollowCreditType = creditType;
1085 SetRun(mRun);
1087}
void StopFollow(bool complete)
Definition: SmartAI.cpp:1089

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.

983{
984}

◆ SetInvincibilityHpLevel()

void SmartAI::SetInvincibilityHpLevel ( uint32  level)
inline
186{ 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:190
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition: SmartScript.cpp:5224

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

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
1005{
1006 me->SetSwim(swim);
1007}
bool SetSwim(bool enable) override
Definition: Creature.cpp:3229

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

◆ SetWPPauseTimer()

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

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player player)
overridevirtual

Reimplemented from UnitAI.

1015{
1017}
@ SMART_EVENT_GOSSIP_HELLO
Definition: SmartScriptMgr.h:183

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

◆ sGossipSelect()

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

Reimplemented from UnitAI.

Reimplemented in npc_stable_master::npc_stable_masterAI.

1020{
1021 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1022}
@ SMART_EVENT_GOSSIP_SELECT
Definition: SmartScriptMgr.h:181

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.

1025{
1026}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

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

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.

859{
860 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
861}
@ SMART_EVENT_SPELLHIT
Definition: SmartScriptMgr.h:127

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

◆ SpellHitTarget()

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

Reimplemented from CreatureAI.

864{
865 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
866}
@ SMART_EVENT_SPELLHIT_TARGET
Definition: SmartScriptMgr.h:150

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

◆ sQuestAccept()

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

Reimplemented from UnitAI.

1029{
1030 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1031}
@ SMART_EVENT_ACCEPTED_QUEST
Definition: SmartScriptMgr.h:138

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.

1034{
1035 GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
1036}
@ SMART_EVENT_REWARD_QUEST
Definition: SmartScriptMgr.h:139

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

◆ StartDespawn()

void SmartAI::StartDespawn ( )
inline
204{ 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 
)
188{
190 StopPath();
191
192 if (path)
193 {
194 if (!LoadPath(path))
195 return;
196 }
197
198 if (!mWayPoints || mWayPoints->empty())
199 return;
200
201 if (WayPoint* wp = GetNextWayPoint())
202 {
204 mCanRepeatPath = repeat;
205 SetRun(run);
206
207 if (invoker && invoker->IsPlayer())
208 {
211 }
212
213 Movement::PointsArray pathPoints;
214 GenerateWayPointArray(&pathPoints);
215
216 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
217 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
218 }
219}
@ SMART_EVENT_WAYPOINT_START
Definition: SmartScriptMgr.h:158
@ UNIT_NPC_FLAG_NONE
Definition: UnitDefines.h:293
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition: SmartAI.cpp:269
bool LoadPath(uint32 entry)
Definition: SmartAI.cpp:221
bool IsPlayer() const
Definition: Object.h:197
NPCFlags GetNpcFlags() const
Definition: Unit.h:693

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)
1090{
1092 mFollowDist = 0;
1093 mFollowAngle = 0;
1094 mFollowCredit = 0;
1095 mFollowArrivedTimer = 1000;
1098
1099 me->GetMotionMaster()->Clear(false);
1100 me->StopMoving();
1102
1103 if (!complete)
1104 return;
1105
1107 if (player)
1108 {
1109 if (!mFollowCreditType)
1111 else
1113 }
1114
1115 SetDespawnTime(5000);
1116 StartDespawn();
1117
1119}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition: SmartScriptMgr.h:184
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:223
void SetDespawnTime(uint32 t)
Definition: SmartAI.h:199
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition: Player.cpp:12733

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.

902{
905}
@ SMART_EVENT_SUMMON_DESPAWNED
Definition: SmartScriptMgr.h:154
void RemoveCreatureSummon(ObjectGuid const &guid)
Definition: SmartScript.cpp:5346

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.

822{
824}
@ SMART_EVENT_SUMMONED_UNIT_DIES
Definition: SmartScriptMgr.h:203

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

◆ SummonedCreatureEvade()

void SmartAI::SummonedCreatureEvade ( Creature summon)
overridevirtual

Reimplemented from CreatureAI.

827{
829}
@ SMART_EVENT_SUMMONED_UNIT_EVADE
Definition: SmartScriptMgr.h:216

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.

504{
505 bool hasVictim = UpdateVictim();
506 CheckConditions(diff);
507 GetScript()->OnUpdate(diff);
508 UpdatePath(diff);
509 UpdateDespawn(diff);
510
511 //TODO move to void
512 if (mFollowGuid)
513 {
514 if (mFollowArrivedTimer < diff)
515 {
517 {
518 StopFollow(true);
519 return;
520 }
521
522 mFollowArrivedTimer = 1000;
523 }
524 else
525 mFollowArrivedTimer -= diff;
526 }
527
528 if (!IsAIControlled())
529 {
530 if (CharmInfo* charmInfo = me->GetCharmInfo())
531 {
532 if (charmInfo->IsCommandAttack() && mCanAutoAttack)
533 {
535 }
536 }
537
538 return;
539 }
540
541 if (!hasVictim)
542 return;
543
544 if (mCanAutoAttack)
546}
#define INTERACTION_DISTANCE
Definition: ObjectDefines.h:24
void DoMeleeAttackIfReady()
Definition: UnitAI.cpp:39
void UpdatePath(const uint32 diff)
Definition: SmartAI.cpp:392
void CheckConditions(const uint32 diff)
Definition: SmartAI.cpp:474
void UpdateDespawn(const uint32 diff)
Definition: SmartAI.cpp:86
void OnUpdate(const uint32 diff)
Definition: SmartScript.cpp:4905
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition: Object.cpp:2446
Definition: CharmInfo.h:125
CharmInfo * GetCharmInfo()
Definition: Unit.h:1278

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
87{
88 if (mDespawnState <= 1 || mDespawnState > 3)
89 return;
90
91 if (mDespawnTime < diff)
92 {
93 if (mDespawnState == 2)
94 {
95 me->SetVisible(false);
96 mDespawnTime = 5000;
98 }
99 else
101 }
102 else
103 mDespawnTime -= diff;
104}
void DespawnOrUnsummon(Milliseconds msTimeToDespawn, Seconds forcedRespawnTimer)
Definition: Creature.cpp:2173

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

Referenced by UpdateAI().

◆ UpdatePath()

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

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

◆ 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