Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Scripting/Spell): Add new hooks for Spell (OnSpellCast, OnSpellPrepare, OnSpellCancel) #21149

Merged
merged 10 commits into from
Jan 18, 2025
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
Loading