Advertisement
Guest User

Untitled

a guest
Mar 20th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.73 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17.  
  18. #ifndef __SPELL_SCRIPT_H
  19. #define __SPELL_SCRIPT_H
  20.  
  21. #include "Util.h"
  22. #include "SharedDefines.h"
  23. #include "SpellAuraDefines.h"
  24. #include "Spell.h"
  25. #include <stack>
  26.  
  27. class Unit;
  28. class SpellInfo;
  29. class SpellScript;
  30. class Spell;
  31. class Aura;
  32. class AuraEffect;
  33. struct SpellModifier;
  34. class Creature;
  35. class GameObject;
  36. class DynamicObject;
  37. class Player;
  38. class Item;
  39. class WorldLocation;
  40. class WorldObject;
  41.  
  42. #define SPELL_EFFECT_ANY (uint16)-1
  43. #define SPELL_AURA_ANY (uint16)-1
  44.  
  45. enum SpellScriptState
  46. {
  47. SPELL_SCRIPT_STATE_NONE = 0,
  48. SPELL_SCRIPT_STATE_REGISTRATION,
  49. SPELL_SCRIPT_STATE_LOADING,
  50. SPELL_SCRIPT_STATE_UNLOADING,
  51. };
  52. #define SPELL_SCRIPT_STATE_END SPELL_SCRIPT_STATE_UNLOADING + 1
  53.  
  54. // helper class from which SpellScript and SpellAura derive, use these classes instead
  55. class _SpellScript
  56. {
  57. // internal use classes & functions
  58. // DO NOT OVERRIDE THESE IN SCRIPTS
  59. protected:
  60. virtual bool _Validate(SpellInfo const* entry);
  61.  
  62. public:
  63. _SpellScript() : m_currentScriptState(SPELL_SCRIPT_STATE_NONE) {}
  64. virtual ~_SpellScript() {}
  65. virtual void _Register();
  66. virtual void _Unload();
  67. virtual void _Init(std::string const* scriptname, uint32 spellId);
  68. std::string const* _GetScriptName() const;
  69.  
  70. protected:
  71. class EffectHook
  72. {
  73. public:
  74. EffectHook(uint8 _effIndex);
  75. uint32 GetAffectedEffectsMask(SpellInfo const* spellEntry);
  76. bool IsEffectAffected(SpellInfo const* spellEntry, uint8 effIndex);
  77. virtual bool CheckEffect(SpellInfo const* spellEntry, uint8 effIndex) = 0;
  78. std::string EffIndexToString();
  79. protected:
  80. uint8 effIndex;
  81. };
  82.  
  83. class EffectNameCheck
  84. {
  85. public:
  86. EffectNameCheck(uint16 _effName) {effName = _effName;};
  87. bool Check(SpellInfo const* spellEntry, uint8 effIndex);
  88. std::string ToString();
  89. private:
  90. uint16 effName;
  91. };
  92.  
  93. class EffectAuraNameCheck
  94. {
  95. public:
  96. EffectAuraNameCheck(uint16 _effAurName) { effAurName = _effAurName; }
  97. bool Check(SpellInfo const* spellEntry, uint8 effIndex);
  98. std::string ToString();
  99. private:
  100. uint16 effAurName;
  101. };
  102.  
  103. uint8 m_currentScriptState;
  104. std::string const* m_scriptName;
  105. uint32 m_scriptSpellId;
  106. public:
  107. //
  108. // SpellScript/AuraScript interface base
  109. // these functions are safe to override, see notes below for usage instructions
  110. //
  111. // Function in which handler functions are registered, must be implemented in script
  112. virtual void Register() = 0;
  113. // Function called on server startup, if returns false script won't be used in core
  114. // use for: dbc/template data presence/correctness checks
  115. virtual bool Validate(SpellInfo const* /*spellEntry*/) { return true; }
  116. // Function called when script is created, if returns false script will be unloaded afterwards
  117. // use for: initializing local script variables (DO NOT USE CONSTRUCTOR FOR THIS PURPOSE!)
  118. virtual bool Load() { return true; }
  119. // Function called when script is destroyed
  120. // use for: deallocating memory allocated by script
  121. virtual void Unload() {}
  122. };
  123.  
  124. // SpellScript interface - enum used for runtime checks of script function calls
  125. enum SpellScriptHookType
  126. {
  127. SPELL_SCRIPT_HOOK_EFFECT_LAUNCH = SPELL_SCRIPT_STATE_END,
  128. SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET,
  129. SPELL_SCRIPT_HOOK_EFFECT_HIT,
  130. SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET,
  131. SPELL_SCRIPT_HOOK_BEFORE_HIT,
  132. SPELL_SCRIPT_HOOK_HIT,
  133. SPELL_SCRIPT_HOOK_AFTER_HIT,
  134. SPELL_SCRIPT_HOOK_OBJECT_AREA_TARGET_SELECT,
  135. SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT,
  136. SPELL_SCRIPT_HOOK_CHECK_CAST,
  137. SPELL_SCRIPT_HOOK_BEFORE_CAST,
  138. SPELL_SCRIPT_HOOK_ON_CAST,
  139. SPELL_SCRIPT_HOOK_AFTER_CAST,
  140. };
  141.  
  142. #define HOOK_SPELL_HIT_START SPELL_SCRIPT_HOOK_EFFECT_HIT
  143. #define HOOK_SPELL_HIT_END SPELL_SCRIPT_HOOK_AFTER_HIT + 1
  144. #define HOOK_SPELL_START SPELL_SCRIPT_HOOK_EFFECT
  145. #define HOOK_SPELL_END SPELL_SCRIPT_HOOK_CHECK_CAST + 1
  146. #define HOOK_SPELL_COUNT HOOK_SPELL_END - HOOK_SPELL_START
  147.  
  148. class SpellScript : public _SpellScript
  149. {
  150. // internal use classes & functions
  151. // DO NOT OVERRIDE THESE IN SCRIPTS
  152. public:
  153. #define SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
  154. typedef SpellCastResult(CLASSNAME::*SpellCheckCastFnType)(); \
  155. typedef void(CLASSNAME::*SpellEffectFnType)(SpellEffIndex); \
  156. typedef void(CLASSNAME::*SpellHitFnType)(); \
  157. typedef void(CLASSNAME::*SpellCastFnType)(); \
  158. typedef void(CLASSNAME::*SpellObjectAreaTargetSelectFnType)(std::list<WorldObject*>&); \
  159. typedef void(CLASSNAME::*SpellObjectTargetSelectFnType)(WorldObject*&);
  160.  
  161. SPELLSCRIPT_FUNCTION_TYPE_DEFINES(SpellScript)
  162.  
  163. class CastHandler
  164. {
  165. public:
  166. CastHandler(SpellCastFnType _pCastHandlerScript);
  167. void Call(SpellScript* spellScript);
  168. private:
  169. SpellCastFnType pCastHandlerScript;
  170. };
  171.  
  172. class CheckCastHandler
  173. {
  174. public:
  175. CheckCastHandler(SpellCheckCastFnType checkCastHandlerScript);
  176. SpellCastResult Call(SpellScript* spellScript);
  177. private:
  178. SpellCheckCastFnType _checkCastHandlerScript;
  179. };
  180.  
  181. class EffectHandler : public _SpellScript::EffectNameCheck, public _SpellScript::EffectHook
  182. {
  183. public:
  184. EffectHandler(SpellEffectFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  185. std::string ToString();
  186. bool CheckEffect(SpellInfo const* spellEntry, uint8 effIndex);
  187. void Call(SpellScript* spellScript, SpellEffIndex effIndex);
  188. private:
  189. SpellEffectFnType pEffectHandlerScript;
  190. };
  191.  
  192. class HitHandler
  193. {
  194. public:
  195. HitHandler(SpellHitFnType _pHitHandlerScript);
  196. void Call(SpellScript* spellScript);
  197. private:
  198. SpellHitFnType pHitHandlerScript;
  199. };
  200.  
  201. class TargetHook : public _SpellScript::EffectHook
  202. {
  203. public:
  204. TargetHook(uint8 _effectIndex, uint16 _targetType, bool _area);
  205. bool CheckEffect(SpellInfo const* spellEntry, uint8 effIndex);
  206. std::string ToString();
  207. protected:
  208. uint16 targetType;
  209. bool area;
  210. };
  211.  
  212. class ObjectAreaTargetSelectHandler : public TargetHook
  213. {
  214. public:
  215. ObjectAreaTargetSelectHandler(SpellObjectAreaTargetSelectFnType _pObjectAreaTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType);
  216. void Call(SpellScript* spellScript, std::list<WorldObject*>& targets);
  217. private:
  218. SpellObjectAreaTargetSelectFnType pObjectAreaTargetSelectHandlerScript;
  219. };
  220.  
  221. class ObjectTargetSelectHandler : public TargetHook
  222. {
  223. public:
  224. ObjectTargetSelectHandler(SpellObjectTargetSelectFnType _pObjectTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType);
  225. void Call(SpellScript* spellScript, WorldObject*& targets);
  226. private:
  227. SpellObjectTargetSelectFnType pObjectTargetSelectHandlerScript;
  228. };
  229.  
  230. #define SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) \
  231. class CastHandlerFunction : public SpellScript::CastHandler { public: CastHandlerFunction(SpellCastFnType _pCastHandlerScript) : SpellScript::CastHandler((SpellScript::SpellCastFnType)_pCastHandlerScript) {} }; \
  232. class CheckCastHandlerFunction : public SpellScript::CheckCastHandler { public: CheckCastHandlerFunction(SpellCheckCastFnType _checkCastHandlerScript) : SpellScript::CheckCastHandler((SpellScript::SpellCheckCastFnType)_checkCastHandlerScript) {} }; \
  233. class EffectHandlerFunction : public SpellScript::EffectHandler { public: EffectHandlerFunction(SpellEffectFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : SpellScript::EffectHandler((SpellScript::SpellEffectFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  234. class HitHandlerFunction : public SpellScript::HitHandler { public: HitHandlerFunction(SpellHitFnType _pHitHandlerScript) : SpellScript::HitHandler((SpellScript::SpellHitFnType)_pHitHandlerScript) {} }; \
  235. class ObjectAreaTargetSelectHandlerFunction : public SpellScript::ObjectAreaTargetSelectHandler { public: ObjectAreaTargetSelectHandlerFunction(SpellObjectAreaTargetSelectFnType _pObjectAreaTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::ObjectAreaTargetSelectHandler((SpellScript::SpellObjectAreaTargetSelectFnType)_pObjectAreaTargetSelectHandlerScript, _effIndex, _targetType) {} }; \
  236. class ObjectTargetSelectHandlerFunction : public SpellScript::ObjectTargetSelectHandler { public: ObjectTargetSelectHandlerFunction(SpellObjectTargetSelectFnType _pObjectTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType) : SpellScript::ObjectTargetSelectHandler((SpellScript::SpellObjectTargetSelectFnType)_pObjectTargetSelectHandlerScript, _effIndex, _targetType) {} };
  237.  
  238. #define PrepareSpellScript(CLASSNAME) SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME)
  239. public:
  240. bool _Validate(SpellInfo const* entry);
  241. bool _Load(Spell* spell);
  242. void _InitHit();
  243. bool _IsEffectPrevented(SpellEffIndex effIndex) { return m_hitPreventEffectMask & (1<<effIndex); }
  244. bool _IsDefaultEffectPrevented(SpellEffIndex effIndex) { return m_hitPreventDefaultEffectMask & (1<<effIndex); }
  245. void _PrepareScriptCall(SpellScriptHookType hookType);
  246. void _FinishScriptCall();
  247. bool IsInCheckCastHook() const;
  248. bool IsInTargetHook() const;
  249. bool IsInHitPhase() const;
  250. bool IsInEffectHook() const;
  251. private:
  252. Spell* m_spell;
  253. uint8 m_hitPreventEffectMask;
  254. uint8 m_hitPreventDefaultEffectMask;
  255. public:
  256. //
  257. // SpellScript interface
  258. // hooks to which you can attach your functions
  259. //
  260. // example: BeforeCast += SpellCastFn(class::function);
  261. HookList<CastHandler> BeforeCast;
  262. // example: OnCast += SpellCastFn(class::function);
  263. HookList<CastHandler> OnCast;
  264. // example: AfterCast += SpellCastFn(class::function);
  265. HookList<CastHandler> AfterCast;
  266. #define SpellCastFn(F) CastHandlerFunction(&F)
  267.  
  268. // example: OnCheckCast += SpellCheckCastFn();
  269. // where function is SpellCastResult function()
  270. HookList<CheckCastHandler> OnCheckCast;
  271. #define SpellCheckCastFn(F) CheckCastHandlerFunction(&F)
  272.  
  273. // example: OnEffect**** += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier);
  274. // where function is void function(SpellEffIndex effIndex)
  275. HookList<EffectHandler> OnEffectLaunch;
  276. HookList<EffectHandler> OnEffectLaunchTarget;
  277. HookList<EffectHandler> OnEffectHit;
  278. HookList<EffectHandler> OnEffectHitTarget;
  279. #define SpellEffectFn(F, I, N) EffectHandlerFunction(&F, I, N)
  280.  
  281. // example: BeforeHit += SpellHitFn(class::function);
  282. HookList<HitHandler> BeforeHit;
  283. // example: OnHit += SpellHitFn(class::function);
  284. HookList<HitHandler> OnHit;
  285. // example: AfterHit += SpellHitFn(class::function);
  286. HookList<HitHandler> AfterHit;
  287. // where function is: void function()
  288. #define SpellHitFn(F) HitHandlerFunction(&F)
  289.  
  290. // example: OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
  291. // where function is void function(std::list<WorldObject*>& targets)
  292. HookList<ObjectAreaTargetSelectHandler> OnObjectAreaTargetSelect;
  293. #define SpellObjectAreaTargetSelectFn(F, I, N) ObjectAreaTargetSelectHandlerFunction(&F, I, N)
  294.  
  295. // example: OnObjectTargetSelect += SpellObjectTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
  296. // where function is void function(WorldObject*& target)
  297. HookList<ObjectTargetSelectHandler> OnObjectTargetSelect;
  298. #define SpellObjectTargetSelectFn(F, I, N) ObjectTargetSelectHandlerFunction(&F, I, N)
  299.  
  300. // hooks are executed in following order, at specified event of spell:
  301. // 1. BeforeCast - executed when spell preparation is finished (when cast bar becomes full) before cast is handled
  302. // 2. OnCheckCast - allows to override result of CheckCast function
  303. // 3a. OnObjectAreaTargetSelect - executed just before adding selected targets to final target list (for area targets)
  304. // 3b. OnObjectTargetSelect - executed just before adding selected target to final target list (for single unit targets)
  305. // 4. OnCast - executed just before spell is launched (creates missile) or executed
  306. // 5. AfterCast - executed after spell missile is launched and immediate spell actions are done
  307. // 6. OnEffectLaunch - executed just before specified effect handler call - when spell missile is launched
  308. // 7. OnEffectLaunchTarget - executed just before specified effect handler call - when spell missile is launched - called for each target from spell target map
  309. // 8. OnEffectHit - executed just before specified effect handler call - when spell missile hits dest
  310. // 9. BeforeHit - executed just before spell hits a target - called for each target from spell target map
  311. // 10. OnEffectHitTarget - executed just before specified effect handler call - called for each target from spell target map
  312. // 11. OnHit - executed just before spell deals damage and procs auras - when spell hits target - called for each target from spell target map
  313. // 12. AfterHit - executed just after spell finishes all it's jobs for target - called for each target from spell target map
  314.  
  315. //
  316. // methods allowing interaction with Spell object
  317. //
  318. // methods useable during all spell handling phases
  319. Unit* GetCaster();
  320. Unit* GetOriginalCaster();
  321. SpellInfo const* GetSpellInfo();
  322. SpellValue const* GetSpellValue();
  323.  
  324. // methods useable after spell is prepared
  325. // accessors to the explicit targets of the spell
  326. // explicit target - target selected by caster (player, game client, or script - DoCast(explicitTarget, ...), required for spell to be cast
  327. // examples:
  328. // -shadowstep - explicit target is the unit you want to go behind of
  329. // -chain heal - explicit target is the unit to be healed first
  330. // -holy nova/arcane explosion - explicit target = NULL because target you are selecting doesn't affect how spell targets are selected
  331. // you can determine if spell requires explicit targets by dbc columns:
  332. // - Targets - mask of explicit target types
  333. // - ImplicitTargetXX set to TARGET_XXX_TARGET_YYY, _TARGET_ here means that explicit target is used by the effect, so spell needs one too
  334.  
  335. // returns: WorldLocation which was selected as a spell destination or NULL
  336. WorldLocation const* GetExplTargetDest();
  337.  
  338. void SetExplTargetDest(WorldLocation& loc);
  339.  
  340. // returns: WorldObject which was selected as an explicit spell target or NULL if there's no target
  341. WorldObject* GetExplTargetWorldObject();
  342.  
  343. // returns: Unit which was selected as an explicit spell target or NULL if there's no target
  344. Unit* GetExplTargetUnit();
  345.  
  346. // returns: GameObject which was selected as an explicit spell target or NULL if there's no target
  347. GameObject* GetExplTargetGObj();
  348.  
  349. // returns: Item which was selected as an explicit spell target or NULL if there's no target
  350. Item* GetExplTargetItem();
  351.  
  352. // methods useable only during spell hit on target, or during spell launch on target:
  353. // returns: target of current effect if it was Unit otherwise NULL
  354. Unit* GetHitUnit();
  355. // returns: target of current effect if it was Creature otherwise NULL
  356. Creature* GetHitCreature();
  357. // returns: target of current effect if it was Player otherwise NULL
  358. Player* GetHitPlayer();
  359. // returns: target of current effect if it was Item otherwise NULL
  360. Item* GetHitItem();
  361. // returns: target of current effect if it was GameObject otherwise NULL
  362. GameObject* GetHitGObj();
  363. // returns: destination of current effect
  364. WorldLocation* GetHitDest();
  365. // setter/getter for for damage done by spell to target of spell hit
  366. // returns damage calculated before hit, and real dmg done after hit
  367. int32 GetHitDamage();
  368. void SetHitDamage(int32 damage);
  369. void PreventHitDamage() { SetHitDamage(0); }
  370. // setter/getter for for heal done by spell to target of spell hit
  371. // returns healing calculated before hit, and real dmg done after hit
  372. int32 GetHitHeal();
  373. void SetHitHeal(int32 heal);
  374. void PreventHitHeal() { SetHitHeal(0); }
  375. Spell* GetSpell() { return m_spell; }
  376. // returns current spell hit target aura
  377. AuraPtr GetHitAura();
  378. // prevents applying aura on current spell hit target
  379. void PreventHitAura();
  380.  
  381. // prevents effect execution on current spell hit target
  382. // including other effect/hit scripts
  383. // will not work on aura/damage/heal
  384. // will not work if effects were already handled
  385. void PreventHitEffect(SpellEffIndex effIndex);
  386.  
  387. // prevents default effect execution on current spell hit target
  388. // will not work on aura/damage/heal effects
  389. // will not work if effects were already handled
  390. void PreventHitDefaultEffect(SpellEffIndex effIndex);
  391.  
  392. // method avalible only in EffectHandler method
  393. int32 GetEffectValue();
  394.  
  395. // returns: cast item if present.
  396. Item* GetCastItem();
  397.  
  398. // Creates item. Calls Spell::DoCreateItem method.
  399. void CreateItem(uint32 effIndex, uint32 itemId);
  400.  
  401. // Returns SpellInfo from the spell that triggered the current one
  402. SpellInfo const* GetTriggeringSpell();
  403.  
  404. // finishes spellcast prematurely with selected error message
  405. void FinishCast(SpellCastResult result);
  406.  
  407. void SetCustomCastResultMessage(SpellCustomErrors result);
  408. };
  409.  
  410. // AuraScript interface - enum used for runtime checks of script function calls
  411. enum AuraScriptHookType
  412. {
  413. AURA_SCRIPT_HOOK_EFFECT_APPLY = SPELL_SCRIPT_STATE_END,
  414. AURA_SCRIPT_HOOK_EFFECT_AFTER_APPLY,
  415. AURA_SCRIPT_HOOK_EFFECT_REMOVE,
  416. AURA_SCRIPT_HOOK_EFFECT_AFTER_REMOVE,
  417. AURA_SCRIPT_HOOK_EFFECT_PERIODIC,
  418. AURA_SCRIPT_HOOK_ON_UPDATE,
  419. AURA_SCRIPT_HOOK_EFFECT_UPDATE,
  420. AURA_SCRIPT_HOOK_EFFECT_UPDATE_PERIODIC,
  421. AURA_SCRIPT_HOOK_EFFECT_CALC_AMOUNT,
  422. AURA_SCRIPT_HOOK_EFFECT_CALC_PERIODIC,
  423. AURA_SCRIPT_HOOK_EFFECT_CALC_SPELLMOD,
  424. AURA_SCRIPT_HOOK_EFFECT_ABSORB,
  425. AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB,
  426. AURA_SCRIPT_HOOK_EFFECT_MANASHIELD,
  427. AURA_SCRIPT_HOOK_EFFECT_AFTER_MANASHIELD,
  428. AURA_SCRIPT_HOOK_CHECK_AREA_TARGET,
  429. AURA_SCRIPT_HOOK_DISPEL,
  430. AURA_SCRIPT_HOOK_AFTER_DISPEL,
  431. // Spell Proc Hooks
  432. AURA_SCRIPT_HOOK_CHECK_PROC,
  433. AURA_SCRIPT_HOOK_PREPARE_PROC,
  434. AURA_SCRIPT_HOOK_PROC,
  435. AURA_SCRIPT_HOOK_EFFECT_PROC,
  436. AURA_SCRIPT_HOOK_EFFECT_AFTER_PROC,
  437. AURA_SCRIPT_HOOK_AFTER_PROC,
  438. /*AURA_SCRIPT_HOOK_APPLY,
  439. AURA_SCRIPT_HOOK_REMOVE, */
  440. };
  441. /*
  442. #define HOOK_AURA_EFFECT_START HOOK_AURA_EFFECT_APPLY
  443. #define HOOK_AURA_EFFECT_END HOOK_AURA_EFFECT_CALC_SPELLMOD + 1
  444. #define HOOK_AURA_EFFECT_COUNT HOOK_AURA_EFFECT_END - HOOK_AURA_EFFECT_START
  445. */
  446. class AuraScript : public _SpellScript
  447. {
  448. // internal use classes & functions
  449. // DO NOT OVERRIDE THESE IN SCRIPTS
  450. public:
  451.  
  452. #define AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \
  453. typedef bool(CLASSNAME::*AuraCheckAreaTargetFnType)(Unit* target); \
  454. typedef void(CLASSNAME::*AuraDispelFnType)(DispelInfo* dispelInfo); \
  455. typedef void(CLASSNAME::*AuraEffectApplicationModeFnType)(constAuraEffectPtr, AuraEffectHandleModes); \
  456. typedef void(CLASSNAME::*AuraEffectPeriodicFnType)(constAuraEffectPtr); \
  457. typedef void(CLASSNAME::*AuraUpdateFnType)(uint32); \
  458. typedef void(CLASSNAME::*AuraEffectUpdateFnType)(uint32, AuraEffectPtr); \
  459. typedef void(CLASSNAME::*AuraEffectUpdatePeriodicFnType)(AuraEffectPtr); \
  460. typedef void(CLASSNAME::*AuraEffectCalcAmountFnType)(constAuraEffectPtr, int32 &, bool &); \
  461. typedef void(CLASSNAME::*AuraEffectCalcPeriodicFnType)(constAuraEffectPtr, bool &, int32 &); \
  462. typedef void(CLASSNAME::*AuraEffectCalcSpellModFnType)(constAuraEffectPtr, SpellModifier* &); \
  463. typedef void(CLASSNAME::*AuraEffectAbsorbFnType)(AuraEffectPtr, DamageInfo &, uint32 &); \
  464. typedef bool(CLASSNAME::*AuraCheckProcFnType)(ProcEventInfo&); \
  465. typedef void(CLASSNAME::*AuraProcFnType)(ProcEventInfo&); \
  466. typedef void(CLASSNAME::*AuraEffectProcFnType)(constAuraEffectPtr, ProcEventInfo&); \
  467.  
  468. AURASCRIPT_FUNCTION_TYPE_DEFINES(AuraScript)
  469.  
  470. class CheckAreaTargetHandler
  471. {
  472. public:
  473. CheckAreaTargetHandler(AuraCheckAreaTargetFnType pHandlerScript);
  474. bool Call(AuraScript* auraScript, Unit* target);
  475. private:
  476. AuraCheckAreaTargetFnType pHandlerScript;
  477. };
  478. class AuraDispelHandler
  479. {
  480. public:
  481. AuraDispelHandler(AuraDispelFnType pHandlerScript);
  482. void Call(AuraScript* auraScript, DispelInfo* dispelInfo);
  483. private:
  484. AuraDispelFnType pHandlerScript;
  485. };
  486. class EffectBase : public _SpellScript::EffectAuraNameCheck, public _SpellScript::EffectHook
  487. {
  488. public:
  489. EffectBase(uint8 _effIndex, uint16 _effName);
  490. std::string ToString();
  491. bool CheckEffect(SpellInfo const* spellEntry, uint8 effIndex);
  492. };
  493. class EffectPeriodicHandler : public EffectBase
  494. {
  495. public:
  496. EffectPeriodicHandler(AuraEffectPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  497. void Call(AuraScript* auraScript, constAuraEffectPtr _aurEff);
  498. private:
  499. AuraEffectPeriodicFnType pEffectHandlerScript;
  500. };
  501. class AuraUpdateHandler
  502. {
  503. public:
  504. AuraUpdateHandler(AuraUpdateFnType _pEffectHandlerScript);
  505. void Call(AuraScript* auraScript, uint32 diff);
  506. private:
  507. AuraUpdateFnType pEffectHandlerScript;
  508. };
  509. class EffectUpdateHandler : public EffectBase
  510. {
  511. public:
  512. EffectUpdateHandler(AuraEffectUpdateFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  513. void Call(AuraScript* auraScript, uint32 diff, AuraEffectPtr aurEff);
  514. private:
  515. AuraEffectUpdateFnType pEffectHandlerScript;
  516. };
  517. class EffectUpdatePeriodicHandler : public EffectBase
  518. {
  519. public:
  520. EffectUpdatePeriodicHandler(AuraEffectUpdatePeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  521. void Call(AuraScript* auraScript, AuraEffectPtr aurEff);
  522. private:
  523. AuraEffectUpdatePeriodicFnType pEffectHandlerScript;
  524. };
  525. class EffectCalcAmountHandler : public EffectBase
  526. {
  527. public:
  528. EffectCalcAmountHandler(AuraEffectCalcAmountFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  529. void Call(AuraScript* auraScript, constAuraEffectPtr aurEff, int32 & amount, bool & canBeRecalculated);
  530. private:
  531. AuraEffectCalcAmountFnType pEffectHandlerScript;
  532. };
  533. class EffectCalcPeriodicHandler : public EffectBase
  534. {
  535. public:
  536. EffectCalcPeriodicHandler(AuraEffectCalcPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  537. void Call(AuraScript* auraScript, constAuraEffectPtr aurEff, bool & isPeriodic, int32 & periodicTimer);
  538. private:
  539. AuraEffectCalcPeriodicFnType pEffectHandlerScript;
  540. };
  541. class EffectCalcSpellModHandler : public EffectBase
  542. {
  543. public:
  544. EffectCalcSpellModHandler(AuraEffectCalcSpellModFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName);
  545. void Call(AuraScript* auraScript, constAuraEffectPtr aurEff, SpellModifier* & spellMod);
  546. private:
  547. AuraEffectCalcSpellModFnType pEffectHandlerScript;
  548. };
  549. class EffectApplyHandler : public EffectBase
  550. {
  551. public:
  552. EffectApplyHandler(AuraEffectApplicationModeFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName, AuraEffectHandleModes _mode);
  553. void Call(AuraScript* auraScript, constAuraEffectPtr _aurEff, AuraEffectHandleModes _mode);
  554. private:
  555. AuraEffectApplicationModeFnType pEffectHandlerScript;
  556. AuraEffectHandleModes mode;
  557. };
  558. class EffectAbsorbHandler : public EffectBase
  559. {
  560. public:
  561. EffectAbsorbHandler(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex);
  562. void Call(AuraScript* auraScript, AuraEffectPtr aurEff, DamageInfo & dmgInfo, uint32 & absorbAmount);
  563. private:
  564. AuraEffectAbsorbFnType pEffectHandlerScript;
  565. };
  566. class EffectManaShieldHandler : public EffectBase
  567. {
  568. public:
  569. EffectManaShieldHandler(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex);
  570. void Call(AuraScript* auraScript, AuraEffectPtr aurEff, DamageInfo & dmgInfo, uint32 & absorbAmount);
  571. private:
  572. AuraEffectAbsorbFnType pEffectHandlerScript;
  573. };
  574. class CheckProcHandler
  575. {
  576. public:
  577. CheckProcHandler(AuraCheckProcFnType handlerScript);
  578. bool Call(AuraScript* auraScript, ProcEventInfo& eventInfo);
  579. private:
  580. AuraCheckProcFnType _HandlerScript;
  581. };
  582. class AuraProcHandler
  583. {
  584. public:
  585. AuraProcHandler(AuraProcFnType handlerScript);
  586. void Call(AuraScript* auraScript, ProcEventInfo& eventInfo);
  587. private:
  588. AuraProcFnType _HandlerScript;
  589. };
  590. class EffectProcHandler : public EffectBase
  591. {
  592. public:
  593. EffectProcHandler(AuraEffectProcFnType effectHandlerScript, uint8 effIndex, uint16 effName);
  594. void Call(AuraScript* auraScript, constAuraEffectPtr aurEff, ProcEventInfo& eventInfo);
  595. private:
  596. AuraEffectProcFnType _EffectHandlerScript;
  597. };
  598.  
  599. #define AURASCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) \
  600. class CheckAreaTargetFunction : public AuraScript::CheckAreaTargetHandler { public: CheckAreaTargetFunction(AuraCheckAreaTargetFnType _pHandlerScript) : AuraScript::CheckAreaTargetHandler((AuraScript::AuraCheckAreaTargetFnType)_pHandlerScript) {} }; \
  601. class AuraDispelFunction : public AuraScript::AuraDispelHandler { public: AuraDispelFunction(AuraDispelFnType _pHandlerScript) : AuraScript::AuraDispelHandler((AuraScript::AuraDispelFnType)_pHandlerScript) {} }; \
  602. class EffectPeriodicHandlerFunction : public AuraScript::EffectPeriodicHandler { public: EffectPeriodicHandlerFunction(AuraEffectPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectPeriodicHandler((AuraScript::AuraEffectPeriodicFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  603. class AuraUpdateHandlerFunction : public AuraScript::AuraUpdateHandler { public: AuraUpdateHandlerFunction(AuraUpdateFnType _pEffectHandlerScript) : AuraScript::AuraUpdateHandler((AuraScript::AuraUpdateFnType)_pEffectHandlerScript) {} }; \
  604. class EffectUpdateHandlerFunction : public AuraScript::EffectUpdateHandler { public: EffectUpdateHandlerFunction(AuraEffectUpdateFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectUpdateHandler((AuraScript::AuraEffectUpdateFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  605. class EffectUpdatePeriodicHandlerFunction : public AuraScript::EffectUpdatePeriodicHandler { public: EffectUpdatePeriodicHandlerFunction(AuraEffectUpdatePeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectUpdatePeriodicHandler((AuraScript::AuraEffectUpdatePeriodicFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  606. class EffectCalcAmountHandlerFunction : public AuraScript::EffectCalcAmountHandler { public: EffectCalcAmountHandlerFunction(AuraEffectCalcAmountFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectCalcAmountHandler((AuraScript::AuraEffectCalcAmountFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  607. class EffectCalcPeriodicHandlerFunction : public AuraScript::EffectCalcPeriodicHandler { public: EffectCalcPeriodicHandlerFunction(AuraEffectCalcPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectCalcPeriodicHandler((AuraScript::AuraEffectCalcPeriodicFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  608. class EffectCalcSpellModHandlerFunction : public AuraScript::EffectCalcSpellModHandler { public: EffectCalcSpellModHandlerFunction(AuraEffectCalcSpellModFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName) : AuraScript::EffectCalcSpellModHandler((AuraScript::AuraEffectCalcSpellModFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \
  609. class EffectApplyHandlerFunction : public AuraScript::EffectApplyHandler { public: EffectApplyHandlerFunction(AuraEffectApplicationModeFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName, AuraEffectHandleModes _mode) : AuraScript::EffectApplyHandler((AuraScript::AuraEffectApplicationModeFnType)_pEffectHandlerScript, _effIndex, _effName, _mode) {} }; \
  610. class EffectAbsorbFunction : public AuraScript::EffectAbsorbHandler { public: EffectAbsorbFunction(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex) : AuraScript::EffectAbsorbHandler((AuraScript::AuraEffectAbsorbFnType)_pEffectHandlerScript, _effIndex) {} }; \
  611. class EffectManaShieldFunction : public AuraScript::EffectManaShieldHandler { public: EffectManaShieldFunction(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex) : AuraScript::EffectManaShieldHandler((AuraScript::AuraEffectAbsorbFnType)_pEffectHandlerScript, _effIndex) {} }; \
  612. class CheckProcHandlerFunction : public AuraScript::CheckProcHandler { public: CheckProcHandlerFunction(AuraCheckProcFnType handlerScript) : AuraScript::CheckProcHandler((AuraScript::AuraCheckProcFnType)handlerScript) {} }; \
  613. class AuraProcHandlerFunction : public AuraScript::AuraProcHandler { public: AuraProcHandlerFunction(AuraProcFnType handlerScript) : AuraScript::AuraProcHandler((AuraScript::AuraProcFnType)handlerScript) {} }; \
  614. class EffectProcHandlerFunction : public AuraScript::EffectProcHandler { public: EffectProcHandlerFunction(AuraEffectProcFnType effectHandlerScript, uint8 effIndex, uint16 effName) : AuraScript::EffectProcHandler((AuraScript::AuraEffectProcFnType)effectHandlerScript, effIndex, effName) {} }; \
  615.  
  616. #define PrepareAuraScript(CLASSNAME) AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) AURASCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME)
  617.  
  618. public:
  619. AuraScript() : _SpellScript(), m_aura(NULL), m_auraApplication(NULL), m_defaultActionPrevented(false)
  620. {}
  621. bool _Validate(SpellInfo const* entry);
  622. bool _Load(AuraPtr aura);
  623. void _PrepareScriptCall(AuraScriptHookType hookType, AuraApplication const* aurApp = NULL);
  624. void _FinishScriptCall();
  625. bool _IsDefaultActionPrevented();
  626. private:
  627. AuraPtr m_aura;
  628. AuraApplication const* m_auraApplication;
  629. bool m_defaultActionPrevented;
  630.  
  631. class ScriptStateStore
  632. {
  633. public:
  634. uint8 _currentScriptState;
  635. AuraApplication const* _auraApplication;
  636. bool _defaultActionPrevented;
  637. ScriptStateStore(uint8 currentScriptState, AuraApplication const* auraApplication, bool defaultActionPrevented)
  638. : _currentScriptState(currentScriptState), _auraApplication(auraApplication), _defaultActionPrevented(defaultActionPrevented)
  639. {}
  640. };
  641. typedef std::stack<ScriptStateStore> ScriptStateStack;
  642. ScriptStateStack m_scriptStates;
  643.  
  644. public:
  645. //
  646. // AuraScript interface
  647. // hooks to which you can attach your functions
  648. //
  649. // executed when area aura checks if it can be applied on target
  650. // example: OnEffectApply += AuraEffectApplyFn(class::function);
  651. // where function is: bool function (Unit* target);
  652. HookList<CheckAreaTargetHandler> DoCheckAreaTarget;
  653. #define AuraCheckAreaTargetFn(F) CheckAreaTargetFunction(&F)
  654.  
  655. // executed when aura is dispelled by a unit
  656. // example: OnDispel += AuraDispelFn(class::function);
  657. // where function is: void function (DispelInfo* dispelInfo);
  658. HookList<AuraDispelHandler> OnDispel;
  659. // executed after aura is dispelled by a unit
  660. // example: AfterDispel += AuraDispelFn(class::function);
  661. // where function is: void function (DispelInfo* dispelInfo);
  662. HookList<AuraDispelHandler> AfterDispel;
  663. #define AuraDispelFn(F) AuraDispelFunction(&F)
  664.  
  665. // executed when aura effect is applied with specified mode to target
  666. // 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
  667. // example: OnEffectApply += AuraEffectApplyFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
  668. // where function is: void function (constAuraEffectPtr aurEff, AuraEffectHandleModes mode);
  669. HookList<EffectApplyHandler> OnEffectApply;
  670. // executed after aura effect is applied with specified mode to target
  671. // example: AfterEffectApply += AuraEffectApplyFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
  672. // where function is: void function (constAuraEffectPtr aurEff, AuraEffectHandleModes mode);
  673. HookList<EffectApplyHandler> AfterEffectApply;
  674. #define AuraEffectApplyFn(F, I, N, M) EffectApplyHandlerFunction(&F, I, N, M)
  675.  
  676. // executed after aura effect is removed with specified mode from target
  677. // 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
  678. // example: OnEffectRemove += AuraEffectRemoveFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
  679. // where function is: void function (constAuraEffectPtr aurEff, AuraEffectHandleModes mode);
  680. HookList<EffectApplyHandler> OnEffectRemove;
  681. // executed when aura effect is removed with specified mode from target
  682. // example: AfterEffectRemove += AuraEffectRemoveFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
  683. // where function is: void function (constAuraEffectPtr aurEff, AuraEffectHandleModes mode);
  684. HookList<EffectApplyHandler> AfterEffectRemove;
  685. #define AuraEffectRemoveFn(F, I, N, M) EffectApplyHandlerFunction(&F, I, N, M)
  686.  
  687. // executed when periodic aura effect ticks on target
  688. // example: OnEffectPeriodic += AuraEffectPeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  689. // where function is: void function (constAuraEffectPtr aurEff);
  690. HookList<EffectPeriodicHandler> OnEffectPeriodic;
  691. #define AuraEffectPeriodicFn(F, I, N) EffectPeriodicHandlerFunction(&F, I, N)
  692.  
  693. // executed when aura is updated
  694. // example: OnAuraUpdate += AuraUpdateFn(class::function);
  695. // where function is: void function (const uint32 diff);
  696. HookList<AuraUpdateHandler> OnAuraUpdate;
  697. #define AuraUpdateFn(F) AuraUpdateHandlerFunction(&F)
  698.  
  699. // executed when aura effect is updated
  700. // example: OnEffectUpdate += AuraEffectUpdateFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  701. // where function is: void function (AuraEffectPtr aurEff);
  702. HookList<EffectUpdateHandler> OnEffectUpdate;
  703. #define AuraEffectUpdateFn(F, I, N) EffectUpdateHandlerFunction(&F, I, N)
  704.  
  705. // executed when periodic aura effect is updated
  706. // example: OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  707. // where function is: void function (AuraEffectPtr aurEff);
  708. HookList<EffectUpdatePeriodicHandler> OnEffectUpdatePeriodic;
  709. #define AuraEffectUpdatePeriodicFn(F, I, N) EffectUpdatePeriodicHandlerFunction(&F, I, N)
  710.  
  711. // executed when aura effect calculates amount
  712. // example: DoEffectCalcAmount += AuraEffectCalcAmounFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  713. // where function is: void function (AuraEffectPtr aurEff, int32& amount, bool& canBeRecalculated);
  714. HookList<EffectCalcAmountHandler> DoEffectCalcAmount;
  715. #define AuraEffectCalcAmountFn(F, I, N) EffectCalcAmountHandlerFunction(&F, I, N)
  716.  
  717. // executed when aura effect calculates periodic data
  718. // example: DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  719. // where function is: void function (constAuraEffectPtr aurEff, bool& isPeriodic, int32& amplitude);
  720. HookList<EffectCalcPeriodicHandler> DoEffectCalcPeriodic;
  721. #define AuraEffectCalcPeriodicFn(F, I, N) EffectCalcPeriodicHandlerFunction(&F, I, N)
  722.  
  723. // executed when aura effect calculates spellmod
  724. // example: DoEffectCalcSpellMod += AuraEffectCalcSpellModFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  725. // where function is: void function (constAuraEffectPtr aurEff, SpellModifier*& spellMod);
  726. HookList<EffectCalcSpellModHandler> DoEffectCalcSpellMod;
  727. #define AuraEffectCalcSpellModFn(F, I, N) EffectCalcSpellModHandlerFunction(&F, I, N)
  728.  
  729. // executed when absorb aura effect is going to reduce damage
  730. // example: OnEffectAbsorb += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
  731. // where function is: void function (constAuraEffectPtr aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
  732. HookList<EffectAbsorbHandler> OnEffectAbsorb;
  733. #define AuraEffectAbsorbFn(F, I) EffectAbsorbFunction(&F, I)
  734.  
  735. // executed after absorb aura effect reduced damage to target - absorbAmount is real amount absorbed by aura
  736. // example: AfterEffectAbsorb += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
  737. // where function is: void function (AuraEffectPtr aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
  738. HookList<EffectAbsorbHandler> AfterEffectAbsorb;
  739.  
  740. // executed when mana shield aura effect is going to reduce damage
  741. // example: OnEffectManaShield += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
  742. // where function is: void function (AuraEffectPtr aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
  743. HookList<EffectManaShieldHandler> OnEffectManaShield;
  744. #define AuraEffectManaShieldFn(F, I) EffectManaShieldFunction(&F, I)
  745.  
  746. // executed after mana shield aura effect reduced damage to target - absorbAmount is real amount absorbed by aura
  747. // example: AfterEffectManaShield += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
  748. // where function is: void function (AuraEffectPtr aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
  749. HookList<EffectManaShieldHandler> AfterEffectManaShield;
  750.  
  751. // executed when aura checks if it can proc
  752. // example: DoCheckProc += AuraCheckProcFn(class::function);
  753. // where function is: bool function (ProcEventInfo& eventInfo);
  754. HookList<CheckProcHandler> DoCheckProc;
  755. #define AuraCheckProcFn(F) CheckProcHandlerFunction(&F)
  756.  
  757. // executed before aura procs (possibility to prevent charge drop/cooldown)
  758. // example: DoPrepareProc += AuraProcFn(class::function);
  759. // where function is: void function (ProcEventInfo& eventInfo);
  760. HookList<AuraProcHandler> DoPrepareProc;
  761. // executed when aura procs
  762. // example: OnProc += AuraProcFn(class::function);
  763. // where function is: void function (ProcEventInfo& eventInfo);
  764. HookList<AuraProcHandler> OnProc;
  765. // executed after aura proced
  766. // example: AfterProc += AuraProcFn(class::function);
  767. // where function is: void function (ProcEventInfo& eventInfo);
  768. HookList<AuraProcHandler> AfterProc;
  769. #define AuraProcFn(F) AuraProcHandlerFunction(&F)
  770.  
  771. // executed when aura effect procs
  772. // example: OnEffectProc += AuraEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  773. // where function is: void function (AuraEffect const* aurEff, ProcEventInfo& procInfo);
  774. HookList<EffectProcHandler> OnEffectProc;
  775. // executed after aura effect proced
  776. // example: AfterEffectProc += AuraEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
  777. // where function is: void function (AuraEffect const* aurEff, ProcEventInfo& procInfo);
  778. HookList<EffectProcHandler> AfterEffectProc;
  779. #define AuraEffectProcFn(F, I, N) EffectProcHandlerFunction(&F, I, N)
  780.  
  781. // AuraScript interface - hook/effect execution manipulators
  782.  
  783. // prevents default action of a hook from being executed (works only while called in a hook which default action can be prevented)
  784. void PreventDefaultAction();
  785.  
  786. // AuraScript interface - functions which are redirecting to Aura class
  787.  
  788. // returns proto of the spell
  789. SpellInfo const* GetSpellInfo() const;
  790. // returns spellid of the spell
  791. uint32 GetId() const;
  792.  
  793. // returns guid of object which casted the aura (m_originalCaster of the Spell class)
  794. uint64 GetCasterGUID() const;
  795. // returns unit which casted the aura or NULL if not avalible (caster logged out for example)
  796. Unit* GetCaster() const;
  797. // returns object on which aura was casted, target for non-area auras, area aura source for area auras
  798. WorldObject* GetOwner() const;
  799. // returns owner if it's unit or unit derived object, NULL otherwise (only for persistent area auras NULL is returned)
  800. Unit* GetUnitOwner() const;
  801. // returns owner if it's dynobj, NULL otherwise
  802. DynamicObject* GetDynobjOwner() const;
  803.  
  804. // removes aura with remove mode (see AuraRemoveMode enum)
  805. void Remove(uint32 removeMode = 0);
  806. // returns aura object of script
  807. AuraPtr GetAura() const;
  808.  
  809. // returns type of the aura, may be dynobj owned aura or unit owned aura
  810. AuraObjectType GetType() const;
  811.  
  812. // aura duration manipulation - when duration goes to 0 aura is removed
  813. int32 GetDuration() const;
  814. void SetDuration(int32 duration, bool withMods = false);
  815. // sets duration to maxduration
  816. void RefreshDuration();
  817. time_t GetApplyTime() const;
  818. int32 GetMaxDuration() const;
  819. void SetMaxDuration(int32 duration);
  820. int32 CalcMaxDuration() const;
  821. // expired - duration just went to 0
  822. bool IsExpired() const;
  823. // permament - has infinite duration
  824. bool IsPermanent() const;
  825.  
  826. // charges manipulation - 0 - not charged aura
  827. uint8 GetCharges() const;
  828. void SetCharges(uint8 charges);
  829. uint8 CalcMaxCharges() const;
  830. bool ModCharges(int8 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
  831. // returns true if last charge dropped
  832. bool DropCharge(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
  833.  
  834. // stack amount manipulation
  835. uint8 GetStackAmount() const;
  836. void SetStackAmount(uint8 num);
  837. bool ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
  838.  
  839. // passive - "working in background", not saved, not removed by immunities, not seen by player
  840. bool IsPassive() const;
  841. // death persistent - not removed on death
  842. bool IsDeathPersistent() const;
  843.  
  844. // check if aura has effect of given effindex
  845. bool HasEffect(uint8 effIndex) const;
  846. // returns aura effect of given effect index or NULL
  847. AuraEffectPtr GetEffect(uint8 effIndex) const;
  848.  
  849. // check if aura has effect of given aura type
  850. bool HasEffectType(AuraType type) const;
  851.  
  852. // Permit to communicate some data with the script
  853. virtual void SetData(uint32 type, uint32 data) {}
  854.  
  855. // Permit to communicate some uint64 data with the script
  856. virtual void SetGuid(uint32 type, uint64 data) {}
  857.  
  858. // AuraScript interface - functions which are redirecting to AuraApplication class
  859. // Do not call these in hooks in which AuraApplication is not avalible, otherwise result will differ from expected (the functions will return NULL)
  860.  
  861. // returns currently processed target of an aura
  862. // Return value does not need to be NULL-checked, the only situation this will (always)
  863. // return NULL is when the call happens in an unsupported hook, in other cases, it is always valid
  864. Unit* GetTarget() const;
  865. // returns AuraApplication object of currently processed target
  866. AuraApplication const* GetTargetApplication() const;
  867. };
  868.  
  869. //
  870. // definitions:
  871. //
  872. // EffectIndexSpecifier - specifies conditions for effects
  873. // EFFECT_0 - first effect matches
  874. // EFFECT_1 - second effect matches
  875. // EFFECT_2 - third effect matches
  876. // EFFECT_FIRST_FOUND - first effect matching other conditions matches
  877. // EFFECT_ALL - all effects of spell match
  878. //
  879. // EffectNameSpecifier - specifies conditions for spell effect names
  880. // SPELL_EFFECT_ANY - any effect but not 0 matches condition
  881. // SPELL_EFFECT_XXX - one of values of enum SpellEffects - effect with equal name matches
  882. //
  883.  
  884. #endif // __SPELL_SCRIPT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement