[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / SpellAuras.cpp
blob421fbbb5a3d6495c98bc708a44882dd271ea10a8
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "Opcodes.h"
24 #include "Log.h"
25 #include "UpdateMask.h"
26 #include "World.h"
27 #include "ObjectMgr.h"
28 #include "SpellMgr.h"
29 #include "Player.h"
30 #include "Unit.h"
31 #include "Spell.h"
32 #include "DynamicObject.h"
33 #include "Group.h"
34 #include "UpdateData.h"
35 #include "ObjectAccessor.h"
36 #include "Policies/SingletonImp.h"
37 #include "Totem.h"
38 #include "Creature.h"
39 #include "Formulas.h"
40 #include "BattleGround.h"
41 #include "CreatureAI.h"
42 #include "ScriptCalls.h"
43 #include "Util.h"
44 #include "GridNotifiers.h"
45 #include "GridNotifiersImpl.h"
46 #include "Vehicle.h"
47 #include "CellImpl.h"
49 #define NULL_AURA_SLOT 0xFF
51 pAuraHandler AuraHandler[TOTAL_AURAS]=
53 &Aura::HandleNULL, // 0 SPELL_AURA_NONE
54 &Aura::HandleBindSight, // 1 SPELL_AURA_BIND_SIGHT
55 &Aura::HandleModPossess, // 2 SPELL_AURA_MOD_POSSESS
56 &Aura::HandlePeriodicDamage, // 3 SPELL_AURA_PERIODIC_DAMAGE
57 &Aura::HandleAuraDummy, // 4 SPELL_AURA_DUMMY
58 &Aura::HandleModConfuse, // 5 SPELL_AURA_MOD_CONFUSE
59 &Aura::HandleModCharm, // 6 SPELL_AURA_MOD_CHARM
60 &Aura::HandleModFear, // 7 SPELL_AURA_MOD_FEAR
61 &Aura::HandlePeriodicHeal, // 8 SPELL_AURA_PERIODIC_HEAL
62 &Aura::HandleModAttackSpeed, // 9 SPELL_AURA_MOD_ATTACKSPEED
63 &Aura::HandleModThreat, // 10 SPELL_AURA_MOD_THREAT
64 &Aura::HandleModTaunt, // 11 SPELL_AURA_MOD_TAUNT
65 &Aura::HandleAuraModStun, // 12 SPELL_AURA_MOD_STUN
66 &Aura::HandleModDamageDone, // 13 SPELL_AURA_MOD_DAMAGE_DONE
67 &Aura::HandleNoImmediateEffect, // 14 SPELL_AURA_MOD_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellBaseDamageBonusForVictim
68 &Aura::HandleNoImmediateEffect, // 15 SPELL_AURA_DAMAGE_SHIELD implemented in Unit::DealMeleeDamage
69 &Aura::HandleModStealth, // 16 SPELL_AURA_MOD_STEALTH
70 &Aura::HandleNoImmediateEffect, // 17 SPELL_AURA_MOD_STEALTH_DETECT implemented in Unit::isVisibleForOrDetect
71 &Aura::HandleInvisibility, // 18 SPELL_AURA_MOD_INVISIBILITY
72 &Aura::HandleInvisibilityDetect, // 19 SPELL_AURA_MOD_INVISIBILITY_DETECTION
73 &Aura::HandleAuraModTotalHealthPercentRegen, // 20 SPELL_AURA_OBS_MOD_HEALTH
74 &Aura::HandleAuraModTotalManaPercentRegen, // 21 SPELL_AURA_OBS_MOD_MANA
75 &Aura::HandleAuraModResistance, // 22 SPELL_AURA_MOD_RESISTANCE
76 &Aura::HandlePeriodicTriggerSpell, // 23 SPELL_AURA_PERIODIC_TRIGGER_SPELL
77 &Aura::HandlePeriodicEnergize, // 24 SPELL_AURA_PERIODIC_ENERGIZE
78 &Aura::HandleAuraModPacify, // 25 SPELL_AURA_MOD_PACIFY
79 &Aura::HandleAuraModRoot, // 26 SPELL_AURA_MOD_ROOT
80 &Aura::HandleAuraModSilence, // 27 SPELL_AURA_MOD_SILENCE
81 &Aura::HandleNoImmediateEffect, // 28 SPELL_AURA_REFLECT_SPELLS implement in Unit::SpellHitResult
82 &Aura::HandleAuraModStat, // 29 SPELL_AURA_MOD_STAT
83 &Aura::HandleAuraModSkill, // 30 SPELL_AURA_MOD_SKILL
84 &Aura::HandleAuraModIncreaseSpeed, // 31 SPELL_AURA_MOD_INCREASE_SPEED
85 &Aura::HandleAuraModIncreaseMountedSpeed, // 32 SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
86 &Aura::HandleAuraModDecreaseSpeed, // 33 SPELL_AURA_MOD_DECREASE_SPEED
87 &Aura::HandleAuraModIncreaseHealth, // 34 SPELL_AURA_MOD_INCREASE_HEALTH
88 &Aura::HandleAuraModIncreaseEnergy, // 35 SPELL_AURA_MOD_INCREASE_ENERGY
89 &Aura::HandleAuraModShapeshift, // 36 SPELL_AURA_MOD_SHAPESHIFT
90 &Aura::HandleAuraModEffectImmunity, // 37 SPELL_AURA_EFFECT_IMMUNITY
91 &Aura::HandleAuraModStateImmunity, // 38 SPELL_AURA_STATE_IMMUNITY
92 &Aura::HandleAuraModSchoolImmunity, // 39 SPELL_AURA_SCHOOL_IMMUNITY
93 &Aura::HandleAuraModDmgImmunity, // 40 SPELL_AURA_DAMAGE_IMMUNITY
94 &Aura::HandleAuraModDispelImmunity, // 41 SPELL_AURA_DISPEL_IMMUNITY
95 &Aura::HandleAuraProcTriggerSpell, // 42 SPELL_AURA_PROC_TRIGGER_SPELL implemented in Unit::ProcDamageAndSpellFor and Unit::HandleProcTriggerSpell
96 &Aura::HandleNoImmediateEffect, // 43 SPELL_AURA_PROC_TRIGGER_DAMAGE implemented in Unit::ProcDamageAndSpellFor
97 &Aura::HandleAuraTrackCreatures, // 44 SPELL_AURA_TRACK_CREATURES
98 &Aura::HandleAuraTrackResources, // 45 SPELL_AURA_TRACK_RESOURCES
99 &Aura::HandleUnused, // 46 SPELL_AURA_46 (used in test spells 54054 and 54058, and spell 48050) (3.0.8a-3.2.2a)
100 &Aura::HandleAuraModParryPercent, // 47 SPELL_AURA_MOD_PARRY_PERCENT
101 &Aura::HandleNULL, // 48 SPELL_AURA_48 spell Napalm (area damage spell with additional delayed damage effect)
102 &Aura::HandleAuraModDodgePercent, // 49 SPELL_AURA_MOD_DODGE_PERCENT
103 &Aura::HandleNoImmediateEffect, // 50 SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT implemented in Unit::SpellCriticalHealingBonus
104 &Aura::HandleAuraModBlockPercent, // 51 SPELL_AURA_MOD_BLOCK_PERCENT
105 &Aura::HandleAuraModCritPercent, // 52 SPELL_AURA_MOD_CRIT_PERCENT
106 &Aura::HandlePeriodicLeech, // 53 SPELL_AURA_PERIODIC_LEECH
107 &Aura::HandleModHitChance, // 54 SPELL_AURA_MOD_HIT_CHANCE
108 &Aura::HandleModSpellHitChance, // 55 SPELL_AURA_MOD_SPELL_HIT_CHANCE
109 &Aura::HandleAuraTransform, // 56 SPELL_AURA_TRANSFORM
110 &Aura::HandleModSpellCritChance, // 57 SPELL_AURA_MOD_SPELL_CRIT_CHANCE
111 &Aura::HandleAuraModIncreaseSwimSpeed, // 58 SPELL_AURA_MOD_INCREASE_SWIM_SPEED
112 &Aura::HandleNoImmediateEffect, // 59 SPELL_AURA_MOD_DAMAGE_DONE_CREATURE implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
113 &Aura::HandleAuraModPacifyAndSilence, // 60 SPELL_AURA_MOD_PACIFY_SILENCE
114 &Aura::HandleAuraModScale, // 61 SPELL_AURA_MOD_SCALE
115 &Aura::HandlePeriodicHealthFunnel, // 62 SPELL_AURA_PERIODIC_HEALTH_FUNNEL
116 &Aura::HandleUnused, // 63 unused (3.0.8a-3.2.2a) old SPELL_AURA_PERIODIC_MANA_FUNNEL
117 &Aura::HandlePeriodicManaLeech, // 64 SPELL_AURA_PERIODIC_MANA_LEECH
118 &Aura::HandleModCastingSpeed, // 65 SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
119 &Aura::HandleFeignDeath, // 66 SPELL_AURA_FEIGN_DEATH
120 &Aura::HandleAuraModDisarm, // 67 SPELL_AURA_MOD_DISARM
121 &Aura::HandleAuraModStalked, // 68 SPELL_AURA_MOD_STALKED
122 &Aura::HandleSchoolAbsorb, // 69 SPELL_AURA_SCHOOL_ABSORB implemented in Unit::CalcAbsorbResist
123 &Aura::HandleUnused, // 70 SPELL_AURA_EXTRA_ATTACKS Useless, used by only one spell 41560 that has only visual effect (3.2.2a)
124 &Aura::HandleModSpellCritChanceShool, // 71 SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
125 &Aura::HandleModPowerCostPCT, // 72 SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
126 &Aura::HandleModPowerCost, // 73 SPELL_AURA_MOD_POWER_COST_SCHOOL
127 &Aura::HandleNoImmediateEffect, // 74 SPELL_AURA_REFLECT_SPELLS_SCHOOL implemented in Unit::SpellHitResult
128 &Aura::HandleNoImmediateEffect, // 75 SPELL_AURA_MOD_LANGUAGE implemented in WorldSession::HandleMessagechatOpcode
129 &Aura::HandleFarSight, // 76 SPELL_AURA_FAR_SIGHT
130 &Aura::HandleModMechanicImmunity, // 77 SPELL_AURA_MECHANIC_IMMUNITY
131 &Aura::HandleAuraMounted, // 78 SPELL_AURA_MOUNTED
132 &Aura::HandleModDamagePercentDone, // 79 SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
133 &Aura::HandleModPercentStat, // 80 SPELL_AURA_MOD_PERCENT_STAT
134 &Aura::HandleNoImmediateEffect, // 81 SPELL_AURA_SPLIT_DAMAGE_PCT implemented in Unit::CalcAbsorbResist
135 &Aura::HandleWaterBreathing, // 82 SPELL_AURA_WATER_BREATHING
136 &Aura::HandleModBaseResistance, // 83 SPELL_AURA_MOD_BASE_RESISTANCE
137 &Aura::HandleModRegen, // 84 SPELL_AURA_MOD_REGEN
138 &Aura::HandleModPowerRegen, // 85 SPELL_AURA_MOD_POWER_REGEN
139 &Aura::HandleChannelDeathItem, // 86 SPELL_AURA_CHANNEL_DEATH_ITEM
140 &Aura::HandleNoImmediateEffect, // 87 SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
141 &Aura::HandleNoImmediateEffect, // 88 SPELL_AURA_MOD_HEALTH_REGEN_PERCENT implemented in Player::RegenerateHealth
142 &Aura::HandlePeriodicDamagePCT, // 89 SPELL_AURA_PERIODIC_DAMAGE_PERCENT
143 &Aura::HandleUnused, // 90 unused (3.0.8a-3.2.2a) old SPELL_AURA_MOD_RESIST_CHANCE
144 &Aura::HandleNoImmediateEffect, // 91 SPELL_AURA_MOD_DETECT_RANGE implemented in Creature::GetAttackDistance
145 &Aura::HandlePreventFleeing, // 92 SPELL_AURA_PREVENTS_FLEEING
146 &Aura::HandleModUnattackable, // 93 SPELL_AURA_MOD_UNATTACKABLE
147 &Aura::HandleNoImmediateEffect, // 94 SPELL_AURA_INTERRUPT_REGEN implemented in Player::RegenerateAll
148 &Aura::HandleAuraGhost, // 95 SPELL_AURA_GHOST
149 &Aura::HandleNoImmediateEffect, // 96 SPELL_AURA_SPELL_MAGNET implemented in Unit::SelectMagnetTarget
150 &Aura::HandleManaShield, // 97 SPELL_AURA_MANA_SHIELD implemented in Unit::CalcAbsorbResist
151 &Aura::HandleAuraModSkill, // 98 SPELL_AURA_MOD_SKILL_TALENT
152 &Aura::HandleAuraModAttackPower, // 99 SPELL_AURA_MOD_ATTACK_POWER
153 &Aura::HandleUnused, //100 SPELL_AURA_AURAS_VISIBLE obsolete 3.x? all player can see all auras now, but still have 2 spells including GM-spell (1852,2855)
154 &Aura::HandleModResistancePercent, //101 SPELL_AURA_MOD_RESISTANCE_PCT
155 &Aura::HandleNoImmediateEffect, //102 SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
156 &Aura::HandleAuraModTotalThreat, //103 SPELL_AURA_MOD_TOTAL_THREAT
157 &Aura::HandleAuraWaterWalk, //104 SPELL_AURA_WATER_WALK
158 &Aura::HandleAuraFeatherFall, //105 SPELL_AURA_FEATHER_FALL
159 &Aura::HandleAuraHover, //106 SPELL_AURA_HOVER
160 &Aura::HandleAddModifier, //107 SPELL_AURA_ADD_FLAT_MODIFIER
161 &Aura::HandleAddModifier, //108 SPELL_AURA_ADD_PCT_MODIFIER
162 &Aura::HandleAddTargetTrigger, //109 SPELL_AURA_ADD_TARGET_TRIGGER
163 &Aura::HandleModPowerRegenPCT, //110 SPELL_AURA_MOD_POWER_REGEN_PERCENT
164 &Aura::HandleNoImmediateEffect, //111 SPELL_AURA_ADD_CASTER_HIT_TRIGGER implemented in Unit::SelectMagnetTarget
165 &Aura::HandleNoImmediateEffect, //112 SPELL_AURA_OVERRIDE_CLASS_SCRIPTS implemented in diff functions.
166 &Aura::HandleNoImmediateEffect, //113 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
167 &Aura::HandleNoImmediateEffect, //114 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
168 &Aura::HandleNoImmediateEffect, //115 SPELL_AURA_MOD_HEALING implemented in Unit::SpellBaseHealingBonusForVictim
169 &Aura::HandleNoImmediateEffect, //116 SPELL_AURA_MOD_REGEN_DURING_COMBAT imppemented in Player::RegenerateAll and Player::RegenerateHealth
170 &Aura::HandleNoImmediateEffect, //117 SPELL_AURA_MOD_MECHANIC_RESISTANCE implemented in Unit::MagicSpellHitResult
171 &Aura::HandleNoImmediateEffect, //118 SPELL_AURA_MOD_HEALING_PCT implemented in Unit::SpellHealingBonus
172 &Aura::HandleUnused, //119 unused (3.0.8a-3.2.2a) old SPELL_AURA_SHARE_PET_TRACKING
173 &Aura::HandleAuraUntrackable, //120 SPELL_AURA_UNTRACKABLE
174 &Aura::HandleAuraEmpathy, //121 SPELL_AURA_EMPATHY
175 &Aura::HandleModOffhandDamagePercent, //122 SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT
176 &Aura::HandleModTargetResistance, //123 SPELL_AURA_MOD_TARGET_RESISTANCE
177 &Aura::HandleAuraModRangedAttackPower, //124 SPELL_AURA_MOD_RANGED_ATTACK_POWER
178 &Aura::HandleNoImmediateEffect, //125 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
179 &Aura::HandleNoImmediateEffect, //126 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
180 &Aura::HandleNoImmediateEffect, //127 SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
181 &Aura::HandleModPossessPet, //128 SPELL_AURA_MOD_POSSESS_PET
182 &Aura::HandleAuraModIncreaseSpeed, //129 SPELL_AURA_MOD_SPEED_ALWAYS
183 &Aura::HandleAuraModIncreaseMountedSpeed, //130 SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
184 &Aura::HandleNoImmediateEffect, //131 SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
185 &Aura::HandleAuraModIncreaseEnergyPercent, //132 SPELL_AURA_MOD_INCREASE_ENERGY_PERCENT
186 &Aura::HandleAuraModIncreaseHealthPercent, //133 SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT
187 &Aura::HandleAuraModRegenInterrupt, //134 SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
188 &Aura::HandleModHealingDone, //135 SPELL_AURA_MOD_HEALING_DONE
189 &Aura::HandleNoImmediateEffect, //136 SPELL_AURA_MOD_HEALING_DONE_PERCENT implemented in Unit::SpellHealingBonus
190 &Aura::HandleModTotalPercentStat, //137 SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE
191 &Aura::HandleHaste, //138 SPELL_AURA_MOD_HASTE
192 &Aura::HandleForceReaction, //139 SPELL_AURA_FORCE_REACTION
193 &Aura::HandleAuraModRangedHaste, //140 SPELL_AURA_MOD_RANGED_HASTE
194 &Aura::HandleRangedAmmoHaste, //141 SPELL_AURA_MOD_RANGED_AMMO_HASTE
195 &Aura::HandleAuraModBaseResistancePCT, //142 SPELL_AURA_MOD_BASE_RESISTANCE_PCT
196 &Aura::HandleAuraModResistanceExclusive, //143 SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE
197 &Aura::HandleAuraSafeFall, //144 SPELL_AURA_SAFE_FALL implemented in WorldSession::HandleMovementOpcodes
198 &Aura::HandleAuraModPetTalentsPoints, //145 SPELL_AURA_MOD_PET_TALENT_POINTS
199 &Aura::HandleNoImmediateEffect, //146 SPELL_AURA_ALLOW_TAME_PET_TYPE implemented in Player::CanTameExoticPets
200 &Aura::HandleModMechanicImmunityMask, //147 SPELL_AURA_MECHANIC_IMMUNITY_MASK implemented in Unit::IsImmunedToSpell and Unit::IsImmunedToSpellEffect (check part)
201 &Aura::HandleAuraRetainComboPoints, //148 SPELL_AURA_RETAIN_COMBO_POINTS
202 &Aura::HandleNoImmediateEffect, //149 SPELL_AURA_REDUCE_PUSHBACK implemented in Spell::Delayed and Spell::DelayedChannel
203 &Aura::HandleShieldBlockValue, //150 SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT
204 &Aura::HandleAuraTrackStealthed, //151 SPELL_AURA_TRACK_STEALTHED
205 &Aura::HandleNoImmediateEffect, //152 SPELL_AURA_MOD_DETECTED_RANGE implemented in Creature::GetAttackDistance
206 &Aura::HandleNoImmediateEffect, //153 SPELL_AURA_SPLIT_DAMAGE_FLAT implemented in Unit::CalcAbsorbResist
207 &Aura::HandleNoImmediateEffect, //154 SPELL_AURA_MOD_STEALTH_LEVEL implemented in Unit::isVisibleForOrDetect
208 &Aura::HandleNoImmediateEffect, //155 SPELL_AURA_MOD_WATER_BREATHING implemented in Player::getMaxTimer
209 &Aura::HandleNoImmediateEffect, //156 SPELL_AURA_MOD_REPUTATION_GAIN implemented in Player::CalculateReputationGain
210 &Aura::HandleUnused, //157 SPELL_AURA_PET_DAMAGE_MULTI (single test like spell 20782, also single for 214 aura)
211 &Aura::HandleShieldBlockValue, //158 SPELL_AURA_MOD_SHIELD_BLOCKVALUE
212 &Aura::HandleNoImmediateEffect, //159 SPELL_AURA_NO_PVP_CREDIT implemented in Player::RewardHonor
213 &Aura::HandleNoImmediateEffect, //160 SPELL_AURA_MOD_AOE_AVOIDANCE implemented in Unit::MagicSpellHitResult
214 &Aura::HandleNoImmediateEffect, //161 SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT implemented in Player::RegenerateAll and Player::RegenerateHealth
215 &Aura::HandleAuraPowerBurn, //162 SPELL_AURA_POWER_BURN_MANA
216 &Aura::HandleNoImmediateEffect, //163 SPELL_AURA_MOD_CRIT_DAMAGE_BONUS implemented in Unit::CalculateMeleeDamage and Unit::SpellCriticalDamageBonus
217 &Aura::HandleUnused, //164 unused (3.0.8a-3.2.2a), only one test spell 10654
218 &Aura::HandleNoImmediateEffect, //165 SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
219 &Aura::HandleAuraModAttackPowerPercent, //166 SPELL_AURA_MOD_ATTACK_POWER_PCT
220 &Aura::HandleAuraModRangedAttackPowerPercent, //167 SPELL_AURA_MOD_RANGED_ATTACK_POWER_PCT
221 &Aura::HandleNoImmediateEffect, //168 SPELL_AURA_MOD_DAMAGE_DONE_VERSUS implemented in Unit::SpellDamageBonus, Unit::MeleeDamageBonus
222 &Aura::HandleNoImmediateEffect, //169 SPELL_AURA_MOD_CRIT_PERCENT_VERSUS implemented in Unit::DealDamageBySchool, Unit::DoAttackDamage, Unit::SpellCriticalBonus
223 &Aura::HandleNULL, //170 SPELL_AURA_DETECT_AMORE different spells that ignore transformation effects
224 &Aura::HandleAuraModIncreaseSpeed, //171 SPELL_AURA_MOD_SPEED_NOT_STACK
225 &Aura::HandleAuraModIncreaseMountedSpeed, //172 SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
226 &Aura::HandleUnused, //173 unused (3.0.8a-3.2.2a) no spells, old SPELL_AURA_ALLOW_CHAMPION_SPELLS only for Proclaim Champion spell
227 &Aura::HandleModSpellDamagePercentFromStat, //174 SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT implemented in Unit::SpellBaseDamageBonus
228 &Aura::HandleModSpellHealingPercentFromStat, //175 SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT implemented in Unit::SpellBaseHealingBonus
229 &Aura::HandleSpiritOfRedemption, //176 SPELL_AURA_SPIRIT_OF_REDEMPTION only for Spirit of Redemption spell, die at aura end
230 &Aura::HandleNULL, //177 SPELL_AURA_AOE_CHARM (22 spells)
231 &Aura::HandleNoImmediateEffect, //178 SPELL_AURA_MOD_DEBUFF_RESISTANCE implemented in Unit::MagicSpellHitResult
232 &Aura::HandleNoImmediateEffect, //179 SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE implemented in Unit::SpellCriticalBonus
233 &Aura::HandleNoImmediateEffect, //180 SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS implemented in Unit::SpellDamageBonus
234 &Aura::HandleUnused, //181 unused (3.0.8a-3.2.2a) old SPELL_AURA_MOD_FLAT_SPELL_CRIT_DAMAGE_VERSUS
235 &Aura::HandleAuraModResistenceOfStatPercent, //182 SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT
236 &Aura::HandleNoImmediateEffect, //183 SPELL_AURA_MOD_CRITICAL_THREAT only used in 28746, implemented in ThreatCalcHelper::calcThreat
237 &Aura::HandleNoImmediateEffect, //184 SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
238 &Aura::HandleNoImmediateEffect, //185 SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
239 &Aura::HandleNoImmediateEffect, //186 SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE implemented in Unit::MagicSpellHitResult
240 &Aura::HandleNoImmediateEffect, //187 SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE implemented in Unit::GetUnitCriticalChance
241 &Aura::HandleNoImmediateEffect, //188 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE implemented in Unit::GetUnitCriticalChance
242 &Aura::HandleModRating, //189 SPELL_AURA_MOD_RATING
243 &Aura::HandleNoImmediateEffect, //190 SPELL_AURA_MOD_FACTION_REPUTATION_GAIN implemented in Player::CalculateReputationGain
244 &Aura::HandleAuraModUseNormalSpeed, //191 SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
245 &Aura::HandleModMeleeRangedSpeedPct, //192 SPELL_AURA_HASTE_MELEE
246 &Aura::HandleModCombatSpeedPct, //193 SPELL_AURA_MELEE_SLOW (in fact combat (any type attack) speed pct)
247 &Aura::HandleNoImmediateEffect, //194 SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL implement in Unit::CalcNotIgnoreAbsorbDamage
248 &Aura::HandleNoImmediateEffect, //195 SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL implement in Unit::CalcNotIgnoreAbsorbDamage
249 &Aura::HandleNULL, //196 SPELL_AURA_MOD_COOLDOWN (single spell 24818 in 3.2.2a)
250 &Aura::HandleNoImmediateEffect, //197 SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE implemented in Unit::SpellCriticalBonus Unit::GetUnitCriticalChance
251 &Aura::HandleUnused, //198 unused (3.0.8a-3.2.2a) old SPELL_AURA_MOD_ALL_WEAPON_SKILLS
252 &Aura::HandleNoImmediateEffect, //199 SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT implemented in Unit::MagicSpellHitResult
253 &Aura::HandleNoImmediateEffect, //200 SPELL_AURA_MOD_KILL_XP_PCT implemented in Player::GiveXP
254 &Aura::HandleAuraAllowFlight, //201 SPELL_AURA_FLY this aura enable flight mode...
255 &Aura::HandleNoImmediateEffect, //202 SPELL_AURA_CANNOT_BE_DODGED implemented in Unit::RollPhysicalOutcomeAgainst
256 &Aura::HandleNoImmediateEffect, //203 SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE implemented in Unit::CalculateMeleeDamage and Unit::SpellCriticalDamageBonus
257 &Aura::HandleNoImmediateEffect, //204 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE implemented in Unit::CalculateMeleeDamage and Unit::SpellCriticalDamageBonus
258 &Aura::HandleNoImmediateEffect, //205 SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE implemented in Unit::SpellCriticalDamageBonus
259 &Aura::HandleNULL, //206 SPELL_AURA_MOD_SPEED_MOUNTED
260 &Aura::HandleAuraModIncreaseFlightSpeed, //207 SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
261 &Aura::HandleAuraModIncreaseFlightSpeed, //208 SPELL_AURA_MOD_SPEED_FLIGHT, used only in spell: Flight Form (Passive)
262 &Aura::HandleAuraModIncreaseFlightSpeed, //209 SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
263 &Aura::HandleNULL, //210 "Increase flight speed by"
264 &Aura::HandleAuraModIncreaseFlightSpeed, //211 SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
265 &Aura::HandleAuraModRangedAttackPowerOfStatPercent, //212 SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT
266 &Aura::HandleNoImmediateEffect, //213 SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT implemented in Player::RewardRage
267 &Aura::HandleUnused, //214 Tamed Pet Passive (single test like spell 20782, also single for 157 aura)
268 &Aura::HandleArenaPreparation, //215 SPELL_AURA_ARENA_PREPARATION
269 &Aura::HandleModCastingSpeed, //216 SPELL_AURA_HASTE_SPELLS
270 &Aura::HandleUnused, //217 unused (3.0.8a-3.2.2a)
271 &Aura::HandleAuraModRangedHaste, //218 SPELL_AURA_HASTE_RANGED
272 &Aura::HandleModManaRegen, //219 SPELL_AURA_MOD_MANA_REGEN_FROM_STAT
273 &Aura::HandleModRatingFromStat, //220 SPELL_AURA_MOD_RATING_FROM_STAT
274 &Aura::HandleNULL, //221 ignored
275 &Aura::HandleUnused, //222 unused (3.0.8a-3.2.2a) only for spell 44586 that not used in real spell cast
276 &Aura::HandleNULL, //223 dummy code (cast damage spell to attacker) and another dymmy (jump to another nearby raid member)
277 &Aura::HandleUnused, //224 unused (3.0.8a-3.2.2a)
278 &Aura::HandleNoImmediateEffect, //225 SPELL_AURA_PRAYER_OF_MENDING
279 &Aura::HandleAuraPeriodicDummy, //226 SPELL_AURA_PERIODIC_DUMMY
280 &Aura::HandlePeriodicTriggerSpellWithValue, //227 SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE
281 &Aura::HandleNoImmediateEffect, //228 SPELL_AURA_DETECT_STEALTH
282 &Aura::HandleNoImmediateEffect, //229 SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE implemented in Unit::SpellDamageBonus
283 &Aura::HandleAuraModIncreaseMaxHealth, //230 Commanding Shout
284 &Aura::HandleNoImmediateEffect, //231 SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
285 &Aura::HandleNoImmediateEffect, //232 SPELL_AURA_MECHANIC_DURATION_MOD implement in Unit::CalculateSpellDuration
286 &Aura::HandleNULL, //233 set model id to the one of the creature with id m_modifier.m_miscvalue
287 &Aura::HandleNoImmediateEffect, //234 SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK implement in Unit::CalculateSpellDuration
288 &Aura::HandleAuraModDispelResist, //235 SPELL_AURA_MOD_DISPEL_RESIST implement in Unit::MagicSpellHitResult
289 &Aura::HandleAuraControlVehicle, //236 SPELL_AURA_CONTROL_VEHICLE
290 &Aura::HandleModSpellDamagePercentFromAttackPower, //237 SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER implemented in Unit::SpellBaseDamageBonus
291 &Aura::HandleModSpellHealingPercentFromAttackPower, //238 SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER implemented in Unit::SpellBaseHealingBonus
292 &Aura::HandleAuraModScale, //239 SPELL_AURA_MOD_SCALE_2 only in Noggenfogger Elixir (16595) before 2.3.0 aura 61
293 &Aura::HandleAuraModExpertise, //240 SPELL_AURA_MOD_EXPERTISE
294 &Aura::HandleForceMoveForward, //241 Forces the player to move forward
295 &Aura::HandleUnused, //242 SPELL_AURA_MOD_SPELL_DAMAGE_FROM_HEALING (only 2 test spels in 3.2.2a)
296 &Aura::HandleNULL, //243 faction reaction override spells
297 &Aura::HandleComprehendLanguage, //244 SPELL_AURA_COMPREHEND_LANGUAGE
298 &Aura::HandleNoImmediateEffect, //245 SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS implemented in Unit::CalculateSpellDuration
299 &Aura::HandleNoImmediateEffect, //246 SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL implemented in Unit::CalculateSpellDuration
300 &Aura::HandleNULL, //247 target to become a clone of the caster
301 &Aura::HandleNoImmediateEffect, //248 SPELL_AURA_MOD_COMBAT_RESULT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
302 &Aura::HandleAuraConvertRune, //249 SPELL_AURA_CONVERT_RUNE
303 &Aura::HandleAuraModIncreaseHealth, //250 SPELL_AURA_MOD_INCREASE_HEALTH_2
304 &Aura::HandleNULL, //251 SPELL_AURA_MOD_ENEMY_DODGE
305 &Aura::HandleNULL, //252 haste all?
306 &Aura::HandleNULL, //253 SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
307 &Aura::HandleNULL, //254 SPELL_AURA_MOD_DISARM_SHIELD disarm Shield
308 &Aura::HandleNoImmediateEffect, //255 SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT implemented in Unit::SpellDamageBonus
309 &Aura::HandleNoReagentUseAura, //256 SPELL_AURA_NO_REAGENT_USE Use SpellClassMask for spell select
310 &Aura::HandleNULL, //257 SPELL_AURA_MOD_TARGET_RESIST_BY_SPELL_CLASS Use SpellClassMask for spell select
311 &Aura::HandleNULL, //258 SPELL_AURA_MOD_SPELL_VISUAL
312 &Aura::HandleNULL, //259 corrupt healing over time spell
313 &Aura::HandleNoImmediateEffect, //260 SPELL_AURA_SCREEN_EFFECT (miscvalue = id in ScreenEffect.dbc) not required any code
314 &Aura::HandlePhase, //261 SPELL_AURA_PHASE undetectable invisibility? implemented in Unit::isVisibleForOrDetect
315 &Aura::HandleNULL, //262 ignore combat/aura state?
316 &Aura::HandleAllowOnlyAbility, //263 SPELL_AURA_ALLOW_ONLY_ABILITY player can use only abilities set in SpellClassMask
317 &Aura::HandleUnused, //264 unused (3.0.8a-3.2.2a)
318 &Aura::HandleUnused, //265 unused (3.0.8a-3.2.2a)
319 &Aura::HandleUnused, //266 unused (3.0.8a-3.2.2a)
320 &Aura::HandleNoImmediateEffect, //267 SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL implemented in Unit::IsImmunedToSpellEffect
321 &Aura::HandleAuraModAttackPowerOfStatPercent, //268 SPELL_AURA_MOD_ATTACK_POWER_OF_STAT_PERCENT
322 &Aura::HandleNoImmediateEffect, //269 SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL implemented in Unit::CalcNotIgnoreDamageRedunction
323 &Aura::HandleUnused, //270 SPELL_AURA_MOD_IGNORE_TARGET_RESIST (unused in 3.2.2a)
324 &Aura::HandleNoImmediateEffect, //271 SPELL_AURA_MOD_DAMAGE_FROM_CASTER implemented in Unit::SpellDamageBonus
325 &Aura::HandleNoImmediateEffect, //272 SPELL_AURA_MAELSTROM_WEAPON (unclear use for aura, it used in (3.2.2a...3.3.0) in single spell 53817 that spellmode stacked and charged spell expected to be drop as stack
326 &Aura::HandleNoImmediateEffect, //273 SPELL_AURA_X_RAY (client side implementation)
327 &Aura::HandleNULL, //274 proc free shot?
328 &Aura::HandleNoImmediateEffect, //275 SPELL_AURA_MOD_IGNORE_SHAPESHIFT Use SpellClassMask for spell select
329 &Aura::HandleNULL, //276 mod damage % mechanic?
330 &Aura::HandleNoImmediateEffect, //277 SPELL_AURA_MOD_MAX_AFFECTED_TARGETS Use SpellClassMask for spell select
331 &Aura::HandleNULL, //278 SPELL_AURA_MOD_DISARM_RANGED disarm ranged weapon
332 &Aura::HandleNULL, //279 visual effects? 58836 and 57507
333 &Aura::HandleModTargetArmorPct, //280 SPELL_AURA_MOD_TARGET_ARMOR_PCT
334 &Aura::HandleNoImmediateEffect, //281 SPELL_AURA_MOD_HONOR_GAIN implemented in Player::RewardHonor
335 &Aura::HandleAuraIncreaseBaseHealthPercent, //282 SPELL_AURA_INCREASE_BASE_HEALTH_PERCENT
336 &Aura::HandleNoImmediateEffect, //283 SPELL_AURA_MOD_HEALING_RECEIVED implemented in Unit::SpellHealingBonus
337 &Aura::HandleNULL, //284 51 spells
338 &Aura::HandleAuraModAttackPowerOfArmor, //285 SPELL_AURA_MOD_ATTACK_POWER_OF_ARMOR implemented in Player::UpdateAttackPowerAndDamage
339 &Aura::HandleNoImmediateEffect, //286 SPELL_AURA_ABILITY_PERIODIC_CRIT implemented in Aura::IsCritFromAbilityAura called from Aura::PeriodicTick
340 &Aura::HandleNoImmediateEffect, //287 SPELL_AURA_DEFLECT_SPELLS implemented in Unit::MagicSpellHitResult and Unit::MeleeSpellHitResult
341 &Aura::HandleNULL, //288 increase parry/deflect, prevent attack (single spell used 67801)
342 &Aura::HandleUnused, //289 unused (3.2.2a)
343 &Aura::HandleAuraModAllCritChance, //290 SPELL_AURA_MOD_ALL_CRIT_CHANCE
344 &Aura::HandleNoImmediateEffect, //291 SPELL_AURA_MOD_QUEST_XP_PCT implemented in Player::GiveXP
345 &Aura::HandleNULL, //292 call stabled pet
346 &Aura::HandleNULL, //293 3 spells
347 &Aura::HandleNULL, //294 2 spells, possible prevent mana regen
348 &Aura::HandleUnused, //295 unused (3.2.2a)
349 &Aura::HandleNULL, //296 2 spells
350 &Aura::HandleNULL, //297 1 spell (counter spell school?)
351 &Aura::HandleUnused, //298 unused (3.2.2a)
352 &Aura::HandleUnused, //299 unused (3.2.2a)
353 &Aura::HandleNULL, //300 3 spells (share damage?)
354 &Aura::HandleNULL, //301 5 spells
355 &Aura::HandleUnused, //302 unused (3.2.2a)
356 &Aura::HandleNULL, //303 17 spells
357 &Aura::HandleNULL, //304 2 spells (alcohol effect?)
358 &Aura::HandleAuraModIncreaseSpeed, //305 SPELL_AURA_MOD_MINIMUM_SPEED
359 &Aura::HandleNULL, //306 1 spell
360 &Aura::HandleNULL, //307 absorb healing?
361 &Aura::HandleNULL, //308 new aura for hunter traps
362 &Aura::HandleNULL, //309 absorb healing?
363 &Aura::HandleNULL, //310 pet avoidance passive?
364 &Aura::HandleNULL, //311 0 spells in 3.3
365 &Aura::HandleNULL, //312 0 spells in 3.3
366 &Aura::HandleNULL, //313 0 spells in 3.3
367 &Aura::HandleNULL, //314 1 test spell (reduce duration of silince/magic)
368 &Aura::HandleNULL, //315 underwater walking
369 &Aura::HandleNULL //316 makes haste affect HOT/DOT ticks
372 static AuraType const frozenAuraTypes[] = { SPELL_AURA_MOD_ROOT, SPELL_AURA_MOD_STUN, SPELL_AURA_NONE };
374 Aura::Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem) :
375 m_spellmod(NULL), m_caster_guid(0), m_target(target), m_castItemGuid(castItem?castItem->GetGUID():0),
376 m_timeCla(1000), m_periodicTimer(0), m_periodicTick(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE),
377 m_effIndex(eff), m_auraSlot(MAX_AURAS), m_auraFlags(AFLAG_NONE), m_auraLevel(1), m_procCharges(0), m_stackAmount(1),
378 m_positive(false), m_permanent(false), m_isPeriodic(false), m_isAreaAura(false), m_isPersistent(false),
379 m_isRemovedOnShapeLost(true), m_in_use(0), m_deleted(false)
381 assert(target);
383 assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
385 m_spellProto = spellproto;
387 m_currentBasePoints = currentBasePoints ? *currentBasePoints : m_spellProto->EffectBasePoints[eff];
389 m_isPassive = IsPassiveSpell(GetId());
390 m_positive = IsPositiveEffect(GetId(), m_effIndex);
392 m_isSingleTargetAura = IsSingleTargetSpell(m_spellProto);
394 m_applyTime = time(NULL);
396 int32 damage;
397 if(!caster)
399 m_caster_guid = target->GetGUID();
400 damage = m_currentBasePoints+1; // stored value-1
401 m_maxduration = target->CalculateSpellDuration(m_spellProto, m_effIndex, target);
403 else
405 m_caster_guid = caster->GetGUID();
407 damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target);
408 m_maxduration = caster->CalculateSpellDuration(m_spellProto, m_effIndex, target);
410 if (!damage && castItem && castItem->GetItemSuffixFactor())
412 ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
413 if(item_rand_suffix)
415 for (int k = 0; k < 3; ++k)
417 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand_suffix->enchant_id[k]);
418 if(pEnchant)
420 for (int t = 0; t < 3; ++t)
421 if(pEnchant->spellid[t] == m_spellProto->Id)
423 damage = uint32((item_rand_suffix->prefix[k]*castItem->GetItemSuffixFactor()) / 10000 );
424 break;
428 if(damage)
429 break;
435 if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0)
436 m_permanent = true;
438 Player* modOwner = caster ? caster->GetSpellModOwner() : NULL;
440 if(!m_permanent && modOwner)
442 modOwner->ApplySpellMod(GetId(), SPELLMOD_DURATION, m_maxduration);
443 // Get zero duration aura after - need set m_maxduration > 0 for apply/remove aura work
444 if (m_maxduration<=0)
445 m_maxduration = 1;
448 m_duration = m_maxduration;
450 sLog.outDebug("Aura: construct Spellid : %u, Aura : %u Duration : %d Target : %d Damage : %d", m_spellProto->Id, m_spellProto->EffectApplyAuraName[eff], m_maxduration, m_spellProto->EffectImplicitTargetA[eff],damage);
452 m_effIndex = eff;
453 SetModifier(AuraType(m_spellProto->EffectApplyAuraName[eff]), damage, m_spellProto->EffectAmplitude[eff], m_spellProto->EffectMiscValue[eff]);
455 // Apply periodic time mod
456 if(modOwner && m_modifier.periodictime)
457 modOwner->ApplySpellMod(GetId(), SPELLMOD_ACTIVATION_TIME, m_modifier.periodictime);
459 // Start periodic on next tick or at aura apply
460 if (!(m_spellProto->AttributesEx5 & SPELL_ATTR_EX5_START_PERIODIC_AT_APPLY))
461 m_periodicTimer += m_modifier.periodictime;
463 m_isDeathPersist = IsDeathPersistentSpell(m_spellProto);
465 m_procCharges = m_spellProto->procCharges;
466 if(modOwner)
467 modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
469 m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() &&
470 m_spellProto->Stances &&
471 !(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) &&
472 !(m_spellProto->Attributes & SPELL_ATTR_NOT_SHAPESHIFT));
474 if (caster && m_spellProto->Id == 22959) // Improved Scorch
476 // Glyph of Improved Scorch
477 if (Aura* glyph = caster->GetDummyAura(56371))
478 m_stackAmount = glyph->GetModifier()->m_amount;
482 Aura::~Aura()
486 AreaAura::AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
487 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
489 m_isAreaAura = true;
491 // caster==NULL in constructor args if target==caster in fact
492 Unit* caster_ptr = caster ? caster : target;
494 m_radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
495 if(Player* modOwner = caster_ptr->GetSpellModOwner())
496 modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
498 switch(spellproto->Effect[eff])
500 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
501 m_areaAuraType = AREA_AURA_PARTY;
502 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
503 m_modifier.m_auraname = SPELL_AURA_NONE;
504 break;
505 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
506 m_areaAuraType = AREA_AURA_RAID;
507 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
508 m_modifier.m_auraname = SPELL_AURA_NONE;
509 // Light's Beacon not applied to caster itself (TODO: more generic check for another simialr spell if any?)
510 else if (target == caster_ptr && m_spellProto->Id == 53651)
511 m_modifier.m_auraname = SPELL_AURA_NONE;
512 break;
513 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
514 m_areaAuraType = AREA_AURA_FRIEND;
515 break;
516 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
517 m_areaAuraType = AREA_AURA_ENEMY;
518 if (target == caster_ptr)
519 m_modifier.m_auraname = SPELL_AURA_NONE; // Do not do any effect on self
520 break;
521 case SPELL_EFFECT_APPLY_AREA_AURA_PET:
522 m_areaAuraType = AREA_AURA_PET;
523 break;
524 case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
525 m_areaAuraType = AREA_AURA_OWNER;
526 if (target == caster_ptr)
527 m_modifier.m_auraname = SPELL_AURA_NONE;
528 break;
529 default:
530 sLog.outError("Wrong spell effect in AreaAura constructor");
531 ASSERT(false);
532 break;
536 AreaAura::~AreaAura()
540 PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
541 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
543 m_isPersistent = true;
546 PersistentAreaAura::~PersistentAreaAura()
550 SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
551 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
553 if (caster)
554 m_casters_target_guid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelection() : caster->GetTargetGUID();
555 else
556 m_casters_target_guid = 0;
559 SingleEnemyTargetAura::~SingleEnemyTargetAura()
563 Unit* SingleEnemyTargetAura::GetTriggerTarget() const
565 return ObjectAccessor::GetUnit(*m_target, m_casters_target_guid);
568 Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem)
570 if (IsAreaAuraEffect(spellproto->Effect[eff]))
571 return new AreaAura(spellproto, eff, currentBasePoints, target, caster, castItem);
573 uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff];
575 if(SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
576 for (int i = 0; i < 3; ++i)
577 if (triggeredSpellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_ENEMY)
578 return new SingleEnemyTargetAura(spellproto, eff, currentBasePoints, target, caster, castItem);
580 return new Aura(spellproto, eff, currentBasePoints, target, caster, castItem);
583 Unit* Aura::GetCaster() const
585 if(m_caster_guid == m_target->GetGUID())
586 return m_target;
588 //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
589 //must return caster even if it's in another grid/map
590 Unit *unit = ObjectAccessor::GetUnitInWorld(*m_target,m_caster_guid);
591 return unit && unit->IsInWorld() ? unit : NULL;
594 void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
596 m_modifier.m_auraname = t;
597 m_modifier.m_amount = a;
598 m_modifier.m_miscvalue = miscValue;
599 m_modifier.periodictime = pt;
602 void Aura::Update(uint32 diff)
604 if (m_duration > 0)
606 m_duration -= diff;
607 if (m_duration < 0)
608 m_duration = 0;
609 m_timeCla -= diff;
611 // GetEffIndex()==0 prevent double/triple apply manaPerSecond/manaPerSecondPerLevel to same spell with many auras
612 // all spells with manaPerSecond/manaPerSecondPerLevel have aura in effect 0
613 if(GetEffIndex()==0 && m_timeCla <= 0)
615 if(Unit* caster = GetCaster())
617 Powers powertype = Powers(m_spellProto->powerType);
618 int32 manaPerSecond = m_spellProto->manaPerSecond + m_spellProto->manaPerSecondPerLevel * caster->getLevel();
619 m_timeCla = 1*IN_MILISECONDS;
620 if (manaPerSecond)
622 if(powertype==POWER_HEALTH)
623 caster->ModifyHealth(-manaPerSecond);
624 else
625 caster->ModifyPower(powertype,-manaPerSecond);
631 // Channeled aura required check distance from caster
632 if(IsChanneledSpell(m_spellProto) && m_caster_guid != m_target->GetGUID())
634 Unit* caster = GetCaster();
635 if(!caster)
637 m_target->RemoveAura(GetId(), GetEffIndex());
638 return;
641 // need check distance for channeled target only
642 if (caster->GetChannelObjectGUID() == m_target->GetGUID())
644 // Get spell range
645 float max_range = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellProto->rangeIndex));
647 if(Player* modOwner = caster->GetSpellModOwner())
648 modOwner->ApplySpellMod(GetId(), SPELLMOD_RANGE, max_range, NULL);
650 if(!caster->IsWithinDistInMap(m_target, max_range))
652 m_target->RemoveAura(GetId(), GetEffIndex());
653 return;
658 if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
660 m_periodicTimer -= diff;
661 if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
663 // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls)
664 m_periodicTimer += m_modifier.periodictime;
665 ++m_periodicTick; // for some infinity auras in some cases can overflow and reset
666 PeriodicTick();
671 void AreaAura::Update(uint32 diff)
673 // update for the caster of the aura
674 if(m_caster_guid == m_target->GetGUID())
676 Unit* caster = m_target;
678 if( !caster->hasUnitState(UNIT_STAT_ISOLATED) )
680 Unit* owner = caster->GetCharmerOrOwner();
681 if (!owner)
682 owner = caster;
683 std::list<Unit *> targets;
685 switch(m_areaAuraType)
687 case AREA_AURA_PARTY:
689 Group *pGroup = NULL;
691 if (owner->GetTypeId() == TYPEID_PLAYER)
692 pGroup = ((Player*)owner)->GetGroup();
694 if( pGroup)
696 uint8 subgroup = ((Player*)owner)->GetSubGroup();
697 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
699 Player* Target = itr->getSource();
700 if(Target && Target->isAlive() && Target->GetSubGroup()==subgroup && caster->IsFriendlyTo(Target))
702 if(caster->IsWithinDistInMap(Target, m_radius))
703 targets.push_back(Target);
704 Pet *pet = Target->GetPet();
705 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
706 targets.push_back(pet);
710 else
712 // add owner
713 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
714 targets.push_back(owner);
715 // add caster's pet
716 Unit* pet = caster->GetPet();
717 if( pet && caster->IsWithinDistInMap(pet, m_radius))
718 targets.push_back(pet);
720 break;
722 case AREA_AURA_RAID:
724 Group *pGroup = NULL;
726 if (owner->GetTypeId() == TYPEID_PLAYER)
727 pGroup = ((Player*)owner)->GetGroup();
729 if( pGroup)
731 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
733 Player* Target = itr->getSource();
734 if(Target && Target->isAlive() && caster->IsFriendlyTo(Target))
736 if(caster->IsWithinDistInMap(Target, m_radius))
737 targets.push_back(Target);
738 Pet *pet = Target->GetPet();
739 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
740 targets.push_back(pet);
744 else
746 // add owner
747 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
748 targets.push_back(owner);
749 // add caster's pet
750 Unit* pet = caster->GetPet();
751 if( pet && caster->IsWithinDistInMap(pet, m_radius))
752 targets.push_back(pet);
754 break;
756 case AREA_AURA_FRIEND:
758 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
759 Cell cell(p);
760 cell.data.Part.reserved = ALL_DISTRICT;
761 cell.SetNoCreate();
763 MaNGOS::AnyFriendlyUnitInObjectRangeCheck u_check(caster, owner, m_radius);
764 MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck> searcher(caster,targets, u_check);
765 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
766 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
767 cell.Visit(p, world_unit_searcher, *caster->GetMap(), *caster, m_radius);
768 cell.Visit(p, grid_unit_searcher, *caster->GetMap(), *caster, m_radius);
769 break;
771 case AREA_AURA_ENEMY:
773 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
774 Cell cell(p);
775 cell.data.Part.reserved = ALL_DISTRICT;
776 cell.SetNoCreate();
778 MaNGOS::AnyAoETargetUnitInObjectRangeCheck u_check(caster, owner, m_radius); // No GetCharmer in searcher
779 MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck> searcher(caster, targets, u_check);
780 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
781 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
782 cell.Visit(p, world_unit_searcher, *caster->GetMap(), *caster, m_radius);
783 cell.Visit(p, grid_unit_searcher, *caster->GetMap(), *caster, m_radius);
784 break;
786 case AREA_AURA_OWNER:
787 case AREA_AURA_PET:
789 if(owner != caster && caster->IsWithinDistInMap(owner, m_radius))
790 targets.push_back(owner);
791 break;
795 for(std::list<Unit *>::iterator tIter = targets.begin(); tIter != targets.end(); tIter++)
797 // flag for seelction is need apply aura to current iteration target
798 bool apply = true;
800 // we need ignore present caster self applied are auras sometime
801 // in cases if this only auras applied for spell effect
802 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), m_effIndex);
803 for(Unit::AuraMap::const_iterator i = (*tIter)->GetAuras().lower_bound(spair); i != (*tIter)->GetAuras().upper_bound(spair); ++i)
805 if (i->second->IsDeleted())
806 continue;
808 switch(m_areaAuraType)
810 case AREA_AURA_ENEMY:
811 // non caster self-casted auras (non stacked)
812 if(i->second->GetModifier()->m_auraname != SPELL_AURA_NONE)
813 apply = false;
814 break;
815 case AREA_AURA_RAID:
816 // non caster self-casted auras (stacked from diff. casters)
817 if(i->second->GetModifier()->m_auraname != SPELL_AURA_NONE || i->second->GetCasterGUID() == GetCasterGUID())
818 apply = false;
819 break;
820 default:
821 // in generic case not allow stacking area auras
822 apply = false;
823 break;
826 if(!apply)
827 break;
830 if(!apply)
831 continue;
833 if(SpellEntry const *actualSpellInfo = sSpellMgr.SelectAuraRankForPlayerLevel(GetSpellProto(), (*tIter)->getLevel()))
835 int32 actualBasePoints = m_currentBasePoints;
836 // recalculate basepoints for lower rank (all AreaAura spell not use custom basepoints?)
837 if(actualSpellInfo != GetSpellProto())
838 actualBasePoints = actualSpellInfo->EffectBasePoints[m_effIndex];
839 AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
840 aur->SetAuraDuration(GetAuraDuration());
841 (*tIter)->AddAura(aur);
845 Aura::Update(diff);
847 else // aura at non-caster
849 Unit* caster = GetCaster();
851 Aura::Update(diff);
853 // remove aura if out-of-range from caster (after teleport for example)
854 // or caster is isolated or caster no longer has the aura
855 // or caster is (no longer) friendly
856 bool needFriendly = (m_areaAuraType == AREA_AURA_ENEMY ? false : true);
857 if( !caster || caster->hasUnitState(UNIT_STAT_ISOLATED) ||
858 !caster->IsWithinDistInMap(m_target, m_radius) ||
859 !caster->HasAura(GetId(), GetEffIndex()) ||
860 caster->IsFriendlyTo(m_target) != needFriendly
863 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(),GetCasterGUID());
865 else if( m_areaAuraType == AREA_AURA_PARTY) // check if in same sub group
867 // not check group if target == owner or target == pet
868 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
870 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
872 Group *pGroup = check ? check->GetGroup() : NULL;
873 if( pGroup )
875 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
876 if(!checkTarget || !pGroup->SameSubGroup(check, checkTarget))
877 m_target->RemoveAura(GetId(), GetEffIndex());
879 else
880 m_target->RemoveAura(GetId(), GetEffIndex());
883 else if( m_areaAuraType == AREA_AURA_RAID) // TODO: fix me!
885 // not check group if target == owner or target == pet
886 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
888 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
890 Group *pGroup = check ? check->GetGroup() : NULL;
891 if( pGroup )
893 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
894 if(!checkTarget)
895 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
897 else
898 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
901 else if( m_areaAuraType == AREA_AURA_PET || m_areaAuraType == AREA_AURA_OWNER )
903 if( m_target->GetGUID() != caster->GetCharmerOrOwnerGUID() )
904 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
909 void PersistentAreaAura::Update(uint32 diff)
911 bool remove = false;
913 // remove the aura if its caster or the dynamic object causing it was removed
914 // or if the target moves too far from the dynamic object
915 if(Unit *caster = GetCaster())
917 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
918 if (dynObj)
920 if (!m_target->IsWithinDistInMap(dynObj, dynObj->GetRadius()))
921 remove = true;
923 else
924 remove = true;
926 else
927 remove = true;
929 Aura::Update(diff);
931 if(remove)
932 m_target->RemoveAura(GetId(), GetEffIndex());
935 void Aura::ApplyModifier(bool apply, bool Real)
937 AuraType aura = m_modifier.m_auraname;
939 SetInUse(true);
940 if(aura < TOTAL_AURAS)
941 (*this.*AuraHandler [aura])(apply, Real);
942 SetInUse(false);
945 bool Aura::IsNeedVisibleSlot(Unit const* caster) const
947 bool totemAura = caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem();
949 // passive auras (except totem auras) do not get placed in the slots
950 if (m_isPassive && !totemAura)
951 return false;
953 // generic not caster case
954 if (m_target != caster)
955 return true;
957 // special area auras case at caster
958 switch(m_spellProto->Effect[GetEffIndex()])
960 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
961 return false;
962 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
963 // not sure is totemAura need, just preserve old code results
964 return totemAura || m_modifier.m_auraname != SPELL_AURA_NONE;
965 default: break;
968 return true;
971 void Aura::_AddAura()
973 if (!GetId())
974 return;
975 if(!m_target)
976 return;
978 // Second aura if some spell
979 bool secondaura = false;
980 // Try find slot for aura
981 uint8 slot = NULL_AURA_SLOT;
982 // Lookup for some spell auras (and get slot from it)
983 for(uint8 i = 0; i < m_effIndex; ++i)
985 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
986 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
988 // allow use single slot only by auras from same caster
989 if(itr->second->GetCasterGUID()==GetCasterGUID())
991 slot = itr->second->GetAuraSlot();
992 secondaura = true;
993 break;
996 if (secondaura)
997 break;
999 // Lookup free slot
1000 if (!secondaura && m_target->GetVisibleAurasCount() < MAX_AURAS)
1002 Unit::VisibleAuraMap const *visibleAuras = m_target->GetVisibleAuras();
1003 for(uint8 i = 0; i < MAX_AURAS; ++i)
1005 Unit::VisibleAuraMap::const_iterator itr = visibleAuras->find(i);
1006 if(itr == visibleAuras->end())
1008 slot = i;
1009 // update for out of range group members (on 1 slot use)
1010 m_target->UpdateAuraForGroup(slot);
1011 break;
1016 Unit* caster = GetCaster();
1018 // set infinity cooldown state for spells
1019 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1021 if (m_spellProto->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)
1023 Item* castItem = m_castItemGuid ? ((Player*)caster)->GetItemByGuid(m_castItemGuid) : NULL;
1024 ((Player*)caster)->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true);
1028 if (IsNeedVisibleSlot(caster))
1030 SetAuraSlot( slot );
1031 if(slot < MAX_AURAS) // slot found send data to client
1033 SetAura(false);
1034 SetAuraFlags((1 << GetEffIndex()) | AFLAG_NOT_CASTER | ((GetAuraMaxDuration() > 0) ? AFLAG_DURATION : AFLAG_NONE) | (IsPositive() ? AFLAG_POSITIVE : AFLAG_NEGATIVE));
1035 SetAuraLevel(caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
1036 SendAuraUpdate(false);
1039 //*****************************************************
1040 // Update target aura state flag (at 1 aura apply)
1041 // TODO: Make it easer
1042 //*****************************************************
1043 if (!secondaura)
1045 // Sitdown on apply aura req seated
1046 if (m_spellProto->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED && !m_target->IsSitState())
1047 m_target->SetStandState(UNIT_STAND_STATE_SIT);
1049 // register aura diminishing on apply
1050 if (getDiminishGroup() != DIMINISHING_NONE )
1051 m_target->ApplyDiminishingAura(getDiminishGroup(), true);
1053 // Update Seals information
1054 if (IsSealSpell(m_spellProto))
1055 m_target->ModifyAuraState(AURA_STATE_JUDGEMENT, true);
1057 // Conflagrate aura state on Immolate and Shadowflame
1058 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARLOCK &&
1059 // Immolate
1060 ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1061 // Shadowflame
1062 (m_spellProto->SpellFamilyFlags2 & 0x00000002)))
1063 m_target->ModifyAuraState(AURA_STATE_CONFLAGRATE, true);
1065 // Faerie Fire (druid versions)
1066 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
1067 m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE, true);
1069 // Victorious
1070 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARRIOR && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
1071 m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, true);
1073 // Swiftmend state on Regrowth & Rejuvenation
1074 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x50)))
1075 m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, true);
1077 // Deadly poison aura state
1078 if(m_spellProto->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellProto->SpellFamilyFlags & UI64LIT(0x10000)))
1079 m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON, true);
1081 // Enrage aura state
1082 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1083 m_target->ModifyAuraState(AURA_STATE_ENRAGE, true);
1088 bool Aura::_RemoveAura()
1090 // Remove all triggered by aura spells vs unlimited duration
1091 // except same aura replace case
1092 if(m_removeMode!=AURA_REMOVE_BY_STACK)
1093 CleanupTriggeredSpells();
1095 Unit* caster = GetCaster();
1097 if(caster && IsPersistent())
1099 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
1100 if (dynObj)
1101 dynObj->RemoveAffected(m_target);
1104 //passive auras do not get put in slots
1105 // Note: but totem can be not accessible for aura target in time remove (to far for find in grid)
1106 //if(m_isPassive && !(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()))
1107 // return;
1109 uint8 slot = GetAuraSlot();
1111 if(slot >= MAX_AURAS) // slot not set
1112 return false;
1114 if(m_target->GetVisibleAura(slot) == 0)
1115 return false;
1117 bool lastaura = true;
1119 // find other aura in same slot (current already removed from list)
1120 for(uint8 i = 0; i < 3; ++i)
1122 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
1123 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
1125 if(itr->second->GetAuraSlot() == slot)
1127 lastaura = false;
1128 break;
1131 if(!lastaura)
1132 break;
1135 // only remove icon when the last aura of the spell is removed (current aura already removed from list)
1136 if (!lastaura)
1137 return false;
1139 // unregister aura diminishing (and store last time)
1140 if (getDiminishGroup() != DIMINISHING_NONE )
1141 m_target->ApplyDiminishingAura(getDiminishGroup(), false);
1143 SetAura(true);
1144 SetAuraFlags(AFLAG_NONE);
1145 SetAuraLevel(0);
1147 if (m_removeMode != AURA_REMOVE_BY_DELETE)
1149 SendAuraUpdate(true);
1151 // update for out of range group members
1152 m_target->UpdateAuraForGroup(slot);
1154 //*****************************************************
1155 // Update target aura state flag (at last aura remove)
1156 //*****************************************************
1157 // Enrage aura state
1158 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1159 m_target->ModifyAuraState(AURA_STATE_ENRAGE, false);
1161 uint32 removeState = 0;
1162 uint64 removeFamilyFlag = m_spellProto->SpellFamilyFlags;
1163 uint32 removeFamilyFlag2 = m_spellProto->SpellFamilyFlags2;
1164 switch(m_spellProto->SpellFamilyName)
1166 case SPELLFAMILY_PALADIN:
1167 if (IsSealSpell(m_spellProto))
1168 removeState = AURA_STATE_JUDGEMENT; // Update Seals information
1169 break;
1170 case SPELLFAMILY_WARLOCK:
1171 // Conflagrate aura state on Immolate and Shadowflame,
1172 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1173 (m_spellProto->SpellFamilyFlags2 & 0x00000002))
1175 removeFamilyFlag = UI64LIT(0x0000000000000004);
1176 removeFamilyFlag2 = 0x00000002;
1177 removeState = AURA_STATE_CONFLAGRATE;
1179 break;
1180 case SPELLFAMILY_DRUID:
1181 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400))
1182 removeState = AURA_STATE_FAERIE_FIRE; // Faerie Fire (druid versions)
1183 else if(m_spellProto->SpellFamilyFlags & UI64LIT(0x50))
1185 removeFamilyFlag = 0x50;
1186 removeState = AURA_STATE_SWIFTMEND; // Swiftmend aura state
1188 break;
1189 case SPELLFAMILY_WARRIOR:
1190 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000))
1191 removeState = AURA_STATE_WARRIOR_VICTORY_RUSH; // Victorious
1192 break;
1193 case SPELLFAMILY_ROGUE:
1194 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x10000))
1195 removeState = AURA_STATE_DEADLY_POISON; // Deadly poison aura state
1196 break;
1197 case SPELLFAMILY_HUNTER:
1198 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
1199 removeState = AURA_STATE_FAERIE_FIRE; // Sting (hunter versions)
1202 // Remove state (but need check other auras for it)
1203 if (removeState)
1205 bool found = false;
1206 Unit::AuraMap& Auras = m_target->GetAuras();
1207 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
1209 SpellEntry const *auraSpellInfo = (*i).second->GetSpellProto();
1210 if(auraSpellInfo->SpellFamilyName == m_spellProto->SpellFamilyName &&
1211 (auraSpellInfo->SpellFamilyFlags & removeFamilyFlag || auraSpellInfo->SpellFamilyFlags2 & removeFamilyFlag2))
1213 found = true;
1214 break;
1217 // this has been last aura
1218 if(!found)
1219 m_target->ModifyAuraState(AuraState(removeState), false);
1222 // reset cooldown state for spells
1223 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1225 if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE )
1226 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
1227 ((Player*)caster)->SendCooldownEvent(GetSpellProto());
1231 return true;
1234 void Aura::SendAuraUpdate(bool remove)
1236 WorldPacket data(SMSG_AURA_UPDATE);
1237 data.append(m_target->GetPackGUID());
1238 data << uint8(GetAuraSlot());
1239 data << uint32(remove ? 0 : GetId());
1241 if(remove)
1243 m_target->SendMessageToSet(&data, true);
1244 return;
1247 uint8 auraFlags = GetAuraFlags();
1248 data << uint8(auraFlags);
1249 data << uint8(GetAuraLevel());
1250 data << uint8(m_procCharges ? m_procCharges*m_stackAmount : m_stackAmount);
1252 if(!(auraFlags & AFLAG_NOT_CASTER))
1254 data << uint8(0); // pguid
1257 if(auraFlags & AFLAG_DURATION)
1259 data << uint32(GetAuraMaxDuration());
1260 data << uint32(GetAuraDuration());
1263 m_target->SendMessageToSet(&data, true);
1266 void Aura::SetStackAmount(uint8 stackAmount)
1268 Unit *target = GetTarget();
1269 Unit *caster = GetCaster();
1270 if (!target || !caster)
1271 return;
1273 bool refresh = stackAmount >= m_stackAmount;
1274 if (stackAmount != m_stackAmount)
1276 m_stackAmount = stackAmount;
1277 int32 amount = m_stackAmount * caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, target);
1278 // Reapply if amount change
1279 if (amount!=m_modifier.m_amount)
1281 ApplyModifier(false, true);
1282 m_modifier.m_amount = amount;
1283 ApplyModifier(true, true);
1287 if (refresh)
1288 // Stack increased refresh duration
1289 RefreshAura();
1290 else
1291 // Stack decreased only send update
1292 SendAuraUpdate(false);
1295 bool Aura::modStackAmount(int32 num)
1297 // Can`t mod
1298 if (!m_spellProto->StackAmount)
1299 return true;
1301 // Modify stack but limit it
1302 int32 stackAmount = m_stackAmount + num;
1303 if (stackAmount > m_spellProto->StackAmount)
1304 stackAmount = m_spellProto->StackAmount;
1305 else if (stackAmount <=0) // Last aura from stack removed
1307 m_stackAmount = 0;
1308 return true; // need remove aura
1311 // Update stack amount
1312 SetStackAmount(stackAmount);
1313 return false;
1316 void Aura::RefreshAura()
1318 m_duration = m_maxduration;
1319 SendAuraUpdate(false);
1322 bool Aura::isAffectedOnSpell(SpellEntry const *spell) const
1324 // Check family name
1325 if (spell->SpellFamilyName != m_spellProto->SpellFamilyName)
1326 return false;
1327 // Check EffectClassMask
1328 uint32 const *ptr = getAuraSpellClassMask();
1329 if (((uint64*)ptr)[0] & spell->SpellFamilyFlags)
1330 return true;
1331 if (ptr[2] & spell->SpellFamilyFlags2)
1332 return true;
1333 return false;
1336 void Aura::ReapplyAffectedPassiveAuras( Unit* target, bool owner_mode )
1338 std::set<uint32> affectedSelf;
1339 std::set<uint32> affectedAuraCaster;
1341 for(Unit::AuraMap::const_iterator itr = target->GetAuras().begin(); itr != target->GetAuras().end(); ++itr)
1343 // permanent passive or permanent area aura
1344 // passive spells can be affected only by own or owner spell mods)
1345 if (itr->second->IsPermanent() && (owner_mode && itr->second->IsPassive() || itr->second->IsAreaAura()) &&
1346 // non deleted and not same aura (any with same spell id)
1347 !itr->second->IsDeleted() && itr->second->GetId() != GetId() &&
1348 // and affected by aura
1349 isAffectedOnSpell(itr->second->GetSpellProto()))
1351 // only applied by self or aura caster
1352 if (itr->second->GetCasterGUID() == target->GetGUID())
1353 affectedSelf.insert(itr->second->GetId());
1354 else if (itr->second->GetCasterGUID() == GetCasterGUID())
1355 affectedAuraCaster.insert(itr->second->GetId());
1359 for(std::set<uint32>::const_iterator set_itr = affectedSelf.begin(); set_itr != affectedSelf.end(); ++set_itr)
1361 target->RemoveAurasDueToSpell(*set_itr);
1362 target->CastSpell(m_target, *set_itr, true);
1365 if (!affectedAuraCaster.empty())
1367 Unit* caster = GetCaster();
1368 for(std::set<uint32>::const_iterator set_itr = affectedAuraCaster.begin(); set_itr != affectedAuraCaster.end(); ++set_itr)
1370 target->RemoveAurasDueToSpell(*set_itr);
1371 if (caster)
1372 caster->CastSpell(m_target, *set_itr, true);
1377 struct ReapplyAffectedPassiveAurasHelper
1379 explicit ReapplyAffectedPassiveAurasHelper(Aura* _aura) : aura(_aura) {}
1380 void operator()(Unit* unit) const { aura->ReapplyAffectedPassiveAuras(unit, true); }
1381 Aura* aura;
1384 void Aura::ReapplyAffectedPassiveAuras()
1386 // not reapply spell mods with charges (use original value because processed and at remove)
1387 if (m_spellProto->procCharges)
1388 return;
1390 // not reapply some spell mods ops (mostly speedup case)
1391 switch (m_modifier.m_miscvalue)
1393 case SPELLMOD_DURATION:
1394 case SPELLMOD_CHARGES:
1395 case SPELLMOD_NOT_LOSE_CASTING_TIME:
1396 case SPELLMOD_CASTING_TIME:
1397 case SPELLMOD_COOLDOWN:
1398 case SPELLMOD_COST:
1399 case SPELLMOD_ACTIVATION_TIME:
1400 case SPELLMOD_CASTING_TIME_OLD:
1401 return;
1404 // reapply talents to own passive persistent auras
1405 ReapplyAffectedPassiveAuras(m_target, true);
1407 // re-apply talents/passives/area auras applied to pet/totems (it affected by player spellmods)
1408 m_target->CallForAllControlledUnits(ReapplyAffectedPassiveAurasHelper(this),true,false,false);
1410 // re-apply talents/passives/area auras applied to group members (it affected by player spellmods)
1411 if (Group* group = ((Player*)m_target)->GetGroup())
1412 for(GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
1413 if (Player* member = itr->getSource())
1414 if (member != m_target && member->IsInMap(m_target))
1415 ReapplyAffectedPassiveAuras(member, false);
1418 /*********************************************************/
1419 /*** BASIC AURA FUNCTION ***/
1420 /*********************************************************/
1421 void Aura::HandleAddModifier(bool apply, bool Real)
1423 if(m_target->GetTypeId() != TYPEID_PLAYER || !Real)
1424 return;
1426 if(m_modifier.m_miscvalue >= MAX_SPELLMOD)
1427 return;
1429 if (apply)
1431 // Add custom charges for some mod aura
1432 switch (m_spellProto->Id)
1434 case 17941: // Shadow Trance
1435 case 22008: // Netherwind Focus
1436 case 31834: // Light's Grace
1437 case 34754: // Clearcasting
1438 case 34936: // Backlash
1439 case 44401: // Missile Barrage
1440 case 48108: // Hot Streak
1441 case 51124: // Killing Machine
1442 case 54741: // Firestarter
1443 case 57761: // Fireball!
1444 case 64823: // Elune's Wrath (Balance druid t8 set
1445 SetAuraCharges(1);
1446 break;
1449 m_spellmod = new SpellModifier(
1450 SpellModOp(m_modifier.m_miscvalue),
1451 SpellModType(m_modifier.m_auraname), // SpellModType value == spell aura types
1452 m_modifier.m_amount,
1453 this,
1454 // prevent expire spell mods with (charges > 0 && m_stackAmount > 1)
1455 // all this spell expected expire not at use but at spell proc event check
1456 m_spellProto->StackAmount > 1 ? 0 : m_procCharges);
1459 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
1461 ReapplyAffectedPassiveAuras();
1464 void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
1466 // Use SpellModifier structure for check
1467 // used only fields:
1468 // spellId, mask, mask2
1469 if (apply)
1471 SpellModifier *mod = new SpellModifier;
1472 mod->spellId = GetId();
1474 uint32 const *ptr = m_spellProto->GetEffectSpellClassMask(m_effIndex);
1476 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1477 mod->mask2= ptr[2];
1478 m_spellmod = mod;
1480 else
1482 delete m_spellmod;
1483 m_spellmod = NULL;
1487 void Aura::TriggerSpell()
1489 const uint64& casterGUID = GetCasterGUID();
1490 Unit* target = GetTriggerTarget();
1492 if(!casterGUID || !target)
1493 return;
1495 // generic casting code with custom spells and target/caster customs
1496 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
1498 SpellEntry const *triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1499 SpellEntry const *auraSpellInfo = GetSpellProto();
1500 uint32 auraId = auraSpellInfo->Id;
1502 // specific code for cases with no trigger spell provided in field
1503 if (triggeredSpellInfo == NULL)
1505 switch(auraSpellInfo->SpellFamilyName)
1507 case SPELLFAMILY_GENERIC:
1509 switch(auraId)
1511 // Firestone Passive (1-5 ranks)
1512 case 758:
1513 case 17945:
1514 case 17947:
1515 case 17949:
1516 case 27252:
1518 if (target->GetTypeId() != TYPEID_PLAYER)
1519 return;
1520 Item* item = ((Player*)target)->GetWeaponForAttack(BASE_ATTACK);
1521 if (!item)
1522 return;
1523 uint32 enchant_id = 0;
1524 switch (GetId())
1526 case 758: enchant_id = 1803; break; // Rank 1
1527 case 17945: enchant_id = 1823; break; // Rank 2
1528 case 17947: enchant_id = 1824; break; // Rank 3
1529 case 17949: enchant_id = 1825; break; // Rank 4
1530 case 27252: enchant_id = 2645; break; // Rank 5
1531 default:
1532 return;
1534 // remove old enchanting before applying new
1535 ((Player*)target)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1536 item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
1537 // add new enchanting
1538 ((Player*)target)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
1539 return;
1541 // // Periodic Mana Burn
1542 // case 812: break;
1543 // // Polymorphic Ray
1544 // case 6965: break;
1545 // Thaumaturgy Channel
1546 case 9712: trigger_spell_id = 21029; break;
1547 // // Egan's Blaster
1548 // case 17368: break;
1549 // // Haunted
1550 // case 18347: break;
1551 // // Ranshalla Waiting
1552 // case 18953: break;
1553 // // Inferno
1554 // case 19695: break;
1555 // // Frostwolf Muzzle DND
1556 // case 21794: break;
1557 // // Alterac Ram Collar DND
1558 // case 21866: break;
1559 // // Celebras Waiting
1560 // case 21916: break;
1561 // Brood Affliction: Bronze
1562 case 23170:
1564 m_target->CastSpell(m_target, 23171, true, NULL, this);
1565 return;
1567 // // Mark of Frost
1568 // case 23184: break;
1569 // Restoration
1570 case 23493:
1572 int32 heal = target->GetMaxHealth() / 10;
1573 target->DealHeal(target, heal, auraSpellInfo);
1575 if (int32 mana = target->GetMaxPower(POWER_MANA))
1577 mana /= 10;
1578 target->EnergizeBySpell(target, 23493, mana, POWER_MANA);
1580 return;
1582 // // Stoneclaw Totem Passive TEST
1583 // case 23792: break;
1584 // // Axe Flurry
1585 // case 24018: break;
1586 // // Mark of Arlokk
1587 // case 24210: break;
1588 // // Restoration
1589 // case 24379: break;
1590 // // Happy Pet
1591 // case 24716: break;
1592 // // Dream Fog
1593 // case 24780: break;
1594 // // Cannon Prep
1595 // case 24832: break;
1596 // Shadow Bolt Whirl
1597 case 24834:
1599 uint32 spellForTick[8] = { 24820, 24821, 24822, 24823, 24835, 24836, 24837, 24838 };
1600 uint32 tick = GetAuraTicks();
1601 if(tick < 8)
1603 trigger_spell_id = spellForTick[tick];
1605 // casted in left/right (but triggered spell have wide forward cone)
1606 float forward = m_target->GetOrientation();
1607 float angle = m_target->GetOrientation() + ( tick % 2 == 0 ? M_PI / 2 : - M_PI / 2);
1608 m_target->SetOrientation(angle);
1609 target->CastSpell(target, trigger_spell_id, true, NULL, this, casterGUID);
1610 m_target->SetOrientation(forward);
1612 return;
1614 // // Stink Trap
1615 // case 24918: break;
1616 // // Mark of Nature
1617 // case 25041: break;
1618 // // Agro Drones
1619 // case 25152: break;
1620 // Consume
1621 case 25371:
1623 int32 bpDamage = target->GetMaxHealth()*10/100;
1624 target->CastCustomSpell(target, 25373, &bpDamage, NULL, NULL, true, NULL, this, casterGUID);
1625 return;
1627 // // Pain Spike
1628 // case 25572: break;
1629 // // Rotate 360
1630 // case 26009: break;
1631 // // Rotate -360
1632 // case 26136: break;
1633 // // Consume
1634 // case 26196: break;
1635 // // Berserk
1636 // case 26615: break;
1637 // // Defile
1638 // case 27177: break;
1639 // // Teleport: IF/UC
1640 // case 27601: break;
1641 // // Five Fat Finger Exploding Heart Technique
1642 // case 27673: break;
1643 // // Nitrous Boost
1644 // case 27746: break;
1645 // // Steam Tank Passive
1646 // case 27747: break;
1647 // Frost Blast
1648 case 27808:
1650 int32 bpDamage = target->GetMaxHealth()*26/100;
1651 target->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this, casterGUID);
1652 return;
1654 // // Detonate Mana
1655 // case 27819: break;
1656 // // Controller Timer
1657 // case 28095: break;
1658 // // Stalagg Chain
1659 // case 28096: break;
1660 // // Stalagg Tesla Passive
1661 // case 28097: break;
1662 // // Feugen Tesla Passive
1663 // case 28109: break;
1664 // // Feugen Chain
1665 // case 28111: break;
1666 // // Mark of Didier
1667 // case 28114: break;
1668 // // Communique Timer, camp
1669 // case 28346: break;
1670 // // Icebolt
1671 // case 28522: break;
1672 // // Silithyst
1673 // case 29519: break;
1674 // Inoculate Nestlewood Owlkin
1675 case 29528:
1676 if(target->GetTypeId() != TYPEID_UNIT)// prevent error reports in case ignored player target
1677 return;
1678 break;
1679 // // Overload
1680 // case 29768: break;
1681 // // Return Fire
1682 // case 29788: break;
1683 // // Return Fire
1684 // case 29793: break;
1685 // // Return Fire
1686 // case 29794: break;
1687 // // Guardian of Icecrown Passive
1688 // case 29897: break;
1689 // Feed Captured Animal
1690 case 29917: trigger_spell_id = 29916; break;
1691 // // Flame Wreath
1692 // case 29946: break;
1693 // // Flame Wreath
1694 // case 29947: break;
1695 // // Mind Exhaustion Passive
1696 // case 30025: break;
1697 // // Nether Beam - Serenity
1698 // case 30401: break;
1699 // Extract Gas
1700 case 30427:
1702 Unit* caster = GetCaster();
1703 if (!caster)
1704 return;
1705 // move loot to player inventory and despawn target
1706 if(caster->GetTypeId() ==TYPEID_PLAYER &&
1707 target->GetTypeId() == TYPEID_UNIT &&
1708 ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
1710 Player* player = (Player*)caster;
1711 Creature* creature = (Creature*)target;
1712 // missing lootid has been reported on startup - just return
1713 if (!creature->GetCreatureInfo()->SkinLootId)
1714 return;
1716 player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true);
1718 creature->ForcedDespawn();
1720 return;
1722 // Quake
1723 case 30576: trigger_spell_id = 30571; break;
1724 // // Burning Maul
1725 // case 30598: break;
1726 // // Regeneration
1727 // case 30799:
1728 // case 30800:
1729 // case 30801:
1730 // break;
1731 // // Despawn Self - Smoke cloud
1732 // case 31269: break;
1733 // // Time Rift Periodic
1734 // case 31320: break;
1735 // // Corrupt Medivh
1736 // case 31326: break;
1737 // Doom
1738 case 31347:
1740 m_target->CastSpell(m_target,31350,true);
1741 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
1742 return;
1744 // Spellcloth
1745 case 31373:
1747 // Summon Elemental after create item
1748 target->SummonCreature(17870, 0, 0, 0, target->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
1749 return;
1751 // // Bloodmyst Tesla
1752 // case 31611: break;
1753 // Doomfire
1754 case 31944:
1756 int32 damage = m_modifier.m_amount * ((float)(GetAuraDuration() + m_modifier.periodictime) / GetAuraMaxDuration());
1757 target->CastCustomSpell(target, 31969, &damage, NULL, NULL, true, NULL, this, casterGUID);
1758 return;
1760 // // Teleport Test
1761 // case 32236: break;
1762 // // Earthquake
1763 // case 32686: break;
1764 // // Possess
1765 // case 33401: break;
1766 // // Draw Shadows
1767 // case 33563: break;
1768 // // Murmur's Touch
1769 // case 33711: break;
1770 // Flame Quills
1771 case 34229:
1773 // cast 24 spells 34269-34289, 34314-34316
1774 for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
1775 target->CastSpell(target, spell_id, true, NULL, this, casterGUID);
1776 for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
1777 target->CastSpell(target, spell_id, true, NULL, this, casterGUID);
1778 return;
1780 // // Gravity Lapse
1781 // case 34480: break;
1782 // // Tornado
1783 // case 34683: break;
1784 // // Frostbite Rotate
1785 // case 34748: break;
1786 // // Arcane Flurry
1787 // case 34821: break;
1788 // // Interrupt Shutdown
1789 // case 35016: break;
1790 // // Interrupt Shutdown
1791 // case 35176: break;
1792 // // Inferno
1793 // case 35268: break;
1794 // // Salaadin's Tesla
1795 // case 35515: break;
1796 // // Ethereal Channel (Red)
1797 // case 35518: break;
1798 // // Nether Vapor
1799 // case 35879: break;
1800 // // Dark Portal Storm
1801 // case 36018: break;
1802 // // Burning Maul
1803 // case 36056: break;
1804 // // Living Grove Defender Lifespan
1805 // case 36061: break;
1806 // // Professor Dabiri Talks
1807 // case 36064: break;
1808 // // Kael Gaining Power
1809 // case 36091: break;
1810 // // They Must Burn Bomb Aura
1811 // case 36344: break;
1812 // // They Must Burn Bomb Aura (self)
1813 // case 36350: break;
1814 // // Stolen Ravenous Ravager Egg
1815 // case 36401: break;
1816 // // Activated Cannon
1817 // case 36410: break;
1818 // // Stolen Ravenous Ravager Egg
1819 // case 36418: break;
1820 // // Enchanted Weapons
1821 // case 36510: break;
1822 // // Cursed Scarab Periodic
1823 // case 36556: break;
1824 // // Cursed Scarab Despawn Periodic
1825 // case 36561: break;
1826 // // Vision Guide
1827 // case 36573: break;
1828 // // Cannon Charging (platform)
1829 // case 36785: break;
1830 // // Cannon Charging (self)
1831 // case 36860: break;
1832 // Remote Toy
1833 case 37027: trigger_spell_id = 37029; break;
1834 // // Mark of Death
1835 // case 37125: break;
1836 // // Arcane Flurry
1837 // case 37268: break;
1838 // // Spout
1839 // case 37429: break;
1840 // // Spout
1841 // case 37430: break;
1842 // // Karazhan - Chess NPC AI, Snapshot timer
1843 // case 37440: break;
1844 // // Karazhan - Chess NPC AI, action timer
1845 // case 37504: break;
1846 // // Karazhan - Chess: Is Square OCCUPIED aura (DND)
1847 // case 39400: break;
1848 // // Banish
1849 // case 37546: break;
1850 // // Shriveling Gaze
1851 // case 37589: break;
1852 // // Fake Aggro Radius (2 yd)
1853 // case 37815: break;
1854 // // Corrupt Medivh
1855 // case 37853: break;
1856 // Eye of Grillok
1857 case 38495:
1859 m_target->CastSpell(m_target, 38530, true);
1860 return;
1862 // Absorb Eye of Grillok (Zezzak's Shard)
1863 case 38554:
1865 if(m_target->GetTypeId() != TYPEID_UNIT)
1866 return;
1868 if (Unit* caster = GetCaster())
1869 caster->CastSpell(caster, 38495, true, NULL, this);
1870 else
1871 return;
1873 Creature* creatureTarget = (Creature*)m_target;
1875 creatureTarget->ForcedDespawn();
1876 return;
1878 // // Magic Sucker Device timer
1879 // case 38672: break;
1880 // // Tomb Guarding Charging
1881 // case 38751: break;
1882 // // Murmur's Touch
1883 // case 38794: break;
1884 // // Activate Nether-wraith Beacon (31742 Nether-wraith Beacon item)
1885 // case 39105: break;
1886 // // Drain World Tree Visual
1887 // case 39140: break;
1888 // // Quest - Dustin's Undead Dragon Visual aura
1889 // case 39259: break;
1890 // // Hellfire - The Exorcism, Jules releases darkness, aura
1891 // case 39306: break;
1892 // // Inferno
1893 // case 39346: break;
1894 // // Enchanted Weapons
1895 // case 39489: break;
1896 // // Shadow Bolt Whirl
1897 // case 39630: break;
1898 // // Shadow Bolt Whirl
1899 // case 39634: break;
1900 // // Shadow Inferno
1901 // case 39645: break;
1902 // Tear of Azzinoth Summon Channel - it's not really supposed to do anything,and this only prevents the console spam
1903 case 39857: trigger_spell_id = 39856; break;
1904 // // Soulgrinder Ritual Visual (Smashed)
1905 // case 39974: break;
1906 // // Simon Game Pre-game timer
1907 // case 40041: break;
1908 // // Knockdown Fel Cannon: The Aggro Check Aura
1909 // case 40113: break;
1910 // // Spirit Lance
1911 // case 40157: break;
1912 // // Demon Transform 2
1913 // case 40398: break;
1914 // // Demon Transform 1
1915 // case 40511: break;
1916 // // Ancient Flames
1917 // case 40657: break;
1918 // // Ethereal Ring Cannon: Cannon Aura
1919 // case 40734: break;
1920 // // Cage Trap
1921 // case 40760: break;
1922 // // Random Periodic
1923 // case 40867: break;
1924 // // Prismatic Shield
1925 // case 40879: break;
1926 // // Aura of Desire
1927 // case 41350: break;
1928 // // Dementia
1929 // case 41404: break;
1930 // // Chaos Form
1931 // case 41629: break;
1932 // // Alert Drums
1933 // case 42177: break;
1934 // // Spout
1935 // case 42581: break;
1936 // // Spout
1937 // case 42582: break;
1938 // // Return to the Spirit Realm
1939 // case 44035: break;
1940 // // Curse of Boundless Agony
1941 // case 45050: break;
1942 // // Earthquake
1943 // case 46240: break;
1944 // Personalized Weather
1945 case 46736: trigger_spell_id = 46737; break;
1946 // // Stay Submerged
1947 // case 46981: break;
1948 // // Dragonblight Ram
1949 // case 47015: break;
1950 // // Party G.R.E.N.A.D.E.
1951 // case 51510: break;
1952 default:
1953 break;
1955 break;
1957 case SPELLFAMILY_MAGE:
1959 switch(auraId)
1961 // Invisibility
1962 case 66:
1963 // Here need periodic triger reducing threat spell (or do it manually)
1964 return;
1965 default:
1966 break;
1968 break;
1970 // case SPELLFAMILY_WARRIOR:
1971 // {
1972 // switch(auraId)
1973 // {
1974 // // Wild Magic
1975 // case 23410: break;
1976 // // Corrupted Totems
1977 // case 23425: break;
1978 // default:
1979 // break;
1980 // }
1981 // break;
1982 // }
1983 // case SPELLFAMILY_PRIEST:
1984 // {
1985 // switch(auraId)
1986 // {
1987 // // Blue Beam
1988 // case 32930: break;
1989 // // Fury of the Dreghood Elders
1990 // case 35460: break;
1991 // default:
1992 // break;
1993 // }
1994 // break;
1995 // }
1996 case SPELLFAMILY_HUNTER:
1998 switch (auraId)
2000 // Sniper training
2001 case 53302:
2002 case 53303:
2003 case 53304:
2004 if (target->GetTypeId() != TYPEID_PLAYER)
2005 return;
2007 // Reset reapply counter at move
2008 if (((Player*)target)->isMoving())
2010 m_modifier.m_amount = 6;
2011 return;
2014 // We are standing at the moment
2015 if (m_modifier.m_amount > 0)
2017 --m_modifier.m_amount;
2018 return;
2021 // select rank of buff
2022 switch(auraId)
2024 case 53302: trigger_spell_id = 64418; break;
2025 case 53303: trigger_spell_id = 64419; break;
2026 case 53304: trigger_spell_id = 64420; break;
2029 // If aura is active - no need to continue
2030 if (target->HasAura(trigger_spell_id))
2031 return;
2033 break;
2034 default:
2035 break;
2037 break;
2039 case SPELLFAMILY_DRUID:
2041 switch(auraId)
2043 // Cat Form
2044 // trigger_spell_id not set and unknown effect triggered in this case, ignoring for while
2045 case 768:
2046 return;
2047 // Frenzied Regeneration
2048 case 22842:
2049 case 22895:
2050 case 22896:
2051 case 26999:
2053 int32 LifePerRage = GetModifier()->m_amount;
2055 int32 lRage = m_target->GetPower(POWER_RAGE);
2056 if(lRage > 100) // rage stored as rage*10
2057 lRage = 100;
2058 m_target->ModifyPower(POWER_RAGE, -lRage);
2059 int32 FRTriggerBasePoints = int32(lRage*LifePerRage/10);
2060 m_target->CastCustomSpell(m_target, 22845, &FRTriggerBasePoints, NULL, NULL, true, NULL, this);
2061 return;
2063 default:
2064 break;
2066 break;
2069 // case SPELLFAMILY_HUNTER:
2070 // {
2071 // switch(auraId)
2072 // {
2073 // //Frost Trap Aura
2074 // case 13810:
2075 // return;
2076 // //Rizzle's Frost Trap
2077 // case 39900:
2078 // return;
2079 // // Tame spells
2080 // case 19597: // Tame Ice Claw Bear
2081 // case 19676: // Tame Snow Leopard
2082 // case 19677: // Tame Large Crag Boar
2083 // case 19678: // Tame Adult Plainstrider
2084 // case 19679: // Tame Prairie Stalker
2085 // case 19680: // Tame Swoop
2086 // case 19681: // Tame Dire Mottled Boar
2087 // case 19682: // Tame Surf Crawler
2088 // case 19683: // Tame Armored Scorpid
2089 // case 19684: // Tame Webwood Lurker
2090 // case 19685: // Tame Nightsaber Stalker
2091 // case 19686: // Tame Strigid Screecher
2092 // case 30100: // Tame Crazed Dragonhawk
2093 // case 30103: // Tame Elder Springpaw
2094 // case 30104: // Tame Mistbat
2095 // case 30647: // Tame Barbed Crawler
2096 // case 30648: // Tame Greater Timberstrider
2097 // case 30652: // Tame Nightstalker
2098 // return;
2099 // default:
2100 // break;
2101 // }
2102 // break;
2103 // }
2104 case SPELLFAMILY_SHAMAN:
2106 switch(auraId)
2108 // Lightning Shield (The Earthshatterer set trigger after cast Lighting Shield)
2109 case 28820:
2111 // Need remove self if Lightning Shield not active
2112 Unit::AuraMap const& auras = target->GetAuras();
2113 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
2115 SpellEntry const* spell = itr->second->GetSpellProto();
2116 if( spell->SpellFamilyName == SPELLFAMILY_SHAMAN &&
2117 (spell->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
2118 return;
2120 target->RemoveAurasDueToSpell(28820);
2121 return;
2123 // Totemic Mastery (Skyshatter Regalia (Shaman Tier 6) - bonus)
2124 case 38443:
2126 bool all = true;
2127 for(int i = 0; i < MAX_TOTEM; ++i)
2129 if(!target->m_TotemSlot[i])
2131 all = false;
2132 break;
2136 if(all)
2137 target->CastSpell(target, 38437, true, NULL, this);
2138 else
2139 target->RemoveAurasDueToSpell(38437);
2140 return;
2142 default:
2143 break;
2145 break;
2147 default:
2148 break;
2151 // Reget trigger spell proto
2152 triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
2154 else
2156 // Spell exist but require custom code
2157 switch(auraId)
2159 // Curse of Idiocy
2160 case 1010:
2162 // TODO: spell casted by result in correct way mostly
2163 // BUT:
2164 // 1) target show casting at each triggered cast: target don't must show casting animation for any triggered spell
2165 // but must show affect apply like item casting
2166 // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
2168 // prevent cast by triggered auras
2169 if(casterGUID == target->GetGUID())
2170 return;
2172 // stop triggering after each affected stats lost > 90
2173 int32 intelectLoss = 0;
2174 int32 spiritLoss = 0;
2176 Unit::AuraList const& mModStat = target->GetAurasByType(SPELL_AURA_MOD_STAT);
2177 for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
2179 if ((*i)->GetId() == 1010)
2181 switch((*i)->GetModifier()->m_miscvalue)
2183 case STAT_INTELLECT: intelectLoss += (*i)->GetModifier()->m_amount; break;
2184 case STAT_SPIRIT: spiritLoss += (*i)->GetModifier()->m_amount; break;
2185 default: break;
2190 if(intelectLoss <= -90 && spiritLoss <= -90)
2191 return;
2193 break;
2195 // Mana Tide
2196 case 16191:
2198 target->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
2199 return;
2201 // Ground Slam
2202 case 33525:
2203 target->CastSpell(target, trigger_spell_id, true, NULL, this, casterGUID);
2204 return;
2205 // Beacon of Light
2206 case 53563:
2207 // original caster must be target (beacon)
2208 target->CastSpell(target, trigger_spell_id, true, NULL, this, target->GetGUID());
2209 return;
2210 // Rapid Recuperation (triggered energize have baspioints == 0)
2211 case 56654:
2212 case 58882:
2214 int32 mana = m_target->GetMaxPower(POWER_MANA) * m_modifier.m_amount / 100;
2215 target->CastCustomSpell(target, trigger_spell_id, &mana, NULL, NULL, true, NULL, this);
2216 return;
2221 // All ok cast by default case
2222 if(triggeredSpellInfo)
2223 target->CastSpell(target, triggeredSpellInfo, true, NULL, this, casterGUID);
2224 else
2226 if (Unit* caster = GetCaster())
2228 if(target->GetTypeId() != TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target))
2229 sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
2234 void Aura::TriggerSpellWithValue()
2236 const uint64& casterGUID = GetCasterGUID();
2237 Unit* target = GetTriggerTarget();
2239 if(!casterGUID || !target)
2240 return;
2242 // generic casting code with custom spells and target/caster customs
2243 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
2244 int32 basepoints0 = this->GetModifier()->m_amount;
2246 target->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this, casterGUID);
2249 /*********************************************************/
2250 /*** AURA EFFECTS ***/
2251 /*********************************************************/
2253 void Aura::HandleAuraDummy(bool apply, bool Real)
2255 // spells required only Real aura add/remove
2256 if(!Real)
2257 return;
2259 // AT APPLY
2260 if(apply)
2262 switch(m_spellProto->SpellFamilyName)
2264 case SPELLFAMILY_GENERIC:
2265 switch(GetId())
2267 case 1515: // Tame beast
2268 // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
2269 if (m_target->CanHaveThreatList())
2270 if (Unit* caster = GetCaster())
2271 m_target->AddThreat(caster, 10.0f, false, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
2272 return;
2273 case 7057: // Haunting Spirits
2274 // expected to tick with 30 sec period (tick part see in Aura::PeriodicTick)
2275 m_isPeriodic = true;
2276 m_modifier.periodictime = 30*IN_MILISECONDS;
2277 m_periodicTimer = m_modifier.periodictime;
2278 return;
2279 case 13139: // net-o-matic
2280 // root to self part of (root_target->charge->root_self sequence
2281 if (Unit* caster = GetCaster())
2282 caster->CastSpell(caster, 13138, true, NULL, this);
2283 return;
2284 case 39850: // Rocket Blast
2285 if(roll_chance_i(20)) // backfire stun
2286 m_target->CastSpell(m_target, 51581, true, NULL, this);
2287 return;
2288 case 43873: // Headless Horseman Laugh
2289 m_target->PlayDistanceSound(11965);
2290 return;
2291 case 46354: // Blood Elf Illusion
2292 if (Unit* caster = GetCaster())
2294 switch(caster->getGender())
2296 case GENDER_FEMALE:
2297 caster->CastSpell(m_target, 46356, true, NULL, this);
2298 break;
2299 case GENDER_MALE:
2300 caster->CastSpell(m_target, 46355, true, NULL, this);
2301 break;
2302 default:
2303 break;
2306 return;
2307 case 46699: // Requires No Ammo
2308 if (m_target->GetTypeId() == TYPEID_PLAYER)
2309 // not use ammo and not allow use
2310 ((Player*)m_target)->RemoveAmmo();
2311 return;
2312 case 62061: // Festive Holiday Mount
2313 if (m_target->HasAuraType(SPELL_AURA_MOUNTED))
2314 // Reindeer Transformation
2315 m_target->CastSpell(m_target, 25860, true, NULL, this);
2316 return;
2318 break;
2319 case SPELLFAMILY_WARRIOR:
2320 // Overpower
2321 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004))
2323 // Must be casting target
2324 if (!m_target->IsNonMeleeSpellCasted(false))
2325 return;
2327 Unit* caster = GetCaster();
2328 if (!caster)
2329 return;
2331 Unit::AuraList const& modifierAuras = caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
2332 for(Unit::AuraList::const_iterator itr = modifierAuras.begin(); itr != modifierAuras.end(); ++itr)
2334 // Unrelenting Assault
2335 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARRIOR && (*itr)->GetSpellProto()->SpellIconID == 2775)
2337 switch ((*itr)->GetSpellProto()->Id)
2339 case 46859: // Unrelenting Assault, rank 1
2340 m_target->CastSpell(m_target,64849,true,NULL,(*itr));
2341 break;
2342 case 46860: // Unrelenting Assault, rank 2
2343 m_target->CastSpell(m_target,64850,true,NULL,(*itr));
2344 break;
2345 default:
2346 break;
2348 break;
2351 return;
2353 break;
2354 case SPELLFAMILY_SHAMAN:
2355 // Tidal Force
2356 if (GetId() == 55198)
2358 // apply max stack bufs
2359 SpellEntry const* buffEntry = sSpellStore.LookupEntry(55166);
2360 if (!buffEntry)
2361 return;
2362 for(int k = 0; k < buffEntry->StackAmount; ++k)
2363 m_target->CastSpell(m_target, buffEntry, true, NULL, this);
2365 // Earth Shield
2366 else if ((GetSpellProto()->SpellFamilyFlags & UI64LIT(0x40000000000)))
2368 // prevent double apply bonuses
2369 if(m_target->GetTypeId() != TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2370 if (Unit* caster = GetCaster())
2371 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2372 return;
2374 break;
2377 // AT REMOVE
2378 else
2380 if( m_target->GetTypeId() == TYPEID_PLAYER &&
2381 ( GetSpellProto()->Effect[0]==72 || GetSpellProto()->Effect[0]==6 &&
2382 ( GetSpellProto()->EffectApplyAuraName[0]==1 || GetSpellProto()->EffectApplyAuraName[0]==128 ) ) )
2384 // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
2385 ((Player*)m_target)->SetFarSightGUID(0);
2386 WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0);
2387 ((Player*)m_target)->GetSession()->SendPacket(&data);
2388 return;
2391 if (IsQuestTameSpell(GetId()) && m_target->isAlive())
2393 Unit* caster = GetCaster();
2394 if (!caster || !caster->isAlive())
2395 return;
2397 uint32 finalSpelId = 0;
2398 switch(GetId())
2400 case 19548: finalSpelId = 19597; break;
2401 case 19674: finalSpelId = 19677; break;
2402 case 19687: finalSpelId = 19676; break;
2403 case 19688: finalSpelId = 19678; break;
2404 case 19689: finalSpelId = 19679; break;
2405 case 19692: finalSpelId = 19680; break;
2406 case 19693: finalSpelId = 19684; break;
2407 case 19694: finalSpelId = 19681; break;
2408 case 19696: finalSpelId = 19682; break;
2409 case 19697: finalSpelId = 19683; break;
2410 case 19699: finalSpelId = 19685; break;
2411 case 19700: finalSpelId = 19686; break;
2412 case 30646: finalSpelId = 30647; break;
2413 case 30653: finalSpelId = 30648; break;
2414 case 30654: finalSpelId = 30652; break;
2415 case 30099: finalSpelId = 30100; break;
2416 case 30102: finalSpelId = 30103; break;
2417 case 30105: finalSpelId = 30104; break;
2420 if(finalSpelId)
2421 caster->CastSpell(m_target, finalSpelId, true, NULL, this);
2422 return;
2425 switch(GetId())
2427 case 12479: // Hex of Jammal'an
2428 m_target->CastSpell(m_target, 12480, true, NULL, this);
2429 return;
2430 case 28169: // Mutating Injection
2432 // Mutagen Explosion
2433 m_target->CastSpell(m_target, 28206, true, NULL, this);
2434 // Poison Cloud
2435 m_target->CastSpell(m_target, 28240, true, NULL, this);
2436 return;
2438 case 32286: // Focus Target Visual
2440 if (m_removeMode == AURA_REMOVE_BY_DEFAULT)
2441 m_target->CastSpell(m_target, 32301, true, NULL, this);
2443 return;
2445 case 36730: // Flame Strike
2447 m_target->CastSpell(m_target, 36731, true, NULL, this);
2448 return;
2450 case 44191: // Flame Strike
2452 if (m_target->GetMap()->IsDungeon())
2454 uint32 spellId = m_target->GetMap()->IsRegularDifficulty() ? 44190 : 46163;
2456 m_target->CastSpell(m_target, spellId, true, NULL, this);
2458 return;
2460 case 45934: // Dark Fiend
2462 // Kill target if dispelled
2463 if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2464 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2465 return;
2467 case 46308: // Burning Winds
2469 // casted only at creatures at spawn
2470 m_target->CastSpell(m_target, 47287, true, NULL, this);
2471 return;
2475 // Living Bomb
2476 if (m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE && (m_spellProto->SpellFamilyFlags & UI64LIT(0x2000000000000)))
2478 // Zero duration is equal to AURA_REMOVE_BY_DEFAULT. We can't use it directly, as it is set even
2479 // when removing aura from one target due to casting Living Bomb at other.
2480 if (m_duration == 0 || m_removeMode == AURA_REMOVE_BY_DISPEL)
2481 m_target->CastSpell(m_target,m_modifier.m_amount,true,NULL,this);
2482 return;
2485 if (m_removeMode == AURA_REMOVE_BY_DEATH)
2487 // Stop caster Arcane Missle chanelling on death
2488 if (m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE &&
2489 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000800)))
2491 if (Unit* caster = GetCaster())
2492 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2493 return;
2495 // Stop caster Penance chanelling on death
2496 if (m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST &&
2497 (m_spellProto->SpellFamilyFlags2 & UI64LIT(0x00000080)))
2499 if (Unit* caster = GetCaster())
2500 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2501 return;
2506 // AT APPLY & REMOVE
2508 switch(m_spellProto->SpellFamilyName)
2510 case SPELLFAMILY_GENERIC:
2512 switch(GetId())
2514 // Recently Bandaged
2515 case 11196:
2516 m_target->ApplySpellImmune(GetId(), IMMUNITY_MECHANIC, GetMiscValue(), apply);
2517 return;
2518 // Unstable Power
2519 case 24658:
2521 uint32 spellId = 24659;
2522 if (apply)
2524 SpellEntry const *spell = sSpellStore.LookupEntry(spellId);
2525 Unit* caster = GetCaster();
2526 if (!spell || !caster)
2527 return;
2529 for (int i=0; i < spell->StackAmount; ++i)
2530 caster->CastSpell(m_target, spellId, true, NULL, NULL, GetCasterGUID());
2531 return;
2533 m_target->RemoveAurasDueToSpell(spellId);
2534 return;
2536 // Restless Strength
2537 case 24661:
2539 uint32 spellId = 24662;
2540 if (apply)
2542 SpellEntry const* spell = sSpellStore.LookupEntry(spellId);
2543 Unit* caster = GetCaster();
2544 if (!spell || !caster)
2545 return;
2546 for (int i=0; i < spell->StackAmount; ++i)
2547 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2548 return;
2550 m_target->RemoveAurasDueToSpell(spellId);
2551 return;
2553 //Summon Fire Elemental
2554 case 40133:
2556 Unit* caster = GetCaster();
2557 if (!caster)
2558 return;
2560 Unit *owner = caster->GetOwner();
2561 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2563 if(apply)
2564 owner->CastSpell(owner, 8985, true);
2565 else
2566 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2568 return;
2570 //Summon Earth Elemental
2571 case 40132 :
2573 Unit* caster = GetCaster();
2574 if (!caster)
2575 return;
2577 Unit *owner = caster->GetOwner();
2578 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2580 if(apply)
2581 owner->CastSpell(owner, 19704, true);
2582 else
2583 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2585 return;
2587 //Dragonmaw Illusion
2588 case 40214 :
2590 if(apply)
2592 m_target->CastSpell(m_target, 40216, true);
2593 m_target->CastSpell(m_target, 42016, true);
2595 else
2597 m_target->RemoveAurasDueToSpell(40216);
2598 m_target->RemoveAurasDueToSpell(42016);
2600 return;
2602 // LK Intro VO (1)
2603 case 58204:
2604 if(m_target->GetTypeId() == TYPEID_PLAYER)
2606 // Play part 1
2607 if(apply)
2608 m_target->PlayDirectSound(14970, (Player *)m_target);
2609 // continue in 58205
2610 else
2611 m_target->CastSpell(m_target, 58205, true);
2613 return;
2614 // LK Intro VO (2)
2615 case 58205:
2616 if(m_target->GetTypeId() == TYPEID_PLAYER)
2618 // Play part 2
2619 if(apply)
2620 m_target->PlayDirectSound(14971, (Player *)m_target);
2621 // Play part 3
2622 else
2623 m_target->PlayDirectSound(14972, (Player *)m_target);
2625 return;
2626 case 40131:
2627 case 27978:
2628 if (apply)
2629 m_target->m_AuraFlags |= UNIT_AURAFLAG_ALIVE_INVISIBLE;
2630 else
2631 m_target->m_AuraFlags |= ~UNIT_AURAFLAG_ALIVE_INVISIBLE;
2632 return;
2634 break;
2636 case SPELLFAMILY_MAGE:
2637 break;
2638 case SPELLFAMILY_WARLOCK:
2640 // Haunt
2641 if (GetSpellProto()->SpellIconID == 3172 && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
2643 // NOTE: for avoid use additional field damage stored in dummy value (replace unused 100%
2644 if (apply)
2645 m_modifier.m_amount = 0; // use value as damage counter instead redundent 100% percent
2646 else
2648 int32 bp0 = m_modifier.m_amount;
2650 if (Unit* caster = GetCaster())
2651 m_target->CastCustomSpell(caster,48210,&bp0,NULL,NULL,true);
2654 break;
2656 case SPELLFAMILY_PRIEST:
2658 // Pain and Suffering
2659 if( m_spellProto->SpellIconID == 2874 && m_target->GetTypeId()==TYPEID_PLAYER )
2661 if(apply)
2663 // Reduce backfire damage (dot damage) from Shadow Word: Death
2664 // aura have wrong effectclassmask, so use hardcoded value
2665 m_spellmod = new SpellModifier(SPELLMOD_DOT,SPELLMOD_PCT,m_modifier.m_amount,GetId(),UI64LIT(0x0000200000000000));
2667 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2668 return;
2670 break;
2672 case SPELLFAMILY_DRUID:
2674 switch(GetId())
2676 case 34246: // Idol of the Emerald Queen
2677 case 60779: // Idol of Lush Moss
2679 if (m_target->GetTypeId() != TYPEID_PLAYER)
2680 return;
2682 if(apply)
2683 // dummy not have proper effectclassmask
2684 m_spellmod = new SpellModifier(SPELLMOD_DOT,SPELLMOD_FLAT,m_modifier.m_amount/7,GetId(),UI64LIT(0x001000000000));
2686 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2687 return;
2689 case 52610: // Savage Roar
2691 if(apply)
2693 if(m_target->m_form != FORM_CAT)
2694 return;
2696 m_target->CastSpell(m_target, 62071, true);
2698 else
2699 m_target-> RemoveAurasDueToSpell(62071);
2700 return;
2702 case 61336: // Survival Instincts
2704 if(apply)
2706 if (!m_target->IsInFeralForm())
2707 return;
2709 int32 bp0 = int32(m_target->GetMaxHealth() * m_modifier.m_amount / 100);
2710 m_target->CastCustomSpell(m_target, 50322, &bp0, NULL, NULL, true);
2712 else
2713 m_target-> RemoveAurasDueToSpell(50322);
2714 return;
2718 // Lifebloom
2719 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000))
2721 if ( apply )
2723 if (Unit* caster = GetCaster())
2724 // prevent double apply bonuses
2725 if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2726 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2728 else
2730 // Final heal only on dispelled or duration end
2731 if ( !(GetAuraDuration() <= 0 || m_removeMode == AURA_REMOVE_BY_DISPEL) )
2732 return;
2734 // have a look if there is still some other Lifebloom dummy aura
2735 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2736 for(Unit::AuraList::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
2737 if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2738 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000)))
2739 return;
2741 // final heal
2742 if(m_target->IsInWorld() && m_stackAmount > 0)
2744 int32 amount = m_modifier.m_amount / m_stackAmount;
2745 m_target->CastCustomSpell(m_target, 33778, &amount, NULL, NULL, true, NULL, this, GetCasterGUID());
2747 if (Unit* caster = GetCaster())
2749 int32 returnmana = (GetSpellProto()->ManaCostPercentage * caster->GetCreateMana() / 100) * m_stackAmount / 2;
2750 caster->CastCustomSpell(caster, 64372, &returnmana, NULL, NULL, true, NULL, this, GetCasterGUID());
2754 return;
2757 // Predatory Strikes
2758 if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2760 ((Player*)m_target)->UpdateAttackPowerAndDamage();
2761 return;
2764 // Improved Moonkin Form
2765 if(GetSpellProto()->SpellIconID == 2855)
2767 uint32 spell_id;
2768 switch(GetId())
2770 case 48384: spell_id = 50170; break; //Rank 1
2771 case 48395: spell_id = 50171; break; //Rank 2
2772 case 48396: spell_id = 50172; break; //Rank 3
2773 default:
2774 sLog.outError("HandleAuraDummy: Not handled rank of IMF (Spell: %u)",GetId());
2775 return;
2778 if(apply)
2780 if(m_target->m_form != FORM_MOONKIN)
2781 return;
2783 m_target->CastSpell(m_target, spell_id, true);
2785 else
2786 m_target-> RemoveAurasDueToSpell(spell_id);
2787 return;
2789 break;
2791 case SPELLFAMILY_HUNTER:
2792 break;
2793 case SPELLFAMILY_PALADIN:
2794 switch(GetId())
2796 case 20911: // Blessing of Sanctuary
2797 case 25899: // Greater Blessing of Sanctuary
2799 if (apply)
2800 m_target->CastSpell(m_target, 67480, true, NULL, this);
2801 else
2802 m_target->RemoveAurasDueToSpell(67480);
2803 return;
2806 break;
2807 case SPELLFAMILY_SHAMAN:
2808 break;
2811 // pet auras
2812 if(PetAura const* petSpell = sSpellMgr.GetPetAura(GetId(), m_effIndex))
2814 if(apply)
2815 m_target->AddPetAura(petSpell);
2816 else
2817 m_target->RemovePetAura(petSpell);
2818 return;
2821 if(GetEffIndex()==0 && m_target->GetTypeId()==TYPEID_PLAYER)
2823 SpellAreaForAreaMapBounds saBounds = sSpellMgr.GetSpellAreaForAuraMapBounds(GetId());
2824 if(saBounds.first != saBounds.second)
2826 uint32 zone, area;
2827 m_target->GetZoneAndAreaId(zone, area);
2829 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2831 // some auras remove at aura remove
2832 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
2833 m_target->RemoveAurasDueToSpell(itr->second->spellId);
2834 // some auras applied at aura apply
2835 else if(itr->second->autocast)
2837 if( !m_target->HasAura(itr->second->spellId, 0) )
2838 m_target->CastSpell(m_target, itr->second->spellId, true);
2845 void Aura::HandleAuraMounted(bool apply, bool Real)
2847 // only at real add/remove aura
2848 if(!Real)
2849 return;
2851 if(apply)
2853 CreatureInfo const* ci = ObjectMgr::GetCreatureTemplate(m_modifier.m_miscvalue);
2854 if(!ci)
2856 sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2857 return;
2860 uint32 team = 0;
2861 if (m_target->GetTypeId()==TYPEID_PLAYER)
2862 team = ((Player*)m_target)->GetTeam();
2864 uint32 display_id = sObjectMgr.ChooseDisplayId(team,ci);
2865 CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
2866 if (minfo)
2867 display_id = minfo->modelid;
2869 m_target->Mount(display_id, m_spellProto->Id);
2871 else
2873 m_target->Unmount();
2877 void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2879 // only at real add/remove aura
2880 if(!Real)
2881 return;
2883 WorldPacket data;
2884 if(apply)
2885 data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2886 else
2887 data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2888 data.append(m_target->GetPackGUID());
2889 data << uint32(0);
2890 m_target->SendMessageToSet(&data, true);
2893 void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2895 // only at real add/remove aura
2896 if(!Real)
2897 return;
2899 WorldPacket data;
2900 if(apply)
2901 data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2902 else
2903 data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2904 data.append(m_target->GetPackGUID());
2905 data << uint32(0);
2906 m_target->SendMessageToSet(&data, true);
2908 // start fall from current height
2909 if(!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2910 ((Player*)m_target)->SetFallInformation(0, m_target->GetPositionZ());
2913 void Aura::HandleAuraHover(bool apply, bool Real)
2915 // only at real add/remove aura
2916 if(!Real)
2917 return;
2919 WorldPacket data;
2920 if(apply)
2921 data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2922 else
2923 data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2924 data.append(m_target->GetPackGUID());
2925 data << uint32(0);
2926 m_target->SendMessageToSet(&data, true);
2929 void Aura::HandleWaterBreathing(bool /*apply*/, bool /*Real*/)
2931 // update timers in client
2932 if(m_target->GetTypeId()==TYPEID_PLAYER)
2933 ((Player*)m_target)->UpdateMirrorTimers();
2936 void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2938 if(!Real)
2939 return;
2941 uint32 modelid = 0;
2942 Powers PowerType = POWER_MANA;
2943 ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2945 SpellShapeshiftEntry const* ssEntry = sSpellShapeshiftStore.LookupEntry(form);
2946 if (!ssEntry)
2948 sLog.outError("Unknown shapeshift form %u in spell %u", form, GetId());
2949 return;
2952 if (ssEntry->modelID_A)
2954 // i will asume that creatures will always take the defined model from the dbc
2955 // since no field in creature_templates describes wether an alliance or
2956 // horde modelid should be used at shapeshifting
2957 if (m_target->GetTypeId() != TYPEID_PLAYER)
2958 modelid = ssEntry->modelID_A;
2959 else
2961 // players are a bit difficult since the dbc has seldomly an horde modelid
2962 // so we add hacks here to set the right model
2963 if (Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2964 modelid = ssEntry->modelID_A;
2965 else // 3.2.3 only the moonkin form has this information
2966 modelid = ssEntry->modelID_H;
2968 // no model found, if player is horde we look here for our hardcoded modelids
2969 if (!modelid && Player::TeamForRace(m_target->getRace()) == HORDE)
2972 switch(form)
2974 case FORM_CAT:
2975 modelid = 8571;
2976 break;
2977 case FORM_BEAR:
2978 case FORM_DIREBEAR:
2979 modelid = 2289;
2980 break;
2981 case FORM_FLIGHT:
2982 modelid = 20872;
2983 break;
2984 case FORM_FLIGHT_EPIC:
2985 modelid = 21244;
2986 break;
2987 // per default use alliance modelid
2988 // mostly horde and alliance share the same
2989 default:
2990 modelid = ssEntry->modelID_A;
2991 break;
2997 // now only powertype must be set
2998 switch(form)
3000 case FORM_CAT:
3001 PowerType = POWER_ENERGY;
3002 break;
3003 case FORM_BEAR:
3004 case FORM_DIREBEAR:
3005 case FORM_BATTLESTANCE:
3006 case FORM_BERSERKERSTANCE:
3007 case FORM_DEFENSIVESTANCE:
3008 PowerType = POWER_RAGE;
3009 break;
3010 default:
3011 break;
3014 // remove polymorph before changing display id to keep new display id
3015 switch ( form )
3017 case FORM_CAT:
3018 case FORM_TREE:
3019 case FORM_TRAVEL:
3020 case FORM_AQUA:
3021 case FORM_BEAR:
3022 case FORM_DIREBEAR:
3023 case FORM_FLIGHT_EPIC:
3024 case FORM_FLIGHT:
3025 case FORM_MOONKIN:
3027 // remove movement affects
3028 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
3029 Unit::AuraList const& slowingAuras = m_target->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
3030 for (Unit::AuraList::const_iterator iter = slowingAuras.begin(); iter != slowingAuras.end();)
3032 SpellEntry const* aurSpellInfo = (*iter)->GetSpellProto();
3034 uint32 aurMechMask = GetAllSpellMechanicMask(aurSpellInfo);
3036 // If spell that caused this aura has Croud Control or Daze effect
3037 if((aurMechMask & MECHANIC_NOT_REMOVED_BY_SHAPESHIFT) ||
3038 // some Daze spells have these parameters instead of MECHANIC_DAZE (skip snare spells)
3039 aurSpellInfo->SpellIconID == 15 && aurSpellInfo->Dispel == 0 &&
3040 (aurMechMask & (1 << (MECHANIC_SNARE-1)))==0)
3042 ++iter;
3043 continue;
3046 // All OK, remove aura now
3047 m_target->RemoveAurasDueToSpellByCancel(aurSpellInfo->Id);
3048 iter = slowingAuras.begin();
3051 // and polymorphic affects
3052 if(m_target->IsPolymorphed())
3053 m_target->RemoveAurasDueToSpell(m_target->getTransForm());
3055 break;
3057 default:
3058 break;
3061 if(apply)
3063 // remove other shapeshift before applying a new one
3064 if(m_target->m_ShapeShiftFormSpellId)
3065 m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId, this);
3067 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
3069 if(modelid > 0)
3070 m_target->SetDisplayId(modelid);
3072 if(PowerType != POWER_MANA)
3074 // reset power to default values only at power change
3075 if(m_target->getPowerType() != PowerType)
3076 m_target->setPowerType(PowerType);
3078 switch(form)
3080 case FORM_CAT:
3081 case FORM_BEAR:
3082 case FORM_DIREBEAR:
3084 // get furor proc chance
3085 int32 furorChance = 0;
3086 Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3087 for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
3089 if ((*i)->GetSpellProto()->SpellIconID == 238)
3091 furorChance = (*i)->GetModifier()->m_amount;
3092 break;
3096 if (m_modifier.m_miscvalue == FORM_CAT)
3098 // Furor chance is now amount allowed to save energy for cat form
3099 // without talent it reset to 0
3100 if (m_target->GetPower(POWER_ENERGY) > furorChance)
3102 m_target->SetPower(POWER_ENERGY, 0);
3103 m_target->CastCustomSpell(m_target, 17099, &furorChance, NULL, NULL, this);
3106 else if(furorChance) // only if talent known
3108 m_target->SetPower(POWER_RAGE, 0);
3109 if(urand(1,100) <= furorChance)
3110 m_target->CastSpell(m_target, 17057, true, NULL, this);
3112 break;
3114 case FORM_BATTLESTANCE:
3115 case FORM_DEFENSIVESTANCE:
3116 case FORM_BERSERKERSTANCE:
3118 uint32 Rage_val = 0;
3119 // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
3120 if(m_target->GetTypeId() == TYPEID_PLAYER)
3122 PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
3123 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
3125 if(itr->second->state == PLAYERSPELL_REMOVED) continue;
3126 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
3127 if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
3128 Rage_val += m_target->CalculateSpellDamage(spellInfo, 0, spellInfo->EffectBasePoints[0], m_target) * 10;
3132 if (m_target->GetPower(POWER_RAGE) > Rage_val)
3133 m_target->SetPower(POWER_RAGE, Rage_val);
3134 break;
3136 default:
3137 break;
3141 m_target->m_ShapeShiftFormSpellId = GetId();
3142 m_target->m_form = form;
3144 // a form can give the player a new castbar with some spells.. this is a clientside process..
3145 // serverside just needs to register the new spells so that player isn't kicked as cheater
3146 if (m_target->GetTypeId() == TYPEID_PLAYER)
3147 for (uint32 i = 0; i < 8; ++i)
3148 if (ssEntry->spellId[i])
3149 ((Player*)m_target)->addSpell(ssEntry->spellId[i], true, false, false, false);
3152 else
3154 if(modelid > 0)
3155 m_target->SetDisplayId(m_target->GetNativeDisplayId());
3156 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
3157 if(m_target->getClass() == CLASS_DRUID)
3158 m_target->setPowerType(POWER_MANA);
3159 m_target->m_ShapeShiftFormSpellId = 0;
3160 m_target->m_form = FORM_NONE;
3162 switch(form)
3164 // Nordrassil Harness - bonus
3165 case FORM_BEAR:
3166 case FORM_DIREBEAR:
3167 case FORM_CAT:
3168 if(Aura* dummy = m_target->GetDummyAura(37315) )
3169 m_target->CastSpell(m_target, 37316, true, NULL, dummy);
3170 break;
3171 // Nordrassil Regalia - bonus
3172 case FORM_MOONKIN:
3173 if(Aura* dummy = m_target->GetDummyAura(37324) )
3174 m_target->CastSpell(m_target, 37325, true, NULL, dummy);
3175 break;
3176 default:
3177 break;
3180 // look at the comment in apply-part
3181 if (m_target->GetTypeId() == TYPEID_PLAYER)
3182 for (uint32 i = 0; i < 8; ++i)
3183 if (ssEntry->spellId[i])
3184 ((Player*)m_target)->removeSpell(ssEntry->spellId[i], false, false, false);
3188 // adding/removing linked auras
3189 // add/remove the shapeshift aura's boosts
3190 HandleShapeshiftBoosts(apply);
3192 if(m_target->GetTypeId() == TYPEID_PLAYER)
3193 ((Player*)m_target)->InitDataForForm();
3196 void Aura::HandleAuraTransform(bool apply, bool Real)
3198 if (apply)
3200 // special case (spell specific functionality)
3201 if (m_modifier.m_miscvalue == 0)
3203 // player applied only
3204 if (m_target->GetTypeId() != TYPEID_PLAYER)
3205 return;
3207 switch (GetId())
3209 // Orb of Deception
3210 case 16739:
3212 uint32 orb_model = m_target->GetNativeDisplayId();
3213 switch(orb_model)
3215 // Troll Female
3216 case 1479: m_target->SetDisplayId(10134); break;
3217 // Troll Male
3218 case 1478: m_target->SetDisplayId(10135); break;
3219 // Tauren Male
3220 case 59: m_target->SetDisplayId(10136); break;
3221 // Human Male
3222 case 49: m_target->SetDisplayId(10137); break;
3223 // Human Female
3224 case 50: m_target->SetDisplayId(10138); break;
3225 // Orc Male
3226 case 51: m_target->SetDisplayId(10139); break;
3227 // Orc Female
3228 case 52: m_target->SetDisplayId(10140); break;
3229 // Dwarf Male
3230 case 53: m_target->SetDisplayId(10141); break;
3231 // Dwarf Female
3232 case 54: m_target->SetDisplayId(10142); break;
3233 // NightElf Male
3234 case 55: m_target->SetDisplayId(10143); break;
3235 // NightElf Female
3236 case 56: m_target->SetDisplayId(10144); break;
3237 // Undead Female
3238 case 58: m_target->SetDisplayId(10145); break;
3239 // Undead Male
3240 case 57: m_target->SetDisplayId(10146); break;
3241 // Tauren Female
3242 case 60: m_target->SetDisplayId(10147); break;
3243 // Gnome Male
3244 case 1563: m_target->SetDisplayId(10148); break;
3245 // Gnome Female
3246 case 1564: m_target->SetDisplayId(10149); break;
3247 // BloodElf Female
3248 case 15475: m_target->SetDisplayId(17830); break;
3249 // BloodElf Male
3250 case 15476: m_target->SetDisplayId(17829); break;
3251 // Dranei Female
3252 case 16126: m_target->SetDisplayId(17828); break;
3253 // Dranei Male
3254 case 16125: m_target->SetDisplayId(17827); break;
3255 default: break;
3257 break;
3259 // Murloc costume
3260 case 42365: m_target->SetDisplayId(21723); break;
3261 // Honor the Dead
3262 case 65386:
3263 case 65495:
3265 switch(m_target->getGender())
3267 case GENDER_MALE:
3268 m_target->SetDisplayId(29203); // Chapman
3269 break;
3270 case GENDER_FEMALE:
3271 case GENDER_NONE:
3272 m_target->SetDisplayId(29204); // Catrina
3273 break;
3275 break;
3277 default: break;
3280 else
3282 uint32 model_id;
3284 CreatureInfo const * ci = ObjectMgr::GetCreatureTemplate(m_modifier.m_miscvalue);
3285 if (!ci)
3287 model_id = 16358; // pig pink ^_^
3288 sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
3290 else
3291 model_id = ci->DisplayID_A[0]; // Will use the default model here
3293 // Polymorph (sheep/penguin case)
3294 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
3295 if (Unit* caster = GetCaster())
3296 if (caster->HasAura(52648)) // Glyph of the Penguin
3297 model_id = 26452;
3299 m_target->SetDisplayId(model_id);
3301 // Dragonmaw Illusion (set mount model also)
3302 if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
3303 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3306 // update active transform spell only not set or not overwriting negative by positive case
3307 if (!m_target->getTransForm() || !IsPositiveSpell(GetId()) || IsPositiveSpell(m_target->getTransForm()))
3308 m_target->setTransForm(GetId());
3310 // polymorph case
3311 if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
3313 // for players, start regeneration after 1s (in polymorph fast regeneration case)
3314 // only if caster is Player (after patch 2.4.2)
3315 if (IS_PLAYER_GUID(GetCasterGUID()) )
3316 ((Player*)m_target)->setRegenTimer(1*IN_MILISECONDS);
3318 //dismount polymorphed target (after patch 2.4.2)
3319 if (m_target->IsMounted())
3320 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
3323 else
3325 // ApplyModifier(true) will reapply it if need
3326 m_target->setTransForm(0);
3327 m_target->SetDisplayId(m_target->GetNativeDisplayId());
3329 // re-aplly some from still active with preference negative cases
3330 Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
3331 if (!otherTransforms.empty())
3333 // look for other transform auras
3334 Aura* handledAura = *otherTransforms.begin();
3335 for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
3337 // negative auras are preferred
3338 if (!IsPositiveSpell((*i)->GetSpellProto()->Id))
3340 handledAura = *i;
3341 break;
3344 handledAura->ApplyModifier(true);
3347 // Dragonmaw Illusion (restore mount model)
3348 if (GetId() == 42016 && m_target->GetMountID() == 16314)
3350 if (!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
3352 uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
3353 if (CreatureInfo const* ci = ObjectMgr::GetCreatureTemplate(cr_id))
3355 uint32 team = 0;
3356 if (m_target->GetTypeId() == TYPEID_PLAYER)
3357 team = ((Player*)m_target)->GetTeam();
3359 uint32 display_id = sObjectMgr.ChooseDisplayId(team, ci);
3360 CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
3361 if (minfo)
3362 display_id = minfo->modelid;
3364 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, display_id);
3371 void Aura::HandleForceReaction(bool apply, bool Real)
3373 if(m_target->GetTypeId() != TYPEID_PLAYER)
3374 return;
3376 if(!Real)
3377 return;
3379 Player* player = (Player*)m_target;
3381 uint32 faction_id = m_modifier.m_miscvalue;
3382 ReputationRank faction_rank = ReputationRank(m_modifier.m_amount);
3384 player->GetReputationMgr().ApplyForceReaction(faction_id, faction_rank, apply);
3385 player->GetReputationMgr().SendForceReactions();
3387 // stop fighting if at apply forced rank friendly or at remove real rank friendly
3388 if (apply && faction_rank >= REP_FRIENDLY || !apply && player->GetReputationRank(faction_id) >= REP_FRIENDLY)
3389 player->StopAttackFaction(faction_id);
3392 void Aura::HandleAuraModSkill(bool apply, bool /*Real*/)
3394 if(m_target->GetTypeId() != TYPEID_PLAYER)
3395 return;
3397 uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
3398 int32 points = GetModifier()->m_amount;
3400 ((Player*)m_target)->ModifySkillBonus(prot, (apply ? points: -points), m_modifier.m_auraname == SPELL_AURA_MOD_SKILL_TALENT);
3401 if(prot == SKILL_DEFENSE)
3402 ((Player*)m_target)->UpdateDefenseBonusesMod();
3405 void Aura::HandleChannelDeathItem(bool apply, bool Real)
3407 if(Real && !apply)
3409 if(m_removeMode != AURA_REMOVE_BY_DEATH)
3410 return;
3411 // Item amount
3412 if (m_modifier.m_amount <= 0)
3413 return;
3415 SpellEntry const *spellInfo = GetSpellProto();
3416 if(spellInfo->EffectItemType[m_effIndex] == 0)
3417 return;
3419 Unit* victim = GetTarget();
3420 Unit* caster = GetCaster();
3421 if (!caster || caster->GetTypeId() != TYPEID_PLAYER)
3422 return;
3424 // Soul Shard only from non-grey units
3425 if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
3426 (victim->getLevel() <= MaNGOS::XP::GetGrayLevel(caster->getLevel()) ||
3427 victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
3428 return;
3429 //Adding items
3430 uint32 noSpaceForCount = 0;
3431 uint32 count = m_modifier.m_amount;
3433 ItemPosCountVec dest;
3434 uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], count, &noSpaceForCount);
3435 if( msg != EQUIP_ERR_OK )
3437 count-=noSpaceForCount;
3438 ((Player*)caster)->SendEquipError( msg, NULL, NULL );
3439 if (count==0)
3440 return;
3443 Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
3444 ((Player*)caster)->SendNewItem(newitem, count, true, false);
3448 void Aura::HandleBindSight(bool apply, bool /*Real*/)
3450 Unit* caster = GetCaster();
3451 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3452 return;
3454 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3457 void Aura::HandleFarSight(bool apply, bool /*Real*/)
3459 Unit* caster = GetCaster();
3460 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3461 return;
3463 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3466 void Aura::HandleAuraTrackCreatures(bool apply, bool /*Real*/)
3468 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3469 return;
3471 if(apply)
3472 m_target->RemoveNoStackAurasDueToAura(this);
3473 m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
3476 void Aura::HandleAuraTrackResources(bool apply, bool /*Real*/)
3478 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3479 return;
3481 if(apply)
3482 m_target->RemoveNoStackAurasDueToAura(this);
3483 m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
3486 void Aura::HandleAuraTrackStealthed(bool apply, bool /*Real*/)
3488 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3489 return;
3491 if(apply)
3492 m_target->RemoveNoStackAurasDueToAura(this);
3494 m_target->ApplyModFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTE_TRACK_STEALTHED, apply);
3497 void Aura::HandleAuraModScale(bool apply, bool /*Real*/)
3499 m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X, m_modifier.m_amount, apply);
3502 void Aura::HandleModPossess(bool apply, bool Real)
3504 if(!Real)
3505 return;
3507 // not possess yourself
3508 if(GetCasterGUID() == m_target->GetGUID())
3509 return;
3511 Unit* caster = GetCaster();
3512 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3513 return;
3515 Player* p_caster = (Player*)caster;
3518 if( apply )
3520 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3522 m_target->SetCharmerGUID(p_caster->GetGUID());
3523 m_target->setFaction(p_caster->getFaction());
3525 p_caster->SetCharm(m_target);
3527 p_caster->SetFarSightGUID(m_target->GetGUID());
3528 p_caster->SetClientControl(m_target, 1);
3529 p_caster->SetMover(m_target);
3531 m_target->CombatStop();
3532 m_target->DeleteThreatList();
3534 if(m_target->GetTypeId() == TYPEID_UNIT)
3536 m_target->StopMoving();
3537 m_target->GetMotionMaster()->Clear();
3538 m_target->GetMotionMaster()->MoveIdle();
3540 else if(m_target->GetTypeId() == TYPEID_PLAYER)
3542 ((Player*)m_target)->SetClientControl(m_target, 0);
3545 if(CharmInfo *charmInfo = m_target->InitCharmInfo(m_target))
3546 charmInfo->InitPossessCreateSpells();
3548 p_caster->PossessSpellInitialize();
3550 else
3552 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3554 m_target->SetCharmerGUID(0);
3555 p_caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now
3557 if(m_target->GetTypeId() == TYPEID_PLAYER)
3559 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3560 ((Player*)m_target)->SetClientControl(m_target, 1);
3562 else if(m_target->GetTypeId() == TYPEID_UNIT)
3564 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3565 m_target->setFaction(cinfo->faction_A);
3568 p_caster->SetCharm(NULL);
3570 p_caster->SetFarSightGUID(0);
3571 p_caster->SetClientControl(m_target, 0);
3572 p_caster->SetMover(NULL);
3574 p_caster->RemovePetActionBar();
3576 if(m_target->GetTypeId() == TYPEID_UNIT)
3578 ((Creature*)m_target)->AIM_Initialize();
3580 if (((Creature*)m_target)->AI())
3581 ((Creature*)m_target)->AI()->AttackedBy(caster);
3586 void Aura::HandleModPossessPet(bool apply, bool Real)
3588 if(!Real)
3589 return;
3591 Unit* caster = GetCaster();
3592 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3593 return;
3595 Pet *pet = caster->GetPet();
3596 if(!pet || pet != m_target)
3597 return;
3599 Player* p_caster = (Player*)caster;
3601 if(apply)
3602 pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3603 else
3604 pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3606 p_caster->SetFarSightGUID(apply ? pet->GetGUID() : 0);
3607 p_caster->SetCharm(apply ? pet : NULL);
3608 p_caster->SetClientControl(pet, apply ? 1 : 0);
3609 ((Player*)caster)->SetMover(apply ? pet : NULL);
3611 if(apply)
3613 pet->StopMoving();
3614 pet->GetMotionMaster()->Clear();
3615 pet->GetMotionMaster()->MoveIdle();
3617 else
3619 pet->AttackStop();
3620 pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
3621 pet->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
3625 void Aura::HandleAuraModPetTalentsPoints(bool /*Apply*/, bool Real)
3627 if(!Real)
3628 return;
3630 // Recalculate pet talent points
3631 if (Pet *pet=m_target->GetPet())
3632 pet->InitTalentForLevel();
3635 void Aura::HandleModCharm(bool apply, bool Real)
3637 if(!Real)
3638 return;
3640 // not charm yourself
3641 if(GetCasterGUID() == m_target->GetGUID())
3642 return;
3644 Unit* caster = GetCaster();
3645 if(!caster)
3646 return;
3648 if( apply )
3650 if (m_target->GetCharmerGUID())
3652 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM);
3653 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS);
3656 m_target->SetCharmerGUID(GetCasterGUID());
3657 m_target->setFaction(caster->getFaction());
3658 m_target->CastStop(m_target == caster ? GetId() : 0);
3659 caster->SetCharm(m_target);
3661 m_target->CombatStop();
3662 m_target->DeleteThreatList();
3664 if(m_target->GetTypeId() == TYPEID_UNIT)
3666 ((Creature*)m_target)->AIM_Initialize();
3667 CharmInfo *charmInfo = m_target->InitCharmInfo(m_target);
3668 charmInfo->InitCharmCreateSpells();
3669 charmInfo->SetReactState( REACT_DEFENSIVE );
3671 if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
3673 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3674 if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
3676 // creature with pet number expected have class set
3677 if(m_target->GetByteValue(UNIT_FIELD_BYTES_0, 1)==0)
3679 if(cinfo->unit_class==0)
3680 sLog.outErrorDb("Creature (Entry: %u) have unit_class = 0 but used in charmed spell, that will be result client crash.",cinfo->Entry);
3681 else
3682 sLog.outError("Creature (Entry: %u) have unit_class = %u but at charming have class 0!!! that will be result client crash.",cinfo->Entry,cinfo->unit_class);
3684 m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, CLASS_MAGE);
3687 //just to enable stat window
3688 charmInfo->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
3689 //if charmed two demons the same session, the 2nd gets the 1st one's name
3690 m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
3695 if(caster->GetTypeId() == TYPEID_PLAYER)
3696 ((Player*)caster)->CharmSpellInitialize();
3698 else
3700 m_target->SetCharmerGUID(0);
3702 if(m_target->GetTypeId() == TYPEID_PLAYER)
3703 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3704 else
3706 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3708 // restore faction
3709 if(((Creature*)m_target)->isPet())
3711 if(Unit* owner = m_target->GetOwner())
3712 m_target->setFaction(owner->getFaction());
3713 else if(cinfo)
3714 m_target->setFaction(cinfo->faction_A);
3716 else if(cinfo) // normal creature
3717 m_target->setFaction(cinfo->faction_A);
3719 // restore UNIT_FIELD_BYTES_0
3720 if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3722 // DB must have proper class set in field at loading, not req. restore, including workaround case at apply
3723 // m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, cinfo->unit_class);
3725 if(m_target->GetCharmInfo())
3726 m_target->GetCharmInfo()->SetPetNumber(0, true);
3727 else
3728 sLog.outError("Aura::HandleModCharm: target (GUID: %u TypeId: %u) has a charm aura but no charm info!", m_target->GetGUIDLow(), m_target->GetTypeId());
3732 caster->SetCharm(NULL);
3734 if(caster->GetTypeId() == TYPEID_PLAYER)
3735 ((Player*)caster)->RemovePetActionBar();
3737 if(m_target->GetTypeId() == TYPEID_UNIT)
3739 ((Creature*)m_target)->AIM_Initialize();
3740 if (((Creature*)m_target)->AI())
3741 ((Creature*)m_target)->AI()->AttackedBy(caster);
3746 void Aura::HandleModConfuse(bool apply, bool Real)
3748 if(!Real)
3749 return;
3751 m_target->SetConfused(apply, GetCasterGUID(), GetId());
3754 void Aura::HandleModFear(bool apply, bool Real)
3756 if (!Real)
3757 return;
3759 m_target->SetFeared(apply, GetCasterGUID(), GetId());
3762 void Aura::HandleFeignDeath(bool apply, bool Real)
3764 if(!Real)
3765 return;
3767 m_target->SetFeignDeath(apply, GetCasterGUID(), GetId());
3770 void Aura::HandleAuraModDisarm(bool apply, bool Real)
3772 if(!Real)
3773 return;
3775 if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3776 return;
3778 // not sure for it's correctness
3779 if(apply)
3780 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3781 else
3782 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3784 // only at real add/remove aura
3785 if (m_target->GetTypeId() != TYPEID_PLAYER)
3786 return;
3788 // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3789 if (m_target->IsInFeralForm())
3790 return;
3792 if (apply)
3793 m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3794 else
3795 ((Player *)m_target)->SetRegularAttackTime();
3797 m_target->UpdateDamagePhysical(BASE_ATTACK);
3800 void Aura::HandleAuraModStun(bool apply, bool Real)
3802 if(!Real)
3803 return;
3805 if (apply)
3807 // Frost stun aura -> freeze/unfreeze target
3808 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3809 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3811 m_target->addUnitState(UNIT_STAT_STUNNED);
3812 m_target->SetTargetGUID(0);
3814 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3815 m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3817 // Creature specific
3818 if(m_target->GetTypeId() != TYPEID_PLAYER)
3819 m_target->StopMoving();
3820 else
3822 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEFLAG_NONE);
3823 m_target->SetStandState(UNIT_STAND_STATE_STAND);// in 1.5 client
3826 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3827 data.append(m_target->GetPackGUID());
3828 data << uint32(0);
3829 m_target->SendMessageToSet(&data, true);
3831 // Summon the Naj'entus Spine GameObject on target if spell is Impaling Spine
3832 if(GetId() == 39837)
3834 GameObject* pObj = new GameObject;
3835 if(pObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 185584, m_target->GetMap(), m_target->GetPhaseMask(),
3836 m_target->GetPositionX(), m_target->GetPositionY(), m_target->GetPositionZ(), m_target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
3838 pObj->SetRespawnTime(GetAuraDuration()/IN_MILISECONDS);
3839 pObj->SetSpellId(GetId());
3840 m_target->AddGameObject(pObj);
3841 m_target->GetMap()->Add(pObj);
3843 else
3844 delete pObj;
3847 else
3849 // Frost stun aura -> freeze/unfreeze target
3850 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3852 bool found_another = false;
3853 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3855 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3856 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3858 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3860 found_another = true;
3861 break;
3864 if(found_another)
3865 break;
3868 if(!found_another)
3869 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3872 // Real remove called after current aura remove from lists, check if other similar auras active
3873 if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3874 return;
3876 m_target->clearUnitState(UNIT_STAT_STUNNED);
3877 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3879 if(!m_target->hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
3881 if(m_target->getVictim() && m_target->isAlive())
3882 m_target->SetTargetGUID(m_target->getVictim()->GetGUID());
3884 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3885 data.append(m_target->GetPackGUID());
3886 data << uint32(0);
3887 m_target->SendMessageToSet(&data, true);
3890 // Wyvern Sting
3891 if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & UI64LIT(0x0000100000000000))
3893 Unit* caster = GetCaster();
3894 if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3895 return;
3897 uint32 spell_id = 0;
3899 switch(GetId())
3901 case 19386: spell_id = 24131; break;
3902 case 24132: spell_id = 24134; break;
3903 case 24133: spell_id = 24135; break;
3904 case 27068: spell_id = 27069; break;
3905 case 49011: spell_id = 49009; break;
3906 case 49012: spell_id = 49010; break;
3907 default:
3908 sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3909 return;
3912 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3914 if(!spellInfo)
3915 return;
3917 caster->CastSpell(m_target,spellInfo,true,NULL,this);
3918 return;
3923 void Aura::HandleModStealth(bool apply, bool Real)
3925 if (apply)
3927 // drop flag at stealth in bg
3928 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3930 // only at real aura add
3931 if (Real)
3933 m_target->SetStandFlags(UNIT_STAND_FLAGS_CREEP);
3935 if (m_target->GetTypeId()==TYPEID_PLAYER)
3936 m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3938 // apply only if not in GM invisibility (and overwrite invisibility state)
3939 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3941 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3942 m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3945 // apply full stealth period bonuses only at first stealth aura in stack
3946 if(m_target->GetAurasByType(SPELL_AURA_MOD_STEALTH).size()<=1)
3948 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3949 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3951 // Master of Subtlety
3952 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3954 m_target->RemoveAurasDueToSpell(31666);
3955 int32 bp = (*i)->GetModifier()->m_amount;
3956 m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3958 // Overkill
3959 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3961 m_target->RemoveAurasDueToSpell(58428);
3962 m_target->CastSpell(m_target, 58427, true);
3968 else
3970 // only at real aura remove of _last_ SPELL_AURA_MOD_STEALTH
3971 if (Real && !m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3973 // if no GM invisibility
3974 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3976 m_target->RemoveStandFlags(UNIT_STAND_FLAGS_CREEP);
3978 if (m_target->GetTypeId()==TYPEID_PLAYER)
3979 m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3981 // restore invisibility if any
3982 if (m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3984 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3985 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3987 else
3988 m_target->SetVisibility(VISIBILITY_ON);
3991 // apply delayed talent bonus remover at last stealth aura remove
3992 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3993 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3995 // Master of Subtlety
3996 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3997 m_target->CastSpell(m_target, 31666, true);
3998 // Overkill
3999 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
4000 m_target->CastSpell(m_target, 58428, true);
4006 void Aura::HandleInvisibility(bool apply, bool Real)
4008 if(apply)
4010 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
4012 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
4014 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
4016 // apply glow vision
4017 m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
4021 // apply only if not in GM invisibility and not stealth
4022 if(m_target->GetVisibility() == VISIBILITY_ON)
4024 // Aura not added yet but visibility code expect temporary add aura
4025 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
4026 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
4029 else
4031 // recalculate value at modifier remove (current aura already removed)
4032 m_target->m_invisibilityMask = 0;
4033 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
4034 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
4035 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
4037 // only at real aura remove and if not have different invisibility auras.
4038 if(Real && m_target->m_invisibilityMask == 0)
4040 // remove glow vision
4041 if(m_target->GetTypeId() == TYPEID_PLAYER)
4042 m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
4044 // apply only if not in GM invisibility & not stealthed while invisible
4045 if(m_target->GetVisibility() != VISIBILITY_OFF)
4047 // if have stealth aura then already have stealth visibility
4048 if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
4049 m_target->SetVisibility(VISIBILITY_ON);
4055 void Aura::HandleInvisibilityDetect(bool apply, bool Real)
4057 if(apply)
4059 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
4061 else
4063 // recalculate value at modifier remove (current aura already removed)
4064 m_target->m_detectInvisibilityMask = 0;
4065 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
4066 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
4067 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
4069 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
4070 ((Player*)m_target)->UpdateVisibilityForPlayer();
4073 void Aura::HandleAuraModRoot(bool apply, bool Real)
4075 // only at real add/remove aura
4076 if(!Real)
4077 return;
4079 if (apply)
4081 // Frost root aura -> freeze/unfreeze target
4082 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
4083 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
4085 m_target->addUnitState(UNIT_STAT_ROOT);
4086 m_target->SetTargetGUID(0);
4088 //Save last orientation
4089 if( m_target->getVictim() )
4090 m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
4092 if(m_target->GetTypeId() == TYPEID_PLAYER)
4094 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
4095 data.append(m_target->GetPackGUID());
4096 data << (uint32)2;
4097 m_target->SendMessageToSet(&data, true);
4099 //Clear unit movement flags
4100 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEFLAG_NONE);
4102 else
4103 m_target->StopMoving();
4105 else
4107 // Frost root aura -> freeze/unfreeze target
4108 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
4110 bool found_another = false;
4111 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
4113 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
4114 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
4116 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
4118 found_another = true;
4119 break;
4122 if(found_another)
4123 break;
4126 if(!found_another)
4127 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
4130 // Real remove called after current aura remove from lists, check if other similar auras active
4131 if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
4132 return;
4134 m_target->clearUnitState(UNIT_STAT_ROOT);
4136 if(!m_target->hasUnitState(UNIT_STAT_STUNNED)) // prevent allow move if have also stun effect
4138 if(m_target->getVictim() && m_target->isAlive())
4139 m_target->SetTargetGUID(m_target->getVictim()->GetGUID());
4141 if(m_target->GetTypeId() == TYPEID_PLAYER)
4143 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
4144 data.append(m_target->GetPackGUID());
4145 data << (uint32)2;
4146 m_target->SendMessageToSet(&data, true);
4152 void Aura::HandleAuraModSilence(bool apply, bool Real)
4154 // only at real add/remove aura
4155 if(!Real)
4156 return;
4158 if(apply)
4160 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
4161 // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
4162 for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4163 if (Spell* spell = m_target->GetCurrentSpell(CurrentSpellTypes(i)))
4164 if(spell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
4165 // Stop spells on prepare or casting state
4166 m_target->InterruptSpell(CurrentSpellTypes(i), false);
4168 else
4170 // Real remove called after current aura remove from lists, check if other similar auras active
4171 if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
4172 return;
4174 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
4178 void Aura::HandleModThreat(bool apply, bool Real)
4180 // only at real add/remove aura
4181 if (!Real)
4182 return;
4184 if (!m_target->isAlive())
4185 return;
4187 Unit* caster = GetCaster();
4189 if (!caster || !caster->isAlive())
4190 return;
4192 int level_diff = 0;
4193 int multiplier = 0;
4194 switch (GetId())
4196 // Arcane Shroud
4197 case 26400:
4198 level_diff = m_target->getLevel() - 60;
4199 multiplier = 2;
4200 break;
4201 // The Eye of Diminution
4202 case 28862:
4203 level_diff = m_target->getLevel() - 60;
4204 multiplier = 1;
4205 break;
4208 if (level_diff > 0)
4209 m_modifier.m_amount += multiplier * level_diff;
4211 if (m_target->GetTypeId() == TYPEID_PLAYER)
4212 for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
4213 if (m_modifier.m_miscvalue & int32(1<<x))
4214 ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_modifier.m_amount, apply);
4217 void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
4219 // only at real add/remove aura
4220 if (!Real)
4221 return;
4223 if (!m_target->isAlive() || m_target->GetTypeId() != TYPEID_PLAYER)
4224 return;
4226 Unit* caster = GetCaster();
4228 if (!caster || !caster->isAlive())
4229 return;
4231 float threatMod = apply ? float(m_modifier.m_amount) : float(-m_modifier.m_amount);
4233 m_target->getHostileRefManager().threatAssist(caster, threatMod, GetSpellProto());
4236 void Aura::HandleModTaunt(bool apply, bool Real)
4238 // only at real add/remove aura
4239 if (!Real)
4240 return;
4242 if (!m_target->isAlive() || !m_target->CanHaveThreatList())
4243 return;
4245 Unit* caster = GetCaster();
4247 if (!caster || !caster->isAlive())
4248 return;
4250 if (apply)
4251 m_target->TauntApply(caster);
4252 else
4254 // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
4255 m_target->TauntFadeOut(caster);
4259 /*********************************************************/
4260 /*** MODIFY SPEED ***/
4261 /*********************************************************/
4262 void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real)
4264 // all applied/removed only at real aura add/remove
4265 if(!Real)
4266 return;
4268 m_target->UpdateSpeed(MOVE_RUN, true);
4271 void Aura::HandleAuraModIncreaseMountedSpeed(bool apply, bool Real)
4273 // all applied/removed only at real aura add/remove
4274 if(!Real)
4275 return;
4277 m_target->UpdateSpeed(MOVE_RUN, true);
4279 // Festive Holiday Mount
4280 if (apply && GetSpellProto()->SpellIconID != 1794 && m_target->HasAura(62061))
4281 // Reindeer Transformation
4282 m_target->CastSpell(m_target, 25860, true, NULL, this);
4285 void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
4287 // all applied/removed only at real aura add/remove
4288 if(!Real)
4289 return;
4291 // Enable Fly mode for flying mounts
4292 if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
4294 WorldPacket data;
4295 if(apply)
4296 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
4297 else
4298 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
4299 data.append(m_target->GetPackGUID());
4300 data << uint32(0); // unknown
4301 m_target->SendMessageToSet(&data, true);
4303 //Players on flying mounts must be immune to polymorph
4304 if (m_target->GetTypeId()==TYPEID_PLAYER)
4305 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
4307 // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
4308 if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
4309 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
4311 // Festive Holiday Mount
4312 if (apply && GetSpellProto()->SpellIconID != 1794 && m_target->HasAura(62061))
4313 // Reindeer Transformation
4314 m_target->CastSpell(m_target, 25860, true, NULL, this);
4317 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4320 void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real)
4322 // all applied/removed only at real aura add/remove
4323 if(!Real)
4324 return;
4326 m_target->UpdateSpeed(MOVE_SWIM, true);
4329 void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real)
4331 // all applied/removed only at real aura add/remove
4332 if(!Real)
4333 return;
4335 if (apply)
4337 // Gronn Lord's Grasp, becomes stoned
4338 if (GetId() == 33572)
4340 if (GetStackAmount() >= 5 && !m_target->HasAura(33652))
4341 m_target->CastSpell(m_target, 33652, true);
4345 m_target->UpdateSpeed(MOVE_RUN, true);
4346 m_target->UpdateSpeed(MOVE_SWIM, true);
4347 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4350 void Aura::HandleAuraModUseNormalSpeed(bool /*apply*/, bool Real)
4352 // all applied/removed only at real aura add/remove
4353 if(!Real)
4354 return;
4356 m_target->UpdateSpeed(MOVE_RUN, true);
4357 m_target->UpdateSpeed(MOVE_SWIM, true);
4358 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4361 /*********************************************************/
4362 /*** IMMUNITY ***/
4363 /*********************************************************/
4365 void Aura::HandleModMechanicImmunity(bool apply, bool /*Real*/)
4367 uint32 misc = m_modifier.m_miscvalue;
4368 // Forbearance
4369 // in DBC wrong mechanic immune since 3.0.x
4370 if (GetId() == 25771)
4371 misc = MECHANIC_IMMUNE_SHIELD;
4374 if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4376 uint32 mechanic = 1 << (misc-1);
4378 //immune movement impairment and loss of control
4379 if(GetId()==42292 || GetId()==59752)
4380 mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
4382 m_target->RemoveAurasAtMechanicImmunity(mechanic,GetId());
4385 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,misc,apply);
4387 // Bestial Wrath
4388 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1680)
4390 // The Beast Within cast on owner if talent present
4391 if (Unit* owner = m_target->GetOwner())
4393 // Search talent The Beast Within
4394 Unit::AuraList const& dummyAuras = owner->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE);
4395 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); ++i)
4397 if ((*i)->GetSpellProto()->SpellIconID == 2229)
4399 if (apply)
4400 owner->CastSpell(owner, 34471, true, NULL, this);
4401 else
4402 owner->RemoveAurasDueToSpell(34471);
4403 break;
4410 void Aura::HandleModMechanicImmunityMask(bool apply, bool /*Real*/)
4412 uint32 mechanic = m_modifier.m_miscvalue;
4414 if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4415 m_target->RemoveAurasAtMechanicImmunity(mechanic,GetId());
4417 // check implemented in Unit::IsImmunedToSpell and Unit::IsImmunedToSpellEffect
4420 //this method is called whenever we add / remove aura which gives m_target some imunity to some spell effect
4421 void Aura::HandleAuraModEffectImmunity(bool apply, bool /*Real*/)
4423 // when removing flag aura, handle flag drop
4424 if( !apply && m_target->GetTypeId() == TYPEID_PLAYER
4425 && (GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION) )
4427 if( BattleGround *bg = ((Player*)m_target)->GetBattleGround() )
4428 bg->EventPlayerDroppedFlag(((Player*)m_target));
4431 m_target->ApplySpellImmune(GetId(), IMMUNITY_EFFECT, m_modifier.m_miscvalue, apply);
4434 void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
4436 if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4438 Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
4439 for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
4441 if (auraList.front() != this) // skip itself aura (it already added)
4443 m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
4444 itr = auraList.begin();
4446 else
4447 ++itr;
4451 m_target->ApplySpellImmune(GetId(), IMMUNITY_STATE, m_modifier.m_miscvalue, apply);
4454 void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
4456 m_target->ApplySpellImmune(GetId(), IMMUNITY_SCHOOL, m_modifier.m_miscvalue, apply);
4458 // remove all flag auras (they are positive, but they must be removed when you are immune)
4459 if( this->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4460 && this->GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_DAMAGE_REDUCED_SHIELD )
4461 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
4463 // TODO: optimalize this cycle - use RemoveAurasWithInterruptFlags call or something else
4464 if( Real && apply
4465 && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4466 && IsPositiveSpell(GetId()) ) //Only positive immunity removes auras
4468 uint32 school_mask = m_modifier.m_miscvalue;
4469 Unit::AuraMap& Auras = m_target->GetAuras();
4470 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4472 next = iter;
4473 ++next;
4474 SpellEntry const *spell = iter->second->GetSpellProto();
4475 if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
4476 && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) //Spells unaffected by invulnerability
4477 && !iter->second->IsPositive() //Don't remove positive spells
4478 && spell->Id != GetId() ) //Don't remove self
4480 m_target->RemoveAurasDueToSpell(spell->Id);
4481 if(Auras.empty())
4482 break;
4483 else
4484 next = Auras.begin();
4488 if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
4490 if( apply )
4491 m_target->addUnitState(UNIT_STAT_ISOLATED);
4492 else
4493 m_target->clearUnitState(UNIT_STAT_ISOLATED);
4497 void Aura::HandleAuraModDmgImmunity(bool apply, bool /*Real*/)
4499 m_target->ApplySpellImmune(GetId(), IMMUNITY_DAMAGE, m_modifier.m_miscvalue, apply);
4502 void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
4504 // all applied/removed only at real aura add/remove
4505 if(!Real)
4506 return;
4508 m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
4511 void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
4513 if(!Real)
4514 return;
4516 if(apply)
4518 // some spell have charges by functionality not have its in spell data
4519 switch (GetId())
4521 case 28200: // Ascendance (Talisman of Ascendance trinket)
4522 SetAuraCharges(6);
4523 break;
4524 default: break;
4529 void Aura::HandleAuraModStalked(bool apply, bool /*Real*/)
4531 // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
4532 if(apply)
4533 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4534 else
4535 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4538 /*********************************************************/
4539 /*** PERIODIC ***/
4540 /*********************************************************/
4542 void Aura::HandlePeriodicTriggerSpell(bool apply, bool /*Real*/)
4544 m_isPeriodic = apply;
4546 if (!apply)
4548 switch(m_spellProto->Id)
4550 case 66: // Invisibility
4551 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && m_duration<=0)
4552 m_target->CastSpell(m_target, 32612, true, NULL, this);
4554 return;
4555 case 42783: //Wrath of the Astrom...
4556 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && GetEffIndex() + 1 < 3)
4557 m_target->CastSpell(m_target, m_spellProto->CalculateSimpleValue(GetEffIndex()+1), true);
4558 return;
4559 default:
4560 break;
4565 void Aura::HandlePeriodicTriggerSpellWithValue(bool apply, bool /*Real*/)
4567 m_isPeriodic = apply;
4570 void Aura::HandlePeriodicEnergize(bool apply, bool Real)
4572 if (!Real)
4573 return;
4575 // For prevent double apply bonuses
4576 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4578 if (apply && !loading)
4580 switch (GetId())
4582 case 54833: // Glyph of Innervate (value%/2 of casters base mana)
4584 if (Unit* caster = GetCaster())
4585 m_modifier.m_amount = int32(caster->GetCreateMana() * GetBasePoints() / (200 * GetAuraMaxTicks()));
4586 break;
4589 case 29166: // Innervate (value% of casters base mana)
4591 if (Unit* caster = GetCaster())
4593 // Glyph of Innervate
4594 if (caster->HasAura(54832))
4595 caster->CastSpell(caster,54833,true,NULL,this);
4597 m_modifier.m_amount = int32(caster->GetCreateMana() * GetBasePoints() / (100 * GetAuraMaxTicks()));
4599 break;
4601 case 48391: // Owlkin Frenzy 2% base mana
4602 m_modifier.m_amount = m_target->GetCreateMana() * 2 / 100;
4603 break;
4604 case 57669: // Replenishment (0.2% from max)
4605 case 61782: // Infinite Replenishment
4606 m_modifier.m_amount = m_target->GetMaxPower(POWER_MANA) * 2 / 1000;
4607 break;
4608 default:
4609 break;
4613 m_isPeriodic = apply;
4616 void Aura::HandleAuraPowerBurn(bool apply, bool /*Real*/)
4618 m_isPeriodic = apply;
4621 void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
4623 // spells required only Real aura add/remove
4624 if(!Real)
4625 return;
4627 // For prevent double apply bonuses
4628 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4630 SpellEntry const*spell = GetSpellProto();
4631 switch( spell->SpellFamilyName)
4633 case SPELLFAMILY_ROGUE:
4635 if(!apply)
4637 switch(spell->Id)
4639 // Master of Subtlety
4640 case 31666: m_target->RemoveAurasDueToSpell(31665); break;
4641 // Overkill
4642 case 58428: m_target->RemoveAurasDueToSpell(58427); break;
4645 break;
4647 case SPELLFAMILY_HUNTER:
4649 Unit* caster = GetCaster();
4651 // Explosive Shot
4652 if (apply && !loading && caster)
4653 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 14 / 100);
4654 break;
4658 m_isPeriodic = apply;
4661 void Aura::HandlePeriodicHeal(bool apply, bool /*Real*/)
4663 m_isPeriodic = apply;
4666 void Aura::HandlePeriodicDamage(bool apply, bool Real)
4668 // spells required only Real aura add/remove
4669 if(!Real)
4670 return;
4672 m_isPeriodic = apply;
4674 // For prevent double apply bonuses
4675 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4677 // Custom damage calculation after
4678 if (apply)
4680 if(loading)
4681 return;
4683 Unit *caster = GetCaster();
4684 if (!caster)
4685 return;
4687 switch (m_spellProto->SpellFamilyName)
4689 case SPELLFAMILY_GENERIC:
4691 // Pounce Bleed
4692 if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual[0] == 0 )
4694 // $AP*0.18/6 bonus per tick
4695 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4696 return;
4698 break;
4700 case SPELLFAMILY_WARRIOR:
4702 // Rend
4703 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000020))
4705 // $0.2*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4706 float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4707 int32 mws = caster->GetAttackTime(BASE_ATTACK);
4708 float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4709 float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4710 m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.2f);
4711 return;
4713 break;
4715 case SPELLFAMILY_DRUID:
4717 // Rake
4718 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellProto->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
4720 // $AP*0.18/3 bonus per tick
4721 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 6 / 100);
4722 return;
4724 // Lacerate
4725 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000010000000000))
4727 // $AP*0.05/5 bonus per tick
4728 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4729 return;
4731 // Rip
4732 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000800000))
4734 // 0.01*$AP*cp
4735 if (caster->GetTypeId() != TYPEID_PLAYER)
4736 return;
4738 uint8 cp = ((Player*)caster)->GetComboPoints();
4740 // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4741 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4742 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4744 if((*itr)->GetId()==34241)
4746 m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4747 break;
4750 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4751 return;
4753 // Lock Jaw
4754 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
4756 // 0.15*$AP
4757 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 15 / 100);
4758 return;
4760 break;
4762 case SPELLFAMILY_ROGUE:
4764 // Rupture
4765 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000100000))
4767 if (caster->GetTypeId() != TYPEID_PLAYER)
4768 return;
4769 //1 point : ${($m1+$b1*1+0.015*$AP)*4} damage over 8 secs
4770 //2 points: ${($m1+$b1*2+0.024*$AP)*5} damage over 10 secs
4771 //3 points: ${($m1+$b1*3+0.03*$AP)*6} damage over 12 secs
4772 //4 points: ${($m1+$b1*4+0.03428571*$AP)*7} damage over 14 secs
4773 //5 points: ${($m1+$b1*5+0.0375*$AP)*8} damage over 16 secs
4774 float AP_per_combo[6] = {0.0f, 0.015f, 0.024f, 0.03f, 0.03428571f, 0.0375f};
4775 uint8 cp = ((Player*)caster)->GetComboPoints();
4776 if (cp > 5) cp = 5;
4777 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * AP_per_combo[cp]);
4778 return;
4780 // Garrote
4781 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000000100))
4783 // $AP*0.07 bonus per tick
4784 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 7 / 100);
4785 return;
4787 // Deadly Poison
4788 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000010000))
4790 // 0.12*$AP / 4 * amount of stack
4791 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 * GetStackAmount() / 100);
4792 return;
4794 break;
4796 case SPELLFAMILY_HUNTER:
4798 // Serpent Sting
4799 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000004000))
4801 // $RAP*0.2/5 bonus per tick
4802 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 0.2 / 5);
4803 return;
4805 // Immolation Trap
4806 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) && m_spellProto->SpellIconID == 678)
4808 // $RAP*0.1/5 bonus per tick
4809 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4810 return;
4812 break;
4814 case SPELLFAMILY_PALADIN:
4816 // Holy Vengeance / Blood Corruption
4817 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000080000000000) && m_spellProto->SpellVisual[0] == 7902)
4819 // AP * 0.025 + SPH * 0.013 bonus per tick
4820 float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4821 int32 holy = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) +
4822 caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellProto), GetTarget());
4823 m_modifier.m_amount += int32(GetStackAmount()) * (int32(ap * 0.025f) + int32(holy * 13 / 1000));
4824 return;
4826 break;
4828 default:
4829 break;
4832 // remove time effects
4833 else
4835 // Parasitic Shadowfiend - handle summoning of two Shadowfiends on DoT expire
4836 if(m_spellProto->Id == 41917)
4837 m_target->CastSpell(m_target, 41915, true);
4841 void Aura::HandlePeriodicDamagePCT(bool apply, bool /*Real*/)
4843 m_isPeriodic = apply;
4846 void Aura::HandlePeriodicLeech(bool apply, bool /*Real*/)
4848 m_isPeriodic = apply;
4851 void Aura::HandlePeriodicManaLeech(bool apply, bool /*Real*/)
4853 m_isPeriodic = apply;
4856 void Aura::HandlePeriodicHealthFunnel(bool apply, bool /*Real*/)
4858 m_isPeriodic = apply;
4861 /*********************************************************/
4862 /*** MODIFY STATS ***/
4863 /*********************************************************/
4865 /********************************/
4866 /*** RESISTANCE ***/
4867 /********************************/
4869 void Aura::HandleAuraModResistanceExclusive(bool apply, bool /*Real*/)
4871 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4873 if(m_modifier.m_miscvalue & int32(1<<x))
4875 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4876 if(m_target->GetTypeId() == TYPEID_PLAYER)
4877 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4882 void Aura::HandleAuraModResistance(bool apply, bool /*Real*/)
4884 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4886 if(m_modifier.m_miscvalue & int32(1<<x))
4888 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4889 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4890 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4895 void Aura::HandleAuraModBaseResistancePCT(bool apply, bool /*Real*/)
4897 // only players have base stats
4898 if(m_target->GetTypeId() != TYPEID_PLAYER)
4900 //pets only have base armor
4901 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4902 m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4904 else
4906 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4908 if(m_modifier.m_miscvalue & int32(1<<x))
4909 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4914 void Aura::HandleModResistancePercent(bool apply, bool /*Real*/)
4916 for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4918 if(m_modifier.m_miscvalue & int32(1<<i))
4920 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4921 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4923 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, m_modifier.m_amount, apply);
4924 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, m_modifier.m_amount, apply);
4930 void Aura::HandleModBaseResistance(bool apply, bool /*Real*/)
4932 // only players have base stats
4933 if(m_target->GetTypeId() != TYPEID_PLAYER)
4935 //only pets have base stats
4936 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4937 m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4939 else
4941 for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4942 if(m_modifier.m_miscvalue & (1<<i))
4943 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4947 /********************************/
4948 /*** STAT ***/
4949 /********************************/
4951 void Aura::HandleAuraModStat(bool apply, bool /*Real*/)
4953 if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4955 sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4956 return;
4959 for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4961 // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4962 if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4964 //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4965 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4966 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4967 m_target->ApplyStatBuffMod(Stats(i), m_modifier.m_amount, apply);
4972 void Aura::HandleModPercentStat(bool apply, bool /*Real*/)
4974 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4976 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4977 return;
4980 // only players have base stats
4981 if (m_target->GetTypeId() != TYPEID_PLAYER)
4982 return;
4984 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4986 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4987 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4991 void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool /*Real*/)
4993 if(m_target->GetTypeId() != TYPEID_PLAYER)
4994 return;
4996 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4997 // This information for client side use only
4998 // Recalculate bonus
4999 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
5002 void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool /*Real*/)
5004 if(m_target->GetTypeId() != TYPEID_PLAYER)
5005 return;
5007 // Recalculate bonus
5008 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
5011 void Aura::HandleAuraModDispelResist(bool apply, bool Real)
5013 if(!Real || !apply)
5014 return;
5016 if(GetId() == 33206)
5017 m_target->CastSpell(m_target, 44416, true, NULL, this, GetCasterGUID());
5020 void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool /*Real*/)
5022 if(m_target->GetTypeId() != TYPEID_PLAYER)
5023 return;
5025 // Magic damage modifiers implemented in Unit::SpellDamageBonus
5026 // This information for client side use only
5027 // Recalculate bonus
5028 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
5031 void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool /*Real*/)
5033 if(m_target->GetTypeId() != TYPEID_PLAYER)
5034 return;
5036 // Recalculate bonus
5037 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
5040 void Aura::HandleModHealingDone(bool /*apply*/, bool /*Real*/)
5042 if(m_target->GetTypeId() != TYPEID_PLAYER)
5043 return;
5044 // implemented in Unit::SpellHealingBonus
5045 // this information is for client side only
5046 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
5049 void Aura::HandleModTotalPercentStat(bool apply, bool /*Real*/)
5051 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
5053 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
5054 return;
5057 //save current and max HP before applying aura
5058 uint32 curHPValue = m_target->GetHealth();
5059 uint32 maxHPValue = m_target->GetMaxHealth();
5061 for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
5063 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
5065 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
5066 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
5067 m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
5071 //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
5072 if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
5074 // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
5075 uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
5076 m_target->SetHealth(newHPValue);
5080 void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool /*Real*/)
5082 if(m_target->GetTypeId() != TYPEID_PLAYER)
5083 return;
5085 if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
5087 // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
5088 // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
5089 sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
5090 return;
5093 // Recalculate Armor
5094 m_target->UpdateArmor();
5097 /********************************/
5098 /*** HEAL & ENERGIZE ***/
5099 /********************************/
5100 void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool /*Real*/)
5102 m_isPeriodic = apply;
5105 void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool /*Real*/)
5107 if(m_modifier.periodictime == 0)
5108 m_modifier.periodictime = 1000;
5110 m_periodicTimer = m_modifier.periodictime;
5111 m_isPeriodic = apply;
5114 void Aura::HandleModRegen(bool apply, bool /*Real*/) // eating
5116 if(m_modifier.periodictime == 0)
5117 m_modifier.periodictime = 5000;
5119 m_periodicTimer = 5000;
5120 m_isPeriodic = apply;
5123 void Aura::HandleModPowerRegen(bool apply, bool Real) // drinking
5125 if (!Real)
5126 return;
5128 Powers pt = m_target->getPowerType();
5129 if(m_modifier.periodictime == 0)
5131 // Anger Management (only spell use this aura for rage)
5132 if (pt == POWER_RAGE)
5133 m_modifier.periodictime = 3000;
5134 else
5135 m_modifier.periodictime = 2000;
5138 m_periodicTimer = 5000;
5140 if (m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
5141 ((Player*)m_target)->UpdateManaRegen();
5143 m_isPeriodic = apply;
5146 void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real)
5148 // spells required only Real aura add/remove
5149 if(!Real)
5150 return;
5152 if (m_target->GetTypeId() != TYPEID_PLAYER)
5153 return;
5155 // Update manaregen value
5156 if (m_modifier.m_miscvalue == POWER_MANA)
5157 ((Player*)m_target)->UpdateManaRegen();
5160 void Aura::HandleModManaRegen(bool /*apply*/, bool Real)
5162 // spells required only Real aura add/remove
5163 if(!Real)
5164 return;
5166 if (m_target->GetTypeId() != TYPEID_PLAYER)
5167 return;
5169 //Note: an increase in regen does NOT cause threat.
5170 ((Player*)m_target)->UpdateManaRegen();
5173 void Aura::HandleComprehendLanguage(bool apply, bool /*Real*/)
5175 if(apply)
5176 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
5177 else
5178 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
5181 void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
5183 // Special case with temporary increase max/current health
5184 switch(GetId())
5186 case 12976: // Warrior Last Stand triggered spell
5187 case 28726: // Nightmare Seed ( Nightmare Seed )
5188 case 34511: // Valor (Bulwark of Kings, Bulwark of the Ancient Kings)
5189 case 44055: case 55915: case 55917: case 67596: // Tremendous Fortitude (Battlemaster's Alacrity)
5190 case 50322: // Survival Instincts
5191 case 54443: // Demonic Empowerment (Voidwalker)
5193 if(Real)
5195 if(apply)
5197 // Demonic Empowerment (Voidwalker) - special case, store percent in data
5198 // recalculate to full amount at apply for proper remove
5199 if (GetId() == 54443)
5200 m_modifier.m_amount = m_target->GetMaxHealth() * m_modifier.m_amount / 100;
5202 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5203 m_target->ModifyHealth(m_modifier.m_amount);
5205 else
5207 if (int32(m_target->GetHealth()) > m_modifier.m_amount)
5208 m_target->ModifyHealth(-m_modifier.m_amount);
5209 else
5210 m_target->SetHealth(1);
5211 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5214 return;
5218 // generic case
5219 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5222 void Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool /*Real*/)
5224 uint32 oldhealth = m_target->GetHealth();
5225 double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
5227 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5229 // refresh percentage
5230 if(oldhealth > 0)
5232 uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
5233 if(newhealth==0)
5234 newhealth = 1;
5236 m_target->SetHealth(newhealth);
5240 void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
5242 Powers powerType = m_target->getPowerType();
5243 if(int32(powerType) != m_modifier.m_miscvalue)
5244 return;
5246 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5248 // Special case with temporary increase max/current power (percent)
5249 if (GetId()==64904) // Hymn of Hope
5251 if(Real)
5253 uint32 val = m_target->GetPower(powerType);
5254 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5255 m_target->SetPower(powerType, apply ? val*(100+m_modifier.m_amount)/100 : val*100/(100+m_modifier.m_amount));
5257 return;
5260 // generic flat case
5261 m_target->HandleStatModifier(unitMod, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5264 void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool /*Real*/)
5266 Powers powerType = m_target->getPowerType();
5267 if(int32(powerType) != m_modifier.m_miscvalue)
5268 return;
5270 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5272 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5275 void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool /*Real*/)
5277 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
5280 void Aura::HandleAuraIncreaseBaseHealthPercent(bool apply, bool /*Real*/)
5282 m_target->HandleStatModifier(UNIT_MOD_HEALTH, BASE_PCT, float(m_modifier.m_amount), apply);
5285 /********************************/
5286 /*** FIGHT ***/
5287 /********************************/
5289 void Aura::HandleAuraModParryPercent(bool /*apply*/, bool /*Real*/)
5291 if(m_target->GetTypeId() != TYPEID_PLAYER)
5292 return;
5294 ((Player*)m_target)->UpdateParryPercentage();
5297 void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool /*Real*/)
5299 if(m_target->GetTypeId() != TYPEID_PLAYER)
5300 return;
5302 ((Player*)m_target)->UpdateDodgePercentage();
5303 //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
5306 void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool /*Real*/)
5308 if(m_target->GetTypeId() != TYPEID_PLAYER)
5309 return;
5311 ((Player*)m_target)->UpdateBlockPercentage();
5312 //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
5315 void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real)
5317 // spells required only Real aura add/remove
5318 if(!Real)
5319 return;
5321 if(m_target->GetTypeId() != TYPEID_PLAYER)
5322 return;
5324 ((Player*)m_target)->UpdateManaRegen();
5327 void Aura::HandleAuraModCritPercent(bool apply, bool Real)
5329 if(m_target->GetTypeId() != TYPEID_PLAYER)
5330 return;
5332 // apply item specific bonuses for already equipped weapon
5333 if(Real)
5335 for(int i = 0; i < MAX_ATTACK; ++i)
5336 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i),true,false))
5337 ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem, WeaponAttackType(i), this, apply);
5340 // mods must be applied base at equipped weapon class and subclass comparison
5341 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5342 // m_modifier.m_miscvalue comparison with item generated damage types
5344 if (GetSpellProto()->EquippedItemClass == -1)
5346 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5347 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5348 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5350 else
5352 // done in Player::_ApplyWeaponDependentAuraMods
5356 void Aura::HandleModHitChance(bool apply, bool /*Real*/)
5358 if(m_target->GetTypeId() == TYPEID_PLAYER)
5360 ((Player*)m_target)->UpdateMeleeHitChances();
5361 ((Player*)m_target)->UpdateRangedHitChances();
5363 else
5365 m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5366 m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5370 void Aura::HandleModSpellHitChance(bool apply, bool /*Real*/)
5372 if(m_target->GetTypeId() == TYPEID_PLAYER)
5374 ((Player*)m_target)->UpdateSpellHitChances();
5376 else
5378 m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
5382 void Aura::HandleModSpellCritChance(bool apply, bool Real)
5384 // spells required only Real aura add/remove
5385 if(!Real)
5386 return;
5388 if(m_target->GetTypeId() == TYPEID_PLAYER)
5390 ((Player*)m_target)->UpdateAllSpellCritChances();
5392 else
5394 m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
5398 void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real)
5400 // spells required only Real aura add/remove
5401 if(!Real)
5402 return;
5404 if(m_target->GetTypeId() != TYPEID_PLAYER)
5405 return;
5407 for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
5408 if (m_modifier.m_miscvalue & (1<<school))
5409 ((Player*)m_target)->UpdateSpellCritChance(school);
5412 /********************************/
5413 /*** ATTACK SPEED ***/
5414 /********************************/
5416 void Aura::HandleModCastingSpeed(bool apply, bool /*Real*/)
5418 m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
5421 void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool /*Real*/)
5423 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5424 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5425 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5428 void Aura::HandleModCombatSpeedPct(bool apply, bool /*Real*/)
5430 m_target->ApplyCastTimePercentMod(m_modifier.m_amount, apply);
5431 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5432 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5433 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5436 void Aura::HandleModAttackSpeed(bool apply, bool /*Real*/)
5438 if(!m_target->isAlive() )
5439 return;
5441 m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
5444 void Aura::HandleHaste(bool apply, bool /*Real*/)
5446 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5447 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5448 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5451 void Aura::HandleAuraModRangedHaste(bool apply, bool /*Real*/)
5453 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5456 void Aura::HandleRangedAmmoHaste(bool apply, bool /*Real*/)
5458 if(m_target->GetTypeId() != TYPEID_PLAYER)
5459 return;
5460 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
5463 /********************************/
5464 /*** ATTACK POWER ***/
5465 /********************************/
5467 void Aura::HandleAuraModAttackPower(bool apply, bool /*Real*/)
5469 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5472 void Aura::HandleAuraModRangedAttackPower(bool apply, bool /*Real*/)
5474 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5475 return;
5477 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5480 void Aura::HandleAuraModAttackPowerPercent(bool apply, bool /*Real*/)
5482 //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
5483 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
5486 void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool /*Real*/)
5488 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5489 return;
5491 //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
5492 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5495 void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5497 // spells required only Real aura add/remove
5498 if(!Real)
5499 return;
5501 // Recalculate bonus
5502 if(m_target->GetTypeId() == TYPEID_PLAYER && !(m_target->getClassMask() & CLASSMASK_WAND_USERS))
5503 ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
5506 void Aura::HandleAuraModAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5508 // spells required only Real aura add/remove
5509 if(!Real)
5510 return;
5512 // Recalculate bonus
5513 if(m_target->GetTypeId() == TYPEID_PLAYER)
5514 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5517 void Aura::HandleAuraModAttackPowerOfArmor(bool /*apply*/, bool Real)
5519 // spells required only Real aura add/remove
5520 if(!Real)
5521 return;
5523 // Recalculate bonus
5524 if(m_target->GetTypeId() == TYPEID_PLAYER)
5525 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5527 /********************************/
5528 /*** DAMAGE BONUS ***/
5529 /********************************/
5530 void Aura::HandleModDamageDone(bool apply, bool Real)
5532 // apply item specific bonuses for already equipped weapon
5533 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5535 for(int i = 0; i < MAX_ATTACK; ++i)
5536 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i),true,false))
5537 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5540 // m_modifier.m_miscvalue is bitmask of spell schools
5541 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5542 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
5543 // 127 - full bitmask any damages
5545 // mods must be applied base at equipped weapon class and subclass comparison
5546 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5547 // m_modifier.m_miscvalue comparison with item generated damage types
5549 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5551 // apply generic physical damage bonuses including wand case
5552 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5554 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5555 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5556 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5558 else
5560 // done in Player::_ApplyWeaponDependentAuraMods
5563 if(m_target->GetTypeId() == TYPEID_PLAYER)
5565 if(m_positive)
5566 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS, m_modifier.m_amount, apply);
5567 else
5568 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG, m_modifier.m_amount, apply);
5572 // Skip non magic case for speedup
5573 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5574 return;
5576 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5578 // wand magic case (skip generic to all item spell bonuses)
5579 // done in Player::_ApplyWeaponDependentAuraMods
5581 // Skip item specific requirements for not wand magic damage
5582 return;
5585 // Magic damage modifiers implemented in Unit::SpellDamageBonus
5586 // This information for client side use only
5587 if(m_target->GetTypeId() == TYPEID_PLAYER)
5589 if(m_positive)
5591 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5593 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5594 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, m_modifier.m_amount, apply);
5597 else
5599 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5601 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5602 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, m_modifier.m_amount, apply);
5605 Pet* pet = m_target->GetPet();
5606 if(pet)
5607 pet->UpdateAttackPowerAndDamage();
5611 void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5613 sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5615 // apply item specific bonuses for already equipped weapon
5616 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5618 for(int i = 0; i < MAX_ATTACK; ++i)
5619 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i),true,false))
5620 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5623 // m_modifier.m_miscvalue is bitmask of spell schools
5624 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5625 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5626 // 127 - full bitmask any damages
5628 // mods must be applied base at equipped weapon class and subclass comparison
5629 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5630 // m_modifier.m_miscvalue comparison with item generated damage types
5632 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5634 // apply generic physical damage bonuses including wand case
5635 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5637 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5638 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5639 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5641 else
5643 // done in Player::_ApplyWeaponDependentAuraMods
5645 // For show in client
5646 if(m_target->GetTypeId() == TYPEID_PLAYER)
5647 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT, m_modifier.m_amount/100.0f, apply);
5650 // Skip non magic case for speedup
5651 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5652 return;
5654 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5656 // wand magic case (skip generic to all item spell bonuses)
5657 // done in Player::_ApplyWeaponDependentAuraMods
5659 // Skip item specific requirements for not wand magic damage
5660 return;
5663 // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5664 // Send info to client
5665 if(m_target->GetTypeId() == TYPEID_PLAYER)
5666 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5667 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT + i, m_modifier.m_amount/100.0f, apply);
5670 void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5672 // spells required only Real aura add/remove
5673 if(!Real)
5674 return;
5676 sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5678 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5681 /********************************/
5682 /*** POWER COST ***/
5683 /********************************/
5685 void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5687 // spells required only Real aura add/remove
5688 if(!Real)
5689 return;
5691 float amount = m_modifier.m_amount/100.0f;
5692 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5693 if(m_modifier.m_miscvalue & (1<<i))
5694 m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + i, amount, apply);
5697 void Aura::HandleModPowerCost(bool apply, bool Real)
5699 // spells required only Real aura add/remove
5700 if(!Real)
5701 return;
5703 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5704 if(m_modifier.m_miscvalue & (1<<i))
5705 m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + i, m_modifier.m_amount, apply);
5708 void Aura::HandleNoReagentUseAura(bool /*Apply*/, bool Real)
5710 // spells required only Real aura add/remove
5711 if(!Real)
5712 return;
5713 if(m_target->GetTypeId() != TYPEID_PLAYER)
5714 return;
5715 uint32 mask[3] = {0, 0, 0};
5716 Unit::AuraList const& noReagent = m_target->GetAurasByType(SPELL_AURA_NO_REAGENT_USE);
5717 for(Unit::AuraList::const_iterator i = noReagent.begin(); i != noReagent.end(); ++i)
5719 uint32 const *ptr = (*i)->getAuraSpellClassMask();
5720 mask[0] |= ptr[0];
5721 mask[1] |= ptr[1];
5722 mask[2] |= ptr[2];
5725 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+0, mask[0]);
5726 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+1, mask[1]);
5727 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+2, mask[2]);
5730 /*********************************************************/
5731 /*** OTHERS ***/
5732 /*********************************************************/
5734 void Aura::HandleShapeshiftBoosts(bool apply)
5736 uint32 spellId1 = 0;
5737 uint32 spellId2 = 0;
5738 uint32 HotWSpellId = 0;
5739 uint32 MasterShaperSpellId = 0;
5741 uint32 form = GetModifier()->m_miscvalue;
5743 switch(form)
5745 case FORM_CAT:
5746 spellId1 = 3025;
5747 HotWSpellId = 24900;
5748 MasterShaperSpellId = 48420;
5749 break;
5750 case FORM_TREE:
5751 spellId1 = 5420;
5752 spellId2 = 34123;
5753 MasterShaperSpellId = 48422;
5754 break;
5755 case FORM_TRAVEL:
5756 spellId1 = 5419;
5757 break;
5758 case FORM_AQUA:
5759 spellId1 = 5421;
5760 break;
5761 case FORM_BEAR:
5762 spellId1 = 1178;
5763 spellId2 = 21178;
5764 HotWSpellId = 24899;
5765 MasterShaperSpellId = 48418;
5766 break;
5767 case FORM_DIREBEAR:
5768 spellId1 = 9635;
5769 spellId2 = 21178;
5770 HotWSpellId = 24899;
5771 MasterShaperSpellId = 48418;
5772 break;
5773 case FORM_BATTLESTANCE:
5774 spellId1 = 21156;
5775 break;
5776 case FORM_DEFENSIVESTANCE:
5777 spellId1 = 7376;
5778 break;
5779 case FORM_BERSERKERSTANCE:
5780 spellId1 = 7381;
5781 break;
5782 case FORM_MOONKIN:
5783 spellId1 = 24905;
5784 MasterShaperSpellId = 48421;
5785 break;
5786 case FORM_FLIGHT:
5787 spellId1 = 33948;
5788 spellId2 = 34764;
5789 break;
5790 case FORM_FLIGHT_EPIC:
5791 spellId1 = 40122;
5792 spellId2 = 40121;
5793 break;
5794 case FORM_METAMORPHOSIS:
5795 spellId1 = 54817;
5796 spellId2 = 54879;
5797 break;
5798 case FORM_SPIRITOFREDEMPTION:
5799 spellId1 = 27792;
5800 spellId2 = 27795; // must be second, this important at aura remove to prevent to early iterator invalidation.
5801 break;
5802 case FORM_SHADOW:
5803 spellId1 = 49868;
5805 if(m_target->GetTypeId() == TYPEID_PLAYER) // Spell 49868 have same category as main form spell and share cooldown
5806 ((Player*)m_target)->RemoveSpellCooldown(49868);
5807 break;
5808 case FORM_GHOSTWOLF:
5809 spellId1 = 67116;
5810 break;
5811 case FORM_AMBIENT:
5812 case FORM_GHOUL:
5813 case FORM_STEALTH:
5814 case FORM_CREATURECAT:
5815 case FORM_CREATUREBEAR:
5816 break;
5819 if(apply)
5821 if (spellId1)
5822 m_target->CastSpell(m_target, spellId1, true, NULL, this );
5823 if (spellId2)
5824 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5826 if (m_target->GetTypeId() == TYPEID_PLAYER)
5828 const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5829 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5831 if (itr->second->state == PLAYERSPELL_REMOVED) continue;
5832 if (itr->first==spellId1 || itr->first==spellId2) continue;
5833 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5834 if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7))))
5835 continue;
5836 if (spellInfo->Stances & (1<<(form-1)))
5837 m_target->CastSpell(m_target, itr->first, true, NULL, this);
5840 // Master Shapeshifter
5841 if (MasterShaperSpellId)
5843 Unit::AuraList const& ShapeShifterAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5844 for(Unit::AuraList::const_iterator i = ShapeShifterAuras.begin(); i != ShapeShifterAuras.end(); i++)
5846 if ((*i)->GetSpellProto()->SpellIconID == 2851)
5848 int32 ShiftMod = (*i)->GetModifier()->m_amount;
5849 m_target->CastCustomSpell(m_target, MasterShaperSpellId, &ShiftMod, NULL, NULL, true);
5850 break;
5855 // Leader of the Pack
5856 if (((Player*)m_target)->HasSpell(17007))
5858 SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5859 if (spellInfo && spellInfo->Stances & (1<<(form-1)))
5860 m_target->CastSpell(m_target, 24932, true, NULL, this);
5863 // Savage Roar
5864 if (form == FORM_CAT && ((Player*)m_target)->HasAura(52610))
5865 m_target->CastSpell(m_target, 62071, true);
5867 // Improved Moonkin Form
5868 if (form == FORM_MOONKIN)
5870 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5871 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); i++)
5873 if ((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_DRUID &&
5874 (*i)->GetSpellProto()->SpellIconID == 2855)
5876 uint32 spell_id = 0;
5877 switch((*i)->GetId())
5879 case 48384:spell_id=50170;break;//Rank 1
5880 case 48395:spell_id=50171;break;//Rank 2
5881 case 48396:spell_id=50172;break;//Rank 3
5882 default:
5883 sLog.outError("Aura::HandleShapeshiftBoosts: Not handled rank of IMF (Spell: %u)",(*i)->GetId());
5884 break;
5887 if(spell_id)
5888 m_target->CastSpell(m_target, spell_id, true, NULL, this);
5889 break;
5894 // Heart of the Wild
5895 if (HotWSpellId)
5897 Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5898 for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5900 if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5902 int32 HotWMod = (*i)->GetModifier()->m_amount;
5903 if(GetModifier()->m_miscvalue == FORM_CAT)
5904 HotWMod /= 2;
5906 m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5907 break;
5913 else
5915 if(spellId1)
5916 m_target->RemoveAurasDueToSpell(spellId1);
5917 if(spellId2)
5918 m_target->RemoveAurasDueToSpell(spellId2);
5919 if(MasterShaperSpellId)
5920 m_target->RemoveAurasDueToSpell(MasterShaperSpellId);
5922 Unit::AuraMap& tAuras = m_target->GetAuras();
5923 for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5925 if (itr->second->IsRemovedOnShapeLost())
5927 m_target->RemoveAurasDueToSpell(itr->second->GetId());
5928 itr = tAuras.begin();
5930 else
5931 ++itr;
5936 void Aura::HandleSpellSpecificBoosts(bool apply)
5938 bool cast_at_remove = false; // if spell must be casted at last aura from stack remove
5939 uint32 spellId1 = 0;
5940 uint32 spellId2 = 0;
5941 uint32 spellId3 = 0;
5942 uint32 spellId4 = 0;
5944 switch(GetSpellProto()->SpellFamilyName)
5946 case SPELLFAMILY_GENERIC:
5948 // Illusionary Barrier
5949 if(GetId() == 57350 && !apply && m_target->getPowerType() == POWER_MANA)
5951 cast_at_remove = true;
5952 spellId1 = 60242; // Darkmoon Card: Illusion
5954 else
5955 return;
5956 break;
5958 case SPELLFAMILY_MAGE:
5960 // Ice Barrier (non stacking from one caster)
5961 if (m_spellProto->SpellIconID == 32)
5963 if (!apply && (m_removeMode == AURA_REMOVE_BY_DISPEL || (m_removeMode == AURA_REMOVE_BY_DEFAULT && !GetModifier()->m_amount)))
5965 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5966 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
5968 // Shattered Barrier
5969 if ((*itr)->GetSpellProto()->SpellIconID == 2945)
5971 cast_at_remove = true;
5972 // first rank have 50% chance
5973 if ((*itr)->GetId() != 44745 || roll_chance_i(50))
5974 spellId1 = 55080;
5975 break;
5979 else
5980 return;
5982 // Combustion (remove triggered aura stack)
5983 else if (m_spellProto->Id == 11129)
5985 if(!apply)
5986 spellId1 = 28682;
5987 else
5988 return;
5990 // Combustion (remove main aura)
5991 else if (m_spellProto->Id == 28682)
5993 if(!apply)
5994 spellId1 = 11129;
5995 else
5996 return;
5998 else
5999 return;
6000 break;
6002 case SPELLFAMILY_WARRIOR:
6004 if(!apply)
6006 // Remove Blood Frenzy only if target no longer has any Deep Wound or Rend (applying is handled by procs)
6007 if (GetSpellProto()->Mechanic != MECHANIC_BLEED)
6008 return;
6010 // If target still has one of Warrior's bleeds, do nothing
6011 Unit::AuraList const& PeriodicDamage = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
6012 for(Unit::AuraList::const_iterator i = PeriodicDamage.begin(); i != PeriodicDamage.end(); ++i)
6013 if( (*i)->GetCasterGUID() == GetCasterGUID() &&
6014 (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARRIOR &&
6015 (*i)->GetSpellProto()->Mechanic == MECHANIC_BLEED)
6016 return;
6018 spellId1 = 30069; // Blood Frenzy (Rank 1)
6019 spellId2 = 30070; // Blood Frenzy (Rank 2)
6021 break;
6023 case SPELLFAMILY_WARLOCK:
6025 // Fear (non stacking)
6026 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000040000000000))
6028 if(!apply)
6030 Unit* caster = GetCaster();
6031 if(!caster)
6032 return;
6034 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6035 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
6037 SpellEntry const* dummyEntry = (*itr)->GetSpellProto();
6038 // Improved Fear
6039 if (dummyEntry->SpellFamilyName == SPELLFAMILY_WARLOCK && dummyEntry->SpellIconID == 98)
6041 cast_at_remove = true;
6042 switch((*itr)->GetModifier()->m_amount)
6044 // Rank 1
6045 case 0: spellId1 = 60946; break;
6046 // Rank 1
6047 case 1: spellId1 = 60947; break;
6049 break;
6053 else
6054 return;
6056 // Shadowflame (DoT)
6057 else if (m_spellProto->SpellFamilyFlags2 & 0x00000002)
6059 // Glyph of Shadowflame
6060 Unit* caster;
6061 if(!apply)
6062 spellId1 = 63311;
6063 else if(((caster = GetCaster())) && caster->HasAura(63310))
6064 spellId1 = 63311;
6065 else
6066 return;
6068 else
6069 return;
6070 break;
6072 case SPELLFAMILY_PRIEST:
6074 // Shadow Word: Pain (need visual check fro skip improvement talent) or Vampiric Touch
6075 if (m_spellProto->SpellIconID == 234 && m_spellProto->SpellVisual[0] || m_spellProto->SpellIconID == 2213)
6077 if (!apply && m_removeMode == AURA_REMOVE_BY_DISPEL)
6079 Unit* caster = GetCaster();
6080 if(!caster)
6081 return;
6083 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6084 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
6086 // Shadow Affinity
6087 if ((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST
6088 && (*itr)->GetSpellProto()->SpellIconID == 178)
6090 // custom cast code
6091 int32 basepoints0 = (*itr)->GetModifier()->m_amount * caster->GetCreateMana() / 100;
6092 caster->CastCustomSpell(caster, 64103, &basepoints0, NULL, NULL, true, NULL, this);
6093 return;
6097 else
6098 return;
6101 switch(GetId())
6103 // Abolish Disease (remove 1 more poison effect with Body and Soul)
6104 case 552:
6106 if(apply)
6108 int chance =0;
6109 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
6110 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
6112 SpellEntry const* dummyEntry = (*itr)->GetSpellProto();
6113 // Body and Soul (talent ranks)
6114 if (dummyEntry->SpellFamilyName == SPELLFAMILY_PRIEST && dummyEntry->SpellIconID == 2218 &&
6115 dummyEntry->SpellVisual[0]==0)
6117 chance = (*itr)->GetSpellProto()->CalculateSimpleValue(1);
6118 break;
6122 if(roll_chance_i(chance))
6123 spellId1 = 64134; // Body and Soul (periodic dispel effect)
6125 else
6126 spellId1 = 64134; // Body and Soul (periodic dispel effect)
6127 break;
6129 // Dispersion mana reg and immunity
6130 case 47585:
6131 spellId1 = 60069; // Dispersion
6132 spellId2 = 63230; // Dispersion
6133 break;
6134 default:
6135 return;
6137 break;
6139 case SPELLFAMILY_ROGUE:
6140 // Sprint (skip non player casted spells by category)
6141 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000040) && GetSpellProto()->Category == 44)
6143 if(!apply || m_target->HasAura(58039)) // Glyph of Blurred Speed
6144 spellId1 = 61922; // Sprint (waterwalk)
6145 else
6146 return;
6148 else
6149 return;
6150 break;
6151 case SPELLFAMILY_HUNTER:
6153 // The Beast Within and Bestial Wrath - immunity
6154 if (GetId() == 19574 || GetId() == 34471)
6156 spellId1 = 24395;
6157 spellId2 = 24396;
6158 spellId3 = 24397;
6159 spellId4 = 26592;
6161 // Aspect of the Dragonhawk dodge
6162 else if (GetSpellProto()->SpellFamilyFlags2 & 0x00001000)
6164 spellId1 = 61848;
6166 // triggered spell have same category as main spell and cooldown
6167 if (apply && m_target->GetTypeId()==TYPEID_PLAYER)
6168 ((Player*)m_target)->RemoveSpellCooldown(61848);
6170 else
6171 return;
6172 break;
6174 case SPELLFAMILY_PALADIN:
6176 if (m_spellProto->Id == 31884) // Avenging Wrath
6178 if(!apply)
6179 spellId1 = 57318; // Sanctified Wrath (triggered)
6180 else
6182 int32 percent = 0;
6183 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
6184 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
6186 if ((*itr)->GetSpellProto()->SpellIconID == 3029)
6188 percent = (*itr)->GetModifier()->m_amount;
6189 break;
6193 // apply in special way
6194 if(percent)
6196 spellId1 = 57318; // Sanctified Wrath (triggered)
6197 // prevent aura deletion, specially in multi-boost case
6198 SetInUse(true);
6199 m_target->CastCustomSpell(m_target, spellId1, &percent, &percent, NULL, true, NULL, this);
6200 SetInUse(false);
6202 return;
6204 break;
6207 // Only process on player casting paladin aura
6208 // all aura bonuses applied also in aura area effect way to caster
6209 if (GetCasterGUID() != m_target->GetGUID() || !IS_PLAYER_GUID(GetCasterGUID()))
6210 return;
6212 if (GetSpellSpecific(m_spellProto->Id) != SPELL_AURA)
6213 return;
6215 // Sanctified Retribution and Swift Retribution (they share one aura), but not Retribution Aura (already gets modded)
6216 if ((GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000008))==0)
6217 spellId1 = 63531; // placeholder for talent spell mods
6218 // Improved Concentration Aura (auras bonus)
6219 spellId2 = 63510; // placeholder for talent spell mods
6220 // Improved Devotion Aura (auras bonus)
6221 spellId3 = 63514; // placeholder for talent spell mods
6222 break;
6224 case SPELLFAMILY_DEATHKNIGHT:
6226 // second part of spell apply
6227 switch (GetId())
6229 case 49039: spellId1 = 50397; break; // Lichborne
6230 case 48263: spellId1 = 61261; break; // Frost Presence
6231 case 48265: spellId1 = 49772; break; // Unholy Presence move speed
6232 default: return;
6234 break;
6236 default:
6237 return;
6240 // prevent aura deletion, specially in multi-boost case
6241 SetInUse(true);
6243 if (apply || cast_at_remove)
6245 if (spellId1)
6246 m_target->CastSpell(m_target, spellId1, true, NULL, this);
6247 if (spellId2 && !IsDeleted())
6248 m_target->CastSpell(m_target, spellId2, true, NULL, this);
6249 if (spellId3 && !IsDeleted())
6250 m_target->CastSpell(m_target, spellId3, true, NULL, this);
6251 if (spellId4 && !IsDeleted())
6252 m_target->CastSpell(m_target, spellId4, true, NULL, this);
6254 else
6256 if (spellId1)
6257 m_target->RemoveAurasByCasterSpell(spellId1, GetCasterGUID());
6258 if (spellId2)
6259 m_target->RemoveAurasByCasterSpell(spellId2, GetCasterGUID());
6260 if (spellId3)
6261 m_target->RemoveAurasByCasterSpell(spellId3, GetCasterGUID());
6262 if (spellId4)
6263 m_target->RemoveAurasByCasterSpell(spellId4, GetCasterGUID());
6266 SetInUse(false);
6269 void Aura::HandleAuraEmpathy(bool apply, bool /*Real*/)
6271 if(m_target->GetTypeId() != TYPEID_UNIT)
6272 return;
6274 CreatureInfo const * ci = ObjectMgr::GetCreatureTemplate(m_target->GetEntry());
6275 if(ci && ci->type == CREATURE_TYPE_BEAST)
6276 m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
6279 void Aura::HandleAuraUntrackable(bool apply, bool /*Real*/)
6281 if(apply)
6282 m_target->SetByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
6283 else
6284 m_target->RemoveByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
6287 void Aura::HandleAuraModPacify(bool apply, bool /*Real*/)
6289 if(m_target->GetTypeId() != TYPEID_PLAYER)
6290 return;
6292 if(apply)
6293 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
6294 else
6295 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
6298 void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
6300 HandleAuraModPacify(apply, Real);
6301 HandleAuraModSilence(apply, Real);
6304 void Aura::HandleAuraGhost(bool apply, bool /*Real*/)
6306 if(m_target->GetTypeId() != TYPEID_PLAYER)
6307 return;
6309 if(apply)
6311 m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
6313 else
6315 m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
6319 void Aura::HandleAuraAllowFlight(bool apply, bool Real)
6321 // all applied/removed only at real aura add/remove
6322 if(!Real)
6323 return;
6325 // allow fly
6326 WorldPacket data;
6327 if(apply)
6328 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
6329 else
6330 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
6331 data.append(m_target->GetPackGUID());
6332 data << uint32(0); // unk
6333 m_target->SendMessageToSet(&data, true);
6336 void Aura::HandleModRating(bool apply, bool Real)
6338 // spells required only Real aura add/remove
6339 if(!Real)
6340 return;
6342 if(m_target->GetTypeId() != TYPEID_PLAYER)
6343 return;
6345 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
6346 if (m_modifier.m_miscvalue & (1 << rating))
6347 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
6350 void Aura::HandleModRatingFromStat(bool apply, bool Real)
6352 // spells required only Real aura add/remove
6353 if(!Real)
6354 return;
6356 if(m_target->GetTypeId() != TYPEID_PLAYER)
6357 return;
6358 // Just recalculate ratings
6359 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
6360 if (m_modifier.m_miscvalue & (1 << rating))
6361 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), 0, apply);
6364 void Aura::HandleForceMoveForward(bool apply, bool Real)
6366 if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
6367 return;
6368 if(apply)
6369 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
6370 else
6371 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
6374 void Aura::HandleAuraModExpertise(bool /*apply*/, bool /*Real*/)
6376 if(m_target->GetTypeId() != TYPEID_PLAYER)
6377 return;
6379 ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
6380 ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
6383 void Aura::HandleModTargetResistance(bool apply, bool Real)
6385 // spells required only Real aura add/remove
6386 if(!Real)
6387 return;
6388 // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
6390 // show armor penetration
6391 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
6392 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE, m_modifier.m_amount, apply);
6394 // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
6395 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
6396 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE, m_modifier.m_amount, apply);
6399 void Aura::HandleShieldBlockValue(bool apply, bool /*Real*/)
6401 BaseModType modType = FLAT_MOD;
6402 if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
6403 modType = PCT_MOD;
6405 if(m_target->GetTypeId() == TYPEID_PLAYER)
6406 ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
6409 void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
6411 // spells required only Real aura add/remove
6412 if(!Real)
6413 return;
6415 if(m_target->GetTypeId() != TYPEID_PLAYER)
6416 return;
6418 Player *target = (Player*)m_target;
6420 // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
6421 // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
6422 if( !apply && m_duration==0 && target->GetComboTarget())
6423 if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
6424 target->AddComboPoints(unit, -m_modifier.m_amount);
6427 void Aura::HandleModUnattackable( bool Apply, bool Real )
6429 if(Real && Apply)
6431 m_target->CombatStop();
6432 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
6434 m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
6437 void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
6439 // spells required only Real aura add/remove
6440 if(!Real)
6441 return;
6443 // prepare spirit state
6444 if(apply)
6446 if(m_target->GetTypeId()==TYPEID_PLAYER)
6448 // disable breath/etc timers
6449 ((Player*)m_target)->StopMirrorTimers();
6451 // set stand state (expected in this form)
6452 if(!m_target->IsStandState())
6453 m_target->SetStandState(UNIT_STAND_STATE_STAND);
6456 m_target->SetHealth(1);
6458 // die at aura end
6459 else
6460 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
6463 void Aura::CleanupTriggeredSpells()
6465 uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
6466 if(!tSpellId)
6467 return;
6469 SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
6470 if(!tProto)
6471 return;
6473 if(GetSpellDuration(tProto) != -1)
6474 return;
6476 // needed for spell 43680, maybe others
6477 // TODO: is there a spell flag, which can solve this in a more sophisticated way?
6478 if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
6479 GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
6480 return;
6481 m_target->RemoveAurasDueToSpell(tSpellId);
6484 void Aura::HandleSchoolAbsorb(bool apply, bool Real)
6486 if(!Real)
6487 return;
6489 Unit* caster = GetCaster();
6490 if(!caster)
6491 return;
6493 if (apply)
6495 // prevent double apply bonuses
6496 if (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
6498 float DoneActualBenefit = 0.0f;
6499 switch(m_spellProto->SpellFamilyName)
6501 case SPELLFAMILY_PRIEST:
6502 // Power Word: Shield
6503 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001))
6505 //+80.68% from +spell bonus
6506 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.8068f;
6507 //Borrowed Time
6508 Unit::AuraList const& borrowedTime = caster->GetAurasByType(SPELL_AURA_DUMMY);
6509 for(Unit::AuraList::const_iterator itr = borrowedTime.begin(); itr != borrowedTime.end(); ++itr)
6511 SpellEntry const* i_spell = (*itr)->GetSpellProto();
6512 if(i_spell->SpellFamilyName==SPELLFAMILY_PRIEST && i_spell->SpellIconID == 2899 && i_spell->EffectMiscValue[(*itr)->GetEffIndex()] == 24)
6514 DoneActualBenefit += DoneActualBenefit * (*itr)->GetModifier()->m_amount / 100;
6515 break;
6520 break;
6521 case SPELLFAMILY_MAGE:
6522 // Frost Ward, Fire Ward
6523 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000108))
6524 //+10% from +spell bonus
6525 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
6526 // Ice Barrier
6527 else if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000100000000))
6528 //+80.67% from +spell bonus
6529 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.8067f;
6530 break;
6531 case SPELLFAMILY_WARLOCK:
6532 // Shadow Ward
6533 if (m_spellProto->SpellFamilyFlags2 & 0x00000040)
6534 //+30% from +spell bonus
6535 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.30f;
6536 break;
6537 case SPELLFAMILY_PALADIN:
6538 // Sacred Shield
6539 // (check not strictly needed, only Sacred Shield has SPELL_AURA_SCHOOL_ABSORB in SPELLFAMILY_PALADIN at this time)
6540 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0008000000000000))
6542 // +75% from spell power
6543 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.75f;
6545 break;
6546 default:
6547 break;
6550 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6552 m_modifier.m_amount += (int32)DoneActualBenefit;
6555 else
6557 if (caster &&
6558 // Power Word: Shield
6559 m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST && m_spellProto->Mechanic == MECHANIC_SHIELD &&
6560 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001)) &&
6561 // completely absorbed or dispelled
6562 ((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6564 Unit::AuraList const& vDummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6565 for(Unit::AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); ++itr)
6567 SpellEntry const* vSpell = (*itr)->GetSpellProto();
6569 // Rapture (main spell)
6570 if(vSpell->SpellFamilyName == SPELLFAMILY_PRIEST && vSpell->SpellIconID == 2894 && vSpell->Effect[1])
6572 switch((*itr)->GetEffIndex())
6574 case 0:
6576 // energize caster
6577 int32 manapct1000 = 5 * ((*itr)->GetModifier()->m_amount + sSpellMgr.GetSpellRank(vSpell->Id));
6578 int32 basepoints0 = caster->GetMaxPower(POWER_MANA) * manapct1000 / 1000;
6579 caster->CastCustomSpell(caster, 47755, &basepoints0, NULL, NULL, true);
6580 break;
6582 case 1:
6584 // energize target
6585 if (!roll_chance_i((*itr)->GetModifier()->m_amount) || caster->HasAura(63853))
6586 break;
6588 switch(m_target->getPowerType())
6590 case POWER_RUNIC_POWER:
6591 m_target->CastSpell(m_target, 63652, true, NULL, NULL, m_caster_guid);
6592 break;
6593 case POWER_RAGE:
6594 m_target->CastSpell(m_target, 63653, true, NULL, NULL, m_caster_guid);
6595 break;
6596 case POWER_MANA:
6598 int32 basepoints0 = m_target->GetMaxPower(POWER_MANA) * 2 / 100;
6599 m_target->CastCustomSpell(m_target, 63654, &basepoints0, NULL, NULL, true);
6600 break;
6602 case POWER_ENERGY:
6603 m_target->CastSpell(m_target, 63655, true, NULL, NULL, m_caster_guid);
6604 break;
6605 default:
6606 break;
6609 //cooldwon aura
6610 caster->CastSpell(caster, 63853, true);
6611 break;
6613 default:
6614 sLog.outError("Changes in R-dummy spell???: effect 3");
6615 break;
6623 void Aura::PeriodicTick()
6625 switch(m_modifier.m_auraname)
6627 case SPELL_AURA_PERIODIC_DAMAGE:
6628 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
6630 // don't damage target if not alive, possible death persistent effects
6631 if (!m_target->isAlive())
6632 return;
6634 Unit *pCaster = GetCaster();
6635 if(!pCaster)
6636 return;
6638 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6639 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6640 return;
6642 // Check for immune (not use charges)
6643 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6644 return;
6646 // some auras remove at specific health level or more
6647 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6649 switch(GetId())
6651 case 43093: case 31956: case 38801:
6652 case 35321: case 38363: case 39215:
6653 if(m_target->GetHealth() == m_target->GetMaxHealth() )
6655 m_target->RemoveAurasDueToSpell(GetId());
6656 return;
6658 break;
6659 case 38772:
6661 uint32 percent =
6662 GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_DUMMY ?
6663 pCaster->CalculateSpellDamage(GetSpellProto(), GetEffIndex() + 1, GetSpellProto()->EffectBasePoints[GetEffIndex() + 1], m_target) :
6664 100;
6665 if(m_target->GetHealth() * 100 >= m_target->GetMaxHealth() * percent )
6667 m_target->RemoveAurasDueToSpell(GetId());
6668 return;
6670 break;
6672 default:
6673 break;
6677 uint32 absorb = 0;
6678 uint32 resist = 0;
6679 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6681 // ignore non positive values (can be result apply spellmods to aura damage
6682 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6684 uint32 pdamage;
6686 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6688 pdamage = amount;
6690 // SpellDamageBonus for magic spells
6691 if(GetSpellProto()->DmgClass == SPELL_DAMAGE_CLASS_NONE || GetSpellProto()->DmgClass == SPELL_DAMAGE_CLASS_MAGIC)
6692 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6693 // MeleeDamagebonus for weapon based spells
6694 else
6696 WeaponAttackType attackType = GetWeaponAttackType(GetSpellProto());
6697 pdamage = pCaster->MeleeDamageBonus(m_target, pdamage, attackType, GetSpellProto(), DOT, GetStackAmount());
6700 // Calculate armor mitigation if it is a physical spell
6701 // But not for bleed mechanic spells
6702 if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
6703 GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
6705 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6706 cleanDamage.damage += pdamage - pdamageReductedArmor;
6707 pdamage = pdamageReductedArmor;
6710 // Curse of Agony damage-per-tick calculation
6711 if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000400)) && GetSpellProto()->SpellIconID==544)
6713 // 1..4 ticks, 1/2 from normal tick damage
6714 if (GetAuraTicks() <= 4)
6715 pdamage = pdamage/2;
6716 // 9..12 ticks, 3/2 from normal tick damage
6717 else if(GetAuraTicks() >= 9)
6718 pdamage += (pdamage + 1) / 2; // +1 prevent 0.5 damage possible lost at 1..4 ticks
6719 // 5..8 ticks have normal tick damage
6722 else
6723 pdamage = uint32(m_target->GetMaxHealth()*amount/100);
6725 // This method can modify pdamage
6726 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6728 // send critical in hit info for threat calculation
6729 if (isCrit)
6731 cleanDamage.hitOutCome = MELEE_HIT_CRIT;
6732 // Resilience - reduce crit damage
6733 pdamage -= m_target->GetSpellCritDamageReduction(pdamage);
6736 // only from players
6737 // FIXME: need use SpellDamageBonus instead?
6738 if (IS_PLAYER_GUID(m_caster_guid))
6739 pdamage -= m_target->GetSpellDamageReduction(pdamage);
6741 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist, !(GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_CANT_REFLECTED));
6743 sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6744 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6746 pCaster->DealDamageMods(m_target, pdamage, &absorb);
6748 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, absorb, resist, 0.0f, isCrit);
6749 m_target->SendPeriodicAuraLog(&pInfo);
6751 // Set trigger flag
6752 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6753 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6754 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage - absorb - resist);
6755 if (pdamage)
6756 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6757 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6759 pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6760 break;
6762 case SPELL_AURA_PERIODIC_LEECH:
6763 case SPELL_AURA_PERIODIC_HEALTH_FUNNEL:
6765 // don't damage target if not alive, possible death persistent effects
6766 if (!m_target->isAlive())
6767 return;
6769 Unit *pCaster = GetCaster();
6770 if(!pCaster)
6771 return;
6773 if(!pCaster->isAlive())
6774 return;
6776 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6777 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6778 return;
6780 // Check for immune
6781 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6782 return;
6784 uint32 absorb=0;
6785 uint32 resist=0;
6786 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6788 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6790 //Calculate armor mitigation if it is a physical spell
6791 if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
6793 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6794 cleanDamage.damage += pdamage - pdamageReductedArmor;
6795 pdamage = pdamageReductedArmor;
6798 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6799 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6801 // send critical in hit info for threat calculation
6802 if (isCrit)
6804 cleanDamage.hitOutCome = MELEE_HIT_CRIT;
6805 // Resilience - reduce crit damage
6806 pdamage -= m_target->GetSpellCritDamageReduction(pdamage);
6809 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist, !(GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_CANT_REFLECTED));
6811 if(m_target->GetHealth() < pdamage)
6812 pdamage = uint32(m_target->GetHealth());
6814 sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6815 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6817 pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0, isCrit);
6819 float multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()] > 0 ? GetSpellProto()->EffectMultipleValue[GetEffIndex()] : 1;
6821 // Set trigger flag
6822 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6823 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6824 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage-absorb-resist);
6825 if (pdamage)
6826 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6827 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6828 int32 new_damage = pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
6830 if (!m_target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
6831 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
6832 if (Spell* spell = pCaster->GetCurrentSpell(CurrentSpellTypes(i)))
6833 if (spell->m_spellInfo->Id == GetId())
6834 spell->cancel();
6837 if(Player *modOwner = pCaster->GetSpellModOwner())
6838 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, multiplier);
6840 uint32 heal = pCaster->SpellHealingBonus(pCaster, GetSpellProto(), uint32(new_damage * multiplier), DOT, GetStackAmount());
6842 int32 gain = pCaster->DealHeal(pCaster, heal, GetSpellProto());
6843 pCaster->getHostileRefManager().threatAssist(pCaster, gain * 0.5f, GetSpellProto());
6844 break;
6846 case SPELL_AURA_PERIODIC_HEAL:
6847 case SPELL_AURA_OBS_MOD_HEALTH:
6849 // don't heal target if not alive, mostly death persistent effects from items
6850 if (!m_target->isAlive())
6851 return;
6853 Unit *pCaster = GetCaster();
6854 if(!pCaster)
6855 return;
6857 // heal for caster damage (must be alive)
6858 if(m_target != pCaster && GetSpellProto()->SpellVisual[0] == 163 && !pCaster->isAlive())
6859 return;
6861 // ignore non positive values (can be result apply spellmods to aura damage
6862 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6864 uint32 pdamage;
6866 if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
6867 pdamage = uint32(m_target->GetMaxHealth() * amount / 100);
6868 else
6870 pdamage = amount;
6872 // Wild Growth (1/7 - 6 + 2*ramainTicks) %
6873 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && m_spellProto->SpellIconID == 2864)
6875 int32 ticks = GetAuraMaxTicks();
6876 int32 remainingTicks = ticks - GetAuraTicks();
6877 pdamage = int32(pdamage) + int32(amount)*ticks*(-6+2*remainingTicks)/100;
6881 pdamage = pCaster->SpellHealingBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6883 // This method can modify pdamage
6884 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6886 sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
6887 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6889 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f, isCrit);
6890 m_target->SendPeriodicAuraLog(&pInfo);
6892 int32 gain = m_target->ModifyHealth(pdamage);
6894 // Set trigger flag
6895 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC;
6896 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;
6897 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, gain, BASE_ATTACK, m_spellProto);
6899 // add HoTs to amount healed in bgs
6900 if( pCaster->GetTypeId() == TYPEID_PLAYER )
6901 if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
6902 bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
6904 m_target->getHostileRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6906 SpellEntry const* spellProto = GetSpellProto();
6908 // heal for caster damage
6909 if(m_target != pCaster && spellProto->SpellVisual[0] == 163)
6911 uint32 dmg = spellProto->manaPerSecond;
6912 if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
6914 pCaster->RemoveAurasDueToSpell(GetId());
6916 // finish current generic/channeling spells, don't affect autorepeat
6917 pCaster->FinishSpell(CURRENT_GENERIC_SPELL);
6918 pCaster->FinishSpell(CURRENT_CHANNELED_SPELL);
6920 else
6922 uint32 damage = gain;
6923 uint32 absorb = 0;
6924 pCaster->DealDamageMods(pCaster, damage, &absorb);
6925 pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), damage, GetSpellSchoolMask(GetSpellProto()), absorb, 0, false, 0, false);
6927 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6928 pCaster->DealDamage(pCaster, damage, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6932 // uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC;// | PROC_FLAG_SUCCESSFUL_HEAL;
6933 // uint32 procVictim = 0;//ROC_FLAG_ON_TAKE_PERIODIC | PROC_FLAG_TAKEN_HEAL;
6934 // ignore item heals
6935 // if(procSpell && !haveCastItem)
6936 // pCaster->ProcDamageAndSpell(target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, spellProto);
6937 break;
6939 case SPELL_AURA_PERIODIC_MANA_LEECH:
6941 // don't damage target if not alive, possible death persistent effects
6942 if (!m_target->isAlive())
6943 return;
6945 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6946 return;
6948 Powers power = Powers(m_modifier.m_miscvalue);
6950 // power type might have changed between aura applying and tick (druid's shapeshift)
6951 if(m_target->getPowerType() != power)
6952 return;
6954 Unit *pCaster = GetCaster();
6955 if(!pCaster)
6956 return;
6958 if(!pCaster->isAlive())
6959 return;
6961 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6962 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6963 return;
6965 // Check for immune (not use charges)
6966 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6967 return;
6969 // ignore non positive values (can be result apply spellmods to aura damage
6970 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6972 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
6973 // It's mana percent cost spells, m_modifier.m_amount is percent drain from target
6974 if (m_spellProto->ManaCostPercentage)
6976 // max value
6977 uint32 maxmana = pCaster->GetMaxPower(power) * pdamage * 2 / 100;
6978 pdamage = m_target->GetMaxPower(power) * pdamage / 100;
6979 if(pdamage > maxmana)
6980 pdamage = maxmana;
6983 sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
6984 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6986 int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
6988 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6989 if (power == POWER_MANA)
6990 drain_amount -= m_target->GetSpellCritDamageReduction(drain_amount);
6992 m_target->ModifyPower(power, -drain_amount);
6994 float gain_multiplier = 0;
6996 if(pCaster->GetMaxPower(power) > 0)
6998 gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
7000 if(Player *modOwner = pCaster->GetSpellModOwner())
7001 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
7004 SpellPeriodicAuraLogInfo pInfo(this, drain_amount, 0, 0, 0, gain_multiplier);
7005 m_target->SendPeriodicAuraLog(&pInfo);
7007 int32 gain_amount = int32(drain_amount * gain_multiplier);
7009 if(gain_amount)
7011 int32 gain = pCaster->ModifyPower(power, gain_amount);
7012 m_target->AddThreat(pCaster, float(gain) * 0.5f, pInfo.critical, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
7014 break;
7016 case SPELL_AURA_PERIODIC_ENERGIZE:
7018 // don't energize target if not alive, possible death persistent effects
7019 if (!m_target->isAlive())
7020 return;
7022 // ignore non positive values (can be result apply spellmods to aura damage
7023 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
7025 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
7026 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
7028 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
7029 break;
7031 Powers power = Powers(m_modifier.m_miscvalue);
7033 if(m_target->GetMaxPower(power) == 0)
7034 break;
7036 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
7037 m_target->SendPeriodicAuraLog(&pInfo);
7039 int32 gain = m_target->ModifyPower(power,pdamage);
7041 if(Unit* pCaster = GetCaster())
7042 m_target->getHostileRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
7043 break;
7045 case SPELL_AURA_OBS_MOD_MANA:
7047 // don't energize target if not alive, possible death persistent effects
7048 if (!m_target->isAlive())
7049 return;
7051 // ignore non positive values (can be result apply spellmods to aura damage
7052 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
7054 uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount / 100);
7056 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
7057 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
7059 if(m_target->GetMaxPower(POWER_MANA) == 0)
7060 break;
7062 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
7063 m_target->SendPeriodicAuraLog(&pInfo);
7065 int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
7067 if(Unit* pCaster = GetCaster())
7068 m_target->getHostileRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
7069 break;
7071 case SPELL_AURA_POWER_BURN_MANA:
7073 // don't mana burn target if not alive, possible death persistent effects
7074 if (!m_target->isAlive())
7075 return;
7077 Unit *pCaster = GetCaster();
7078 if(!pCaster)
7079 return;
7081 // Check for immune (not use charges)
7082 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
7083 return;
7085 int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
7087 Powers powerType = Powers(m_modifier.m_miscvalue);
7089 if(!m_target->isAlive() || m_target->getPowerType() != powerType)
7090 return;
7092 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
7093 if (powerType == POWER_MANA)
7094 pdamage -= m_target->GetSpellCritDamageReduction(pdamage);
7096 uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
7098 gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
7100 SpellEntry const* spellProto = GetSpellProto();
7101 // maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
7102 SpellNonMeleeDamage damageInfo(pCaster, m_target, spellProto->Id, spellProto->SchoolMask);
7103 pCaster->CalculateSpellDamage(&damageInfo, gain, spellProto);
7105 pCaster->DealDamageMods(damageInfo.target, damageInfo.damage, &damageInfo.absorb);
7107 pCaster->SendSpellNonMeleeDamageLog(&damageInfo);
7109 // Set trigger flag
7110 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
7111 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
7112 uint32 procEx = createProcExtendMask(&damageInfo, SPELL_MISS_NONE);
7113 if (damageInfo.damage)
7114 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
7116 pCaster->ProcDamageAndSpell(damageInfo.target, procAttacker, procVictim, procEx, damageInfo.damage, BASE_ATTACK, spellProto);
7118 pCaster->DealSpellDamage(&damageInfo, true);
7119 break;
7121 case SPELL_AURA_MOD_REGEN:
7123 // don't heal target if not alive, possible death persistent effects
7124 if (!m_target->isAlive())
7125 return;
7127 int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
7128 if (Unit *caster = GetCaster())
7129 m_target->getHostileRefManager().threatAssist(caster, float(gain) * 0.5f, GetSpellProto());
7130 break;
7132 case SPELL_AURA_MOD_POWER_REGEN:
7134 // don't energize target if not alive, possible death persistent effects
7135 if (!m_target->isAlive())
7136 return;
7138 Powers pt = m_target->getPowerType();
7139 if(int32(pt) != m_modifier.m_miscvalue)
7140 return;
7142 if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
7144 // eating anim
7145 m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
7147 else if( GetId() == 20577 )
7149 // cannibalize anim
7150 m_target->HandleEmoteCommand(EMOTE_STATE_CANNIBALIZE);
7153 // Anger Management
7154 // amount = 1+ 16 = 17 = 3,4*5 = 10,2*5/3
7155 // so 17 is rounded amount for 5 sec tick grow ~ 1 range grow in 3 sec
7156 if(pt == POWER_RAGE)
7157 m_target->ModifyPower(pt, m_modifier.m_amount * 3 / 5);
7158 break;
7160 // Here tick dummy auras
7161 case SPELL_AURA_DUMMY: // some spells have dummy aura
7162 case SPELL_AURA_PERIODIC_DUMMY:
7164 PeriodicDummyTick();
7165 break;
7167 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
7169 TriggerSpell();
7170 break;
7172 case SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE:
7174 TriggerSpellWithValue();
7175 break;
7177 default:
7178 break;
7182 void Aura::PeriodicDummyTick()
7184 SpellEntry const* spell = GetSpellProto();
7185 switch (spell->SpellFamilyName)
7187 case SPELLFAMILY_GENERIC:
7188 switch (spell->Id)
7190 // Drink
7191 case 430:
7192 case 431:
7193 case 432:
7194 case 1133:
7195 case 1135:
7196 case 1137:
7197 case 10250:
7198 case 22734:
7199 case 27089:
7200 case 34291:
7201 case 43182:
7202 case 43183:
7203 case 43706:
7204 case 46755:
7205 case 49472: // Drink Coffee
7206 case 57073:
7207 case 61830:
7209 if (m_target->GetTypeId() != TYPEID_PLAYER)
7210 return;
7211 // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
7212 Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
7213 for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
7215 if ((*i)->GetId() == GetId())
7217 (*i)->GetModifier()->m_amount = m_modifier.m_amount;
7218 ((Player*)m_target)->UpdateManaRegen();
7219 // Disable continue
7220 m_isPeriodic = false;
7221 return;
7224 return;
7226 // Forsaken Skills
7227 case 7054:
7229 // Possibly need cast one of them (but
7230 // 7038 Forsaken Skill: Swords
7231 // 7039 Forsaken Skill: Axes
7232 // 7040 Forsaken Skill: Daggers
7233 // 7041 Forsaken Skill: Maces
7234 // 7042 Forsaken Skill: Staves
7235 // 7043 Forsaken Skill: Bows
7236 // 7044 Forsaken Skill: Guns
7237 // 7045 Forsaken Skill: 2H Axes
7238 // 7046 Forsaken Skill: 2H Maces
7239 // 7047 Forsaken Skill: 2H Swords
7240 // 7048 Forsaken Skill: Defense
7241 // 7049 Forsaken Skill: Fire
7242 // 7050 Forsaken Skill: Frost
7243 // 7051 Forsaken Skill: Holy
7244 // 7053 Forsaken Skill: Shadow
7245 return;
7247 case 7057: // Haunting Spirits
7248 if (roll_chance_i(33))
7249 m_target->CastSpell(m_target,m_modifier.m_amount,true,NULL,this);
7250 return;
7251 // // Panda
7252 // case 19230: break;
7253 // // Gossip NPC Periodic - Talk
7254 // case 33208: break;
7255 // // Gossip NPC Periodic - Despawn
7256 // case 33209: break;
7257 // // Steal Weapon
7258 // case 36207: break;
7259 // // Simon Game START timer, (DND)
7260 // case 39993: break;
7261 // // Knockdown Fel Cannon: break; The Aggro Burst
7262 // case 40119: break;
7263 // // Old Mount Spell
7264 // case 40154: break;
7265 // // Magnetic Pull
7266 // case 40581: break;
7267 // // Ethereal Ring: break; The Bolt Burst
7268 // case 40801: break;
7269 // // Crystal Prison
7270 // case 40846: break;
7271 // // Copy Weapon
7272 // case 41054: break;
7273 // // Dementia
7274 // case 41404: break;
7275 // // Ethereal Ring Visual, Lightning Aura
7276 // case 41477: break;
7277 // // Ethereal Ring Visual, Lightning Aura (Fork)
7278 // case 41525: break;
7279 // // Ethereal Ring Visual, Lightning Jumper Aura
7280 // case 41567: break;
7281 // // No Man's Land
7282 // case 41955: break;
7283 // // Headless Horseman - Fire
7284 // case 42074: break;
7285 // // Headless Horseman - Visual - Large Fire
7286 // case 42075: break;
7287 // // Headless Horseman - Start Fire, Periodic Aura
7288 // case 42140: break;
7289 // // Ram Speed Boost
7290 // case 42152: break;
7291 // // Headless Horseman - Fires Out Victory Aura
7292 // case 42235: break;
7293 // // Pumpkin Life Cycle
7294 // case 42280: break;
7295 // // Brewfest Request Chick Chuck Mug Aura
7296 // case 42537: break;
7297 // // Squashling
7298 // case 42596: break;
7299 // // Headless Horseman Climax, Head: Periodic
7300 // case 42603: break;
7301 // // Fire Bomb
7302 // case 42621: break;
7303 // // Headless Horseman - Conflagrate, Periodic Aura
7304 // case 42637: break;
7305 // // Headless Horseman - Create Pumpkin Treats Aura
7306 // case 42774: break;
7307 // // Headless Horseman Climax - Summoning Rhyme Aura
7308 // case 42879: break;
7309 // // Tricky Treat
7310 // case 42919: break;
7311 // // Giddyup!
7312 // case 42924: break;
7313 // // Ram - Trot
7314 // case 42992: break;
7315 // // Ram - Canter
7316 // case 42993: break;
7317 // // Ram - Gallop
7318 // case 42994: break;
7319 // // Ram Level - Neutral
7320 // case 43310: break;
7321 // // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
7322 // case 43884: break;
7323 // // Wretched!
7324 // case 43963: break;
7325 // // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
7326 // case 44000: break;
7327 // // Energy Feedback
7328 // case 44328: break;
7329 // // Romantic Picnic
7330 // case 45102: break;
7331 // // Romantic Picnic
7332 // case 45123: break;
7333 // // Looking for Love
7334 // case 45124: break;
7335 // // Kite - Lightning Strike Kite Aura
7336 // case 45197: break;
7337 // // Rocket Chicken
7338 // case 45202: break;
7339 // // Copy Offhand Weapon
7340 // case 45205: break;
7341 // // Upper Deck - Kite - Lightning Periodic Aura
7342 // case 45207: break;
7343 // // Kite -Sky Lightning Strike Kite Aura
7344 // case 45251: break;
7345 // // Ribbon Pole Dancer Check Aura
7346 // case 45390: break;
7347 // // Holiday - Midsummer, Ribbon Pole Periodic Visual
7348 // case 45406: break;
7349 // // Parachute
7350 // case 45472: break;
7351 // // Alliance Flag, Extra Damage Debuff
7352 // case 45898: break;
7353 // // Horde Flag, Extra Damage Debuff
7354 // case 45899: break;
7355 // // Ahune - Summoning Rhyme Aura
7356 // case 45926: break;
7357 // // Ahune - Slippery Floor
7358 // case 45945: break;
7359 // // Ahune's Shield
7360 // case 45954: break;
7361 // // Nether Vapor Lightning
7362 // case 45960: break;
7363 // // Darkness
7364 // case 45996: break;
7365 case 46041: // Summon Blood Elves Periodic
7366 m_target->CastSpell(m_target, 46037, true, NULL, this);
7367 m_target->CastSpell(m_target, roll_chance_i(50) ? 46038 : 46039, true, NULL, this);
7368 m_target->CastSpell(m_target, 46040, true, NULL, this);
7369 return;
7370 // // Transform Visual Missile Periodic
7371 // case 46205: break;
7372 // // Find Opening Beam End
7373 // case 46333: break;
7374 // // Ice Spear Control Aura
7375 // case 46371: break;
7376 // // Hailstone Chill
7377 // case 46458: break;
7378 // // Hailstone Chill, Internal
7379 // case 46465: break;
7380 // // Chill, Internal Shifter
7381 // case 46549: break;
7382 // // Summon Ice Spear Knockback Delayer
7383 // case 46878: break;
7384 // // Burninate Effect
7385 // case 47214: break;
7386 // // Fizzcrank Practice Parachute
7387 // case 47228: break;
7388 // // Send Mug Control Aura
7389 // case 47369: break;
7390 // // Direbrew's Disarm (precast)
7391 // case 47407: break;
7392 // // Mole Machine Port Schedule
7393 // case 47489: break;
7394 // case 47941: break; // Crystal Spike
7395 // case 48200: break; // Healer Aura
7396 case 48630: // Summon Gauntlet Mobs Periodic
7397 case 59275: // Below may need some adjustment, pattern for amount of summon and where is not verified 100% (except for odd/even tick)
7399 bool chance = roll_chance_i(50);
7401 m_target->CastSpell(m_target, chance ? 48631 : 48632, true, NULL, this);
7403 if (GetAuraTicks() % 2) // which doctor at odd tick
7404 m_target->CastSpell(m_target, chance ? 48636 : 48635, true, NULL, this);
7405 else // or harponeer, at even tick
7406 m_target->CastSpell(m_target, chance ? 48634 : 48633, true, NULL, this);
7408 return;
7410 // case 49313: break; // Proximity Mine Area Aura
7411 // // Mole Machine Portal Schedule
7412 // case 49466: break;
7413 // case 49555: break; // Corpse Explode
7414 // case 49592: break; // Temporal Rift
7415 // case 49957: break; // Cutting Laser
7416 // case 50085: break; // Slow Fall
7417 // // Listening to Music
7418 // case 50493: break;
7419 // // Love Rocket Barrage
7420 // case 50530: break;
7421 case 50789: // Summon iron dwarf (left or right)
7422 case 59860:
7423 m_target->CastSpell(m_target, roll_chance_i(50) ? 50790 : 50791, true, NULL, this);
7424 return;
7425 case 50792: // Summon iron trogg (left or right)
7426 case 59859:
7427 m_target->CastSpell(m_target, roll_chance_i(50) ? 50793 : 50794, true, NULL, this);
7428 return;
7429 case 50801: // Summon malformed ooze (left or right)
7430 case 59858:
7431 m_target->CastSpell(m_target, roll_chance_i(50) ? 50802 : 50803, true, NULL, this);
7432 return;
7433 case 50824: // Summon earthen dwarf
7434 m_target->CastSpell(m_target, roll_chance_i(50) ? 50825 : 50826, true, NULL, this);
7435 return;
7436 case 52441: // Cool Down
7437 m_target->CastSpell(m_target, 52443, true);
7438 return;
7439 case 53520: // Carrion Beetles
7440 m_target->CastSpell(m_target, 53521, true, NULL, this);
7441 m_target->CastSpell(m_target, 53521, true, NULL, this);
7442 return;
7443 case 55592: // Clean
7444 switch(urand(0,2))
7446 case 0: m_target->CastSpell(m_target, 55731, true); break;
7447 case 1: m_target->CastSpell(m_target, 55738, true); break;
7448 case 2: m_target->CastSpell(m_target, 55739, true); break;
7450 return;
7451 // Exist more after, need add later
7452 default:
7453 break;
7455 // Prey on the Weak
7456 if (spell->SpellIconID == 2983)
7458 Unit *target=m_target->getVictim();
7459 if (target && (m_target->GetHealth() * 100 / m_target->GetMaxHealth() > target->GetHealth() * 100 / target->GetMaxHealth()))
7461 if(!m_target->HasAura(58670))
7463 int32 basepoints = GetBasePoints();
7464 m_target->CastCustomSpell(m_target, 58670, &basepoints, 0, 0, true);
7467 else
7468 m_target->RemoveAurasDueToSpell(58670);
7470 break;
7471 case SPELLFAMILY_MAGE:
7473 // Mirror Image
7474 // if (spell->Id == 55342)
7475 // return;
7476 break;
7478 case SPELLFAMILY_DRUID:
7480 switch (spell->Id)
7482 // Frenzied Regeneration
7483 case 22842:
7485 // Converts up to 10 rage per second into health for $d. Each point of rage is converted into ${$m2/10}.1% of max health.
7486 // Should be manauser
7487 if (m_target->getPowerType() != POWER_RAGE)
7488 return;
7489 uint32 rage = m_target->GetPower(POWER_RAGE);
7490 // Nothing todo
7491 if (rage == 0)
7492 return;
7493 int32 mod = (rage < 100) ? rage : 100;
7494 int32 points = m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7495 int32 regen = m_target->GetMaxHealth() * (mod * points / 10) / 1000;
7496 m_target->CastCustomSpell(m_target, 22845, &regen, NULL, NULL, true, NULL, this);
7497 m_target->SetPower(POWER_RAGE, rage-mod);
7498 return;
7500 // Force of Nature
7501 case 33831:
7502 return;
7503 default:
7504 break;
7506 break;
7508 case SPELLFAMILY_ROGUE:
7510 switch (spell->Id)
7512 // Killing Spree
7513 case 51690:
7515 if (m_target->hasUnitState(UNIT_STAT_STUNNED) || m_target->isFeared())
7516 return;
7518 std::list<Unit*> targets;
7520 // eff_radius ==0
7521 float radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spell->rangeIndex));
7523 CellPair p(MaNGOS::ComputeCellPair(m_target->GetPositionX(),m_target->GetPositionY()));
7524 Cell cell(p);
7525 cell.data.Part.reserved = ALL_DISTRICT;
7527 MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck u_check(m_target, m_target, radius);
7528 MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck> checker(m_target, targets, u_check);
7530 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker);
7531 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
7533 cell.Visit(p, grid_object_checker, *m_target->GetMap(), *m_target, radius);
7534 cell.Visit(p, world_object_checker, *m_target->GetMap(), *m_target, radius);
7537 if(targets.empty())
7538 return;
7540 std::list<Unit*>::const_iterator itr = targets.begin();
7541 std::advance(itr, rand()%targets.size());
7542 Unit* target = *itr;
7544 m_target->CastSpell(target, 57840, true);
7545 m_target->CastSpell(target, 57841, true);
7546 return;
7548 default:
7549 break;
7551 break;
7553 case SPELLFAMILY_HUNTER:
7555 // Explosive Shot
7556 if (spell->SpellFamilyFlags & UI64LIT(0x8000000000000000))
7558 m_target->CastCustomSpell(m_target, 53352, &m_modifier.m_amount, 0, 0, true, 0, this, GetCasterGUID());
7559 return;
7561 switch (spell->Id)
7563 // Harpooner's Mark
7564 // case 40084:
7565 // return;
7566 // Feeding Frenzy Rank 1
7567 case 53511:
7568 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
7569 m_target->CastSpell(m_target, 60096, true, NULL, this);
7570 return;
7571 // Feeding Frenzy Rank 2
7572 case 53512:
7573 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
7574 m_target->CastSpell(m_target, 60097, true, NULL, this);
7575 return;
7576 default:
7577 break;
7579 break;
7581 case SPELLFAMILY_SHAMAN:
7583 // Astral Shift
7584 if (spell->Id == 52179)
7586 // Periodic need for remove visual on stun/fear/silence lost
7587 if (!(m_target->GetUInt32Value(UNIT_FIELD_FLAGS)&(UNIT_FLAG_STUNNED|UNIT_FLAG_FLEEING|UNIT_FLAG_SILENCED)))
7588 m_target->RemoveAurasDueToSpell(52179);
7589 return;
7591 break;
7593 case SPELLFAMILY_DEATHKNIGHT:
7595 // Death and Decay
7596 if (spell->SpellFamilyFlags & UI64LIT(0x0000000000000020))
7598 if (Unit *caster = GetCaster())
7599 caster->CastCustomSpell(m_target, 52212, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
7600 return;
7602 // Raise Dead
7603 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000001000))
7604 // return;
7605 // Chains of Ice
7606 if (spell->SpellFamilyFlags & UI64LIT(0x0000400000000000))
7608 // Get 0 effect aura
7609 Aura *slow = m_target->GetAura(GetId(), 0);
7610 if (slow)
7612 slow->ApplyModifier(false, true);
7613 Modifier *mod = slow->GetModifier();
7614 mod->m_amount+= m_modifier.m_amount;
7615 if (mod->m_amount > 0) mod->m_amount = 0;
7616 slow->ApplyModifier(true, true);
7618 return;
7620 // Summon Gargoyle
7621 // if (spell->SpellFamilyFlags & UI64LIT(0x0000008000000000))
7622 // return;
7623 // Death Rune Mastery
7624 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000004000))
7625 // return;
7626 // Bladed Armor
7627 if (spell->SpellIconID == 2653)
7629 // Increases your attack power by $s1 for every $s2 armor value you have.
7630 // Calculate AP bonus (from 1 efect of this spell)
7631 int32 apBonus = m_modifier.m_amount * m_target->GetArmor() / m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7632 m_target->CastCustomSpell(m_target, 61217, &apBonus, &apBonus, NULL, true, NULL, this);
7633 return;
7635 // Reaping
7636 // if (spell->SpellIconID == 22)
7637 // return;
7638 // Blood of the North
7639 // if (spell->SpellIconID == 30412)
7640 // return;
7641 break;
7643 default:
7644 break;
7648 void Aura::HandlePreventFleeing(bool apply, bool Real)
7650 if(!Real)
7651 return;
7653 Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
7654 if( !fearAuras.empty() )
7656 if (apply)
7657 m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
7658 else
7659 m_target->SetFeared(true);
7663 void Aura::HandleManaShield(bool apply, bool Real)
7665 if(!Real)
7666 return;
7668 // prevent double apply bonuses
7669 if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
7671 if(Unit* caster = GetCaster())
7673 float DoneActualBenefit = 0.0f;
7674 switch(m_spellProto->SpellFamilyName)
7676 case SPELLFAMILY_MAGE:
7677 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000008000))
7679 // Mana Shield
7680 // +50% from +spd bonus
7681 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
7682 break;
7684 break;
7685 default:
7686 break;
7689 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
7691 m_modifier.m_amount += (int32)DoneActualBenefit;
7696 void Aura::HandleArenaPreparation(bool apply, bool Real)
7698 if(!Real)
7699 return;
7701 if(apply)
7702 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7703 else
7704 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7708 * Such auras are applied from a caster(=player) to a vehicle.
7709 * This has been verified using spell #49256
7711 void Aura::HandleAuraControlVehicle(bool apply, bool Real)
7713 if(!Real)
7714 return;
7716 Unit *player = GetCaster();
7717 Vehicle *vehicle = dynamic_cast<Vehicle*>(m_target);
7718 if(!player || player->GetTypeId() != TYPEID_PLAYER || !vehicle)
7719 return;
7721 if (apply)
7723 if(Pet *pet = player->GetPet())
7724 pet->Remove(PET_SAVE_AS_CURRENT);
7725 ((Player*)player)->EnterVehicle(vehicle);
7727 else
7729 SpellEntry const *spell = GetSpellProto();
7731 // some SPELL_AURA_CONTROL_VEHICLE auras have a dummy effect on the player - remove them
7732 player->RemoveAurasDueToSpell(spell->Id);
7734 ((Player*)player)->ExitVehicle(vehicle);
7738 void Aura::HandleAuraConvertRune(bool apply, bool Real)
7740 if(!Real)
7741 return;
7743 if(m_target->GetTypeId() != TYPEID_PLAYER)
7744 return;
7746 Player *plr = (Player*)m_target;
7748 if(plr->getClass() != CLASS_DEATH_KNIGHT)
7749 return;
7751 RuneType runeFrom = RuneType(GetSpellProto()->EffectMiscValue[m_effIndex]);
7752 RuneType runeTo = RuneType(GetSpellProto()->EffectMiscValueB[m_effIndex]);
7754 if (apply)
7756 for(uint32 i = 0; i < MAX_RUNES; ++i)
7758 if (plr->GetCurrentRune(i) == runeFrom && !plr->GetRuneCooldown(i))
7760 plr->ConvertRune(i, runeTo);
7761 break;
7765 else
7767 for(uint32 i = 0; i < MAX_RUNES; ++i)
7769 if(plr->GetCurrentRune(i) == runeTo && plr->GetBaseRune(i) == runeFrom)
7771 plr->ConvertRune(i, runeFrom);
7772 break;
7778 void Aura::HandlePhase(bool apply, bool Real)
7780 if(!Real)
7781 return;
7783 // always non stackable
7784 if(apply)
7786 Unit::AuraList const& phases = m_target->GetAurasByType(SPELL_AURA_PHASE);
7787 if(!phases.empty())
7788 m_target->RemoveAurasDueToSpell(phases.front()->GetId(), this);
7791 // no-phase is also phase state so same code for apply and remove
7793 // phase auras normally not expected at BG but anyway better check
7794 if(m_target->GetTypeId() == TYPEID_PLAYER)
7796 // drop flag at invisible in bg
7797 if(((Player*)m_target)->InBattleGround())
7798 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
7799 bg->EventPlayerDroppedFlag((Player*)m_target);
7801 // GM-mode have mask 0xFFFFFFFF
7802 if(!((Player*)m_target)->isGameMaster())
7803 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7805 ((Player*)m_target)->GetSession()->SendSetPhaseShift(apply ? GetMiscValue() : PHASEMASK_NORMAL);
7807 if(GetEffIndex()==0)
7809 SpellAreaForAreaMapBounds saBounds = sSpellMgr.GetSpellAreaForAuraMapBounds(GetId());
7810 if(saBounds.first != saBounds.second)
7812 uint32 zone, area;
7813 m_target->GetZoneAndAreaId(zone, area);
7815 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
7817 // some auras remove at aura remove
7818 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
7819 m_target->RemoveAurasDueToSpell(itr->second->spellId);
7820 // some auras applied at aura apply
7821 else if(itr->second->autocast)
7823 if( !m_target->HasAura(itr->second->spellId, 0) )
7824 m_target->CastSpell(m_target, itr->second->spellId, true);
7830 else
7831 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7833 // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases)
7834 if(m_target->GetVisibility() != VISIBILITY_OFF)
7835 m_target->SetVisibility(m_target->GetVisibility());
7838 void Aura::UnregisterSingleCastAura()
7840 if (IsSingleTarget())
7842 if(Unit* caster = GetCaster())
7844 caster->GetSingleCastAuras().remove(this);
7846 else
7848 sLog.outError("Couldn't find the caster of the single target aura (SpellId %u), may crash later!", GetId());
7849 assert(false);
7851 m_isSingleTargetAura = false;
7855 void Aura::HandleAuraSafeFall( bool Apply, bool Real )
7857 // implemented in WorldSession::HandleMovementOpcodes
7859 // only special case
7860 if(Apply && Real && GetId() == 32474 && m_target->GetTypeId() == TYPEID_PLAYER)
7861 ((Player*)m_target)->ActivateTaxiPathTo(506, GetId());
7864 bool Aura::IsCritFromAbilityAura(Unit* caster, uint32& damage)
7866 Unit::AuraList const& auras = caster->GetAurasByType(SPELL_AURA_ABILITY_PERIODIC_CRIT);
7867 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
7869 if (!(*itr)->isAffectedOnSpell(m_spellProto))
7870 continue;
7871 if (!caster->isSpellCrit(m_target, m_spellProto, GetSpellSchoolMask(m_spellProto)))
7872 break;
7874 damage = caster->SpellCriticalDamageBonus(m_spellProto, damage, m_target);
7875 return true;
7877 return false;
7880 void Aura::HandleModTargetArmorPct(bool apply, bool Real)
7882 if(m_target->GetTypeId() != TYPEID_PLAYER)
7883 return;
7885 ((Player*)m_target)->UpdateArmorPenetration();
7888 void Aura::HandleAuraModAllCritChance(bool apply, bool Real)
7890 // spells required only Real aura add/remove
7891 if(!Real)
7892 return;
7894 if(m_target->GetTypeId() != TYPEID_PLAYER)
7895 return;
7897 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
7898 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
7899 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
7901 // included in Player::UpdateSpellCritChance calculation
7902 ((Player*)m_target)->UpdateAllSpellCritChances();
7905 void Aura::HandleAllowOnlyAbility(bool apply, bool Real)
7907 if(!Real)
7908 return;
7910 if(apply)
7912 m_target->setAttackTimer(BASE_ATTACK,m_duration);
7913 m_target->setAttackTimer(RANGED_ATTACK,m_duration);
7914 m_target->setAttackTimer(OFF_ATTACK,m_duration);
7916 else
7918 m_target->resetAttackTimer(BASE_ATTACK);
7919 m_target->resetAttackTimer(RANGED_ATTACK);
7920 m_target->resetAttackTimer(OFF_ATTACK);
7923 m_target->UpdateDamagePhysical(BASE_ATTACK);
7924 m_target->UpdateDamagePhysical(RANGED_ATTACK);
7925 m_target->UpdateDamagePhysical(OFF_ATTACK);