Core/Spells: unify OnSpellCastInterrupt and OnSuccessfulSpellCast hooks into OnSpellCastFinished (#25522)

* added support for calling the hook when completing a channeled spell as well

(cherry picked from commit 77aa058504e1ee99b560176d70bcf452c7e3d4f7)
This commit is contained in:
Ovah
2022-02-28 14:21:08 +01:00
committed by Shauren
parent 58ce0904aa
commit d1594c7295
6 changed files with 25 additions and 14 deletions
+3 -5
View File
@@ -33,6 +33,7 @@ class PlayerAI;
class WorldObject;
struct Position;
enum class QuestGiverStatus : uint32;
enum SpellFinishReason : uint8;
typedef std::vector<AreaBoundary const*> CreatureBoundary;
@@ -139,11 +140,8 @@ class TC_GAME_API CreatureAI : public UnitAI
// Called when spell hits a target
virtual void SpellHitTarget(WorldObject* /*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*/) { }
// Called when a spell either finishes, interrupts or cancels a spell cast
virtual void OnSpellCastFinished(SpellInfo const* /*spell*/, SpellFinishReason /*reason*/) { }
// Should return true if the NPC is currently being escorted
virtual bool IsEscorted() const { return false; }
+1 -1
View File
@@ -2879,7 +2879,7 @@ void Unit::InterruptSpell(CurrentSpellTypes spellType, bool withDelayed, bool wi
}
if (GetTypeId() == TYPEID_UNIT && IsAIEnabled())
ToCreature()->AI()->OnSpellCastInterrupt(spell->GetSpellInfo());
ToCreature()->AI()->OnSpellCastFinished(spell->GetSpellInfo(), SPELL_FINISHED_CANCELED);
}
}
+7 -2
View File
@@ -3724,10 +3724,10 @@ void Spell::_cast(bool skipCheck)
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
// Call CreatureAI hook OnSpellCastFinished
if (Creature* caster = m_originalCaster->ToCreature())
if (caster->IsAIEnabled())
caster->AI()->OnSuccessfulSpellCast(GetSpellInfo());
caster->AI()->OnSpellCastFinished(GetSpellInfo(), SPELL_FINISHED_SUCCESSFUL_CAST);
}
template <class Container>
@@ -4086,6 +4086,11 @@ void Spell::update(uint32 difftime)
{
SendChannelUpdate(0);
finish();
// 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);
}
break;
}
+7
View File
@@ -152,6 +152,13 @@ enum SpellRangeFlag
SPELL_RANGE_RANGED = 2 //hunter range and ranged weapon
};
enum SpellFinishReason : uint8
{
SPELL_FINISHED_SUCCESSFUL_CAST = 0, // spell has sucessfully launched
SPELL_FINISHED_CANCELED = 1, // spell has been canceled (interrupts)
SPELL_FINISHED_CHANNELING_COMPLETE = 2 // spell channeling has been finished
};
struct SpellLogEffectPowerDrainParams
{
ObjectGuid Victim;
@@ -24,6 +24,7 @@
#include "ObjectAccessor.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "Spell.h"
#include "SpellAuras.h"
#include "SpellScript.h"
#include "SpellAuraEffects.h"
@@ -246,8 +247,11 @@ struct boss_garothi_worldbreaker : public BossAI
instance->SendEncounterUnit(ENCOUNTER_FRAME_DISENGAGE, me);
}
void OnSuccessfulSpellCast(SpellInfo const* spell) override
void OnSpellCastFinished(SpellInfo const* spell, SpellFinishReason reason) override
{
if (reason != SPELL_FINISHED_SUCCESSFUL_CAST)
return;
switch (spell->Id)
{
case SPELL_APOCALYPSE_DRIVE_FINAL_DAMAGE:
@@ -1321,12 +1321,9 @@ struct npc_shambling_horror_icc : public ScriptedAI
DoMeleeAttackIfReady();
}
void OnSpellCastInterrupt(SpellInfo const* spell) override
void OnSpellCastFinished(SpellInfo const* spell, SpellFinishReason reason) override
{
ScriptedAI::OnSpellCastInterrupt(spell);
// When enrage is interrupted, reschedule the event
if (spell->Id == ENRAGE)
if (reason == SPELL_FINISHED_CANCELED && spell->Id == ENRAGE)
_events.RescheduleEvent(EVENT_ENRAGE, 1s);
}