[11109] Move DoMeleeAttackIfReady to CreatureAI and reuse more wide.

This commit is contained in:
VladimirMangos 2011-02-05 21:09:47 +03:00
parent d1007e49ca
commit caf9f0cae2
8 changed files with 28 additions and 45 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11108"
#define REVISION_NR "11109"
#endif // __REVISION_NR_H__