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

#include "CombatAI.h"

Inheritance diagram for CombatAI:
CreatureAI UnitAI CasterAI npc_boss_gothik_minion::npc_boss_gothik_minionAI npc_crusade_persuaded::npc_crusade_persuadedAI npc_death_knight_initiate::npc_death_knight_initiateAI npc_heated_battle::npc_heated_battleAI npc_llod_generic::npc_llod_genericAI npc_pet_dk_army_of_the_dead::npc_pet_dk_army_of_the_deadAI npc_pet_dk_ghoul::npc_pet_dk_ghoulAI npc_ravenous_worg::npc_ravenous_worgAI

Public Member Functions

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

Static Public Member Functions

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

Protected Attributes

EventMap events
 
SpellVct spells
 
- 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
 

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)
 

Detailed Description

Constructor & Destructor Documentation

◆ CombatAI()

CombatAI::CombatAI ( Creature c)
inlineexplicit
42: CreatureAI(c) {}
Definition: CreatureAI.h:71

Member Function Documentation

◆ InitializeAI()

void CombatAI::InitializeAI ( )
overridevirtual

Reimplemented from UnitAI.

Reimplemented in CasterAI, npc_pet_dk_army_of_the_dead::npc_pet_dk_army_of_the_deadAI, and npc_pet_mage_mirror_image.

51{
52 for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
53 if (me->m_spells[i] && sSpellMgr->GetSpellInfo(me->m_spells[i]))
54 spells.push_back(me->m_spells[i]);
55
57}
#define sSpellMgr
Definition: SpellMgr.h:825
static constexpr uint32 MAX_CREATURE_SPELLS
Definition: Unit.h:45
spells
Definition: boss_krystallus.cpp:26
std::uint32_t uint32
Definition: Define.h:107
virtual void InitializeAI()
Definition: UnitAI.h:204
Creature *const me
Definition: CreatureAI.h:73
uint32 m_spells[MAX_CREATURE_SPELLS]
Definition: Creature.h:251

References UnitAI::InitializeAI(), Creature::m_spells, MAX_CREATURE_SPELLS, CreatureAI::me, and sSpellMgr.

Referenced by CasterAI::InitializeAI(), and npc_pet_dk_army_of_the_dead::npc_pet_dk_army_of_the_deadAI::InitializeAI().

◆ JustDied()

void CombatAI::JustDied ( Unit killer)
overridevirtual

Reimplemented from CreatureAI.

Reimplemented in npc_boss_gothik_minion::npc_boss_gothik_minionAI, and npc_pet_dk_ghoul::npc_pet_dk_ghoulAI.

65{
66 for (SpellVct::iterator i = spells.begin(); i != spells.end(); ++i)
67 if (AISpellInfo[*i].condition == AICOND_DIE)
68 me->CastSpell(killer, *i, true);
69}
@ AICOND_DIE
Definition: CreatureAIImpl.h:50
static AISpellInfoType * AISpellInfo
Definition: UnitAI.h:407
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:1154

References AICOND_DIE, UnitAI::AISpellInfo, Unit::CastSpell(), and CreatureAI::me.

◆ JustEngagedWith()

void CombatAI::JustEngagedWith ( Unit who)
overridevirtual

Called for reaction when initially engaged.

Parameters
whoWho 'me' Engaged combat with

Reimplemented from CreatureAI.

Reimplemented in CasterAI, npc_crusade_persuaded::npc_crusade_persuadedAI, and npc_boss_gothik_minion::npc_boss_gothik_minionAI.

77{
78 for (SpellVct::iterator i = spells.begin(); i != spells.end(); ++i)
79 {
80 if (AISpellInfo[*i].condition == AICOND_AGGRO)
81 me->CastSpell(who, *i, false);
82 else if (AISpellInfo[*i].condition == AICOND_COMBAT)
83 events.ScheduleEvent(*i, AISpellInfo[*i].cooldown + rand() % AISpellInfo[*i].cooldown);
84 }
85}
@ AICOND_COMBAT
Definition: CreatureAIImpl.h:49
@ AICOND_AGGRO
Definition: CreatureAIImpl.h:48
events
Definition: boss_sartura.cpp:43

References AICOND_AGGRO, AICOND_COMBAT, UnitAI::AISpellInfo, Unit::CastSpell(), and CreatureAI::me.

◆ Permissible()

static int32 CombatAI::Permissible ( Creature const *  )
inlinestatic
50{ return PERMIT_BASE_NO; }
@ PERMIT_BASE_NO
Definition: CreatureAI.h:240

References PERMIT_BASE_NO.

◆ Reset()

◆ UpdateAI()

void CombatAI::UpdateAI ( uint32  )
overridevirtual

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

Implements UnitAI.

Reimplemented in CasterAI, npc_death_knight_initiate::npc_death_knight_initiateAI, npc_crusade_persuaded::npc_crusade_persuadedAI, npc_boss_gothik_minion::npc_boss_gothik_minionAI, npc_ravenous_worg::npc_ravenous_worgAI, npc_llod_generic::npc_llod_genericAI, and npc_pet_mage_mirror_image.

88{
89 if (!UpdateVictim())
90 return;
91
92 events.Update(diff);
93
95 return;
96
97 if (uint32 spellId = events.ExecuteEvent())
98 {
99 DoCast(spellId);
100 events.ScheduleEvent(spellId, AISpellInfo[spellId].cooldown + rand() % AISpellInfo[spellId].cooldown);
101 }
102 else
104}
@ UNIT_STATE_CASTING
Definition: UnitDefines.h:164
void DoMeleeAttackIfReady()
Definition: UnitAI.cpp:39
SpellCastResult DoCast(uint32 spellId)
Definition: UnitAI.cpp:177
bool UpdateVictim()
Definition: CreatureAI.cpp:269
bool HasUnitState(const uint32 f) const
Definition: Unit.h:739

References UnitAI::AISpellInfo, UnitAI::DoCast(), UnitAI::DoMeleeAttackIfReady(), Unit::HasUnitState(), CreatureAI::me, UNIT_STATE_CASTING, and CreatureAI::UpdateVictim().

Referenced by npc_death_knight_initiate::npc_death_knight_initiateAI::UpdateAI(), npc_crusade_persuaded::npc_crusade_persuadedAI::UpdateAI(), npc_ravenous_worg::npc_ravenous_worgAI::UpdateAI(), and npc_llod_generic::npc_llod_genericAI::UpdateAI().

Member Data Documentation

◆ events

EventMap CombatAI::events
protected

◆ spells

SpellVct CombatAI::spells
protected