1. /*
  2. * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
  3. * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "Common.h"
  19. #include "DatabaseEnv.h"
  20. #include "WorldPacket.h"
  21. #include "Opcodes.h"
  22. #include "Log.h"
  23. #include "UpdateMask.h"
  24. #include "World.h"
  25. #include "ObjectMgr.h"
  26. #include "SpellMgr.h"
  27. #include "Player.h"
  28. #include "SkillExtraItems.h"
  29. #include "Unit.h"
  30. #include "Spell.h"
  31. #include "DynamicObject.h"
  32. #include "SpellAuras.h"
  33. #include "SpellAuraEffects.h"
  34. #include "Group.h"
  35. #include "UpdateData.h"
  36. #include "MapManager.h"
  37. #include "ObjectAccessor.h"
  38. #include "SharedDefines.h"
  39. #include "Pet.h"
  40. #include "GameObject.h"
  41. #include "GossipDef.h"
  42. #include "Creature.h"
  43. #include "Totem.h"
  44. #include "CreatureAI.h"
  45. #include "BattlegroundMgr.h"
  46. #include "Battleground.h"
  47. #include "OutdoorPvPMgr.h"
  48. #include "Language.h"
  49. #include "SocialMgr.h"
  50. #include "Util.h"
  51. #include "VMapFactory.h"
  52. #include "TemporarySummon.h"
  53. #include "CellImpl.h"
  54. #include "GridNotifiers.h"
  55. #include "GridNotifiersImpl.h"
  56. #include "SkillDiscovery.h"
  57. #include "Formulas.h"
  58. #include "Vehicle.h"
  59. #include "ScriptMgr.h"
  60. #include "GameObjectAI.h"
  61. #include "AccountMgr.h"
  62. #include "InstanceScript.h"
  63. #include "PathGenerator.h"
  64. #include "ReputationMgr.h"
  65. pEffect SpellEffects[TOTAL_SPELL_EFFECTS]=
  66. {
  67. &Spell::EffectNULL, // 0
  68. &Spell::EffectInstaKill, // 1 SPELL_EFFECT_INSTAKILL
  69. &Spell::EffectSchoolDMG, // 2 SPELL_EFFECT_SCHOOL_DAMAGE
  70. &Spell::EffectDummy, // 3 SPELL_EFFECT_DUMMY
  71. &Spell::EffectUnused, // 4 SPELL_EFFECT_PORTAL_TELEPORT unused
  72. &Spell::EffectTeleportUnits, // 5 SPELL_EFFECT_TELEPORT_UNITS
  73. &Spell::EffectApplyAura, // 6 SPELL_EFFECT_APPLY_AURA
  74. &Spell::EffectEnvironmentalDMG, // 7 SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
  75. &Spell::EffectPowerDrain, // 8 SPELL_EFFECT_POWER_DRAIN
  76. &Spell::EffectHealthLeech, // 9 SPELL_EFFECT_HEALTH_LEECH
  77. &Spell::EffectHeal, // 10 SPELL_EFFECT_HEAL
  78. &Spell::EffectBind, // 11 SPELL_EFFECT_BIND
  79. &Spell::EffectNULL, // 12 SPELL_EFFECT_PORTAL
  80. &Spell::EffectUnused, // 13 SPELL_EFFECT_RITUAL_BASE unused
  81. &Spell::EffectUnused, // 14 SPELL_EFFECT_RITUAL_SPECIALIZE unused
  82. &Spell::EffectUnused, // 15 SPELL_EFFECT_RITUAL_ACTIVATE_PORTAL unused
  83. &Spell::EffectQuestComplete, // 16 SPELL_EFFECT_QUEST_COMPLETE
  84. &Spell::EffectWeaponDmg, // 17 SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
  85. &Spell::EffectResurrect, // 18 SPELL_EFFECT_RESURRECT
  86. &Spell::EffectAddExtraAttacks, // 19 SPELL_EFFECT_ADD_EXTRA_ATTACKS
  87. &Spell::EffectUnused, // 20 SPELL_EFFECT_DODGE one spell: Dodge
  88. &Spell::EffectUnused, // 21 SPELL_EFFECT_EVADE one spell: Evade (DND)
  89. &Spell::EffectParry, // 22 SPELL_EFFECT_PARRY
  90. &Spell::EffectBlock, // 23 SPELL_EFFECT_BLOCK one spell: Block
  91. &Spell::EffectCreateItem, // 24 SPELL_EFFECT_CREATE_ITEM
  92. &Spell::EffectUnused, // 25 SPELL_EFFECT_WEAPON
  93. &Spell::EffectUnused, // 26 SPELL_EFFECT_DEFENSE one spell: Defense
  94. &Spell::EffectPersistentAA, // 27 SPELL_EFFECT_PERSISTENT_AREA_AURA
  95. &Spell::EffectSummonType, // 28 SPELL_EFFECT_SUMMON
  96. &Spell::EffectLeap, // 29 SPELL_EFFECT_LEAP
  97. &Spell::EffectEnergize, // 30 SPELL_EFFECT_ENERGIZE
  98. &Spell::EffectWeaponDmg, // 31 SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
  99. &Spell::EffectTriggerMissileSpell, // 32 SPELL_EFFECT_TRIGGER_MISSILE
  100. &Spell::EffectOpenLock, // 33 SPELL_EFFECT_OPEN_LOCK
  101. &Spell::EffectSummonChangeItem, // 34 SPELL_EFFECT_SUMMON_CHANGE_ITEM
  102. &Spell::EffectApplyAreaAura, // 35 SPELL_EFFECT_APPLY_AREA_AURA_PARTY
  103. &Spell::EffectLearnSpell, // 36 SPELL_EFFECT_LEARN_SPELL
  104. &Spell::EffectUnused, // 37 SPELL_EFFECT_SPELL_DEFENSE one spell: SPELLDEFENSE (DND)
  105. &Spell::EffectDispel, // 38 SPELL_EFFECT_DISPEL
  106. &Spell::EffectUnused, // 39 SPELL_EFFECT_LANGUAGE
  107. &Spell::EffectDualWield, // 40 SPELL_EFFECT_DUAL_WIELD
  108. &Spell::EffectJump, // 41 SPELL_EFFECT_JUMP
  109. &Spell::EffectJumpDest, // 42 SPELL_EFFECT_JUMP_DEST
  110. &Spell::EffectTeleUnitsFaceCaster, // 43 SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
  111. &Spell::EffectLearnSkill, // 44 SPELL_EFFECT_SKILL_STEP
  112. &Spell::EffectAddHonor, // 45 SPELL_EFFECT_ADD_HONOR honor/pvp related
  113. &Spell::EffectUnused, // 46 SPELL_EFFECT_SPAWN clientside, unit appears as if it was just spawned
  114. &Spell::EffectTradeSkill, // 47 SPELL_EFFECT_TRADE_SKILL
  115. &Spell::EffectUnused, // 48 SPELL_EFFECT_STEALTH one spell: Base Stealth
  116. &Spell::EffectUnused, // 49 SPELL_EFFECT_DETECT one spell: Detect
  117. &Spell::EffectTransmitted, // 50 SPELL_EFFECT_TRANS_DOOR
  118. &Spell::EffectUnused, // 51 SPELL_EFFECT_FORCE_CRITICAL_HIT unused
  119. &Spell::EffectUnused, // 52 SPELL_EFFECT_GUARANTEE_HIT one spell: zzOLDCritical Shot
  120. &Spell::EffectEnchantItemPerm, // 53 SPELL_EFFECT_ENCHANT_ITEM
  121. &Spell::EffectEnchantItemTmp, // 54 SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
  122. &Spell::EffectTameCreature, // 55 SPELL_EFFECT_TAMECREATURE
  123. &Spell::EffectSummonPet, // 56 SPELL_EFFECT_SUMMON_PET
  124. &Spell::EffectLearnPetSpell, // 57 SPELL_EFFECT_LEARN_PET_SPELL
  125. &Spell::EffectWeaponDmg, // 58 SPELL_EFFECT_WEAPON_DAMAGE
  126. &Spell::EffectCreateRandomItem, // 59 SPELL_EFFECT_CREATE_RANDOM_ITEM create item base at spell specific loot
  127. &Spell::EffectProficiency, // 60 SPELL_EFFECT_PROFICIENCY
  128. &Spell::EffectSendEvent, // 61 SPELL_EFFECT_SEND_EVENT
  129. &Spell::EffectPowerBurn, // 62 SPELL_EFFECT_POWER_BURN
  130. &Spell::EffectThreat, // 63 SPELL_EFFECT_THREAT
  131. &Spell::EffectTriggerSpell, // 64 SPELL_EFFECT_TRIGGER_SPELL
  132. &Spell::EffectApplyAreaAura, // 65 SPELL_EFFECT_APPLY_AREA_AURA_RAID
  133. &Spell::EffectRechargeManaGem, // 66 SPELL_EFFECT_CREATE_MANA_GEM (possibly recharge it, misc - is item ID)
  134. &Spell::EffectHealMaxHealth, // 67 SPELL_EFFECT_HEAL_MAX_HEALTH
  135. &Spell::EffectInterruptCast, // 68 SPELL_EFFECT_INTERRUPT_CAST
  136. &Spell::EffectDistract, // 69 SPELL_EFFECT_DISTRACT
  137. &Spell::EffectPull, // 70 SPELL_EFFECT_PULL one spell: Distract Move
  138. &Spell::EffectPickPocket, // 71 SPELL_EFFECT_PICKPOCKET
  139. &Spell::EffectAddFarsight, // 72 SPELL_EFFECT_ADD_FARSIGHT
  140. &Spell::EffectUntrainTalents, // 73 SPELL_EFFECT_UNTRAIN_TALENTS
  141. &Spell::EffectApplyGlyph, // 74 SPELL_EFFECT_APPLY_GLYPH
  142. &Spell::EffectHealMechanical, // 75 SPELL_EFFECT_HEAL_MECHANICAL one spell: Mechanical Patch Kit
  143. &Spell::EffectSummonObjectWild, // 76 SPELL_EFFECT_SUMMON_OBJECT_WILD
  144. &Spell::EffectScriptEffect, // 77 SPELL_EFFECT_SCRIPT_EFFECT
  145. &Spell::EffectUnused, // 78 SPELL_EFFECT_ATTACK
  146. &Spell::EffectSanctuary, // 79 SPELL_EFFECT_SANCTUARY
  147. &Spell::EffectAddComboPoints, // 80 SPELL_EFFECT_ADD_COMBO_POINTS
  148. &Spell::EffectUnused, // 81 SPELL_EFFECT_CREATE_HOUSE one spell: Create House (TEST)
  149. &Spell::EffectNULL, // 82 SPELL_EFFECT_BIND_SIGHT
  150. &Spell::EffectDuel, // 83 SPELL_EFFECT_DUEL
  151. &Spell::EffectStuck, // 84 SPELL_EFFECT_STUCK
  152. &Spell::EffectSummonPlayer, // 85 SPELL_EFFECT_SUMMON_PLAYER
  153. &Spell::EffectActivateObject, // 86 SPELL_EFFECT_ACTIVATE_OBJECT
  154. &Spell::EffectGameObjectDamage, // 87 SPELL_EFFECT_GAMEOBJECT_DAMAGE
  155. &Spell::EffectGameObjectRepair, // 88 SPELL_EFFECT_GAMEOBJECT_REPAIR
  156. &Spell::EffectGameObjectSetDestructionState, // 89 SPELL_EFFECT_GAMEOBJECT_SET_DESTRUCTION_STATE
  157. &Spell::EffectKillCreditPersonal, // 90 SPELL_EFFECT_KILL_CREDIT Kill credit but only for single person
  158. &Spell::EffectUnused, // 91 SPELL_EFFECT_THREAT_ALL one spell: zzOLDBrainwash
  159. &Spell::EffectEnchantHeldItem, // 92 SPELL_EFFECT_ENCHANT_HELD_ITEM
  160. &Spell::EffectForceDeselect, // 93 SPELL_EFFECT_FORCE_DESELECT
  161. &Spell::EffectSelfResurrect, // 94 SPELL_EFFECT_SELF_RESURRECT
  162. &Spell::EffectSkinning, // 95 SPELL_EFFECT_SKINNING
  163. &Spell::EffectCharge, // 96 SPELL_EFFECT_CHARGE
  164. &Spell::EffectCastButtons, // 97 SPELL_EFFECT_CAST_BUTTON (totem bar since 3.2.2a)
  165. &Spell::EffectKnockBack, // 98 SPELL_EFFECT_KNOCK_BACK
  166. &Spell::EffectDisEnchant, // 99 SPELL_EFFECT_DISENCHANT
  167. &Spell::EffectInebriate, //100 SPELL_EFFECT_INEBRIATE
  168. &Spell::EffectFeedPet, //101 SPELL_EFFECT_FEED_PET
  169. &Spell::EffectDismissPet, //102 SPELL_EFFECT_DISMISS_PET
  170. &Spell::EffectReputation, //103 SPELL_EFFECT_REPUTATION
  171. &Spell::EffectSummonObject, //104 SPELL_EFFECT_SUMMON_OBJECT_SLOT1
  172. &Spell::EffectSummonObject, //105 SPELL_EFFECT_SUMMON_OBJECT_SLOT2
  173. &Spell::EffectSummonObject, //106 SPELL_EFFECT_SUMMON_OBJECT_SLOT3
  174. &Spell::EffectSummonObject, //107 SPELL_EFFECT_SUMMON_OBJECT_SLOT4
  175. &Spell::EffectDispelMechanic, //108 SPELL_EFFECT_DISPEL_MECHANIC
  176. &Spell::EffectResurrectPet, //109 SPELL_EFFECT_RESURRECT_PET
  177. &Spell::EffectDestroyAllTotems, //110 SPELL_EFFECT_DESTROY_ALL_TOTEMS
  178. &Spell::EffectDurabilityDamage, //111 SPELL_EFFECT_DURABILITY_DAMAGE
  179. &Spell::EffectUnused, //112 SPELL_EFFECT_112
  180. &Spell::EffectResurrectNew, //113 SPELL_EFFECT_RESURRECT_NEW
  181. &Spell::EffectTaunt, //114 SPELL_EFFECT_ATTACK_ME
  182. &Spell::EffectDurabilityDamagePCT, //115 SPELL_EFFECT_DURABILITY_DAMAGE_PCT
  183. &Spell::EffectSkinPlayerCorpse, //116 SPELL_EFFECT_SKIN_PLAYER_CORPSE one spell: Remove Insignia, bg usage, required special corpse flags...
  184. &Spell::EffectSpiritHeal, //117 SPELL_EFFECT_SPIRIT_HEAL one spell: Spirit Heal
  185. &Spell::EffectSkill, //118 SPELL_EFFECT_SKILL professions and more
  186. &Spell::EffectApplyAreaAura, //119 SPELL_EFFECT_APPLY_AREA_AURA_PET
  187. &Spell::EffectUnused, //120 SPELL_EFFECT_TELEPORT_GRAVEYARD one spell: Graveyard Teleport Test
  188. &Spell::EffectWeaponDmg, //121 SPELL_EFFECT_NORMALIZED_WEAPON_DMG
  189. &Spell::EffectUnused, //122 SPELL_EFFECT_122 unused
  190. &Spell::EffectSendTaxi, //123 SPELL_EFFECT_SEND_TAXI taxi/flight related (misc value is taxi path id)
  191. &Spell::EffectPullTowards, //124 SPELL_EFFECT_PULL_TOWARDS
  192. &Spell::EffectModifyThreatPercent, //125 SPELL_EFFECT_MODIFY_THREAT_PERCENT
  193. &Spell::EffectStealBeneficialBuff, //126 SPELL_EFFECT_STEAL_BENEFICIAL_BUFF spell steal effect?
  194. &Spell::EffectProspecting, //127 SPELL_EFFECT_PROSPECTING Prospecting spell
  195. &Spell::EffectApplyAreaAura, //128 SPELL_EFFECT_APPLY_AREA_AURA_FRIEND
  196. &Spell::EffectApplyAreaAura, //129 SPELL_EFFECT_APPLY_AREA_AURA_ENEMY
  197. &Spell::EffectRedirectThreat, //130 SPELL_EFFECT_REDIRECT_THREAT
  198. &Spell::EffectPlaySound, //131 SPELL_EFFECT_PLAY_SOUND sound id in misc value (SoundEntries.dbc)
  199. &Spell::EffectPlayMusic, //132 SPELL_EFFECT_PLAY_MUSIC sound id in misc value (SoundEntries.dbc)
  200. &Spell::EffectUnlearnSpecialization, //133 SPELL_EFFECT_UNLEARN_SPECIALIZATION unlearn profession specialization
  201. &Spell::EffectKillCredit, //134 SPELL_EFFECT_KILL_CREDIT misc value is creature entry
  202. &Spell::EffectNULL, //135 SPELL_EFFECT_CALL_PET
  203. &Spell::EffectHealPct, //136 SPELL_EFFECT_HEAL_PCT
  204. &Spell::EffectEnergizePct, //137 SPELL_EFFECT_ENERGIZE_PCT
  205. &Spell::EffectLeapBack, //138 SPELL_EFFECT_LEAP_BACK Leap back
  206. &Spell::EffectQuestClear, //139 SPELL_EFFECT_CLEAR_QUEST Reset quest status (miscValue - quest ID)
  207. &Spell::EffectForceCast, //140 SPELL_EFFECT_FORCE_CAST
  208. &Spell::EffectForceCast, //141 SPELL_EFFECT_FORCE_CAST_WITH_VALUE
  209. &Spell::EffectTriggerSpell, //142 SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE
  210. &Spell::EffectApplyAreaAura, //143 SPELL_EFFECT_APPLY_AREA_AURA_OWNER
  211. &Spell::EffectKnockBack, //144 SPELL_EFFECT_KNOCK_BACK_DEST
  212. &Spell::EffectPullTowards, //145 SPELL_EFFECT_PULL_TOWARDS_DEST Black Hole Effect
  213. &Spell::EffectActivateRune, //146 SPELL_EFFECT_ACTIVATE_RUNE
  214. &Spell::EffectQuestFail, //147 SPELL_EFFECT_QUEST_FAIL quest fail
  215. &Spell::EffectTriggerMissileSpell, //148 SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE
  216. &Spell::EffectChargeDest, //149 SPELL_EFFECT_CHARGE_DEST
  217. &Spell::EffectQuestStart, //150 SPELL_EFFECT_QUEST_START
  218. &Spell::EffectTriggerRitualOfSummoning, //151 SPELL_EFFECT_TRIGGER_SPELL_2
  219. &Spell::EffectSummonRaFFriend, //152 SPELL_EFFECT_SUMMON_RAF_FRIEND summon Refer-a-Friend
  220. &Spell::EffectCreateTamedPet, //153 SPELL_EFFECT_CREATE_TAMED_PET misc value is creature entry
  221. &Spell::EffectDiscoverTaxi, //154 SPELL_EFFECT_DISCOVER_TAXI
  222. &Spell::EffectTitanGrip, //155 SPELL_EFFECT_TITAN_GRIP Allows you to equip two-handed axes, maces and swords in one hand, but you attack $49152s1% slower than normal.
  223. &Spell::EffectEnchantItemPrismatic, //156 SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
  224. &Spell::EffectCreateItem2, //157 SPELL_EFFECT_CREATE_ITEM_2 create item or create item template and replace by some randon spell loot item
  225. &Spell::EffectMilling, //158 SPELL_EFFECT_MILLING milling
  226. &Spell::EffectRenamePet, //159 SPELL_EFFECT_ALLOW_RENAME_PET allow rename pet once again
  227. &Spell::EffectNULL, //160 SPELL_EFFECT_160 1 spell - 45534
  228. &Spell::EffectSpecCount, //161 SPELL_EFFECT_TALENT_SPEC_COUNT second talent spec (learn/revert)
  229. &Spell::EffectActivateSpec, //162 SPELL_EFFECT_TALENT_SPEC_SELECT activate primary/secondary spec
  230. &Spell::EffectNULL, //163 unused
  231. &Spell::EffectRemoveAura, //164 SPELL_EFFECT_REMOVE_AURA
  232. };
  233. void Spell::EffectNULL(SpellEffIndex /*effIndex*/)
  234. {
  235. TC_LOG_DEBUG("spells", "WORLD: Spell Effect DUMMY");
  236. }
  237. void Spell::EffectUnused(SpellEffIndex /*effIndex*/)
  238. {
  239. // NOT USED BY ANY SPELL OR USELESS OR IMPLEMENTED IN DIFFERENT WAY IN TRINITY
  240. }
  241. void Spell::EffectResurrectNew(SpellEffIndex effIndex)
  242. {
  243. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  244. return;
  245. if (!unitTarget || unitTarget->IsAlive())
  246. return;
  247. if (unitTarget->GetTypeId() != TYPEID_PLAYER)
  248. return;
  249. if (!unitTarget->IsInWorld())
  250. return;
  251. Player* target = unitTarget->ToPlayer();
  252. if (target->isRessurectRequested()) // already have one active request
  253. return;
  254. uint32 health = damage;
  255. uint32 mana = m_spellInfo->Effects[effIndex].MiscValue;
  256. ExecuteLogEffectResurrect(effIndex, target);
  257. target->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
  258. SendResurrectRequest(target);
  259. }
  260. void Spell::EffectInstaKill(SpellEffIndex /*effIndex*/)
  261. {
  262. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  263. return;
  264. if (!unitTarget || !unitTarget->IsAlive())
  265. return;
  266. if (unitTarget->GetTypeId() == TYPEID_PLAYER)
  267. if (unitTarget->ToPlayer()->GetCommandStatus(CHEAT_GOD))
  268. return;
  269. if (m_caster == unitTarget) // prevent interrupt message
  270. finish();
  271. WorldPacket data(SMSG_SPELLINSTAKILLLOG, 8+8+4);
  272. data << uint64(m_caster->GetGUID());
  273. data << uint64(unitTarget->GetGUID());
  274. data << uint32(m_spellInfo->Id);
  275. m_caster->SendMessageToSet(&data, true);
  276. m_caster->DealDamage(unitTarget, unitTarget->GetHealth(), NULL, NODAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
  277. }
  278. void Spell::EffectEnvironmentalDMG(SpellEffIndex /*effIndex*/)
  279. {
  280. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  281. return;
  282. if (!unitTarget || !unitTarget->IsAlive())
  283. return;
  284. uint32 absorb = 0;
  285. uint32 resist = 0;
  286. m_caster->CalcAbsorbResist(unitTarget, m_spellInfo->GetSchoolMask(), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist, m_spellInfo);
  287. m_caster->SendSpellNonMeleeDamageLog(unitTarget, m_spellInfo->Id, damage, m_spellInfo->GetSchoolMask(), absorb, resist, false, 0, false);
  288. if (unitTarget->GetTypeId() == TYPEID_PLAYER)
  289. unitTarget->ToPlayer()->EnvironmentalDamage(DAMAGE_FIRE, damage);
  290. }
  291. void Spell::EffectSchoolDMG(SpellEffIndex effIndex)
  292. {
  293. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  294. return;
  295. if (unitTarget && unitTarget->IsAlive())
  296. {
  297. bool apply_direct_bonus = true;
  298. switch (m_spellInfo->SpellFamilyName)
  299. {
  300. case SPELLFAMILY_GENERIC:
  301. {
  302. // Meteor like spells (divided damage to targets)
  303. if (m_spellInfo->AttributesCu & SPELL_ATTR0_CU_SHARE_DAMAGE)
  304. {
  305. uint32 count = 0;
  306. for (std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
  307. if (ihit->effectMask & (1<<effIndex))
  308. ++count;
  309. damage /= count; // divide to all targets
  310. }
  311. switch (m_spellInfo->Id) // better way to check unknown
  312. {
  313. // Consumption
  314. case 28865:
  315. damage = (((InstanceMap*)m_caster->GetMap())->GetDifficulty() == REGULAR_DIFFICULTY ? 2750 : 4250);
  316. break;
  317. // percent from health with min
  318. case 25599: // Thundercrash
  319. {
  320. damage = unitTarget->GetHealth() / 2;
  321. if (damage < 200)
  322. damage = 200;
  323. break;
  324. }
  325. // arcane charge. must only affect demons (also undead?)
  326. case 45072:
  327. {
  328. if (unitTarget->GetCreatureType() != CREATURE_TYPE_DEMON
  329. && unitTarget->GetCreatureType() != CREATURE_TYPE_UNDEAD)
  330. return;
  331. break;
  332. }
  333. // Gargoyle Strike
  334. case 51963:
  335. {
  336. // about +4 base spell dmg per level
  337. damage = (m_caster->getLevel() - 60) * 4 + 60;
  338. break;
  339. }
  340. }
  341. break;
  342. }
  343. case SPELLFAMILY_WARRIOR:
  344. {
  345. // Shield Slam
  346. if (m_spellInfo->SpellFamilyFlags[1] & 0x200 && m_spellInfo->GetCategory() == 1209)
  347. {
  348. uint8 level = m_caster->getLevel();
  349. uint32 block_value = m_caster->GetShieldBlockValue(uint32(float(level) * 24.5f), uint32(float(level) * 34.5f));
  350. damage += int32(m_caster->ApplyEffectModifiers(m_spellInfo, effIndex, float(block_value)));
  351. }
  352. // Victory Rush
  353. else if (m_spellInfo->SpellFamilyFlags[1] & 0x100)
  354. ApplyPct(damage, m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
  355. // Shockwave
  356. else if (m_spellInfo->Id == 46968)
  357. {
  358. int32 pct = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, 2);
  359. if (pct > 0)
  360. damage += int32(CalculatePct(m_caster->GetTotalAttackPowerValue(BASE_ATTACK), pct));
  361. break;
  362. }
  363. break;
  364. }
  365. case SPELLFAMILY_WARLOCK:
  366. {
  367. // Incinerate Rank 1 & 2
  368. if ((m_spellInfo->SpellFamilyFlags[1] & 0x000040) && m_spellInfo->SpellIconID == 2128)
  369. {
  370. // Incinerate does more dmg (dmg*0.25) if the target have Immolate debuff.
  371. // Check aura state for speed but aura state set not only for Immolate spell
  372. if (unitTarget->HasAuraState(AURA_STATE_CONFLAGRATE))
  373. {
  374. if (unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_WARLOCK, 0x4, 0, 0))
  375. damage += damage/4;
  376. }
  377. }
  378. // Conflagrate - consumes Immolate or Shadowflame
  379. else if (m_spellInfo->TargetAuraState == AURA_STATE_CONFLAGRATE)
  380. {
  381. AuraEffect const* aura = NULL; // found req. aura for damage calculation
  382. Unit::AuraEffectList const &mPeriodic = unitTarget->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE);
  383. for (Unit::AuraEffectList::const_iterator i = mPeriodic.begin(); i != mPeriodic.end(); ++i)
  384. {
  385. // for caster applied auras only
  386. if ((*i)->GetSpellInfo()->SpellFamilyName != SPELLFAMILY_WARLOCK ||
  387. (*i)->GetCasterGUID() != m_caster->GetGUID())
  388. continue;
  389. // Immolate
  390. if ((*i)->GetSpellInfo()->SpellFamilyFlags[0] & 0x4)
  391. {
  392. aura = *i; // it selected always if exist
  393. break;
  394. }
  395. // Shadowflame
  396. if ((*i)->GetSpellInfo()->SpellFamilyFlags[2] & 0x00000002)
  397. aura = *i; // remember but wait possible Immolate as primary priority
  398. }
  399. // found Immolate or Shadowflame
  400. if (aura)
  401. {
  402. uint32 pdamage = uint32(std::max(aura->GetAmount(), 0));
  403. pdamage = m_caster->SpellDamageBonusDone(unitTarget, aura->GetSpellInfo(), pdamage, DOT, aura->GetBase()->GetStackAmount());
  404. pdamage = unitTarget->SpellDamageBonusTaken(m_caster, aura->GetSpellInfo(), pdamage, DOT, aura->GetBase()->GetStackAmount());
  405. uint32 pct_dir = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, (effIndex + 1));
  406. uint8 baseTotalTicks = uint8(m_caster->CalcSpellDuration(aura->GetSpellInfo()) / aura->GetSpellInfo()->Effects[EFFECT_0].Amplitude);
  407. damage += int32(CalculatePct(pdamage * baseTotalTicks, pct_dir));
  408. uint32 pct_dot = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, (effIndex + 2)) / 3;
  409. m_spellValue->EffectBasePoints[1] = m_spellInfo->Effects[EFFECT_1].CalcBaseValue(int32(CalculatePct(pdamage * baseTotalTicks, pct_dot)));
  410. apply_direct_bonus = false;
  411. // Glyph of Conflagrate
  412. if (!m_caster->HasAura(56235))
  413. unitTarget->RemoveAurasDueToSpell(aura->GetId(), m_caster->GetGUID());
  414. break;
  415. }
  416. }
  417. // Shadow Bite
  418. else if (m_spellInfo->SpellFamilyFlags[1] & 0x400000)
  419. {
  420. if (m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->IsPet())
  421. {
  422. if (Player* owner = m_caster->GetOwner()->ToPlayer())
  423. {
  424. if (AuraEffect* aurEff = owner->GetAuraEffect(SPELL_AURA_ADD_FLAT_MODIFIER, SPELLFAMILY_WARLOCK, 214, 0))
  425. {
  426. int32 bp0 = aurEff->GetId() == 54037 ? 4 : 8;
  427. m_caster->CastCustomSpell(m_caster, 54425, &bp0, NULL, NULL, true);
  428. }
  429. }
  430. }
  431. }
  432. break;
  433. }
  434. case SPELLFAMILY_PRIEST:
  435. {
  436. // Improved Mind Blast (Mind Blast in shadow form bonus)
  437. if (m_caster->GetShapeshiftForm() == FORM_SHADOW && (m_spellInfo->SpellFamilyFlags[0] & 0x00002000))
  438. {
  439. Unit::AuraEffectList const& ImprMindBlast = m_caster->GetAuraEffectsByType(SPELL_AURA_ADD_FLAT_MODIFIER);
  440. for (Unit::AuraEffectList::const_iterator i = ImprMindBlast.begin(); i != ImprMindBlast.end(); ++i)
  441. {
  442. if ((*i)->GetSpellInfo()->SpellFamilyName == SPELLFAMILY_PRIEST &&
  443. ((*i)->GetSpellInfo()->SpellIconID == 95))
  444. {
  445. int chance = (*i)->GetSpellInfo()->Effects[EFFECT_1].CalcValue(m_caster);
  446. if (roll_chance_i(chance))
  447. // Mind Trauma
  448. m_caster->CastSpell(unitTarget, 48301, true, 0);
  449. break;
  450. }
  451. }
  452. }
  453. break;
  454. }
  455. case SPELLFAMILY_DRUID:
  456. {
  457. // Ferocious Bite
  458. if (m_caster->GetTypeId() == TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags[0] & 0x000800000) && m_spellInfo->SpellVisual[0] == 6587)
  459. {
  460. // converts each extra point of energy into ($f1+$AP/410) additional damage
  461. float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
  462. float multiple = ap / 410 + m_spellInfo->Effects[effIndex].DamageMultiplier;
  463. int32 energy = -(m_caster->ModifyPower(POWER_ENERGY, -30));
  464. damage += int32(energy * multiple);
  465. damage += int32(CalculatePct(m_caster->ToPlayer()->GetComboPoints() * ap, 7));
  466. }
  467. // Wrath
  468. else if (m_spellInfo->SpellFamilyFlags[0] & 0x00000001)
  469. {
  470. // Improved Insect Swarm
  471. if (AuraEffect const* aurEff = m_caster->GetDummyAuraEffect(SPELLFAMILY_DRUID, 1771, 0))
  472. if (unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_DRUID, 0x00200000, 0, 0))
  473. AddPct(damage, aurEff->GetAmount());
  474. }
  475. break;
  476. }
  477. case SPELLFAMILY_ROGUE:
  478. {
  479. // Envenom
  480. if (m_spellInfo->SpellFamilyFlags[1] & 0x00000008)
  481. {
  482. if (Player* player = m_caster->ToPlayer())
  483. {
  484. // consume from stack dozes not more that have combo-points
  485. if (uint32 combo = player->GetComboPoints())
  486. {
  487. // Lookup for Deadly poison (only attacker applied)
  488. if (AuraEffect const* aurEff = unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_ROGUE, 0x00010000, 0, 0, m_caster->GetGUID()))
  489. {
  490. // count consumed deadly poison doses at target
  491. bool needConsume = true;
  492. uint32 spellId = aurEff->GetId();
  493. uint32 doses = aurEff->GetBase()->GetStackAmount();
  494. if (doses > combo)
  495. doses = combo;
  496. // Master Poisoner
  497. Unit::AuraEffectList const& auraList = player->GetAuraEffectsByType(SPELL_AURA_MOD_AURA_DURATION_BY_DISPEL_NOT_STACK);
  498. for (Unit::AuraEffectList::const_iterator iter = auraList.begin(); iter != auraList.end(); ++iter)
  499. {
  500. if ((*iter)->GetSpellInfo()->SpellFamilyName == SPELLFAMILY_ROGUE && (*iter)->GetSpellInfo()->SpellIconID == 1960)
  501. {
  502. uint32 chance = (*iter)->GetSpellInfo()->Effects[EFFECT_2].CalcValue(m_caster);
  503. if (chance && roll_chance_i(chance))
  504. needConsume = false;
  505. break;
  506. }
  507. }
  508. if (needConsume)
  509. for (uint32 i = 0; i < doses; ++i)
  510. unitTarget->RemoveAuraFromStack(spellId, m_caster->GetGUID());
  511. damage *= doses;
  512. damage += int32(player->GetTotalAttackPowerValue(BASE_ATTACK) * 0.09f * combo);
  513. }
  514. // Eviscerate and Envenom Bonus Damage (item set effect)
  515. if (m_caster->HasAura(37169))
  516. damage += combo * 40;
  517. }
  518. }
  519. }
  520. // Eviscerate
  521. else if (m_spellInfo->SpellFamilyFlags[0] & 0x00020000)
  522. {
  523. if (Player* player = m_caster->ToPlayer())
  524. {
  525. if (uint32 combo = player->GetComboPoints())
  526. {
  527. float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
  528. damage += irand(int32(ap * combo * 0.03f), int32(ap * combo * 0.07f));
  529. // Eviscerate and Envenom Bonus Damage (item set effect)
  530. if (m_caster->HasAura(37169))
  531. damage += combo*40;
  532. }
  533. }
  534. }
  535. break;
  536. }
  537. case SPELLFAMILY_HUNTER:
  538. {
  539. //Gore
  540. if (m_spellInfo->SpellIconID == 1578)
  541. {
  542. if (m_caster->HasAura(57627)) // Charge 6 sec post-affect
  543. damage *= 2;
  544. }
  545. // Steady Shot
  546. else if (m_spellInfo->SpellFamilyFlags[1] & 0x1)
  547. {
  548. bool found = false;
  549. // check dazed affect
  550. Unit::AuraEffectList const& decSpeedList = unitTarget->GetAuraEffectsByType(SPELL_AURA_MOD_DECREASE_SPEED);
  551. for (Unit::AuraEffectList::const_iterator iter = decSpeedList.begin(); iter != decSpeedList.end(); ++iter)
  552. {
  553. if ((*iter)->GetSpellInfo()->SpellIconID == 15 && (*iter)->GetSpellInfo()->Dispel == 0)
  554. {
  555. found = true;
  556. break;
  557. }
  558. }
  559. /// @todo should this be put on taken but not done?
  560. if (found)
  561. damage += m_spellInfo->Effects[EFFECT_1].CalcValue();
  562. if (Player* caster = m_caster->ToPlayer())
  563. {
  564. // Add Ammo and Weapon damage plus RAP * 0.1
  565. if (Item* item = caster->GetWeaponForAttack(RANGED_ATTACK))
  566. {
  567. ItemTemplate const* weaponTemplate = item->GetTemplate();
  568. float dmg_min = weaponTemplate->Damage[0].DamageMin;
  569. float dmg_max = weaponTemplate->Damage[0].DamageMax;
  570. if (dmg_max == 0.0f && dmg_min > dmg_max)
  571. damage += int32(dmg_min);
  572. else
  573. damage += irand(int32(dmg_min), int32(dmg_max));
  574. damage += int32(caster->GetAmmoDPS() * weaponTemplate->Delay * 0.001f);
  575. }
  576. }
  577. }
  578. break;
  579. }
  580. case SPELLFAMILY_PALADIN:
  581. {
  582. // Hammer of the Righteous
  583. if (m_spellInfo->SpellFamilyFlags[1]&0x00040000)
  584. {
  585. // Add main hand dps * effect[2] amount
  586. float average = (m_caster->GetFloatValue(UNIT_FIELD_MINDAMAGE) + m_caster->GetFloatValue(UNIT_FIELD_MAXDAMAGE)) / 2;
  587. int32 count = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, EFFECT_2);
  588. damage += count * int32(average * IN_MILLISECONDS) / m_caster->GetAttackTime(BASE_ATTACK);
  589. break;
  590. }
  591. // Shield of Righteousness
  592. if (m_spellInfo->SpellFamilyFlags[EFFECT_1] & 0x100000)
  593. {
  594. uint8 level = m_caster->getLevel();
  595. uint32 block_value = m_caster->GetShieldBlockValue(uint32(float(level) * 29.5f), uint32(float(level) * 39.5f));
  596. damage += CalculatePct(block_value, m_spellInfo->Effects[EFFECT_1].CalcValue());
  597. break;
  598. }
  599. break;
  600. }
  601. case SPELLFAMILY_DEATHKNIGHT:
  602. {
  603. // Blood Boil - bonus for diseased targets
  604. if (m_spellInfo->SpellFamilyFlags[0] & 0x00040000)
  605. {
  606. if (unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_DEATHKNIGHT, 0, 0, 0x00000002, m_caster->GetGUID()))
  607. {
  608. damage += m_damage / 2;
  609. damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.035f);
  610. }
  611. }
  612. break;
  613. }
  614. case SPELLFAMILY_MAGE:
  615. {
  616. // Deep Freeze should deal damage to permanently stun-immune targets.
  617. if (m_spellInfo->Id == 71757)
  618. if (unitTarget->GetTypeId() != TYPEID_UNIT || !(unitTarget->IsImmunedToSpellEffect(sSpellMgr->GetSpellInfo(44572), 0)))
  619. return;
  620. break;
  621. }
  622. }
  623. if (m_originalCaster && damage > 0 && apply_direct_bonus)
  624. {
  625. damage = m_originalCaster->SpellDamageBonusDone(unitTarget, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE);
  626. damage = unitTarget->SpellDamageBonusTaken(m_originalCaster, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE);
  627. }
  628. m_damage += damage;
  629. }
  630. }
  631. void Spell::EffectDummy(SpellEffIndex effIndex)
  632. {
  633. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  634. return;
  635. if (!unitTarget && !gameObjTarget && !itemTarget)
  636. return;
  637. // selection by spell family
  638. switch (m_spellInfo->SpellFamilyName)
  639. {
  640. case SPELLFAMILY_PALADIN:
  641. switch (m_spellInfo->Id)
  642. {
  643. case 31789: // Righteous Defense (step 1)
  644. {
  645. // Clear targets for eff 1
  646. for (std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
  647. ihit->effectMask &= ~(1<<1);
  648. // not empty (checked), copy
  649. Unit::AttackerSet attackers = unitTarget->getAttackers();
  650. // remove invalid attackers
  651. for (Unit::AttackerSet::iterator aItr = attackers.begin(); aItr != attackers.end();)
  652. if (!(*aItr)->IsValidAttackTarget(m_caster))
  653. attackers.erase(aItr++);
  654. else
  655. ++aItr;
  656. // selected from list 3
  657. uint32 maxTargets = std::min<uint32>(3, attackers.size());
  658. for (uint32 i = 0; i < maxTargets; ++i)
  659. {
  660. Unit* attacker = Trinity::Containers::SelectRandomContainerElement(attackers);
  661. AddUnitTarget(attacker, 1 << 1);
  662. attackers.erase(attacker);
  663. }
  664. // now let next effect cast spell at each target.
  665. return;
  666. }
  667. }
  668. break;
  669. case SPELLFAMILY_MAGE:
  670. // Cold Snap
  671. if (m_spellInfo->Id == 11958)
  672. // Normal and Glyph of Eternal Water - Water Elemental
  673. if (Creature* playerPet = m_caster->ToPlayer()->GetGuardianPet())
  674. if ((playerPet->GetEntry() == 510 || playerPet->GetEntry() == 37994) && playerPet->isDead())
  675. playerPet->DespawnOrUnsummon();
  676. break;
  677. default:
  678. break;
  679. }
  680. // pet auras
  681. if (PetAura const* petSpell = sSpellMgr->GetPetAura(m_spellInfo->Id, effIndex))
  682. {
  683. m_caster->AddPetAura(petSpell);
  684. return;
  685. }
  686. // normal DB scripted effect
  687. TC_LOG_DEBUG("spells", "Spell ScriptStart spellid %u in EffectDummy(%u)", m_spellInfo->Id, effIndex);
  688. m_caster->GetMap()->ScriptsStart(sSpellScripts, uint32(m_spellInfo->Id | (effIndex << 24)), m_caster, unitTarget);
  689. // Script based implementation. Must be used only for not good for implementation in core spell effects
  690. // So called only for not proccessed cases
  691. if (gameObjTarget)
  692. sScriptMgr->OnDummyEffect(m_caster, m_spellInfo->Id, effIndex, gameObjTarget);
  693. else if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT)
  694. sScriptMgr->OnDummyEffect(m_caster, m_spellInfo->Id, effIndex, unitTarget->ToCreature());
  695. else if (itemTarget)
  696. sScriptMgr->OnDummyEffect(m_caster, m_spellInfo->Id, effIndex, itemTarget);
  697. }
  698. void Spell::EffectTriggerSpell(SpellEffIndex effIndex)
  699. {
  700. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET
  701. && effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH)
  702. return;
  703. uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell;
  704. /// @todo move those to spell scripts
  705. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_SPELL
  706. && effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  707. {
  708. // special cases
  709. switch (triggered_spell_id)
  710. {
  711. // Mirror Image
  712. case 58832:
  713. {
  714. // Glyph of Mirror Image
  715. if (m_caster->HasAura(63093))
  716. m_caster->CastSpell(m_caster, 65047, true); // Mirror Image
  717. break;
  718. }
  719. // Vanish (not exist)
  720. case 18461:
  721. {
  722. unitTarget->RemoveMovementImpairingAuras();
  723. unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STALKED);
  724. unitTarget->CombatStop();
  725. // If this spell is given to an NPC, it must handle the rest using its own AI
  726. if (unitTarget->GetTypeId() != TYPEID_PLAYER)
  727. return;
  728. // See if we already are stealthed. If so, we're done.
  729. if (unitTarget->HasAura(1784))
  730. return;
  731. // Reset cooldown on stealth if needed
  732. if (unitTarget->ToPlayer()->HasSpellCooldown(1784))
  733. unitTarget->ToPlayer()->RemoveSpellCooldown(1784);
  734. unitTarget->CastSpell(unitTarget, 1784, true);
  735. return;
  736. }
  737. // Demonic Empowerment -- succubus
  738. case 54437:
  739. {
  740. unitTarget->RemoveMovementImpairingAuras();
  741. unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STALKED);
  742. unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STUN);
  743. // Cast Lesser Invisibility
  744. unitTarget->CastSpell(unitTarget, 7870, true);
  745. return;
  746. }
  747. // just skip
  748. case 23770: // Sayge's Dark Fortune of *
  749. // not exist, common cooldown can be implemented in scripts if need.
  750. return;
  751. // Brittle Armor - (need add max stack of 24575 Brittle Armor)
  752. case 29284:
  753. {
  754. // Brittle Armor
  755. SpellInfo const* spell = sSpellMgr->GetSpellInfo(24575);
  756. if (!spell)
  757. return;
  758. for (uint32 j = 0; j < spell->StackAmount; ++j)
  759. m_caster->CastSpell(unitTarget, spell->Id, true);
  760. return;
  761. }
  762. // Mercurial Shield - (need add max stack of 26464 Mercurial Shield)
  763. case 29286:
  764. {
  765. // Mercurial Shield
  766. SpellInfo const* spell = sSpellMgr->GetSpellInfo(26464);
  767. if (!spell)
  768. return;
  769. for (uint32 j = 0; j < spell->StackAmount; ++j)
  770. m_caster->CastSpell(unitTarget, spell->Id, true);
  771. return;
  772. }
  773. // Cloak of Shadows
  774. case 35729:
  775. {
  776. uint32 dispelMask = SpellInfo::GetDispelMask(DISPEL_ALL);
  777. Unit::AuraApplicationMap& Auras = unitTarget->GetAppliedAuras();
  778. for (Unit::AuraApplicationMap::iterator iter = Auras.begin(); iter != Auras.end();)
  779. {
  780. // remove all harmful spells on you...
  781. SpellInfo const* spell = iter->second->GetBase()->GetSpellInfo();
  782. if ((spell->DmgClass == SPELL_DAMAGE_CLASS_MAGIC // only affect magic spells
  783. || ((spell->GetDispelMask()) & dispelMask))
  784. // ignore positive and passive auras
  785. && !iter->second->IsPositive() && !iter->second->GetBase()->IsPassive())
  786. {
  787. m_caster->RemoveAura(iter);
  788. }
  789. else
  790. ++iter;
  791. }
  792. return;
  793. }
  794. }
  795. }
  796. // normal case
  797. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id);
  798. if (!spellInfo)
  799. {
  800. TC_LOG_ERROR("spells", "Spell::EffectTriggerSpell spell %u tried to trigger unknown spell %u", m_spellInfo->Id, triggered_spell_id);
  801. return;
  802. }
  803. SpellCastTargets targets;
  804. if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  805. {
  806. if (!spellInfo->NeedsToBeTriggeredByCaster(m_spellInfo))
  807. return;
  808. targets.SetUnitTarget(unitTarget);
  809. }
  810. else //if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH)
  811. {
  812. if (spellInfo->NeedsToBeTriggeredByCaster(m_spellInfo) && (m_spellInfo->Effects[effIndex].GetProvidedTargetMask() & TARGET_FLAG_UNIT_MASK))
  813. return;
  814. if (spellInfo->GetExplicitTargetMask() & TARGET_FLAG_DEST_LOCATION)
  815. targets.SetDst(m_targets);
  816. targets.SetUnitTarget(m_caster);
  817. }
  818. CustomSpellValues values;
  819. // set basepoints for trigger with value effect
  820. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE)
  821. {
  822. values.AddSpellMod(SPELLVALUE_BASE_POINT0, damage);
  823. values.AddSpellMod(SPELLVALUE_BASE_POINT1, damage);
  824. values.AddSpellMod(SPELLVALUE_BASE_POINT2, damage);
  825. }
  826. // Remove spell cooldown (not category) if spell triggering spell with cooldown and same category
  827. if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime
  828. && m_spellInfo->GetCategory() == spellInfo->GetCategory())
  829. m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id);
  830. // original caster guid only for GO cast
  831. m_caster->CastSpell(targets, spellInfo, &values, TRIGGERED_FULL_MASK, NULL, NULL, m_originalCasterGUID);
  832. }
  833. void Spell::EffectTriggerMissileSpell(SpellEffIndex effIndex)
  834. {
  835. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET
  836. && effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  837. return;
  838. uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell;
  839. // normal case
  840. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id);
  841. if (!spellInfo)
  842. {
  843. TC_LOG_ERROR("spells", "Spell::EffectTriggerMissileSpell spell %u tried to trigger unknown spell %u", m_spellInfo->Id, triggered_spell_id);
  844. return;
  845. }
  846. SpellCastTargets targets;
  847. if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET)
  848. {
  849. if (!spellInfo->NeedsToBeTriggeredByCaster(m_spellInfo))
  850. return;
  851. targets.SetUnitTarget(unitTarget);
  852. }
  853. else //if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT)
  854. {
  855. if (spellInfo->NeedsToBeTriggeredByCaster(m_spellInfo) && (m_spellInfo->Effects[effIndex].GetProvidedTargetMask() & TARGET_FLAG_UNIT_MASK))
  856. return;
  857. if (spellInfo->GetExplicitTargetMask() & TARGET_FLAG_DEST_LOCATION)
  858. targets.SetDst(m_targets);
  859. targets.SetUnitTarget(m_caster);
  860. }
  861. CustomSpellValues values;
  862. // set basepoints for trigger with value effect
  863. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE)
  864. {
  865. // maybe need to set value only when basepoints == 0?
  866. values.AddSpellMod(SPELLVALUE_BASE_POINT0, damage);
  867. values.AddSpellMod(SPELLVALUE_BASE_POINT1, damage);
  868. values.AddSpellMod(SPELLVALUE_BASE_POINT2, damage);
  869. }
  870. // Remove spell cooldown (not category) if spell triggering spell with cooldown and same category
  871. if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime
  872. && m_spellInfo->GetCategory() == spellInfo->GetCategory())
  873. m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id);
  874. // original caster guid only for GO cast
  875. m_caster->CastSpell(targets, spellInfo, &values, TRIGGERED_FULL_MASK, NULL, NULL, m_originalCasterGUID);
  876. }
  877. void Spell::EffectForceCast(SpellEffIndex effIndex)
  878. {
  879. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  880. return;
  881. if (!unitTarget)
  882. return;
  883. uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell;
  884. // normal case
  885. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id);
  886. if (!spellInfo)
  887. {
  888. TC_LOG_ERROR("spells", "Spell::EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id);
  889. return;
  890. }
  891. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_FORCE_CAST && damage)
  892. {
  893. switch (m_spellInfo->Id)
  894. {
  895. case 52588: // Skeletal Gryphon Escape
  896. case 48598: // Ride Flamebringer Cue
  897. unitTarget->RemoveAura(damage);
  898. break;
  899. case 52463: // Hide In Mine Car
  900. case 52349: // Overtake
  901. unitTarget->CastCustomSpell(unitTarget, spellInfo->Id, &damage, NULL, NULL, true, NULL, NULL, m_originalCasterGUID);
  902. return;
  903. case 72299: // Malleable Goo Summon Trigger
  904. unitTarget->CastSpell(unitTarget, spellInfo->Id, true, NULL, NULL, m_originalCasterGUID);
  905. return;
  906. }
  907. }
  908. CustomSpellValues values;
  909. // set basepoints for trigger with value effect
  910. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_FORCE_CAST_WITH_VALUE)
  911. {
  912. // maybe need to set value only when basepoints == 0?
  913. values.AddSpellMod(SPELLVALUE_BASE_POINT0, damage);
  914. values.AddSpellMod(SPELLVALUE_BASE_POINT1, damage);
  915. values.AddSpellMod(SPELLVALUE_BASE_POINT2, damage);
  916. }
  917. SpellCastTargets targets;
  918. targets.SetUnitTarget(m_caster);
  919. unitTarget->CastSpell(targets, spellInfo, &values, TRIGGERED_FULL_MASK);
  920. }
  921. void Spell::EffectTriggerRitualOfSummoning(SpellEffIndex effIndex)
  922. {
  923. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  924. return;
  925. uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell;
  926. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id);
  927. if (!spellInfo)
  928. {
  929. TC_LOG_ERROR("spells", "EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id);
  930. return;
  931. }
  932. finish();
  933. m_caster->CastSpell((Unit*)NULL, spellInfo, false);
  934. }
  935. void Spell::EffectJump(SpellEffIndex effIndex)
  936. {
  937. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  938. return;
  939. if (m_caster->IsInFlight())
  940. return;
  941. if (!unitTarget)
  942. return;
  943. float x, y, z;
  944. unitTarget->GetContactPoint(m_caster, x, y, z, CONTACT_DISTANCE);
  945. float speedXY, speedZ;
  946. CalculateJumpSpeeds(effIndex, m_caster->GetExactDist2d(x, y), speedXY, speedZ);
  947. m_caster->GetMotionMaster()->MoveJump(x, y, z, speedXY, speedZ);
  948. }
  949. void Spell::EffectJumpDest(SpellEffIndex effIndex)
  950. {
  951. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH)
  952. return;
  953. if (m_caster->IsInFlight())
  954. return;
  955. if (!m_targets.HasDst())
  956. return;
  957. // Init dest coordinates
  958. float x, y, z;
  959. destTarget->GetPosition(x, y, z);
  960. if (m_spellInfo->Id == 49575) // Death Grip
  961. {
  962. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  963. if (Pet* pet = m_caster->ToPlayer()->GetPet())
  964. if (m_caster->IsWithinDistInMap(pet, m_caster->GetCombatReach() + m_caster->GetObjectSize()))
  965. {
  966. Position pos;
  967. pet->GetFirstCollisionPosition(pos, m_caster->GetCombatReach() - m_caster->GetObjectSize() + PET_FOLLOW_DIST, pet->GetFollowAngle());
  968. pet->GetMotionMaster()->MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), 64.0f, 3.0f);
  969. }
  970. m_caster->GetMotionMaster()->MoveJump(x, y, z, 64.0f, 3.0f);
  971. }
  972. else
  973. {
  974. float speedXY, speedZ;
  975. CalculateJumpSpeeds(effIndex, m_caster->GetExactDist2d(x, y), speedXY, speedZ);
  976. m_caster->GetMotionMaster()->MoveJump(x, y, z, speedXY, speedZ);
  977. }
  978. }
  979. void Spell::CalculateJumpSpeeds(uint8 i, float dist, float & speedXY, float & speedZ)
  980. {
  981. if (m_spellInfo->Effects[i].MiscValue)
  982. speedZ = float(m_spellInfo->Effects[i].MiscValue)/10;
  983. else if (m_spellInfo->Effects[i].MiscValueB)
  984. speedZ = float(m_spellInfo->Effects[i].MiscValueB)/10;
  985. else
  986. speedZ = 10.0f;
  987. speedXY = dist * 10.0f / speedZ;
  988. }
  989. void Spell::EffectTeleportUnits(SpellEffIndex /*effIndex*/)
  990. {
  991. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  992. return;
  993. if (!unitTarget || unitTarget->IsInFlight())
  994. return;
  995. // If not exist data for dest location - return
  996. if (!m_targets.HasDst())
  997. {
  998. TC_LOG_ERROR("spells", "Spell::EffectTeleportUnits - does not have destination for spellId %u.", m_spellInfo->Id);
  999. return;
  1000. }
  1001. // Init dest coordinates
  1002. uint32 mapid = destTarget->GetMapId();
  1003. if (mapid == MAPID_INVALID)
  1004. mapid = unitTarget->GetMapId();
  1005. float x, y, z, orientation;
  1006. destTarget->GetPosition(x, y, z, orientation);
  1007. if (!orientation && m_targets.GetUnitTarget())
  1008. orientation = m_targets.GetUnitTarget()->GetOrientation();
  1009. TC_LOG_DEBUG("spells", "Spell::EffectTeleportUnits - teleport unit to %u %f %f %f %f\n", mapid, x, y, z, orientation);
  1010. if (unitTarget->GetTypeId() == TYPEID_PLAYER)
  1011. unitTarget->ToPlayer()->TeleportTo(mapid, x, y, z, orientation, unitTarget == m_caster ? TELE_TO_SPELL : 0);
  1012. else if (mapid == unitTarget->GetMapId())
  1013. unitTarget->NearTeleportTo(x, y, z, orientation, unitTarget == m_caster);
  1014. else
  1015. {
  1016. TC_LOG_ERROR("spells", "Spell::EffectTeleportUnits - spellId %u attempted to teleport creature to a different map.", m_spellInfo->Id);
  1017. return;
  1018. }
  1019. // post effects for TARGET_DEST_DB
  1020. switch (m_spellInfo->Id)
  1021. {
  1022. // Dimensional Ripper - Everlook
  1023. case 23442:
  1024. {
  1025. int32 r = irand(0, 119);
  1026. if (r >= 70) // 7/12 success
  1027. {
  1028. if (r < 100) // 4/12 evil twin
  1029. m_caster->CastSpell(m_caster, 23445, true);
  1030. else // 1/12 fire
  1031. m_caster->CastSpell(m_caster, 23449, true);
  1032. }
  1033. return;
  1034. }
  1035. // Ultrasafe Transporter: Toshley's Station
  1036. case 36941:
  1037. {
  1038. if (roll_chance_i(50)) // 50% success
  1039. {
  1040. int32 rand_eff = urand(1, 7);
  1041. switch (rand_eff)
  1042. {
  1043. case 1:
  1044. // soul split - evil
  1045. m_caster->CastSpell(m_caster, 36900, true);
  1046. break;
  1047. case 2:
  1048. // soul split - good
  1049. m_caster->CastSpell(m_caster, 36901, true);
  1050. break;
  1051. case 3:
  1052. // Increase the size
  1053. m_caster->CastSpell(m_caster, 36895, true);
  1054. break;
  1055. case 4:
  1056. // Decrease the size
  1057. m_caster->CastSpell(m_caster, 36893, true);
  1058. break;
  1059. case 5:
  1060. // Transform
  1061. {
  1062. if (m_caster->ToPlayer()->GetTeam() == ALLIANCE)
  1063. m_caster->CastSpell(m_caster, 36897, true);
  1064. else
  1065. m_caster->CastSpell(m_caster, 36899, true);
  1066. break;
  1067. }
  1068. case 6:
  1069. // chicken
  1070. m_caster->CastSpell(m_caster, 36940, true);
  1071. break;
  1072. case 7:
  1073. // evil twin
  1074. m_caster->CastSpell(m_caster, 23445, true);
  1075. break;
  1076. }
  1077. }
  1078. return;
  1079. }
  1080. // Dimensional Ripper - Area 52
  1081. case 36890:
  1082. {
  1083. if (roll_chance_i(50)) // 50% success
  1084. {
  1085. int32 rand_eff = urand(1, 4);
  1086. switch (rand_eff)
  1087. {
  1088. case 1:
  1089. // soul split - evil
  1090. m_caster->CastSpell(m_caster, 36900, true);
  1091. break;
  1092. case 2:
  1093. // soul split - good
  1094. m_caster->CastSpell(m_caster, 36901, true);
  1095. break;
  1096. case 3:
  1097. // Increase the size
  1098. m_caster->CastSpell(m_caster, 36895, true);
  1099. break;
  1100. case 4:
  1101. // Transform
  1102. {
  1103. if (m_caster->ToPlayer()->GetTeam() == ALLIANCE)
  1104. m_caster->CastSpell(m_caster, 36897, true);
  1105. else
  1106. m_caster->CastSpell(m_caster, 36899, true);
  1107. break;
  1108. }
  1109. }
  1110. }
  1111. return;
  1112. }
  1113. }
  1114. }
  1115. void Spell::EffectApplyAura(SpellEffIndex effIndex)
  1116. {
  1117. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1118. return;
  1119. if (!m_spellAura || !unitTarget)
  1120. return;
  1121. ASSERT(unitTarget == m_spellAura->GetOwner());
  1122. m_spellAura->_ApplyEffectForTargets(effIndex);
  1123. }
  1124. void Spell::EffectApplyAreaAura(SpellEffIndex effIndex)
  1125. {
  1126. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1127. return;
  1128. if (!m_spellAura || !unitTarget)
  1129. return;
  1130. ASSERT (unitTarget == m_spellAura->GetOwner());
  1131. m_spellAura->_ApplyEffectForTargets(effIndex);
  1132. }
  1133. void Spell::EffectUnlearnSpecialization(SpellEffIndex effIndex)
  1134. {
  1135. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1136. return;
  1137. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  1138. return;
  1139. Player* player = unitTarget->ToPlayer();
  1140. uint32 spellToUnlearn = m_spellInfo->Effects[effIndex].TriggerSpell;
  1141. player->removeSpell(spellToUnlearn);
  1142. TC_LOG_DEBUG("spells", "Spell: Player %u has unlearned spell %u from NpcGUID: %u", player->GetGUIDLow(), spellToUnlearn, m_caster->GetGUIDLow());
  1143. }
  1144. void Spell::EffectPowerDrain(SpellEffIndex effIndex)
  1145. {
  1146. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1147. return;
  1148. if (m_spellInfo->Effects[effIndex].MiscValue < 0 || m_spellInfo->Effects[effIndex].MiscValue >= int8(MAX_POWERS))
  1149. return;
  1150. Powers powerType = Powers(m_spellInfo->Effects[effIndex].MiscValue);
  1151. if (!unitTarget || !unitTarget->IsAlive() || unitTarget->getPowerType() != powerType || damage < 0)
  1152. return;
  1153. // add spell damage bonus
  1154. damage = m_caster->SpellDamageBonusDone(unitTarget, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE);
  1155. damage = unitTarget->SpellDamageBonusTaken(m_caster, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE);
  1156. // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
  1157. int32 power = damage;
  1158. if (powerType == POWER_MANA)
  1159. power -= unitTarget->GetSpellCritDamageReduction(power);
  1160. int32 newDamage = -(unitTarget->ModifyPower(powerType, -int32(power)));
  1161. float gainMultiplier = 0.0f;
  1162. // Don't restore from self drain
  1163. if (m_caster != unitTarget)
  1164. {
  1165. gainMultiplier = m_spellInfo->Effects[effIndex].CalcValueMultiplier(m_originalCaster, this);
  1166. int32 gain = int32(newDamage* gainMultiplier);
  1167. m_caster->EnergizeBySpell(m_caster, m_spellInfo->Id, gain, powerType);
  1168. }
  1169. ExecuteLogEffectTakeTargetPower(effIndex, unitTarget, powerType, newDamage, gainMultiplier);
  1170. }
  1171. void Spell::EffectSendEvent(SpellEffIndex effIndex)
  1172. {
  1173. // we do not handle a flag dropping or clicking on flag in battleground by sendevent system
  1174. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET
  1175. && effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  1176. return;
  1177. WorldObject* target = NULL;
  1178. // call events for object target if present
  1179. if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET)
  1180. {
  1181. if (unitTarget)
  1182. target = unitTarget;
  1183. else if (gameObjTarget)
  1184. target = gameObjTarget;
  1185. }
  1186. else // if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT)
  1187. {
  1188. // let's prevent executing effect handler twice in case when spell effect is capable of targeting an object
  1189. // this check was requested by scripters, but it has some downsides:
  1190. // now it's impossible to script (using sEventScripts) a cast which misses all targets
  1191. // or to have an ability to script the moment spell hits dest (in a case when there are object targets present)
  1192. if (m_spellInfo->Effects[effIndex].GetProvidedTargetMask() & (TARGET_FLAG_UNIT_MASK | TARGET_FLAG_GAMEOBJECT_MASK))
  1193. return;
  1194. // some spells have no target entries in dbc and they use focus target
  1195. if (focusObject)
  1196. target = focusObject;
  1197. /// @todo there should be a possibility to pass dest target to event script
  1198. }
  1199. TC_LOG_DEBUG("spells", "Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->Effects[effIndex].MiscValue, m_spellInfo->Id);
  1200. if (ZoneScript* zoneScript = m_caster->GetZoneScript())
  1201. zoneScript->ProcessEvent(target, m_spellInfo->Effects[effIndex].MiscValue);
  1202. else if (InstanceScript* instanceScript = m_caster->GetInstanceScript()) // needed in case Player is the caster
  1203. instanceScript->ProcessEvent(target, m_spellInfo->Effects[effIndex].MiscValue);
  1204. m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->Effects[effIndex].MiscValue, m_caster, target);
  1205. }
  1206. void Spell::EffectPowerBurn(SpellEffIndex effIndex)
  1207. {
  1208. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1209. return;
  1210. if (m_spellInfo->Effects[effIndex].MiscValue < 0 || m_spellInfo->Effects[effIndex].MiscValue >= int8(MAX_POWERS))
  1211. return;
  1212. Powers powerType = Powers(m_spellInfo->Effects[effIndex].MiscValue);
  1213. if (!unitTarget || !unitTarget->IsAlive() || unitTarget->getPowerType() != powerType || damage < 0)
  1214. return;
  1215. // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn)
  1216. if (m_spellInfo->Id == 8129)
  1217. {
  1218. int32 maxDamage = int32(CalculatePct(m_caster->GetMaxPower(powerType), damage * 2));
  1219. damage = int32(CalculatePct(unitTarget->GetMaxPower(powerType), damage));
  1220. damage = std::min(damage, maxDamage);
  1221. }
  1222. int32 power = damage;
  1223. // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
  1224. if (powerType == POWER_MANA)
  1225. power -= unitTarget->GetSpellCritDamageReduction(power);
  1226. int32 newDamage = -(unitTarget->ModifyPower(powerType, -power));
  1227. // NO - Not a typo - EffectPowerBurn uses effect value multiplier - not effect damage multiplier
  1228. float dmgMultiplier = m_spellInfo->Effects[effIndex].CalcValueMultiplier(m_originalCaster, this);
  1229. // add log data before multiplication (need power amount, not damage)
  1230. ExecuteLogEffectTakeTargetPower(effIndex, unitTarget, powerType, newDamage, 0.0f);
  1231. newDamage = int32(newDamage* dmgMultiplier);
  1232. m_damage += newDamage;
  1233. }
  1234. void Spell::EffectHeal(SpellEffIndex /*effIndex*/)
  1235. {
  1236. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  1237. return;
  1238. if (unitTarget && unitTarget->IsAlive() && damage >= 0)
  1239. {
  1240. // Try to get original caster
  1241. Unit* caster = m_originalCasterGUID ? m_originalCaster : m_caster;
  1242. // Skip if m_originalCaster not available
  1243. if (!caster)
  1244. return;
  1245. int32 addhealth = damage;
  1246. // Vessel of the Naaru (Vial of the Sunwell trinket)
  1247. if (m_spellInfo->Id == 45064)
  1248. {
  1249. // Amount of heal - depends from stacked Holy Energy
  1250. int damageAmount = 0;
  1251. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(45062, 0))
  1252. {
  1253. damageAmount+= aurEff->GetAmount();
  1254. m_caster->RemoveAurasDueToSpell(45062);
  1255. }
  1256. addhealth += damageAmount;
  1257. }
  1258. // Runic Healing Injector (heal increased by 25% for engineers - 3.2.0 patch change)
  1259. else if (m_spellInfo->Id == 67489)
  1260. {
  1261. if (Player* player = m_caster->ToPlayer())
  1262. if (player->HasSkill(SKILL_ENGINEERING))
  1263. AddPct(addhealth, 25);
  1264. }
  1265. // Swiftmend - consumes Regrowth or Rejuvenation
  1266. else if (m_spellInfo->TargetAuraState == AURA_STATE_SWIFTMEND && unitTarget->HasAuraState(AURA_STATE_SWIFTMEND, m_spellInfo, m_caster))
  1267. {
  1268. Unit::AuraEffectList const& RejorRegr = unitTarget->GetAuraEffectsByType(SPELL_AURA_PERIODIC_HEAL);
  1269. // find most short by duration
  1270. AuraEffect* targetAura = NULL;
  1271. for (Unit::AuraEffectList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
  1272. {
  1273. if ((*i)->GetSpellInfo()->SpellFamilyName == SPELLFAMILY_DRUID
  1274. && (*i)->GetSpellInfo()->SpellFamilyFlags[0] & 0x50)
  1275. {
  1276. if (!targetAura || (*i)->GetBase()->GetDuration() < targetAura->GetBase()->GetDuration())
  1277. targetAura = *i;
  1278. }
  1279. }
  1280. if (!targetAura)
  1281. {
  1282. TC_LOG_ERROR("spells", "Target(GUID:" UI64FMTD ") has aurastate AURA_STATE_SWIFTMEND but no matching aura.", unitTarget->GetGUID());
  1283. return;
  1284. }
  1285. int32 tickheal = targetAura->GetAmount();
  1286. if (Unit* auraCaster = targetAura->GetCaster())
  1287. tickheal = auraCaster->SpellHealingBonusDone(unitTarget, targetAura->GetSpellInfo(), tickheal, DOT);
  1288. //int32 tickheal = targetAura->GetSpellInfo()->EffectBasePoints[idx] + 1;
  1289. //It is said that talent bonus should not be included
  1290. int32 tickcount = 0;
  1291. // Rejuvenation
  1292. if (targetAura->GetSpellInfo()->SpellFamilyFlags[0] & 0x10)
  1293. tickcount = 4;
  1294. // Regrowth
  1295. else // if (targetAura->GetSpellInfo()->SpellFamilyFlags[0] & 0x40)
  1296. tickcount = 6;
  1297. addhealth += tickheal * tickcount;
  1298. // Glyph of Swiftmend
  1299. if (!caster->HasAura(54824))
  1300. unitTarget->RemoveAura(targetAura->GetId(), targetAura->GetCasterGUID());
  1301. //addhealth += tickheal * tickcount;
  1302. //addhealth = caster->SpellHealingBonus(m_spellInfo, addhealth, HEAL, unitTarget);
  1303. }
  1304. // Nourish
  1305. else if (m_spellInfo->SpellFamilyName == SPELLFAMILY_DRUID && m_spellInfo->SpellFamilyFlags[1] & 0x2000000)
  1306. {
  1307. addhealth = caster->SpellHealingBonusDone(unitTarget, m_spellInfo, addhealth, HEAL);
  1308. // Glyph of Nourish
  1309. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(62971, 0))
  1310. {
  1311. Unit::AuraEffectList const& Periodic = unitTarget->GetAuraEffectsByType(SPELL_AURA_PERIODIC_HEAL);
  1312. for (Unit::AuraEffectList::const_iterator i = Periodic.begin(); i != Periodic.end(); ++i)
  1313. {
  1314. if (m_caster->GetGUID() == (*i)->GetCasterGUID())
  1315. AddPct(addhealth, aurEff->GetAmount());
  1316. }
  1317. }
  1318. }
  1319. // Death Pact - return pct of max health to caster
  1320. else if (m_spellInfo->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT && m_spellInfo->SpellFamilyFlags[0] & 0x00080000)
  1321. addhealth = caster->SpellHealingBonusDone(unitTarget, m_spellInfo, int32(caster->CountPctFromMaxHealth(damage)), HEAL);
  1322. else
  1323. addhealth = caster->SpellHealingBonusDone(unitTarget, m_spellInfo, addhealth, HEAL);
  1324. addhealth = unitTarget->SpellHealingBonusTaken(caster, m_spellInfo, addhealth, HEAL);
  1325. // Remove Grievious bite if fully healed
  1326. if (unitTarget->HasAura(48920) && (unitTarget->GetHealth() + addhealth >= unitTarget->GetMaxHealth()))
  1327. unitTarget->RemoveAura(48920);
  1328. m_damage -= addhealth;
  1329. }
  1330. }
  1331. void Spell::EffectHealPct(SpellEffIndex /*effIndex*/)
  1332. {
  1333. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1334. return;
  1335. if (!unitTarget || !unitTarget->IsAlive() || damage < 0)
  1336. return;
  1337. // Skip if m_originalCaster not available
  1338. if (!m_originalCaster)
  1339. return;
  1340. uint32 heal = m_originalCaster->SpellHealingBonusDone(unitTarget, m_spellInfo, unitTarget->CountPctFromMaxHealth(damage), HEAL);
  1341. heal = unitTarget->SpellHealingBonusTaken(m_originalCaster, m_spellInfo, heal, HEAL);
  1342. m_healing += heal;
  1343. }
  1344. void Spell::EffectHealMechanical(SpellEffIndex /*effIndex*/)
  1345. {
  1346. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1347. return;
  1348. if (!unitTarget || !unitTarget->IsAlive() || damage < 0)
  1349. return;
  1350. // Skip if m_originalCaster not available
  1351. if (!m_originalCaster)
  1352. return;
  1353. uint32 heal = m_originalCaster->SpellHealingBonusDone(unitTarget, m_spellInfo, uint32(damage), HEAL);
  1354. m_healing += unitTarget->SpellHealingBonusTaken(m_originalCaster, m_spellInfo, heal, HEAL);
  1355. }
  1356. void Spell::EffectHealthLeech(SpellEffIndex effIndex)
  1357. {
  1358. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1359. return;
  1360. if (!unitTarget || !unitTarget->IsAlive() || damage < 0)
  1361. return;
  1362. damage = m_caster->SpellDamageBonusDone(unitTarget, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE);
  1363. damage = unitTarget->SpellDamageBonusTaken(m_caster, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE);
  1364. TC_LOG_DEBUG("spells", "HealthLeech :%i", damage);
  1365. float healMultiplier = m_spellInfo->Effects[effIndex].CalcValueMultiplier(m_originalCaster, this);
  1366. m_damage += damage;
  1367. // get max possible damage, don't count overkill for heal
  1368. uint32 healthGain = uint32(-unitTarget->GetHealthGain(-damage) * healMultiplier);
  1369. if (m_caster->IsAlive())
  1370. {
  1371. healthGain = m_caster->SpellHealingBonusDone(m_caster, m_spellInfo, healthGain, HEAL);
  1372. healthGain = m_caster->SpellHealingBonusTaken(m_caster, m_spellInfo, healthGain, HEAL);
  1373. m_caster->HealBySpell(m_caster, m_spellInfo, uint32(healthGain));
  1374. }
  1375. }
  1376. void Spell::DoCreateItem(uint32 /*i*/, uint32 itemtype)
  1377. {
  1378. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  1379. return;
  1380. Player* player = unitTarget->ToPlayer();
  1381. uint32 newitemid = itemtype;
  1382. ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(newitemid);
  1383. if (!pProto)
  1384. {
  1385. player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL);
  1386. return;
  1387. }
  1388. // bg reward have some special in code work
  1389. uint32 bgType = 0;
  1390. switch (m_spellInfo->Id)
  1391. {
  1392. case SPELL_AV_MARK_WINNER:
  1393. case SPELL_AV_MARK_LOSER:
  1394. bgType = BATTLEGROUND_AV;
  1395. break;
  1396. case SPELL_WS_MARK_WINNER:
  1397. case SPELL_WS_MARK_LOSER:
  1398. bgType = BATTLEGROUND_WS;
  1399. break;
  1400. case SPELL_AB_MARK_WINNER:
  1401. case SPELL_AB_MARK_LOSER:
  1402. bgType = BATTLEGROUND_AB;
  1403. break;
  1404. default:
  1405. break;
  1406. }
  1407. uint32 num_to_add = damage;
  1408. if (num_to_add < 1)
  1409. num_to_add = 1;
  1410. if (num_to_add > pProto->GetMaxStackSize())
  1411. num_to_add = pProto->GetMaxStackSize();
  1412. // init items_count to 1, since 1 item will be created regardless of specialization
  1413. int items_count=1;
  1414. // the chance to create additional items
  1415. float additionalCreateChance=0.0f;
  1416. // the maximum number of created additional items
  1417. uint8 additionalMaxNum=0;
  1418. // get the chance and maximum number for creating extra items
  1419. if (CanCreateExtraItems(player, m_spellInfo->Id, additionalCreateChance, additionalMaxNum))
  1420. {
  1421. // roll with this chance till we roll not to create or we create the max num
  1422. while (roll_chance_f(additionalCreateChance) && items_count <= additionalMaxNum)
  1423. ++items_count;
  1424. }
  1425. // really will be created more items
  1426. num_to_add *= items_count;
  1427. // can the player store the new item?
  1428. ItemPosCountVec dest;
  1429. uint32 no_space = 0;
  1430. InventoryResult msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, newitemid, num_to_add, &no_space);
  1431. if (msg != EQUIP_ERR_OK)
  1432. {
  1433. // convert to possible store amount
  1434. if (msg == EQUIP_ERR_INVENTORY_FULL || msg == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS)
  1435. num_to_add -= no_space;
  1436. else
  1437. {
  1438. // if not created by another reason from full inventory or unique items amount limitation
  1439. player->SendEquipError(msg, NULL, NULL, newitemid);
  1440. return;
  1441. }
  1442. }
  1443. if (num_to_add)
  1444. {
  1445. // create the new item and store it
  1446. Item* pItem = player->StoreNewItem(dest, newitemid, true, Item::GenerateItemRandomPropertyId(newitemid));
  1447. // was it successful? return error if not
  1448. if (!pItem)
  1449. {
  1450. player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL);
  1451. return;
  1452. }
  1453. // set the "Crafted by ..." property of the item
  1454. if (pItem->GetTemplate()->Class != ITEM_CLASS_CONSUMABLE && pItem->GetTemplate()->Class != ITEM_CLASS_QUEST && newitemid != 6265 && newitemid != 6948)
  1455. pItem->SetUInt32Value(ITEM_FIELD_CREATOR, player->GetGUIDLow());
  1456. // send info to the client
  1457. player->SendNewItem(pItem, num_to_add, true, bgType == 0);
  1458. // we succeeded in creating at least one item, so a levelup is possible
  1459. if (bgType == 0)
  1460. player->UpdateCraftSkill(m_spellInfo->Id);
  1461. }
  1462. /*
  1463. // for battleground marks send by mail if not add all expected
  1464. if (no_space > 0 && bgType)
  1465. {
  1466. if (Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(BattlegroundTypeId(bgType)))
  1467. bg->SendRewardMarkByMail(player, newitemid, no_space);
  1468. }
  1469. */
  1470. }
  1471. void Spell::EffectCreateItem(SpellEffIndex effIndex)
  1472. {
  1473. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1474. return;
  1475. DoCreateItem(effIndex, m_spellInfo->Effects[effIndex].ItemType);
  1476. ExecuteLogEffectCreateItem(effIndex, m_spellInfo->Effects[effIndex].ItemType);
  1477. }
  1478. void Spell::EffectCreateItem2(SpellEffIndex effIndex)
  1479. {
  1480. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1481. return;
  1482. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  1483. return;
  1484. Player* player = unitTarget->ToPlayer();
  1485. uint32 item_id = m_spellInfo->Effects[effIndex].ItemType;
  1486. if (item_id)
  1487. DoCreateItem(effIndex, item_id);
  1488. // special case: fake item replaced by generate using spell_loot_template
  1489. if (m_spellInfo->IsLootCrafting())
  1490. {
  1491. if (item_id)
  1492. {
  1493. if (!player->HasItemCount(item_id))
  1494. return;
  1495. // remove reagent
  1496. uint32 count = 1;
  1497. player->DestroyItemCount(item_id, count, true);
  1498. // create some random items
  1499. player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
  1500. }
  1501. else
  1502. player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell); // create some random items
  1503. }
  1504. /// @todo ExecuteLogEffectCreateItem(i, m_spellInfo->Effects[i].ItemType);
  1505. }
  1506. void Spell::EffectCreateRandomItem(SpellEffIndex /*effIndex*/)
  1507. {
  1508. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1509. return;
  1510. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  1511. return;
  1512. Player* player = unitTarget->ToPlayer();
  1513. // create some random items
  1514. player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
  1515. /// @todo ExecuteLogEffectCreateItem(i, m_spellInfo->Effects[i].ItemType);
  1516. }
  1517. void Spell::EffectPersistentAA(SpellEffIndex effIndex)
  1518. {
  1519. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  1520. return;
  1521. if (!m_spellAura)
  1522. {
  1523. Unit* caster = m_caster->GetEntry() == WORLD_TRIGGER ? m_originalCaster : m_caster;
  1524. float radius = m_spellInfo->Effects[effIndex].CalcRadius(caster);
  1525. // Caster not in world, might be spell triggered from aura removal
  1526. if (!caster->IsInWorld())
  1527. return;
  1528. DynamicObject* dynObj = new DynamicObject(false);
  1529. if (!dynObj->CreateDynamicObject(sObjectMgr->GenerateLowGuid(HIGHGUID_DYNAMICOBJECT), caster, m_spellInfo->Id, *destTarget, radius, DYNAMIC_OBJECT_AREA_SPELL))
  1530. {
  1531. delete dynObj;
  1532. return;
  1533. }
  1534. if (Aura* aura = Aura::TryCreate(m_spellInfo, MAX_EFFECT_MASK, dynObj, caster, &m_spellValue->EffectBasePoints[0]))
  1535. {
  1536. m_spellAura = aura;
  1537. m_spellAura->_RegisterForTargets();
  1538. }
  1539. else
  1540. return;
  1541. }
  1542. ASSERT(m_spellAura->GetDynobjOwner());
  1543. m_spellAura->_ApplyEffectForTargets(effIndex);
  1544. }
  1545. void Spell::EffectEnergize(SpellEffIndex effIndex)
  1546. {
  1547. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1548. return;
  1549. if (!unitTarget)
  1550. return;
  1551. if (!unitTarget->IsAlive())
  1552. return;
  1553. if (m_spellInfo->Effects[effIndex].MiscValue < 0 || m_spellInfo->Effects[effIndex].MiscValue >= int8(MAX_POWERS))
  1554. return;
  1555. Powers power = Powers(m_spellInfo->Effects[effIndex].MiscValue);
  1556. // Some level depends spells
  1557. int level_multiplier = 0;
  1558. int level_diff = 0;
  1559. switch (m_spellInfo->Id)
  1560. {
  1561. case 9512: // Restore Energy
  1562. level_diff = m_caster->getLevel() - 40;
  1563. level_multiplier = 2;
  1564. break;
  1565. case 24571: // Blood Fury
  1566. level_diff = m_caster->getLevel() - 60;
  1567. level_multiplier = 10;
  1568. break;
  1569. case 24532: // Burst of Energy
  1570. level_diff = m_caster->getLevel() - 60;
  1571. level_multiplier = 4;
  1572. break;
  1573. case 31930: // Judgements of the Wise
  1574. case 63375: // Improved Stormstrike
  1575. case 68082: // Glyph of Seal of Command
  1576. damage = int32(CalculatePct(unitTarget->GetCreateMana(), damage));
  1577. break;
  1578. case 48542: // Revitalize
  1579. damage = int32(CalculatePct(unitTarget->GetMaxPower(power), damage));
  1580. break;
  1581. case 67490: // Runic Mana Injector (mana gain increased by 25% for engineers - 3.2.0 patch change)
  1582. {
  1583. if (Player* player = m_caster->ToPlayer())
  1584. if (player->HasSkill(SKILL_ENGINEERING))
  1585. AddPct(damage, 25);
  1586. break;
  1587. }
  1588. case 71132: // Glyph of Shadow Word: Pain
  1589. damage = int32(CalculatePct(unitTarget->GetCreateMana(), 1)); // set 1 as value, missing in dbc
  1590. break;
  1591. default:
  1592. break;
  1593. }
  1594. if (level_diff > 0)
  1595. damage -= level_multiplier * level_diff;
  1596. if (damage < 0)
  1597. return;
  1598. if (unitTarget->GetMaxPower(power) == 0)
  1599. return;
  1600. m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, damage, power);
  1601. // Mad Alchemist's Potion
  1602. if (m_spellInfo->Id == 45051)
  1603. {
  1604. // find elixirs on target
  1605. bool guardianFound = false;
  1606. bool battleFound = false;
  1607. Unit::AuraApplicationMap& Auras = unitTarget->GetAppliedAuras();
  1608. for (Unit::AuraApplicationMap::iterator itr = Auras.begin(); itr != Auras.end(); ++itr)
  1609. {
  1610. uint32 spell_id = itr->second->GetBase()->GetId();
  1611. if (!guardianFound)
  1612. if (sSpellMgr->IsSpellMemberOfSpellGroup(spell_id, SPELL_GROUP_ELIXIR_GUARDIAN))
  1613. guardianFound = true;
  1614. if (!battleFound)
  1615. if (sSpellMgr->IsSpellMemberOfSpellGroup(spell_id, SPELL_GROUP_ELIXIR_BATTLE))
  1616. battleFound = true;
  1617. if (battleFound && guardianFound)
  1618. break;
  1619. }
  1620. // get all available elixirs by mask and spell level
  1621. std::set<uint32> avalibleElixirs;
  1622. if (!guardianFound)
  1623. sSpellMgr->GetSetOfSpellsInSpellGroup(SPELL_GROUP_ELIXIR_GUARDIAN, avalibleElixirs);
  1624. if (!battleFound)
  1625. sSpellMgr->GetSetOfSpellsInSpellGroup(SPELL_GROUP_ELIXIR_BATTLE, avalibleElixirs);
  1626. for (std::set<uint32>::iterator itr = avalibleElixirs.begin(); itr != avalibleElixirs.end();)
  1627. {
  1628. SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(*itr);
  1629. if (spellInfo->SpellLevel < m_spellInfo->SpellLevel || spellInfo->SpellLevel > unitTarget->getLevel())
  1630. avalibleElixirs.erase(itr++);
  1631. else if (sSpellMgr->IsSpellMemberOfSpellGroup(*itr, SPELL_GROUP_ELIXIR_SHATTRATH))
  1632. avalibleElixirs.erase(itr++);
  1633. else if (sSpellMgr->IsSpellMemberOfSpellGroup(*itr, SPELL_GROUP_ELIXIR_UNSTABLE))
  1634. avalibleElixirs.erase(itr++);
  1635. else
  1636. ++itr;
  1637. }
  1638. if (!avalibleElixirs.empty())
  1639. {
  1640. // cast random elixir on target
  1641. m_caster->CastSpell(unitTarget, Trinity::Containers::SelectRandomContainerElement(avalibleElixirs), true, m_CastItem);
  1642. }
  1643. }
  1644. }
  1645. void Spell::EffectEnergizePct(SpellEffIndex effIndex)
  1646. {
  1647. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1648. return;
  1649. if (!unitTarget)
  1650. return;
  1651. if (!unitTarget->IsAlive())
  1652. return;
  1653. if (m_spellInfo->Effects[effIndex].MiscValue < 0 || m_spellInfo->Effects[effIndex].MiscValue >= int8(MAX_POWERS))
  1654. return;
  1655. Powers power = Powers(m_spellInfo->Effects[effIndex].MiscValue);
  1656. uint32 maxPower = unitTarget->GetMaxPower(power);
  1657. if (maxPower == 0)
  1658. return;
  1659. uint32 gain = CalculatePct(maxPower, damage);
  1660. m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power);
  1661. }
  1662. void Spell::SendLoot(uint64 guid, LootType loottype)
  1663. {
  1664. Player* player = m_caster->ToPlayer();
  1665. if (!player)
  1666. return;
  1667. if (gameObjTarget)
  1668. {
  1669. // Players shouldn't be able to loot gameobjects that are currently despawned
  1670. if (!gameObjTarget->isSpawned() && !player->IsGameMaster())
  1671. {
  1672. TC_LOG_ERROR("spells", "Possible hacking attempt: Player %s [guid: %u] tried to loot a gameobject [entry: %u id: %u] which is on respawn time without being in GM mode!",
  1673. player->GetName().c_str(), player->GetGUIDLow(), gameObjTarget->GetEntry(), gameObjTarget->GetGUIDLow());
  1674. return;
  1675. }
  1676. // special case, already has GossipHello inside so return and avoid calling twice
  1677. if (gameObjTarget->GetGoType() == GAMEOBJECT_TYPE_GOOBER)
  1678. {
  1679. gameObjTarget->Use(m_caster);
  1680. return;
  1681. }
  1682. if (sScriptMgr->OnGossipHello(player, gameObjTarget))
  1683. return;
  1684. if (gameObjTarget->AI()->GossipHello(player))
  1685. return;
  1686. switch (gameObjTarget->GetGoType())
  1687. {
  1688. case GAMEOBJECT_TYPE_DOOR:
  1689. case GAMEOBJECT_TYPE_BUTTON:
  1690. gameObjTarget->UseDoorOrButton(0, false, player);
  1691. return;
  1692. case GAMEOBJECT_TYPE_QUESTGIVER:
  1693. player->PrepareGossipMenu(gameObjTarget, gameObjTarget->GetGOInfo()->questgiver.gossipID, true);
  1694. player->SendPreparedGossip(gameObjTarget);
  1695. return;
  1696. case GAMEOBJECT_TYPE_SPELL_FOCUS:
  1697. // triggering linked GO
  1698. if (uint32 trapEntry = gameObjTarget->GetGOInfo()->spellFocus.linkedTrapId)
  1699. gameObjTarget->TriggeringLinkedGameObject(trapEntry, m_caster);
  1700. return;
  1701. case GAMEOBJECT_TYPE_CHEST:
  1702. /// @todo possible must be moved to loot release (in different from linked triggering)
  1703. if (gameObjTarget->GetGOInfo()->chest.eventId)
  1704. {
  1705. TC_LOG_DEBUG("spells", "Chest ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->chest.eventId, gameObjTarget->GetDBTableGUIDLow());
  1706. player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->chest.eventId, player, gameObjTarget);
  1707. }
  1708. // triggering linked GO
  1709. if (uint32 trapEntry = gameObjTarget->GetGOInfo()->chest.linkedTrapId)
  1710. gameObjTarget->TriggeringLinkedGameObject(trapEntry, m_caster);
  1711. // Don't return, let loots been taken
  1712. default:
  1713. break;
  1714. }
  1715. }
  1716. // Send loot
  1717. player->SendLoot(guid, loottype);
  1718. }
  1719. void Spell::EffectOpenLock(SpellEffIndex effIndex)
  1720. {
  1721. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  1722. return;
  1723. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  1724. {
  1725. TC_LOG_DEBUG("spells", "WORLD: Open Lock - No Player Caster!");
  1726. return;
  1727. }
  1728. Player* player = m_caster->ToPlayer();
  1729. uint32 lockId = 0;
  1730. uint64 guid = 0;
  1731. // Get lockId
  1732. if (gameObjTarget)
  1733. {
  1734. GameObjectTemplate const* goInfo = gameObjTarget->GetGOInfo();
  1735. // Arathi Basin banner opening. /// @todo Verify correctness of this check
  1736. if ((goInfo->type == GAMEOBJECT_TYPE_BUTTON && goInfo->button.noDamageImmune) ||
  1737. (goInfo->type == GAMEOBJECT_TYPE_GOOBER && goInfo->goober.losOK))
  1738. {
  1739. //CanUseBattlegroundObject() already called in CheckCast()
  1740. // in battleground check
  1741. if (Battleground* bg = player->GetBattleground())
  1742. {
  1743. bg->EventPlayerClickedOnFlag(player, gameObjTarget);
  1744. return;
  1745. }
  1746. }
  1747. else if (goInfo->type == GAMEOBJECT_TYPE_FLAGSTAND)
  1748. {
  1749. //CanUseBattlegroundObject() already called in CheckCast()
  1750. // in battleground check
  1751. if (Battleground* bg = player->GetBattleground())
  1752. {
  1753. if (bg->GetTypeID(true) == BATTLEGROUND_EY)
  1754. bg->EventPlayerClickedOnFlag(player, gameObjTarget);
  1755. return;
  1756. }
  1757. }
  1758. else if (m_spellInfo->Id == 1842 && gameObjTarget->GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP && gameObjTarget->GetOwner())
  1759. {
  1760. gameObjTarget->SetLootState(GO_JUST_DEACTIVATED);
  1761. return;
  1762. }
  1763. /// @todo Add script for spell 41920 - Filling, becouse server it freze when use this spell
  1764. // handle outdoor pvp object opening, return true if go was registered for handling
  1765. // these objects must have been spawned by outdoorpvp!
  1766. else if (gameObjTarget->GetGOInfo()->type == GAMEOBJECT_TYPE_GOOBER && sOutdoorPvPMgr->HandleOpenGo(player, gameObjTarget->GetGUID()))
  1767. return;
  1768. lockId = goInfo->GetLockId();
  1769. guid = gameObjTarget->GetGUID();
  1770. }
  1771. else if (itemTarget)
  1772. {
  1773. lockId = itemTarget->GetTemplate()->LockID;
  1774. guid = itemTarget->GetGUID();
  1775. }
  1776. else
  1777. {
  1778. TC_LOG_DEBUG("spells", "WORLD: Open Lock - No GameObject/Item Target!");
  1779. return;
  1780. }
  1781. SkillType skillId = SKILL_NONE;
  1782. int32 reqSkillValue = 0;
  1783. int32 skillValue;
  1784. SpellCastResult res = CanOpenLock(effIndex, lockId, skillId, reqSkillValue, skillValue);
  1785. if (res != SPELL_CAST_OK)
  1786. {
  1787. SendCastResult(res);
  1788. return;
  1789. }
  1790. if (gameObjTarget)
  1791. SendLoot(guid, LOOT_SKINNING);
  1792. else if (itemTarget)
  1793. itemTarget->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_UNLOCKED);
  1794. // not allow use skill grow at item base open
  1795. if (!m_CastItem && skillId != SKILL_NONE)
  1796. {
  1797. // update skill if really known
  1798. if (uint32 pureSkillValue = player->GetPureSkillValue(skillId))
  1799. {
  1800. if (gameObjTarget)
  1801. {
  1802. // Allow one skill-up until respawned
  1803. if (!gameObjTarget->IsInSkillupList(player->GetGUIDLow()) &&
  1804. player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue))
  1805. gameObjTarget->AddToSkillupList(player->GetGUIDLow());
  1806. }
  1807. else if (itemTarget)
  1808. {
  1809. // Do one skill-up
  1810. player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue);
  1811. }
  1812. }
  1813. }
  1814. ExecuteLogEffectOpenLock(effIndex, gameObjTarget ? (Object*)gameObjTarget : (Object*)itemTarget);
  1815. }
  1816. void Spell::EffectSummonChangeItem(SpellEffIndex effIndex)
  1817. {
  1818. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  1819. return;
  1820. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  1821. return;
  1822. Player* player = m_caster->ToPlayer();
  1823. // applied only to using item
  1824. if (!m_CastItem)
  1825. return;
  1826. // ... only to item in own inventory/bank/equip_slot
  1827. if (m_CastItem->GetOwnerGUID() != player->GetGUID())
  1828. return;
  1829. uint32 newitemid = m_spellInfo->Effects[effIndex].ItemType;
  1830. if (!newitemid)
  1831. return;
  1832. uint16 pos = m_CastItem->GetPos();
  1833. Item* pNewItem = Item::CreateItem(newitemid, 1, player);
  1834. if (!pNewItem)
  1835. return;
  1836. for (uint8 j = PERM_ENCHANTMENT_SLOT; j <= TEMP_ENCHANTMENT_SLOT; ++j)
  1837. if (m_CastItem->GetEnchantmentId(EnchantmentSlot(j)))
  1838. pNewItem->SetEnchantment(EnchantmentSlot(j), m_CastItem->GetEnchantmentId(EnchantmentSlot(j)), m_CastItem->GetEnchantmentDuration(EnchantmentSlot(j)), m_CastItem->GetEnchantmentCharges(EnchantmentSlot(j)));
  1839. if (m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) < m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY))
  1840. {
  1841. double lossPercent = 1 - m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) / double(m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY));
  1842. player->DurabilityLoss(pNewItem, lossPercent);
  1843. }
  1844. if (player->IsInventoryPos(pos))
  1845. {
  1846. ItemPosCountVec dest;
  1847. InventoryResult msg = player->CanStoreItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true);
  1848. if (msg == EQUIP_ERR_OK)
  1849. {
  1850. player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
  1851. // prevent crash at access and unexpected charges counting with item update queue corrupt
  1852. if (m_CastItem == m_targets.GetItemTarget())
  1853. m_targets.SetItemTarget(NULL);
  1854. m_CastItem = NULL;
  1855. player->StoreItem(dest, pNewItem, true);
  1856. return;
  1857. }
  1858. }
  1859. else if (player->IsBankPos(pos))
  1860. {
  1861. ItemPosCountVec dest;
  1862. uint8 msg = player->CanBankItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true);
  1863. if (msg == EQUIP_ERR_OK)
  1864. {
  1865. player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
  1866. // prevent crash at access and unexpected charges counting with item update queue corrupt
  1867. if (m_CastItem == m_targets.GetItemTarget())
  1868. m_targets.SetItemTarget(NULL);
  1869. m_CastItem = NULL;
  1870. player->BankItem(dest, pNewItem, true);
  1871. return;
  1872. }
  1873. }
  1874. else if (player->IsEquipmentPos(pos))
  1875. {
  1876. uint16 dest;
  1877. player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
  1878. uint8 msg = player->CanEquipItem(m_CastItem->GetSlot(), dest, pNewItem, true);
  1879. if (msg == EQUIP_ERR_OK || msg == EQUIP_ERR_CANT_DO_RIGHT_NOW)
  1880. {
  1881. if (msg == EQUIP_ERR_CANT_DO_RIGHT_NOW) dest = EQUIPMENT_SLOT_MAINHAND;
  1882. // prevent crash at access and unexpected charges counting with item update queue corrupt
  1883. if (m_CastItem == m_targets.GetItemTarget())
  1884. m_targets.SetItemTarget(NULL);
  1885. m_CastItem = NULL;
  1886. player->EquipItem(dest, pNewItem, true);
  1887. player->AutoUnequipOffhandIfNeed();
  1888. return;
  1889. }
  1890. }
  1891. // fail
  1892. delete pNewItem;
  1893. }
  1894. void Spell::EffectProficiency(SpellEffIndex /*effIndex*/)
  1895. {
  1896. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  1897. return;
  1898. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  1899. return;
  1900. Player* p_target = m_caster->ToPlayer();
  1901. uint32 subClassMask = m_spellInfo->EquippedItemSubClassMask;
  1902. if (m_spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && !(p_target->GetWeaponProficiency() & subClassMask))
  1903. {
  1904. p_target->AddWeaponProficiency(subClassMask);
  1905. p_target->SendProficiency(ITEM_CLASS_WEAPON, p_target->GetWeaponProficiency());
  1906. }
  1907. if (m_spellInfo->EquippedItemClass == ITEM_CLASS_ARMOR && !(p_target->GetArmorProficiency() & subClassMask))
  1908. {
  1909. p_target->AddArmorProficiency(subClassMask);
  1910. p_target->SendProficiency(ITEM_CLASS_ARMOR, p_target->GetArmorProficiency());
  1911. }
  1912. }
  1913. void Spell::EffectSummonType(SpellEffIndex effIndex)
  1914. {
  1915. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  1916. return;
  1917. uint32 entry = m_spellInfo->Effects[effIndex].MiscValue;
  1918. if (!entry)
  1919. return;
  1920. SummonPropertiesEntry const* properties = sSummonPropertiesStore.LookupEntry(m_spellInfo->Effects[effIndex].MiscValueB);
  1921. if (!properties)
  1922. {
  1923. TC_LOG_ERROR("spells", "EffectSummonType: Unhandled summon type %u", m_spellInfo->Effects[effIndex].MiscValueB);
  1924. return;
  1925. }
  1926. if (!m_originalCaster)
  1927. return;
  1928. int32 duration = m_spellInfo->GetDuration();
  1929. if (Player* modOwner = m_originalCaster->GetSpellModOwner())
  1930. modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
  1931. TempSummon* summon = NULL;
  1932. // determine how many units should be summoned
  1933. uint32 numSummons;
  1934. // some spells need to summon many units, for those spells number of summons is stored in effect value
  1935. // however so far noone found a generic check to find all of those (there's no related data in summonproperties.dbc
  1936. // and in spell attributes, possibly we need to add a table for those)
  1937. // so here's a list of MiscValueB values, which is currently most generic check
  1938. switch (properties->Id)
  1939. {
  1940. case 64:
  1941. case 61:
  1942. case 1101:
  1943. case 66:
  1944. case 648:
  1945. case 2301:
  1946. case 1061:
  1947. case 1261:
  1948. case 629:
  1949. case 181:
  1950. case 715:
  1951. case 1562:
  1952. case 833:
  1953. case 1161:
  1954. numSummons = (damage > 0) ? damage : 1;
  1955. break;
  1956. default:
  1957. numSummons = 1;
  1958. break;
  1959. }
  1960. switch (properties->Category)
  1961. {
  1962. case SUMMON_CATEGORY_WILD:
  1963. case SUMMON_CATEGORY_ALLY:
  1964. case SUMMON_CATEGORY_UNK:
  1965. if (properties->Flags & 512)
  1966. {
  1967. SummonGuardian(effIndex, entry, properties, numSummons);
  1968. break;
  1969. }
  1970. switch (properties->Type)
  1971. {
  1972. case SUMMON_TYPE_PET:
  1973. case SUMMON_TYPE_GUARDIAN:
  1974. case SUMMON_TYPE_GUARDIAN2:
  1975. case SUMMON_TYPE_MINION:
  1976. SummonGuardian(effIndex, entry, properties, numSummons);
  1977. break;
  1978. // Summons a vehicle, but doesn't force anyone to enter it (see SUMMON_CATEGORY_VEHICLE)
  1979. case SUMMON_TYPE_VEHICLE:
  1980. case SUMMON_TYPE_VEHICLE2:
  1981. summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
  1982. break;
  1983. case SUMMON_TYPE_LIGHTWELL:
  1984. case SUMMON_TYPE_TOTEM:
  1985. {
  1986. summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
  1987. if (!summon || !summon->IsTotem())
  1988. return;
  1989. // Mana Tide Totem
  1990. if (m_spellInfo->Id == 16190)
  1991. damage = m_caster->CountPctFromMaxHealth(10);
  1992. if (damage) // if not spell info, DB values used
  1993. {
  1994. summon->SetMaxHealth(damage);
  1995. summon->SetHealth(damage);
  1996. }
  1997. break;
  1998. }
  1999. case SUMMON_TYPE_MINIPET:
  2000. {
  2001. summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
  2002. if (!summon || !summon->HasUnitTypeMask(UNIT_MASK_MINION))
  2003. return;
  2004. summon->SelectLevel(); // some summoned creaters have different from 1 DB data for level/hp
  2005. summon->SetUInt32Value(UNIT_NPC_FLAGS, summon->GetCreatureTemplate()->npcflag);
  2006. summon->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
  2007. summon->AI()->EnterEvadeMode();
  2008. break;
  2009. }
  2010. default:
  2011. {
  2012. float radius = m_spellInfo->Effects[effIndex].CalcRadius();
  2013. TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN;
  2014. for (uint32 count = 0; count < numSummons; ++count)
  2015. {
  2016. Position pos;
  2017. if (count == 0)
  2018. pos = *destTarget;
  2019. else
  2020. // randomize position for multiple summons
  2021. pos = m_caster->GetRandomPoint(*destTarget, radius);
  2022. summon = m_originalCaster->SummonCreature(entry, pos, summonType, duration);
  2023. if (!summon)
  2024. continue;
  2025. if (properties->Category == SUMMON_CATEGORY_ALLY)
  2026. {
  2027. summon->SetOwnerGUID(m_originalCaster->GetGUID());
  2028. summon->setFaction(m_originalCaster->getFaction());
  2029. summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
  2030. }
  2031. ExecuteLogEffectSummonObject(effIndex, summon);
  2032. }
  2033. return;
  2034. }
  2035. }//switch
  2036. break;
  2037. case SUMMON_CATEGORY_PET:
  2038. SummonGuardian(effIndex, entry, properties, numSummons);
  2039. break;
  2040. case SUMMON_CATEGORY_PUPPET:
  2041. summon = m_caster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_originalCaster, m_spellInfo->Id);
  2042. break;
  2043. case SUMMON_CATEGORY_VEHICLE:
  2044. // Summoning spells (usually triggered by npc_spellclick) that spawn a vehicle and that cause the clicker
  2045. // to cast a ride vehicle spell on the summoned unit.
  2046. summon = m_originalCaster->GetMap()->SummonCreature(entry, *destTarget, properties, duration, m_caster, m_spellInfo->Id);
  2047. if (!summon || !summon->IsVehicle())
  2048. return;
  2049. // The spell that this effect will trigger. It has SPELL_AURA_CONTROL_VEHICLE
  2050. uint32 spellId = VEHICLE_SPELL_RIDE_HARDCODED;
  2051. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(m_spellInfo->Effects[effIndex].CalcValue());
  2052. if (spellInfo && spellInfo->HasAura(SPELL_AURA_CONTROL_VEHICLE))
  2053. spellId = spellInfo->Id;
  2054. // Hard coded enter vehicle spell
  2055. m_originalCaster->CastSpell(summon, spellId, true);
  2056. uint32 faction = properties->Faction;
  2057. if (!faction)
  2058. faction = m_originalCaster->getFaction();
  2059. summon->setFaction(faction);
  2060. break;
  2061. }
  2062. if (summon)
  2063. {
  2064. summon->SetCreatorGUID(m_originalCaster->GetGUID());
  2065. ExecuteLogEffectSummonObject(effIndex, summon);
  2066. }
  2067. }
  2068. void Spell::EffectLearnSpell(SpellEffIndex effIndex)
  2069. {
  2070. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2071. return;
  2072. if (!unitTarget)
  2073. return;
  2074. if (unitTarget->GetTypeId() != TYPEID_PLAYER)
  2075. {
  2076. if (unitTarget->ToPet())
  2077. EffectLearnPetSpell(effIndex);
  2078. return;
  2079. }
  2080. Player* player = unitTarget->ToPlayer();
  2081. uint32 spellToLearn = (m_spellInfo->Id == 483 || m_spellInfo->Id == 55884) ? damage : m_spellInfo->Effects[effIndex].TriggerSpell;
  2082. player->learnSpell(spellToLearn, false);
  2083. TC_LOG_DEBUG("spells", "Spell: Player %u has learned spell %u from NpcGUID=%u", player->GetGUIDLow(), spellToLearn, m_caster->GetGUIDLow());
  2084. }
  2085. typedef std::list< std::pair<uint32, uint64> > DispelList;
  2086. void Spell::EffectDispel(SpellEffIndex effIndex)
  2087. {
  2088. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2089. return;
  2090. if (!unitTarget)
  2091. return;
  2092. // Create dispel mask by dispel type
  2093. uint32 dispel_type = m_spellInfo->Effects[effIndex].MiscValue;
  2094. uint32 dispelMask = SpellInfo::GetDispelMask(DispelType(dispel_type));
  2095. DispelChargesList dispel_list;
  2096. unitTarget->GetDispellableAuraList(m_caster, dispelMask, dispel_list);
  2097. if (dispel_list.empty())
  2098. return;
  2099. // Ok if exist some buffs for dispel try dispel it
  2100. uint32 failCount = 0;
  2101. DispelChargesList success_list;
  2102. WorldPacket dataFail(SMSG_DISPEL_FAILED, 8+8+4+4+damage*4);
  2103. // dispel N = damage buffs (or while exist buffs for dispel)
  2104. for (int32 count = 0; count < damage && !dispel_list.empty();)
  2105. {
  2106. // Random select buff for dispel
  2107. DispelChargesList::iterator itr = dispel_list.begin();
  2108. std::advance(itr, urand(0, dispel_list.size() - 1));
  2109. int32 chance = itr->first->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster));
  2110. // 2.4.3 Patch Notes: "Dispel effects will no longer attempt to remove effects that have 100% dispel resistance."
  2111. if (!chance)
  2112. {
  2113. dispel_list.erase(itr);
  2114. continue;
  2115. }
  2116. else
  2117. {
  2118. if (roll_chance_i(chance))
  2119. {
  2120. bool alreadyListed = false;
  2121. for (DispelChargesList::iterator successItr = success_list.begin(); successItr != success_list.end(); ++successItr)
  2122. {
  2123. if (successItr->first->GetId() == itr->first->GetId())
  2124. {
  2125. ++successItr->second;
  2126. alreadyListed = true;
  2127. }
  2128. }
  2129. if (!alreadyListed)
  2130. success_list.push_back(std::make_pair(itr->first, 1));
  2131. --itr->second;
  2132. if (itr->second <= 0)
  2133. dispel_list.erase(itr);
  2134. }
  2135. else
  2136. {
  2137. if (!failCount)
  2138. {
  2139. // Failed to dispell
  2140. dataFail << uint64(m_caster->GetGUID()); // Caster GUID
  2141. dataFail << uint64(unitTarget->GetGUID()); // Victim GUID
  2142. dataFail << uint32(m_spellInfo->Id); // dispel spell id
  2143. }
  2144. ++failCount;
  2145. dataFail << uint32(itr->first->GetId()); // Spell Id
  2146. }
  2147. ++count;
  2148. }
  2149. }
  2150. if (failCount)
  2151. m_caster->SendMessageToSet(&dataFail, true);
  2152. if (success_list.empty())
  2153. return;
  2154. WorldPacket dataSuccess(SMSG_SPELLDISPELLOG, 8+8+4+1+4+success_list.size()*5);
  2155. // Send packet header
  2156. dataSuccess.append(unitTarget->GetPackGUID()); // Victim GUID
  2157. dataSuccess.append(m_caster->GetPackGUID()); // Caster GUID
  2158. dataSuccess << uint32(m_spellInfo->Id); // dispel spell id
  2159. dataSuccess << uint8(0); // not used
  2160. dataSuccess << uint32(success_list.size()); // count
  2161. for (DispelChargesList::iterator itr = success_list.begin(); itr != success_list.end(); ++itr)
  2162. {
  2163. // Send dispelled spell info
  2164. dataSuccess << uint32(itr->first->GetId()); // Spell Id
  2165. dataSuccess << uint8(0); // 0 - dispelled !=0 cleansed
  2166. unitTarget->RemoveAurasDueToSpellByDispel(itr->first->GetId(), m_spellInfo->Id, itr->first->GetCasterGUID(), m_caster, itr->second);
  2167. }
  2168. m_caster->SendMessageToSet(&dataSuccess, true);
  2169. // On success dispel
  2170. // Devour Magic
  2171. if (m_spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo->GetCategory() == SPELLCATEGORY_DEVOUR_MAGIC)
  2172. {
  2173. int32 heal_amount = m_spellInfo->Effects[EFFECT_1].CalcValue();
  2174. m_caster->CastCustomSpell(m_caster, 19658, &heal_amount, NULL, NULL, true);
  2175. // Glyph of Felhunter
  2176. if (Unit* owner = m_caster->GetOwner())
  2177. if (owner->GetAura(56249))
  2178. owner->CastCustomSpell(owner, 19658, &heal_amount, NULL, NULL, true);
  2179. }
  2180. }
  2181. void Spell::EffectDualWield(SpellEffIndex /*effIndex*/)
  2182. {
  2183. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2184. return;
  2185. unitTarget->SetCanDualWield(true);
  2186. }
  2187. void Spell::EffectPull(SpellEffIndex effIndex)
  2188. {
  2189. /// @todo create a proper pull towards distract spell center for distract
  2190. EffectNULL(effIndex);
  2191. }
  2192. void Spell::EffectDistract(SpellEffIndex /*effIndex*/)
  2193. {
  2194. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2195. return;
  2196. // Check for possible target
  2197. if (!unitTarget || unitTarget->IsInCombat())
  2198. return;
  2199. // target must be OK to do this
  2200. if (unitTarget->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_STUNNED | UNIT_STATE_FLEEING))
  2201. return;
  2202. unitTarget->SetFacingTo(unitTarget->GetAngle(destTarget));
  2203. unitTarget->ClearUnitState(UNIT_STATE_MOVING);
  2204. if (unitTarget->GetTypeId() == TYPEID_UNIT)
  2205. unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILLISECONDS);
  2206. }
  2207. void Spell::EffectPickPocket(SpellEffIndex /*effIndex*/)
  2208. {
  2209. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2210. return;
  2211. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  2212. return;
  2213. // victim must be creature and attackable
  2214. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->IsFriendlyTo(unitTarget))
  2215. return;
  2216. // victim have to be alive and humanoid or undead
  2217. if (unitTarget->IsAlive() && (unitTarget->GetCreatureTypeMask() &CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD) != 0)
  2218. m_caster->ToPlayer()->SendLoot(unitTarget->GetGUID(), LOOT_PICKPOCKETING);
  2219. }
  2220. void Spell::EffectAddFarsight(SpellEffIndex effIndex)
  2221. {
  2222. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  2223. return;
  2224. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  2225. return;
  2226. float radius = m_spellInfo->Effects[effIndex].CalcRadius();
  2227. int32 duration = m_spellInfo->GetDuration();
  2228. // Caster not in world, might be spell triggered from aura removal
  2229. if (!m_caster->IsInWorld())
  2230. return;
  2231. DynamicObject* dynObj = new DynamicObject(true);
  2232. if (!dynObj->CreateDynamicObject(sObjectMgr->GenerateLowGuid(HIGHGUID_DYNAMICOBJECT), m_caster, m_spellInfo->Id, *destTarget, radius, DYNAMIC_OBJECT_FARSIGHT_FOCUS))
  2233. {
  2234. delete dynObj;
  2235. return;
  2236. }
  2237. dynObj->SetDuration(duration);
  2238. dynObj->SetCasterViewpoint();
  2239. }
  2240. void Spell::EffectUntrainTalents(SpellEffIndex /*effIndex*/)
  2241. {
  2242. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2243. return;
  2244. if (!unitTarget || m_caster->GetTypeId() == TYPEID_PLAYER)
  2245. return;
  2246. if (uint64 guid = m_caster->GetGUID()) // the trainer is the caster
  2247. unitTarget->ToPlayer()->SendTalentWipeConfirm(guid);
  2248. }
  2249. void Spell::EffectTeleUnitsFaceCaster(SpellEffIndex effIndex)
  2250. {
  2251. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2252. return;
  2253. if (!unitTarget)
  2254. return;
  2255. if (unitTarget->IsInFlight())
  2256. return;
  2257. float dis = m_spellInfo->Effects[effIndex].CalcRadius(m_caster);
  2258. float fx, fy, fz;
  2259. m_caster->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
  2260. unitTarget->NearTeleportTo(fx, fy, fz, -m_caster->GetOrientation(), unitTarget == m_caster);
  2261. }
  2262. void Spell::EffectLearnSkill(SpellEffIndex effIndex)
  2263. {
  2264. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2265. return;
  2266. if (unitTarget->GetTypeId() != TYPEID_PLAYER)
  2267. return;
  2268. if (damage < 0)
  2269. return;
  2270. uint32 skillid = m_spellInfo->Effects[effIndex].MiscValue;
  2271. uint16 skillval = unitTarget->ToPlayer()->GetPureSkillValue(skillid);
  2272. unitTarget->ToPlayer()->SetSkill(skillid, m_spellInfo->Effects[effIndex].CalcValue(), skillval?skillval:1, damage*75);
  2273. }
  2274. void Spell::EffectAddHonor(SpellEffIndex /*effIndex*/)
  2275. {
  2276. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2277. return;
  2278. if (unitTarget->GetTypeId() != TYPEID_PLAYER)
  2279. return;
  2280. // not scale value for item based reward (/10 value expected)
  2281. if (m_CastItem)
  2282. {
  2283. unitTarget->ToPlayer()->RewardHonor(NULL, 1, damage/10);
  2284. TC_LOG_DEBUG("spells", "SpellEffect::AddHonor (spell_id %u) rewards %d honor points (item %u) for player: %u", m_spellInfo->Id, damage/10, m_CastItem->GetEntry(), unitTarget->ToPlayer()->GetGUIDLow());
  2285. return;
  2286. }
  2287. // do not allow to add too many honor for player (50 * 21) = 1040 at level 70, or (50 * 31) = 1550 at level 80
  2288. if (damage <= 50)
  2289. {
  2290. uint32 honor_reward = Trinity::Honor::hk_honor_at_level(unitTarget->getLevel(), float(damage));
  2291. unitTarget->ToPlayer()->RewardHonor(NULL, 1, honor_reward);
  2292. TC_LOG_DEBUG("spells", "SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, unitTarget->ToPlayer()->GetGUIDLow());
  2293. }
  2294. else
  2295. {
  2296. //maybe we have correct honor_gain in damage already
  2297. unitTarget->ToPlayer()->RewardHonor(NULL, 1, damage);
  2298. TC_LOG_DEBUG("spells", "SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, unitTarget->ToPlayer()->GetGUIDLow());
  2299. }
  2300. }
  2301. void Spell::EffectTradeSkill(SpellEffIndex /*effIndex*/)
  2302. {
  2303. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  2304. return;
  2305. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  2306. return;
  2307. // uint32 skillid = m_spellInfo->Effects[i].MiscValue;
  2308. // uint16 skillmax = unitTarget->ToPlayer()->(skillid);
  2309. // m_caster->ToPlayer()->SetSkill(skillid, skillval?skillval:1, skillmax+75);
  2310. }
  2311. void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex)
  2312. {
  2313. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2314. return;
  2315. if (!itemTarget)
  2316. return;
  2317. Player* player = m_caster->ToPlayer();
  2318. if (!player)
  2319. return;
  2320. // Handle vellums
  2321. if (itemTarget->IsWeaponVellum() || itemTarget->IsArmorVellum())
  2322. {
  2323. // destroy one vellum from stack
  2324. uint32 count = 1;
  2325. player->DestroyItemCount(itemTarget, count, true);
  2326. unitTarget = player;
  2327. // and add a scroll
  2328. DoCreateItem(effIndex, m_spellInfo->Effects[effIndex].ItemType);
  2329. itemTarget = NULL;
  2330. m_targets.SetItemTarget(NULL);
  2331. }
  2332. else
  2333. {
  2334. // do not increase skill if vellum used
  2335. if (!(m_CastItem && m_CastItem->GetTemplate()->Flags & ITEM_PROTO_FLAG_TRIGGERED_CAST))
  2336. player->UpdateCraftSkill(m_spellInfo->Id);
  2337. uint32 enchant_id = m_spellInfo->Effects[effIndex].MiscValue;
  2338. if (!enchant_id)
  2339. return;
  2340. SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
  2341. if (!pEnchant)
  2342. return;
  2343. // item can be in trade slot and have owner diff. from caster
  2344. Player* item_owner = itemTarget->GetOwner();
  2345. if (!item_owner)
  2346. return;
  2347. if (item_owner != player && player->GetSession()->HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE))
  2348. {
  2349. sLog->outCommand(player->GetSession()->GetAccountId(), "GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
  2350. player->GetName().c_str(), player->GetSession()->GetAccountId(),
  2351. itemTarget->GetTemplate()->Name1.c_str(), itemTarget->GetEntry(),
  2352. item_owner->GetName().c_str(), item_owner->GetSession()->GetAccountId());
  2353. }
  2354. // remove old enchanting before applying new if equipped
  2355. item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, false);
  2356. itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0, m_caster->GetGUID());
  2357. // add new enchanting if equipped
  2358. item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, true);
  2359. item_owner->RemoveTradeableItem(itemTarget);
  2360. itemTarget->ClearSoulboundTradeable(item_owner);
  2361. }
  2362. }
  2363. void Spell::EffectEnchantItemPrismatic(SpellEffIndex effIndex)
  2364. {
  2365. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2366. return;
  2367. if (!itemTarget)
  2368. return;
  2369. Player* player = m_caster->ToPlayer();
  2370. if (!player)
  2371. return;
  2372. uint32 enchantId = m_spellInfo->Effects[effIndex].MiscValue;
  2373. if (!enchantId)
  2374. return;
  2375. SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId);
  2376. if (!enchant)
  2377. return;
  2378. // support only enchantings with add socket in this slot
  2379. {
  2380. bool add_socket = false;
  2381. for (uint8 i = 0; i < MAX_ITEM_ENCHANTMENT_EFFECTS; ++i)
  2382. {
  2383. if (enchant->type[i] == ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET)
  2384. {
  2385. add_socket = true;
  2386. break;
  2387. }
  2388. }
  2389. if (!add_socket)
  2390. {
  2391. TC_LOG_ERROR("spells", "Spell::EffectEnchantItemPrismatic: attempt apply enchant spell %u with SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC (%u) but without ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET (%u), not suppoted yet.",
  2392. m_spellInfo->Id, SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC, ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET);
  2393. return;
  2394. }
  2395. }
  2396. // item can be in trade slot and have owner diff. from caster
  2397. Player* item_owner = itemTarget->GetOwner();
  2398. if (!item_owner)
  2399. return;
  2400. if (item_owner != player && player->GetSession()->HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE))
  2401. {
  2402. sLog->outCommand(player->GetSession()->GetAccountId(), "GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
  2403. player->GetName().c_str(), player->GetSession()->GetAccountId(),
  2404. itemTarget->GetTemplate()->Name1.c_str(), itemTarget->GetEntry(),
  2405. item_owner->GetName().c_str(), item_owner->GetSession()->GetAccountId());
  2406. }
  2407. // remove old enchanting before applying new if equipped
  2408. item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, false);
  2409. itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchantId, 0, 0, m_caster->GetGUID());
  2410. // add new enchanting if equipped
  2411. item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, true);
  2412. item_owner->RemoveTradeableItem(itemTarget);
  2413. itemTarget->ClearSoulboundTradeable(item_owner);
  2414. }
  2415. void Spell::EffectEnchantItemTmp(SpellEffIndex effIndex)
  2416. {
  2417. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2418. return;
  2419. Player* player = m_caster->ToPlayer();
  2420. if (!player)
  2421. return;
  2422. // Rockbiter Weapon apply to both weapon
  2423. if (!itemTarget)
  2424. return;
  2425. if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellFamilyFlags[0] & 0x400000)
  2426. {
  2427. uint32 spell_id = 0;
  2428. // enchanting spell selected by calculated damage-per-sec stored in Effect[1] base value
  2429. // Note: damage calculated (correctly) with rounding int32(float(v)) but
  2430. // RW enchantments applied damage int32(float(v)+0.5), this create 0..1 difference sometime
  2431. switch (damage)
  2432. {
  2433. // Rank 1
  2434. case 2: spell_id = 36744; break; // 0% [ 7% == 2, 14% == 2, 20% == 2]
  2435. // Rank 2
  2436. case 4: spell_id = 36753; break; // 0% [ 7% == 4, 14% == 4]
  2437. case 5: spell_id = 36751; break; // 20%
  2438. // Rank 3
  2439. case 6: spell_id = 36754; break; // 0% [ 7% == 6, 14% == 6]
  2440. case 7: spell_id = 36755; break; // 20%
  2441. // Rank 4
  2442. case 9: spell_id = 36761; break; // 0% [ 7% == 6]
  2443. case 10: spell_id = 36758; break; // 14%
  2444. case 11: spell_id = 36760; break; // 20%
  2445. default:
  2446. TC_LOG_ERROR("spells", "Spell::EffectEnchantItemTmp: Damage %u not handled in S'RW", damage);
  2447. return;
  2448. }
  2449. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id);
  2450. if (!spellInfo)
  2451. {
  2452. TC_LOG_ERROR("spells", "Spell::EffectEnchantItemTmp: unknown spell id %i", spell_id);
  2453. return;
  2454. }
  2455. for (int j = BASE_ATTACK; j <= OFF_ATTACK; ++j)
  2456. {
  2457. if (Item* item = player->GetWeaponForAttack(WeaponAttackType(j)))
  2458. {
  2459. if (item->IsFitToSpellRequirements(m_spellInfo))
  2460. {
  2461. Spell* spell = new Spell(m_caster, spellInfo, TRIGGERED_FULL_MASK);
  2462. SpellCastTargets targets;
  2463. targets.SetItemTarget(item);
  2464. spell->prepare(&targets);
  2465. }
  2466. }
  2467. }
  2468. return;
  2469. }
  2470. if (!itemTarget)
  2471. return;
  2472. uint32 enchant_id = m_spellInfo->Effects[effIndex].MiscValue;
  2473. if (!enchant_id)
  2474. {
  2475. TC_LOG_ERROR("spells", "Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have 0 as enchanting id", m_spellInfo->Id, effIndex);
  2476. return;
  2477. }
  2478. SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
  2479. if (!pEnchant)
  2480. {
  2481. TC_LOG_ERROR("spells", "Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have not existed enchanting id %u ", m_spellInfo->Id, effIndex, enchant_id);
  2482. return;
  2483. }
  2484. // select enchantment duration
  2485. uint32 duration;
  2486. // rogue family enchantments exception by duration
  2487. if (m_spellInfo->Id == 38615)
  2488. duration = 1800; // 30 mins
  2489. // other rogue family enchantments always 1 hour (some have spell damage=0, but some have wrong data in EffBasePoints)
  2490. else if (m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE)
  2491. duration = 3600; // 1 hour
  2492. // shaman family enchantments
  2493. else if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN)
  2494. duration = 1800; // 30 mins
  2495. // other cases with this SpellVisual already selected
  2496. else if (m_spellInfo->SpellVisual[0] == 215)
  2497. duration = 1800; // 30 mins
  2498. // some fishing pole bonuses except Glow Worm which lasts full hour
  2499. else if (m_spellInfo->SpellVisual[0] == 563 && m_spellInfo->Id != 64401)
  2500. duration = 600; // 10 mins
  2501. // shaman rockbiter enchantments
  2502. else if (m_spellInfo->SpellVisual[0] == 0)
  2503. duration = 1800; // 30 mins
  2504. else if (m_spellInfo->Id == 29702)
  2505. duration = 300; // 5 mins
  2506. else if (m_spellInfo->Id == 37360)
  2507. duration = 300; // 5 mins
  2508. // default case
  2509. else
  2510. duration = 3600; // 1 hour
  2511. // item can be in trade slot and have owner diff. from caster
  2512. Player* item_owner = itemTarget->GetOwner();
  2513. if (!item_owner)
  2514. return;
  2515. if (item_owner != player && player->GetSession()->HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE))
  2516. {
  2517. sLog->outCommand(player->GetSession()->GetAccountId(), "GM %s (Account: %u) enchanting(temp): %s (Entry: %d) for player: %s (Account: %u)",
  2518. player->GetName().c_str(), player->GetSession()->GetAccountId(),
  2519. itemTarget->GetTemplate()->Name1.c_str(), itemTarget->GetEntry(),
  2520. item_owner->GetName().c_str(), item_owner->GetSession()->GetAccountId());
  2521. }
  2522. // remove old enchanting before applying new if equipped
  2523. item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, false);
  2524. itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0, m_caster->GetGUID());
  2525. // add new enchanting if equipped
  2526. item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true);
  2527. }
  2528. void Spell::EffectTameCreature(SpellEffIndex /*effIndex*/)
  2529. {
  2530. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2531. return;
  2532. if (m_caster->GetPetGUID())
  2533. return;
  2534. if (!unitTarget)
  2535. return;
  2536. if (unitTarget->GetTypeId() != TYPEID_UNIT)
  2537. return;
  2538. Creature* creatureTarget = unitTarget->ToCreature();
  2539. if (creatureTarget->IsPet())
  2540. return;
  2541. if (m_caster->getClass() != CLASS_HUNTER)
  2542. return;
  2543. // cast finish successfully
  2544. //SendChannelUpdate(0);
  2545. finish();
  2546. Pet* pet = m_caster->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
  2547. if (!pet) // in very specific state like near world end/etc.
  2548. return;
  2549. // "kill" original creature
  2550. creatureTarget->DespawnOrUnsummon();
  2551. uint8 level = m_caster->getLevel();
  2552. // prepare visual effect for levelup
  2553. pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
  2554. // add to world
  2555. pet->GetMap()->AddToMap(pet->ToCreature());
  2556. // visual effect for levelup
  2557. pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
  2558. // caster have pet now
  2559. m_caster->SetMinion(pet, true);
  2560. pet->InitTalentForLevel();
  2561. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  2562. {
  2563. pet->SavePetToDB(PET_SAVE_AS_CURRENT);
  2564. m_caster->ToPlayer()->PetSpellInitialize();
  2565. }
  2566. }
  2567. void Spell::EffectSummonPet(SpellEffIndex effIndex)
  2568. {
  2569. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  2570. return;
  2571. Player* owner = NULL;
  2572. if (m_originalCaster)
  2573. {
  2574. owner = m_originalCaster->ToPlayer();
  2575. if (!owner && m_originalCaster->ToCreature()->IsTotem())
  2576. owner = m_originalCaster->GetCharmerOrOwnerPlayerOrPlayerItself();
  2577. }
  2578. uint32 petentry = m_spellInfo->Effects[effIndex].MiscValue;
  2579. if (!owner)
  2580. {
  2581. SummonPropertiesEntry const* properties = sSummonPropertiesStore.LookupEntry(67);
  2582. if (properties)
  2583. SummonGuardian(effIndex, petentry, properties, 1);
  2584. return;
  2585. }
  2586. Pet* OldSummon = owner->GetPet();
  2587. // if pet requested type already exist
  2588. if (OldSummon)
  2589. {
  2590. OldSummon->m_CreatureSpellCooldowns.clear();
  2591. OldSummon->SetHealth(OldSummon->GetMaxHealth());
  2592. OldSummon->SetPower(OldSummon->getPowerType(), OldSummon->GetMaxPower(OldSummon->getPowerType()));
  2593. Unit::AuraApplicationMap& appliedAuras = OldSummon->GetAppliedAuras();
  2594. for (Unit::AuraApplicationMap::iterator itr = appliedAuras.begin(); itr != appliedAuras.end(); ++itr)
  2595. if (AuraApplication* aurApp = itr->second)
  2596. if (Aura* aura = aurApp->GetBase())
  2597. if (!aura->IsPermanent())
  2598. OldSummon->RemoveAura(itr);
  2599. if (petentry == 0 || OldSummon->GetEntry() == petentry)
  2600. {
  2601. // pet in corpse state can't be summoned
  2602. if (OldSummon->isDead())
  2603. return;
  2604. ASSERT(OldSummon->GetMap() == owner->GetMap());
  2605. //OldSummon->GetMap()->Remove(OldSummon->ToCreature(), false);
  2606. float px, py, pz;
  2607. owner->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
  2608. OldSummon->NearTeleportTo(px, py, pz, OldSummon->GetOrientation());
  2609. //OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation());
  2610. //OldSummon->SetMap(owner->GetMap());
  2611. //owner->GetMap()->Add(OldSummon->ToCreature());
  2612. if (owner->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled())
  2613. owner->ToPlayer()->PetSpellInitialize();
  2614. return;
  2615. }
  2616. if (owner->GetTypeId() == TYPEID_PLAYER)
  2617. owner->ToPlayer()->RemovePet(OldSummon, (OldSummon->getPetType() == HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT), false);
  2618. else
  2619. return;
  2620. }
  2621. float x, y, z;
  2622. owner->GetClosePoint(x, y, z, owner->GetObjectSize());
  2623. Pet* pet = owner->SummonPet(petentry, x, y, z, owner->GetOrientation(), SUMMON_PET, 0);
  2624. if (!pet)
  2625. return;
  2626. if (m_caster->GetTypeId() == TYPEID_UNIT)
  2627. {
  2628. if (m_caster->ToCreature()->IsTotem())
  2629. pet->SetReactState(REACT_AGGRESSIVE);
  2630. else
  2631. pet->SetReactState(REACT_DEFENSIVE);
  2632. }
  2633. pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
  2634. // generate new name for summon pet
  2635. std::string new_name=sObjectMgr->GeneratePetName(petentry);
  2636. if (!new_name.empty())
  2637. pet->SetName(new_name);
  2638. ExecuteLogEffectSummonObject(effIndex, pet);
  2639. }
  2640. void Spell::EffectLearnPetSpell(SpellEffIndex effIndex)
  2641. {
  2642. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2643. return;
  2644. if (!unitTarget)
  2645. return;
  2646. if (unitTarget->ToPlayer())
  2647. {
  2648. EffectLearnSpell(effIndex);
  2649. return;
  2650. }
  2651. Pet* pet = unitTarget->ToPet();
  2652. if (!pet)
  2653. return;
  2654. SpellInfo const* learn_spellproto = sSpellMgr->GetSpellInfo(m_spellInfo->Effects[effIndex].TriggerSpell);
  2655. if (!learn_spellproto)
  2656. return;
  2657. pet->learnSpell(learn_spellproto->Id);
  2658. pet->SavePetToDB(PET_SAVE_AS_CURRENT);
  2659. pet->GetOwner()->PetSpellInitialize();
  2660. }
  2661. void Spell::EffectTaunt(SpellEffIndex /*effIndex*/)
  2662. {
  2663. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2664. return;
  2665. if (!unitTarget)
  2666. return;
  2667. // this effect use before aura Taunt apply for prevent taunt already attacking target
  2668. // for spell as marked "non effective at already attacking target"
  2669. if (!unitTarget || !unitTarget->CanHaveThreatList()
  2670. || unitTarget->GetVictim() == m_caster)
  2671. {
  2672. SendCastResult(SPELL_FAILED_DONT_REPORT);
  2673. return;
  2674. }
  2675. if (m_spellInfo->Id == 62124)
  2676. m_caster->CastSpell(unitTarget, 67485, true);
  2677. // Also use this effect to set the taunter's threat to the taunted creature's highest value
  2678. if (unitTarget->getThreatManager().getCurrentVictim())
  2679. {
  2680. float myThreat = unitTarget->getThreatManager().getThreat(m_caster);
  2681. float itsThreat = unitTarget->getThreatManager().getCurrentVictim()->getThreat();
  2682. if (itsThreat > myThreat)
  2683. unitTarget->getThreatManager().addThreat(m_caster, itsThreat - myThreat);
  2684. }
  2685. //Set aggro victim to caster
  2686. if (!unitTarget->getThreatManager().getOnlineContainer().empty())
  2687. if (HostileReference* forcedVictim = unitTarget->getThreatManager().getOnlineContainer().getReferenceByTarget(m_caster))
  2688. unitTarget->getThreatManager().setCurrentVictim(forcedVictim);
  2689. if (unitTarget->ToCreature()->IsAIEnabled && !unitTarget->ToCreature()->HasReactState(REACT_PASSIVE))
  2690. unitTarget->ToCreature()->AI()->AttackStart(m_caster);
  2691. }
  2692. void Spell::EffectWeaponDmg(SpellEffIndex effIndex)
  2693. {
  2694. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  2695. return;
  2696. if (!unitTarget || !unitTarget->IsAlive())
  2697. return;
  2698. // multiple weapon dmg effect workaround
  2699. // execute only the last weapon damage
  2700. // and handle all effects at once
  2701. for (uint32 j = effIndex + 1; j < MAX_SPELL_EFFECTS; ++j)
  2702. {
  2703. switch (m_spellInfo->Effects[j].Effect)
  2704. {
  2705. case SPELL_EFFECT_WEAPON_DAMAGE:
  2706. case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
  2707. case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
  2708. case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
  2709. return; // we must calculate only at last weapon effect
  2710. break;
  2711. }
  2712. }
  2713. // some spell specific modifiers
  2714. float totalDamagePercentMod = 1.0f; // applied to final bonus+weapon damage
  2715. int32 fixed_bonus = 0;
  2716. int32 spell_bonus = 0; // bonus specific for spell
  2717. switch (m_spellInfo->SpellFamilyName)
  2718. {
  2719. case SPELLFAMILY_WARRIOR:
  2720. {
  2721. // Devastate (player ones)
  2722. if (m_spellInfo->SpellFamilyFlags[1] & 0x40)
  2723. {
  2724. // Player can apply only 58567 Sunder Armor effect.
  2725. bool needCast = !unitTarget->HasAura(58567, m_caster->GetGUID());
  2726. if (needCast)
  2727. m_caster->CastSpell(unitTarget, 58567, true);
  2728. if (Aura* aur = unitTarget->GetAura(58567, m_caster->GetGUID()))
  2729. {
  2730. // 58388 - Glyph of Devastate dummy aura.
  2731. if (int32 num = (needCast ? 0 : 1) + (m_caster->HasAura(58388) ? 1 : 0))
  2732. aur->ModStackAmount(num);
  2733. fixed_bonus += (aur->GetStackAmount() - 1) * CalculateDamage(2, unitTarget);
  2734. }
  2735. }
  2736. if (m_spellInfo->SpellFamilyFlags[0] & 0x8000000) // Mocking Blow
  2737. {
  2738. if (unitTarget->IsImmunedToSpellEffect(m_spellInfo, EFFECT_1) || unitTarget->GetTypeId() == TYPEID_PLAYER)
  2739. {
  2740. m_damage = 0;
  2741. return;
  2742. }
  2743. }
  2744. break;
  2745. }
  2746. case SPELLFAMILY_ROGUE:
  2747. {
  2748. // Fan of Knives, Hemorrhage, Ghostly Strike
  2749. if ((m_spellInfo->SpellFamilyFlags[1] & 0x40000)
  2750. || (m_spellInfo->SpellFamilyFlags[0] & 0x6000000))
  2751. {
  2752. // Hemorrhage
  2753. if (m_spellInfo->SpellFamilyFlags[0] & 0x2000000)
  2754. {
  2755. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  2756. m_caster->ToPlayer()->AddComboPoints(unitTarget, 1, this);
  2757. }
  2758. // 50% more damage with daggers
  2759. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  2760. if (Item* item = m_caster->ToPlayer()->GetWeaponForAttack(m_attackType, true))
  2761. if (item->GetTemplate()->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)
  2762. totalDamagePercentMod *= 1.5f;
  2763. }
  2764. // Mutilate (for each hand)
  2765. else if (m_spellInfo->SpellFamilyFlags[1] & 0x6)
  2766. {
  2767. bool found = false;
  2768. // fast check
  2769. if (unitTarget->HasAuraState(AURA_STATE_DEADLY_POISON, m_spellInfo, m_caster))
  2770. found = true;
  2771. // full aura scan
  2772. else
  2773. {
  2774. Unit::AuraApplicationMap const& auras = unitTarget->GetAppliedAuras();
  2775. for (Unit::AuraApplicationMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
  2776. {
  2777. if (itr->second->GetBase()->GetSpellInfo()->Dispel == DISPEL_POISON)
  2778. {
  2779. found = true;
  2780. break;
  2781. }
  2782. }
  2783. }
  2784. if (found)
  2785. totalDamagePercentMod *= 1.2f; // 120% if poisoned
  2786. }
  2787. break;
  2788. }
  2789. case SPELLFAMILY_PALADIN:
  2790. {
  2791. // Seal of Command Unleashed
  2792. if (m_spellInfo->Id == 20467)
  2793. {
  2794. spell_bonus += int32(0.08f * m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
  2795. spell_bonus += int32(0.13f * m_caster->SpellBaseDamageBonusDone(m_spellInfo->GetSchoolMask()));
  2796. }
  2797. break;
  2798. }
  2799. case SPELLFAMILY_SHAMAN:
  2800. {
  2801. // Skyshatter Harness item set bonus
  2802. // Stormstrike
  2803. if (AuraEffect* aurEff = m_caster->IsScriptOverriden(m_spellInfo, 5634))
  2804. m_caster->CastSpell(m_caster, 38430, true, NULL, aurEff);
  2805. break;
  2806. }
  2807. case SPELLFAMILY_DRUID:
  2808. {
  2809. // Mangle (Cat): CP
  2810. if (m_spellInfo->SpellFamilyFlags[1] & 0x400)
  2811. {
  2812. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  2813. m_caster->ToPlayer()->AddComboPoints(unitTarget, 1, this);
  2814. }
  2815. // Shred, Maul - Rend and Tear
  2816. else if (m_spellInfo->SpellFamilyFlags[0] & 0x00008800 && unitTarget->HasAuraState(AURA_STATE_BLEEDING))
  2817. {
  2818. if (AuraEffect const* rendAndTear = m_caster->GetDummyAuraEffect(SPELLFAMILY_DRUID, 2859, 0))
  2819. AddPct(totalDamagePercentMod, rendAndTear->GetAmount());
  2820. }
  2821. break;
  2822. }
  2823. case SPELLFAMILY_HUNTER:
  2824. {
  2825. // Kill Shot - bonus damage from Ranged Attack Power
  2826. if (m_spellInfo->SpellFamilyFlags[1] & 0x800000)
  2827. spell_bonus += int32(0.4f * m_caster->GetTotalAttackPowerValue(RANGED_ATTACK));
  2828. break;
  2829. }
  2830. case SPELLFAMILY_DEATHKNIGHT:
  2831. {
  2832. // Plague Strike
  2833. if (m_spellInfo->SpellFamilyFlags[0] & 0x1)
  2834. {
  2835. // Glyph of Plague Strike
  2836. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(58657, EFFECT_0))
  2837. AddPct(totalDamagePercentMod, aurEff->GetAmount());
  2838. break;
  2839. }
  2840. // Blood Strike
  2841. if (m_spellInfo->SpellFamilyFlags[0] & 0x400000)
  2842. {
  2843. float bonusPct = m_spellInfo->Effects[EFFECT_2].CalcValue() * unitTarget->GetDiseasesByCaster(m_caster->GetGUID()) / 2.0f;
  2844. // Death Knight T8 Melee 4P Bonus
  2845. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(64736, EFFECT_0))
  2846. AddPct(bonusPct, aurEff->GetAmount());
  2847. AddPct(totalDamagePercentMod, bonusPct);
  2848. // Glyph of Blood Strike
  2849. if (m_caster->GetAuraEffect(59332, EFFECT_0))
  2850. if (unitTarget->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED))
  2851. AddPct(totalDamagePercentMod, 20);
  2852. break;
  2853. }
  2854. // Death Strike
  2855. if (m_spellInfo->SpellFamilyFlags[0] & 0x10)
  2856. {
  2857. // Glyph of Death Strike
  2858. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(59336, EFFECT_0))
  2859. if (uint32 runic = std::min<uint32>(m_caster->GetPower(POWER_RUNIC_POWER), aurEff->GetSpellInfo()->Effects[EFFECT_1].CalcValue()))
  2860. AddPct(totalDamagePercentMod, runic);
  2861. break;
  2862. }
  2863. // Obliterate (12.5% more damage per disease)
  2864. if (m_spellInfo->SpellFamilyFlags[1] & 0x20000)
  2865. {
  2866. bool consumeDiseases = true;
  2867. // Annihilation
  2868. if (AuraEffect const* aurEff = m_caster->GetDummyAuraEffect(SPELLFAMILY_DEATHKNIGHT, 2710, EFFECT_0))
  2869. // Do not consume diseases if roll sucesses
  2870. if (roll_chance_i(aurEff->GetAmount()))
  2871. consumeDiseases = false;
  2872. float bonusPct = m_spellInfo->Effects[EFFECT_2].CalcValue() * unitTarget->GetDiseasesByCaster(m_caster->GetGUID(), consumeDiseases) / 2.0f;
  2873. // Death Knight T8 Melee 4P Bonus
  2874. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(64736, EFFECT_0))
  2875. AddPct(bonusPct, aurEff->GetAmount());
  2876. AddPct(totalDamagePercentMod, bonusPct);
  2877. break;
  2878. }
  2879. // Blood-Caked Strike - Blood-Caked Blade
  2880. if (m_spellInfo->SpellIconID == 1736)
  2881. {
  2882. AddPct(totalDamagePercentMod, unitTarget->GetDiseasesByCaster(m_caster->GetGUID()) * 50.0f);
  2883. break;
  2884. }
  2885. // Heart Strike
  2886. if (m_spellInfo->SpellFamilyFlags[0] & 0x1000000)
  2887. {
  2888. float bonusPct = m_spellInfo->Effects[EFFECT_2].CalcValue() * unitTarget->GetDiseasesByCaster(m_caster->GetGUID());
  2889. // Death Knight T8 Melee 4P Bonus
  2890. if (AuraEffect const* aurEff = m_caster->GetAuraEffect(64736, EFFECT_0))
  2891. AddPct(bonusPct, aurEff->GetAmount());
  2892. AddPct(totalDamagePercentMod, bonusPct);
  2893. break;
  2894. }
  2895. break;
  2896. }
  2897. }
  2898. bool normalized = false;
  2899. float weaponDamagePercentMod = 1.0f;
  2900. for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
  2901. {
  2902. switch (m_spellInfo->Effects[j].Effect)
  2903. {
  2904. case SPELL_EFFECT_WEAPON_DAMAGE:
  2905. case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
  2906. fixed_bonus += CalculateDamage(j, unitTarget);
  2907. break;
  2908. case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
  2909. fixed_bonus += CalculateDamage(j, unitTarget);
  2910. normalized = true;
  2911. break;
  2912. case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
  2913. ApplyPct(weaponDamagePercentMod, CalculateDamage(j, unitTarget));
  2914. break;
  2915. default:
  2916. break; // not weapon damage effect, just skip
  2917. }
  2918. }
  2919. // apply to non-weapon bonus weapon total pct effect, weapon total flat effect included in weapon damage
  2920. if (fixed_bonus || spell_bonus)
  2921. {
  2922. UnitMods unitMod;
  2923. switch (m_attackType)
  2924. {
  2925. default:
  2926. case BASE_ATTACK: unitMod = UNIT_MOD_DAMAGE_MAINHAND; break;
  2927. case OFF_ATTACK: unitMod = UNIT_MOD_DAMAGE_OFFHAND; break;
  2928. case RANGED_ATTACK: unitMod = UNIT_MOD_DAMAGE_RANGED; break;
  2929. }
  2930. float weapon_total_pct = 1.0f;
  2931. if (m_spellInfo->SchoolMask & SPELL_SCHOOL_MASK_NORMAL)
  2932. weapon_total_pct = m_caster->GetModifierValue(unitMod, TOTAL_PCT);
  2933. if (fixed_bonus)
  2934. fixed_bonus = int32(fixed_bonus * weapon_total_pct);
  2935. if (spell_bonus)
  2936. spell_bonus = int32(spell_bonus * weapon_total_pct);
  2937. }
  2938. int32 weaponDamage = m_caster->CalculateDamage(m_attackType, normalized, true);
  2939. // Sequence is important
  2940. for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
  2941. {
  2942. // We assume that a spell have at most one fixed_bonus
  2943. // and at most one weaponDamagePercentMod
  2944. switch (m_spellInfo->Effects[j].Effect)
  2945. {
  2946. case SPELL_EFFECT_WEAPON_DAMAGE:
  2947. case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
  2948. case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
  2949. weaponDamage += fixed_bonus;
  2950. break;
  2951. case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
  2952. weaponDamage = int32(weaponDamage* weaponDamagePercentMod);
  2953. default:
  2954. break; // not weapon damage effect, just skip
  2955. }
  2956. }
  2957. if (spell_bonus)
  2958. weaponDamage += spell_bonus;
  2959. if (totalDamagePercentMod != 1.0f)
  2960. weaponDamage = int32(weaponDamage* totalDamagePercentMod);
  2961. // prevent negative damage
  2962. uint32 eff_damage(std::max(weaponDamage, 0));
  2963. // Add melee damage bonuses (also check for negative)
  2964. uint32 damage = m_caster->MeleeDamageBonusDone(unitTarget, eff_damage, m_attackType, m_spellInfo);
  2965. m_damage += unitTarget->MeleeDamageBonusTaken(m_caster, damage, m_attackType, m_spellInfo);
  2966. }
  2967. void Spell::EffectThreat(SpellEffIndex /*effIndex*/)
  2968. {
  2969. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2970. return;
  2971. if (!unitTarget || !unitTarget->IsAlive() || !m_caster->IsAlive())
  2972. return;
  2973. if (!unitTarget->CanHaveThreatList())
  2974. return;
  2975. unitTarget->AddThreat(m_caster, float(damage));
  2976. }
  2977. void Spell::EffectHealMaxHealth(SpellEffIndex /*effIndex*/)
  2978. {
  2979. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2980. return;
  2981. if (!unitTarget || !unitTarget->IsAlive())
  2982. return;
  2983. int32 addhealth = 0;
  2984. // damage == 0 - heal for caster max health
  2985. if (damage == 0)
  2986. addhealth = m_caster->GetMaxHealth();
  2987. else
  2988. addhealth = unitTarget->GetMaxHealth() - unitTarget->GetHealth();
  2989. m_healing += addhealth;
  2990. }
  2991. void Spell::EffectInterruptCast(SpellEffIndex effIndex)
  2992. {
  2993. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  2994. return;
  2995. if (!unitTarget || !unitTarget->IsAlive())
  2996. return;
  2997. /// @todo not all spells that used this effect apply cooldown at school spells
  2998. // also exist case: apply cooldown to interrupted cast only and to all spells
  2999. // there is no CURRENT_AUTOREPEAT_SPELL spells that can be interrupted
  3000. for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_AUTOREPEAT_SPELL; ++i)
  3001. {
  3002. if (Spell* spell = unitTarget->GetCurrentSpell(CurrentSpellTypes(i)))
  3003. {
  3004. SpellInfo const* curSpellInfo = spell->m_spellInfo;
  3005. // check if we can interrupt spell
  3006. if ((spell->getState() == SPELL_STATE_CASTING
  3007. || (spell->getState() == SPELL_STATE_PREPARING && spell->GetCastTime() > 0.0f))
  3008. && curSpellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE
  3009. && ((i == CURRENT_GENERIC_SPELL && curSpellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT)
  3010. || (i == CURRENT_CHANNELED_SPELL && curSpellInfo->ChannelInterruptFlags & CHANNEL_INTERRUPT_FLAG_INTERRUPT)))
  3011. {
  3012. if (m_originalCaster)
  3013. {
  3014. int32 duration = m_spellInfo->GetDuration();
  3015. unitTarget->ProhibitSpellSchool(curSpellInfo->GetSchoolMask(), unitTarget->ModSpellDuration(m_spellInfo, unitTarget, duration, false, 1 << effIndex));
  3016. }
  3017. ExecuteLogEffectInterruptCast(effIndex, unitTarget, curSpellInfo->Id);
  3018. unitTarget->InterruptSpell(CurrentSpellTypes(i), false);
  3019. }
  3020. }
  3021. }
  3022. }
  3023. void Spell::EffectSummonObjectWild(SpellEffIndex effIndex)
  3024. {
  3025. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  3026. return;
  3027. uint32 gameobject_id = m_spellInfo->Effects[effIndex].MiscValue;
  3028. GameObject* pGameObj = new GameObject;
  3029. WorldObject* target = focusObject;
  3030. if (!target)
  3031. target = m_caster;
  3032. float x, y, z;
  3033. if (m_targets.HasDst())
  3034. destTarget->GetPosition(x, y, z);
  3035. else
  3036. m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
  3037. Map* map = target->GetMap();
  3038. if (!pGameObj->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map,
  3039. m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
  3040. {
  3041. delete pGameObj;
  3042. return;
  3043. }
  3044. int32 duration = m_spellInfo->GetDuration();
  3045. pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0);
  3046. pGameObj->SetSpellId(m_spellInfo->Id);
  3047. ExecuteLogEffectSummonObject(effIndex, pGameObj);
  3048. // Wild object not have owner and check clickable by players
  3049. map->AddToMap(pGameObj);
  3050. if (pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP)
  3051. if (Player* player = m_caster->ToPlayer())
  3052. if (Battleground* bg = player->GetBattleground())
  3053. bg->SetDroppedFlagGUID(pGameObj->GetGUID(), player->GetTeam() == ALLIANCE ? TEAM_HORDE: TEAM_ALLIANCE);
  3054. if (uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
  3055. {
  3056. GameObject* linkedGO = new GameObject;
  3057. if (linkedGO->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, map,
  3058. m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
  3059. {
  3060. linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0);
  3061. linkedGO->SetSpellId(m_spellInfo->Id);
  3062. ExecuteLogEffectSummonObject(effIndex, linkedGO);
  3063. // Wild object not have owner and check clickable by players
  3064. map->AddToMap(linkedGO);
  3065. }
  3066. else
  3067. {
  3068. delete linkedGO;
  3069. linkedGO = NULL;
  3070. return;
  3071. }
  3072. }
  3073. }
  3074. void Spell::EffectScriptEffect(SpellEffIndex effIndex)
  3075. {
  3076. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3077. return;
  3078. /// @todo we must implement hunter pet summon at login there (spell 6962)
  3079. switch (m_spellInfo->SpellFamilyName)
  3080. {
  3081. case SPELLFAMILY_GENERIC:
  3082. {
  3083. switch (m_spellInfo->Id)
  3084. {
  3085. // Glyph of Backstab
  3086. case 63975:
  3087. {
  3088. // search our Rupture aura on target
  3089. if (AuraEffect const* aurEff = unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_ROGUE, 0x00100000, 0, 0, m_caster->GetGUID()))
  3090. {
  3091. uint32 countMin = aurEff->GetBase()->GetMaxDuration();
  3092. uint32 countMax = 12000; // this can be wrong, duration should be based on combo-points
  3093. countMax += m_caster->HasAura(56801) ? 4000 : 0;
  3094. if (countMin < countMax)
  3095. {
  3096. aurEff->GetBase()->SetDuration(uint32(aurEff->GetBase()->GetDuration() + 3000));
  3097. aurEff->GetBase()->SetMaxDuration(countMin + 2000);
  3098. }
  3099. }
  3100. return;
  3101. }
  3102. // Glyph of Scourge Strike
  3103. case 69961:
  3104. {
  3105. Unit::AuraEffectList const &mPeriodic = unitTarget->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE);
  3106. for (Unit::AuraEffectList::const_iterator i = mPeriodic.begin(); i != mPeriodic.end(); ++i)
  3107. {
  3108. AuraEffect const* aurEff = *i;
  3109. SpellInfo const* spellInfo = aurEff->GetSpellInfo();
  3110. // search our Blood Plague and Frost Fever on target
  3111. if (spellInfo->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT && spellInfo->SpellFamilyFlags[2] & 0x2 &&
  3112. aurEff->GetCasterGUID() == m_caster->GetGUID())
  3113. {
  3114. uint32 countMin = aurEff->GetBase()->GetMaxDuration();
  3115. uint32 countMax = spellInfo->GetMaxDuration();
  3116. // this Glyph
  3117. countMax += 9000;
  3118. // talent Epidemic
  3119. if (AuraEffect const* epidemic = m_caster->GetAuraEffect(SPELL_AURA_ADD_FLAT_MODIFIER, SPELLFAMILY_DEATHKNIGHT, 234, EFFECT_0))
  3120. countMax += epidemic->GetAmount();
  3121. if (countMin < countMax)
  3122. {
  3123. aurEff->GetBase()->SetDuration(aurEff->GetBase()->GetDuration() + 3000);
  3124. aurEff->GetBase()->SetMaxDuration(countMin + 3000);
  3125. }
  3126. }
  3127. }
  3128. return;
  3129. }
  3130. case 55693: // Remove Collapsing Cave Aura
  3131. if (!unitTarget)
  3132. return;
  3133. unitTarget->RemoveAurasDueToSpell(m_spellInfo->Effects[effIndex].CalcValue());
  3134. break;
  3135. // Bending Shinbone
  3136. case 8856:
  3137. {
  3138. if (!itemTarget && m_caster->GetTypeId() != TYPEID_PLAYER)
  3139. return;
  3140. uint32 spell_id = roll_chance_i(20) ? 8854 : 8855;
  3141. m_caster->CastSpell(m_caster, spell_id, true, NULL);
  3142. return;
  3143. }
  3144. // Brittle Armor - need remove one 24575 Brittle Armor aura
  3145. case 24590:
  3146. unitTarget->RemoveAuraFromStack(24575);
  3147. return;
  3148. // Mercurial Shield - need remove one 26464 Mercurial Shield aura
  3149. case 26465:
  3150. unitTarget->RemoveAuraFromStack(26464);
  3151. return;
  3152. // Shadow Flame (All script effects, not just end ones to prevent player from dodging the last triggered spell)
  3153. case 22539:
  3154. case 22972:
  3155. case 22975:
  3156. case 22976:
  3157. case 22977:
  3158. case 22978:
  3159. case 22979:
  3160. case 22980:
  3161. case 22981:
  3162. case 22982:
  3163. case 22983:
  3164. case 22984:
  3165. case 22985:
  3166. {
  3167. if (!unitTarget || !unitTarget->IsAlive())
  3168. return;
  3169. // Onyxia Scale Cloak
  3170. if (unitTarget->HasAura(22683))
  3171. return;
  3172. // Shadow Flame
  3173. m_caster->CastSpell(unitTarget, 22682, true);
  3174. return;
  3175. }
  3176. // Decimate
  3177. case 28374:
  3178. case 54426:
  3179. if (unitTarget)
  3180. {
  3181. int32 damage = int32(unitTarget->GetHealth()) - int32(unitTarget->CountPctFromMaxHealth(5));
  3182. if (damage > 0)
  3183. m_caster->CastCustomSpell(28375, SPELLVALUE_BASE_POINT0, damage, unitTarget);
  3184. }
  3185. return;
  3186. // Mirren's Drinking Hat
  3187. case 29830:
  3188. {
  3189. uint32 item = 0;
  3190. switch (urand(1, 6))
  3191. {
  3192. case 1:
  3193. case 2:
  3194. case 3:
  3195. item = 23584; break; // Loch Modan Lager
  3196. case 4:
  3197. case 5:
  3198. item = 23585; break; // Stouthammer Lite
  3199. case 6:
  3200. item = 23586; break; // Aerie Peak Pale Ale
  3201. }
  3202. if (item)
  3203. DoCreateItem(effIndex, item);
  3204. break;
  3205. }
  3206. case 20589: // Escape artist
  3207. case 30918: // Improved Sprint
  3208. {
  3209. // Removes snares and roots.
  3210. unitTarget->RemoveMovementImpairingAuras();
  3211. break;
  3212. }
  3213. // Plant Warmaul Ogre Banner
  3214. case 32307:
  3215. if (Player* caster = m_caster->ToPlayer())
  3216. {
  3217. caster->RewardPlayerAndGroupAtEvent(18388, unitTarget);
  3218. if (Creature* target = unitTarget->ToCreature())
  3219. {
  3220. target->setDeathState(CORPSE);
  3221. target->RemoveCorpse();
  3222. }
  3223. }
  3224. break;
  3225. // Mug Transformation
  3226. case 41931:
  3227. {
  3228. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  3229. return;
  3230. uint8 bag = 19;
  3231. uint8 slot = 0;
  3232. Item* item = NULL;
  3233. while (bag) // 256 = 0 due to var type
  3234. {
  3235. item = m_caster->ToPlayer()->GetItemByPos(bag, slot);
  3236. if (item && item->GetEntry() == 38587)
  3237. break;
  3238. ++slot;
  3239. if (slot == 39)
  3240. {
  3241. slot = 0;
  3242. ++bag;
  3243. }
  3244. }
  3245. if (bag)
  3246. {
  3247. if (m_caster->ToPlayer()->GetItemByPos(bag, slot)->GetCount() == 1) m_caster->ToPlayer()->RemoveItem(bag, slot, true);
  3248. else m_caster->ToPlayer()->GetItemByPos(bag, slot)->SetCount(m_caster->ToPlayer()->GetItemByPos(bag, slot)->GetCount()-1);
  3249. // Spell 42518 (Braufest - Gratisprobe des Braufest herstellen)
  3250. m_caster->CastSpell(m_caster, 42518, true);
  3251. return;
  3252. }
  3253. break;
  3254. }
  3255. // Brutallus - Burn
  3256. case 45141:
  3257. case 45151:
  3258. {
  3259. //Workaround for Range ... should be global for every ScriptEffect
  3260. float radius = m_spellInfo->Effects[effIndex].CalcRadius();
  3261. if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER && unitTarget->GetDistance(m_caster) >= radius && !unitTarget->HasAura(46394) && unitTarget != m_caster)
  3262. unitTarget->CastSpell(unitTarget, 46394, true);
  3263. break;
  3264. }
  3265. // Goblin Weather Machine
  3266. case 46203:
  3267. {
  3268. if (!unitTarget)
  3269. return;
  3270. uint32 spellId = 0;
  3271. switch (rand() % 4)
  3272. {
  3273. case 0: spellId = 46740; break;
  3274. case 1: spellId = 46739; break;
  3275. case 2: spellId = 46738; break;
  3276. case 3: spellId = 46736; break;
  3277. }
  3278. unitTarget->CastSpell(unitTarget, spellId, true);
  3279. break;
  3280. }
  3281. // 5, 000 Gold
  3282. case 46642:
  3283. {
  3284. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3285. return;
  3286. unitTarget->ToPlayer()->ModifyMoney(5000 * GOLD);
  3287. break;
  3288. }
  3289. // Roll Dice - Decahedral Dwarven Dice
  3290. case 47770:
  3291. {
  3292. char buf[128];
  3293. const char *gender = "his";
  3294. if (m_caster->getGender() > 0)
  3295. gender = "her";
  3296. sprintf(buf, "%s rubs %s [Decahedral Dwarven Dice] between %s hands and rolls. One %u and one %u.", m_caster->GetName().c_str(), gender, gender, urand(1, 10), urand(1, 10));
  3297. m_caster->MonsterTextEmote(buf, NULL);
  3298. break;
  3299. }
  3300. // Roll 'dem Bones - Worn Troll Dice
  3301. case 47776:
  3302. {
  3303. char buf[128];
  3304. const char *gender = "his";
  3305. if (m_caster->getGender() > 0)
  3306. gender = "her";
  3307. sprintf(buf, "%s causually tosses %s [Worn Troll Dice]. One %u and one %u.", m_caster->GetName().c_str(), gender, urand(1, 6), urand(1, 6));
  3308. m_caster->MonsterTextEmote(buf, NULL);
  3309. break;
  3310. }
  3311. // Death Knight Initiate Visual
  3312. case 51519:
  3313. {
  3314. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
  3315. return;
  3316. uint32 iTmpSpellId = 0;
  3317. switch (unitTarget->GetDisplayId())
  3318. {
  3319. case 25369: iTmpSpellId = 51552; break; // bloodelf female
  3320. case 25373: iTmpSpellId = 51551; break; // bloodelf male
  3321. case 25363: iTmpSpellId = 51542; break; // draenei female
  3322. case 25357: iTmpSpellId = 51541; break; // draenei male
  3323. case 25361: iTmpSpellId = 51537; break; // dwarf female
  3324. case 25356: iTmpSpellId = 51538; break; // dwarf male
  3325. case 25372: iTmpSpellId = 51550; break; // forsaken female
  3326. case 25367: iTmpSpellId = 51549; break; // forsaken male
  3327. case 25362: iTmpSpellId = 51540; break; // gnome female
  3328. case 25359: iTmpSpellId = 51539; break; // gnome male
  3329. case 25355: iTmpSpellId = 51534; break; // human female
  3330. case 25354: iTmpSpellId = 51520; break; // human male
  3331. case 25360: iTmpSpellId = 51536; break; // nightelf female
  3332. case 25358: iTmpSpellId = 51535; break; // nightelf male
  3333. case 25368: iTmpSpellId = 51544; break; // orc female
  3334. case 25364: iTmpSpellId = 51543; break; // orc male
  3335. case 25371: iTmpSpellId = 51548; break; // tauren female
  3336. case 25366: iTmpSpellId = 51547; break; // tauren male
  3337. case 25370: iTmpSpellId = 51545; break; // troll female
  3338. case 25365: iTmpSpellId = 51546; break; // troll male
  3339. default: return;
  3340. }
  3341. unitTarget->CastSpell(unitTarget, iTmpSpellId, true);
  3342. Creature* npc = unitTarget->ToCreature();
  3343. npc->LoadEquipment();
  3344. return;
  3345. }
  3346. // Deathbolt from Thalgran Blightbringer
  3347. // reflected by Freya's Ward
  3348. // Retribution by Sevenfold Retribution
  3349. case 51854:
  3350. {
  3351. if (!unitTarget)
  3352. return;
  3353. if (unitTarget->HasAura(51845))
  3354. unitTarget->CastSpell(m_caster, 51856, true);
  3355. else
  3356. m_caster->CastSpell(unitTarget, 51855, true);
  3357. break;
  3358. }
  3359. // Summon Ghouls On Scarlet Crusade
  3360. case 51904:
  3361. {
  3362. if (!m_targets.HasDst())
  3363. return;
  3364. float x, y, z;
  3365. float radius = m_spellInfo->Effects[effIndex].CalcRadius();
  3366. for (uint8 i = 0; i < 15; ++i)
  3367. {
  3368. m_caster->GetRandomPoint(*destTarget, radius, x, y, z);
  3369. m_caster->CastSpell(x, y, z, 54522, true);
  3370. }
  3371. break;
  3372. }
  3373. case 52173: // Coyote Spirit Despawn
  3374. case 60243: // Blood Parrot Despawn
  3375. if (unitTarget->GetTypeId() == TYPEID_UNIT && unitTarget->ToCreature()->IsSummon())
  3376. unitTarget->ToTempSummon()->UnSummon();
  3377. return;
  3378. case 52479: // Gift of the Harvester
  3379. if (unitTarget && m_originalCaster)
  3380. m_originalCaster->CastSpell(unitTarget, urand(0, 1) ? damage : 52505, true);
  3381. return;
  3382. case 53110: // Devour Humanoid
  3383. if (unitTarget)
  3384. unitTarget->CastSpell(m_caster, damage, true);
  3385. return;
  3386. case 57347: // Retrieving (Wintergrasp RP-GG pickup spell)
  3387. {
  3388. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->GetTypeId() != TYPEID_PLAYER)
  3389. return;
  3390. unitTarget->ToCreature()->DespawnOrUnsummon();
  3391. return;
  3392. }
  3393. case 57349: // Drop RP-GG (Wintergrasp RP-GG at death drop spell)
  3394. {
  3395. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  3396. return;
  3397. // Delete item from inventory at death
  3398. m_caster->ToPlayer()->DestroyItemCount(damage, 5, true);
  3399. return;
  3400. }
  3401. case 58418: // Portal to Orgrimmar
  3402. case 58420: // Portal to Stormwind
  3403. {
  3404. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || effIndex != 0)
  3405. return;
  3406. uint32 spellID = m_spellInfo->Effects[EFFECT_0].CalcValue();
  3407. uint32 questID = m_spellInfo->Effects[EFFECT_1].CalcValue();
  3408. if (unitTarget->ToPlayer()->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE)
  3409. unitTarget->CastSpell(unitTarget, spellID, true);
  3410. return;
  3411. }
  3412. case 58983: // Big Blizzard Bear
  3413. {
  3414. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3415. return;
  3416. // Prevent stacking of mounts and client crashes upon dismounting
  3417. unitTarget->RemoveAurasByType(SPELL_AURA_MOUNTED);
  3418. // Triggered spell id dependent on riding skill
  3419. if (uint16 skillval = unitTarget->ToPlayer()->GetSkillValue(SKILL_RIDING))
  3420. {
  3421. if (skillval >= 150)
  3422. unitTarget->CastSpell(unitTarget, 58999, true);
  3423. else
  3424. unitTarget->CastSpell(unitTarget, 58997, true);
  3425. }
  3426. return;
  3427. }
  3428. case 59317: // Teleporting
  3429. {
  3430. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3431. return;
  3432. // return from top
  3433. if (unitTarget->ToPlayer()->GetAreaId() == 4637)
  3434. unitTarget->CastSpell(unitTarget, 59316, true);
  3435. // teleport atop
  3436. else
  3437. unitTarget->CastSpell(unitTarget, 59314, true);
  3438. return;
  3439. }
  3440. case 62482: // Grab Crate
  3441. {
  3442. if (unitTarget)
  3443. {
  3444. if (Unit* seat = m_caster->GetVehicleBase())
  3445. {
  3446. if (Unit* parent = seat->GetVehicleBase())
  3447. {
  3448. /// @todo a hack, range = 11, should after some time cast, otherwise too far
  3449. m_caster->CastSpell(parent, 62496, true);
  3450. unitTarget->CastSpell(parent, m_spellInfo->Effects[EFFECT_0].CalcValue());
  3451. }
  3452. }
  3453. }
  3454. return;
  3455. }
  3456. case 60123: // Lightwell
  3457. {
  3458. if (m_caster->GetTypeId() != TYPEID_UNIT || !m_caster->ToCreature()->IsSummon())
  3459. return;
  3460. uint32 spell_heal;
  3461. switch (m_caster->GetEntry())
  3462. {
  3463. case 31897: spell_heal = 7001; break;
  3464. case 31896: spell_heal = 27873; break;
  3465. case 31895: spell_heal = 27874; break;
  3466. case 31894: spell_heal = 28276; break;
  3467. case 31893: spell_heal = 48084; break;
  3468. case 31883: spell_heal = 48085; break;
  3469. default:
  3470. TC_LOG_ERROR("spells", "Unknown Lightwell spell caster %u", m_caster->GetEntry());
  3471. return;
  3472. }
  3473. // proc a spellcast
  3474. if (Aura* chargesAura = m_caster->GetAura(59907))
  3475. {
  3476. m_caster->CastSpell(unitTarget, spell_heal, true, NULL, NULL, m_caster->ToTempSummon()->GetSummonerGUID());
  3477. if (chargesAura->ModCharges(-1))
  3478. m_caster->ToTempSummon()->UnSummon();
  3479. }
  3480. return;
  3481. }
  3482. // Stoneclaw Totem
  3483. case 55328: // Rank 1
  3484. case 55329: // Rank 2
  3485. case 55330: // Rank 3
  3486. case 55332: // Rank 4
  3487. case 55333: // Rank 5
  3488. case 55335: // Rank 6
  3489. case 55278: // Rank 7
  3490. case 58589: // Rank 8
  3491. case 58590: // Rank 9
  3492. case 58591: // Rank 10
  3493. {
  3494. int32 basepoints0 = damage;
  3495. // Cast Absorb on totems
  3496. for (uint8 slot = SUMMON_SLOT_TOTEM; slot < MAX_TOTEM_SLOT; ++slot)
  3497. {
  3498. if (!unitTarget->m_SummonSlot[slot])
  3499. continue;
  3500. Creature* totem = unitTarget->GetMap()->GetCreature(unitTarget->m_SummonSlot[slot]);
  3501. if (totem && totem->IsTotem())
  3502. {
  3503. m_caster->CastCustomSpell(totem, 55277, &basepoints0, NULL, NULL, true);
  3504. }
  3505. }
  3506. // Glyph of Stoneclaw Totem
  3507. if (AuraEffect* aur=unitTarget->GetAuraEffect(63298, 0))
  3508. {
  3509. basepoints0 *= aur->GetAmount();
  3510. m_caster->CastCustomSpell(unitTarget, 55277, &basepoints0, NULL, NULL, true);
  3511. }
  3512. break;
  3513. }
  3514. case 45668: // Ultra-Advanced Proto-Typical Shortening Blaster
  3515. {
  3516. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
  3517. return;
  3518. if (roll_chance_i(50)) // chance unknown, using 50
  3519. return;
  3520. static uint32 const spellPlayer[5] =
  3521. {
  3522. 45674, // Bigger!
  3523. 45675, // Shrunk
  3524. 45678, // Yellow
  3525. 45682, // Ghost
  3526. 45684 // Polymorph
  3527. };
  3528. static uint32 const spellTarget[5] =
  3529. {
  3530. 45673, // Bigger!
  3531. 45672, // Shrunk
  3532. 45677, // Yellow
  3533. 45681, // Ghost
  3534. 45683 // Polymorph
  3535. };
  3536. m_caster->CastSpell(m_caster, spellPlayer[urand(0, 4)], true);
  3537. unitTarget->CastSpell(unitTarget, spellTarget[urand(0, 4)], true);
  3538. break;
  3539. }
  3540. }
  3541. break;
  3542. }
  3543. case SPELLFAMILY_DEATHKNIGHT:
  3544. {
  3545. // Pestilence
  3546. if (m_spellInfo->SpellFamilyFlags[1]&0x10000)
  3547. {
  3548. // Get diseases on target of spell
  3549. if (m_targets.GetUnitTarget() && // Glyph of Disease - cast on unit target too to refresh aura
  3550. (m_targets.GetUnitTarget() != unitTarget || m_caster->GetAura(63334)))
  3551. {
  3552. // And spread them on target
  3553. // Blood Plague
  3554. if (m_targets.GetUnitTarget()->GetAura(55078))
  3555. m_caster->CastSpell(unitTarget, 55078, true);
  3556. // Frost Fever
  3557. if (m_targets.GetUnitTarget()->GetAura(55095))
  3558. m_caster->CastSpell(unitTarget, 55095, true);
  3559. }
  3560. }
  3561. break;
  3562. }
  3563. }
  3564. // normal DB scripted effect
  3565. TC_LOG_DEBUG("spells", "Spell ScriptStart spellid %u in EffectScriptEffect(%u)", m_spellInfo->Id, effIndex);
  3566. m_caster->GetMap()->ScriptsStart(sSpellScripts, uint32(m_spellInfo->Id | (effIndex << 24)), m_caster, unitTarget);
  3567. }
  3568. void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/)
  3569. {
  3570. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3571. return;
  3572. if (!unitTarget)
  3573. return;
  3574. unitTarget->getHostileRefManager().UpdateVisibility();
  3575. Unit::AttackerSet const& attackers = unitTarget->getAttackers();
  3576. for (Unit::AttackerSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
  3577. {
  3578. if (!(*itr)->CanSeeOrDetect(unitTarget))
  3579. (*(itr++))->AttackStop();
  3580. else
  3581. ++itr;
  3582. }
  3583. unitTarget->m_lastSanctuaryTime = getMSTime();
  3584. // Vanish allows to remove all threat and cast regular stealth so other spells can be used
  3585. if (m_caster->GetTypeId() == TYPEID_PLAYER
  3586. && m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE
  3587. && (m_spellInfo->SpellFamilyFlags[0] & SPELLFAMILYFLAG_ROGUE_VANISH))
  3588. {
  3589. m_caster->ToPlayer()->RemoveAurasByType(SPELL_AURA_MOD_ROOT);
  3590. // Overkill
  3591. if (m_caster->ToPlayer()->HasSpell(58426))
  3592. m_caster->CastSpell(m_caster, 58427, true);
  3593. }
  3594. }
  3595. void Spell::EffectAddComboPoints(SpellEffIndex /*effIndex*/)
  3596. {
  3597. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3598. return;
  3599. if (!unitTarget)
  3600. return;
  3601. if (!m_caster->m_movedPlayer)
  3602. return;
  3603. if (damage <= 0)
  3604. return;
  3605. m_caster->m_movedPlayer->AddComboPoints(unitTarget, damage, this);
  3606. }
  3607. void Spell::EffectDuel(SpellEffIndex effIndex)
  3608. {
  3609. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3610. return;
  3611. if (!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3612. return;
  3613. Player* caster = m_caster->ToPlayer();
  3614. Player* target = unitTarget->ToPlayer();
  3615. // caster or target already have requested duel
  3616. if (caster->duel || target->duel || !target->GetSocial() || target->GetSocial()->HasIgnore(caster->GetGUIDLow()))
  3617. return;
  3618. // Players can only fight a duel in zones with this flag
  3619. AreaTableEntry const* casterAreaEntry = GetAreaEntryByAreaID(caster->GetAreaId());
  3620. if (casterAreaEntry && !(casterAreaEntry->flags & AREA_FLAG_ALLOW_DUELS))
  3621. {
  3622. SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
  3623. return;
  3624. }
  3625. AreaTableEntry const* targetAreaEntry = GetAreaEntryByAreaID(target->GetAreaId());
  3626. if (targetAreaEntry && !(targetAreaEntry->flags & AREA_FLAG_ALLOW_DUELS))
  3627. {
  3628. SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
  3629. return;
  3630. }
  3631. //CREATE DUEL FLAG OBJECT
  3632. GameObject* pGameObj = new GameObject;
  3633. uint32 gameobject_id = m_spellInfo->Effects[effIndex].MiscValue;
  3634. Map* map = m_caster->GetMap();
  3635. if (!pGameObj->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id,
  3636. map, m_caster->GetPhaseMask(),
  3637. m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2,
  3638. m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2,
  3639. m_caster->GetPositionZ(),
  3640. m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
  3641. {
  3642. delete pGameObj;
  3643. return;
  3644. }
  3645. pGameObj->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction());
  3646. pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1);
  3647. int32 duration = m_spellInfo->GetDuration();
  3648. pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0);
  3649. pGameObj->SetSpellId(m_spellInfo->Id);
  3650. ExecuteLogEffectSummonObject(effIndex, pGameObj);
  3651. m_caster->AddGameObject(pGameObj);
  3652. map->AddToMap(pGameObj);
  3653. //END
  3654. // Send request
  3655. WorldPacket data(SMSG_DUEL_REQUESTED, 8 + 8);
  3656. data << uint64(pGameObj->GetGUID());
  3657. data << uint64(caster->GetGUID());
  3658. caster->GetSession()->SendPacket(&data);
  3659. target->GetSession()->SendPacket(&data);
  3660. // create duel-info
  3661. DuelInfo* duel = new DuelInfo;
  3662. duel->initiator = caster;
  3663. duel->opponent = target;
  3664. duel->startTime = 0;
  3665. duel->startTimer = 0;
  3666. duel->isMounted = (GetSpellInfo()->Id == 62875); // Mounted Duel
  3667. caster->duel = duel;
  3668. DuelInfo* duel2 = new DuelInfo;
  3669. duel2->initiator = caster;
  3670. duel2->opponent = caster;
  3671. duel2->startTime = 0;
  3672. duel2->startTimer = 0;
  3673. duel2->isMounted = (GetSpellInfo()->Id == 62875); // Mounted Duel
  3674. target->duel = duel2;
  3675. caster->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
  3676. target->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
  3677. sScriptMgr->OnPlayerDuelRequest(target, caster);
  3678. }
  3679. void Spell::EffectStuck(SpellEffIndex /*effIndex*/)
  3680. {
  3681. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  3682. return;
  3683. if (!sWorld->getBoolConfig(CONFIG_CAST_UNSTUCK))
  3684. return;
  3685. Player* player = m_caster->ToPlayer();
  3686. if (!player)
  3687. return;
  3688. TC_LOG_DEBUG("spells", "Spell Effect: Stuck");
  3689. TC_LOG_INFO("spells", "Player %s (guid %u) used auto-unstuck future at map %u (%f, %f, %f)", player->GetName().c_str(), player->GetGUIDLow(), player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
  3690. if (player->IsInFlight())
  3691. return;
  3692. player->TeleportTo(player->GetStartPosition(), TELE_TO_SPELL);
  3693. // homebind location is loaded always
  3694. // target->TeleportTo(target->m_homebindMapId, target->m_homebindX, target->m_homebindY, target->m_homebindZ, target->GetOrientation(), (m_caster == m_caster ? TELE_TO_SPELL : 0));
  3695. // Stuck spell trigger Hearthstone cooldown
  3696. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(8690);
  3697. if (!spellInfo)
  3698. return;
  3699. Spell spell(player, spellInfo, TRIGGERED_FULL_MASK);
  3700. spell.SendSpellCooldown();
  3701. }
  3702. void Spell::EffectSummonPlayer(SpellEffIndex /*effIndex*/)
  3703. {
  3704. // workaround - this effect should not use target map
  3705. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3706. return;
  3707. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3708. return;
  3709. // Evil Twin (ignore player summon, but hide this for summoner)
  3710. if (unitTarget->HasAura(23445))
  3711. return;
  3712. float x, y, z;
  3713. m_caster->GetPosition(x, y, z);
  3714. unitTarget->ToPlayer()->SetSummonPoint(m_caster->GetMapId(), x, y, z);
  3715. WorldPacket data(SMSG_SUMMON_REQUEST, 8+4+4);
  3716. data << uint64(m_caster->GetGUID()); // summoner guid
  3717. data << uint32(m_caster->GetZoneId()); // summoner zone
  3718. data << uint32(MAX_PLAYER_SUMMON_DELAY*IN_MILLISECONDS); // auto decline after msecs
  3719. unitTarget->ToPlayer()->GetSession()->SendPacket(&data);
  3720. }
  3721. void Spell::EffectActivateObject(SpellEffIndex /*effIndex*/)
  3722. {
  3723. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3724. return;
  3725. if (!gameObjTarget)
  3726. return;
  3727. ScriptInfo activateCommand;
  3728. activateCommand.command = SCRIPT_COMMAND_ACTIVATE_OBJECT;
  3729. // int32 unk = m_spellInfo->Effects[effIndex].MiscValue; // This is set for EffectActivateObject spells; needs research
  3730. gameObjTarget->GetMap()->ScriptCommandStart(activateCommand, 0, m_caster, gameObjTarget);
  3731. }
  3732. void Spell::EffectApplyGlyph(SpellEffIndex effIndex)
  3733. {
  3734. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  3735. return;
  3736. if (m_glyphIndex >= MAX_GLYPH_SLOT_INDEX)
  3737. return;
  3738. Player* player = m_caster->ToPlayer();
  3739. if (!player)
  3740. return;
  3741. // glyph sockets level requirement
  3742. uint8 minLevel = 0;
  3743. switch (m_glyphIndex)
  3744. {
  3745. case 0:
  3746. case 1: minLevel = 15; break;
  3747. case 2: minLevel = 50; break;
  3748. case 3: minLevel = 30; break;
  3749. case 4: minLevel = 70; break;
  3750. case 5: minLevel = 80; break;
  3751. }
  3752. if (minLevel && m_caster->getLevel() < minLevel)
  3753. {
  3754. SendCastResult(SPELL_FAILED_GLYPH_SOCKET_LOCKED);
  3755. return;
  3756. }
  3757. // apply new one
  3758. if (uint32 glyph = m_spellInfo->Effects[effIndex].MiscValue)
  3759. {
  3760. if (GlyphPropertiesEntry const* gp = sGlyphPropertiesStore.LookupEntry(glyph))
  3761. {
  3762. if (GlyphSlotEntry const* gs = sGlyphSlotStore.LookupEntry(player->GetGlyphSlot(m_glyphIndex)))
  3763. {
  3764. if (gp->TypeFlags != gs->TypeFlags)
  3765. {
  3766. SendCastResult(SPELL_FAILED_INVALID_GLYPH);
  3767. return; // glyph slot mismatch
  3768. }
  3769. }
  3770. // remove old glyph
  3771. if (uint32 oldglyph = player->GetGlyph(m_glyphIndex))
  3772. {
  3773. if (GlyphPropertiesEntry const* old_gp = sGlyphPropertiesStore.LookupEntry(oldglyph))
  3774. {
  3775. player->RemoveAurasDueToSpell(old_gp->SpellId);
  3776. player->SetGlyph(m_glyphIndex, 0);
  3777. }
  3778. }
  3779. player->CastSpell(m_caster, gp->SpellId, true);
  3780. player->SetGlyph(m_glyphIndex, glyph);
  3781. player->SendTalentsInfoData(false);
  3782. }
  3783. }
  3784. }
  3785. void Spell::EffectEnchantHeldItem(SpellEffIndex effIndex)
  3786. {
  3787. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3788. return;
  3789. // this is only item spell effect applied to main-hand weapon of target player (players in area)
  3790. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3791. return;
  3792. Player* item_owner = unitTarget->ToPlayer();
  3793. Item* item = item_owner->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
  3794. if (!item)
  3795. return;
  3796. // must be equipped
  3797. if (!item->IsEquipped())
  3798. return;
  3799. if (m_spellInfo->Effects[effIndex].MiscValue)
  3800. {
  3801. uint32 enchant_id = m_spellInfo->Effects[effIndex].MiscValue;
  3802. int32 duration = m_spellInfo->GetDuration(); //Try duration index first ..
  3803. if (!duration)
  3804. duration = damage;//+1; //Base points after ..
  3805. if (!duration)
  3806. duration = 10; //10 seconds for enchants which don't have listed duration
  3807. SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
  3808. if (!pEnchant)
  3809. return;
  3810. // Always go to temp enchantment slot
  3811. EnchantmentSlot slot = TEMP_ENCHANTMENT_SLOT;
  3812. // Enchantment will not be applied if a different one already exists
  3813. if (item->GetEnchantmentId(slot) && item->GetEnchantmentId(slot) != enchant_id)
  3814. return;
  3815. // Apply the temporary enchantment
  3816. item->SetEnchantment(slot, enchant_id, duration*IN_MILLISECONDS, 0, m_caster->GetGUID());
  3817. item_owner->ApplyEnchantment(item, slot, true);
  3818. }
  3819. }
  3820. void Spell::EffectDisEnchant(SpellEffIndex /*effIndex*/)
  3821. {
  3822. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3823. return;
  3824. if (!itemTarget || !itemTarget->GetTemplate()->DisenchantID)
  3825. return;
  3826. if (Player* caster = m_caster->ToPlayer())
  3827. {
  3828. caster->UpdateCraftSkill(m_spellInfo->Id);
  3829. caster->SendLoot(itemTarget->GetGUID(), LOOT_DISENCHANTING);
  3830. }
  3831. // item will be removed at disenchanting end
  3832. }
  3833. void Spell::EffectInebriate(SpellEffIndex /*effIndex*/)
  3834. {
  3835. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3836. return;
  3837. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3838. return;
  3839. Player* player = unitTarget->ToPlayer();
  3840. uint8 currentDrunk = player->GetDrunkValue();
  3841. uint8 drunkMod = damage;
  3842. if (currentDrunk + drunkMod > 100)
  3843. {
  3844. currentDrunk = 100;
  3845. if (rand_chance() < 25.0f)
  3846. player->CastSpell(player, 67468, false); // Drunken Vomit
  3847. }
  3848. else
  3849. currentDrunk += drunkMod;
  3850. player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0);
  3851. }
  3852. void Spell::EffectFeedPet(SpellEffIndex effIndex)
  3853. {
  3854. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3855. return;
  3856. Player* player = m_caster->ToPlayer();
  3857. if (!player)
  3858. return;
  3859. Item* foodItem = itemTarget;
  3860. if (!foodItem)
  3861. return;
  3862. Pet* pet = player->GetPet();
  3863. if (!pet)
  3864. return;
  3865. if (!pet->IsAlive())
  3866. return;
  3867. int32 benefit = pet->GetCurrentFoodBenefitLevel(foodItem->GetTemplate()->ItemLevel);
  3868. if (benefit <= 0)
  3869. return;
  3870. ExecuteLogEffectDestroyItem(effIndex, foodItem->GetEntry());
  3871. uint32 count = 1;
  3872. player->DestroyItemCount(foodItem, count, true);
  3873. /// @todo fix crash when a spell has two effects, both pointed at the same item target
  3874. m_caster->CastCustomSpell(pet, m_spellInfo->Effects[effIndex].TriggerSpell, &benefit, NULL, NULL, true);
  3875. }
  3876. void Spell::EffectDismissPet(SpellEffIndex effIndex)
  3877. {
  3878. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3879. return;
  3880. if (!unitTarget || !unitTarget->IsPet())
  3881. return;
  3882. Pet* pet = unitTarget->ToPet();
  3883. ExecuteLogEffectUnsummonObject(effIndex, pet);
  3884. pet->GetOwner()->RemovePet(pet, PET_SAVE_NOT_IN_SLOT);
  3885. }
  3886. void Spell::EffectSummonObject(SpellEffIndex effIndex)
  3887. {
  3888. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  3889. return;
  3890. uint32 go_id = m_spellInfo->Effects[effIndex].MiscValue;
  3891. uint8 slot = m_spellInfo->Effects[effIndex].Effect - SPELL_EFFECT_SUMMON_OBJECT_SLOT1;
  3892. if (uint64 guid = m_caster->m_ObjectSlot[slot])
  3893. {
  3894. if (GameObject* obj = m_caster->GetMap()->GetGameObject(guid))
  3895. {
  3896. // Recast case - null spell id to make auras not be removed on object remove from world
  3897. if (m_spellInfo->Id == obj->GetSpellId())
  3898. obj->SetSpellId(0);
  3899. m_caster->RemoveGameObject(obj, true);
  3900. }
  3901. m_caster->m_ObjectSlot[slot] = 0;
  3902. }
  3903. GameObject* go = new GameObject();
  3904. float x, y, z;
  3905. // If dest location if present
  3906. if (m_targets.HasDst())
  3907. destTarget->GetPosition(x, y, z);
  3908. // Summon in random point all other units if location present
  3909. else
  3910. m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
  3911. Map* map = m_caster->GetMap();
  3912. if (!go->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), go_id, map,
  3913. m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
  3914. {
  3915. delete go;
  3916. return;
  3917. }
  3918. //pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
  3919. int32 duration = m_spellInfo->GetDuration();
  3920. go->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0);
  3921. go->SetSpellId(m_spellInfo->Id);
  3922. m_caster->AddGameObject(go);
  3923. ExecuteLogEffectSummonObject(effIndex, go);
  3924. map->AddToMap(go);
  3925. m_caster->m_ObjectSlot[slot] = go->GetGUID();
  3926. }
  3927. void Spell::EffectResurrect(SpellEffIndex effIndex)
  3928. {
  3929. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3930. return;
  3931. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3932. return;
  3933. if (unitTarget->IsAlive() || !unitTarget->IsInWorld())
  3934. return;
  3935. Player* target = unitTarget->ToPlayer();
  3936. if (target->isRessurectRequested()) // already have one active request
  3937. return;
  3938. uint32 health = target->CountPctFromMaxHealth(damage);
  3939. uint32 mana = CalculatePct(target->GetMaxPower(POWER_MANA), damage);
  3940. ExecuteLogEffectResurrect(effIndex, target);
  3941. target->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
  3942. SendResurrectRequest(target);
  3943. }
  3944. void Spell::EffectAddExtraAttacks(SpellEffIndex effIndex)
  3945. {
  3946. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3947. return;
  3948. if (!unitTarget || !unitTarget->IsAlive() || !unitTarget->GetVictim())
  3949. return;
  3950. if (unitTarget->m_extraAttacks)
  3951. return;
  3952. unitTarget->m_extraAttacks = damage;
  3953. ExecuteLogEffectExtraAttacks(effIndex, unitTarget->GetVictim(), damage);
  3954. }
  3955. void Spell::EffectParry(SpellEffIndex /*effIndex*/)
  3956. {
  3957. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  3958. return;
  3959. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  3960. m_caster->ToPlayer()->SetCanParry(true);
  3961. }
  3962. void Spell::EffectBlock(SpellEffIndex /*effIndex*/)
  3963. {
  3964. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  3965. return;
  3966. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  3967. m_caster->ToPlayer()->SetCanBlock(true);
  3968. }
  3969. void Spell::EffectLeap(SpellEffIndex /*effIndex*/)
  3970. {
  3971. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3972. return;
  3973. if (!unitTarget || unitTarget->IsInFlight())
  3974. return;
  3975. if (!m_targets.HasDst())
  3976. return;
  3977. Position pos = destTarget->GetPosition();
  3978. pos = unitTarget->GetFirstCollisionPosition(unitTarget->GetDistance(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ() + 2.0f), 0.0f);
  3979. unitTarget->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), unitTarget == m_caster);
  3980. }
  3981. void Spell::EffectReputation(SpellEffIndex effIndex)
  3982. {
  3983. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3984. return;
  3985. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  3986. return;
  3987. Player* player = unitTarget->ToPlayer();
  3988. int32 repChange = damage;
  3989. uint32 factionId = m_spellInfo->Effects[effIndex].MiscValue;
  3990. FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId);
  3991. if (!factionEntry)
  3992. return;
  3993. repChange = player->CalculateReputationGain(REPUTATION_SOURCE_SPELL, 0, repChange, factionId);
  3994. player->GetReputationMgr().ModifyReputation(factionEntry, repChange);
  3995. }
  3996. void Spell::EffectQuestComplete(SpellEffIndex effIndex)
  3997. {
  3998. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  3999. return;
  4000. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4001. return;
  4002. Player* player = unitTarget->ToPlayer();
  4003. uint32 questId = m_spellInfo->Effects[effIndex].MiscValue;
  4004. if (questId)
  4005. {
  4006. Quest const* quest = sObjectMgr->GetQuestTemplate(questId);
  4007. if (!quest)
  4008. return;
  4009. uint16 logSlot = player->FindQuestSlot(questId);
  4010. if (logSlot < MAX_QUEST_LOG_SIZE)
  4011. player->AreaExploredOrEventHappens(questId);
  4012. else if (player->CanTakeQuest(quest, false)) // never rewarded before
  4013. player->CompleteQuest(questId); // quest not in log - for internal use
  4014. }
  4015. }
  4016. void Spell::EffectForceDeselect(SpellEffIndex /*effIndex*/)
  4017. {
  4018. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4019. return;
  4020. WorldPacket data(SMSG_CLEAR_TARGET, 8);
  4021. data << uint64(m_caster->GetGUID());
  4022. m_caster->SendMessageToSet(&data, true);
  4023. }
  4024. void Spell::EffectSelfResurrect(SpellEffIndex effIndex)
  4025. {
  4026. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4027. return;
  4028. if (!m_caster || m_caster->IsAlive())
  4029. return;
  4030. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  4031. return;
  4032. if (!m_caster->IsInWorld())
  4033. return;
  4034. uint32 health = 0;
  4035. uint32 mana = 0;
  4036. // flat case
  4037. if (damage < 0)
  4038. {
  4039. health = uint32(-damage);
  4040. mana = m_spellInfo->Effects[effIndex].MiscValue;
  4041. }
  4042. // percent case
  4043. else
  4044. {
  4045. health = m_caster->CountPctFromMaxHealth(damage);
  4046. if (m_caster->GetMaxPower(POWER_MANA) > 0)
  4047. mana = CalculatePct(m_caster->GetMaxPower(POWER_MANA), damage);
  4048. }
  4049. Player* player = m_caster->ToPlayer();
  4050. player->ResurrectPlayer(0.0f);
  4051. player->SetHealth(health);
  4052. player->SetPower(POWER_MANA, mana);
  4053. player->SetPower(POWER_RAGE, 0);
  4054. player->SetPower(POWER_ENERGY, player->GetMaxPower(POWER_ENERGY));
  4055. player->SpawnCorpseBones();
  4056. }
  4057. void Spell::EffectSkinning(SpellEffIndex /*effIndex*/)
  4058. {
  4059. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4060. return;
  4061. if (unitTarget->GetTypeId() != TYPEID_UNIT)
  4062. return;
  4063. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  4064. return;
  4065. Creature* creature = unitTarget->ToCreature();
  4066. int32 targetLevel = creature->getLevel();
  4067. uint32 skill = creature->GetCreatureTemplate()->GetRequiredLootSkill();
  4068. m_caster->ToPlayer()->SendLoot(creature->GetGUID(), LOOT_SKINNING);
  4069. creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
  4070. int32 reqValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel-10)*10 : targetLevel*5;
  4071. int32 skillValue = m_caster->ToPlayer()->GetPureSkillValue(skill);
  4072. // Double chances for elites
  4073. m_caster->ToPlayer()->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1);
  4074. }
  4075. void Spell::EffectCharge(SpellEffIndex /*effIndex*/)
  4076. {
  4077. if (!unitTarget)
  4078. return;
  4079. if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  4080. {
  4081. // Spell is not using explicit target - no generated path
  4082. if (m_preGeneratedPath.GetPathType() == PATHFIND_BLANK)
  4083. {
  4084. //unitTarget->GetContactPoint(m_caster, pos.m_positionX, pos.m_positionY, pos.m_positionZ);
  4085. Position pos = unitTarget->GetFirstCollisionPosition(unitTarget->GetObjectSize(), unitTarget->GetRelativeAngle(m_caster));
  4086. m_caster->GetMotionMaster()->MoveCharge(pos.m_positionX, pos.m_positionY, pos.m_positionZ);
  4087. }
  4088. else
  4089. m_caster->GetMotionMaster()->MoveCharge(m_preGeneratedPath);
  4090. }
  4091. if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET)
  4092. {
  4093. // not all charge effects used in negative spells
  4094. if (!m_spellInfo->IsPositive() && m_caster->GetTypeId() == TYPEID_PLAYER)
  4095. m_caster->Attack(unitTarget, true);
  4096. }
  4097. }
  4098. void Spell::EffectChargeDest(SpellEffIndex /*effIndex*/)
  4099. {
  4100. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH)
  4101. return;
  4102. if (m_targets.HasDst())
  4103. {
  4104. Position pos = destTarget->GetPosition();
  4105. float angle = m_caster->GetRelativeAngle(pos.GetPositionX(), pos.GetPositionY());
  4106. float dist = m_caster->GetDistance(pos);
  4107. pos = m_caster->GetFirstCollisionPosition(dist, angle);
  4108. m_caster->GetMotionMaster()->MoveCharge(pos.m_positionX, pos.m_positionY, pos.m_positionZ);
  4109. }
  4110. }
  4111. void Spell::EffectKnockBack(SpellEffIndex effIndex)
  4112. {
  4113. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4114. return;
  4115. if (!unitTarget)
  4116. return;
  4117. if (Creature* creatureTarget = unitTarget->ToCreature())
  4118. if (creatureTarget->isWorldBoss() || creatureTarget->IsDungeonBoss())
  4119. return;
  4120. // Spells with SPELL_EFFECT_KNOCK_BACK (like Thunderstorm) can't knockback target if target has ROOT/STUN
  4121. if (unitTarget->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
  4122. return;
  4123. // Instantly interrupt non melee spells being cast
  4124. if (unitTarget->IsNonMeleeSpellCast(true))
  4125. unitTarget->InterruptNonMeleeSpells(true);
  4126. float ratio = 0.1f;
  4127. float speedxy = float(m_spellInfo->Effects[effIndex].MiscValue) * ratio;
  4128. float speedz = float(damage) * ratio;
  4129. if (speedxy < 0.1f && speedz < 0.1f)
  4130. return;
  4131. float x, y;
  4132. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_KNOCK_BACK_DEST)
  4133. {
  4134. if (m_targets.HasDst())
  4135. destTarget->GetPosition(x, y);
  4136. else
  4137. return;
  4138. }
  4139. else //if (m_spellInfo->Effects[i].Effect == SPELL_EFFECT_KNOCK_BACK)
  4140. {
  4141. m_caster->GetPosition(x, y);
  4142. }
  4143. unitTarget->KnockbackFrom(x, y, speedxy, speedz);
  4144. }
  4145. void Spell::EffectLeapBack(SpellEffIndex effIndex)
  4146. {
  4147. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET)
  4148. return;
  4149. if (!unitTarget)
  4150. return;
  4151. float speedxy = float(m_spellInfo->Effects[effIndex].MiscValue)/10;
  4152. float speedz = float(damage/10);
  4153. //1891: Disengage
  4154. m_caster->JumpTo(speedxy, speedz, m_spellInfo->SpellIconID != 1891);
  4155. }
  4156. void Spell::EffectQuestClear(SpellEffIndex effIndex)
  4157. {
  4158. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4159. return;
  4160. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4161. return;
  4162. Player* player = unitTarget->ToPlayer();
  4163. uint32 quest_id = m_spellInfo->Effects[effIndex].MiscValue;
  4164. Quest const* quest = sObjectMgr->GetQuestTemplate(quest_id);
  4165. if (!quest)
  4166. return;
  4167. // Player has never done this quest
  4168. if (player->GetQuestStatus(quest_id) == QUEST_STATUS_NONE)
  4169. return;
  4170. // remove all quest entries for 'entry' from quest log
  4171. for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
  4172. {
  4173. uint32 logQuest = player->GetQuestSlotQuestId(slot);
  4174. if (logQuest == quest_id)
  4175. {
  4176. player->SetQuestSlot(slot, 0);
  4177. // we ignore unequippable quest items in this case, it's still be equipped
  4178. player->TakeQuestSourceItem(logQuest, false);
  4179. if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
  4180. {
  4181. player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
  4182. player->UpdatePvPState();
  4183. }
  4184. }
  4185. }
  4186. player->RemoveActiveQuest(quest_id, false);
  4187. player->RemoveRewardedQuest(quest_id);
  4188. }
  4189. void Spell::EffectSendTaxi(SpellEffIndex effIndex)
  4190. {
  4191. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4192. return;
  4193. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4194. return;
  4195. unitTarget->ToPlayer()->ActivateTaxiPathTo(m_spellInfo->Effects[effIndex].MiscValue, m_spellInfo->Id);
  4196. }
  4197. void Spell::EffectPullTowards(SpellEffIndex effIndex)
  4198. {
  4199. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4200. return;
  4201. if (!unitTarget)
  4202. return;
  4203. Position pos;
  4204. if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_PULL_TOWARDS_DEST)
  4205. {
  4206. if (m_targets.HasDst())
  4207. pos.Relocate(*destTarget);
  4208. else
  4209. return;
  4210. }
  4211. else //if (m_spellInfo->Effects[i].Effect == SPELL_EFFECT_PULL_TOWARDS)
  4212. {
  4213. pos.Relocate(m_caster);
  4214. }
  4215. float speedXY = float(m_spellInfo->Effects[effIndex].MiscValue) * 0.1f;
  4216. float speedZ = unitTarget->GetDistance(pos) / speedXY * 0.5f * Movement::gravity;
  4217. unitTarget->GetMotionMaster()->MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), speedXY, speedZ);
  4218. }
  4219. void Spell::EffectDispelMechanic(SpellEffIndex effIndex)
  4220. {
  4221. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4222. return;
  4223. if (!unitTarget)
  4224. return;
  4225. uint32 mechanic = m_spellInfo->Effects[effIndex].MiscValue;
  4226. std::queue < std::pair < uint32, uint64 > > dispel_list;
  4227. Unit::AuraMap const& auras = unitTarget->GetOwnedAuras();
  4228. for (Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
  4229. {
  4230. Aura* aura = itr->second;
  4231. if (!aura->GetApplicationOfTarget(unitTarget->GetGUID()))
  4232. continue;
  4233. if (roll_chance_i(aura->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster))))
  4234. if ((aura->GetSpellInfo()->GetAllEffectsMechanicMask() & (1 << mechanic)))
  4235. dispel_list.push(std::make_pair(aura->GetId(), aura->GetCasterGUID()));
  4236. }
  4237. for (; dispel_list.size(); dispel_list.pop())
  4238. {
  4239. unitTarget->RemoveAura(dispel_list.front().first, dispel_list.front().second, 0, AURA_REMOVE_BY_ENEMY_SPELL);
  4240. }
  4241. }
  4242. void Spell::EffectResurrectPet(SpellEffIndex /*effIndex*/)
  4243. {
  4244. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4245. return;
  4246. if (damage < 0)
  4247. return;
  4248. Player* player = m_caster->ToPlayer();
  4249. if (!player)
  4250. return;
  4251. // Maybe player dismissed dead pet or pet despawned?
  4252. bool hadPet = true;
  4253. if (!player->GetPet())
  4254. {
  4255. // Position passed to SummonPet is irrelevant with current implementation,
  4256. // pet will be relocated without using these coords in Pet::LoadPetFromDB
  4257. player->SummonPet(0, 0.0f, 0.0f, 0.0f, 0.0f, SUMMON_PET, 0);
  4258. hadPet = false;
  4259. }
  4260. // TODO: Better to fail Hunter's "Revive Pet" at cast instead of here when casting ends
  4261. Pet* pet = player->GetPet(); // Attempt to get current pet
  4262. if (!pet || pet->IsAlive())
  4263. return;
  4264. // If player did have a pet before reviving, teleport it
  4265. if (hadPet)
  4266. {
  4267. // Reposition the pet's corpse before reviving so as not to grab aggro
  4268. // We can use a different, more accurate version of GetClosePoint() since we have a pet
  4269. float x, y, z; // Will be used later to reposition the pet if we have one
  4270. player->GetClosePoint(x, y, z, pet->GetObjectSize(), PET_FOLLOW_DIST, pet->GetFollowAngle());
  4271. pet->NearTeleportTo(x, y, z, player->GetOrientation());
  4272. pet->Relocate(x, y, z, player->GetOrientation()); // This is needed so SaveStayPosition() will get the proper coords.
  4273. }
  4274. pet->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_NONE);
  4275. pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
  4276. pet->setDeathState(ALIVE);
  4277. pet->ClearUnitState(uint32(UNIT_STATE_ALL_STATE));
  4278. pet->SetHealth(pet->CountPctFromMaxHealth(damage));
  4279. // Reset things for when the AI to takes over
  4280. CharmInfo *ci = pet->GetCharmInfo();
  4281. if (ci)
  4282. {
  4283. // In case the pet was at stay, we don't want it running back
  4284. ci->SaveStayPosition();
  4285. ci->SetIsAtStay(ci->HasCommandState(COMMAND_STAY));
  4286. ci->SetIsFollowing(false);
  4287. ci->SetIsCommandAttack(false);
  4288. ci->SetIsCommandFollow(false);
  4289. ci->SetIsReturning(false);
  4290. }
  4291. pet->SavePetToDB(PET_SAVE_AS_CURRENT);
  4292. }
  4293. void Spell::EffectDestroyAllTotems(SpellEffIndex /*effIndex*/)
  4294. {
  4295. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4296. return;
  4297. int32 mana = 0;
  4298. for (uint8 slot = SUMMON_SLOT_TOTEM; slot < MAX_TOTEM_SLOT; ++slot)
  4299. {
  4300. if (!m_caster->m_SummonSlot[slot])
  4301. continue;
  4302. Creature* totem = m_caster->GetMap()->GetCreature(m_caster->m_SummonSlot[slot]);
  4303. if (totem && totem->IsTotem())
  4304. {
  4305. uint32 spell_id = totem->GetUInt32Value(UNIT_CREATED_BY_SPELL);
  4306. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id);
  4307. if (spellInfo)
  4308. {
  4309. mana += spellInfo->ManaCost;
  4310. mana += int32(CalculatePct(m_caster->GetCreateMana(), spellInfo->ManaCostPercentage));
  4311. }
  4312. totem->ToTotem()->UnSummon();
  4313. }
  4314. }
  4315. ApplyPct(mana, damage);
  4316. if (mana)
  4317. m_caster->CastCustomSpell(m_caster, 39104, &mana, NULL, NULL, true);
  4318. }
  4319. void Spell::EffectDurabilityDamage(SpellEffIndex effIndex)
  4320. {
  4321. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4322. return;
  4323. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4324. return;
  4325. int32 slot = m_spellInfo->Effects[effIndex].MiscValue;
  4326. // -1 means all player equipped items and -2 all items
  4327. if (slot < 0)
  4328. {
  4329. unitTarget->ToPlayer()->DurabilityPointsLossAll(damage, (slot < -1));
  4330. ExecuteLogEffectDurabilityDamage(effIndex, unitTarget, -1, -1);
  4331. return;
  4332. }
  4333. // invalid slot value
  4334. if (slot >= INVENTORY_SLOT_BAG_END)
  4335. return;
  4336. if (Item* item = unitTarget->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
  4337. {
  4338. unitTarget->ToPlayer()->DurabilityPointsLoss(item, damage);
  4339. ExecuteLogEffectDurabilityDamage(effIndex, unitTarget, item->GetEntry(), slot);
  4340. }
  4341. }
  4342. void Spell::EffectDurabilityDamagePCT(SpellEffIndex effIndex)
  4343. {
  4344. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4345. return;
  4346. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4347. return;
  4348. int32 slot = m_spellInfo->Effects[effIndex].MiscValue;
  4349. // FIXME: some spells effects have value -1/-2
  4350. // Possibly its mean -1 all player equipped items and -2 all items
  4351. if (slot < 0)
  4352. {
  4353. unitTarget->ToPlayer()->DurabilityLossAll(float(damage) / 100.0f, (slot < -1));
  4354. return;
  4355. }
  4356. // invalid slot value
  4357. if (slot >= INVENTORY_SLOT_BAG_END)
  4358. return;
  4359. if (damage <= 0)
  4360. return;
  4361. if (Item* item = unitTarget->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
  4362. unitTarget->ToPlayer()->DurabilityLoss(item, float(damage) / 100.0f);
  4363. }
  4364. void Spell::EffectModifyThreatPercent(SpellEffIndex /*effIndex*/)
  4365. {
  4366. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4367. return;
  4368. if (!unitTarget)
  4369. return;
  4370. unitTarget->getThreatManager().modifyThreatPercent(m_caster, damage);
  4371. }
  4372. void Spell::EffectTransmitted(SpellEffIndex effIndex)
  4373. {
  4374. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4375. return;
  4376. uint32 name_id = m_spellInfo->Effects[effIndex].MiscValue;
  4377. GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(name_id);
  4378. if (!goinfo)
  4379. {
  4380. TC_LOG_ERROR("sql.sql", "Gameobject (Entry: %u) not exist and not created at spell (ID: %u) cast", name_id, m_spellInfo->Id);
  4381. return;
  4382. }
  4383. float fx, fy, fz;
  4384. if (m_targets.HasDst())
  4385. destTarget->GetPosition(fx, fy, fz);
  4386. //FIXME: this can be better check for most objects but still hack
  4387. else if (m_spellInfo->Effects[effIndex].HasRadius() && m_spellInfo->Speed == 0)
  4388. {
  4389. float dis = m_spellInfo->Effects[effIndex].CalcRadius(m_originalCaster);
  4390. m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
  4391. }
  4392. else
  4393. {
  4394. //GO is always friendly to it's creator, get range for friends
  4395. float min_dis = m_spellInfo->GetMinRange(true);
  4396. float max_dis = m_spellInfo->GetMaxRange(true);
  4397. float dis = (float)rand_norm() * (max_dis - min_dis) + min_dis;
  4398. m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
  4399. }
  4400. Map* cMap = m_caster->GetMap();
  4401. // if gameobject is summoning object, it should be spawned right on caster's position
  4402. if (goinfo->type == GAMEOBJECT_TYPE_SUMMONING_RITUAL)
  4403. m_caster->GetPosition(fx, fy, fz);
  4404. GameObject* pGameObj = new GameObject;
  4405. if (!pGameObj->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), name_id, cMap,
  4406. m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
  4407. {
  4408. delete pGameObj;
  4409. return;
  4410. }
  4411. int32 duration = m_spellInfo->GetDuration();
  4412. switch (goinfo->type)
  4413. {
  4414. case GAMEOBJECT_TYPE_FISHINGNODE:
  4415. {
  4416. m_caster->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, pGameObj->GetGUID());
  4417. m_caster->AddGameObject(pGameObj); // will removed at spell cancel
  4418. // end time of range when possible catch fish (FISHING_BOBBER_READY_TIME..GetDuration(m_spellInfo))
  4419. // start time == fish-FISHING_BOBBER_READY_TIME (0..GetDuration(m_spellInfo)-FISHING_BOBBER_READY_TIME)
  4420. int32 lastSec = 0;
  4421. switch (urand(0, 3))
  4422. {
  4423. case 0: lastSec = 3; break;
  4424. case 1: lastSec = 7; break;
  4425. case 2: lastSec = 13; break;
  4426. case 3: lastSec = 17; break;
  4427. }
  4428. duration = duration - lastSec*IN_MILLISECONDS + FISHING_BOBBER_READY_TIME*IN_MILLISECONDS;
  4429. break;
  4430. }
  4431. case GAMEOBJECT_TYPE_SUMMONING_RITUAL:
  4432. {
  4433. if (m_caster->GetTypeId() == TYPEID_PLAYER)
  4434. {
  4435. pGameObj->AddUniqueUse(m_caster->ToPlayer());
  4436. m_caster->AddGameObject(pGameObj); // will be removed at spell cancel
  4437. }
  4438. break;
  4439. }
  4440. case GAMEOBJECT_TYPE_DUEL_ARBITER: // 52991
  4441. m_caster->AddGameObject(pGameObj);
  4442. break;
  4443. case GAMEOBJECT_TYPE_FISHINGHOLE:
  4444. case GAMEOBJECT_TYPE_CHEST:
  4445. default:
  4446. break;
  4447. }
  4448. pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0);
  4449. pGameObj->SetOwnerGUID(m_caster->GetGUID());
  4450. //pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
  4451. pGameObj->SetSpellId(m_spellInfo->Id);
  4452. ExecuteLogEffectSummonObject(effIndex, pGameObj);
  4453. TC_LOG_DEBUG("spells", "AddObject at SpellEfects.cpp EffectTransmitted");
  4454. //m_caster->AddGameObject(pGameObj);
  4455. //m_ObjToDel.push_back(pGameObj);
  4456. cMap->AddToMap(pGameObj);
  4457. if (uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
  4458. {
  4459. GameObject* linkedGO = new GameObject;
  4460. if (linkedGO->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, cMap,
  4461. m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
  4462. {
  4463. linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILLISECONDS : 0);
  4464. //linkedGO->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
  4465. linkedGO->SetSpellId(m_spellInfo->Id);
  4466. linkedGO->SetOwnerGUID(m_caster->GetGUID());
  4467. ExecuteLogEffectSummonObject(effIndex, linkedGO);
  4468. linkedGO->GetMap()->AddToMap(linkedGO);
  4469. }
  4470. else
  4471. {
  4472. delete linkedGO;
  4473. linkedGO = NULL;
  4474. return;
  4475. }
  4476. }
  4477. }
  4478. void Spell::EffectProspecting(SpellEffIndex /*effIndex*/)
  4479. {
  4480. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4481. return;
  4482. Player* player = m_caster->ToPlayer();
  4483. if (!player)
  4484. return;
  4485. if (!itemTarget || !(itemTarget->GetTemplate()->Flags & ITEM_PROTO_FLAG_PROSPECTABLE))
  4486. return;
  4487. if (itemTarget->GetCount() < 5)
  4488. return;
  4489. if (sWorld->getBoolConfig(CONFIG_SKILL_PROSPECTING))
  4490. {
  4491. uint32 SkillValue = player->GetPureSkillValue(SKILL_JEWELCRAFTING);
  4492. uint32 reqSkillValue = itemTarget->GetTemplate()->RequiredSkillRank;
  4493. player->UpdateGatherSkill(SKILL_JEWELCRAFTING, SkillValue, reqSkillValue);
  4494. }
  4495. player->SendLoot(itemTarget->GetGUID(), LOOT_PROSPECTING);
  4496. }
  4497. void Spell::EffectMilling(SpellEffIndex /*effIndex*/)
  4498. {
  4499. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4500. return;
  4501. Player* player = m_caster->ToPlayer();
  4502. if (!player)
  4503. return;
  4504. if (!itemTarget || !(itemTarget->GetTemplate()->Flags & ITEM_PROTO_FLAG_MILLABLE))
  4505. return;
  4506. if (itemTarget->GetCount() < 5)
  4507. return;
  4508. if (sWorld->getBoolConfig(CONFIG_SKILL_MILLING))
  4509. {
  4510. uint32 SkillValue = player->GetPureSkillValue(SKILL_INSCRIPTION);
  4511. uint32 reqSkillValue = itemTarget->GetTemplate()->RequiredSkillRank;
  4512. player->UpdateGatherSkill(SKILL_INSCRIPTION, SkillValue, reqSkillValue);
  4513. }
  4514. player->SendLoot(itemTarget->GetGUID(), LOOT_MILLING);
  4515. }
  4516. void Spell::EffectSkill(SpellEffIndex /*effIndex*/)
  4517. {
  4518. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4519. return;
  4520. TC_LOG_DEBUG("spells", "WORLD: SkillEFFECT");
  4521. }
  4522. /* There is currently no need for this effect. We handle it in Battleground.cpp
  4523. If we would handle the resurrection here, the spiritguide would instantly disappear as the
  4524. player revives, and so we wouldn't see the spirit heal visual effect on the npc.
  4525. This is why we use a half sec delay between the visual effect and the resurrection itself */
  4526. void Spell::EffectSpiritHeal(SpellEffIndex /*effIndex*/)
  4527. {
  4528. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4529. return;
  4530. /*
  4531. if (unitTarget->GetTypeId() != TYPEID_PLAYER)
  4532. return;
  4533. if (!unitTarget->IsInWorld())
  4534. return;
  4535. //m_spellInfo->Effects[i].BasePoints; == 99 (percent?)
  4536. //unitTarget->ToPlayer()->setResurrect(m_caster->GetGUID(), unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), unitTarget->GetMaxHealth(), unitTarget->GetMaxPower(POWER_MANA));
  4537. unitTarget->ToPlayer()->ResurrectPlayer(1.0f);
  4538. unitTarget->ToPlayer()->SpawnCorpseBones();
  4539. */
  4540. }
  4541. // remove insignia spell effect
  4542. void Spell::EffectSkinPlayerCorpse(SpellEffIndex /*effIndex*/)
  4543. {
  4544. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4545. return;
  4546. TC_LOG_DEBUG("spells", "Effect: SkinPlayerCorpse");
  4547. Player* player = m_caster->ToPlayer();
  4548. Player* target = unitTarget->ToPlayer();
  4549. if (!player || !target || target->IsAlive())
  4550. return;
  4551. target->RemovedInsignia(player);
  4552. }
  4553. void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex)
  4554. {
  4555. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4556. return;
  4557. TC_LOG_DEBUG("spells", "Effect: StealBeneficialBuff");
  4558. if (!unitTarget || unitTarget == m_caster) // can't steal from self
  4559. return;
  4560. DispelChargesList steal_list;
  4561. // Create dispel mask by dispel type
  4562. uint32 dispelMask = SpellInfo::GetDispelMask(DispelType(m_spellInfo->Effects[effIndex].MiscValue));
  4563. Unit::AuraMap const& auras = unitTarget->GetOwnedAuras();
  4564. for (Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
  4565. {
  4566. Aura* aura = itr->second;
  4567. AuraApplication * aurApp = aura->GetApplicationOfTarget(unitTarget->GetGUID());
  4568. if (!aurApp)
  4569. continue;
  4570. if ((aura->GetSpellInfo()->GetDispelMask()) & dispelMask)
  4571. {
  4572. // Need check for passive? this
  4573. if (!aurApp->IsPositive() || aura->IsPassive() || aura->GetSpellInfo()->AttributesEx4 & SPELL_ATTR4_NOT_STEALABLE)
  4574. continue;
  4575. // The charges / stack amounts don't count towards the total number of auras that can be dispelled.
  4576. // Ie: A dispel on a target with 5 stacks of Winters Chill and a Polymorph has 1 / (1 + 1) -> 50% chance to dispell
  4577. // Polymorph instead of 1 / (5 + 1) -> 16%.
  4578. bool dispel_charges = aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES;
  4579. uint8 charges = dispel_charges ? aura->GetCharges() : aura->GetStackAmount();
  4580. if (charges > 0)
  4581. steal_list.push_back(std::make_pair(aura, charges));
  4582. }
  4583. }
  4584. if (steal_list.empty())
  4585. return;
  4586. // Ok if exist some buffs for dispel try dispel it
  4587. uint32 failCount = 0;
  4588. DispelList success_list;
  4589. WorldPacket dataFail(SMSG_DISPEL_FAILED, 8+8+4+4+damage*4);
  4590. // dispel N = damage buffs (or while exist buffs for dispel)
  4591. for (int32 count = 0; count < damage && !steal_list.empty();)
  4592. {
  4593. // Random select buff for dispel
  4594. DispelChargesList::iterator itr = steal_list.begin();
  4595. std::advance(itr, urand(0, steal_list.size() - 1));
  4596. int32 chance = itr->first->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster));
  4597. // 2.4.3 Patch Notes: "Dispel effects will no longer attempt to remove effects that have 100% dispel resistance."
  4598. if (!chance)
  4599. {
  4600. steal_list.erase(itr);
  4601. continue;
  4602. }
  4603. else
  4604. {
  4605. if (roll_chance_i(chance))
  4606. {
  4607. success_list.push_back(std::make_pair(itr->first->GetId(), itr->first->GetCasterGUID()));
  4608. --itr->second;
  4609. if (itr->second <= 0)
  4610. steal_list.erase(itr);
  4611. }
  4612. else
  4613. {
  4614. if (!failCount)
  4615. {
  4616. // Failed to dispell
  4617. dataFail << uint64(m_caster->GetGUID()); // Caster GUID
  4618. dataFail << uint64(unitTarget->GetGUID()); // Victim GUID
  4619. dataFail << uint32(m_spellInfo->Id); // dispel spell id
  4620. }
  4621. ++failCount;
  4622. dataFail << uint32(itr->first->GetId()); // Spell Id
  4623. }
  4624. ++count;
  4625. }
  4626. }
  4627. if (failCount)
  4628. m_caster->SendMessageToSet(&dataFail, true);
  4629. if (success_list.empty())
  4630. return;
  4631. WorldPacket dataSuccess(SMSG_SPELLSTEALLOG, 8+8+4+1+4+damage*5);
  4632. dataSuccess.append(unitTarget->GetPackGUID()); // Victim GUID
  4633. dataSuccess.append(m_caster->GetPackGUID()); // Caster GUID
  4634. dataSuccess << uint32(m_spellInfo->Id); // dispel spell id
  4635. dataSuccess << uint8(0); // not used
  4636. dataSuccess << uint32(success_list.size()); // count
  4637. for (DispelList::iterator itr = success_list.begin(); itr!=success_list.end(); ++itr)
  4638. {
  4639. dataSuccess << uint32(itr->first); // Spell Id
  4640. dataSuccess << uint8(0); // 0 - steals !=0 transfers
  4641. unitTarget->RemoveAurasDueToSpellBySteal(itr->first, itr->second, m_caster);
  4642. if (itr->first == 2825)
  4643. m_caster->CastSpell(m_caster, 57724, true, NULL, NULL); //Bloodlust - Sated
  4644. if (itr->first == 32182)
  4645. m_caster->CastSpell(m_caster, 57723, true, NULL, NULL); //Heroism - Exhaustion
  4646. }
  4647. m_caster->SendMessageToSet(&dataSuccess, true);
  4648. }
  4649. void Spell::EffectKillCreditPersonal(SpellEffIndex effIndex)
  4650. {
  4651. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4652. return;
  4653. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4654. return;
  4655. unitTarget->ToPlayer()->KilledMonsterCredit(m_spellInfo->Effects[effIndex].MiscValue, 0);
  4656. }
  4657. void Spell::EffectKillCredit(SpellEffIndex effIndex)
  4658. {
  4659. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4660. return;
  4661. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4662. return;
  4663. int32 creatureEntry = m_spellInfo->Effects[effIndex].MiscValue;
  4664. if (!creatureEntry)
  4665. {
  4666. if (m_spellInfo->Id == 42793) // Burn Body
  4667. creatureEntry = 24008; // Fallen Combatant
  4668. }
  4669. if (creatureEntry)
  4670. unitTarget->ToPlayer()->RewardPlayerAndGroupAtEvent(creatureEntry, unitTarget);
  4671. }
  4672. void Spell::EffectQuestFail(SpellEffIndex effIndex)
  4673. {
  4674. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4675. return;
  4676. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4677. return;
  4678. unitTarget->ToPlayer()->FailQuest(m_spellInfo->Effects[effIndex].MiscValue);
  4679. }
  4680. void Spell::EffectQuestStart(SpellEffIndex effIndex)
  4681. {
  4682. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4683. return;
  4684. if (!unitTarget)
  4685. return;
  4686. Player* player = unitTarget->ToPlayer();
  4687. if (!player)
  4688. return;
  4689. if (Quest const* quest = sObjectMgr->GetQuestTemplate(m_spellInfo->Effects[effIndex].MiscValue))
  4690. {
  4691. if (!player->CanTakeQuest(quest, false))
  4692. return;
  4693. if (quest->IsAutoAccept() && player->CanAddQuest(quest, false))
  4694. player->AddQuestAndCheckCompletion(quest, player);
  4695. player->PlayerTalkClass->SendQuestGiverQuestDetails(quest, player->GetGUID(), true);
  4696. }
  4697. }
  4698. void Spell::EffectActivateRune(SpellEffIndex effIndex)
  4699. {
  4700. if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH)
  4701. return;
  4702. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  4703. return;
  4704. Player* player = m_caster->ToPlayer();
  4705. if (player->getClass() != CLASS_DEATH_KNIGHT)
  4706. return;
  4707. // needed later
  4708. m_runesState = m_caster->ToPlayer()->GetRunesState();
  4709. uint32 count = damage;
  4710. if (count == 0) count = 1;
  4711. for (uint32 j = 0; j < MAX_RUNES && count > 0; ++j)
  4712. {
  4713. if (player->GetRuneCooldown(j) && player->GetCurrentRune(j) == RuneType(m_spellInfo->Effects[effIndex].MiscValue))
  4714. {
  4715. if (m_spellInfo->Id == 45529)
  4716. if (player->GetBaseRune(j) != RuneType(m_spellInfo->Effects[effIndex].MiscValueB))
  4717. continue;
  4718. player->SetRuneCooldown(j, 0);
  4719. --count;
  4720. }
  4721. }
  4722. // Blood Tap
  4723. if (m_spellInfo->Id == 45529 && count > 0)
  4724. {
  4725. for (uint32 l = 0; l + 1 < MAX_RUNES && count > 0; ++l)
  4726. {
  4727. // Check if both runes are on cd as that is the only time when this needs to come into effect
  4728. if ((player->GetRuneCooldown(l) && player->GetCurrentRune(l) == RuneType(m_spellInfo->Effects[effIndex].MiscValueB)) && (player->GetRuneCooldown(l+1) && player->GetCurrentRune(l+1) == RuneType(m_spellInfo->Effects[effIndex].MiscValueB)))
  4729. {
  4730. // Should always update the rune with the lowest cd
  4731. if (l + 1 < MAX_RUNES && player->GetRuneCooldown(l) >= player->GetRuneCooldown(l+1))
  4732. l++;
  4733. player->SetRuneCooldown(l, 0);
  4734. --count;
  4735. // is needed to push through to the client that the rune is active
  4736. player->ResyncRunes(MAX_RUNES);
  4737. }
  4738. else
  4739. break;
  4740. }
  4741. }
  4742. // Empower rune weapon
  4743. if (m_spellInfo->Id == 47568)
  4744. {
  4745. // Need to do this just once
  4746. if (effIndex != 0)
  4747. return;
  4748. for (uint32 i = 0; i < MAX_RUNES; ++i)
  4749. {
  4750. if (player->GetRuneCooldown(i) && (player->GetCurrentRune(i) == RUNE_FROST || player->GetCurrentRune(i) == RUNE_DEATH))
  4751. player->SetRuneCooldown(i, 0);
  4752. }
  4753. }
  4754. }
  4755. void Spell::EffectCreateTamedPet(SpellEffIndex effIndex)
  4756. {
  4757. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4758. return;
  4759. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || unitTarget->GetPetGUID() || unitTarget->getClass() != CLASS_HUNTER)
  4760. return;
  4761. uint32 creatureEntry = m_spellInfo->Effects[effIndex].MiscValue;
  4762. Pet* pet = unitTarget->CreateTamedPetFrom(creatureEntry, m_spellInfo->Id);
  4763. if (!pet)
  4764. return;
  4765. // add to world
  4766. pet->GetMap()->AddToMap(pet->ToCreature());
  4767. // unitTarget has pet now
  4768. unitTarget->SetMinion(pet, true);
  4769. pet->InitTalentForLevel();
  4770. if (unitTarget->GetTypeId() == TYPEID_PLAYER)
  4771. {
  4772. pet->SavePetToDB(PET_SAVE_AS_CURRENT);
  4773. unitTarget->ToPlayer()->PetSpellInitialize();
  4774. }
  4775. }
  4776. void Spell::EffectDiscoverTaxi(SpellEffIndex effIndex)
  4777. {
  4778. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4779. return;
  4780. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4781. return;
  4782. uint32 nodeid = m_spellInfo->Effects[effIndex].MiscValue;
  4783. if (sTaxiNodesStore.LookupEntry(nodeid))
  4784. unitTarget->ToPlayer()->GetSession()->SendDiscoverNewTaxiNode(nodeid);
  4785. }
  4786. void Spell::EffectTitanGrip(SpellEffIndex /*effIndex*/)
  4787. {
  4788. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4789. return;
  4790. if (Player* player = (Player*)m_caster)
  4791. {
  4792. player->SetCanTitanGrip(true);
  4793. if (player->HasTwoHandWeaponInOneHand() && !player->HasAura(49152))
  4794. player->CastSpell(player, 49152, true);
  4795. }
  4796. }
  4797. void Spell::EffectRedirectThreat(SpellEffIndex /*effIndex*/)
  4798. {
  4799. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4800. return;
  4801. if (unitTarget)
  4802. m_caster->SetRedirectThreat(unitTarget->GetGUID(), uint32(damage));
  4803. }
  4804. void Spell::EffectGameObjectDamage(SpellEffIndex /*effIndex*/)
  4805. {
  4806. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4807. return;
  4808. if (!gameObjTarget)
  4809. return;
  4810. Unit* caster = m_originalCaster;
  4811. if (!caster)
  4812. return;
  4813. FactionTemplateEntry const* casterFaction = caster->GetFactionTemplateEntry();
  4814. FactionTemplateEntry const* targetFaction = sFactionTemplateStore.LookupEntry(gameObjTarget->GetUInt32Value(GAMEOBJECT_FACTION));
  4815. // Do not allow to damage GO's of friendly factions (ie: Wintergrasp Walls/Ulduar Storm Beacons)
  4816. if ((casterFaction && targetFaction && !casterFaction->IsFriendlyTo(*targetFaction)) || !targetFaction)
  4817. gameObjTarget->ModifyHealth(-damage, caster, GetSpellInfo()->Id);
  4818. }
  4819. void Spell::EffectGameObjectRepair(SpellEffIndex /*effIndex*/)
  4820. {
  4821. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4822. return;
  4823. if (!gameObjTarget)
  4824. return;
  4825. gameObjTarget->ModifyHealth(damage, m_caster);
  4826. }
  4827. void Spell::EffectGameObjectSetDestructionState(SpellEffIndex effIndex)
  4828. {
  4829. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4830. return;
  4831. if (!gameObjTarget || !m_originalCaster)
  4832. return;
  4833. Player* player = m_originalCaster->GetCharmerOrOwnerPlayerOrPlayerItself();
  4834. gameObjTarget->SetDestructibleState(GameObjectDestructibleState(m_spellInfo->Effects[effIndex].MiscValue), player, true);
  4835. }
  4836. void Spell::SummonGuardian(uint32 i, uint32 entry, SummonPropertiesEntry const* properties, uint32 numGuardians)
  4837. {
  4838. Unit* caster = m_originalCaster;
  4839. if (!caster)
  4840. return;
  4841. if (caster->IsTotem())
  4842. caster = caster->ToTotem()->GetOwner();
  4843. // in another case summon new
  4844. uint8 level = caster->getLevel();
  4845. // level of pet summoned using engineering item based at engineering skill level
  4846. if (m_CastItem && caster->GetTypeId() == TYPEID_PLAYER)
  4847. if (ItemTemplate const* proto = m_CastItem->GetTemplate())
  4848. if (proto->RequiredSkill == SKILL_ENGINEERING)
  4849. if (uint16 skill202 = caster->ToPlayer()->GetSkillValue(SKILL_ENGINEERING))
  4850. level = skill202 / 5;
  4851. float radius = 5.0f;
  4852. int32 duration = m_spellInfo->GetDuration();
  4853. if (Player* modOwner = m_originalCaster->GetSpellModOwner())
  4854. modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
  4855. //TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN;
  4856. Map* map = caster->GetMap();
  4857. for (uint32 count = 0; count < numGuardians; ++count)
  4858. {
  4859. Position pos;
  4860. if (count == 0)
  4861. pos = *destTarget;
  4862. else
  4863. // randomize position for multiple summons
  4864. pos = m_caster->GetRandomPoint(*destTarget, radius);
  4865. TempSummon* summon = map->SummonCreature(entry, pos, properties, duration, caster, m_spellInfo->Id);
  4866. if (!summon)
  4867. return;
  4868. if (summon->HasUnitTypeMask(UNIT_MASK_GUARDIAN))
  4869. ((Guardian*)summon)->InitStatsForLevel(level);
  4870. if (properties && properties->Category == SUMMON_CATEGORY_ALLY)
  4871. summon->setFaction(caster->getFaction());
  4872. if (summon->HasUnitTypeMask(UNIT_MASK_MINION) && m_targets.HasDst())
  4873. ((Minion*)summon)->SetFollowAngle(m_caster->GetAngle(summon));
  4874. if (summon->GetEntry() == 27893)
  4875. {
  4876. if (uint32 weapon = m_caster->GetUInt32Value(PLAYER_VISIBLE_ITEM_16_ENTRYID))
  4877. {
  4878. summon->SetDisplayId(11686); // modelid2
  4879. summon->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, weapon);
  4880. summon->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, caster->GetWeaponDamageRange(BASE_ATTACK, MINDAMAGE));
  4881. summon->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, caster->GetWeaponDamageRange(BASE_ATTACK, MINDAMAGE));
  4882. }
  4883. else
  4884. summon->SetDisplayId(1126); // modelid1
  4885. }
  4886. summon->AI()->EnterEvadeMode();
  4887. ExecuteLogEffectSummonObject(i, summon);
  4888. }
  4889. }
  4890. void Spell::EffectRenamePet(SpellEffIndex /*effIndex*/)
  4891. {
  4892. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4893. return;
  4894. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT ||
  4895. !unitTarget->ToCreature()->IsPet() || ((Pet*)unitTarget)->getPetType() != HUNTER_PET)
  4896. return;
  4897. unitTarget->SetByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
  4898. }
  4899. void Spell::EffectPlayMusic(SpellEffIndex effIndex)
  4900. {
  4901. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4902. return;
  4903. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4904. return;
  4905. uint32 soundid = m_spellInfo->Effects[effIndex].MiscValue;
  4906. if (!sSoundEntriesStore.LookupEntry(soundid))
  4907. {
  4908. TC_LOG_ERROR("spells", "EffectPlayMusic: Sound (Id: %u) not exist in spell %u.", soundid, m_spellInfo->Id);
  4909. return;
  4910. }
  4911. WorldPacket data(SMSG_PLAY_MUSIC, 4);
  4912. data << uint32(soundid);
  4913. unitTarget->ToPlayer()->GetSession()->SendPacket(&data);
  4914. }
  4915. void Spell::EffectSpecCount(SpellEffIndex /*effIndex*/)
  4916. {
  4917. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4918. return;
  4919. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4920. return;
  4921. unitTarget->ToPlayer()->UpdateSpecCount(damage);
  4922. }
  4923. void Spell::EffectActivateSpec(SpellEffIndex /*effIndex*/)
  4924. {
  4925. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4926. return;
  4927. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4928. return;
  4929. unitTarget->ToPlayer()->ActivateSpec(damage-1); // damage is 1 or 2, spec is 0 or 1
  4930. }
  4931. void Spell::EffectPlaySound(SpellEffIndex effIndex)
  4932. {
  4933. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4934. return;
  4935. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  4936. return;
  4937. switch (m_spellInfo->Id)
  4938. {
  4939. case 58730: // Restricted Flight Area
  4940. case 58600: // Restricted Flight Area
  4941. unitTarget->ToPlayer()->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE);
  4942. break;
  4943. default:
  4944. break;
  4945. }
  4946. uint32 soundId = m_spellInfo->Effects[effIndex].MiscValue;
  4947. if (!sSoundEntriesStore.LookupEntry(soundId))
  4948. {
  4949. TC_LOG_ERROR("spells", "EffectPlaySound: Sound (Id: %u) not exist in spell %u.", soundId, m_spellInfo->Id);
  4950. return;
  4951. }
  4952. WorldPacket data(SMSG_PLAY_SOUND, 4);
  4953. data << uint32(soundId);
  4954. unitTarget->ToPlayer()->GetSession()->SendPacket(&data);
  4955. }
  4956. void Spell::EffectRemoveAura(SpellEffIndex effIndex)
  4957. {
  4958. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  4959. return;
  4960. if (!unitTarget)
  4961. return;
  4962. // there may be need of specifying casterguid of removed auras
  4963. unitTarget->RemoveAurasDueToSpell(m_spellInfo->Effects[effIndex].TriggerSpell);
  4964. }
  4965. void Spell::EffectCastButtons(SpellEffIndex effIndex)
  4966. {
  4967. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT)
  4968. return;
  4969. if (m_caster->GetTypeId() != TYPEID_PLAYER)
  4970. return;
  4971. Player* p_caster = m_caster->ToPlayer();
  4972. uint32 button_id = m_spellInfo->Effects[effIndex].MiscValue + 132;
  4973. uint32 n_buttons = m_spellInfo->Effects[effIndex].MiscValueB;
  4974. for (; n_buttons; --n_buttons, ++button_id)
  4975. {
  4976. ActionButton const* ab = p_caster->GetActionButton(button_id);
  4977. if (!ab || ab->GetType() != ACTION_BUTTON_SPELL)
  4978. continue;
  4979. //! Action button data is unverified when it's set so it can be "hacked"
  4980. //! to contain invalid spells, so filter here.
  4981. uint32 spell_id = ab->GetAction();
  4982. if (!spell_id)
  4983. continue;
  4984. SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id);
  4985. if (!spellInfo)
  4986. continue;
  4987. if (!p_caster->HasSpell(spell_id) || p_caster->HasSpellCooldown(spell_id))
  4988. continue;
  4989. if (!(spellInfo->AttributesEx7 & SPELL_ATTR7_SUMMON_PLAYER_TOTEM))
  4990. continue;
  4991. uint32 cost = spellInfo->CalcPowerCost(m_caster, spellInfo->GetSchoolMask());
  4992. if (m_caster->GetPower(POWER_MANA) < cost)
  4993. continue;
  4994. TriggerCastFlags triggerFlags = TriggerCastFlags(TRIGGERED_IGNORE_GCD | TRIGGERED_IGNORE_CAST_IN_PROGRESS | TRIGGERED_CAST_DIRECTLY);
  4995. m_caster->CastSpell(m_caster, spell_id, triggerFlags);
  4996. }
  4997. }
  4998. void Spell::EffectRechargeManaGem(SpellEffIndex /*effIndex*/)
  4999. {
  5000. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  5001. return;
  5002. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  5003. return;
  5004. Player* player = m_caster->ToPlayer();
  5005. if (!player)
  5006. return;
  5007. uint32 item_id = m_spellInfo->Effects[EFFECT_0].ItemType;
  5008. ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(item_id);
  5009. if (!pProto)
  5010. {
  5011. player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL);
  5012. return;
  5013. }
  5014. if (Item* pItem = player->GetItemByEntry(item_id))
  5015. {
  5016. for (int x = 0; x < MAX_ITEM_PROTO_SPELLS; ++x)
  5017. pItem->SetSpellCharges(x, pProto->Spells[x].SpellCharges);
  5018. pItem->SetState(ITEM_CHANGED, player);
  5019. }
  5020. }
  5021. void Spell::EffectBind(SpellEffIndex effIndex)
  5022. {
  5023. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  5024. return;
  5025. if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  5026. return;
  5027. Player* player = unitTarget->ToPlayer();
  5028. WorldLocation homeLoc;
  5029. uint32 areaId = player->GetAreaId();
  5030. if (m_spellInfo->Effects[effIndex].MiscValue)
  5031. areaId = m_spellInfo->Effects[effIndex].MiscValue;
  5032. if (m_targets.HasDst())
  5033. homeLoc.WorldRelocate(*destTarget);
  5034. else
  5035. homeLoc = player->GetWorldLocation();
  5036. player->SetHomebind(homeLoc, areaId);
  5037. // binding
  5038. WorldPacket data(SMSG_BINDPOINTUPDATE, 4 + 4 + 4 + 4 + 4);
  5039. data << float(homeLoc.GetPositionX());
  5040. data << float(homeLoc.GetPositionY());
  5041. data << float(homeLoc.GetPositionZ());
  5042. data << uint32(homeLoc.GetMapId());
  5043. data << uint32(areaId);
  5044. player->SendDirectMessage(&data);
  5045. TC_LOG_DEBUG("spells", "EffectBind: New homebind X: %f, Y: %f, Z: %f, MapId: %u, AreaId: %u",
  5046. homeLoc.GetPositionX(), homeLoc.GetPositionY(), homeLoc.GetPositionZ(), homeLoc.GetMapId(), areaId);
  5047. // zone update
  5048. data.Initialize(SMSG_PLAYERBOUND, 8 + 4);
  5049. data << uint64(m_caster->GetGUID());
  5050. data << uint32(areaId);
  5051. player->SendDirectMessage(&data);
  5052. }
  5053. void Spell::EffectSummonRaFFriend(SpellEffIndex effIndex)
  5054. {
  5055. if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
  5056. return;
  5057. if (m_caster->GetTypeId() != TYPEID_PLAYER || !unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
  5058. return;
  5059. m_caster->CastSpell(unitTarget, m_spellInfo->Effects[effIndex].TriggerSpell, true);
  5060. }