aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Examples
diff options
context:
space:
mode:
authorQAston <qaston@gmail.com>2011-12-31 13:10:13 +0100
committerQAston <qaston@gmail.com>2011-12-31 13:11:12 +0100
commitafc18461d76b74f1e6dfaccebb3689e4ec2c2012 (patch)
tree5e6997a14ee307e31fc9721e7e44ceca7150f6de /src/server/scripts/Examples
parentb65722a85959508e23c683e8d55a4bce4eeb9373 (diff)
Core/SpellScripts: Add BeforeCast, OnCast and AfterCast hooks to SpellScripts.
Diffstat (limited to 'src/server/scripts/Examples')
-rw-r--r--src/server/scripts/Examples/example_spell.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/server/scripts/Examples/example_spell.cpp b/src/server/scripts/Examples/example_spell.cpp
index 372abc45268..4d2064bf630 100644
--- a/src/server/scripts/Examples/example_spell.cpp
+++ b/src/server/scripts/Examples/example_spell.cpp
@@ -76,6 +76,38 @@ class spell_ex_5581 : public SpellScriptLoader
delete localVariable2;
}
+ void HandleBeforeCast()
+ {
+ // this hook is executed before anything about casting the spell is done
+ // after this hook is executed all the machinery starts
+ sLog->outString("Caster just finished preparing the spell (cast bar has expired)");
+ }
+
+ void HandleOnCast()
+ {
+ // cast is validated and spell targets are selected at this moment
+ // this is a last place when the spell can be safely interrupted
+ sLog->outString("Spell is about to do take reagents, power, launch missile, do visuals and instant spell effects");
+ }
+
+ void HandleAfterCast()
+ {
+ sLog->outString("All immediate actions for the spell are finished now");
+ // this is a safe for triggering additional effects for a spell without interfering
+ // with visuals or with other effects of the spell
+ //GetCaster()->CastSpell(target, SPELL_TRIGGERED, true);
+ }
+
+ SpellCastResult CheckRequirement()
+ {
+ // in this hook you can add additional requirements for spell caster (and throw a client error if reqs're not passed)
+ // in this case we're disallowing to select non-player as a target of the spell
+ //if (!GetTargetUnit() || GetTargetUnit()->ToPlayer())
+ //return SPELL_FAILED_BAD_TARGETS;
+ return SPELL_CAST_OK;
+ }
+
+
void HandleDummyLaunch(SpellEffIndex /*effIndex*/)
{
sLog->outString("Spell %u with SPELL_EFFECT_DUMMY is just launched!", GetSpellInfo()->Id);
@@ -127,7 +159,11 @@ class spell_ex_5581 : public SpellScriptLoader
// register functions used in spell script - names of these functions do not matter
void Register()
{
- // we're registering our function here
+ // we're registering our functions here
+ BeforeCast += SpellCastFn(spell_ex_5581SpellScript::HandleBeforeCast);
+ OnCast += SpellCastFn(spell_ex_5581SpellScript::HandleOnCast);
+ AfterCast += SpellCastFn(spell_ex_5581SpellScript::HandleAfterCast);
+ OnCheckCast += SpellCheckCastFn(spell_ex_5581SpellScript::CheckRequirement);
// function HandleDummy will be called when spell is launched, independant from targets selected for spell, just before default effect 0 launch handler
OnEffectLaunch += SpellEffectFn(spell_ex_5581SpellScript::HandleDummyLaunch, EFFECT_0, SPELL_EFFECT_DUMMY);
// function HandleDummy will be called when spell is launched at target, just before default effect 0 launch at target handler