Advertisement
Guest User

Untitled

a guest
Mar 20th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.57 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. #include <string>
  19. #include "Spell.h"
  20. #include "SpellAuras.h"
  21. #include "SpellScript.h"
  22. #include "SpellMgr.h"
  23.  
  24. bool _SpellScript::_Validate(SpellInfo const* entry)
  25. {
  26. if (!Validate(entry))
  27. {
  28. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` did not pass Validate() function of script `%s` - script will be not added to the spell", entry->Id, m_scriptName->c_str());
  29. return false;
  30. }
  31. return true;
  32. }
  33.  
  34. void _SpellScript::_Register()
  35. {
  36. m_currentScriptState = SPELL_SCRIPT_STATE_REGISTRATION;
  37. Register();
  38. m_currentScriptState = SPELL_SCRIPT_STATE_NONE;
  39. }
  40.  
  41. void _SpellScript::_Unload()
  42. {
  43. m_currentScriptState = SPELL_SCRIPT_STATE_UNLOADING;
  44. Unload();
  45. m_currentScriptState = SPELL_SCRIPT_STATE_NONE;
  46. }
  47.  
  48. void _SpellScript::_Init(std::string const* scriptname, uint32 spellId)
  49. {
  50. m_currentScriptState = SPELL_SCRIPT_STATE_NONE;
  51. m_scriptName = scriptname;
  52. m_scriptSpellId = spellId;
  53. }
  54.  
  55. std::string const* _SpellScript::_GetScriptName() const
  56. {
  57. return m_scriptName;
  58. }
  59.  
  60. _SpellScript::EffectHook::EffectHook(uint8 _effIndex)
  61. {
  62. // effect index must be in range <0;2>, allow use of special effindexes
  63. ASSERT(_effIndex == EFFECT_ALL || _effIndex == EFFECT_FIRST_FOUND || _effIndex < MAX_SPELL_EFFECTS);
  64. effIndex = _effIndex;
  65. }
  66.  
  67. uint32 _SpellScript::EffectHook::GetAffectedEffectsMask(SpellInfo const* spellEntry)
  68. {
  69. uint32 mask = 0;
  70. if ((effIndex == EFFECT_ALL) || (effIndex == EFFECT_FIRST_FOUND))
  71. {
  72. for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
  73. {
  74. if ((effIndex == EFFECT_FIRST_FOUND) && mask)
  75. return mask;
  76. if (CheckEffect(spellEntry, i))
  77. mask |= 1<<i;
  78. }
  79. }
  80. else
  81. {
  82. if (CheckEffect(spellEntry, effIndex))
  83. mask |= (uint8)1<<effIndex;
  84. }
  85. return mask;
  86. }
  87.  
  88. bool _SpellScript::EffectHook::IsEffectAffected(SpellInfo const* spellEntry, uint8 effIndex)
  89. {
  90. return GetAffectedEffectsMask(spellEntry) & 1<<effIndex;
  91. }
  92.  
  93. std::string _SpellScript::EffectHook::EffIndexToString()
  94. {
  95. switch (effIndex)
  96. {
  97. case EFFECT_ALL:
  98. return "EFFECT_ALL";
  99. case EFFECT_FIRST_FOUND:
  100. return "EFFECT_FIRST_FOUND";
  101. case EFFECT_0:
  102. return "EFFECT_0";
  103. case EFFECT_1:
  104. return "EFFECT_1";
  105. case EFFECT_2:
  106. return "EFFECT_2";
  107. }
  108. return "Invalid Value";
  109. }
  110.  
  111. bool _SpellScript::EffectNameCheck::Check(SpellInfo const* spellEntry, uint8 effIndex)
  112. {
  113. if (!spellEntry->Effects[effIndex].Effect && !effName)
  114. return true;
  115. if (!spellEntry->Effects[effIndex].Effect)
  116. return false;
  117. return (effName == SPELL_EFFECT_ANY) || (spellEntry->Effects[effIndex].Effect == effName);
  118. }
  119.  
  120. std::string _SpellScript::EffectNameCheck::ToString()
  121. {
  122. switch (effName)
  123. {
  124. case SPELL_EFFECT_ANY:
  125. return "SPELL_EFFECT_ANY";
  126. default:
  127. char num[10];
  128. sprintf (num, "%u", effName);
  129. return num;
  130. }
  131. }
  132.  
  133. bool _SpellScript::EffectAuraNameCheck::Check(SpellInfo const* spellEntry, uint8 effIndex)
  134. {
  135. if (!spellEntry->Effects[effIndex].ApplyAuraName && !effAurName)
  136. return true;
  137. if (!spellEntry->Effects[effIndex].ApplyAuraName)
  138. return false;
  139. return (effAurName == SPELL_EFFECT_ANY) || (spellEntry->Effects[effIndex].ApplyAuraName == effAurName);
  140. }
  141.  
  142. std::string _SpellScript::EffectAuraNameCheck::ToString()
  143. {
  144. switch (effAurName)
  145. {
  146. case SPELL_AURA_ANY:
  147. return "SPELL_AURA_ANY";
  148. default:
  149. char num[10];
  150. sprintf (num, "%u", effAurName);
  151. return num;
  152. }
  153. }
  154.  
  155. SpellScript::CastHandler::CastHandler(SpellCastFnType _pCastHandlerScript)
  156. {
  157. pCastHandlerScript = _pCastHandlerScript;
  158. }
  159.  
  160. void SpellScript::CastHandler::Call(SpellScript* spellScript)
  161. {
  162. (spellScript->*pCastHandlerScript)();
  163. }
  164.  
  165. SpellScript::CheckCastHandler::CheckCastHandler(SpellCheckCastFnType checkCastHandlerScript)
  166. {
  167. _checkCastHandlerScript = checkCastHandlerScript;
  168. }
  169.  
  170. SpellCastResult SpellScript::CheckCastHandler::Call(SpellScript* spellScript)
  171. {
  172. return (spellScript->*_checkCastHandlerScript)();
  173. }
  174.  
  175. SpellScript::EffectHandler::EffectHandler(SpellEffectFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  176. : _SpellScript::EffectNameCheck(_effName), _SpellScript::EffectHook(_effIndex)
  177. {
  178. pEffectHandlerScript = _pEffectHandlerScript;
  179. }
  180.  
  181. std::string SpellScript::EffectHandler::ToString()
  182. {
  183. return "Index: " + EffIndexToString() + " Name: " +_SpellScript::EffectNameCheck::ToString();
  184. }
  185.  
  186. bool SpellScript::EffectHandler::CheckEffect(SpellInfo const* spellEntry, uint8 effIndex)
  187. {
  188. return _SpellScript::EffectNameCheck::Check(spellEntry, effIndex);
  189. }
  190.  
  191. void SpellScript::EffectHandler::Call(SpellScript* spellScript, SpellEffIndex effIndex)
  192. {
  193. (spellScript->*pEffectHandlerScript)(effIndex);
  194. }
  195.  
  196. SpellScript::HitHandler::HitHandler(SpellHitFnType _pHitHandlerScript)
  197. {
  198. pHitHandlerScript = _pHitHandlerScript;
  199. }
  200.  
  201. void SpellScript::HitHandler::Call(SpellScript* spellScript)
  202. {
  203. (spellScript->*pHitHandlerScript)();
  204. }
  205.  
  206. SpellScript::TargetHook::TargetHook(uint8 _effectIndex, uint16 _targetType, bool _area)
  207. : _SpellScript::EffectHook(_effectIndex), targetType(_targetType), area(_area)
  208. {
  209. }
  210.  
  211. std::string SpellScript::TargetHook::ToString()
  212. {
  213. std::ostringstream oss;
  214. oss << "Index: " << EffIndexToString() << " Target: " << targetType;
  215. return oss.str();
  216. }
  217.  
  218. bool SpellScript::TargetHook::CheckEffect(SpellInfo const* spellEntry, uint8 effIndex)
  219. {
  220. if (!targetType)
  221. return false;
  222.  
  223. if (spellEntry->Effects[effIndex].TargetA.GetTarget() != targetType &&
  224. spellEntry->Effects[effIndex].TargetB.GetTarget() != targetType)
  225. return false;
  226.  
  227. SpellImplicitTargetInfo targetInfo(targetType);
  228. switch (targetInfo.GetSelectionCategory())
  229. {
  230. case TARGET_SELECT_CATEGORY_CHANNEL: // SINGLE
  231. return !area;
  232. case TARGET_SELECT_CATEGORY_NEARBY: // BOTH
  233. return true;
  234. case TARGET_SELECT_CATEGORY_CONE: // AREA
  235. case TARGET_SELECT_CATEGORY_AREA: // AREA
  236. return area;
  237. case TARGET_SELECT_CATEGORY_DEFAULT:
  238. switch (targetInfo.GetObjectType())
  239. {
  240. case TARGET_OBJECT_TYPE_SRC: // EMPTY
  241. case TARGET_OBJECT_TYPE_DEST: // EMPTY
  242. return false;
  243. default:
  244. switch (targetInfo.GetReferenceType())
  245. {
  246. case TARGET_REFERENCE_TYPE_CASTER: // SINGLE
  247. return !area;
  248. case TARGET_REFERENCE_TYPE_TARGET: // BOTH
  249. return true;
  250. default:
  251. break;
  252. }
  253. break;
  254. }
  255. break;
  256. default:
  257. break;
  258. }
  259.  
  260. return false;
  261. }
  262.  
  263. SpellScript::ObjectAreaTargetSelectHandler::ObjectAreaTargetSelectHandler(SpellObjectAreaTargetSelectFnType _pObjectAreaTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType)
  264. : TargetHook(_effIndex, _targetType, true)
  265. {
  266. pObjectAreaTargetSelectHandlerScript = _pObjectAreaTargetSelectHandlerScript;
  267. }
  268.  
  269. void SpellScript::ObjectAreaTargetSelectHandler::Call(SpellScript* spellScript, std::list<WorldObject*>& targets)
  270. {
  271. (spellScript->*pObjectAreaTargetSelectHandlerScript)(targets);
  272. }
  273.  
  274. SpellScript::ObjectTargetSelectHandler::ObjectTargetSelectHandler(SpellObjectTargetSelectFnType _pObjectTargetSelectHandlerScript, uint8 _effIndex, uint16 _targetType)
  275. : TargetHook(_effIndex, _targetType, false)
  276. {
  277. pObjectTargetSelectHandlerScript = _pObjectTargetSelectHandlerScript;
  278. }
  279.  
  280. void SpellScript::ObjectTargetSelectHandler::Call(SpellScript* spellScript, WorldObject*& target)
  281. {
  282. (spellScript->*pObjectTargetSelectHandlerScript)(target);
  283. }
  284.  
  285. bool SpellScript::_Validate(SpellInfo const* entry)
  286. {
  287. for (std::list<EffectHandler>::iterator itr = OnEffectLaunch.begin(); itr != OnEffectLaunch.end(); ++itr)
  288. if (!(*itr).GetAffectedEffectsMask(entry))
  289. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectLaunch` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  290.  
  291. for (std::list<EffectHandler>::iterator itr = OnEffectLaunchTarget.begin(); itr != OnEffectLaunchTarget.end(); ++itr)
  292. if (!(*itr).GetAffectedEffectsMask(entry))
  293. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectLaunchTarget` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  294.  
  295. for (std::list<EffectHandler>::iterator itr = OnEffectHit.begin(); itr != OnEffectHit.end(); ++itr)
  296. if (!(*itr).GetAffectedEffectsMask(entry))
  297. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectHit` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  298.  
  299. for (std::list<EffectHandler>::iterator itr = OnEffectHitTarget.begin(); itr != OnEffectHitTarget.end(); ++itr)
  300. if (!(*itr).GetAffectedEffectsMask(entry))
  301. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectHitTarget` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  302.  
  303. for (std::list<ObjectAreaTargetSelectHandler>::iterator itr = OnObjectAreaTargetSelect.begin(); itr != OnObjectAreaTargetSelect.end(); ++itr)
  304. if (!(*itr).GetAffectedEffectsMask(entry))
  305. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnObjectAreaTargetSelect` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  306.  
  307. for (std::list<ObjectTargetSelectHandler>::iterator itr = OnObjectTargetSelect.begin(); itr != OnObjectTargetSelect.end(); ++itr)
  308. if (!(*itr).GetAffectedEffectsMask(entry))
  309. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnObjectTargetSelect` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  310.  
  311. return _SpellScript::_Validate(entry);
  312. }
  313.  
  314. bool SpellScript::_Load(Spell* spell)
  315. {
  316. m_spell = spell;
  317. _PrepareScriptCall((SpellScriptHookType)SPELL_SCRIPT_STATE_LOADING);
  318. bool load = Load();
  319. _FinishScriptCall();
  320. return load;
  321. }
  322.  
  323. void SpellScript::_InitHit()
  324. {
  325. m_hitPreventEffectMask = 0;
  326. m_hitPreventDefaultEffectMask = 0;
  327. }
  328.  
  329. void SpellScript::_PrepareScriptCall(SpellScriptHookType hookType)
  330. {
  331. m_currentScriptState = hookType;
  332. }
  333.  
  334. void SpellScript::_FinishScriptCall()
  335. {
  336. m_currentScriptState = SPELL_SCRIPT_STATE_NONE;
  337. }
  338.  
  339. bool SpellScript::IsInCheckCastHook() const
  340. {
  341. return m_currentScriptState == SPELL_SCRIPT_HOOK_CHECK_CAST;
  342. }
  343. bool SpellScript::IsInTargetHook() const
  344. {
  345. switch (m_currentScriptState)
  346. {
  347. case SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET:
  348. case SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET:
  349. case SPELL_SCRIPT_HOOK_BEFORE_HIT:
  350. case SPELL_SCRIPT_HOOK_HIT:
  351. case SPELL_SCRIPT_HOOK_AFTER_HIT:
  352. return true;
  353. }
  354. return false;
  355. }
  356. bool SpellScript::IsInHitPhase() const
  357. {
  358. return (m_currentScriptState >= HOOK_SPELL_HIT_START && m_currentScriptState < HOOK_SPELL_HIT_END);
  359. }
  360.  
  361. bool SpellScript::IsInEffectHook() const
  362. {
  363. return (m_currentScriptState >= SPELL_SCRIPT_HOOK_EFFECT_LAUNCH && m_currentScriptState <= SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET);
  364. }
  365.  
  366. Unit* SpellScript::GetCaster()
  367. {
  368. return m_spell->GetCaster();
  369. }
  370.  
  371. Unit* SpellScript::GetOriginalCaster()
  372. {
  373. return m_spell->GetOriginalCaster();
  374. }
  375.  
  376. SpellInfo const* SpellScript::GetSpellInfo()
  377. {
  378. return m_spell->GetSpellInfo();
  379. }
  380.  
  381. WorldLocation const* SpellScript::GetExplTargetDest()
  382. {
  383. if (m_spell->m_targets.HasDst())
  384. return m_spell->m_targets.GetDstPos();
  385. return NULL;
  386. }
  387.  
  388. void SpellScript::SetExplTargetDest(WorldLocation& loc)
  389. {
  390. m_spell->m_targets.SetDst(loc);
  391. }
  392.  
  393. WorldObject* SpellScript::GetExplTargetWorldObject()
  394. {
  395. return m_spell->m_targets.GetObjectTarget();
  396. }
  397.  
  398. Unit* SpellScript::GetExplTargetUnit()
  399. {
  400. return m_spell->m_targets.GetUnitTarget();
  401. }
  402.  
  403. GameObject* SpellScript::GetExplTargetGObj()
  404. {
  405. return m_spell->m_targets.GetGOTarget();
  406. }
  407.  
  408. Item* SpellScript::GetExplTargetItem()
  409. {
  410. return m_spell->m_targets.GetItemTarget();
  411. }
  412.  
  413. Unit* SpellScript::GetHitUnit()
  414. {
  415. if (!IsInTargetHook())
  416. {
  417. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitUnit was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  418. return NULL;
  419. }
  420. return m_spell->unitTarget;
  421. }
  422.  
  423. Creature* SpellScript::GetHitCreature()
  424. {
  425. if (!IsInTargetHook())
  426. {
  427. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitCreature was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  428. return NULL;
  429. }
  430. if (m_spell->unitTarget)
  431. return m_spell->unitTarget->ToCreature();
  432. else
  433. return NULL;
  434. }
  435.  
  436. Player* SpellScript::GetHitPlayer()
  437. {
  438. if (!IsInTargetHook())
  439. {
  440. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitPlayer was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  441. return NULL;
  442. }
  443. if (m_spell->unitTarget)
  444. return m_spell->unitTarget->ToPlayer();
  445. else
  446. return NULL;
  447. }
  448.  
  449. Item* SpellScript::GetHitItem()
  450. {
  451. if (!IsInTargetHook())
  452. {
  453. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitItem was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  454. return NULL;
  455. }
  456. return m_spell->itemTarget;
  457. }
  458.  
  459. GameObject* SpellScript::GetHitGObj()
  460. {
  461. if (!IsInTargetHook())
  462. {
  463. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitGObj was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  464. return NULL;
  465. }
  466. return m_spell->gameObjTarget;
  467. }
  468.  
  469. WorldLocation* SpellScript::GetHitDest()
  470. {
  471. if (!IsInEffectHook())
  472. {
  473. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitDest was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  474. return NULL;
  475. }
  476. return m_spell->destTarget;
  477. }
  478.  
  479. int32 SpellScript::GetHitDamage()
  480. {
  481. if (!IsInTargetHook())
  482. {
  483. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitDamage was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  484. return 0;
  485. }
  486. return m_spell->m_damage;
  487. }
  488.  
  489. void SpellScript::SetHitDamage(int32 damage)
  490. {
  491. if (!IsInTargetHook())
  492. {
  493. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::SetHitDamage was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  494. return;
  495. }
  496. m_spell->m_damage = damage;
  497. }
  498.  
  499. int32 SpellScript::GetHitHeal()
  500. {
  501. if (!IsInTargetHook())
  502. {
  503. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitHeal was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  504. return 0;
  505. }
  506. return m_spell->m_healing;
  507. }
  508.  
  509. void SpellScript::SetHitHeal(int32 heal)
  510. {
  511. if (!IsInTargetHook())
  512. {
  513. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::SetHitHeal was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  514. return;
  515. }
  516. m_spell->m_healing = heal;
  517. }
  518.  
  519. AuraPtr SpellScript::GetHitAura()
  520. {
  521. if (!IsInTargetHook())
  522. {
  523. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::GetHitAura was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  524. return NULLAURA;
  525. }
  526. if (!m_spell->m_spellAura)
  527. return NULLAURA;
  528. if (m_spell->m_spellAura->IsRemoved())
  529. return NULLAURA;
  530. return m_spell->m_spellAura;
  531. }
  532.  
  533. void SpellScript::PreventHitAura()
  534. {
  535. if (!IsInTargetHook())
  536. {
  537. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::PreventHitAura was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  538. return;
  539. }
  540. if (m_spell->m_spellAura)
  541. m_spell->m_spellAura->Remove();
  542. }
  543.  
  544. void SpellScript::PreventHitEffect(SpellEffIndex effIndex)
  545. {
  546. if (!IsInHitPhase() && !IsInEffectHook())
  547. {
  548. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::PreventHitEffect was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  549. return;
  550. }
  551. m_hitPreventEffectMask |= 1 << effIndex;
  552. PreventHitDefaultEffect(effIndex);
  553. }
  554.  
  555. void SpellScript::PreventHitDefaultEffect(SpellEffIndex effIndex)
  556. {
  557. if (!IsInHitPhase() && !IsInEffectHook())
  558. {
  559. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::PreventHitDefaultEffect was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  560. return;
  561. }
  562. m_hitPreventDefaultEffectMask |= 1 << effIndex;
  563. }
  564.  
  565. int32 SpellScript::GetEffectValue()
  566. {
  567. if (!IsInEffectHook())
  568. {
  569. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::PreventHitDefaultEffect was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
  570. return 0;
  571. }
  572. return m_spell->damage;
  573. }
  574.  
  575. Item* SpellScript::GetCastItem()
  576. {
  577. return m_spell->m_CastItem;
  578. }
  579.  
  580. void SpellScript::CreateItem(uint32 effIndex, uint32 itemId)
  581. {
  582. m_spell->DoCreateItem(effIndex, itemId);
  583. }
  584.  
  585. SpellInfo const* SpellScript::GetTriggeringSpell()
  586. {
  587. return m_spell->m_triggeredByAuraSpell;
  588. }
  589.  
  590. void SpellScript::FinishCast(SpellCastResult result)
  591. {
  592. m_spell->SendCastResult(result);
  593. m_spell->finish(result == SPELL_CAST_OK);
  594. }
  595.  
  596. void SpellScript::SetCustomCastResultMessage(SpellCustomErrors result)
  597. {
  598. if (!IsInCheckCastHook())
  599. {
  600. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u`: function SpellScript::SetCustomCastResultMessage was called while spell not in check cast phase!", m_scriptName->c_str(), m_scriptSpellId);
  601. return;
  602. }
  603.  
  604. m_spell->m_customError = result;
  605. }
  606.  
  607. SpellValue const* SpellScript::GetSpellValue()
  608. {
  609. return m_spell->m_spellValue;
  610. }
  611.  
  612. bool AuraScript::_Validate(SpellInfo const* entry)
  613. {
  614. for (std::list<CheckAreaTargetHandler>::iterator itr = DoCheckAreaTarget.begin(); itr != DoCheckAreaTarget.end(); ++itr)
  615. if (!entry->HasAreaAuraEffect())
  616. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have area aura effect - handler bound to hook `DoCheckAreaTarget` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  617.  
  618. for (std::list<AuraDispelHandler>::iterator itr = OnDispel.begin(); itr != OnDispel.end(); ++itr)
  619. if (!entry->HasEffect(SPELL_EFFECT_APPLY_AURA) && !entry->HasAreaAuraEffect())
  620. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have apply aura effect - handler bound to hook `OnDispel` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  621.  
  622. for (std::list<AuraDispelHandler>::iterator itr = AfterDispel.begin(); itr != AfterDispel.end(); ++itr)
  623. if (!entry->HasEffect(SPELL_EFFECT_APPLY_AURA) && !entry->HasAreaAuraEffect())
  624. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have apply aura effect - handler bound to hook `AfterDispel` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  625.  
  626. for (std::list<EffectApplyHandler>::iterator itr = OnEffectApply.begin(); itr != OnEffectApply.end(); ++itr)
  627. if (!(*itr).GetAffectedEffectsMask(entry))
  628. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectApply` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  629.  
  630. for (std::list<EffectApplyHandler>::iterator itr = OnEffectRemove.begin(); itr != OnEffectRemove.end(); ++itr)
  631. if (!(*itr).GetAffectedEffectsMask(entry))
  632. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectRemove` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  633.  
  634. for (std::list<EffectApplyHandler>::iterator itr = AfterEffectApply.begin(); itr != AfterEffectApply.end(); ++itr)
  635. if (!(*itr).GetAffectedEffectsMask(entry))
  636. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `AfterEffectApply` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  637.  
  638. for (std::list<EffectApplyHandler>::iterator itr = AfterEffectRemove.begin(); itr != AfterEffectRemove.end(); ++itr)
  639. if (!(*itr).GetAffectedEffectsMask(entry))
  640. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `AfterEffectRemove` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  641.  
  642. for (std::list<EffectPeriodicHandler>::iterator itr = OnEffectPeriodic.begin(); itr != OnEffectPeriodic.end(); ++itr)
  643. if (!(*itr).GetAffectedEffectsMask(entry))
  644. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectPeriodic` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  645.  
  646. for (std::list<EffectUpdatePeriodicHandler>::iterator itr = OnEffectUpdatePeriodic.begin(); itr != OnEffectUpdatePeriodic.end(); ++itr)
  647. if (!(*itr).GetAffectedEffectsMask(entry))
  648. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectUpdatePeriodic` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  649.  
  650. for (std::list<EffectCalcAmountHandler>::iterator itr = DoEffectCalcAmount.begin(); itr != DoEffectCalcAmount.end(); ++itr)
  651. if (!(*itr).GetAffectedEffectsMask(entry))
  652. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `DoEffectCalcAmount` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  653.  
  654. for (std::list<EffectCalcPeriodicHandler>::iterator itr = DoEffectCalcPeriodic.begin(); itr != DoEffectCalcPeriodic.end(); ++itr)
  655. if (!(*itr).GetAffectedEffectsMask(entry))
  656. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `DoEffectCalcPeriodic` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  657.  
  658. for (std::list<EffectCalcSpellModHandler>::iterator itr = DoEffectCalcSpellMod.begin(); itr != DoEffectCalcSpellMod.end(); ++itr)
  659. if (!(*itr).GetAffectedEffectsMask(entry))
  660. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `DoEffectCalcSpellMod` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  661.  
  662. for (std::list<EffectAbsorbHandler>::iterator itr = OnEffectAbsorb.begin(); itr != OnEffectAbsorb.end(); ++itr)
  663. if (!(*itr).GetAffectedEffectsMask(entry))
  664. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectAbsorb` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  665.  
  666. for (std::list<EffectAbsorbHandler>::iterator itr = AfterEffectAbsorb.begin(); itr != AfterEffectAbsorb.end(); ++itr)
  667. if (!(*itr).GetAffectedEffectsMask(entry))
  668. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `AfterEffectAbsorb` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  669.  
  670. for (std::list<EffectManaShieldHandler>::iterator itr = OnEffectManaShield.begin(); itr != OnEffectManaShield.end(); ++itr)
  671. if (!(*itr).GetAffectedEffectsMask(entry))
  672. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectManaShield` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  673.  
  674. for (std::list<EffectManaShieldHandler>::iterator itr = AfterEffectManaShield.begin(); itr != AfterEffectManaShield.end(); ++itr)
  675. if (!(*itr).GetAffectedEffectsMask(entry))
  676. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `AfterEffectManaShield` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  677.  
  678. for (std::list<CheckProcHandler>::iterator itr = DoCheckProc.begin(); itr != DoCheckProc.end(); ++itr)
  679. if (!entry->HasEffect(SPELL_EFFECT_APPLY_AURA) && !entry->HasAreaAuraEffect())
  680. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have apply aura effect - handler bound to hook `DoCheckProc` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  681.  
  682. for (std::list<AuraProcHandler>::iterator itr = DoPrepareProc.begin(); itr != DoPrepareProc.end(); ++itr)
  683. if (!entry->HasEffect(SPELL_EFFECT_APPLY_AURA) && !entry->HasAreaAuraEffect())
  684. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have apply aura effect - handler bound to hook `DoPrepareProc` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  685.  
  686. for (std::list<AuraProcHandler>::iterator itr = OnProc.begin(); itr != OnProc.end(); ++itr)
  687. if (!entry->HasEffect(SPELL_EFFECT_APPLY_AURA) && !entry->HasAreaAuraEffect())
  688. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have apply aura effect - handler bound to hook `OnProc` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  689.  
  690. for (std::list<AuraProcHandler>::iterator itr = AfterProc.begin(); itr != AfterProc.end(); ++itr)
  691. if (!entry->HasEffect(SPELL_EFFECT_APPLY_AURA) && !entry->HasAreaAuraEffect())
  692. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` of script `%s` does not have apply aura effect - handler bound to hook `AfterProc` of AuraScript won't be executed", entry->Id, m_scriptName->c_str());
  693.  
  694. for (std::list<EffectProcHandler>::iterator itr = OnEffectProc.begin(); itr != OnEffectProc.end(); ++itr)
  695. if (!(*itr).GetAffectedEffectsMask(entry))
  696. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectProc` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  697.  
  698. for (std::list<EffectProcHandler>::iterator itr = AfterEffectProc.begin(); itr != AfterEffectProc.end(); ++itr)
  699. if (!(*itr).GetAffectedEffectsMask(entry))
  700. sLog->outError(LOG_FILTER_TSCR, "Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `AfterEffectProc` of AuraScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str());
  701.  
  702.  
  703. return _SpellScript::_Validate(entry);
  704. }
  705.  
  706. AuraScript::CheckAreaTargetHandler::CheckAreaTargetHandler(AuraCheckAreaTargetFnType _pHandlerScript)
  707. {
  708. pHandlerScript = _pHandlerScript;
  709. }
  710.  
  711. bool AuraScript::CheckAreaTargetHandler::Call(AuraScript* auraScript, Unit* _target)
  712. {
  713. return (auraScript->*pHandlerScript)(_target);
  714. }
  715.  
  716. AuraScript::AuraDispelHandler::AuraDispelHandler(AuraDispelFnType _pHandlerScript)
  717. {
  718. pHandlerScript = _pHandlerScript;
  719. }
  720.  
  721. void AuraScript::AuraDispelHandler::Call(AuraScript* auraScript, DispelInfo* _dispelInfo)
  722. {
  723. (auraScript->*pHandlerScript)(_dispelInfo);
  724. }
  725.  
  726. AuraScript::EffectBase::EffectBase(uint8 _effIndex, uint16 _effName)
  727. : _SpellScript::EffectAuraNameCheck(_effName), _SpellScript::EffectHook(_effIndex)
  728. {
  729. }
  730.  
  731. bool AuraScript::EffectBase::CheckEffect(SpellInfo const* spellEntry, uint8 effIndex)
  732. {
  733. return _SpellScript::EffectAuraNameCheck::Check(spellEntry, effIndex);
  734. }
  735.  
  736. std::string AuraScript::EffectBase::ToString()
  737. {
  738. return "Index: " + EffIndexToString() + " AuraName: " +_SpellScript::EffectAuraNameCheck::ToString();
  739. }
  740.  
  741. AuraScript::EffectPeriodicHandler::EffectPeriodicHandler(AuraEffectPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  742. : AuraScript::EffectBase(_effIndex, _effName)
  743. {
  744. pEffectHandlerScript = _pEffectHandlerScript;
  745. }
  746.  
  747. void AuraScript::EffectPeriodicHandler::Call(AuraScript* auraScript, constAuraEffectPtr _aurEff)
  748. {
  749. (auraScript->*pEffectHandlerScript)(_aurEff);
  750. }
  751.  
  752. AuraScript::AuraUpdateHandler::AuraUpdateHandler(AuraUpdateFnType _pEffectHandlerScript)
  753. {
  754. pEffectHandlerScript = _pEffectHandlerScript;
  755. }
  756.  
  757. void AuraScript::AuraUpdateHandler::Call(AuraScript* auraScript, uint32 diff)
  758. {
  759. (auraScript->*pEffectHandlerScript)(diff);
  760. }
  761.  
  762. AuraScript::EffectUpdateHandler::EffectUpdateHandler(AuraEffectUpdateFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  763. : AuraScript::EffectBase(_effIndex, _effName)
  764. {
  765. pEffectHandlerScript = _pEffectHandlerScript;
  766. }
  767.  
  768. void AuraScript::EffectUpdateHandler::Call(AuraScript* auraScript, uint32 diff, AuraEffectPtr aurEff)
  769. {
  770. (auraScript->*pEffectHandlerScript)(diff, aurEff);
  771. }
  772.  
  773. AuraScript::EffectUpdatePeriodicHandler::EffectUpdatePeriodicHandler(AuraEffectUpdatePeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  774. : AuraScript::EffectBase(_effIndex, _effName)
  775. {
  776. pEffectHandlerScript = _pEffectHandlerScript;
  777. }
  778.  
  779. void AuraScript::EffectUpdatePeriodicHandler::Call(AuraScript* auraScript, AuraEffectPtr aurEff)
  780. {
  781. (auraScript->*pEffectHandlerScript)(aurEff);
  782. }
  783.  
  784. AuraScript::EffectCalcAmountHandler::EffectCalcAmountHandler(AuraEffectCalcAmountFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  785. : AuraScript::EffectBase(_effIndex, _effName)
  786. {
  787. pEffectHandlerScript = _pEffectHandlerScript;
  788. }
  789.  
  790. void AuraScript::EffectCalcAmountHandler::Call(AuraScript* auraScript, constAuraEffectPtr aurEff, int32& amount, bool& canBeRecalculated)
  791. {
  792. (auraScript->*pEffectHandlerScript)(aurEff, amount, canBeRecalculated);
  793. }
  794.  
  795. AuraScript::EffectCalcPeriodicHandler::EffectCalcPeriodicHandler(AuraEffectCalcPeriodicFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  796. : AuraScript::EffectBase(_effIndex, _effName)
  797. {
  798. pEffectHandlerScript = _pEffectHandlerScript;
  799. }
  800.  
  801. void AuraScript::EffectCalcPeriodicHandler::Call(AuraScript* auraScript, constAuraEffectPtr aurEff, bool& isPeriodic, int32& periodicTimer)
  802. {
  803. (auraScript->*pEffectHandlerScript)(aurEff, isPeriodic, periodicTimer);
  804. }
  805.  
  806. AuraScript::EffectCalcSpellModHandler::EffectCalcSpellModHandler(AuraEffectCalcSpellModFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName)
  807. : AuraScript::EffectBase(_effIndex, _effName)
  808. {
  809. pEffectHandlerScript = _pEffectHandlerScript;
  810. }
  811.  
  812. void AuraScript::EffectCalcSpellModHandler::Call(AuraScript* auraScript, constAuraEffectPtr aurEff, SpellModifier*& spellMod)
  813. {
  814. (auraScript->*pEffectHandlerScript)(aurEff, spellMod);
  815. }
  816.  
  817. AuraScript::EffectApplyHandler::EffectApplyHandler(AuraEffectApplicationModeFnType _pEffectHandlerScript, uint8 _effIndex, uint16 _effName, AuraEffectHandleModes _mode)
  818. : AuraScript::EffectBase(_effIndex, _effName)
  819. {
  820. pEffectHandlerScript = _pEffectHandlerScript;
  821. mode = _mode;
  822. }
  823.  
  824. void AuraScript::EffectApplyHandler::Call(AuraScript* auraScript, constAuraEffectPtr _aurEff, AuraEffectHandleModes _mode)
  825. {
  826. if (_mode & mode)
  827. (auraScript->*pEffectHandlerScript)(_aurEff, _mode);
  828. }
  829.  
  830. AuraScript::EffectAbsorbHandler::EffectAbsorbHandler(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex)
  831. : AuraScript::EffectBase(_effIndex, SPELL_AURA_SCHOOL_ABSORB)
  832. {
  833. pEffectHandlerScript = _pEffectHandlerScript;
  834. }
  835.  
  836. void AuraScript::EffectAbsorbHandler::Call(AuraScript* auraScript, AuraEffectPtr aurEff, DamageInfo& dmgInfo, uint32& absorbAmount)
  837. {
  838. (auraScript->*pEffectHandlerScript)(aurEff, dmgInfo, absorbAmount);
  839. }
  840.  
  841. AuraScript::EffectManaShieldHandler::EffectManaShieldHandler(AuraEffectAbsorbFnType _pEffectHandlerScript, uint8 _effIndex)
  842. : AuraScript::EffectBase(_effIndex, SPELL_AURA_MANA_SHIELD)
  843. {
  844. pEffectHandlerScript = _pEffectHandlerScript;
  845. }
  846.  
  847. void AuraScript::EffectManaShieldHandler::Call(AuraScript* auraScript, AuraEffectPtr aurEff, DamageInfo& dmgInfo, uint32& absorbAmount)
  848. {
  849. (auraScript->*pEffectHandlerScript)(aurEff, dmgInfo, absorbAmount);
  850. }
  851.  
  852. AuraScript::CheckProcHandler::CheckProcHandler(AuraCheckProcFnType handlerScript)
  853. {
  854. _HandlerScript = handlerScript;
  855. }
  856.  
  857. bool AuraScript::CheckProcHandler::Call(AuraScript* auraScript, ProcEventInfo& eventInfo)
  858. {
  859. return (auraScript->*_HandlerScript)(eventInfo);
  860. }
  861.  
  862. AuraScript::AuraProcHandler::AuraProcHandler(AuraProcFnType handlerScript)
  863. {
  864. _HandlerScript = handlerScript;
  865. }
  866.  
  867. void AuraScript::AuraProcHandler::Call(AuraScript* auraScript, ProcEventInfo& eventInfo)
  868. {
  869. (auraScript->*_HandlerScript)(eventInfo);
  870. }
  871.  
  872. AuraScript::EffectProcHandler::EffectProcHandler(AuraEffectProcFnType effectHandlerScript, uint8 effIndex, uint16 effName)
  873. : AuraScript::EffectBase(effIndex, effName)
  874. {
  875. _EffectHandlerScript = effectHandlerScript;
  876. }
  877.  
  878. void AuraScript::EffectProcHandler::Call(AuraScript* auraScript, constAuraEffectPtr aurEff, ProcEventInfo& eventInfo)
  879. {
  880. (auraScript->*_EffectHandlerScript)(aurEff, eventInfo);
  881. }
  882.  
  883. bool AuraScript::_Load(AuraPtr aura)
  884. {
  885. m_aura = aura;
  886. _PrepareScriptCall((AuraScriptHookType)SPELL_SCRIPT_STATE_LOADING, NULL);
  887. bool load = Load();
  888. _FinishScriptCall();
  889. return load;
  890. }
  891.  
  892. void AuraScript::_PrepareScriptCall(AuraScriptHookType hookType, AuraApplication const* aurApp)
  893. {
  894. m_scriptStates.push(ScriptStateStore(m_currentScriptState, m_auraApplication, m_defaultActionPrevented));
  895. m_currentScriptState = hookType;
  896. m_defaultActionPrevented = false;
  897. m_auraApplication = aurApp;
  898. }
  899.  
  900. void AuraScript::_FinishScriptCall()
  901. {
  902. ScriptStateStore stateStore = m_scriptStates.top();
  903. m_currentScriptState = stateStore._currentScriptState;
  904. m_auraApplication = stateStore._auraApplication;
  905. m_defaultActionPrevented = stateStore._defaultActionPrevented;
  906. m_scriptStates.pop();
  907. }
  908.  
  909. bool AuraScript::_IsDefaultActionPrevented()
  910. {
  911. switch (m_currentScriptState)
  912. {
  913. case AURA_SCRIPT_HOOK_EFFECT_APPLY:
  914. case AURA_SCRIPT_HOOK_EFFECT_REMOVE:
  915. case AURA_SCRIPT_HOOK_EFFECT_PERIODIC:
  916. case AURA_SCRIPT_HOOK_EFFECT_ABSORB:
  917. case AURA_SCRIPT_HOOK_PREPARE_PROC:
  918. case AURA_SCRIPT_HOOK_EFFECT_PROC:
  919. return m_defaultActionPrevented;
  920. default:
  921. ASSERT(false && "AuraScript::_IsDefaultActionPrevented is called in a wrong place");
  922. return false;
  923. }
  924. }
  925.  
  926. void AuraScript::PreventDefaultAction()
  927. {
  928. switch (m_currentScriptState)
  929. {
  930. case AURA_SCRIPT_HOOK_EFFECT_APPLY:
  931. case AURA_SCRIPT_HOOK_EFFECT_REMOVE:
  932. case AURA_SCRIPT_HOOK_EFFECT_PERIODIC:
  933. case AURA_SCRIPT_HOOK_EFFECT_ABSORB:
  934. case AURA_SCRIPT_HOOK_PREPARE_PROC:
  935. case AURA_SCRIPT_HOOK_EFFECT_PROC:
  936. m_defaultActionPrevented = true;
  937. break;
  938. default:
  939. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u` AuraScript::PreventDefaultAction called in a hook in which the call won't have effect!", m_scriptName->c_str(), m_scriptSpellId);
  940. break;
  941. }
  942. }
  943.  
  944. SpellInfo const* AuraScript::GetSpellInfo() const
  945. {
  946. return m_aura->GetSpellInfo();
  947. }
  948.  
  949. uint32 AuraScript::GetId() const
  950. {
  951. return m_aura->GetId();
  952. }
  953.  
  954. uint64 AuraScript::GetCasterGUID() const
  955. {
  956. return m_aura->GetCasterGUID();
  957. }
  958.  
  959. Unit* AuraScript::GetCaster() const
  960. {
  961. return m_aura->GetCaster();
  962. }
  963.  
  964. WorldObject* AuraScript::GetOwner() const
  965. {
  966. return m_aura->GetOwner();
  967. }
  968.  
  969. Unit* AuraScript::GetUnitOwner() const
  970. {
  971. return m_aura->GetUnitOwner();
  972. }
  973.  
  974. DynamicObject* AuraScript::GetDynobjOwner() const
  975. {
  976. return m_aura->GetDynobjOwner();
  977. }
  978.  
  979. void AuraScript::Remove(uint32 removeMode)
  980. {
  981. m_aura->Remove((AuraRemoveMode)removeMode);
  982. }
  983.  
  984. AuraPtr AuraScript::GetAura() const
  985. {
  986. return m_aura;
  987. }
  988.  
  989. AuraObjectType AuraScript::GetType() const
  990. {
  991. return m_aura->GetType();
  992. }
  993.  
  994. int32 AuraScript::GetDuration() const
  995. {
  996. return m_aura->GetDuration();
  997. }
  998.  
  999. void AuraScript::SetDuration(int32 duration, bool withMods)
  1000. {
  1001. m_aura->SetDuration(duration, withMods);
  1002. }
  1003.  
  1004. void AuraScript::RefreshDuration()
  1005. {
  1006. m_aura->RefreshDuration();
  1007. }
  1008.  
  1009. time_t AuraScript::GetApplyTime() const
  1010. {
  1011. return m_aura->GetApplyTime();
  1012. }
  1013.  
  1014. int32 AuraScript::GetMaxDuration() const
  1015. {
  1016. return m_aura->GetMaxDuration();
  1017. }
  1018.  
  1019. void AuraScript::SetMaxDuration(int32 duration)
  1020. {
  1021. m_aura->SetMaxDuration(duration);
  1022. }
  1023.  
  1024. int32 AuraScript::CalcMaxDuration() const
  1025. {
  1026. return m_aura->CalcMaxDuration();
  1027. }
  1028.  
  1029. bool AuraScript::IsExpired() const
  1030. {
  1031. return m_aura->IsExpired();
  1032. }
  1033.  
  1034. bool AuraScript::IsPermanent() const
  1035. {
  1036. return m_aura->IsPermanent();
  1037. }
  1038.  
  1039. uint8 AuraScript::GetCharges() const
  1040. {
  1041. return m_aura->GetCharges();
  1042. }
  1043.  
  1044. void AuraScript::SetCharges(uint8 charges)
  1045. {
  1046. m_aura->SetCharges(charges);
  1047. }
  1048.  
  1049. uint8 AuraScript::CalcMaxCharges() const
  1050. {
  1051. return m_aura->CalcMaxCharges();
  1052. }
  1053.  
  1054. bool AuraScript::ModCharges(int8 num, AuraRemoveMode removeMode /*= AURA_REMOVE_BY_DEFAULT*/)
  1055. {
  1056. return m_aura->ModCharges(num, removeMode);
  1057. }
  1058.  
  1059. bool AuraScript::DropCharge(AuraRemoveMode removeMode)
  1060. {
  1061. return m_aura->DropCharge(removeMode);
  1062. }
  1063.  
  1064. uint8 AuraScript::GetStackAmount() const
  1065. {
  1066. return m_aura->GetStackAmount();
  1067. }
  1068.  
  1069. void AuraScript::SetStackAmount(uint8 num)
  1070. {
  1071. m_aura->SetStackAmount(num);
  1072. }
  1073.  
  1074. bool AuraScript::ModStackAmount(int32 num, AuraRemoveMode removeMode)
  1075. {
  1076. return m_aura->ModStackAmount(num, removeMode);
  1077. }
  1078.  
  1079. bool AuraScript::IsPassive() const
  1080. {
  1081. return m_aura->IsPassive();
  1082. }
  1083.  
  1084. bool AuraScript::IsDeathPersistent() const
  1085. {
  1086. return m_aura->IsDeathPersistent();
  1087. }
  1088.  
  1089. bool AuraScript::HasEffect(uint8 effIndex) const
  1090. {
  1091. return m_aura->HasEffect(effIndex);
  1092. }
  1093.  
  1094. AuraEffectPtr AuraScript::GetEffect(uint8 effIndex) const
  1095. {
  1096. return m_aura->GetEffect(effIndex);
  1097. }
  1098.  
  1099. bool AuraScript::HasEffectType(AuraType type) const
  1100. {
  1101. return m_aura->HasEffectType(type);
  1102. }
  1103.  
  1104. Unit* AuraScript::GetTarget() const
  1105. {
  1106. switch (m_currentScriptState)
  1107. {
  1108. case AURA_SCRIPT_HOOK_EFFECT_APPLY:
  1109. case AURA_SCRIPT_HOOK_EFFECT_REMOVE:
  1110. case AURA_SCRIPT_HOOK_EFFECT_AFTER_APPLY:
  1111. case AURA_SCRIPT_HOOK_EFFECT_AFTER_REMOVE:
  1112. case AURA_SCRIPT_HOOK_EFFECT_PERIODIC:
  1113. case AURA_SCRIPT_HOOK_EFFECT_ABSORB:
  1114. case AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB:
  1115. case AURA_SCRIPT_HOOK_EFFECT_MANASHIELD:
  1116. case AURA_SCRIPT_HOOK_EFFECT_AFTER_MANASHIELD:
  1117. case AURA_SCRIPT_HOOK_CHECK_PROC:
  1118. case AURA_SCRIPT_HOOK_PREPARE_PROC:
  1119. case AURA_SCRIPT_HOOK_PROC:
  1120. case AURA_SCRIPT_HOOK_AFTER_PROC:
  1121. case AURA_SCRIPT_HOOK_EFFECT_PROC:
  1122. case AURA_SCRIPT_HOOK_EFFECT_AFTER_PROC:
  1123. return m_auraApplication->GetTarget();
  1124. default:
  1125. sLog->outError(LOG_FILTER_TSCR, "Script: `%s` Spell: `%u` AuraScript::GetTarget called in a hook in which the call won't have effect!", m_scriptName->c_str(), m_scriptSpellId);
  1126. }
  1127.  
  1128. return NULL;
  1129. }
  1130.  
  1131. AuraApplication const* AuraScript::GetTargetApplication() const
  1132. {
  1133. return m_auraApplication;
  1134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement