[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

@ -460,37 +460,21 @@ 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)
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) sLog.outDebug("CreatureEventAI: NULL target for ACTION_T_CAST creature entry %u casting spell id %u", m_creature->GetEntry(), action.cast.spellId);
if(target->HasAura(action.cast.spellId, SpellEffectIndex(i)))
return; 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)
{ {
//Check if cannot cast spell case CAST_FAIL_POWER:
if (!(action.cast.castFlags & (CAST_FORCE_TARGET_SELF | CAST_FORCE_CAST)) && case CAST_FAIL_TOO_FAR:
!CanCast(target, tSpell, (action.cast.castFlags & CAST_TRIGGERED)))
{ {
//Melee current victim if flag not set // Melee current victim if flag not set
if (!(action.cast.castFlags & CAST_NO_MELEE_IF_OOM)) if (!(action.cast.castFlags & CAST_NO_MELEE_IF_OOM))
{ {
switch(m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType()) switch(m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType())
@ -505,21 +489,10 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
break; break;
} }
} }
break;
} }
else
{
//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__