Core/ScriptSystem: Add compile time type check of function assigned to hooks - prevents incorrect function calls. Since this rev you have to put PrepareSpellScript(<yourscriptclassnamehere>) at the beginning of every spell script. Yes, i know it's unhandy, but unfortunately C++ preprocessor is very limited, so you have to do that extra work each time you write a script:(.
--HG-- branch : trunk
This commit is contained in:
@@ -7242,7 +7242,7 @@ void Spell::CallScriptBeforeHitHandlers()
|
||||
std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->BeforeHit.end(), hookItr = (*scritr)->BeforeHit.begin();
|
||||
for(; hookItr != hookItrEnd ; ++hookItr)
|
||||
{
|
||||
((*scritr)->*(*hookItr))();
|
||||
(*hookItr).Call(*scritr);
|
||||
}
|
||||
(*scritr)->_FinishScriptCall();
|
||||
}
|
||||
@@ -7256,7 +7256,7 @@ void Spell::CallScriptOnHitHandlers()
|
||||
std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->OnHit.end(), hookItr = (*scritr)->OnHit.begin();
|
||||
for(; hookItr != hookItrEnd ; ++hookItr)
|
||||
{
|
||||
((*scritr)->*(*hookItr))();
|
||||
(*hookItr).Call(*scritr);
|
||||
}
|
||||
(*scritr)->_FinishScriptCall();
|
||||
}
|
||||
@@ -7270,7 +7270,7 @@ void Spell::CallScriptAfterHitHandlers()
|
||||
std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->AfterHit.end(), hookItr = (*scritr)->AfterHit.begin();
|
||||
for(; hookItr != hookItrEnd ; ++hookItr)
|
||||
{
|
||||
((*scritr)->*(*hookItr))();
|
||||
(*hookItr).Call(*scritr);
|
||||
}
|
||||
(*scritr)->_FinishScriptCall();
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ enum ProcFlags
|
||||
PROC_FLAG_TAKEN_MELEE_AUTO_ATTACK = 0x00000008, // 03 Taken melee auto attack
|
||||
|
||||
PROC_FLAG_DONE_SPELL_MELEE_DMG_CLASS = 0x00000010, // 04 Done attack by Spell that has dmg class melee
|
||||
PROC_FLAG_TAKEN_SPELL_MELEE_DMG_CLASS = 0x00000020, // 05 Taken damage by Spell that has dmg class melee
|
||||
PROC_FLAG_TAKEN_SPELL_MELEE_DMG_CLASS = 0x00000020, // 05 Taken attack by Spell that has dmg class melee
|
||||
|
||||
PROC_FLAG_DONE_RANGED_AUTO_ATTACK = 0x00000040, // 06 Done ranged auto attack
|
||||
PROC_FLAG_TAKEN_RANGED_AUTO_ATTACK = 0x00000080, // 07 Taken ranged auto attack
|
||||
|
||||
@@ -167,6 +167,16 @@ void SpellScript::EffectHandler::Call(SpellScript * spellScript, SpellEffIndex e
|
||||
(spellScript->*pEffectHandlerScript)(effIndex);
|
||||
}
|
||||
|
||||
SpellScript::HitHandler::HitHandler(SpellHitFnType _pHitHandlerScript)
|
||||
{
|
||||
pHitHandlerScript = _pHitHandlerScript;
|
||||
}
|
||||
|
||||
void SpellScript::HitHandler::Call(SpellScript * spellScript)
|
||||
{
|
||||
(spellScript->*pHitHandlerScript)();
|
||||
}
|
||||
|
||||
bool SpellScript::_Validate(SpellEntry const * entry)
|
||||
{
|
||||
for (std::list<EffectHandler>::iterator itr = OnEffect.begin(); itr != OnEffect.end(); ++itr)
|
||||
|
||||
@@ -131,8 +131,11 @@ class SpellScript : public _SpellScript
|
||||
// internal use classes & functions
|
||||
// DO NOT OVERRIDE THESE IN SCRIPTS
|
||||
public:
|
||||
typedef void(SpellScript::*SpellEffectFnType)(SpellEffIndex);
|
||||
typedef void(SpellScript::*SpellHitFnType)();
|
||||
#define SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
|
||||
typedef void(CLASSNAME::*SpellEffectFnType)(SpellEffIndex); \
|
||||
typedef void(CLASSNAME::*SpellHitFnType)(); \
|
||||
|
||||
SPELLSCRIPT_FUNCTION_TYPE_DEFINES(SpellScript)
|
||||
|
||||
class EffectHandler : public _SpellScript::EffectNameCheck, public _SpellScript::EffectHook
|
||||
{
|
||||
@@ -144,7 +147,21 @@ class SpellScript : public _SpellScript
|
||||
private:
|
||||
SpellEffectFnType pEffectHandlerScript;
|
||||
};
|
||||
typedef SpellHitFnType HitHandler;
|
||||
|
||||
class HitHandler
|
||||
{
|
||||
public:
|
||||
HitHandler(SpellHitFnType _pHitHandlerScript);
|
||||
void Call(SpellScript * spellScript);
|
||||
private:
|
||||
SpellHitFnType pHitHandlerScript;
|
||||
};
|
||||
|
||||
#define SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) \
|
||||
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) {} }; \
|
||||
|
||||
#define PrepareSpellScript(CLASSNAME) SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME)
|
||||
public:
|
||||
bool _Validate(SpellEntry const * entry);
|
||||
bool _Load(Spell * spell);
|
||||
@@ -167,7 +184,7 @@ class SpellScript : public _SpellScript
|
||||
// example: OnEffect += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier);
|
||||
// where function is void function(SpellEffIndex effIndex)
|
||||
HookList<EffectHandler> OnEffect;
|
||||
#define SpellEffectFn(F, I, N) EffectHandler((SpellEffectFnType)&F, I, N)
|
||||
#define SpellEffectFn(F, I, N) EffectHandlerFunction(&F, I, N)
|
||||
|
||||
// example: BeforeHit += SpellHitFn(class::function);
|
||||
HookList<HitHandler> BeforeHit;
|
||||
@@ -176,7 +193,7 @@ class SpellScript : public _SpellScript
|
||||
// example: AfterHit += SpellHitFn(class::function);
|
||||
HookList<HitHandler> AfterHit;
|
||||
// where function is: void function()
|
||||
#define SpellHitFn(F) (SpellHitFnType)&F
|
||||
#define SpellHitFn(F) HitHandlerFunction(&F)
|
||||
|
||||
// hooks are executed in following order, at specified event of spell:
|
||||
// 1. BeforeHit - executed just before spell hits a target
|
||||
@@ -276,12 +293,16 @@ class AuraScript : public _SpellScript
|
||||
// internal use classes & functions
|
||||
// DO NOT OVERRIDE THESE IN SCRIPTS
|
||||
public:
|
||||
typedef void(AuraScript::*AuraEffectApplicationModeFnType)(AuraEffect const *, AuraApplication const *, AuraEffectHandleModes mode);
|
||||
typedef void(AuraScript::*AuraEffectPeriodicFnType)(AuraEffect const *, AuraApplication const *);
|
||||
typedef void(AuraScript::*AuraEffectUpdatePeriodicFnType)(AuraEffect *);
|
||||
typedef void(AuraScript::*AuraEffectCalcAmountFnType)(AuraEffect const *, int32 &, bool &);
|
||||
typedef void(AuraScript::*AuraEffectCalcPeriodicFnType)(AuraEffect const *, bool &, int32 &);
|
||||
typedef void(AuraScript::*AuraEffectCalcSpellModFnType)(AuraEffect const *, SpellModifier *&);
|
||||
|
||||
#define AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
|
||||
typedef void(CLASSNAME::*AuraEffectApplicationModeFnType)(AuraEffect const *, AuraApplication const *, AuraEffectHandleModes mode); \
|
||||
typedef void(CLASSNAME::*AuraEffectPeriodicFnType)(AuraEffect const *, AuraApplication const *); \
|
||||
typedef void(CLASSNAME::*AuraEffectUpdatePeriodicFnType)(AuraEffect *); \
|
||||
typedef void(CLASSNAME::*AuraEffectCalcAmountFnType)(AuraEffect const *, int32 &, bool &); \
|
||||
typedef void(CLASSNAME::*AuraEffectCalcPeriodicFnType)(AuraEffect const *, bool &, int32 &); \
|
||||
typedef void(CLASSNAME::*AuraEffectCalcSpellModFnType)(AuraEffect const *, SpellModifier *&); \
|
||||
|
||||
AURASCRIPT_FUNCTION_TYPE_DEFINES(AuraScript)
|
||||
|
||||
class EffectBase : public _SpellScript::EffectAuraNameCheck, public _SpellScript::EffectHook
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user