From caf9f0cae2e6bd35307da305a6b5c586b567fc8c Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 5 Feb 2011 21:09:47 +0300 Subject: [PATCH] [11109] Move DoMeleeAttackIfReady to CreatureAI and reuse more wide. --- src/game/AggressorAI.cpp | 9 +-------- src/game/CreatureAI.cpp | 20 ++++++++++++++++++++ src/game/CreatureAI.h | 5 ++++- src/game/CreatureEventAI.cpp | 18 ------------------ src/game/CreatureEventAI.h | 1 - src/game/GuardAI.cpp | 9 +-------- src/game/ReactorAI.cpp | 9 +-------- src/shared/revision_nr.h | 2 +- 8 files changed, 28 insertions(+), 45 deletions(-) diff --git a/src/game/AggressorAI.cpp b/src/game/AggressorAI.cpp index f479df01b..658fc6371 100644 --- a/src/game/AggressorAI.cpp +++ b/src/game/AggressorAI.cpp @@ -127,14 +127,7 @@ AggressorAI::UpdateAI(const uint32 /*diff*/) i_victimGuid = m_creature->getVictim()->GetGUID(); - if( m_creature->isAttackReady() ) - { - if (m_creature->CanReachWithMeleeAttack(m_creature->getVictim())) - { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); - } - } + DoMeleeAttackIfReady(); } bool diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 46c4d69cc..8be95b7ab 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -117,3 +117,23 @@ CanCastResult CreatureAI::DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 else return CAST_FAIL_IS_CASTING; } + +bool CreatureAI::DoMeleeAttackIfReady() +{ + // Check target + if (!m_creature->getVictim()) + return false; + + // Make sure our attack is ready before checking distance + if (!m_creature->isAttackReady()) + return false; + + // If we are within range melee the target + if (!m_creature->CanReachWithMeleeAttack(m_creature->getVictim())) + return false; + + m_creature->AttackerStateUpdate(m_creature->getVictim()); + m_creature->resetAttackTimer(); + + return true; +} diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h index cfff1afa8..c6734548d 100644 --- a/src/game/CreatureAI.h +++ b/src/game/CreatureAI.h @@ -81,7 +81,6 @@ class MANGOS_DLL_SPEC CreatureAI virtual void HealBy(Unit * /*healer*/, uint32 /*amount_healed*/) {} // Helper functions for cast spell - CanCastResult DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags = 0, uint64 uiOriginalCasterGUID = 0); virtual CanCastResult CanCastSpell(Unit* pTarget, const SpellEntry *pSpell, bool isTriggered); // Called at any Damage to any victim (before damage apply) @@ -151,6 +150,10 @@ class MANGOS_DLL_SPEC CreatureAI // Called when victim entered water and creature can not enter water virtual bool canReachByRangeAttack(Unit*) { return false; } + ///== Helper functions ============================= + bool DoMeleeAttackIfReady(); + CanCastResult DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags = 0, uint64 uiOriginalCasterGUID = 0); + ///== Fields ======================================= // Pointer to controlled by AI creature diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 6815647b8..b11a77309 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -1364,24 +1364,6 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit* } } -void CreatureEventAI::DoMeleeAttackIfReady() -{ - // Check target - if (!m_creature->getVictim()) - return; - - // Make sure our attack is ready before checking distance - if (!m_creature->isAttackReady()) - return; - - // If we are within range melee the target - if (!m_creature->CanReachWithMeleeAttack(m_creature->getVictim())) - return; - - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); -} - bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered) { //No target so we can't cast diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 1d58fd565..f8c41ccc1 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -608,7 +608,6 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker); void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target); - void DoMeleeAttackIfReady(); bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered); bool SpawnedEventConditionsCheck(CreatureEventAI_Event const& event); diff --git a/src/game/GuardAI.cpp b/src/game/GuardAI.cpp index 0385c890b..fdeb85e21 100644 --- a/src/game/GuardAI.cpp +++ b/src/game/GuardAI.cpp @@ -113,14 +113,7 @@ void GuardAI::UpdateAI(const uint32 /*diff*/) i_victimGuid = m_creature->getVictim()->GetGUID(); - if (m_creature->isAttackReady()) - { - if (m_creature->CanReachWithMeleeAttack(m_creature->getVictim())) - { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); - } - } + DoMeleeAttackIfReady(); } bool GuardAI::IsVisible(Unit *pl) const diff --git a/src/game/ReactorAI.cpp b/src/game/ReactorAI.cpp index 4de7d1e96..df9a36bf4 100644 --- a/src/game/ReactorAI.cpp +++ b/src/game/ReactorAI.cpp @@ -73,14 +73,7 @@ ReactorAI::UpdateAI(const uint32 /*time_diff*/) i_victimGuid = m_creature->getVictim()->GetGUID(); - if (m_creature->isAttackReady()) - { - if (m_creature->CanReachWithMeleeAttack(m_creature->getVictim())) - { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); - } - } + DoMeleeAttackIfReady(); } void diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index dab0cc9dc..bb0d6b606 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11108" + #define REVISION_NR "11109" #endif // __REVISION_NR_H__