aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorIvan Beňovic <Ivan.Benovic2@gmail.com>2016-07-20 09:08:58 +0200
committerShauren <shauren.trinity@gmail.com>2016-07-20 09:08:58 +0200
commit8ff5b35be1256d03b85438b130dcec7cd4cae6e1 (patch)
tree38d7460449eb774a0ffddcfb046df9c003ad5bfd /src/server/game
parentdc9e2a53aa27a0cad18b876234e13bba79995323 (diff)
Core/Spells: Add SpellMissInfo argument to BeforeHit hooks and call them also when the spell doesn't hit. (#17613)
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/Spells/Spell.cpp17
-rw-r--r--src/server/game/Spells/Spell.h2
-rw-r--r--src/server/game/Spells/SpellScript.cpp10
-rw-r--r--src/server/game/Spells/SpellScript.h18
4 files changed, 36 insertions, 11 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 6f5e3d4a1af..5e07d43b4b4 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -2338,9 +2338,13 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target)
}
}
+ PrepareScriptHitHandlers();
+ CallScriptBeforeHitHandlers(missInfo);
+
if (spellHitTarget)
{
SpellMissInfo missInfo2 = DoSpellHitOnUnit(spellHitTarget, mask, target->scaleAura);
+
if (missInfo2 != SPELL_MISS_NONE)
{
if (missInfo2 != SPELL_MISS_MISS)
@@ -2519,9 +2523,6 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit* unit, uint32 effectMask, bool scaleA
if (!effectMask)
return returnVal;
- PrepareScriptHitHandlers();
- CallScriptBeforeHitHandlers();
-
if (Player* player = unit->ToPlayer())
{
player->StartCriteriaTimer(CRITERIA_TIMED_TYPE_SPELL_TARGET, m_spellInfo->Id);
@@ -2782,7 +2783,7 @@ void Spell::DoAllEffectOnTarget(GOTargetInfo* target)
return;
PrepareScriptHitHandlers();
- CallScriptBeforeHitHandlers();
+ CallScriptBeforeHitHandlers(SPELL_MISS_NONE);
for (SpellEffectInfo const* effect : GetEffects())
if (effect && (effectMask & (1 << effect->EffectIndex)))
@@ -2799,7 +2800,7 @@ void Spell::DoAllEffectOnTarget(ItemTargetInfo* target)
return;
PrepareScriptHitHandlers();
- CallScriptBeforeHitHandlers();
+ CallScriptBeforeHitHandlers(SPELL_MISS_NONE);
for (SpellEffectInfo const* effect : GetEffects())
if (effect && (effectMask & (1 << effect->EffectIndex)))
@@ -7190,14 +7191,14 @@ void Spell::CallScriptSuccessfulDispel(SpellEffIndex effIndex)
}
}
-void Spell::CallScriptBeforeHitHandlers()
+void Spell::CallScriptBeforeHitHandlers(SpellMissInfo missInfo)
{
for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_BEFORE_HIT);
- std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->BeforeHit.end(), hookItr = (*scritr)->BeforeHit.begin();
+ std::list<SpellScript::BeforeHitHandler>::iterator hookItrEnd = (*scritr)->BeforeHit.end(), hookItr = (*scritr)->BeforeHit.begin();
for (; hookItr != hookItrEnd; ++hookItr)
- (*hookItr).Call(*scritr);
+ (*hookItr).Call(*scritr, missInfo);
(*scritr)->_FinishScriptCall();
}
diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h
index 888e813f29b..e369ed29242 100644
--- a/src/server/game/Spells/Spell.h
+++ b/src/server/game/Spells/Spell.h
@@ -801,7 +801,7 @@ class TC_GAME_API Spell
void PrepareScriptHitHandlers();
bool CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode);
void CallScriptSuccessfulDispel(SpellEffIndex effIndex);
- void CallScriptBeforeHitHandlers();
+ void CallScriptBeforeHitHandlers(SpellMissInfo missInfo);
void CallScriptOnHitHandlers();
void CallScriptAfterHitHandlers();
void CallScriptObjectAreaTargetSelectHandlers(std::list<WorldObject*>& targets, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp
index c1eb798760b..a131e005a86 100644
--- a/src/server/game/Spells/SpellScript.cpp
+++ b/src/server/game/Spells/SpellScript.cpp
@@ -206,6 +206,16 @@ void SpellScript::EffectHandler::Call(SpellScript* spellScript, SpellEffIndex ef
(spellScript->*pEffectHandlerScript)(effIndexToHandle);
}
+SpellScript::BeforeHitHandler::BeforeHitHandler(SpellBeforeHitFnType pBeforeHitHandlerScript)
+{
+ _pBeforeHitHandlerScript = pBeforeHitHandlerScript;
+}
+
+void SpellScript::BeforeHitHandler::Call(SpellScript* spellScript, SpellMissInfo missInfo)
+{
+ (spellScript->*_pBeforeHitHandlerScript)(missInfo);
+}
+
SpellScript::HitHandler::HitHandler(SpellHitFnType _pHitHandlerScript)
{
pHitHandlerScript = _pHitHandlerScript;
diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h
index 97bbdf14231..bf67a81612a 100644
--- a/src/server/game/Spells/SpellScript.h
+++ b/src/server/game/Spells/SpellScript.h
@@ -168,6 +168,7 @@ class TC_GAME_API SpellScript : public _SpellScript
#define SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
typedef SpellCastResult(CLASSNAME::*SpellCheckCastFnType)(); \
typedef void(CLASSNAME::*SpellEffectFnType)(SpellEffIndex); \
+ typedef void(CLASSNAME::*SpellBeforeHitFnType)(SpellMissInfo missInfo); \
typedef void(CLASSNAME::*SpellHitFnType)(); \
typedef void(CLASSNAME::*SpellCastFnType)(); \
typedef void(CLASSNAME::*SpellObjectAreaTargetSelectFnType)(std::list<WorldObject*>&); \
@@ -214,6 +215,15 @@ class TC_GAME_API SpellScript : public _SpellScript
SpellHitFnType pHitHandlerScript;
};
+ class TC_GAME_API BeforeHitHandler
+ {
+ public:
+ BeforeHitHandler(SpellBeforeHitFnType pBeforeHitHandlerScript);
+ void Call(SpellScript* spellScript, SpellMissInfo missInfo);
+ private:
+ SpellBeforeHitFnType _pBeforeHitHandlerScript;
+ };
+
class TC_GAME_API TargetHook : public _SpellScript::EffectHook
{
public:
@@ -259,6 +269,7 @@ class TC_GAME_API SpellScript : public _SpellScript
class CheckCastHandlerFunction : public SpellScript::CheckCastHandler { public: CheckCastHandlerFunction(SpellCheckCastFnType _checkCastHandlerScript) : SpellScript::CheckCastHandler((SpellScript::SpellCheckCastFnType)_checkCastHandlerScript) { } }; \
class EffectHandlerFunction : public SpellScript::EffectHandler { public: EffectHandlerFunction(SpellEffectFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : SpellScript::EffectHandler((SpellScript::SpellEffectFnType)_pEffectHandlerScript, _effIndex, _effName) { } }; \
class HitHandlerFunction : public SpellScript::HitHandler { public: HitHandlerFunction(SpellHitFnType _pHitHandlerScript) : SpellScript::HitHandler((SpellScript::SpellHitFnType)_pHitHandlerScript) { } }; \
+ class BeforeHitHandlerFunction : public SpellScript::BeforeHitHandler { public: BeforeHitHandlerFunction(SpellBeforeHitFnType pBeforeHitHandlerScript) : SpellScript::BeforeHitHandler((SpellScript::SpellBeforeHitFnType)pBeforeHitHandlerScript) { } }; \
class ObjectAreaTargetSelectHandlerFunction : public SpellScript::ObjectAreaTargetSelectHandler { public: ObjectAreaTargetSelectHandlerFunction(SpellObjectAreaTargetSelectFnType _pObjectAreaTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::ObjectAreaTargetSelectHandler((SpellScript::SpellObjectAreaTargetSelectFnType)_pObjectAreaTargetSelectHandlerScript, _effIndex, _targetType) { } }; \
class ObjectTargetSelectHandlerFunction : public SpellScript::ObjectTargetSelectHandler { public: ObjectTargetSelectHandlerFunction(SpellObjectTargetSelectFnType _pObjectTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::ObjectTargetSelectHandler((SpellScript::SpellObjectTargetSelectFnType)_pObjectTargetSelectHandlerScript, _effIndex, _targetType) { } }; \
class DestinationTargetSelectHandlerFunction : public SpellScript::DestinationTargetSelectHandler { public: DestinationTargetSelectHandlerFunction(SpellDestinationTargetSelectFnType _DestinationTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::DestinationTargetSelectHandler((SpellScript::SpellDestinationTargetSelectFnType)_DestinationTargetSelectHandlerScript, _effIndex, _targetType) { } }
@@ -307,8 +318,11 @@ class TC_GAME_API SpellScript : public _SpellScript
HookList<EffectHandler> OnEffectSuccessfulDispel;
#define SpellEffectFn(F, I, N) EffectHandlerFunction(&F, I, N)
- // example: BeforeHit += SpellHitFn(class::function);
- HookList<HitHandler> BeforeHit;
+ // example: BeforeHit += BeforeSpellHitFn(class::function);
+ // where function is void function(SpellMissInfo missInfo)
+ HookList<BeforeHitHandler> BeforeHit;
+ #define BeforeSpellHitFn(F) BeforeHitHandlerFunction(&F)
+
// example: OnHit += SpellHitFn(class::function);
HookList<HitHandler> OnHit;
// example: AfterHit += SpellHitFn(class::function);