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)
 
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 SetScript9 (SmartScriptHolder &e, uint32 entry, Unit *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 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
 
void HealReceived (Unit *doneBy, uint32 &addhealth) override
 
void UpdateAI (uint32 diff) override
 
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
 
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
 
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 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 SetWPPauseTimer (uint32 time)
 
void SetForcedCombatMove (float dist)
 
- 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)
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
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.
 
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 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
 
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 ==================
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields =======================================
 
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 *)
 
- 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
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool apply)=0
 
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)
 
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 (NOTE: Creature engage logic should NOT be here, but in JustEngagedWith, which happens once threat is established!)
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat.
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 
virtual void HealReceived (Unit *, uint32 &)
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 
virtual void HealDone (Unit *, uint32 &)
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 
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)
 
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)
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the max threat target, which may not always 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)
 
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
 
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 // Xinef: Vehicle conditions
75 if (me->GetVehicleKit())
77}
@ SMART_ESCORT_NONE
Definition: SmartAI.h:32
#define sConditionMgr
Definition: ConditionMgr.h:289
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
Definition: ConditionMgr.h:138
Definition: CreatureAI.h:71
Creature *const me
Definition: CreatureAI.h:73
uint32 mDespawnTime
Definition: SmartAI.h:240
uint32 mEscortState
Definition: SmartAI.h:222
WayPoint * mLastWP
Definition: SmartAI.h:227
WPPath * mWayPoints
Definition: SmartAI.h:221
uint32 mEscortInvokerCheckTimer
Definition: SmartAI.h:243
uint32 mDespawnState
Definition: SmartAI.h:241
bool mOOCReached
Definition: SmartAI.h:225
uint32 mWPPauseTimer
Definition: SmartAI.h:226
uint32 mCurrentWPID
Definition: SmartAI.h:223
uint32 m_ConditionsTimer
Definition: SmartAI.h:249
bool mIsCharmed
Definition: SmartAI.h:208
bool mWPReached
Definition: SmartAI.h:224
uint32 mFollowArrivedTimer
Definition: SmartAI.h:210
float mFollowAngle
Definition: SmartAI.h:216
uint32 mEscortQuestID
Definition: SmartAI.h:192
bool mRun
Definition: SmartAI.h:231
uint32 mEscortNPCFlags
Definition: SmartAI.h:228
ConditionList conditions
Definition: SmartAI.h:248
uint32 mFollowCreditType
Definition: SmartAI.h:209
bool mFollowArrivedAlive
Definition: SmartAI.h:213
uint32 mInvincibilityHpLevel
Definition: SmartAI.h:236
bool mCanAutoAttack
Definition: SmartAI.h:233
bool mJustReset
Definition: SmartAI.h:244
bool mCanRepeatPath
Definition: SmartAI.h:230
bool mEvadeDisabled
Definition: SmartAI.h:232
bool mCanCombatMove
Definition: SmartAI.h:234
bool mForcedPaused
Definition: SmartAI.h:235
uint32 mFollowCredit
Definition: SmartAI.h:211
uint32 mFollowArrivedEntry
Definition: SmartAI.h:212
float mFollowDist
Definition: SmartAI.h:215
uint32 GetEntry() const
Definition: Object.h:109
Vehicle * GetVehicleKit() const
Definition: Unit.h:2367

References CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, conditions, Object::GetEntry(), Unit::GetVehicleKit(), m_ConditionsTimer, mCanAutoAttack, mCanCombatMove, mCanRepeatPath, 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
723{
724 if (!IsAIControlled())
725 return false;
726
727 // Xinef: if unit has no victim, or victim is player controlled thing
728 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
729 return false;
730
731 //experimental (unknown) flag not present
733 return false;
734
735 // Xinef: victim of unit has to be a player controlled unit
737 return false;
738
739 // Xinef: Check if victim can be assisted
740 if (!me->IsValidAssistTarget(who->GetVictim()))
741 return false;
742
743 //too far away and no free sight?
745 {
746 AttackStart(who);
747 return true;
748 }
749
750 return false;
751}
@ 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:820
bool IsAIControlled() const
Definition: SmartAI.cpp:79
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:199
uint32 type_flags
Definition: CreatureData.h:216
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:170
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition: Unit.h:1845
Unit * GetVictim() const
Definition: Unit.h:1398
bool IsValidAssistTarget(Unit const *target) const
Definition: Unit.cpp:13982

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.

821{
822 // xinef: dont allow charmed npcs to act on their own
824 {
825 if (who && mCanAutoAttack)
826 me->Attack(who, true);
827 return;
828 }
829
830 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
831 {
832 if (mCanCombatMove || GetScript()->GetMaxCombatDist())
833 {
834 SetRun(mRun);
836 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
837 {
839 me->StopMoving();
840 }
842 me->GetMotionMaster()->MoveChase(who, range > 0.f ? ChaseRange(range) : std::optional<ChaseRange>());
843 }
844 }
845}
@ UNIT_FLAG_POSSESSED
Definition: Unit.h:472
@ 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
SmartScript * GetScript()
Definition: SmartAI.h:73
void SetRun(bool run=true)
Definition: SmartAI.cpp:970
float GetCasterActualDist() const
Definition: SmartScript.h:229
uint32 GetActualCombatDist() const
Definition: SmartScript.h:222
MotionMaster * GetMotionMaster()
Definition: Unit.h:2276
bool HasUnitFlag(UnitFlags flags) const
Definition: Unit.h:1494
void StopMoving()
Definition: Unit.cpp:16918
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition: Unit.cpp:683
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:10280
Definition: MotionMaster.h:82
MovementGeneratorType GetMotionSlotType(int slot) const
Definition: MotionMaster.cpp:867
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Definition: MotionMaster.cpp:300
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:178

References Unit::Attack(), ESCORT_MOTION_TYPE, SmartScript::GetActualCombatDist(), SmartScript::GetCasterActualDist(), Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), GetScript(), 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.

718{
719 return !(me->GetReactState() == REACT_PASSIVE);
720}
@ REACT_PASSIVE
Definition: Unit.h:1035
ReactStates GetReactState() const
Definition: Creature.h:91

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

◆ CanCombatMove()

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

References mCanCombatMove.

◆ CheckConditions()

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

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.

897{
898 GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
899
900 // xinef: end escort upon corpse remove, safe check in case of immediate despawn
901 if (IsEscorted())
902 EndPath(true);
903}
@ SMART_EVENT_CORPSE_REMOVED
Definition: SmartScriptMgr.h:154
void EndPath(bool fail=false)
Definition: SmartAI.cpp:286
bool IsEscorted() override
Definition: SmartAI.h:64
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:100

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

◆ DamageDealt()

void SmartAI::DamageDealt ( Unit doneTo,
uint32 damage,
DamageEffectType  damagetyp 
)
overridevirtual

Reimplemented from UnitAI.

886{
888}
@ SMART_EVENT_DAMAGED_TARGET
Definition: SmartScriptMgr.h:151

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

◆ DamageTaken()

void SmartAI::DamageTaken ( Unit done_by,
uint32 damage,
DamageEffectType  damagetype,
SpellSchoolMask  damageSchoolMask 
)
overridevirtual

Reimplemented from UnitAI.

858{
859 if (doneBy)
861
862 if (!IsAIControlled()) // don't allow players to use unkillable units
863 return;
864
865 // Xinef: skip nodamage type (eg. instakill effect)
866 if (damagetype != NODAMAGE && mInvincibilityHpLevel && (damage >= me->GetHealth() - mInvincibilityHpLevel))
867 damage = me->GetHealth() - mInvincibilityHpLevel; // damage should not be nullified, because of player damage req.
868}
@ SMART_EVENT_DAMAGED
Definition: SmartScriptMgr.h:150
@ NODAMAGE
Definition: Unit.h:439
uint32 GetHealth() const
Definition: Unit.h:1454

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.

947{
949}
@ SMART_EVENT_ACTION_DONE
Definition: SmartScriptMgr.h:190

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

◆ EndPath()

void SmartAI::EndPath ( bool  fail = false)
287{
289 mWayPoints = nullptr;
290 mLastWP = nullptr;
291 mWPPauseTimer = 0;
292
293 if (mEscortNPCFlags)
294 {
296 mEscortNPCFlags = 0;
297 }
298
300 if (targets && mEscortQuestID)
301 {
302 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
303 {
304 Player* player = targets->front()->ToPlayer();
305 if (Group* group = player->GetGroup())
306 {
307 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
308 {
309 Player* groupGuy = groupRef->GetSource();
310 if (!groupGuy || !player->IsInMap(groupGuy))
311 continue;
312
313 if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
315 else if (fail && groupGuy->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
316 groupGuy->FailQuest(mEscortQuestID);
317 }
318 }
319 else
320 {
321 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
323 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
324 player->FailQuest(mEscortQuestID);
325 }
326 }
327 else
328 {
329 for (WorldObject* target : *targets)
330 {
331 if (GetScript()->IsPlayer(target))
332 {
333 Player* player = target->ToPlayer();
334 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
336 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
337 player->FailQuest(mEscortQuestID);
338 }
339 }
340 }
341 }
342
343 // Xinef: if the escort failed - DO NOT PROCESS ANYTHING
344 // Xinef: End Path events should be only processed if it was SUCCESSFUL stop or stop called by SMART_ACTION_WAYPOINT_STOP
345 if (fail)
346 {
347 mCurrentWPID = 0;
348 return;
349 }
350
352 mCurrentWPID = 0;
353
354 if (mCanRepeatPath)
355 {
356 if (IsAIControlled())
357 StartPath(mRun, GetScript()->GetPathId(), true);
358 }
359 else
360 GetScript()->SetPathId(0);
361
362 if (mDespawnState == 1)
363 StartDespawn();
364}
@ SMART_ESCORT_ESCORTING
Definition: SmartAI.h:33
@ SMART_ESCORT_PAUSED
Definition: SmartAI.h:35
@ SMART_ESCORT_RETURNING
Definition: SmartAI.h:34
std::vector< WorldObject * > ObjectVector
Definition: SmartScriptMgr.h:1915
@ SMART_EVENT_WAYPOINT_ENDED
Definition: SmartScriptMgr.h:176
@ SMART_ESCORT_TARGETS
Definition: SmartScriptMgr.h:59
NPCFlags
Non Player Character flags.
Definition: Unit.h:514
@ QUEST_STATUS_INCOMPLETE
Definition: QuestDef.h:103
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:185
void StartDespawn()
Definition: SmartAI.h:199
ObjectVector const * GetStoredTargetVector(uint32 id, WorldObject const &ref) const
Definition: SmartScript.h:115
void SetPathId(uint32 id)
Definition: SmartScript.h:52
Definition: Object.h:393
bool IsInMap(WorldObject const *obj) const
Definition: Object.cpp:1285
bool HasCorpse() const
Definition: Player.h:2002
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition: PlayerQuest.cpp:1804
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition: Player.cpp:12678
Group * GetGroup()
Definition: Player.h:2431
void AreaExploredOrEventHappens(uint32 questId)
Definition: PlayerQuest.cpp:1777
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition: PlayerQuest.cpp:1416
void FailQuest(uint32 quest_id)
Definition: PlayerQuest.cpp:885
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:1663
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.

645{
646 if (mEvadeDisabled)
647 {
649 return;
650 }
651
653 {
654 me->AttackStop();
655 return;
656 }
657
658 if (!_EnterEvadeMode())
659 return;
660
662
663 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
664
665 SetRun(mRun);
667 {
670 }
671 else if (mFollowGuid)
672 {
676
677 // xinef: do not forget to reset scripts as we wont call reached home
678 GetScript()->OnReset();
679 }
680 else
681 {
683
684 // xinef: do not forget to reset scripts as we wont call reached home
686 GetScript()->OnReset();
687 }
688}
@ SMART_EVENT_EVADE
Definition: SmartScriptMgr.h:125
@ UNIT_STATE_EVADE
Definition: Unit.h:346
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition: CreatureAI.cpp:291
bool HasEscortState(uint32 uiEscortState)
Definition: SmartAI.h:62
void ReturnToLastOOCPos()
Definition: SmartAI.cpp:379
void AddEscortState(uint32 uiEscortState)
Definition: SmartAI.h:63
ObjectGuid mFollowGuid
Definition: SmartAI.h:214
void OnReset()
Definition: SmartScript.cpp:76
void ClearUnitState(uint32 f)
Definition: Unit.h:1411
void AddUnitState(uint32 f)
Definition: Unit.h:1409
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1410
ObjectGuid GetCharmerGUID() const
Definition: Unit.h:1834
bool AttackStop()
Definition: Unit.cpp:10407
void MoveTargetedHome(bool walk=false)
Definition: MotionMaster.cpp:252
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE)
Definition: MotionMaster.cpp:394

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

952{
953 return 0;
954}

◆ GetGUID()

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

Reimplemented from UnitAI.

966{
967 return ObjectGuid::Empty;
968}
static ObjectGuid const Empty
Definition: ObjectGuid.h:122

References ObjectGuid::Empty.

◆ GetNextWayPoint()

WayPoint * SmartAI::GetNextWayPoint ( )
105{
106 if (!mWayPoints || mWayPoints->empty())
107 return nullptr;
108
109 mCurrentWPID++;
110 WPPath::const_iterator itr = mWayPoints->find(mCurrentWPID);
111 if (itr != mWayPoints->end())
112 {
113 mLastWP = (*itr).second;
114 if (mLastWP->id != mCurrentWPID)
115 LOG_ERROR("scripts.ai.sai", "SmartAI::GetNextWayPoint: Got not expected waypoint id {}, expected {}", mLastWP->id, mCurrentWPID);
116
117 return (*itr).second;
118 }
119 return nullptr;
120}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
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
229{ return mWayPoints ? mWayPoints->size() : 0; }

References mWayPoints.

Referenced by MovepointReached(), and UpdatePath().

◆ HasEscortState()

bool SmartAI::HasEscortState ( uint32  uiEscortState)
inline

◆ HealReceived()

void SmartAI::HealReceived ( Unit doneBy,
uint32 addhealth 
)
overridevirtual

Reimplemented from UnitAI.

871{
873}
@ 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.

911{
913 if (!me->isDead())
914 {
915 mJustReset = true;
918 }
919}
@ SMART_EVENT_RESPAWN
Definition: SmartScriptMgr.h:129
void JustReachedHome() override
Definition: SmartAI.cpp:774
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition: SmartScript.cpp:4789
bool isDead() const
Definition: Unit.h:1824

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

881{
882 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
883}
@ SMART_EVENT_JUST_SUMMONED
Definition: SmartScriptMgr.h:172
GameObject * ToGameObject()
Definition: Object.h:202
Unit * ToUnit()
Definition: Object.h:200

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

◆ JustDied()

void SmartAI::JustDied ( Unit killer)
overridevirtual

Reimplemented from CreatureAI.

798{
801 EndPath(true);
802}
@ 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.

790{
791 // Xinef: Interrupt channeled spells
792 if (IsAIControlled())
795}
@ SMART_EVENT_AGGRO
Definition: SmartScriptMgr.h:122
@ CURRENT_CHANNELED_SPELL
Definition: Unit.h:992
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, bool bySelf=false)
Definition: Unit.cpp:4014

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

775{
776 GetScript()->OnReset();
777
778 if (!mJustReset)
779 {
781
784 }
785
786 mJustReset = false;
787}
@ SMART_EVENT_REACHED_HOME
Definition: SmartScriptMgr.h:139
@ IDLE_MOTION_TYPE
Definition: MotionMaster.h:37
bool UpdateVictim()
Definition: CreatureAI.cpp:268
uint32 GetWaypointPath() const
Definition: Creature.h:340
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:859
void MovePath(uint32 path_id, bool repeatable)
Definition: MotionMaster.cpp:800

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.

754{
755 mDespawnTime = 0;
756 mDespawnState = 0;
758 me->SetVisible(true);
761 mJustReset = true;
764 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
765 mFollowDist = 0;
766 mFollowAngle = 0;
767 mFollowCredit = 0;
768 mFollowArrivedTimer = 1000;
771 mFollowArrivedAlive = true;
772}
uint32 faction
Definition: CreatureData.h:191
void Clear()
Definition: ObjectGuid.h:140
void SetVisible(bool x)
Definition: Unit.cpp:14220
void RestoreFaction()
Definition: Unit.cpp:18959
uint32 GetFaction() const
Definition: Unit.h:1509

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.

810{
812 GetScript()->AddCreatureSummon(creature->GetGUID());
813}
@ SMART_EVENT_SUMMONED_UNIT
Definition: SmartScriptMgr.h:135
void AddCreatureSummon(ObjectGuid const &guid)
Definition: SmartScript.cpp:5090
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106

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

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

805{
807}
@ SMART_EVENT_KILL
Definition: SmartScriptMgr.h:123

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

◆ LoadPath()

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

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

Referenced by StartPath().

◆ MoveInLineOfSight()

void SmartAI::MoveInLineOfSight ( Unit who)
overridevirtual

Reimplemented from CreatureAI.

Reimplemented in npc_fairbanks::npc_fairbanksAI.

691{
692 if (!who)
693 return;
694
696
697 if (!IsAIControlled())
698 return;
699
700 if (me->GetVictim())
701 return;
702
704 return;
705
707 {
709 {
712 }
713 AttackStart(who);
714 }
715}
@ REACT_AGGRESSIVE
Definition: Unit.h:1037
@ UNIT_STATE_DISTRACTED
Definition: Unit.h:337
bool AssistPlayerInCombatAgainst(Unit *who)
Definition: SmartAI.cpp:722
void OnMoveInLineOfSight(Unit *who)
Definition: SmartScript.cpp:4861
bool CanStartAttack(Unit const *u) const
Definition: Creature.cpp:1856
bool HasReactState(ReactStates state) const
Definition: Creature.h:92
void Clear(bool reset=true)
Definition: MotionMaster.h:165

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.

632{
633 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
635
636 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
638 return;
639
640 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
642}
@ SMART_EVENT_MOVEMENTINFORM
Definition: SmartScriptMgr.h:152
@ SMART_ESCORT_LAST_OOC_POINT
Definition: SmartScriptMgr.h:57
Data
Definition: blackfathom_deeps.h:24
void MovepointReached(uint32 id)
Definition: SmartAI.cpp:586

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

◆ MovepointReached()

void SmartAI::MovepointReached ( uint32  id)
587{
588 // override the id, path can be resumed any time and counter will reset
589 // mCurrentWPID holds proper id
590
591 // xinef: both point movement and escort generator can enter this function
593 {
594 mOOCReached = true;
595 return;
596 }
597
598 mWPReached = true;
600
601 if (mLastWP)
602 {
605 }
606
608 {
611
614 }
615 // Xinef: Can be unset in ProcessEvents
617 {
618 mWPReached = false;
619 if (mCurrentWPID == GetWPCount())
620 EndPath();
621 else if (GetNextWayPoint())
622 {
623 SetRun(mRun);
624 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
625 if (me->movespline->Finalized())
626 ResumePath();
627 }
628 }
629}
@ SMART_EVENT_WAYPOINT_REACHED
Definition: SmartScriptMgr.h:158
WayPoint * GetNextWayPoint()
Definition: SmartAI.cpp:104
uint32 GetWPCount()
Definition: SmartAI.h:229
void ResumePath()
Definition: SmartAI.cpp:366
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:330
void SetPosition(float x, float y, float z, float o)
Definition: Creature.cpp:3072
float GetOrientation() const
Definition: Position.h:120
void GetPosition(float &x, float &y) const
Definition: Position.h:122
Movement::MoveSpline * movespline
Definition: Unit.h:2454
void StopMovingOnCurrentPos()
Definition: Unit.cpp:16957
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

Reimplemented from CreatureAI.

922{
923 bool const charmed = me->IsCharmed();
924 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
925 {
927 EndPath(true);
928 }
929
930 mIsCharmed = charmed;
931
932 if (!charmed && !me->IsInEvadeMode())
933 {
934 if (mCanRepeatPath)
935 StartPath(mRun, GetScript()->GetPathId(), true);
936 else
937 me->SetWalk(!mRun);
938
939 if (Unit* charmer = me->GetCharmer())
940 AttackStart(charmer);
941 }
942
943 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
944}
@ SMART_EVENT_CHARMED
Definition: SmartScriptMgr.h:147
bool SetWalk(bool enable) override
Definition: Creature.cpp:3098
bool IsInEvadeMode() const
Definition: Creature.h:130
bool IsCharmed() const
Definition: Unit.h:1885
Unit * GetCharmer() const
Definition: Unit.cpp:10607

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.

1126{
1127 // Xinef: i dont think this is necessery (can be made as event parameter)
1128 //if (!result)
1129 // return;
1130
1132}
@ 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.

906{
908}
@ SMART_EVENT_PASSENGER_REMOVED
Definition: SmartScriptMgr.h:146
@ SMART_EVENT_PASSENGER_BOARDED
Definition: SmartScriptMgr.h:145

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

◆ PausePath()

void SmartAI::PausePath ( uint32  delay,
bool  forced = false 
)
236{
238 return;
239
241 {
242 LOG_ERROR("scripts.ai.sai", "SmartAI::StartPath: Creature entry {} wanted to pause waypoint movement while already paused, ignoring.", me->GetEntry());
243 return;
244 }
245
247 mWPPauseTimer = delay;
248 if (forced && !mWPReached)
249 {
250 mForcedPaused = forced;
251 SetRun(mRun);
254
255 me->StopMoving();
256 me->GetMotionMaster()->MoveIdle();//force stop
257
258 auto waypoint = mWayPoints->find(mCurrentWPID);
259 if (waypoint->second->o.has_value())
260 {
261 me->SetFacingTo(waypoint->second->o.has_value());
262 }
263 }
265}
@ SMART_EVENT_WAYPOINT_PAUSED
Definition: SmartScriptMgr.h:173
void SetFacingTo(float ori)
Definition: Unit.cpp:20884

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

References PERMIT_BASE_NO.

◆ ReceiveEmote()

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

Reimplemented from CreatureAI.

876{
878}
@ SMART_EVENT_RECEIVE_EMOTE
Definition: SmartScriptMgr.h:140

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 ( )
367{
368 SetRun(mRun);
369
370 if (mLastWP)
371 {
372 Movement::PointsArray pathPoints;
373 GenerateWayPointArray(&pathPoints);
374
375 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
376 }
377}
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:28
void GenerateWayPointArray(Movement::PointsArray *points)
Definition: SmartAI.cpp:122
void MoveSplinePath(Movement::PointsArray *path)
Definition: MotionMaster.cpp:436

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

Referenced by MovepointReached(), and UpdatePath().

◆ ReturnToLastOOCPos()

void SmartAI::ReturnToLastOOCPos ( )
private
380{
381 if (!IsAIControlled())
382 return;
383
384 me->SetWalk(false);
385 float x, y, z, o;
386 me->GetHomePosition(x, y, z, o);
388}
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:332
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition: MotionMaster.h:211

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.

◆ SetCombatMove()

void SmartAI::SetCombatMove ( bool  on)
1027{
1028 // Xinef: Fix Combat Movement
1029 if (GetScript()->GetMaxCombatDist()/* || GetScript()->GetCasterMaxDist()*/) // Xinef: we only need this hack for old caster movement system
1030 return;
1031
1032 if (mCanCombatMove == on)
1033 return;
1034
1035 mCanCombatMove = on;
1036
1037 if (!IsAIControlled())
1038 return;
1039
1041 {
1042 if (on && me->GetVictim())
1043 {
1045 {
1046 SetRun(mRun);
1048 me->CastStop();
1049 }
1050 }
1051 else
1052 {
1053 me->StopMoving();
1055 me->GetMotionMaster()->Clear(false);
1057 }
1058 }
1059}
@ CHASE_MOTION_TYPE
Definition: MotionMaster.h:43
void CastStop(uint32 except_spellid=0, bool withInstant=true)
Definition: Unit.cpp:1162

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

◆ SetData()

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

Reimplemented from UnitAI.

957{
958 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, nullptr, id, value);
959}
@ SMART_EVENT_DATA_SET
Definition: SmartScriptMgr.h:156

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

◆ SetDespawnTime()

void SmartAI::SetDespawnTime ( uint32  t)
inline
195 {
196 mDespawnTime = t;
197 mDespawnState = t ? 1 : 0;
198 }

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

void SmartAI::SetEvadeDisabled ( bool  disable = true)
989{
990 mEvadeDisabled = disable;
991}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
977{
978 // xinef: set proper flag!
979 //me->SetDisableGravity(fly);
980 me->SetCanFly(fly);
981}
bool SetCanFly(bool enable, bool packetOnly=false) override
Definition: Creature.cpp:3194

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 
)
1062{
1063 if (!target)
1064 {
1065 StopFollow(false);
1066 return;
1067 }
1068
1069 mFollowGuid = target->GetGUID();
1070 mFollowDist = dist;
1071 mFollowAngle = angle;
1072 mFollowArrivedTimer = 1000;
1073 mFollowCredit = credit;
1074 mFollowArrivedEntry = end;
1075 mFollowArrivedAlive = !aliveState; // negate - 0 is alive
1076 mFollowCreditType = creditType;
1077 SetRun(mRun);
1079}
void StopFollow(bool complete)
Definition: SmartAI.cpp:1081

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

◆ SetForcedCombatMove()

void SmartAI::SetForcedCombatMove ( float  dist)
1018{
1019 if (!me->GetVictim())
1020 return;
1021
1022 SetRun(mRun);
1023 me->GetMotionMaster()->MoveChase(me->GetVictim(), dist);
1024}

References Unit::GetMotionMaster(), Unit::GetVictim(), CreatureAI::me, MotionMaster::MoveChase(), mRun, and SetRun().

◆ SetGUID()

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

Reimplemented from UnitAI.

962{
963}

◆ SetInvincibilityHpLevel()

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

References mInvincibilityHpLevel.

Referenced by SmartScript::ProcessAction().

◆ SetRun()

void SmartAI::SetRun ( bool  run = true)

◆ SetScript9()

void SmartAI::SetScript9 ( SmartScriptHolder e,
uint32  entry,
Unit invoker 
)
1114{
1115 if (invoker)
1116 GetScript()->mLastInvoker = invoker->GetGUID();
1117 GetScript()->SetScript9(e, entry);
1118}
ObjectGuid mLastInvoker
Definition: SmartScript.h:215
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition: SmartScript.cpp:4973

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

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
984{
985 me->SetSwim(swim);
986}
bool SetSwim(bool enable) override
Definition: Creature.cpp:3146

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

◆ SetWPPauseTimer()

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

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player player)
overridevirtual

Reimplemented from UnitAI.

994{
996}
@ 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.

Reimplemented in npc_stable_master::npc_stable_masterAI.

999{
1000 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1001}
@ 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.

1004{
1005}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

1121{
1123}
@ 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.

848{
849 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
850}
@ 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.

853{
854 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
855}
@ 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.

1008{
1009 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1010}
@ 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.

1013{
1014 GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
1015}
@ SMART_EVENT_REWARD_QUEST
Definition: SmartScriptMgr.h:138

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

◆ StartDespawn()

void SmartAI::StartDespawn ( )
inline
199{ 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 
)
186{
188 StopPath();
189
190 if (path)
191 {
192 if (!LoadPath(path))
193 return;
194 }
195
196 if (!mWayPoints || mWayPoints->empty())
197 return;
198
199 if (WayPoint* wp = GetNextWayPoint())
200 {
202 mCanRepeatPath = repeat;
203 SetRun(run);
204
205 if (invoker && invoker->GetTypeId() == TYPEID_PLAYER)
206 {
209 }
210
211 Movement::PointsArray pathPoints;
212 GenerateWayPointArray(&pathPoints);
213
214 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
215 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
216 }
217}
@ SMART_EVENT_WAYPOINT_START
Definition: SmartScriptMgr.h:157
@ TYPEID_PLAYER
Definition: ObjectGuid.h:38
@ UNIT_NPC_FLAG_NONE
Definition: Unit.h:515
void StopPath(uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
Definition: SmartAI.cpp:267
bool LoadPath(uint32 entry)
Definition: SmartAI.cpp:219
TypeID GetTypeId() const
Definition: Object.h:121
NPCFlags GetNpcFlags() const
Definition: Unit.h:1659

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

Referenced by EndPath(), and OnCharmed().

◆ StopFollow()

void SmartAI::StopFollow ( bool  complete)
1082{
1084 mFollowDist = 0;
1085 mFollowAngle = 0;
1086 mFollowCredit = 0;
1087 mFollowArrivedTimer = 1000;
1090
1091 me->GetMotionMaster()->Clear(false);
1092 me->StopMoving();
1094
1095 if (!complete)
1096 return;
1097
1099 if (player)
1100 {
1101 if (!mFollowCreditType)
1103 else
1105 }
1106
1107 SetDespawnTime(5000);
1108 StartDespawn();
1109
1111}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition: SmartScriptMgr.h:183
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:223
void SetDespawnTime(uint32 t)
Definition: SmartAI.h:194
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition: Player.cpp:12650

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.

891{
894}
@ SMART_EVENT_SUMMON_DESPAWNED
Definition: SmartScriptMgr.h:153
void RemoveCreatureSummon(ObjectGuid const &guid)
Definition: SmartScript.cpp:5095

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.

816{
818}
@ SMART_EVENT_SUMMONED_UNIT_DIES
Definition: SmartScriptMgr.h:202

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

◆ UpdateAI()

void SmartAI::UpdateAI ( uint32  diff)
overridevirtual

Implements UnitAI.

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

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

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

Referenced by UpdateAI().

◆ UpdatePath()

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

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

◆ 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