[10368] Use AI function DoCastSpellIfCan for eventAI ACTION_T_CAST

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-08-18 01:31:25 +02:00
parent 9c8533335b
commit a6360987de
3 changed files with 21 additions and 48 deletions

View file

@ -49,7 +49,7 @@ using std::hash_map;
# define HASH_NAMESPACE_END } # define HASH_NAMESPACE_END }
using stdext::hash_map; using stdext::hash_map;
#if !_HAS_TRADITIONAL_STL #if !_HAS_TRADITIONAL_STL
// can be not used by some platforms, so provide fake forward // can be not used by some platforms, so provide fake forward
HASH_NAMESPACE_START HASH_NAMESPACE_START

View file

@ -460,66 +460,39 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
case ACTION_T_CAST: case ACTION_T_CAST:
{ {
Unit* target = GetTargetByType(action.cast.target, pActionInvoker); Unit* target = GetTargetByType(action.cast.target, pActionInvoker);
Unit* caster = m_creature;
if (!target) if (!target)
{
sLog.outDebug("CreatureEventAI: NULL target for ACTION_T_CAST creature entry %u casting spell id %u", m_creature->GetEntry(), action.cast.spellId);
return; return;
if (action.cast.castFlags & CAST_FORCE_TARGET_SELF)
caster = target;
//Allowed to cast only if not casting (unless we interrupt ourself) or if spell is triggered
bool canCast = !caster->IsNonMeleeSpellCasted(false) || (action.cast.castFlags & (CAST_TRIGGERED | CAST_INTERRUPT_PREVIOUS));
// If cast flag CAST_AURA_NOT_PRESENT is active, check if target already has aura on them
if(action.cast.castFlags & CAST_AURA_NOT_PRESENT)
{
for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
if(target->HasAura(action.cast.spellId, SpellEffectIndex(i)))
return;
} }
if (canCast) CanCastResult castResult = DoCastSpellIfCan(target, action.cast.spellId, action.cast.castFlags);
{
const SpellEntry* tSpell = GetSpellStore()->LookupEntry(action.cast.spellId);
//Verify that spell exists switch(castResult)
if (tSpell) {
case CAST_FAIL_POWER:
case CAST_FAIL_TOO_FAR:
{ {
//Check if cannot cast spell // Melee current victim if flag not set
if (!(action.cast.castFlags & (CAST_FORCE_TARGET_SELF | CAST_FORCE_CAST)) && if (!(action.cast.castFlags & CAST_NO_MELEE_IF_OOM))
!CanCast(target, tSpell, (action.cast.castFlags & CAST_TRIGGERED)))
{ {
//Melee current victim if flag not set switch(m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType())
if (!(action.cast.castFlags & CAST_NO_MELEE_IF_OOM))
{ {
switch(m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType()) case CHASE_MOTION_TYPE:
{ case FOLLOW_MOTION_TYPE:
case CHASE_MOTION_TYPE: m_AttackDistance = 0.0f;
case FOLLOW_MOTION_TYPE: m_AttackAngle = 0.0f;
m_AttackDistance = 0.0f;
m_AttackAngle = 0.0f;
m_creature->GetMotionMaster()->Clear(false); m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle); m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
break; break;
}
} }
} }
else break;
{
//Interrupt any previous spell
if (caster->IsNonMeleeSpellCasted(false) && action.cast.castFlags & CAST_INTERRUPT_PREVIOUS)
caster->InterruptNonMeleeSpells(false);
caster->CastSpell(target, action.cast.spellId, (action.cast.castFlags & CAST_TRIGGERED));
}
} }
else
sLog.outErrorDb("CreatureEventAI: event %d creature %d attempt to cast spell that doesn't exist %d", EventId, m_creature->GetEntry(), action.cast.spellId);
} }
break; break;
} }
case ACTION_T_SUMMON: case ACTION_T_SUMMON:

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10367" #define REVISION_NR "10368"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__