Core/AI: Implemented OnSpellCastInterrupt and OnSuccessfulSpellCast hooks

Ported from: 020825902c and 1aa42e97a8
This commit is contained in:
Ovah
2020-04-25 15:54:08 -03:00
committed by Keader
parent 7c91c423d0
commit f1e4ee21f8
3 changed files with 14 additions and 0 deletions

View File

@@ -145,6 +145,12 @@ class TC_GAME_API CreatureAI : public UnitAI
virtual void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spellInfo*/) { }
virtual void SpellHitTargetGameObject(GameObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
// Called when a spell cast gets interrupted
virtual void OnSpellCastInterrupt(SpellInfo const* /*spell*/) { }
// Called when a spell cast has been successfully finished
virtual void OnSuccessfulSpellCast(SpellInfo const* /*spell*/) { }
// Should return true if the NPC is currently being escorted
virtual bool IsEscorted() const { return false; }

View File

@@ -3011,6 +3011,9 @@ void Unit::InterruptSpell(CurrentSpellTypes spellType, bool withDelayed, bool wi
m_currentSpells[spellType] = nullptr;
spell->SetReferencedFromCurrent(false);
}
if (GetTypeId() == TYPEID_UNIT && IsAIEnabled())
ToCreature()->AI()->OnSpellCastInterrupt(spell->GetSpellInfo());
}
}

View File

@@ -3454,6 +3454,11 @@ void Spell::_cast(bool skipCheck)
hitMask |= PROC_HIT_NORMAL;
Unit::ProcSkillsAndAuras(m_originalCaster, nullptr, procAttacker, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_CAST, hitMask, this, nullptr, nullptr);
// Call CreatureAI hook OnSuccessfulSpellCast
if (Creature* caster = m_originalCaster->ToCreature())
if (caster->IsAIEnabled())
caster->AI()->OnSuccessfulSpellCast(GetSpellInfo());
}
template <class Container>