feat(Core/AI): port OnSpellStart/OnSpellCast/OnSpellFailed/OnChannelF… (#25026)

Co-authored-by: offl <11556157+offl@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Andrew
2026-03-07 18:02:58 -03:00
committed by GitHub
parent b632aa9dd6
commit 33a438a585
8 changed files with 55 additions and 27 deletions

View File

@@ -3629,6 +3629,12 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
m_caster->SetCurrentCastedSpell(this);
SendSpellStart();
// Call CreatureAI hook OnSpellStart for spells with cast time or channeled spells
if (m_casttime > 0 || m_spellInfo->IsChanneled())
if (Creature* caster = m_caster->ToCreature())
if (caster->IsAIEnabled)
caster->AI()->OnSpellStart(GetSpellInfo());
// set target for proper facing
if ((m_casttime || m_spellInfo->IsChanneled()) && !HasTriggeredCastFlag(TRIGGERED_IGNORE_SET_FACING))
{
@@ -3727,6 +3733,11 @@ void Spell::cancel(bool bySelf)
sScriptMgr->OnSpellCastCancel(this, m_caster, m_spellInfo, bySelf);
// Call CreatureAI hook OnSpellFailed only for true interrupts/cancels, not prepare-time failures
if (Creature* creatureCaster = m_caster->ToCreature())
if (creatureCaster->IsAIEnabled)
creatureCaster->AI()->OnSpellFailed(m_spellInfo);
finish(false);
}
@@ -4052,11 +4063,10 @@ void Spell::_cast(bool skipCheck)
SetExecutedCurrently(false);
// Call CreatureAI hook OnSpellCastFinished
if (m_originalCaster)
if (Creature* caster = m_originalCaster->ToCreature())
if (caster->IsAIEnabled)
caster->AI()->OnSpellCastFinished(GetSpellInfo(), SPELL_FINISHED_SUCCESSFUL_CAST);
// Call CreatureAI hook on successful cast
if (Creature* caster = m_caster->ToCreature())
if (caster->IsAIEnabled)
caster->AI()->OnSpellCast(GetSpellInfo());
}
void Spell::handle_immediate()
@@ -4416,7 +4426,7 @@ void Spell::update(uint32 difftime)
// We call the hook here instead of in Spell::finish because we only want to call it for completed channeling. Everything else is handled by interrupts
if (Creature* creatureCaster = m_caster->ToCreature())
if (creatureCaster->IsAIEnabled)
creatureCaster->AI()->OnSpellCastFinished(m_spellInfo, SPELL_FINISHED_CHANNELING_COMPLETE);
creatureCaster->AI()->OnChannelFinished(m_spellInfo);
}
// Xinef: Dont update channeled target list on last tick, allow auras to update duration properly
// Xinef: Added this strange check because of diffrent update routines for players / creatures
@@ -4478,8 +4488,8 @@ void Spell::finish(bool ok)
// Xinef: Reset cooldown event in case of fail cast
if (m_spellInfo->IsCooldownStartedOnEvent())
m_caster->ToPlayer()->SendCooldownEvent(m_spellInfo, 0, 0, false);
}
return;
}