2010-10-07 15:54:07 +02:00
/*
2018-01-01 00:40:17 +01:00
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
2010-10-07 15:54:07 +02:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2010-07-24 22:41:42 +02:00
*/
#ifndef __SPELL_SCRIPT_H
#define __SPELL_SCRIPT_H
2017-05-24 21:31:23 +02:00
#include "ObjectGuid.h"
2010-07-25 00:36:32 +02:00
#include "SharedDefines.h"
2010-08-24 00:10:49 +02:00
#include "SpellAuraDefines.h"
2017-05-24 21:31:23 +02:00
#include "Util.h"
#include <memory>
2011-05-26 16:12:33 +02:00
#include <stack>
2010-07-25 00:36:32 +02:00
2010-08-19 14:31:31 +02:00
class Aura ;
2017-05-24 21:31:23 +02:00
class AuraApplication ;
2010-08-24 00:10:49 +02:00
class AuraEffect ;
2010-07-25 00:36:32 +02:00
class Creature ;
2017-05-24 21:31:23 +02:00
class DamageInfo ;
class DispelInfo ;
2010-08-24 00:10:49 +02:00
class DynamicObject ;
2017-05-24 21:31:23 +02:00
class GameObject ;
2010-07-25 00:36:32 +02:00
class Item ;
2017-05-24 21:31:23 +02:00
class ModuleReference ;
class Player ;
class ProcEventInfo ;
class Spell ;
class SpellEffectInfo ;
class SpellInfo ;
class SpellScript ;
class Unit ;
2010-07-25 16:23:57 +02:00
class WorldLocation ;
2010-08-24 00:10:49 +02:00
class WorldObject ;
2017-05-24 21:31:23 +02:00
struct SpellDestination ;
struct SpellModifier ;
struct SpellValue ;
2010-07-24 22:41:42 +02:00
#define SPELL_EFFECT_ANY (uint16)-1
#define SPELL_AURA_ANY (uint16)-1
2010-10-04 17:44:49 +02:00
enum SpellScriptState
{
SPELL_SCRIPT_STATE_NONE = 0 ,
SPELL_SCRIPT_STATE_REGISTRATION ,
SPELL_SCRIPT_STATE_LOADING ,
2012-09-10 13:03:38 +02:00
SPELL_SCRIPT_STATE_UNLOADING
2010-10-04 17:44:49 +02:00
};
#define SPELL_SCRIPT_STATE_END SPELL_SCRIPT_STATE_UNLOADING + 1
2010-07-24 22:41:42 +02:00
// helper class from which SpellScript and SpellAura derive, use these classes instead
2016-03-11 16:37:14 +01:00
class TC_GAME_API _SpellScript
2010-07-24 22:41:42 +02:00
{
// internal use classes & functions
// DO NOT OVERRIDE THESE IN SCRIPTS
protected :
2011-07-26 23:09:28 +02:00
virtual bool _Validate ( SpellInfo const * entry );
2011-04-27 18:58:40 +02:00
2010-10-04 17:44:49 +02:00
public :
2013-12-14 19:36:43 +01:00
_SpellScript () : m_currentScriptState ( SPELL_SCRIPT_STATE_NONE ), m_scriptName ( NULL ), m_scriptSpellId ( 0 ) {}
2013-10-27 22:27:46 +01:00
virtual ~ _SpellScript () { }
2016-11-13 21:44:04 -03:00
void _Register ();
void _Unload ();
void _Init ( std :: string const * scriptname , uint32 spellId );
2011-12-31 13:10:13 +01:00
std :: string const * _GetScriptName () const ;
2011-04-27 18:58:40 +02:00
2010-07-24 22:41:42 +02:00
protected :
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectHook
2010-07-24 22:41:42 +02:00
{
public :
EffectHook ( uint8 _effIndex );
2012-10-24 15:34:23 +02:00
virtual ~ EffectHook () { }
2017-01-04 00:08:52 +01:00
uint32 GetAffectedEffectsMask ( SpellInfo const * spellInfo ) const ;
bool IsEffectAffected ( SpellInfo const * spellInfo , uint8 effIndex ) const ;
virtual bool CheckEffect ( SpellInfo const * spellInfo , uint8 effIndex ) const = 0 ;
std :: string EffIndexToString () const ;
2010-07-24 22:41:42 +02:00
protected :
uint8 effIndex ;
};
2011-04-27 18:58:40 +02:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectNameCheck
2010-07-24 22:41:42 +02:00
{
public :
2012-10-24 15:34:23 +02:00
EffectNameCheck ( uint16 _effName ) { effName = _effName ; }
2017-01-04 00:08:52 +01:00
bool Check ( SpellInfo const * spellInfo , uint8 effIndex ) const ;
std :: string ToString () const ;
2010-07-24 22:41:42 +02:00
private :
uint16 effName ;
};
2011-04-27 18:58:40 +02:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectAuraNameCheck
2010-07-24 22:41:42 +02:00
{
public :
EffectAuraNameCheck ( uint16 _effAurName ) { effAurName = _effAurName ; }
2017-01-04 00:08:52 +01:00
bool Check ( SpellInfo const * spellInfo , uint8 effIndex ) const ;
std :: string ToString () const ;
2010-07-24 22:41:42 +02:00
private :
uint16 effAurName ;
};
2010-10-04 17:44:49 +02:00
uint8 m_currentScriptState ;
2011-04-27 18:58:40 +02:00
std :: string const * m_scriptName ;
2010-10-04 17:44:49 +02:00
uint32 m_scriptSpellId ;
2016-03-11 17:09:26 +01:00
private :
#ifdef TRINITY_API_USE_DYNAMIC_LINKING
// Strong reference to keep the binary code loaded
std :: shared_ptr < ModuleReference > m_moduleReference ;
#endif // #ifndef TRINITY_API_USE_DYNAMIC_LINKING
2010-07-24 22:41:42 +02:00
public :
//
// SpellScript/AuraScript interface base
// these functions are safe to override, see notes below for usage instructions
2010-08-08 19:45:53 +02:00
//
2010-07-24 22:41:42 +02:00
// Function in which handler functions are registered, must be implemented in script
virtual void Register () = 0 ;
// Function called on server startup, if returns false script won't be used in core
// use for: dbc/template data presence/correctness checks
2013-08-18 01:41:10 +02:00
virtual bool Validate ( SpellInfo const * /*spellInfo*/ ) { return true ; }
2010-07-24 22:41:42 +02:00
// Function called when script is created, if returns false script will be unloaded afterwards
// use for: initializing local script variables (DO NOT USE CONSTRUCTOR FOR THIS PURPOSE!)
2011-04-27 18:58:40 +02:00
virtual bool Load () { return true ; }
2010-07-24 22:41:42 +02:00
// Function called when script is destroyed
// use for: deallocating memory allocated by script
2012-10-24 15:34:23 +02:00
virtual void Unload () { }
2017-01-12 23:03:08 +01:00
// Helpers
2017-05-28 16:34:44 +02:00
static bool ValidateSpellInfo ( std :: initializer_list < uint32 > spellIds )
{
return _ValidateSpellInfo ( spellIds . begin (), spellIds . end ());
}
template < class T >
static bool ValidateSpellInfo ( T const & spellIds )
{
return _ValidateSpellInfo ( std :: begin ( spellIds ), std :: end ( spellIds ));
}
private :
static bool _ValidateSpellInfo ( uint32 const * begin , uint32 const * end );
2010-07-24 22:41:42 +02:00
};
2010-10-04 19:12:20 +02:00
// SpellScript interface - enum used for runtime checks of script function calls
enum SpellScriptHookType
{
2011-09-25 13:29:17 +02:00
SPELL_SCRIPT_HOOK_EFFECT_LAUNCH = SPELL_SCRIPT_STATE_END ,
SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET ,
SPELL_SCRIPT_HOOK_EFFECT_HIT ,
SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET ,
2014-12-24 16:40:51 +01:00
SPELL_SCRIPT_HOOK_EFFECT_SUCCESSFUL_DISPEL ,
2010-10-04 19:12:20 +02:00
SPELL_SCRIPT_HOOK_BEFORE_HIT ,
SPELL_SCRIPT_HOOK_HIT ,
SPELL_SCRIPT_HOOK_AFTER_HIT ,
2012-06-30 00:06:17 +02:00
SPELL_SCRIPT_HOOK_OBJECT_AREA_TARGET_SELECT ,
2012-07-03 12:35:06 +02:00
SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT ,
2014-01-23 18:15:59 +01:00
SPELL_SCRIPT_HOOK_DESTINATION_TARGET_SELECT ,
2011-03-04 21:18:38 +01:00
SPELL_SCRIPT_HOOK_CHECK_CAST ,
2011-12-31 13:10:13 +01:00
SPELL_SCRIPT_HOOK_BEFORE_CAST ,
SPELL_SCRIPT_HOOK_ON_CAST ,
2012-09-10 13:03:38 +02:00
SPELL_SCRIPT_HOOK_AFTER_CAST
2010-10-04 19:12:20 +02:00
};
2011-04-27 18:58:40 +02:00
2011-09-25 13:29:17 +02:00
#define HOOK_SPELL_HIT_START SPELL_SCRIPT_HOOK_EFFECT_HIT
2010-10-04 19:12:20 +02:00
#define HOOK_SPELL_HIT_END SPELL_SCRIPT_HOOK_AFTER_HIT + 1
#define HOOK_SPELL_START SPELL_SCRIPT_HOOK_EFFECT
2011-03-04 21:18:38 +01:00
#define HOOK_SPELL_END SPELL_SCRIPT_HOOK_CHECK_CAST + 1
2010-10-04 19:12:20 +02:00
#define HOOK_SPELL_COUNT HOOK_SPELL_END - HOOK_SPELL_START
2016-03-11 16:37:14 +01:00
class TC_GAME_API SpellScript : public _SpellScript
2010-07-24 22:41:42 +02:00
{
// internal use classes & functions
// DO NOT OVERRIDE THESE IN SCRIPTS
public :
2010-10-08 21:33:44 +02:00
#define SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
2011-03-04 21:18:38 +01:00
typedef SpellCastResult(CLASSNAME::*SpellCheckCastFnType)(); \
2010-10-08 21:33:44 +02:00
typedef void(CLASSNAME::*SpellEffectFnType)(SpellEffIndex); \
2016-07-20 09:08:58 +02:00
typedef void(CLASSNAME::*SpellBeforeHitFnType)(SpellMissInfo missInfo); \
2010-10-08 21:33:44 +02:00
typedef void(CLASSNAME::*SpellHitFnType)(); \
2011-12-31 13:10:13 +01:00
typedef void(CLASSNAME::*SpellCastFnType)(); \
2012-06-29 21:53:35 +02:00
typedef void(CLASSNAME::*SpellObjectAreaTargetSelectFnType)(std::list<WorldObject*>&); \
2014-01-23 18:15:59 +01:00
typedef void(CLASSNAME::*SpellObjectTargetSelectFnType)(WorldObject*&); \
typedef void(CLASSNAME::*SpellDestinationTargetSelectFnType)(SpellDestination&);
2010-10-08 21:33:44 +02:00
SPELLSCRIPT_FUNCTION_TYPE_DEFINES ( SpellScript )
2010-08-24 00:10:49 +02:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API CastHandler
2011-12-31 13:10:13 +01:00
{
public :
CastHandler ( SpellCastFnType _pCastHandlerScript );
void Call ( SpellScript * spellScript );
private :
SpellCastFnType pCastHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API CheckCastHandler
2011-03-04 21:18:38 +01:00
{
public :
CheckCastHandler ( SpellCheckCastFnType checkCastHandlerScript );
SpellCastResult Call ( SpellScript * spellScript );
private :
SpellCheckCastFnType _checkCastHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectHandler : public _SpellScript :: EffectNameCheck , public _SpellScript :: EffectHook
2010-07-24 22:41:42 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectHandler ( SpellEffectFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName );
2017-01-04 00:08:52 +01:00
std :: string ToString () const ;
bool CheckEffect ( SpellInfo const * spellInfo , uint8 effIndex ) const override ;
2011-04-27 18:58:40 +02:00
void Call ( SpellScript * spellScript , SpellEffIndex effIndex );
2010-07-24 22:41:42 +02:00
private :
2010-08-24 00:10:49 +02:00
SpellEffectFnType pEffectHandlerScript ;
2010-07-24 22:41:42 +02:00
};
2010-10-08 21:33:44 +02:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API HitHandler
2010-10-08 21:33:44 +02:00
{
public :
HitHandler ( SpellHitFnType _pHitHandlerScript );
2011-04-27 18:58:40 +02:00
void Call ( SpellScript * spellScript );
2010-10-08 21:33:44 +02:00
private :
SpellHitFnType pHitHandlerScript ;
};
2016-07-20 09:08:58 +02:00
class TC_GAME_API BeforeHitHandler
{
public :
BeforeHitHandler ( SpellBeforeHitFnType pBeforeHitHandlerScript );
void Call ( SpellScript * spellScript , SpellMissInfo missInfo );
private :
SpellBeforeHitFnType _pBeforeHitHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API TargetHook : public _SpellScript :: EffectHook
2011-01-21 23:42:51 +01:00
{
public :
2014-01-23 18:15:59 +01:00
TargetHook ( uint8 _effectIndex , uint16 _targetType , bool _area , bool _dest );
2017-01-04 00:08:52 +01:00
bool CheckEffect ( SpellInfo const * spellInfo , uint8 effIndex ) const override ;
std :: string ToString () const ;
2014-03-22 21:39:38 +01:00
uint16 GetTarget () const { return targetType ; }
2012-06-30 00:06:17 +02:00
protected :
uint16 targetType ;
bool area ;
2014-01-23 18:15:59 +01:00
bool dest ;
2012-06-30 00:06:17 +02:00
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API ObjectAreaTargetSelectHandler : public TargetHook
2012-06-30 00:06:17 +02:00
{
public :
ObjectAreaTargetSelectHandler ( SpellObjectAreaTargetSelectFnType _pObjectAreaTargetSelectHandlerScript , uint8 _effIndex , uint16 _targetType );
2012-06-29 21:53:35 +02:00
void Call ( SpellScript * spellScript , std :: list < WorldObject *>& targets );
2011-01-21 23:42:51 +01:00
private :
2012-06-29 21:53:35 +02:00
SpellObjectAreaTargetSelectFnType pObjectAreaTargetSelectHandlerScript ;
2011-01-21 23:42:51 +01:00
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API ObjectTargetSelectHandler : public TargetHook
2012-07-03 12:35:06 +02:00
{
public :
ObjectTargetSelectHandler ( SpellObjectTargetSelectFnType _pObjectTargetSelectHandlerScript , uint8 _effIndex , uint16 _targetType );
2014-01-23 18:15:59 +01:00
void Call ( SpellScript * spellScript , WorldObject *& target );
2012-07-03 12:35:06 +02:00
private :
SpellObjectTargetSelectFnType pObjectTargetSelectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API DestinationTargetSelectHandler : public TargetHook
2014-01-23 18:15:59 +01:00
{
public :
DestinationTargetSelectHandler ( SpellDestinationTargetSelectFnType _DestinationTargetSelectHandlerScript , uint8 _effIndex , uint16 _targetType );
void Call ( SpellScript * spellScript , SpellDestination & target );
private :
SpellDestinationTargetSelectFnType DestinationTargetSelectHandlerScript ;
};
2010-10-08 21:33:44 +02:00
#define SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) \
2013-10-27 22:27:46 +01:00
class CastHandlerFunction : public SpellScript::CastHandler { public: CastHandlerFunction(SpellCastFnType _pCastHandlerScript) : SpellScript::CastHandler((SpellScript::SpellCastFnType)_pCastHandlerScript) { } }; \
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) { } }; \
2016-07-20 09:08:58 +02:00
class BeforeHitHandlerFunction : public SpellScript::BeforeHitHandler { public: BeforeHitHandlerFunction(SpellBeforeHitFnType pBeforeHitHandlerScript) : SpellScript::BeforeHitHandler((SpellScript::SpellBeforeHitFnType)pBeforeHitHandlerScript) { } }; \
2013-10-27 22:27:46 +01:00
class ObjectAreaTargetSelectHandlerFunction : public SpellScript::ObjectAreaTargetSelectHandler { public: ObjectAreaTargetSelectHandlerFunction(SpellObjectAreaTargetSelectFnType _pObjectAreaTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::ObjectAreaTargetSelectHandler((SpellScript::SpellObjectAreaTargetSelectFnType)_pObjectAreaTargetSelectHandlerScript, _effIndex, _targetType) { } }; \
2014-01-23 18:15:59 +01:00
class ObjectTargetSelectHandlerFunction : public SpellScript::ObjectTargetSelectHandler { public: ObjectTargetSelectHandlerFunction(SpellObjectTargetSelectFnType _pObjectTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::ObjectTargetSelectHandler((SpellScript::SpellObjectTargetSelectFnType)_pObjectTargetSelectHandlerScript, _effIndex, _targetType) { } }; \
2014-05-18 12:50:10 +02:00
class DestinationTargetSelectHandlerFunction : public SpellScript::DestinationTargetSelectHandler { public: DestinationTargetSelectHandlerFunction(SpellDestinationTargetSelectFnType _DestinationTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::DestinationTargetSelectHandler((SpellScript::SpellDestinationTargetSelectFnType)_DestinationTargetSelectHandlerScript, _effIndex, _targetType) { } }
2010-10-08 21:33:44 +02:00
#define PrepareSpellScript(CLASSNAME) SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME)
2010-07-24 22:41:42 +02:00
public :
2014-08-09 20:17:40 +01:00
bool _Validate ( SpellInfo const * entry ) override ;
2011-04-27 18:58:40 +02:00
bool _Load ( Spell * spell );
2010-08-19 14:31:31 +02:00
void _InitHit ();
2017-01-04 00:08:52 +01:00
bool _IsEffectPrevented ( SpellEffIndex effIndex ) const { return ( m_hitPreventEffectMask & ( 1 << effIndex )) != 0 ; }
bool _IsDefaultEffectPrevented ( SpellEffIndex effIndex ) const { return ( m_hitPreventDefaultEffectMask & ( 1 << effIndex )) != 0 ; }
2010-10-05 08:17:10 +02:00
void _PrepareScriptCall ( SpellScriptHookType hookType );
void _FinishScriptCall ();
2011-09-25 13:29:17 +02:00
bool IsInCheckCastHook () const ;
bool IsInTargetHook () const ;
bool IsInHitPhase () const ;
bool IsInEffectHook () const ;
2010-07-24 22:41:42 +02:00
private :
2011-04-27 18:58:40 +02:00
Spell * m_spell ;
2017-01-06 17:20:04 +01:00
uint32 m_hitPreventEffectMask ;
uint32 m_hitPreventDefaultEffectMask ;
2010-07-24 22:41:42 +02:00
public :
//
// SpellScript interface
// hooks to which you can attach your functions
2010-08-08 19:45:53 +02:00
//
2011-12-31 13:10:13 +01:00
// example: BeforeCast += SpellCastFn(class::function);
HookList < CastHandler > BeforeCast ;
// example: OnCast += SpellCastFn(class::function);
HookList < CastHandler > OnCast ;
// example: AfterCast += SpellCastFn(class::function);
HookList < CastHandler > AfterCast ;
#define SpellCastFn(F) CastHandlerFunction(&F)
2011-03-04 21:18:38 +01:00
// example: OnCheckCast += SpellCheckCastFn();
// where function is SpellCastResult function()
HookList < CheckCastHandler > OnCheckCast ;
#define SpellCheckCastFn(F) CheckCastHandlerFunction(&F)
2011-09-25 13:29:17 +02:00
// example: OnEffect**** += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier);
2010-08-24 00:10:49 +02:00
// where function is void function(SpellEffIndex effIndex)
2011-09-25 13:29:17 +02:00
HookList < EffectHandler > OnEffectLaunch ;
HookList < EffectHandler > OnEffectLaunchTarget ;
HookList < EffectHandler > OnEffectHit ;
HookList < EffectHandler > OnEffectHitTarget ;
2014-12-24 16:40:51 +01:00
HookList < EffectHandler > OnEffectSuccessfulDispel ;
2010-10-08 21:33:44 +02:00
#define SpellEffectFn(F, I, N) EffectHandlerFunction(&F, I, N)
2010-08-24 00:10:49 +02:00
2016-07-20 09:08:58 +02:00
// example: BeforeHit += BeforeSpellHitFn(class::function);
// where function is void function(SpellMissInfo missInfo)
HookList < BeforeHitHandler > BeforeHit ;
#define BeforeSpellHitFn(F) BeforeHitHandlerFunction(&F)
2010-08-24 00:10:49 +02:00
// example: OnHit += SpellHitFn(class::function);
2010-08-21 20:18:54 +02:00
HookList < HitHandler > OnHit ;
2010-08-24 00:10:49 +02:00
// example: AfterHit += SpellHitFn(class::function);
2010-08-21 20:18:54 +02:00
HookList < HitHandler > AfterHit ;
2010-08-24 00:10:49 +02:00
// where function is: void function()
2010-10-08 21:33:44 +02:00
#define SpellHitFn(F) HitHandlerFunction(&F)
2010-08-21 20:18:54 +02:00
2012-06-30 00:06:17 +02:00
// example: OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
// where function is void function(std::list<WorldObject*>& targets)
2012-06-29 21:53:35 +02:00
HookList < ObjectAreaTargetSelectHandler > OnObjectAreaTargetSelect ;
#define SpellObjectAreaTargetSelectFn(F, I, N) ObjectAreaTargetSelectHandlerFunction(&F, I, N)
2011-01-21 23:42:51 +01:00
2012-07-03 12:35:06 +02:00
// example: OnObjectTargetSelect += SpellObjectTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
// where function is void function(WorldObject*& target)
HookList < ObjectTargetSelectHandler > OnObjectTargetSelect ;
#define SpellObjectTargetSelectFn(F, I, N) ObjectTargetSelectHandlerFunction(&F, I, N)
2014-01-23 18:15:59 +01:00
// example: OnDestinationTargetSelect += SpellDestinationTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
// where function is void function(SpellDestination& target)
HookList < DestinationTargetSelectHandler > OnDestinationTargetSelect ;
#define SpellDestinationTargetSelectFn(F, I, N) DestinationTargetSelectHandlerFunction(&F, I, N)
2010-08-21 20:18:54 +02:00
// hooks are executed in following order, at specified event of spell:
2011-12-31 13:10:13 +01:00
// 1. BeforeCast - executed when spell preparation is finished (when cast bar becomes full) before cast is handled
// 2. OnCheckCast - allows to override result of CheckCast function
2012-06-30 00:06:17 +02:00
// 3a. OnObjectAreaTargetSelect - executed just before adding selected targets to final target list (for area targets)
2012-07-03 12:35:06 +02:00
// 3b. OnObjectTargetSelect - executed just before adding selected target to final target list (for single unit targets)
2014-01-23 18:15:59 +01:00
// 3c. OnDestinationTargetSelect - executed just before adding selected target to final target list (for destination targets)
2011-12-31 13:10:13 +01:00
// 4. OnCast - executed just before spell is launched (creates missile) or executed
// 5. AfterCast - executed after spell missile is launched and immediate spell actions are done
// 6. OnEffectLaunch - executed just before specified effect handler call - when spell missile is launched
// 7. OnEffectLaunchTarget - executed just before specified effect handler call - when spell missile is launched - called for each target from spell target map
// 8. OnEffectHit - executed just before specified effect handler call - when spell missile hits dest
// 9. BeforeHit - executed just before spell hits a target - called for each target from spell target map
// 10. OnEffectHitTarget - executed just before specified effect handler call - called for each target from spell target map
// 11. OnHit - executed just before spell deals damage and procs auras - when spell hits target - called for each target from spell target map
// 12. AfterHit - executed just after spell finishes all it's jobs for target - called for each target from spell target map
2010-07-24 22:41:42 +02:00
2014-12-24 16:40:51 +01:00
// this hook is only executed after a successful dispel of any aura
// OnEffectSuccessfulDispel - executed just after effect successfully dispelled aura(s)
2010-07-25 16:23:57 +02:00
//
2010-07-24 22:41:42 +02:00
// methods allowing interaction with Spell object
2010-07-25 16:23:57 +02:00
//
// methods useable during all spell handling phases
2017-01-04 00:08:52 +01:00
Unit * GetCaster () const ;
Unit * GetOriginalCaster () const ;
SpellInfo const * GetSpellInfo () const ;
SpellValue const * GetSpellValue () const ;
SpellEffectInfo const * GetEffectInfo ( SpellEffIndex effIndex ) const ;
2010-07-25 02:05:12 +02:00
2012-04-28 14:53:40 +02:00
// methods useable after spell is prepared
// accessors to the explicit targets of the spell
// explicit target - target selected by caster (player, game client, or script - DoCast(explicitTarget, ...), required for spell to be cast
// examples:
// -shadowstep - explicit target is the unit you want to go behind of
// -chain heal - explicit target is the unit to be healed first
// -holy nova/arcane explosion - explicit target = NULL because target you are selecting doesn't affect how spell targets are selected
2012-06-29 21:53:35 +02:00
// you can determine if spell requires explicit targets by dbc columns:
2012-04-28 14:53:40 +02:00
// - Targets - mask of explicit target types
// - ImplicitTargetXX set to TARGET_XXX_TARGET_YYY, _TARGET_ here means that explicit target is used by the effect, so spell needs one too
2010-10-04 20:32:10 +02:00
// returns: WorldLocation which was selected as a spell destination or NULL
2017-01-04 00:08:52 +01:00
WorldLocation const * GetExplTargetDest () const ;
2011-06-23 13:28:52 +02:00
2012-04-28 14:53:40 +02:00
void SetExplTargetDest ( WorldLocation & loc );
2010-10-04 20:32:10 +02:00
2012-04-28 14:53:40 +02:00
// returns: WorldObject which was selected as an explicit spell target or NULL if there's no target
2017-01-04 00:08:52 +01:00
WorldObject * GetExplTargetWorldObject () const ;
2010-10-04 20:32:10 +02:00
2012-04-28 14:53:40 +02:00
// returns: Unit which was selected as an explicit spell target or NULL if there's no target
2017-01-04 00:08:52 +01:00
Unit * GetExplTargetUnit () const ;
2010-10-04 20:32:10 +02:00
2012-04-28 14:53:40 +02:00
// returns: GameObject which was selected as an explicit spell target or NULL if there's no target
2017-01-04 00:08:52 +01:00
GameObject * GetExplTargetGObj () const ;
2010-07-25 16:23:57 +02:00
2012-04-28 14:53:40 +02:00
// returns: Item which was selected as an explicit spell target or NULL if there's no target
2017-01-04 00:08:52 +01:00
Item * GetExplTargetItem () const ;
2010-08-08 19:45:53 +02:00
2012-04-28 14:53:40 +02:00
// methods useable only during spell hit on target, or during spell launch on target:
2010-07-25 02:05:12 +02:00
// returns: target of current effect if it was Unit otherwise NULL
2017-01-04 00:08:52 +01:00
Unit * GetHitUnit () const ;
2010-07-25 02:05:12 +02:00
// returns: target of current effect if it was Creature otherwise NULL
2017-01-04 00:08:52 +01:00
Creature * GetHitCreature () const ;
2010-07-25 02:05:12 +02:00
// returns: target of current effect if it was Player otherwise NULL
2017-01-04 00:08:52 +01:00
Player * GetHitPlayer () const ;
2010-07-25 02:05:12 +02:00
// returns: target of current effect if it was Item otherwise NULL
2017-01-04 00:08:52 +01:00
Item * GetHitItem () const ;
2010-07-25 02:05:12 +02:00
// returns: target of current effect if it was GameObject otherwise NULL
2017-01-04 00:08:52 +01:00
GameObject * GetHitGObj () const ;
2012-03-03 00:19:00 +01:00
// returns: destination of current effect
2017-01-04 00:08:52 +01:00
WorldLocation * GetHitDest () const ;
2010-07-25 16:23:57 +02:00
// setter/getter for for damage done by spell to target of spell hit
2011-08-20 00:45:34 +02:00
// returns damage calculated before hit, and real dmg done after hit
2017-01-04 00:08:52 +01:00
int32 GetHitDamage () const ;
2010-07-25 16:23:57 +02:00
void SetHitDamage ( int32 damage );
2011-04-27 18:58:40 +02:00
void PreventHitDamage () { SetHitDamage ( 0 ); }
2010-07-25 16:23:57 +02:00
// setter/getter for for heal done by spell to target of spell hit
2011-08-20 00:45:34 +02:00
// returns healing calculated before hit, and real dmg done after hit
2017-01-04 00:08:52 +01:00
int32 GetHitHeal () const ;
2010-07-25 16:23:57 +02:00
void SetHitHeal ( int32 heal );
2011-04-27 18:58:40 +02:00
void PreventHitHeal () { SetHitHeal ( 0 ); }
2017-01-04 00:08:52 +01:00
Spell * GetSpell () const { return m_spell ; }
2010-08-19 14:31:31 +02:00
// returns current spell hit target aura
2017-01-04 00:08:52 +01:00
Aura * GetHitAura () const ;
2010-08-19 14:31:31 +02:00
// prevents applying aura on current spell hit target
void PreventHitAura ();
// prevents effect execution on current spell hit target
// including other effect/hit scripts
// will not work on aura/damage/heal
// will not work if effects were already handled
void PreventHitEffect ( SpellEffIndex effIndex );
// prevents default effect execution on current spell hit target
// will not work on aura/damage/heal effects
// will not work if effects were already handled
void PreventHitDefaultEffect ( SpellEffIndex effIndex );
2010-07-25 16:23:57 +02:00
2014-12-29 01:00:16 +01:00
// method available only in EffectHandler method
SpellEffectInfo const * GetEffectInfo () const ;
2014-01-30 02:40:12 +01:00
int32 GetEffectValue () const ;
2014-01-31 10:37:55 +01:00
void SetEffectValue ( int32 value );
2010-08-18 00:20:23 +06:00
// returns: cast item if present.
2017-01-04 00:08:52 +01:00
Item * GetCastItem () const ;
2010-08-18 00:20:23 +06:00
// Creates item. Calls Spell::DoCreateItem method.
void CreateItem ( uint32 effIndex , uint32 itemId );
2011-01-22 17:21:24 +01:00
2011-08-06 19:39:45 +02:00
// Returns SpellInfo from the spell that triggered the current one
2017-01-04 00:08:52 +01:00
SpellInfo const * GetTriggeringSpell () const ;
2011-08-06 19:39:45 +02:00
2011-01-22 17:21:24 +01:00
// finishes spellcast prematurely with selected error message
2016-11-13 22:15:03 -03:00
void FinishCast ( SpellCastResult result , uint32 * param1 = nullptr , uint32 * param2 = nullptr );
2011-03-04 21:18:38 +01:00
void SetCustomCastResultMessage ( SpellCustomErrors result );
2010-07-24 22:41:42 +02:00
};
2010-08-24 00:10:49 +02:00
2010-10-04 19:12:20 +02:00
// AuraScript interface - enum used for runtime checks of script function calls
2010-10-04 17:44:49 +02:00
enum AuraScriptHookType
{
AURA_SCRIPT_HOOK_EFFECT_APPLY = SPELL_SCRIPT_STATE_END ,
2011-05-26 16:12:33 +02:00
AURA_SCRIPT_HOOK_EFFECT_AFTER_APPLY ,
2010-10-04 17:44:49 +02:00
AURA_SCRIPT_HOOK_EFFECT_REMOVE ,
2011-05-26 16:12:33 +02:00
AURA_SCRIPT_HOOK_EFFECT_AFTER_REMOVE ,
2010-10-04 17:44:49 +02:00
AURA_SCRIPT_HOOK_EFFECT_PERIODIC ,
AURA_SCRIPT_HOOK_EFFECT_UPDATE_PERIODIC ,
AURA_SCRIPT_HOOK_EFFECT_CALC_AMOUNT ,
AURA_SCRIPT_HOOK_EFFECT_CALC_PERIODIC ,
AURA_SCRIPT_HOOK_EFFECT_CALC_SPELLMOD ,
2010-12-27 20:14:54 +01:00
AURA_SCRIPT_HOOK_EFFECT_ABSORB ,
2010-12-30 02:03:46 +01:00
AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB ,
2010-12-30 19:05:19 +01:00
AURA_SCRIPT_HOOK_EFFECT_MANASHIELD ,
AURA_SCRIPT_HOOK_EFFECT_AFTER_MANASHIELD ,
2012-09-18 23:19:31 +03:00
AURA_SCRIPT_HOOK_EFFECT_SPLIT ,
2011-05-31 20:02:55 +02:00
AURA_SCRIPT_HOOK_CHECK_AREA_TARGET ,
2012-02-04 13:32:40 +01:00
AURA_SCRIPT_HOOK_DISPEL ,
2013-01-11 01:21:44 +01:00
AURA_SCRIPT_HOOK_AFTER_DISPEL ,
// Spell Proc Hooks
AURA_SCRIPT_HOOK_CHECK_PROC ,
2017-08-13 12:03:43 +02:00
AURA_SCRIPT_HOOK_CHECK_EFFECT_PROC ,
2013-01-11 01:21:44 +01:00
AURA_SCRIPT_HOOK_PREPARE_PROC ,
AURA_SCRIPT_HOOK_PROC ,
AURA_SCRIPT_HOOK_EFFECT_PROC ,
AURA_SCRIPT_HOOK_EFFECT_AFTER_PROC ,
AURA_SCRIPT_HOOK_AFTER_PROC ,
2010-10-04 17:44:49 +02:00
/*AURA_SCRIPT_HOOK_APPLY,
2011-04-29 20:47:02 +02:00
AURA_SCRIPT_HOOK_REMOVE, */
2010-10-04 17:44:49 +02:00
};
2013-01-11 01:21:44 +01:00
/*
2010-10-04 17:44:49 +02:00
#define HOOK_AURA_EFFECT_START HOOK_AURA_EFFECT_APPLY
#define HOOK_AURA_EFFECT_END HOOK_AURA_EFFECT_CALC_SPELLMOD + 1
#define HOOK_AURA_EFFECT_COUNT HOOK_AURA_EFFECT_END - HOOK_AURA_EFFECT_START
2013-01-11 01:21:44 +01:00
*/
2016-03-11 16:37:14 +01:00
class TC_GAME_API AuraScript : public _SpellScript
2010-08-24 00:10:49 +02:00
{
// internal use classes & functions
// DO NOT OVERRIDE THESE IN SCRIPTS
public :
2010-10-08 21:33:44 +02:00
#define AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
2011-06-11 22:35:29 +02:00
typedef bool(CLASSNAME::*AuraCheckAreaTargetFnType)(Unit* target); \
2012-02-04 13:32:40 +01:00
typedef void(CLASSNAME::*AuraDispelFnType)(DispelInfo* dispelInfo); \
2011-09-29 12:43:05 +02:00
typedef void(CLASSNAME::*AuraEffectApplicationModeFnType)(AuraEffect const*, AuraEffectHandleModes); \
2011-09-29 09:32:55 +02:00
typedef void(CLASSNAME::*AuraEffectPeriodicFnType)(AuraEffect const*); \
typedef void(CLASSNAME::*AuraEffectUpdatePeriodicFnType)(AuraEffect*); \
2011-09-29 12:43:05 +02:00
typedef void(CLASSNAME::*AuraEffectCalcAmountFnType)(AuraEffect const*, int32 &, bool &); \
typedef void(CLASSNAME::*AuraEffectCalcPeriodicFnType)(AuraEffect const*, bool &, int32 &); \
typedef void(CLASSNAME::*AuraEffectCalcSpellModFnType)(AuraEffect const*, SpellModifier* &); \
typedef void(CLASSNAME::*AuraEffectAbsorbFnType)(AuraEffect*, DamageInfo &, uint32 &); \
2012-09-18 23:19:31 +03:00
typedef void(CLASSNAME::*AuraEffectSplitFnType)(AuraEffect*, DamageInfo &, uint32 &); \
2013-01-11 01:21:44 +01:00
typedef bool(CLASSNAME::*AuraCheckProcFnType)(ProcEventInfo&); \
2017-08-13 12:03:43 +02:00
typedef bool(CLASSNAME::*AuraCheckEffectProcFnType)(AuraEffect const*, ProcEventInfo&); \
2013-01-11 01:21:44 +01:00
typedef void(CLASSNAME::*AuraProcFnType)(ProcEventInfo&); \
typedef void(CLASSNAME::*AuraEffectProcFnType)(AuraEffect const*, ProcEventInfo&); \
2010-10-08 21:33:44 +02:00
AURASCRIPT_FUNCTION_TYPE_DEFINES ( AuraScript )
2010-08-24 00:10:49 +02:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API CheckAreaTargetHandler
2011-05-31 20:02:55 +02:00
{
public :
CheckAreaTargetHandler ( AuraCheckAreaTargetFnType pHandlerScript );
2011-06-11 22:35:29 +02:00
bool Call ( AuraScript * auraScript , Unit * target );
2011-05-31 20:02:55 +02:00
private :
AuraCheckAreaTargetFnType pHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API AuraDispelHandler
2012-02-04 13:32:40 +01:00
{
public :
AuraDispelHandler ( AuraDispelFnType pHandlerScript );
void Call ( AuraScript * auraScript , DispelInfo * dispelInfo );
private :
AuraDispelFnType pHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectBase : public _SpellScript :: EffectAuraNameCheck , public _SpellScript :: EffectHook
2010-08-24 00:10:49 +02:00
{
public :
EffectBase ( uint8 _effIndex , uint16 _effName );
2017-01-04 00:08:52 +01:00
std :: string ToString () const ;
bool CheckEffect ( SpellInfo const * spellInfo , uint8 effIndex ) const override ;
2010-08-24 00:10:49 +02:00
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectPeriodicHandler : public EffectBase
2010-08-24 00:10:49 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectPeriodicHandler ( AuraEffectPeriodicFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect const * _aurEff );
2010-08-24 00:10:49 +02:00
private :
AuraEffectPeriodicFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectUpdatePeriodicHandler : public EffectBase
2010-08-24 00:10:49 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectUpdatePeriodicHandler ( AuraEffectUpdatePeriodicFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect * aurEff );
2010-08-24 00:10:49 +02:00
private :
AuraEffectUpdatePeriodicFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectCalcAmountHandler : public EffectBase
2010-08-24 00:10:49 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectCalcAmountHandler ( AuraEffectCalcAmountFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect const * aurEff , int32 & amount , bool & canBeRecalculated );
2010-08-24 00:10:49 +02:00
private :
AuraEffectCalcAmountFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectCalcPeriodicHandler : public EffectBase
2010-08-24 00:10:49 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectCalcPeriodicHandler ( AuraEffectCalcPeriodicFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect const * aurEff , bool & isPeriodic , int32 & periodicTimer );
2010-08-24 00:10:49 +02:00
private :
AuraEffectCalcPeriodicFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectCalcSpellModHandler : public EffectBase
2010-08-24 00:10:49 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectCalcSpellModHandler ( AuraEffectCalcSpellModFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect const * aurEff , SpellModifier * & spellMod );
2010-08-24 00:10:49 +02:00
private :
AuraEffectCalcSpellModFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectApplyHandler : public EffectBase
2010-08-24 00:10:49 +02:00
{
public :
2011-04-29 20:47:02 +02:00
EffectApplyHandler ( AuraEffectApplicationModeFnType _pEffectHandlerScript , uint8 _effIndex , uint16 _effName , AuraEffectHandleModes _mode );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect const * _aurEff , AuraEffectHandleModes _mode );
2010-08-24 00:10:49 +02:00
private :
AuraEffectApplicationModeFnType pEffectHandlerScript ;
AuraEffectHandleModes mode ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectAbsorbHandler : public EffectBase
2010-12-27 20:14:54 +01:00
{
public :
EffectAbsorbHandler ( AuraEffectAbsorbFnType _pEffectHandlerScript , uint8 _effIndex );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect * aurEff , DamageInfo & dmgInfo , uint32 & absorbAmount );
2010-12-27 20:14:54 +01:00
private :
AuraEffectAbsorbFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectManaShieldHandler : public EffectBase
2010-12-30 19:05:19 +01:00
{
public :
EffectManaShieldHandler ( AuraEffectAbsorbFnType _pEffectHandlerScript , uint8 _effIndex );
2011-09-15 14:08:17 +02:00
void Call ( AuraScript * auraScript , AuraEffect * aurEff , DamageInfo & dmgInfo , uint32 & absorbAmount );
2010-12-30 19:05:19 +01:00
private :
AuraEffectAbsorbFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectSplitHandler : public EffectBase
2012-09-18 23:19:31 +03:00
{
public :
EffectSplitHandler ( AuraEffectSplitFnType _pEffectHandlerScript , uint8 _effIndex );
void Call ( AuraScript * auraScript , AuraEffect * aurEff , DamageInfo & dmgInfo , uint32 & splitAmount );
private :
AuraEffectSplitFnType pEffectHandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API CheckProcHandler
2013-01-11 01:21:44 +01:00
{
public :
CheckProcHandler ( AuraCheckProcFnType handlerScript );
bool Call ( AuraScript * auraScript , ProcEventInfo & eventInfo );
private :
AuraCheckProcFnType _HandlerScript ;
};
2017-08-13 12:03:43 +02:00
class TC_GAME_API CheckEffectProcHandler : public EffectBase
{
public :
CheckEffectProcHandler ( AuraCheckEffectProcFnType handlerScript , uint8 effIndex , uint16 effName );
bool Call ( AuraScript * auraScript , AuraEffect const * aurEff , ProcEventInfo & eventInfo );
private :
AuraCheckEffectProcFnType _HandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API AuraProcHandler
2013-01-11 01:21:44 +01:00
{
public :
AuraProcHandler ( AuraProcFnType handlerScript );
void Call ( AuraScript * auraScript , ProcEventInfo & eventInfo );
private :
AuraProcFnType _HandlerScript ;
};
2016-03-11 16:37:14 +01:00
class TC_GAME_API EffectProcHandler : public EffectBase
2013-01-11 01:21:44 +01:00
{
public :
EffectProcHandler ( AuraEffectProcFnType effectHandlerScript , uint8 effIndex , uint16 effName );
void Call ( AuraScript * auraScript , AuraEffect const * aurEff , ProcEventInfo & eventInfo );
private :
AuraEffectProcFnType _EffectHandlerScript ;
};
2010-10-08 22:33:21 +02:00
#define AURASCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) \
2013-10-27 22:27:46 +01:00
class CheckAreaTargetFunction : public AuraScript::CheckAreaTargetHandler { public: CheckAreaTargetFunction(AuraCheckAreaTargetFnType _pHandlerScript) : AuraScript::CheckAreaTargetHandler((AuraScript::AuraCheckAreaTargetFnType)_pHandlerScript) { } }; \
class AuraDispelFunction : public AuraScript::AuraDispelHandler { public: AuraDispelFunction(AuraDispelFnType _pHandlerScript) : AuraScript::AuraDispelHandler((AuraScript::AuraDispelFnType)_pHandlerScript) { } }; \
class EffectPeriodicHandlerFunction : public AuraScript::EffectPeriodicHandler { public: EffectPeriodicHandlerFunction(AuraEffectPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectPeriodicHandler((AuraScript::AuraEffectPeriodicFnType)_pEffectHandlerScript, _effIndex, _effName) { } }; \
class EffectUpdatePeriodicHandlerFunction : public AuraScript::EffectUpdatePeriodicHandler { public: EffectUpdatePeriodicHandlerFunction(AuraEffectUpdatePeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectUpdatePeriodicHandler((AuraScript::AuraEffectUpdatePeriodicFnType)_pEffectHandlerScript, _effIndex, _effName) { } }; \
class EffectCalcAmountHandlerFunction : public AuraScript::EffectCalcAmountHandler { public: EffectCalcAmountHandlerFunction(AuraEffectCalcAmountFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectCalcAmountHandler((AuraScript::AuraEffectCalcAmountFnType)_pEffectHandlerScript, _effIndex, _effName) { } }; \
class EffectCalcPeriodicHandlerFunction : public AuraScript::EffectCalcPeriodicHandler { public: EffectCalcPeriodicHandlerFunction(AuraEffectCalcPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectCalcPeriodicHandler((AuraScript::AuraEffectCalcPeriodicFnType)_pEffectHandlerScript, _effIndex, _effName) { } }; \
class EffectCalcSpellModHandlerFunction : public AuraScript::EffectCalcSpellModHandler { public: EffectCalcSpellModHandlerFunction(AuraEffectCalcSpellModFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectCalcSpellModHandler((AuraScript::AuraEffectCalcSpellModFnType)_pEffectHandlerScript, _effIndex, _effName) { } }; \
class EffectApplyHandlerFunction : public AuraScript::EffectApplyHandler { public: EffectApplyHandlerFunction(AuraEffectApplicationModeFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName, AuraEffectHandleModes _mode) : AuraScript::EffectApplyHandler((AuraScript::AuraEffectApplicationModeFnType)_pEffectHandlerScript, _effIndex, _effName, _mode) { } }; \
class EffectAbsorbFunction : public AuraScript::EffectAbsorbHandler { public: EffectAbsorbFunction(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex) : AuraScript::EffectAbsorbHandler((AuraScript::AuraEffectAbsorbFnType)_pEffectHandlerScript, _effIndex) { } }; \
class EffectManaShieldFunction : public AuraScript::EffectManaShieldHandler { public: EffectManaShieldFunction(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex) : AuraScript::EffectManaShieldHandler((AuraScript::AuraEffectAbsorbFnType)_pEffectHandlerScript, _effIndex) { } }; \
class EffectSplitFunction : public AuraScript::EffectSplitHandler { public: EffectSplitFunction(AuraEffectSplitFnType _pEffectHandlerScript, uint8 _effIndex) : AuraScript::EffectSplitHandler((AuraScript::AuraEffectSplitFnType)_pEffectHandlerScript, _effIndex) { } }; \
class CheckProcHandlerFunction : public AuraScript::CheckProcHandler { public: CheckProcHandlerFunction(AuraCheckProcFnType handlerScript) : AuraScript::CheckProcHandler((AuraScript::AuraCheckProcFnType)handlerScript) { } }; \
2017-08-13 12:03:43 +02:00
class CheckEffectProcHandlerFunction : public AuraScript::CheckEffectProcHandler { public: CheckEffectProcHandlerFunction(AuraCheckEffectProcFnType handlerScript, uint8 effIndex, uint16 effName) : AuraScript::CheckEffectProcHandler((AuraScript::AuraCheckEffectProcFnType)handlerScript, effIndex, effName) { } }; \
2013-10-27 22:27:46 +01:00
class AuraProcHandlerFunction : public AuraScript::AuraProcHandler { public: AuraProcHandlerFunction(AuraProcFnType handlerScript) : AuraScript::AuraProcHandler((AuraScript::AuraProcFnType)handlerScript) { } }; \
2014-05-18 12:50:10 +02:00
class EffectProcHandlerFunction : public AuraScript::EffectProcHandler { public: EffectProcHandlerFunction(AuraEffectProcFnType effectHandlerScript, uint8 effIndex, uint16 effName) : AuraScript::EffectProcHandler((AuraScript::AuraEffectProcFnType)effectHandlerScript, effIndex, effName) { } }
2010-10-08 22:33:21 +02:00
#define PrepareAuraScript(CLASSNAME) AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) AURASCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME)
2010-08-24 00:10:49 +02:00
public :
2011-05-26 16:12:33 +02:00
AuraScript () : _SpellScript (), m_aura ( NULL ), m_auraApplication ( NULL ), m_defaultActionPrevented ( false )
2013-10-27 22:27:46 +01:00
{ }
2014-08-09 20:17:40 +01:00
bool _Validate ( SpellInfo const * entry ) override ;
2011-09-15 14:08:17 +02:00
bool _Load ( Aura * aura );
2011-06-11 22:35:29 +02:00
void _PrepareScriptCall ( AuraScriptHookType hookType , AuraApplication const * aurApp = NULL );
2010-10-04 17:44:49 +02:00
void _FinishScriptCall ();
2017-01-04 00:08:52 +01:00
bool _IsDefaultActionPrevented () const ;
2010-08-24 00:10:49 +02:00
private :
2011-09-15 14:08:17 +02:00
Aura * m_aura ;
2011-06-11 22:35:29 +02:00
AuraApplication const * m_auraApplication ;
2010-10-04 17:44:49 +02:00
bool m_defaultActionPrevented ;
2011-05-26 16:12:33 +02:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API ScriptStateStore
2011-05-26 16:12:33 +02:00
{
public :
2011-06-11 22:35:29 +02:00
AuraApplication const * _auraApplication ;
2012-10-07 01:31:43 +02:00
uint8 _currentScriptState ;
2011-05-26 16:12:33 +02:00
bool _defaultActionPrevented ;
2011-06-11 22:35:29 +02:00
ScriptStateStore ( uint8 currentScriptState , AuraApplication const * auraApplication , bool defaultActionPrevented )
2012-10-17 14:19:59 +02:00
: _auraApplication ( auraApplication ), _currentScriptState ( currentScriptState ), _defaultActionPrevented ( defaultActionPrevented )
2013-10-27 22:27:46 +01:00
{ }
2011-05-26 16:12:33 +02:00
};
typedef std :: stack < ScriptStateStore > ScriptStateStack ;
ScriptStateStack m_scriptStates ;
2011-06-18 19:51:28 +02:00
2010-08-24 00:10:49 +02:00
public :
//
// AuraScript interface
// hooks to which you can attach your functions
//
2011-05-31 20:02:55 +02:00
// executed when area aura checks if it can be applied on target
// example: OnEffectApply += AuraEffectApplyFn(class::function);
2011-06-11 22:35:29 +02:00
// where function is: bool function (Unit* target);
2011-05-31 20:02:55 +02:00
HookList < CheckAreaTargetHandler > DoCheckAreaTarget ;
#define AuraCheckAreaTargetFn(F) CheckAreaTargetFunction(&F)
2012-02-04 13:32:40 +01:00
// executed when aura is dispelled by a unit
// example: OnDispel += AuraDispelFn(class::function);
// where function is: void function (DispelInfo* dispelInfo);
HookList < AuraDispelHandler > OnDispel ;
// executed after aura is dispelled by a unit
// example: AfterDispel += AuraDispelFn(class::function);
// where function is: void function (DispelInfo* dispelInfo);
HookList < AuraDispelHandler > AfterDispel ;
#define AuraDispelFn(F) AuraDispelFunction(&F)
2011-05-25 15:13:55 +02:00
// executed when aura effect is applied with specified mode to target
2011-05-25 17:13:32 +02:00
// should be used when when effect handler preventing/replacing is needed, do not use this hook for triggering spellcasts/removing auras etc - may be unsafe
2010-08-24 00:10:49 +02:00
// example: OnEffectApply += AuraEffectApplyFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect const* aurEff, AuraEffectHandleModes mode);
2010-08-24 00:10:49 +02:00
HookList < EffectApplyHandler > OnEffectApply ;
2011-05-25 17:13:32 +02:00
// executed after aura effect is applied with specified mode to target
// example: AfterEffectApply += AuraEffectApplyFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
// where function is: void function (AuraEffect const* aurEff, AuraEffectHandleModes mode);
HookList < EffectApplyHandler > AfterEffectApply ;
2010-12-27 20:14:54 +01:00
#define AuraEffectApplyFn(F, I, N, M) EffectApplyHandlerFunction(&F, I, N, M)
2010-08-24 00:10:49 +02:00
2011-05-25 17:13:32 +02:00
// executed after aura effect is removed with specified mode from target
// should be used when when effect handler preventing/replacing is needed, do not use this hook for triggering spellcasts/removing auras etc - may be unsafe
2010-08-24 00:10:49 +02:00
// example: OnEffectRemove += AuraEffectRemoveFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect const* aurEff, AuraEffectHandleModes mode);
2010-08-24 00:10:49 +02:00
HookList < EffectApplyHandler > OnEffectRemove ;
2011-05-25 17:13:32 +02:00
// executed when aura effect is removed with specified mode from target
// example: AfterEffectRemove += AuraEffectRemoveFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
// where function is: void function (AuraEffect const* aurEff, AuraEffectHandleModes mode);
HookList < EffectApplyHandler > AfterEffectRemove ;
2010-12-27 20:14:54 +01:00
#define AuraEffectRemoveFn(F, I, N, M) EffectApplyHandlerFunction(&F, I, N, M)
2010-08-24 00:10:49 +02:00
// executed when periodic aura effect ticks on target
// example: OnEffectPeriodic += AuraEffectPeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect const* aurEff);
2010-08-24 00:10:49 +02:00
HookList < EffectPeriodicHandler > OnEffectPeriodic ;
2010-12-27 20:14:54 +01:00
#define AuraEffectPeriodicFn(F, I, N) EffectPeriodicHandlerFunction(&F, I, N)
2010-08-24 00:10:49 +02:00
// executed when periodic aura effect is updated
// example: OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect* aurEff);
2010-08-24 00:10:49 +02:00
HookList < EffectUpdatePeriodicHandler > OnEffectUpdatePeriodic ;
2010-12-27 20:14:54 +01:00
#define AuraEffectUpdatePeriodicFn(F, I, N) EffectUpdatePeriodicHandlerFunction(&F, I, N)
2010-08-24 00:10:49 +02:00
// executed when aura effect calculates amount
2010-12-27 20:14:54 +01:00
// example: DoEffectCalcAmount += AuraEffectCalcAmounFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect* aurEff, int32& amount, bool& canBeRecalculated);
2010-12-27 20:14:54 +01:00
HookList < EffectCalcAmountHandler > DoEffectCalcAmount ;
#define AuraEffectCalcAmountFn(F, I, N) EffectCalcAmountHandlerFunction(&F, I, N)
2010-08-24 00:10:49 +02:00
// executed when aura effect calculates periodic data
2010-12-27 20:14:54 +01:00
// example: DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect const* aurEff, bool& isPeriodic, int32& amplitude);
2010-12-27 20:14:54 +01:00
HookList < EffectCalcPeriodicHandler > DoEffectCalcPeriodic ;
#define AuraEffectCalcPeriodicFn(F, I, N) EffectCalcPeriodicHandlerFunction(&F, I, N)
2010-08-24 00:10:49 +02:00
// executed when aura effect calculates spellmod
2010-12-27 20:14:54 +01:00
// example: DoEffectCalcSpellMod += AuraEffectCalcSpellModFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect const* aurEff, SpellModifier*& spellMod);
2010-12-27 20:14:54 +01:00
HookList < EffectCalcSpellModHandler > DoEffectCalcSpellMod ;
#define AuraEffectCalcSpellModFn(F, I, N) EffectCalcSpellModHandlerFunction(&F, I, N)
// executed when absorb aura effect is going to reduce damage
// example: OnEffectAbsorb += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
2017-08-27 11:28:08 +02:00
// where function is: void function (AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
2010-12-27 20:14:54 +01:00
HookList < EffectAbsorbHandler > OnEffectAbsorb ;
#define AuraEffectAbsorbFn(F, I) EffectAbsorbFunction(&F, I)
2010-12-30 19:05:19 +01:00
// executed after absorb aura effect reduced damage to target - absorbAmount is real amount absorbed by aura
// example: AfterEffectAbsorb += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
2010-12-30 02:03:46 +01:00
HookList < EffectAbsorbHandler > AfterEffectAbsorb ;
2010-12-30 19:05:19 +01:00
// executed when mana shield aura effect is going to reduce damage
2017-11-02 19:52:47 +01:00
// example: OnEffectManaShield += AuraEffectManaShieldFn(class::function, EffectIndexSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
2010-12-30 19:05:19 +01:00
HookList < EffectManaShieldHandler > OnEffectManaShield ;
#define AuraEffectManaShieldFn(F, I) EffectManaShieldFunction(&F, I)
// executed after mana shield aura effect reduced damage to target - absorbAmount is real amount absorbed by aura
2017-11-02 19:52:47 +01:00
// example: AfterEffectManaShield += AuraEffectManaShieldFn(class::function, EffectIndexSpecifier);
2011-05-19 13:22:17 +02:00
// where function is: void function (AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
2010-12-30 19:05:19 +01:00
HookList < EffectManaShieldHandler > AfterEffectManaShield ;
2010-08-24 00:10:49 +02:00
2012-09-18 23:19:31 +03:00
// executed when the caster of some spell with split dmg aura gets damaged through it
// example: OnEffectSplit += AuraEffectSplitFn(class::function, EffectIndexSpecifier);
// where function is: void function (AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& splitAmount);
HookList < EffectSplitHandler > OnEffectSplit ;
#define AuraEffectSplitFn(F, I) EffectSplitFunction(&F, I)
2013-01-11 01:21:44 +01:00
// executed when aura checks if it can proc
// example: DoCheckProc += AuraCheckProcFn(class::function);
// where function is: bool function (ProcEventInfo& eventInfo);
HookList < CheckProcHandler > DoCheckProc ;
#define AuraCheckProcFn(F) CheckProcHandlerFunction(&F)
2017-08-13 12:03:43 +02:00
// executed when aura effect checks if it can proc the aura
// example: DoCheckEffectProc += AuraCheckEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is bool function (AuraEffect const* aurEff, ProcEventInfo& eventInfo);
HookList < CheckEffectProcHandler > DoCheckEffectProc ;
#define AuraCheckEffectProcFn(F, I, N) CheckEffectProcHandlerFunction(&F, I, N)
2013-01-11 01:21:44 +01:00
// executed before aura procs (possibility to prevent charge drop/cooldown)
// example: DoPrepareProc += AuraProcFn(class::function);
// where function is: void function (ProcEventInfo& eventInfo);
HookList < AuraProcHandler > DoPrepareProc ;
// executed when aura procs
// example: OnProc += AuraProcFn(class::function);
// where function is: void function (ProcEventInfo& eventInfo);
HookList < AuraProcHandler > OnProc ;
// executed after aura proced
// example: AfterProc += AuraProcFn(class::function);
// where function is: void function (ProcEventInfo& eventInfo);
HookList < AuraProcHandler > AfterProc ;
#define AuraProcFn(F) AuraProcHandlerFunction(&F)
// executed when aura effect procs
// example: OnEffectProc += AuraEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function (AuraEffect const* aurEff, ProcEventInfo& procInfo);
HookList < EffectProcHandler > OnEffectProc ;
// executed after aura effect proced
// example: AfterEffectProc += AuraEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function (AuraEffect const* aurEff, ProcEventInfo& procInfo);
HookList < EffectProcHandler > AfterEffectProc ;
#define AuraEffectProcFn(F, I, N) EffectProcHandlerFunction(&F, I, N)
2010-10-04 17:44:49 +02:00
// AuraScript interface - hook/effect execution manipulators
// prevents default action of a hook from being executed (works only while called in a hook which default action can be prevented)
void PreventDefaultAction ();
2010-08-24 00:10:49 +02:00
// AuraScript interface - functions which are redirecting to Aura class
// returns proto of the spell
2011-07-26 23:09:28 +02:00
SpellInfo const * GetSpellInfo () const ;
2010-08-24 00:10:49 +02:00
// returns spellid of the spell
uint32 GetId () const ;
2013-12-25 14:16:55 -03:30
// returns guid of object which cast the aura (m_originalCaster of the Spell class)
2014-09-14 16:14:12 +02:00
ObjectGuid GetCasterGUID () const ;
2013-12-25 14:16:55 -03:30
// returns unit which cast the aura or NULL if not avalible (caster logged out for example)
2010-08-24 00:10:49 +02:00
Unit * GetCaster () const ;
2013-12-25 14:16:55 -03:30
// returns object on which aura was cast, target for non-area auras, area aura source for area auras
2011-09-15 14:08:17 +02:00
WorldObject * GetOwner () const ;
2010-12-05 21:38:52 +01:00
// returns owner if it's unit or unit derived object, NULL otherwise (only for persistent area auras NULL is returned)
2011-06-11 22:35:29 +02:00
Unit * GetUnitOwner () const ;
2010-08-24 00:10:49 +02:00
// returns owner if it's dynobj, NULL otherwise
2011-09-15 14:08:17 +02:00
DynamicObject * GetDynobjOwner () const ;
2010-08-24 00:10:49 +02:00
// removes aura with remove mode (see AuraRemoveMode enum)
2015-01-07 22:48:34 +01:00
void Remove ( AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT );
2010-08-24 00:10:49 +02:00
// returns aura object of script
2011-09-15 14:08:17 +02:00
Aura * GetAura () const ;
2010-08-24 00:10:49 +02:00
// returns type of the aura, may be dynobj owned aura or unit owned aura
AuraObjectType GetType () const ;
// aura duration manipulation - when duration goes to 0 aura is removed
int32 GetDuration () const ;
void SetDuration ( int32 duration , bool withMods = false );
// sets duration to maxduration
void RefreshDuration ();
time_t GetApplyTime () const ;
int32 GetMaxDuration () const ;
void SetMaxDuration ( int32 duration );
2011-06-07 17:25:34 +02:00
int32 CalcMaxDuration () const ;
2010-08-24 00:10:49 +02:00
// expired - duration just went to 0
bool IsExpired () const ;
// permament - has infinite duration
bool IsPermanent () const ;
// charges manipulation - 0 - not charged aura
uint8 GetCharges () const ;
void SetCharges ( uint8 charges );
2011-06-07 17:25:34 +02:00
uint8 CalcMaxCharges () const ;
bool ModCharges ( int8 num , AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT );
2010-08-24 00:10:49 +02:00
// returns true if last charge dropped
2011-06-07 17:25:34 +02:00
bool DropCharge ( AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT );
2010-08-24 00:10:49 +02:00
// stack amount manipulation
uint8 GetStackAmount () const ;
2011-05-29 13:18:47 +02:00
void SetStackAmount ( uint8 num );
2011-06-07 17:25:34 +02:00
bool ModStackAmount ( int32 num , AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT );
2010-08-24 00:10:49 +02:00
2011-06-16 20:08:28 +07:00
// passive - "working in background", not saved, not removed by immunities, not seen by player
2010-08-24 00:10:49 +02:00
bool IsPassive () const ;
// death persistent - not removed on death
bool IsDeathPersistent () const ;
// check if aura has effect of given effindex
bool HasEffect ( uint8 effIndex ) const ;
// returns aura effect of given effect index or NULL
2011-09-15 14:08:17 +02:00
AuraEffect * GetEffect ( uint8 effIndex ) const ;
2010-08-24 00:10:49 +02:00
// check if aura has effect of given aura type
bool HasEffectType ( AuraType type ) const ;
2010-12-27 20:14:54 +01:00
// AuraScript interface - functions which are redirecting to AuraApplication class
// Do not call these in hooks in which AuraApplication is not avalible, otherwise result will differ from expected (the functions will return NULL)
// returns currently processed target of an aura
2011-05-19 13:22:17 +02:00
// Return value does not need to be NULL-checked, the only situation this will (always)
// return NULL is when the call happens in an unsupported hook, in other cases, it is always valid
2011-06-11 22:35:29 +02:00
Unit * GetTarget () const ;
2010-12-27 20:14:54 +01:00
// returns AuraApplication object of currently processed target
2011-06-11 22:35:29 +02:00
AuraApplication const * GetTargetApplication () const ;
2010-08-24 00:10:49 +02:00
};
2010-08-21 20:18:54 +02:00
2010-07-24 22:41:42 +02:00
//
// definitions:
//
// EffectIndexSpecifier - specifies conditions for effects
// EFFECT_0 - first effect matches
// EFFECT_1 - second effect matches
// EFFECT_2 - third effect matches
// EFFECT_FIRST_FOUND - first effect matching other conditions matches
2010-08-08 19:45:53 +02:00
// EFFECT_ALL - all effects of spell match
2010-07-24 22:41:42 +02:00
//
// EffectNameSpecifier - specifies conditions for spell effect names
// SPELL_EFFECT_ANY - any effect but not 0 matches condition
// SPELL_EFFECT_XXX - one of values of enum SpellEffects - effect with equal name matches
//
#endif // __SPELL_SCRIPT_H