TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generic_creature::generic_creatureAI Struct Reference

Public Member Functions

 generic_creatureAI (Creature *creature)
 
void Initialize ()
 
void Reset () override
 
void EnterCombat (Unit *who) override
 
void UpdateAI (uint32 diff) override
 
- Public Member Functions inherited from ScriptedAI
 ScriptedAI (Creature *creature)
 
virtual ~ScriptedAI ()
 
void AttackStartNoMove (Unit *target)
 
void DamageTaken (Unit *, uint32 &) override
 
void JustDied (Unit *) override
 
void KilledUnit (Unit *) override
 
void JustSummoned (Creature *) override
 
void SummonedCreatureDespawn (Creature *) override
 
void SpellHit (Unit *, SpellInfo const *) override
 
void SpellHitTarget (Unit *, SpellInfo const *) override
 
void OnPossess (bool)
 
void AttackStart (Unit *) override
 
void DoStartMovement (Unit *target, float distance=0.0f, float angle=0.0f)
 
void DoStartNoMovement (Unit *target)
 
void DoStopAttack ()
 
void DoCastSpell (Unit *target, SpellInfo const *spellInfo, bool triggered=false)
 
void DoPlaySoundToSet (WorldObject *source, uint32 soundId)
 
void DoResetThreat ()
 
float DoGetThreat (Unit *unit)
 
void DoModifyThreatPercent (Unit *unit, int32 pct)
 
void DoTeleportTo (float x, float y, float z, uint32 time=0)
 
void DoTeleportTo (float const pos[4])
 
void DoTeleportPlayer (Unit *unit, float x, float y, float z, float o)
 
void DoTeleportAll (float x, float y, float z, float o)
 
UnitDoSelectLowestHpFriendly (float range, uint32 minHPDiff=1)
 
std::list< Creature * > DoFindFriendlyCC (float range)
 
std::list< Creature * > DoFindFriendlyMissingBuff (float range, uint32 spellId)
 
PlayerGetPlayerAtMinimumRange (float minRange)
 
CreatureDoSpawnCreature (uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime)
 
bool HealthBelowPct (uint32 pct) const
 
bool HealthAbovePct (uint32 pct) const
 
SpellInfo constSelectSpell (Unit *target, uint32 school, uint32 mechanic, SelectTargetType targets, float rangeMin, float rangeMax, SelectEffect effect)
 
void SetEquipmentSlots (bool loadDefault, int32 mainHand=EQUIP_NO_CHANGE, int32 offHand=EQUIP_NO_CHANGE, int32 ranged=EQUIP_NO_CHANGE)
 
void SetCombatMovement (bool allowMovement)
 
bool IsCombatMovementAllowed () const
 
bool IsHeroic () const
 
Difficulty GetDifficulty () const
 
bool Is25ManRaid () const
 
template<class T >
const T & DUNGEON_MODE (const T &normal5, const T &heroic10) const
 
template<class T >
const T & RAID_MODE (const T &normal10, const T &normal25) const
 
template<class T >
const T & RAID_MODE (const T &normal10, const T &normal25, const T &heroic10, const T &heroic25) const
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr)
 
 CreatureAI (Creature *creature)
 
virtual ~CreatureAI ()
 
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 IsSummonedBy (Unit *)
 
virtual void SummonedCreatureDies (Creature *, Unit *)
 
virtual void AttackedBy (Unit *)
 
virtual bool IsEscorted () const
 
virtual void JustRespawned ()
 
virtual void MovementInform (uint32, uint32)
 
void OnCharmed (bool apply) override
 
virtual void JustReachedHome ()
 
void DoZoneInCombat (Creature *creature=NULL, float maxRangeToNearestTarget=50.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 void OnSpellClick (Unit *, bool &)
 
virtual bool CanSeeAlways (WorldObject const *)
 
int32 VisualizeBoundary (uint32 duration, Unit *owner=nullptr, bool fill=false) const
 
virtual bool CheckInRoom ()
 
CreatureBoundary constGetBoundary () const
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual bool CanAIAttack (Unit const *) const
 
virtual void InitializeAI ()
 
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 (SelectAggroTarget targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectAggroTarget targetType, uint32 position, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectAggroTarget targetType, float dist=0.0f, bool playerOnly=false, int32 aura=0)
 
template<class PREDICATE >
void SelectTargetList (std::list< Unit * > &targetList, PREDICATE const &predicate, uint32 maxTargets, SelectAggroTarget targetType)
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 
virtual void HealReceived (Unit *, uint32 &)
 
virtual void HealDone (Unit *, uint32 &)
 
virtual void SpellInterrupted (uint32, uint32)
 
void AttackStartCaster (Unit *victim, float dist)
 
void DoCast (uint32 spellId)
 
void DoCast (Unit *victim, uint32 spellId, bool triggered=false)
 
void DoCastVictim (uint32 spellId, bool triggered=false)
 
void DoCastAOE (uint32 spellId, bool triggered=false)
 
void DoMeleeAttackIfReady ()
 
bool DoSpellAttackIfReady (uint32 spellId)
 
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 sQuestReward (Player *, Quest const *, uint32)
 
virtual bool sOnDummyEffect (Unit *, uint32, SpellEffIndex)
 
virtual void sOnGameEvent (bool, uint16)
 

Public Attributes

uint32 GlobalCooldown
 
uint32 BuffTimer
 
bool IsSelfRooted
 
- Public Attributes inherited from ScriptedAI
bool IsFleeing
 

Additional Inherited Members

- Public Types inherited from CreatureAI
enum  EvadeReason { EVADE_REASON_NO_HOSTILES, EVADE_REASON_BOUNDARY, EVADE_REASON_SEQUENCE_BREAK, EVADE_REASON_OTHER }
 
- Static Public Member Functions inherited from UnitAI
static void FillAISpellInfo ()
 
- 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 CheckBoundary (Position const *who=nullptr) const
 
void SetBoundary (CreatureBoundary const *boundary)
 
virtual void MoveInLineOfSight (Unit *)
 
bool _EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
CreatureBoundary const_boundary
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Constructor & Destructor Documentation

generic_creature::generic_creatureAI::generic_creatureAI ( Creature creature)
inline
39  : ScriptedAI(creature)
40  {
41  Initialize();
42  }
ScriptedAI(Creature *creature)
Definition: ScriptedCreature.cpp:100
void Initialize()
Definition: mob_generic_creature.cpp:44

+ Here is the call graph for this function:

Member Function Documentation

void generic_creature::generic_creatureAI::EnterCombat ( Unit who)
inlineoverridevirtual

Reimplemented from ScriptedAI.

61  {
62  if (!me->IsWithinMeleeRange(who))
63  IsSelfRooted = true;
64  }
Creature *const me
Definition: CreatureAI.h:71
bool IsSelfRooted
Definition: mob_generic_creature.cpp:53
bool IsWithinMeleeRange(const Unit *obj, float dist=MELEE_RANGE) const
Definition: Unit.cpp:508

+ Here is the call graph for this function:

void generic_creature::generic_creatureAI::Initialize ( void  )
inline
45  {
46  GlobalCooldown = 0;
47  BuffTimer = 0; //Rebuff as soon as we can
48  IsSelfRooted = false;
49  }
bool IsSelfRooted
Definition: mob_generic_creature.cpp:53
uint32 BuffTimer
Definition: mob_generic_creature.cpp:52
uint32 GlobalCooldown
Definition: mob_generic_creature.cpp:51

+ Here is the caller graph for this function:

void generic_creature::generic_creatureAI::Reset ( )
inlineoverridevirtual

Reimplemented from ScriptedAI.

56  {
57  Initialize();
58  }
void Initialize()
Definition: mob_generic_creature.cpp:44

+ Here is the call graph for this function:

void generic_creature::generic_creatureAI::UpdateAI ( uint32  diff)
inlineoverridevirtual

Reimplemented from ScriptedAI.

67  {
68  //Always decrease our global cooldown first
69  if (GlobalCooldown > diff)
70  GlobalCooldown -= diff;
71  else GlobalCooldown = 0;
72 
73  //Buff timer (only buff when we are alive and not in combat
74  if (!me->IsInCombat() && me->IsAlive())
75  {
76  if (BuffTimer <= diff)
77  {
78  //Find a spell that targets friendly and applies an aura (these are generally buffs)
80 
81  if (info && !GlobalCooldown)
82  {
83  //Cast the buff spell
84  DoCastSpell(me, info);
85 
86  //Set our global cooldown
88 
89  //Set our timer to 10 minutes before rebuff
90  BuffTimer = 600000;
91  }//Try agian in 30 seconds
92  else BuffTimer = 30000;
93  } else BuffTimer -= diff;
94  }
95 
96  //Return since we have no target
97  if (!UpdateVictim())
98  return;
99 
100  //If we are within range melee the target
102  {
103  //Make sure our attack is ready and we arn't currently casting
104  if (me->isAttackReady() && !me->IsNonMeleeSpellCast(false))
105  {
106  bool Healing = false;
107  SpellInfo const* info = NULL;
108 
109  //Select a healing spell if less than 30% hp
110  if (HealthBelowPct(30))
112 
113  //No healing spell available, select a hostile spell
114  if (info) Healing = true;
116 
117  //50% chance if elite or higher, 20% chance if not, to replace our white hit with a spell
118  if (info && (rand32() % (me->GetCreatureTemplate()->rank > 1 ? 2 : 5) == 0) && !GlobalCooldown)
119  {
120  //Cast the spell
121  if (Healing)DoCastSpell(me, info);
122  else DoCastSpell(me->GetVictim(), info);
123 
124  //Set our global cooldown
126  }
128 
129  me->resetAttackTimer();
130  }
131  }
132  else
133  {
134  //Only run this code if we arn't already casting
135  if (!me->IsNonMeleeSpellCast(false))
136  {
137  bool Healing = false;
138  SpellInfo const* info = NULL;
139 
140  //Select a healing spell if less than 30% hp ONLY 33% of the time
141  if (HealthBelowPct(30) && rand32() % 3 == 0)
143 
144  //No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
145  if (info) Healing = true;
147 
148  //Found a spell, check if we arn't on cooldown
149  if (info && !GlobalCooldown)
150  {
151  //If we are currently moving stop us and set the movement generator
152  if (!IsSelfRooted)
153  IsSelfRooted = true;
154 
155  //Cast spell
156  if (Healing) DoCastSpell(me, info);
157  else DoCastSpell(me->GetVictim(), info);
158 
159  //Set our global cooldown
161 
162  }//If no spells available and we arn't moving run to target
163  else if (IsSelfRooted)
164  {
165  //Cancel our current spell and then allow movement agian
166  me->InterruptNonMeleeSpells(false);
167  IsSelfRooted = false;
168  }
169  }
170  }
171  }
bool UpdateVictim()
Definition: CreatureAI.cpp:233
uint32 rank
Definition: Creature.h:102
void AttackerStateUpdate(Unit *victim, WeaponAttackType attType=BASE_ATTACK, bool extra=false)
Definition: Unit.cpp:1874
void DoCastSpell(Unit *target, SpellInfo const *spellInfo, bool triggered=false)
Definition: ScriptedCreature.cpp:154
Definition: SpellInfo.h:326
SpellInfo const * SelectSpell(Unit *target, uint32 school, uint32 mechanic, SelectTargetType targets, float rangeMin, float rangeMax, SelectEffect effect)
Definition: ScriptedCreature.cpp:182
bool HealthBelowPct(uint32 pct) const
Definition: ScriptedCreature.h:247
bool IsInCombat() const
Definition: Unit.h:1584
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: CreatureAI.h:55
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false, bool isAutoshoot=false, bool skipInstant=true) const
Definition: Unit.cpp:2886
Definition: CreatureAI.h:45
Creature *const me
Definition: CreatureAI.h:71
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:558
bool IsSelfRooted
Definition: mob_generic_creature.cpp:53
uint32 BuffTimer
Definition: mob_generic_creature.cpp:52
bool IsAlive() const
Definition: Unit.h:1692
Unit * GetVictim() const
Definition: Unit.h:1379
Definition: CreatureAI.h:57
Definition: CreatureAI.h:49
bool IsWithinMeleeRange(const Unit *obj, float dist=MELEE_RANGE) const
Definition: Unit.cpp:508
bool isAttackReady(WeaponAttackType type=BASE_ATTACK) const
Definition: Unit.h:1357
void resetAttackTimer(WeaponAttackType type=BASE_ATTACK)
Definition: Unit.cpp:481
#define NOMINAL_MELEE_RANGE
Definition: Object.h:47
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition: Unit.cpp:2916
Definition: CreatureAI.h:58
uint32 rand32()
Definition: Random.cpp:64
#define GENERIC_CREATURE_COOLDOWN
Definition: mob_generic_creature.cpp:30
uint32 GlobalCooldown
Definition: mob_generic_creature.cpp:51

+ Here is the call graph for this function:

Member Data Documentation

uint32 generic_creature::generic_creatureAI::BuffTimer
uint32 generic_creature::generic_creatureAI::GlobalCooldown
bool generic_creature::generic_creatureAI::IsSelfRooted

The documentation for this struct was generated from the following file: