Skip to content

Commit

Permalink
feat(Scripting/Spell): Add new hooks for Spell (OnSpellCast, OnSpellP…
Browse files Browse the repository at this point in the history
…repare, OnSpellCancel) (azerothcore#21149)

(cherry picked from commit 9056658)
  • Loading branch information
iThorgrim authored and skelUA committed Jan 26, 2025
1 parent 62b4a73 commit d7c01f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/server/game/Scripting/ScriptDefines/AllSpellScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ void ScriptMgr::OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex
CALL_ENABLED_HOOKS(AllSpellScript, ALLSPELLHOOK_ON_DUMMY_EFFECT_ITEM, script->OnDummyEffect(caster, spellID, effIndex, itemTarget));
}

void ScriptMgr::OnSpellCastCancel(Spell* spell, Unit* caster, SpellInfo const* spellInfo, bool bySelf)
{
CALL_ENABLED_HOOKS(AllSpellScript, ALLSPELLHOOK_ON_CAST_CANCEL, script->OnSpellCastCancel(spell, caster, spellInfo, bySelf));
}

void ScriptMgr::OnSpellCast(Spell* spell, Unit* caster, SpellInfo const* spellInfo, bool skipCheck)
{
CALL_ENABLED_HOOKS(AllSpellScript, ALLSPELLHOOK_ON_CAST, script->OnSpellCast(spell, caster, spellInfo, skipCheck));
}

void ScriptMgr::OnSpellPrepare(Spell* spell, Unit* caster, SpellInfo const* spellInfo)
{
CALL_ENABLED_HOOKS(AllSpellScript, ALLSPELLHOOK_ON_PREPARE, script->OnSpellPrepare(spell, caster, spellInfo));
}

AllSpellScript::AllSpellScript(char const* name, std::vector<uint16> enabledHooks)
: ScriptObject(name, ALLSPELLHOOK_END)
{
Expand Down
9 changes: 9 additions & 0 deletions src/server/game/Scripting/ScriptDefines/AllSpellScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ enum AllSpellHook
ALLSPELLHOOK_ON_DUMMY_EFFECT_GAMEOBJECT,
ALLSPELLHOOK_ON_DUMMY_EFFECT_CREATURE,
ALLSPELLHOOK_ON_DUMMY_EFFECT_ITEM,
ALLSPELLHOOK_ON_CAST_CANCEL,
ALLSPELLHOOK_ON_CAST,
ALLSPELLHOOK_ON_PREPARE,
ALLSPELLHOOK_END
};

Expand Down Expand Up @@ -100,6 +103,12 @@ class AllSpellScript : public ScriptObject
* @param itemTarget Contains information about the Item
*/
virtual void OnDummyEffect(WorldObject* /*caster*/, uint32 /*spellID*/, SpellEffIndex /*effIndex*/, Item* /*itemTarget*/) { }

virtual void OnSpellCastCancel(Spell* /*spell*/, Unit* /*caster*/, SpellInfo const* /*spellInfo*/, bool /*bySelf*/) { }

virtual void OnSpellCast(Spell* /*spell*/, Unit* /*caster*/, SpellInfo const* /*spellInfo*/, bool /*skipCheck*/) { }

virtual void OnSpellPrepare(Spell* /*spell*/, Unit* /*caster*/, SpellInfo const* /*spellInfo*/) { }
};

// Compatibility for old scripts
Expand Down
3 changes: 3 additions & 0 deletions src/server/game/Scripting/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ class ScriptMgr
void OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex effIndex, GameObject* gameObjTarget);
void OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex effIndex, Creature* creatureTarget);
void OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex effIndex, Item* itemTarget);
void OnSpellCastCancel(Spell* spell, Unit* caster, SpellInfo const* spellInfo, bool bySelf);
void OnSpellCast(Spell* spell, Unit* caster, SpellInfo const* spellInfo, bool skipCheck);
void OnSpellPrepare(Spell* spell, Unit* caster, SpellInfo const* spellInfo);

public: /* GameEventScript */
void OnGameEventStart(uint16 EventID);
Expand Down
6 changes: 6 additions & 0 deletions src/server/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3717,6 +3717,8 @@ SpellCastResult Spell::prepare(SpellCastTargets const* targets, AuraEffect const
TriggerGlobalCooldown();
}

sScriptMgr->OnSpellPrepare(this, m_caster, m_spellInfo);

return SPELL_CAST_OK;
}

Expand Down Expand Up @@ -3788,6 +3790,8 @@ void Spell::cancel(bool bySelf)
//set state back so finish will be processed
m_spellState = oldState;

sScriptMgr->OnSpellCastCancel(this, m_caster, m_spellInfo, bySelf);

finish(false);
}

Expand Down Expand Up @@ -4114,6 +4118,8 @@ void Spell::_cast(bool skipCheck)
if (m_caster->ToPlayer()->GetCommandStatus(CHEAT_COOLDOWN))
m_caster->ToPlayer()->RemoveSpellCooldown(m_spellInfo->Id, true);

sScriptMgr->OnSpellCast(this, m_caster, m_spellInfo, skipCheck);

SetExecutedCurrently(false);
}

Expand Down

0 comments on commit d7c01f6

Please # to comment.