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_scarlet_guard::npc_scarlet_guardAI 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 HealDone (Unit *, uint32 &)
 
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
 
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
31 : CreatureAI(c)
32{
33 mIsCharmed = false;
34 // copy script to local (protection for table reload)
35
36 mWayPoints = nullptr;
38 mCurrentWPID = 0;//first wp id is 1 !!
39 mWPReached = false;
40 mOOCReached = false;
41 mWPPauseTimer = 0;
42 mLastWP = nullptr;
44
45 mCanRepeatPath = false;
46
47 // spawn in run mode
48 // Xinef: spawn in run mode and set mRun to run... this overrides SetWalk EVERYWHERE
49 mRun = true;
50 mEvadeDisabled = false;
51
52 mCanAutoAttack = true;
53 mCanCombatMove = true;
54
55 mForcedPaused = false;
56
58
59 mDespawnTime = 0;
60 mDespawnState = 0;
61
63 mFollowDist = 0;
64 mFollowAngle = 0;
65 mFollowCredit = 0;
71
72 mJustReset = false;
73
74 // Xinef: Vehicle conditions
76 if (me->GetVehicleKit())
78}
@ 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:70
Creature *const me
Definition: CreatureAI.h:72
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:2353

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
724{
725 if (!IsAIControlled())
726 return false;
727
728 // Xinef: if unit has no victim, or victim is player controlled thing
729 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
730 return false;
731
732 //experimental (unknown) flag not present
734 return false;
735
736 // Xinef: victim of unit has to be a player controlled unit
738 return false;
739
740 // Xinef: Check if victim can be assisted
741 if (!me->IsValidAssistTarget(who->GetVictim()))
742 return false;
743
744 //too far away and no free sight?
746 {
747 AttackStart(who);
748 return true;
749 }
750
751 return false;
752}
@ SMART_MAX_AID_DIST
Definition: SmartAI.h:41
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition: SharedDefines.h:2679
void AttackStart(Unit *who) override
Definition: SmartAI.cpp:835
bool IsAIControlled() const
Definition: SmartAI.cpp:80
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:197
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:1831
Unit * GetVictim() const
Definition: Unit.h:1386
bool IsValidAssistTarget(Unit const *target) const
Definition: Unit.cpp:13896

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.

836{
837 // xinef: dont allow charmed npcs to act on their own
839 {
840 if (who && mCanAutoAttack)
841 me->Attack(who, true);
842 return;
843 }
844
845 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
846 {
847 if (mCanCombatMove || GetScript()->GetMaxCombatDist())
848 {
849 SetRun(mRun);
851 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
852 {
854 me->StopMoving();
855 }
857 me->GetMotionMaster()->MoveChase(who, range > 0.f ? ChaseRange(range) : std::optional<ChaseRange>());
858 }
859 }
860}
@ 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:985
float GetCasterActualDist() const
Definition: SmartScript.h:229
uint32 GetActualCombatDist() const
Definition: SmartScript.h:222
MotionMaster * GetMotionMaster()
Definition: Unit.h:2262
bool HasUnitFlag(UnitFlags flags) const
Definition: Unit.h:1480
void StopMoving()
Definition: Unit.cpp:16824
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition: Unit.cpp:683
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:10245
Definition: MotionMaster.h:82
MovementGeneratorType GetMotionSlotType(int slot) const
Definition: MotionMaster.cpp:825
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Definition: MotionMaster.cpp:299
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.

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

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

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

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.

901{
903}
@ 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.

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

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.

962{
964}
@ SMART_EVENT_ACTION_DONE
Definition: SmartScriptMgr.h:190

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

◆ EndPath()

void SmartAI::EndPath ( bool  fail = false)
288{
290 mWayPoints = nullptr;
291 mLastWP = nullptr;
292 mWPPauseTimer = 0;
293
294 if (mEscortNPCFlags)
295 {
297 mEscortNPCFlags = 0;
298 }
299
301 if (targets && mEscortQuestID)
302 {
303 if (targets->size() == 1 && GetScript()->IsPlayer((*targets->begin())))
304 {
305 Player* player = targets->front()->ToPlayer();
306 if (Group* group = player->GetGroup())
307 {
308 for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
309 {
310 Player* groupGuy = groupRef->GetSource();
311 if (!groupGuy || !player->IsInMap(groupGuy))
312 continue;
313
314 if (!fail && groupGuy->IsAtGroupRewardDistance(me) && !groupGuy->HasCorpse())
316 else if (fail && groupGuy->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
317 groupGuy->FailQuest(mEscortQuestID);
318 }
319 }
320 else
321 {
322 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
324 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
325 player->FailQuest(mEscortQuestID);
326 }
327 }
328 else
329 {
330 for (WorldObject* target : *targets)
331 {
332 if (GetScript()->IsPlayer(target))
333 {
334 Player* player = target->ToPlayer();
335 if (!fail && player->IsAtGroupRewardDistance(me) && !player->HasCorpse())
337 else if (fail && player->GetQuestStatus(mEscortQuestID) == QUEST_STATUS_INCOMPLETE)
338 player->FailQuest(mEscortQuestID);
339 }
340 }
341 }
342 }
343
344 // Xinef: if the escort failed - DO NOT PROCESS ANYTHING
345 // Xinef: End Path events should be only processed if it was SUCCESSFUL stop or stop called by SMART_ACTION_WAYPOINT_STOP
346 if (fail)
347 {
348 mCurrentWPID = 0;
349 return;
350 }
351
353 mCurrentWPID = 0;
354
355 if (mCanRepeatPath)
356 {
357 if (IsAIControlled())
358 StartPath(mRun, GetScript()->GetPathId(), true);
359 }
360 else
361 GetScript()->SetPathId(0);
362
363 if (mDespawnState == 1)
364 StartDespawn();
365}
@ 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:1823
@ 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:186
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:1989
void GroupEventHappens(uint32 questId, WorldObject const *pEventObject)
Definition: PlayerQuest.cpp:1802
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition: Player.cpp:12655
Group * GetGroup()
Definition: Player.h:2418
void AreaExploredOrEventHappens(uint32 questId)
Definition: PlayerQuest.cpp:1775
QuestStatus GetQuestStatus(uint32 quest_id) const
Definition: PlayerQuest.cpp:1414
void FailQuest(uint32 quest_id)
Definition: PlayerQuest.cpp:883
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:1649
Definition: Group.h:168
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.

646{
647 if (mEvadeDisabled)
648 {
650 return;
651 }
652
654 {
655 me->AttackStop();
656 return;
657 }
658
659 if (!_EnterEvadeMode())
660 return;
661
663
664 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
665
666 SetRun(mRun);
668 {
671 }
672 else if (mFollowGuid)
673 {
677
678 // xinef: do not forget to reset scripts as we wont call reached home
679 GetScript()->OnReset();
680 }
681 else
682 {
684
685 // xinef: do not forget to reset scripts as we wont call reached home
687 GetScript()->OnReset();
688 }
689}
@ SMART_EVENT_EVADE
Definition: SmartScriptMgr.h:125
@ UNIT_STATE_EVADE
Definition: Unit.h:346
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition: CreatureAI.cpp:292
bool HasEscortState(uint32 uiEscortState)
Definition: SmartAI.h:62
void ReturnToLastOOCPos()
Definition: SmartAI.cpp:380
void AddEscortState(uint32 uiEscortState)
Definition: SmartAI.h:63
ObjectGuid mFollowGuid
Definition: SmartAI.h:214
void OnReset()
Definition: SmartScript.cpp:71
void ClearUnitState(uint32 f)
Definition: Unit.h:1399
void AddUnitState(uint32 f)
Definition: Unit.h:1397
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1398
ObjectGuid GetCharmerGUID() const
Definition: Unit.h:1820
bool AttackStop()
Definition: Unit.cpp:10368
void MoveTargetedHome(bool walk=false)
Definition: MotionMaster.cpp:251
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE)
Definition: MotionMaster.cpp:367

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

967{
968 return 0;
969}

◆ GetGUID()

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

Reimplemented from UnitAI.

981{
982 return ObjectGuid::Empty;
983}
static ObjectGuid const Empty
Definition: ObjectGuid.h:122

References ObjectGuid::Empty.

◆ GetNextWayPoint()

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

886{
888}
@ 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.

926{
928 if (!me->isDead())
929 {
930 mJustReset = true;
933 }
934}
@ SMART_EVENT_RESPAWN
Definition: SmartScriptMgr.h:129
void JustReachedHome() override
Definition: SmartAI.cpp:775
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition: SmartScript.cpp:4327
bool isDead() const
Definition: Unit.h:1810

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

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

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

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

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

776{
777 GetScript()->OnReset();
778
779 if (!mJustReset)
780 {
782
785 }
786
787 mJustReset = false;
788}
@ SMART_EVENT_REACHED_HOME
Definition: SmartScriptMgr.h:139
@ IDLE_MOTION_TYPE
Definition: MotionMaster.h:37
bool UpdateVictim()
Definition: CreatureAI.cpp:269
uint32 GetWaypointPath() const
Definition: Creature.h:338
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:817
void MovePath(uint32 path_id, bool repeatable)
Definition: MotionMaster.cpp:758

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.

755{
756 mDespawnTime = 0;
757 mDespawnState = 0;
759 me->SetVisible(true);
762 mJustReset = true;
765 mFollowGuid.Clear();//do not reset follower on Reset(), we need it after combat evade
766 mFollowDist = 0;
767 mFollowAngle = 0;
768 mFollowCredit = 0;
769 mFollowArrivedTimer = 1000;
772 mFollowArrivedAlive = true;
773}
uint32 faction
Definition: CreatureData.h:191
void Clear()
Definition: ObjectGuid.h:140
void SetVisible(bool x)
Definition: Unit.cpp:14129
void RestoreFaction()
Definition: Unit.cpp:18863
uint32 GetFaction() const
Definition: Unit.h:1495

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.

811{
813 GetScript()->AddCreatureSummon(creature->GetGUID());
814
815 if (me->IsEngaged() && !creature->IsInEvadeMode())
816 {
817 if (Unit* victim = me->GetVictim())
818 {
819 creature->SetInCombatWith(victim);
820 victim->SetInCombatWith(creature);
821
822 if (creature->CanHaveThreatList())
823 {
824 creature->AddThreat(victim, 0.0f);
825 }
826 }
827 }
828}
@ SMART_EVENT_SUMMONED_UNIT
Definition: SmartScriptMgr.h:135
void AddCreatureSummon(ObjectGuid const &guid)
Definition: SmartScript.cpp:4628
bool IsInEvadeMode() const
Definition: Creature.h:129
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
bool CanHaveThreatList() const
Definition: Unit.cpp:14509
void AddThreat(Unit *victim, float fThreat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=nullptr)
Definition: Unit.cpp:14548
void SetInCombatWith(Unit *enemy, uint32 duration=0)
Definition: Unit.cpp:13492
bool IsEngaged() const
Definition: Unit.h:1685

References SmartScript::AddCreatureSummon(), Unit::AddThreat(), Unit::CanHaveThreatList(), Object::GetGUID(), GetScript(), Unit::GetVictim(), Unit::IsEngaged(), Creature::IsInEvadeMode(), CreatureAI::me, SmartScript::ProcessEventsFor(), Unit::SetInCombatWith(), and SMART_EVENT_SUMMONED_UNIT.

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

806{
808}
@ SMART_EVENT_KILL
Definition: SmartScriptMgr.h:123

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

◆ LoadPath()

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

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_scarlet_guard::npc_scarlet_guardAI, and npc_fairbanks::npc_fairbanksAI.

692{
693 if (!who)
694 return;
695
697
698 if (!IsAIControlled())
699 return;
700
701 if (me->GetVictim())
702 return;
703
705 return;
706
708 {
710 {
713 }
714 AttackStart(who);
715 }
716}
@ REACT_AGGRESSIVE
Definition: Unit.h:1025
@ UNIT_STATE_DISTRACTED
Definition: Unit.h:337
bool AssistPlayerInCombatAgainst(Unit *who)
Definition: SmartAI.cpp:723
void OnMoveInLineOfSight(Unit *who)
Definition: SmartScript.cpp:4399
bool CanStartAttack(Unit const *u) const
Definition: Creature.cpp:1887
bool HasReactState(ReactStates state) const
Definition: Creature.h:91
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_scarlet_guard::npc_scarlet_guardAI::MoveInLineOfSight(), and npc_fairbanks::npc_fairbanksAI::MoveInLineOfSight().

◆ MovementInform()

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

Reimplemented from CreatureAI.

633{
634 if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
636
637 GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
639 return;
640
641 if (MovementType == ESCORT_MOTION_TYPE || (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT))
643}
@ 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:587

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)
588{
589 // override the id, path can be resumed any time and counter will reset
590 // mCurrentWPID holds proper id
591
592 // xinef: both point movement and escort generator can enter this function
594 {
595 mOOCReached = true;
596 return;
597 }
598
599 mWPReached = true;
601
602 if (mLastWP)
603 {
606 }
607
609 {
612
615 }
616 // Xinef: Can be unset in ProcessEvents
618 {
619 mWPReached = false;
620 if (mCurrentWPID == GetWPCount())
621 EndPath();
622 else if (GetNextWayPoint())
623 {
624 SetRun(mRun);
625 // xinef: if we have reached waypoint, and there is no working spline movement it means our splitted array has ended, make new one
626 if (me->movespline->Finalized())
627 ResumePath();
628 }
629 }
630}
@ SMART_EVENT_WAYPOINT_REACHED
Definition: SmartScriptMgr.h:158
WayPoint * GetNextWayPoint()
Definition: SmartAI.cpp:105
uint32 GetWPCount()
Definition: SmartAI.h:229
void ResumePath()
Definition: SmartAI.cpp:367
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:328
void SetPosition(float x, float y, float z, float o)
Definition: Creature.cpp:3055
float GetOrientation() const
Definition: Position.h:120
Movement::MoveSpline * movespline
Definition: Unit.h:2440
void StopMovingOnCurrentPos()
Definition: Unit.cpp:16863
void MoveIdle()
Definition: MotionMaster.cpp:231
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::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), 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.

937{
938 bool const charmed = me->IsCharmed();
939 if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
940 {
942 EndPath(true);
943 }
944
945 mIsCharmed = charmed;
946
947 if (!charmed && !me->IsInEvadeMode())
948 {
949 if (mCanRepeatPath)
950 StartPath(mRun, GetScript()->GetPathId(), true);
951 else
952 me->SetWalk(!mRun);
953
954 if (Unit* charmer = me->GetCharmer())
955 AttackStart(charmer);
956 }
957
958 GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed);
959}
@ SMART_EVENT_CHARMED
Definition: SmartScriptMgr.h:147
bool SetWalk(bool enable) override
Definition: Creature.cpp:3081
bool IsCharmed() const
Definition: Unit.h:1871
Unit * GetCharmer() const
Definition: Unit.cpp:10568

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.

1141{
1142 // Xinef: i dont think this is necessery (can be made as event parameter)
1143 //if (!result)
1144 // return;
1145
1147}
@ 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.

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

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

References PERMIT_BASE_NO.

◆ ReceiveEmote()

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

Reimplemented from CreatureAI.

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

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

Referenced by MovepointReached(), and UpdatePath().

◆ ReturnToLastOOCPos()

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

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)
1042{
1043 // Xinef: Fix Combat Movement
1044 if (GetScript()->GetMaxCombatDist()/* || GetScript()->GetCasterMaxDist()*/) // Xinef: we only need this hack for old caster movement system
1045 return;
1046
1047 if (mCanCombatMove == on)
1048 return;
1049
1050 mCanCombatMove = on;
1051
1052 if (!IsAIControlled())
1053 return;
1054
1056 {
1057 if (on && me->GetVictim())
1058 {
1060 {
1061 SetRun(mRun);
1063 me->CastStop();
1064 }
1065 }
1066 else
1067 {
1068 me->StopMoving();
1070 me->GetMotionMaster()->Clear(false);
1072 }
1073 }
1074}
@ 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.

972{
973 GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, nullptr, id, value);
974}
@ 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)
1004{
1005 mEvadeDisabled = disable;
1006}

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
992{
993 // xinef: set proper flag!
994 //me->SetDisableGravity(fly);
995 me->SetCanFly(fly);
996}
bool SetCanFly(bool enable, bool packetOnly=false) override
Definition: Creature.cpp:3177

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

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)
1033{
1034 if (!me->GetVictim())
1035 return;
1036
1037 SetRun(mRun);
1038 me->GetMotionMaster()->MoveChase(me->GetVictim(), dist);
1039}

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.

977{
978}

◆ 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 
)
1129{
1130 if (invoker)
1131 GetScript()->mLastInvoker = invoker->GetGUID();
1132 GetScript()->SetScript9(e, entry);
1133}
ObjectGuid mLastInvoker
Definition: SmartScript.h:215
void SetScript9(SmartScriptHolder &e, uint32 entry)
Definition: SmartScript.cpp:4511

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

◆ SetSwim()

void SmartAI::SetSwim ( bool  swim = true)
999{
1000 me->SetSwim(swim);
1001}
bool SetSwim(bool enable) override
Definition: Creature.cpp:3129

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.

1009{
1011}
@ 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.

1014{
1015 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1016}
@ 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.

1019{
1020}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

1136{
1138}
@ 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.

863{
864 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
865}
@ 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.

868{
869 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
870}
@ 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.

1023{
1024 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1025}
@ 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.

1028{
1029 GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt);
1030}
@ 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 
)
187{
189 StopPath();
190
191 if (path)
192 {
193 if (!LoadPath(path))
194 return;
195 }
196
197 if (!mWayPoints || mWayPoints->empty())
198 return;
199
200 if (WayPoint* wp = GetNextWayPoint())
201 {
203 mCanRepeatPath = repeat;
204 SetRun(run);
205
206 if (invoker && invoker->GetTypeId() == TYPEID_PLAYER)
207 {
210 }
211
212 Movement::PointsArray pathPoints;
213 GenerateWayPointArray(&pathPoints);
214
215 me->GetMotionMaster()->MoveSplinePath(&pathPoints);
216 GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
217 }
218}
@ 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:268
bool LoadPath(uint32 entry)
Definition: SmartAI.cpp:220
TypeID GetTypeId() const
Definition: Object.h:121
NPCFlags GetNpcFlags() const
Definition: Unit.h:1645

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)
1097{
1099 mFollowDist = 0;
1100 mFollowAngle = 0;
1101 mFollowCredit = 0;
1102 mFollowArrivedTimer = 1000;
1105
1106 me->GetMotionMaster()->Clear(false);
1107 me->StopMoving();
1109
1110 if (!complete)
1111 return;
1112
1114 if (player)
1115 {
1116 if (!mFollowCreditType)
1118 else
1120 }
1121
1122 SetDespawnTime(5000);
1123 StartDespawn();
1124
1126}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition: SmartScriptMgr.h:183
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:225
void SetDespawnTime(uint32 t)
Definition: SmartAI.h:194
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition: Player.cpp:12627

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.

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

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.

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

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

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

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

Referenced by UpdateAI().

◆ UpdatePath()

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

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