AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SmartAI Class Reference

#include "SmartAI.h"

Inheritance diagram for SmartAI:
CreatureAI UnitAI npc_black_morass_summoned_add npc_pos_freed_slave::npc_pos_freed_slaveAI npc_stable_master::npc_stable_masterAI

Public Member Functions

 ~SmartAI () override
 
 SmartAI (Creature *c)
 
bool IsAIControlled () const
 
void StartPath (bool run=false, uint32 path=0, bool repeat=false, Unit *invoker=nullptr)
 
bool LoadPath (uint32 entry)
 
void PausePath (uint32 delay, bool forced=false)
 
void StopPath (uint32 DespawnTime=0, uint32 quest=0, bool fail=false)
 
void EndPath (bool fail=false)
 
void ResumePath ()
 
WayPointGetNextWayPoint ()
 
void GenerateWayPointArray (Movement::PointsArray *points)
 
bool HasEscortState (uint32 uiEscortState)
 
void AddEscortState (uint32 uiEscortState)
 
bool IsEscorted () override
 
void RemoveEscortState (uint32 uiEscortState)
 
void SetAutoAttack (bool on)
 
void SetCombatMove (bool on, float chaseRange=0.0f)
 
bool CanCombatMove ()
 
void SetFollow (Unit *target, float dist=0.0f, float angle=0.0f, uint32 credit=0, uint32 end=0, uint32 creditType=0, bool aliveState=true)
 
void StopFollow (bool complete)
 
void MoveAway (float distance)
 
void SetScript9 (SmartScriptHolder &e, uint32 entry, WorldObject *invoker)
 
SmartScriptGetScript ()
 
bool IsEscortInvokerInRange ()
 
void JustRespawned () override
 
void JustReachedHome () override
 
void JustEngagedWith (Unit *enemy) override
 Called for reaction when initially engaged.
 
void EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER) override
 
void JustDied (Unit *killer) override
 
void KilledUnit (Unit *victim) override
 
void JustSummoned (Creature *creature) override
 
void SummonedCreatureDies (Creature *summon, Unit *killer) override
 
void SummonedCreatureEvade (Creature *summon) override
 
void AttackStart (Unit *who) override
 
void MoveInLineOfSight (Unit *who) override
 
void SpellHit (Unit *unit, SpellInfo const *spellInfo) override
 
void SpellHitTarget (Unit *target, SpellInfo const *spellInfo) override
 
void DamageTaken (Unit *done_by, uint32 &damage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask) override
 Called at any Damage from any attacker (before damage apply)
 
void HealReceived (Unit *doneBy, uint32 &addhealth) override
 Called when the creature receives heal.
 
void UpdateAI (uint32 diff) override
 Use to start attacking a target. Called just before JustEngagedWith()
 
void ReceiveEmote (Player *player, uint32 textEmote) override
 
void MovementInform (uint32 MovementType, uint32 Data) override
 
void IsSummonedBy (WorldObject *summoner) override
 
void DamageDealt (Unit *doneTo, uint32 &damage, DamageEffectType damagetyp, SpellSchoolMask damageSchoolMask) override
 Called at any Damage to any victim (before damage apply)
 
void SummonedCreatureDespawn (Creature *unit) override
 
void CorpseRemoved (uint32 &respawnDelay) override
 == Triggered Actions Requested ==================
 
void PassengerBoarded (Unit *who, int8 seatId, bool apply) override
 == Fields =======================================
 
void InitializeAI () override
 
void OnCharmed (bool apply) override
 Called when unit is charmed.
 
bool CanAIAttack (Unit const *who) const override
 
void DoAction (int32 param=0) override
 
uint32 GetData (uint32 id=0) const override
 
void SetData (uint32 id, uint32 value) override
 
void SetData (uint32 id, uint32 value, WorldObject *invoker)
 
void SetGUID (ObjectGuid guid, int32 id=0) override
 
ObjectGuid GetGUID (int32 id=0) const override
 
void MovepointReached (uint32 id)
 
void SetRun (bool run=true)
 
void SetFly (bool fly=true)
 
void SetSwim (bool swim=true)
 
void SetEvadeDisabled (bool disable=true)
 
void SetInvincibilityHpLevel (uint32 level)
 
void sGossipHello (Player *player) override
 
void sGossipSelect (Player *player, uint32 sender, uint32 action) override
 
void sGossipSelectCode (Player *player, uint32 sender, uint32 action, const char *code) override
 
void sQuestAccept (Player *player, Quest const *quest) override
 
void sQuestReward (Player *player, Quest const *quest, uint32 opt) override
 
void sOnGameEvent (bool start, uint16 eventId) override
 
void SetDespawnTime (uint32 t)
 
void StartDespawn ()
 
void OnSpellClick (Unit *clicker, bool &result) override
 
void PathEndReached (uint32 pathId) override
 
bool CanRespawn () override
 
void SetCanRespawn (bool canSpawn)
 
void SetWPPauseTimer (uint32 time)
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr, Milliseconds delay=0s)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table.
 
void Talk (uint8 id, Milliseconds delay)
 
WorldObjectGetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon.
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual void SummonedCreatureDespawnAll ()
 
virtual void AttackedBy (Unit *)
 
void DoZoneInCombat (Creature *creature=nullptr, float maxRangeToNearestTarget=250.0f)
 
virtual void OwnerAttackedBy (Unit *)
 
virtual void OwnerAttacked (Unit *)
 
virtual bool BeforeSpellClick (Unit *)
 
virtual bool CanSeeAlways (WorldObject const *)
 
virtual bool CanBeSeen (Player const *)
 
virtual bool CanAlwaysBeDetectable (WorldObject const *)
 
virtual void PetStopAttack ()
 
virtual bool CheckInRoom ()
 
CreatureBoundary const * GetBoundary () const
 
void SetBoundary (CreatureBoundary const *boundary, bool negativeBoundaries=false)
 
bool IsInBoundary (Position const *who=nullptr) const
 
virtual void CalculateThreat (Unit *, float &, SpellInfo const *)
 
virtual bool OnTeleportUnreacheablePlayer (Player *)
 
virtual void OnAuraRemove (AuraApplication *, AuraRemoveMode)
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual void Reset ()
 
UnitSelectTarget (SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following:
 
template<class PREDICATE >
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
virtual void JustEnteredCombat (Unit *)
 Called when the unit enters combat.
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat.
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 Called when the creature power updates.
 
virtual void HealDone (Unit *, uint32 &)
 Called when the unit heals.
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 Called during damage calculations.
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 Called during calculation when receiving periodic healing or damage (DoT or HoT)
 
void AttackStartCaster (Unit *victim, float dist)
 
SpellCastResult DoAddAuraToAllHostilePlayers (uint32 spellid)
 
SpellCastResult DoCast (uint32 spellId)
 
SpellCastResult DoCast (Unit *victim, uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastSelf (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastToAllHostilePlayers (uint32 spellid, bool triggered=false)
 To specify the caster as target if the spell is self-cast.
 
SpellCastResult DoCastVictim (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastAOE (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastRandomTarget (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false, bool withTank=true)
 Cast the spell on a random unit from the threat list.
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the top threat target, which may not be the current victim.
 
float DoGetSpellMaxRange (uint32 spellId, bool positive=false)
 
void DoMeleeAttackIfReady ()
 
bool DoSpellAttackIfReady (uint32 spell)
 
void DoSpellAttackToRandomTargetIfReady (uint32 spell, uint32 threatTablePosition=0, float dist=0.f, bool playerOnly=true)
 
virtual void SummonMovementInform (Creature *, uint32, uint32)
 Called when a summon reaches a waypoint or point movement finished.
 
virtual void sQuestSelect (Player *, Quest const *)
 
virtual void sQuestComplete (Player *, Quest const *)
 
virtual std::string GetDebugInfo () const
 

Static Public Member Functions

static int32 Permissible (Creature const *)
 
- Static Public Member Functions inherited from CreatureAI
static bool IsInBounds (CreatureBoundary const &boundary, Position const *who)
 
- Static Public Member Functions inherited from UnitAI
static void FillAISpellInfo ()
 

Public Attributes

uint32 mEscortQuestID
 

Private Member Functions

void ReturnToLastOOCPos ()
 
void UpdatePath (const uint32 diff)
 
uint32 GetWPCount ()
 
bool AssistPlayerInCombatAgainst (Unit *who)
 
void UpdateDespawn (const uint32 diff)
 
void CheckConditions (const uint32 diff)
 

Private Attributes

bool mIsCharmed
 
uint32 mFollowCreditType
 
uint32 mFollowArrivedTimer
 
uint32 mFollowCredit
 
uint32 mFollowArrivedEntry
 
bool mFollowArrivedAlive
 
ObjectGuid mFollowGuid
 
float mFollowDist
 
float mFollowAngle
 
SmartScript mScript
 
WPPathmWayPoints
 
uint32 mEscortState
 
uint32 mCurrentWPID
 
bool mWPReached
 
bool mOOCReached
 
uint32 mWPPauseTimer
 
WayPointmLastWP
 
uint32 mEscortNPCFlags
 
bool mCanRepeatPath
 
bool mRun
 
bool mEvadeDisabled
 
bool mCanAutoAttack
 
bool mCanCombatMove
 
bool mForcedPaused
 
uint32 mInvincibilityHpLevel
 
uint32 mDespawnTime
 
uint32 mDespawnState
 
uint32 mEscortInvokerCheckTimer
 
bool mJustReset
 
bool mcanSpawn
 
ConditionList conditions
 
uint32 m_ConditionsTimer
 

Additional Inherited Members

- Public Types inherited from CreatureAI
enum  EvadeReason {
  EVADE_REASON_NO_HOSTILES ,
  EVADE_REASON_BOUNDARY ,
  EVADE_REASON_SEQUENCE_BREAK ,
  EVADE_REASON_NO_PATH ,
  EVADE_REASON_OTHER
}
 
- Static Public Attributes inherited from UnitAI
static AISpellInfoTypeAISpellInfo
 
- Protected Member Functions inherited from CreatureAI
bool UpdateVictim ()
 
bool UpdateVictimWithGaze ()
 
void SetGazeOn (Unit *target)
 
CreatureDoSummon (uint32 entry, Position const &pos, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummon (uint32 entry, WorldObject *obj, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummonFlyer (uint32 entry, WorldObject *obj, float flightZ, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
bool _EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
EventMap events
 
TaskScheduler scheduler
 
CreatureBoundary const * _boundary
 
bool _negateBoundary
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Detailed Description

Constructor & Destructor Documentation

◆ ~SmartAI()

SmartAI::~SmartAI ( )
inlineoverride
46{};

◆ SmartAI()

SmartAI::SmartAI ( Creature c)
explicit
30 : CreatureAI(c)
31{
32 mIsCharmed = false;
33 // copy script to local (protection for table reload)
34
35 mWayPoints = nullptr;
37 mCurrentWPID = 0;//first wp id is 1 !!
38 mWPReached = false;
39 mOOCReached = false;
40 mWPPauseTimer = 0;
41 mLastWP = nullptr;
43
44 mCanRepeatPath = false;
45
46 // spawn in run mode
47 // Xinef: spawn in run mode and set mRun to run... this overrides SetWalk EVERYWHERE
48 mRun = true;
49 mEvadeDisabled = false;
50
51 mCanAutoAttack = true;
52 mCanCombatMove = true;
53
54 mForcedPaused = false;
55
57
58 mDespawnTime = 0;
59 mDespawnState = 0;
60
62 mFollowDist = 0;
63 mFollowAngle = 0;
64 mFollowCredit = 0;
70
71 mJustReset = false;
72
73 mcanSpawn = true;
74
75 // Xinef: Vehicle conditions
77 if (me->GetVehicleKit())
79}
#define sConditionMgr
Definition ConditionMgr.h:290
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
Definition ConditionMgr.h:139
@ SMART_ESCORT_NONE
Definition SmartAI.h:31
Definition CreatureAI.h:70
Creature *const me
Definition CreatureAI.h:72
uint32 GetEntry() const
Definition Object.h:115
uint32 mDespawnTime
Definition SmartAI.h:248
uint32 mEscortState
Definition SmartAI.h:230
WayPoint * mLastWP
Definition SmartAI.h:235
WPPath * mWayPoints
Definition SmartAI.h:229
uint32 mEscortInvokerCheckTimer
Definition SmartAI.h:251
uint32 mDespawnState
Definition SmartAI.h:249
bool mOOCReached
Definition SmartAI.h:233
uint32 mWPPauseTimer
Definition SmartAI.h:234
uint32 mCurrentWPID
Definition SmartAI.h:231
uint32 m_ConditionsTimer
Definition SmartAI.h:259
bool mIsCharmed
Definition SmartAI.h:216
bool mWPReached
Definition SmartAI.h:232
uint32 mFollowArrivedTimer
Definition SmartAI.h:218
float mFollowAngle
Definition SmartAI.h:224
uint32 mEscortQuestID
Definition SmartAI.h:196
bool mRun
Definition SmartAI.h:239
uint32 mEscortNPCFlags
Definition SmartAI.h:236
ConditionList conditions
Definition SmartAI.h:258
uint32 mFollowCreditType
Definition SmartAI.h:217
bool mFollowArrivedAlive
Definition SmartAI.h:221
bool mcanSpawn
Definition SmartAI.h:254
uint32 mInvincibilityHpLevel
Definition SmartAI.h:244
bool mCanAutoAttack
Definition SmartAI.h:241
bool mJustReset
Definition SmartAI.h:252
bool mCanRepeatPath
Definition SmartAI.h:238
bool mEvadeDisabled
Definition SmartAI.h:240
bool mCanCombatMove
Definition SmartAI.h:242
bool mForcedPaused
Definition SmartAI.h:243
uint32 mFollowCredit
Definition SmartAI.h:219
uint32 mFollowArrivedEntry
Definition SmartAI.h:220
float mFollowDist
Definition SmartAI.h:223
Vehicle * GetVehicleKit() const
Definition Unit.h:1838

References CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE, conditions, Object::GetEntry(), Unit::GetVehicleKit(), m_ConditionsTimer, mCanAutoAttack, mCanCombatMove, mCanRepeatPath, mcanSpawn, mCurrentWPID, mDespawnState, mDespawnTime, CreatureAI::me, mEscortInvokerCheckTimer, mEscortNPCFlags, mEscortQuestID, mEscortState, mEvadeDisabled, mFollowAngle, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mForcedPaused, mInvincibilityHpLevel, mIsCharmed, mJustReset, mLastWP, mOOCReached, mRun, mWayPoints, mWPPauseTimer, mWPReached, sConditionMgr, and SMART_ESCORT_NONE.

Member Function Documentation

◆ AddEscortState()

void SmartAI::AddEscortState ( uint32  uiEscortState)
inline
62{ mEscortState |= uiEscortState; }

References mEscortState.

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

◆ AssistPlayerInCombatAgainst()

bool SmartAI::AssistPlayerInCombatAgainst ( Unit who)
private
729{
730 if (!IsAIControlled())
731 return false;
732
733 // Xinef: if unit has no victim, or victim is player controlled thing
734 if (!who->GetVictim() || who->GetCharmerOrOwnerOrOwnGUID().IsPlayer())
735 return false;
736
737 //experimental (unknown) flag not present
739 return false;
740
741 // Xinef: victim of unit has to be a player controlled unit
743 return false;
744
745 // Xinef: Check if victim can be assisted
746 if (!me->IsValidAssistTarget(who->GetVictim()))
747 return false;
748
749 //too far away and no free sight?
751 {
752 AttackStart(who);
753 return true;
754 }
755
756 return false;
757}
@ CREATURE_TYPE_FLAG_CAN_ASSIST
Definition SharedDefines.h:2707
@ SMART_MAX_AID_DIST
Definition SmartAI.h:40
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:209
bool IsPlayer() const
Definition ObjectGuid.h:168
void AttackStart(Unit *who) override
Definition SmartAI.cpp:831
bool IsAIControlled() const
Definition SmartAI.cpp:81
ObjectGuid GetCharmerOrOwnerOrOwnGUID() const
Definition Unit.h:1230
Unit * GetVictim() const
Definition Unit.h:862
bool IsValidAssistTarget(Unit const *target) const
Definition Unit.cpp:14046
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:1358
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool useBoundingRadius=true) const
Definition Object.cpp:1332
uint32 type_flags
Definition CreatureData.h:223

References AttackStart(), CREATURE_TYPE_FLAG_CAN_ASSIST, Unit::GetCharmerOrOwnerOrOwnGUID(), Creature::GetCreatureTemplate(), Unit::GetVictim(), IsAIControlled(), ObjectGuid::IsPlayer(), Unit::IsValidAssistTarget(), WorldObject::IsWithinDistInMap(), WorldObject::IsWithinLOSInMap(), CreatureAI::me, SMART_MAX_AID_DIST, and CreatureTemplate::type_flags.

Referenced by MoveInLineOfSight().

◆ AttackStart()

void SmartAI::AttackStart ( Unit who)
overridevirtual

Reimplemented from UnitAI.

832{
833 // xinef: dont allow charmed npcs to act on their own
835 {
836 if (who)
837 me->Attack(who, mCanAutoAttack);
838 return;
839 }
840
841 if (who && me->Attack(who, me->IsWithinMeleeRange(who)))
842 {
843 if (mCanCombatMove)
844 {
845 SetRun(mRun);
847 if (type == ESCORT_MOTION_TYPE || type == POINT_MOTION_TYPE)
848 {
850 me->StopMoving();
851 me->GetMotionMaster()->Clear(false);
852 }
853
855 }
856 }
857}
@ MOTION_SLOT_ACTIVE
Definition MotionMaster.h:64
MovementGeneratorType
Definition MotionMaster.h:38
@ ESCORT_MOTION_TYPE
Definition MotionMaster.h:57
@ POINT_MOTION_TYPE
Definition MotionMaster.h:48
@ UNIT_FLAG_POSSESSED
Definition UnitDefines.h:274
MovementGeneratorType GetMotionSlotType(int slot) const
Definition MotionMaster.cpp:921
void MoveChase(Unit *target, std::optional< ChaseRange > dist={}, std::optional< ChaseAngle > angle={})
Force the unit to chase this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:313
void MovementExpired(bool reset=true)
Definition MotionMaster.h:180
void Clear(bool reset=true)
Definition MotionMaster.h:167
void SetRun(bool run=true)
Definition SmartAI.cpp:992
MotionMaster * GetMotionMaster()
Definition Unit.h:1673
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:718
void StopMoving()
Definition Unit.cpp:16702
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:664
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:10313

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

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

◆ CanAIAttack()

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

Reimplemented from UnitAI.

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

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

◆ CanCombatMove()

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

References mCanCombatMove.

◆ CanRespawn()

bool SmartAI::CanRespawn ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

209{ return mcanSpawn; };

References mcanSpawn.

◆ CheckConditions()

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

References conditions, ObjectAccessor::GetUnit(), Unit::GetVehicleKit(), m_ConditionsTimer, CreatureAI::me, sConditionMgr, Vehicle::Seats, and Object::ToPlayer().

Referenced by UpdateAI().

◆ CorpseRemoved()

void SmartAI::CorpseRemoved ( uint32 )
overridevirtual

== Triggered Actions Requested ==================

== State checks =================================

Reimplemented from CreatureAI.

909{
910 GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
911
912 // xinef: end escort upon corpse remove, safe check in case of immediate despawn
913 if (IsEscorted())
914 EndPath(true);
915}
@ SMART_EVENT_CORPSE_REMOVED
Definition SmartScriptMgr.h:154
void EndPath(bool fail=false)
Definition SmartAI.cpp:288
bool IsEscorted() override
Definition SmartAI.h:63
SmartScript * GetScript()
Definition SmartAI.h:73
void ProcessEventsFor(SMART_EVENT e, Unit *unit=nullptr, uint32 var0=0, uint32 var1=0, bool bvar=false, SpellInfo const *spell=nullptr, GameObject *gob=nullptr)
Definition SmartScript.cpp:135

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

◆ DamageDealt()

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

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

Reimplemented from UnitAI.

898{
900}
@ SMART_EVENT_DAMAGED_TARGET
Definition SmartScriptMgr.h:151

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

◆ DamageTaken()

void SmartAI::DamageTaken ( Unit ,
uint32 ,
DamageEffectType  ,
SpellSchoolMask   
)
overridevirtual

Called at any Damage from any attacker (before damage apply)

Note
It use for recalculation damage or special reaction at damage for attack reaction use AttackedBy called for non DOT damage in Unit::DealDamage also

Reimplemented from UnitAI.

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

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.

959{
961}
@ SMART_EVENT_ACTION_DONE
Definition SmartScriptMgr.h:190

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

◆ EndPath()

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

References Player::AreaExploredOrEventHappens(), Player::FailQuest(), Player::GetGroup(), Player::GetQuestStatus(), GetScript(), SmartScript::GetStoredTargetVector(), Player::GroupEventHappens(), Player::HasCorpse(), IsAIControlled(), Player::IsAtGroupRewardDistance(), WorldObject::IsInMap(), SmartScript::IsPlayer(), mCanRepeatPath, mCurrentWPID, mDespawnState, CreatureAI::me, mEscortNPCFlags, mEscortQuestID, mLastWP, mRun, mWayPoints, mWPPauseTimer, SmartScript::ProcessEventsFor(), QUEST_STATUS_INCOMPLETE, RemoveEscortState(), Unit::ReplaceAllNpcFlags(), SmartScript::SetPathId(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_ESCORT_RETURNING, SMART_ESCORT_TARGETS, SMART_EVENT_WAYPOINT_ENDED, StartDespawn(), StartPath(), and Object::ToPlayer().

Referenced by CorpseRemoved(), JustDied(), MovepointReached(), OnCharmed(), StopPath(), and UpdatePath().

◆ EnterEvadeMode()

void SmartAI::EnterEvadeMode ( EvadeReason  why = EVADE_REASON_OTHER)
overridevirtual

Reimplemented from CreatureAI.

651{
652 if (mEvadeDisabled)
653 {
655 return;
656 }
657
659 {
660 me->AttackStop();
661 return;
662 }
663
664 if (!_EnterEvadeMode())
665 return;
666
668
669 GetScript()->ProcessEventsFor(SMART_EVENT_EVADE); //must be after aura clear so we can cast spells from db
670
671 SetRun(mRun);
673 {
676 }
677 else if (mFollowGuid)
678 {
682
683 // xinef: do not forget to reset scripts as we wont call reached home
684 GetScript()->OnReset();
685 }
686 else
687 {
689
690 // xinef: do not forget to reset scripts as we wont call reached home
692 GetScript()->OnReset();
693 }
694}
@ SMART_EVENT_EVADE
Definition SmartScriptMgr.h:125
@ UNIT_STATE_EVADE
Definition UnitDefines.h:191
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
Definition CreatureAI.cpp:303
void MoveTargetedHome(bool walk=false)
The unit will return this initial position (owner for pets and summoned creatures)....
Definition MotionMaster.cpp:259
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE, bool inheritWalkState=true, bool inheritSpeed=true)
The unit will follow this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:409
bool HasEscortState(uint32 uiEscortState)
Definition SmartAI.h:61
void ReturnToLastOOCPos()
Definition SmartAI.cpp:381
void AddEscortState(uint32 uiEscortState)
Definition SmartAI.h:62
ObjectGuid mFollowGuid
Definition SmartAI.h:222
void OnReset()
Definition SmartScript.cpp:109
void ClearUnitState(uint32 f)
Definition Unit.h:708
void AddUnitState(uint32 f)
Definition Unit.h:706
bool HasUnitState(const uint32 f) const
Definition Unit.h:707
ObjectGuid GetCharmerGUID() const
Definition Unit.h:690
bool AttackStop()
Force the unit to stop attacking. This will clear UNIT_STATE_MELEE_ATTACKING, Interrupt current spell...
Definition Unit.cpp:10448

References CreatureAI::_EnterEvadeMode(), AddEscortState(), Unit::AddUnitState(), Unit::AttackStop(), Unit::ClearUnitState(), Unit::GetCharmerGUID(), Unit::GetMotionMaster(), GetScript(), ObjectAccessor::GetUnit(), HasEscortState(), Unit::HasUnitFlag(), Unit::HasUnitState(), ObjectGuid::IsPlayer(), CreatureAI::me, mEvadeDisabled, mFollowAngle, mFollowDist, mFollowGuid, MotionMaster::MoveFollow(), MotionMaster::MoveTargetedHome(), mRun, SmartScript::OnReset(), SmartScript::ProcessEventsFor(), ReturnToLastOOCPos(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_RETURNING, SMART_EVENT_EVADE, UNIT_FLAG_POSSESSED, and UNIT_STATE_EVADE.

Referenced by npc_black_morass_summoned_add::EnterEvadeMode().

◆ GenerateWayPointArray()

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

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

Referenced by ResumePath(), and StartPath().

◆ GetData()

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

Reimplemented from UnitAI.

964{
965 return 0;
966}

◆ GetGUID()

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

Reimplemented from UnitAI.

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

References ObjectGuid::Empty.

◆ GetNextWayPoint()

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

References mWayPoints.

Referenced by MovepointReached(), and UpdatePath().

◆ HasEscortState()

bool SmartAI::HasEscortState ( uint32  uiEscortState)
inline

◆ HealReceived()

void SmartAI::HealReceived ( Unit ,
uint32  
)
overridevirtual

Called when the creature receives heal.

Reimplemented from UnitAI.

883{
885}
@ 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.

923{
925 if (!me->isDead())
926 {
927 mJustReset = true;
930 }
931}
@ SMART_EVENT_RESPAWN
Definition SmartScriptMgr.h:129
void JustReachedHome() override
Definition SmartAI.cpp:780
void OnInitialize(WorldObject *obj, AreaTrigger const *at=nullptr)
Definition SmartScript.cpp:5141
bool isDead() const
Definition Unit.h:1709

References GetScript(), Unit::isDead(), JustReachedHome(), CreatureAI::me, mJustReset, SmartScript::OnInitialize(), SmartScript::ProcessEventsFor(), and SMART_EVENT_RESPAWN.

◆ IsAIControlled()

bool SmartAI::IsAIControlled ( ) const

◆ IsEscorted()

bool SmartAI::IsEscorted ( )
inlineoverridevirtual

Reimplemented from CreatureAI.

References mEscortState, and SMART_ESCORT_ESCORTING.

Referenced by CorpseRemoved().

◆ IsEscortInvokerInRange()

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

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.

893{
894 GetScript()->ProcessEventsFor(SMART_EVENT_JUST_SUMMONED, summoner->ToUnit(), 0, 0, false, nullptr, summoner->ToGameObject());
895}
@ SMART_EVENT_JUST_SUMMONED
Definition SmartScriptMgr.h:172
GameObject * ToGameObject()
Definition Object.h:213
Unit * ToUnit()
Definition Object.h:209

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

◆ JustDied()

void SmartAI::JustDied ( Unit killer)
overridevirtual

Reimplemented from CreatureAI.

804{
807 EndPath(true);
808}
@ SMART_EVENT_DEATH
Definition SmartScriptMgr.h: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.

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

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

◆ JustReachedHome()

void SmartAI::JustReachedHome ( )
overridevirtual

Reimplemented from CreatureAI.

781{
782 GetScript()->OnReset();
783
784 if (!mJustReset)
785 {
787
790 }
791
792 mJustReset = false;
793}
@ IDLE_MOTION_TYPE
Definition MotionMaster.h:39
@ SMART_EVENT_REACHED_HOME
Definition SmartScriptMgr.h:139
bool UpdateVictim()
Definition CreatureAI.cpp:280
uint32 GetWaypointPath() const
Definition Creature.h:350
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:913
void MovePath(uint32 path_id, bool repeatable)
Move the unit following a specific path. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:852

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

Referenced by InitializeAI(), and JustRespawned().

◆ JustRespawned()

void SmartAI::JustRespawned ( )
overridevirtual

Reimplemented from CreatureAI.

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

References ObjectGuid::Clear(), CreatureTemplate::faction, Creature::GetCreatureTemplate(), Unit::GetFaction(), GetScript(), JustReachedHome(), mDespawnState, mDespawnTime, CreatureAI::me, mEscortState, mFollowAngle, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mFollowGuid, mJustReset, SmartScript::ProcessEventsFor(), Unit::RestoreFaction(), Unit::SetVisible(), SMART_ESCORT_NONE, and SMART_EVENT_RESPAWN.

◆ JustSummoned()

void SmartAI::JustSummoned ( Creature creature)
overridevirtual

Reimplemented from CreatureAI.

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

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

◆ KilledUnit()

void SmartAI::KilledUnit ( Unit victim)
overridevirtual

Reimplemented from CreatureAI.

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

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

◆ LoadPath()

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

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

Referenced by StartPath().

◆ MoveAway()

void SmartAI::MoveAway ( float  distance)
1123{
1125 return;
1126
1127 mCanCombatMove = false;
1128
1129 if (!IsAIControlled())
1130 return;
1131
1133 {
1134 if (me->GetVictim())
1135 {
1136 me->StopMoving();
1138 me->GetMotionMaster()->Clear(false);
1139
1140 float x, y, z;
1141 me->GetClosePoint(x, y, z, me->GetObjectSize(), distance, M_PI);
1142 if (me->GetVictim()->IsWithinLOS(x, y, z))
1144 }
1145 }
1146}
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45
@ SMART_RANDOM_POINT
Definition SmartScriptMgr.h:58
void MovePoint(uint32 id, const Position &pos, bool generatePath=true, bool forceDestination=true)
Definition MotionMaster.h:213
bool GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0, WorldObject const *forWho=nullptr, bool force=false) const
Definition Object.cpp:2712
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition Object.cpp:1337
float GetObjectSize() const
Definition Object.cpp:2784

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

◆ MoveInLineOfSight()

void SmartAI::MoveInLineOfSight ( Unit who)
overridevirtual

Reimplemented from CreatureAI.

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

References AssistPlayerInCombatAgainst(), AttackStart(), Creature::CanStartAttack(), MotionMaster::Clear(), Unit::ClearUnitState(), Unit::GetMotionMaster(), GetScript(), Unit::GetVictim(), Creature::HasReactState(), Unit::HasUnitState(), IsAIControlled(), CreatureAI::me, SmartScript::OnMoveInLineOfSight(), REACT_AGGRESSIVE, REACT_PASSIVE, and UNIT_STATE_DISTRACTED.

◆ MovementInform()

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

Reimplemented from CreatureAI.

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

References Unit::ClearUnitState(), ESCORT_MOTION_TYPE, GetScript(), HasEscortState(), CreatureAI::me, MovepointReached(), POINT_MOTION_TYPE, SmartScript::ProcessEventsFor(), SMART_ESCORT_ESCORTING, SMART_ESCORT_LAST_OOC_POINT, SMART_EVENT_MOVEMENTINFORM, SMART_EVENT_WAYPOINT_DATA_REACHED, UNIT_STATE_EVADE, and WAYPOINT_MOTION_TYPE.

◆ MovepointReached()

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

References EndPath(), ESCORT_MOTION_TYPE, Movement::MoveSpline::Finalized(), MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), GetNextWayPoint(), Position::GetOrientation(), Position::GetPosition(), GetScript(), GetWPCount(), HasEscortState(), mCurrentWPID, CreatureAI::me, mLastWP, mOOCReached, MOTION_SLOT_ACTIVE, MotionMaster::MoveIdle(), MotionMaster::MovementExpired(), Unit::movespline, mRun, mWPReached, SmartScript::ProcessEventsFor(), ResumePath(), Creature::SetHomePosition(), Creature::SetPosition(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_LAST_OOC_POINT, SMART_ESCORT_PAUSED, SMART_EVENT_WAYPOINT_REACHED, Unit::StopMovingOnCurrentPos(), WayPoint::x, WayPoint::y, and WayPoint::z.

Referenced by MovementInform().

◆ OnCharmed()

void SmartAI::OnCharmed ( bool  apply)
overridevirtual

Called when unit is charmed.

Reimplemented from CreatureAI.

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

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.

1161{
1162 // Xinef: i dont think this is necessery (can be made as event parameter)
1163 //if (!result)
1164 // return;
1165
1167}
@ 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.

918{
920}
@ SMART_EVENT_PASSENGER_REMOVED
Definition SmartScriptMgr.h:146
@ SMART_EVENT_PASSENGER_BOARDED
Definition SmartScriptMgr.h:145
void apply(T *val)
Definition ByteConverter.h:40

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

◆ PathEndReached()

void SmartAI::PathEndReached ( uint32  pathId)
overridevirtual

Reimplemented from CreatureAI.

1170{
1172 me->LoadPath(0);
1173}
@ SMART_EVENT_WAYPOINT_DATA_ENDED
Definition SmartScriptMgr.h:217
void LoadPath(uint32 pathid)
Definition Creature.h:351

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

◆ PausePath()

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

References AddEscortState(), ESCORT_MOTION_TYPE, Object::GetEntry(), Unit::GetMotionMaster(), MotionMaster::GetMotionSlotType(), GetScript(), HasEscortState(), LOG_ERROR, mCurrentWPID, CreatureAI::me, mForcedPaused, MOTION_SLOT_ACTIVE, MotionMaster::MoveIdle(), MotionMaster::MovementExpired(), mRun, mWayPoints, mWPPauseTimer, mWPReached, SmartScript::ProcessEventsFor(), Unit::SetFacingTo(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_EVENT_WAYPOINT_PAUSED, and Unit::StopMoving().

◆ Permissible()

static int32 SmartAI::Permissible ( Creature const *  )
inlinestatic
171{ return PERMIT_BASE_NO; }
@ PERMIT_BASE_NO
Definition CreatureAI.h:241

References PERMIT_BASE_NO.

◆ ReceiveEmote()

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

Reimplemented from CreatureAI.

888{
890}
@ SMART_EVENT_RECEIVE_EMOTE
Definition SmartScriptMgr.h:140

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

◆ RemoveEscortState()

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

References mEscortState.

Referenced by EndPath(), and UpdatePath().

◆ ResumePath()

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

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

Referenced by MovepointReached(), and UpdatePath().

◆ ReturnToLastOOCPos()

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

References Creature::GetHomePosition(), Unit::GetMotionMaster(), IsAIControlled(), CreatureAI::me, MotionMaster::MovePoint(), Creature::SetWalk(), and SMART_ESCORT_LAST_OOC_POINT.

Referenced by EnterEvadeMode().

◆ SetAutoAttack()

void SmartAI::SetAutoAttack ( bool  on)
inline
65{ mCanAutoAttack = on; }

References mCanAutoAttack.

◆ SetCanRespawn()

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

References mcanSpawn.

◆ SetCombatMove()

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

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

◆ SetData() [1/2]

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

Reimplemented from UnitAI.

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

References SetData().

Referenced by SetData().

◆ SetData() [2/2]

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

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

◆ SetDespawnTime()

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

References mDespawnState, and mDespawnTime.

Referenced by StopFollow(), and StopPath().

◆ SetEvadeDisabled()

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

References mEvadeDisabled.

◆ SetFly()

void SmartAI::SetFly ( bool  fly = true)
999{
1000 // xinef: set proper flag!
1001 //me->SetDisableGravity(fly);
1002 me->SetCanFly(fly);
1003}
bool SetCanFly(bool enable, bool packetOnly=false) override
Add the movement flag: MOVEMENTFLAGCAN_FLY. Generaly only use by players, allowing them to fly by pre...
Definition Creature.cpp:3307

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

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

◆ SetGUID()

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

Reimplemented from UnitAI.

984{
985}

◆ SetInvincibilityHpLevel()

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

References mInvincibilityHpLevel.

Referenced by SmartScript::ProcessAction().

◆ SetRun()

void SmartAI::SetRun ( bool  run = true)

◆ SetScript9()

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

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

◆ SetSwim()

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

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

◆ SetWPPauseTimer()

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

References mWPPauseTimer.

◆ sGossipHello()

void SmartAI::sGossipHello ( Player player)
overridevirtual

Reimplemented from UnitAI.

1016{
1018}
@ 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.

1021{
1022 GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action);
1023}
@ 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.

1026{
1027}

◆ sOnGameEvent()

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

Reimplemented from UnitAI.

1156{
1158}
@ 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.

860{
861 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
862}
@ 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.

865{
866 GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
867}
@ 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.

1030{
1031 GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId());
1032}
@ 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.

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

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

◆ StartDespawn()

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

References mDespawnState.

Referenced by EndPath(), and StopFollow().

◆ StartPath()

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

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

Referenced by EndPath(), and OnCharmed().

◆ StopFollow()

void SmartAI::StopFollow ( bool  complete)
1091{
1093 mFollowDist = 0;
1094 mFollowAngle = 0;
1095 mFollowCredit = 0;
1096 mFollowArrivedTimer = 1000;
1099
1100 me->GetMotionMaster()->Clear(false);
1101 me->StopMoving();
1103
1104 if (!complete)
1105 return;
1106
1108 if (player)
1109 {
1110 if (!mFollowCreditType)
1112 else
1114 }
1115
1116 SetDespawnTime(5000);
1117 StartDespawn();
1118
1120}
@ SMART_EVENT_FOLLOW_COMPLETED
Definition SmartScriptMgr.h:183
void RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject *pRewardSource)
Definition Player.cpp:12792
void SetDespawnTime(uint32 t)
Definition SmartAI.h:198
Player * GetPlayer(Map const *, ObjectGuid const guid)
Definition ObjectAccessor.cpp:220

References ObjectGuid::Clear(), MotionMaster::Clear(), Unit::GetMotionMaster(), ObjectAccessor::GetPlayer(), GetScript(), Player::GroupEventHappens(), CreatureAI::me, mFollowAngle, mFollowArrivedEntry, mFollowArrivedTimer, mFollowCredit, mFollowCreditType, mFollowDist, mFollowGuid, MotionMaster::MoveIdle(), SmartScript::ProcessEventsFor(), Player::RewardPlayerAndGroupAtEvent(), SetDespawnTime(), SMART_EVENT_FOLLOW_COMPLETED, StartDespawn(), and Unit::StopMoving().

Referenced by SetFollow(), and UpdateAI().

◆ StopPath()

◆ SummonedCreatureDespawn()

void SmartAI::SummonedCreatureDespawn ( Creature unit)
overridevirtual

Reimplemented from CreatureAI.

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

References Object::GetGUID(), GetScript(), SmartScript::ProcessEventsFor(), SmartScript::RemoveCreatureSummon(), and SMART_EVENT_SUMMON_DESPAWNED.

◆ SummonedCreatureDies()

void SmartAI::SummonedCreatureDies ( Creature summon,
Unit killer 
)
overridevirtual

Reimplemented from CreatureAI.

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

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

◆ SummonedCreatureEvade()

void SmartAI::SummonedCreatureEvade ( Creature summon)
overridevirtual

Reimplemented from CreatureAI.

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

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

◆ UpdateAI()

void SmartAI::UpdateAI ( uint32  )
overridevirtual

Use to start attacking a target. Called just before JustEngagedWith()

Implements UnitAI.

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

References CheckConditions(), UnitAI::DoMeleeAttackIfReady(), WorldObject::FindNearestCreature(), Unit::GetCharmInfo(), GetScript(), INTERACTION_DISTANCE, IsAIControlled(), mCanAutoAttack, CreatureAI::me, mFollowArrivedAlive, mFollowArrivedEntry, mFollowArrivedTimer, mFollowGuid, SmartScript::OnUpdate(), StopFollow(), UpdateDespawn(), UpdatePath(), and CreatureAI::UpdateVictim().

◆ UpdateDespawn()

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

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

Referenced by UpdateAI().

◆ UpdatePath()

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

References Creature::DespawnOrUnsummon(), EndPath(), Movement::MoveSpline::Finalized(), GetNextWayPoint(), GetScript(), Unit::GetVictim(), GetWPCount(), HasEscortState(), Unit::HasUnitState(), IsEscortInvokerInRange(), Unit::IsInCombat(), mCurrentWPID, CreatureAI::me, mEscortInvokerCheckTimer, mEscortQuestID, mForcedPaused, mOOCReached, Unit::movespline, mRun, mWPPauseTimer, mWPReached, SmartScript::ProcessEventsFor(), RemoveEscortState(), ResumePath(), SetRun(), SMART_ESCORT_ESCORTING, SMART_ESCORT_PAUSED, SMART_ESCORT_RETURNING, SMART_EVENT_DEATH, SMART_EVENT_WAYPOINT_RESUMED, StopPath(), and UNIT_STATE_NOT_MOVE.

Referenced by UpdateAI().

Member Data Documentation

◆ conditions

ConditionList SmartAI::conditions
private

Referenced by CheckConditions(), and SmartAI().

◆ m_ConditionsTimer

uint32 SmartAI::m_ConditionsTimer
private

Referenced by CheckConditions(), and SmartAI().

◆ mCanAutoAttack

bool SmartAI::mCanAutoAttack
private

◆ mCanCombatMove

bool SmartAI::mCanCombatMove
private

◆ mCanRepeatPath

bool SmartAI::mCanRepeatPath
private

Referenced by EndPath(), OnCharmed(), SmartAI(), and StartPath().

◆ mcanSpawn

bool SmartAI::mcanSpawn
private

Referenced by CanRespawn(), SetCanRespawn(), and SmartAI().

◆ mCurrentWPID

◆ mDespawnState

uint32 SmartAI::mDespawnState
private

◆ mDespawnTime

uint32 SmartAI::mDespawnTime
private

◆ mEscortInvokerCheckTimer

uint32 SmartAI::mEscortInvokerCheckTimer
private

Referenced by SmartAI(), and UpdatePath().

◆ mEscortNPCFlags

uint32 SmartAI::mEscortNPCFlags
private

Referenced by EndPath(), SmartAI(), and StartPath().

◆ mEscortQuestID

uint32 SmartAI::mEscortQuestID

Referenced by EndPath(), SmartAI(), StopPath(), and UpdatePath().

◆ mEscortState

uint32 SmartAI::mEscortState
private

◆ mEvadeDisabled

bool SmartAI::mEvadeDisabled
private

◆ mFollowAngle

float SmartAI::mFollowAngle
private

◆ mFollowArrivedAlive

bool SmartAI::mFollowArrivedAlive
private

◆ mFollowArrivedEntry

uint32 SmartAI::mFollowArrivedEntry
private

◆ mFollowArrivedTimer

uint32 SmartAI::mFollowArrivedTimer
private

◆ mFollowCredit

uint32 SmartAI::mFollowCredit
private

◆ mFollowCreditType

uint32 SmartAI::mFollowCreditType
private

◆ mFollowDist

float SmartAI::mFollowDist
private

◆ mFollowGuid

ObjectGuid SmartAI::mFollowGuid
private

◆ mForcedPaused

bool SmartAI::mForcedPaused
private

Referenced by PausePath(), SmartAI(), and UpdatePath().

◆ mInvincibilityHpLevel

uint32 SmartAI::mInvincibilityHpLevel
private

◆ mIsCharmed

bool SmartAI::mIsCharmed
private

Referenced by IsAIControlled(), OnCharmed(), and SmartAI().

◆ mJustReset

bool SmartAI::mJustReset
private

◆ mLastWP

WayPoint* SmartAI::mLastWP
private

◆ mOOCReached

bool SmartAI::mOOCReached
private

◆ mRun

◆ mScript

SmartScript SmartAI::mScript
private

Referenced by GetScript().

◆ mWayPoints

◆ mWPPauseTimer

uint32 SmartAI::mWPPauseTimer
private

◆ mWPReached

bool SmartAI::mWPReached
private

The documentation for this class was generated from the following files: