Restore spell 53563 work at 3.2.x
[getmangos.git] / src / game / SpellAuras.cpp
blob288abc0d58803c90561e739146c345093f90dfd7
1 /*
2 * Copyright (C) 2005-2009 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::SpellDamageBonus
68 &Aura::HandleNoImmediateEffect, // 15 SPELL_AURA_DAMAGE_SHIELD implemented in Unit::DoAttackDamage
69 &Aura::HandleModStealth, // 16 SPELL_AURA_MOD_STEALTH
70 &Aura::HandleNoImmediateEffect, // 17 SPELL_AURA_MOD_STEALTH_DETECT
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)
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) 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 that has only visual effect
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
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
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
142 &Aura::HandlePeriodicDamagePCT, // 89 SPELL_AURA_PERIODIC_DAMAGE_PERCENT
143 &Aura::HandleUnused, // 90 unused (3.0.8a) 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? all player can see all auras now, but still have spells including GM-spell
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
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
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) 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
200 &Aura::HandleNULL, //147 SPELL_AURA_ADD_CREATURE_IMMUNITY
201 &Aura::HandleAuraRetainComboPoints, //148 SPELL_AURA_RETAIN_COMBO_POINTS
202 &Aura::HandleNoImmediateEffect, //149 SPELL_AURA_REDUCE_PUSHBACK
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
207 &Aura::HandleNoImmediateEffect, //154 SPELL_AURA_MOD_STEALTH_LEVEL
208 &Aura::HandleNoImmediateEffect, //155 SPELL_AURA_MOD_WATER_BREATHING
209 &Aura::HandleNoImmediateEffect, //156 SPELL_AURA_MOD_REPUTATION_GAIN
210 &Aura::HandleNULL, //157 SPELL_AURA_PET_DAMAGE_MULTI
211 &Aura::HandleShieldBlockValue, //158 SPELL_AURA_MOD_SHIELD_BLOCKVALUE
212 &Aura::HandleNoImmediateEffect, //159 SPELL_AURA_NO_PVP_CREDIT only for Honorless Target spell
213 &Aura::HandleNoImmediateEffect, //160 SPELL_AURA_MOD_AOE_AVOIDANCE implemented in Unit::MagicSpellHitResult
214 &Aura::HandleNoImmediateEffect, //161 SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
215 &Aura::HandleAuraPowerBurn, //162 SPELL_AURA_POWER_BURN_MANA
216 &Aura::HandleNoImmediateEffect, //163 SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
217 &Aura::HandleUnused, //164 unused (3.0.8a), only one test spell
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) 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
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) old SPELL_AURA_MOD_FLAT_SPELL_CRIT_DAMAGE_VERSUS
235 &Aura::HandleAuraModResistenceOfStatPercent, //182 SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT
236 &Aura::HandleNULL, //183 SPELL_AURA_MOD_CRITICAL_THREAT only used in 28746
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::HandleNULL, //194 SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
248 &Aura::HandleNoImmediateEffect, //195 SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL implement in Unit::CalculateSpellDamage
249 &Aura::HandleNULL, //196 SPELL_AURA_MOD_COOLDOWN
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) 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_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::CalculateSpellDamage
257 &Aura::HandleNoImmediateEffect, //204 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE implemented in Unit::CalculateMeleeDamage and Unit::CalculateSpellDamage
258 &Aura::HandleNULL, //205 vulnerable to school dmg?
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 Commentator's Command
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::HandleNULL, //214 Tamed Pet Passive
268 &Aura::HandleArenaPreparation, //215 SPELL_AURA_ARENA_PREPARATION
269 &Aura::HandleModCastingSpeed, //216 SPELL_AURA_HASTE_SPELLS
270 &Aura::HandleUnused, //217 unused (3.0.8a)
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) only for spell 44586 that not used in real spell cast
276 &Aura::HandleNULL, //223 Cold Stare
277 &Aura::HandleUnused, //224 unused (3.0.8a)
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 stealth detection
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
296 &Aura::HandleNULL, //243 faction reaction override spells
297 &Aura::HandleComprehendLanguage, //244 Comprehend language
298 &Aura::HandleNULL, //245 SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
299 &Aura::HandleNoImmediateEffect, //246 SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
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::HandleNULL, //263 SPELL_AURA_ALLOW_ONLY_ABILITY player can use only abilities set in SpellClassMask
317 &Aura::HandleUnused, //264 unused (3.0.8a)
318 &Aura::HandleUnused, //265 unused (3.0.8a)
319 &Aura::HandleUnused, //266 unused (3.0.8a)
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::HandleNULL, //269 ignore DR effects?
323 &Aura::HandleNULL, //270 SPELL_AURA_MOD_IGNORE_TARGET_RESIST
324 &Aura::HandleNoImmediateEffect, //271 SPELL_AURA_MOD_DAMAGE_FROM_CASTER implemented in Unit::SpellDamageBonus
325 &Aura::HandleNULL, //272 reduce spell cast time?
326 &Aura::HandleNULL, //273 x-ray effect
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::HandleNULL, //281 SPELL_AURA_MOD_HONOR_GAIN
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::HandleUnused, //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::HandleUnused, //288 increase parry/deflect, prevent attack
342 &Aura::HandleUnused, //289 unused
343 &Aura::HandleAuraModAllCritChance, //290 SPELL_AURA_MOD_ALL_CRIT_CHANCE
344 &Aura::HandleUnused, //291 1 spell (+pct experience bonus)
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::HandleNULL, //295 unused
349 &Aura::HandleNULL, //296 2 spells
350 &Aura::HandleNULL, //297 1 spell (counter spell school?)
351 &Aura::HandleNULL, //298 unused
352 &Aura::HandleNULL, //299 unused
353 &Aura::HandleNULL, //300 3 spells (share damage?)
354 &Aura::HandleNULL, //301 5 spells
355 &Aura::HandleNULL, //302 unused
356 &Aura::HandleNULL, //303 17 spells
357 &Aura::HandleNULL, //304 2 spells (alcohol effect?)
358 &Aura::HandleNULL, //305 2 spells
359 &Aura::HandleNULL //306 1 spell
362 static AuraType const frozenAuraTypes[] = { SPELL_AURA_MOD_ROOT, SPELL_AURA_MOD_STUN, SPELL_AURA_NONE };
364 Aura::Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem) :
365 m_spellmod(NULL), m_caster_guid(0), m_target(target), m_castItemGuid(castItem?castItem->GetGUID():0),
366 m_timeCla(1000), m_periodicTimer(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE),
367 m_effIndex(eff), m_auraSlot(MAX_AURAS), m_auraFlags(AFLAG_NONE), m_auraLevel(1), m_procCharges(0), m_stackAmount(1),
368 m_positive(false), m_permanent(false), m_isPeriodic(false), m_isAreaAura(false), m_isPersistent(false),
369 m_isRemovedOnShapeLost(true), m_in_use(0), m_deleted(false)
371 assert(target);
373 assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
375 m_spellProto = spellproto;
377 m_currentBasePoints = currentBasePoints ? *currentBasePoints : m_spellProto->EffectBasePoints[eff];
379 m_isPassive = IsPassiveSpell(GetId());
380 m_positive = IsPositiveEffect(GetId(), m_effIndex);
382 m_isSingleTargetAura = IsSingleTargetSpell(m_spellProto);
384 m_applyTime = time(NULL);
386 int32 damage;
387 if(!caster)
389 m_caster_guid = target->GetGUID();
390 damage = m_currentBasePoints+1; // stored value-1
391 m_maxduration = target->CalculateSpellDuration(m_spellProto, m_effIndex, target);
393 else
395 m_caster_guid = caster->GetGUID();
397 damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target);
398 m_maxduration = caster->CalculateSpellDuration(m_spellProto, m_effIndex, target);
400 if (!damage && castItem && castItem->GetItemSuffixFactor())
402 ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
403 if(item_rand_suffix)
405 for (int k = 0; k < 3; ++k)
407 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand_suffix->enchant_id[k]);
408 if(pEnchant)
410 for (int t = 0; t < 3; ++t)
411 if(pEnchant->spellid[t] == m_spellProto->Id)
413 damage = uint32((item_rand_suffix->prefix[k]*castItem->GetItemSuffixFactor()) / 10000 );
414 break;
418 if(damage)
419 break;
425 if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0)
426 m_permanent = true;
428 Player* modOwner = caster ? caster->GetSpellModOwner() : NULL;
430 if(!m_permanent && modOwner)
432 modOwner->ApplySpellMod(GetId(), SPELLMOD_DURATION, m_maxduration);
433 // Get zero duration aura after - need set m_maxduration > 0 for apply/remove aura work
434 if (m_maxduration<=0)
435 m_maxduration = 1;
438 m_duration = m_maxduration;
440 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);
442 m_effIndex = eff;
443 SetModifier(AuraType(m_spellProto->EffectApplyAuraName[eff]), damage, m_spellProto->EffectAmplitude[eff], m_spellProto->EffectMiscValue[eff]);
445 // Apply periodic time mod
446 if(modOwner && m_modifier.periodictime)
447 modOwner->ApplySpellMod(GetId(), SPELLMOD_ACTIVATION_TIME, m_modifier.periodictime);
449 // Start periodic on next tick or at aura apply
450 if (!(m_spellProto->AttributesEx5 & SPELL_ATTR_EX5_START_PERIODIC_AT_APPLY))
451 m_periodicTimer += m_modifier.periodictime;
453 m_isDeathPersist = IsDeathPersistentSpell(m_spellProto);
455 m_procCharges = m_spellProto->procCharges;
456 if(modOwner)
457 modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
459 m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() &&
460 m_spellProto->Stances &&
461 !(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) &&
462 !(m_spellProto->Attributes & SPELL_ATTR_NOT_SHAPESHIFT));
464 if (caster && m_spellProto->Id == 22959) // Improved Scorch
466 // Glyph of Improved Scorch
467 if (Aura* glyph = caster->GetDummyAura(56371))
468 m_stackAmount = glyph->GetModifier()->m_amount;
472 Aura::~Aura()
476 AreaAura::AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
477 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
479 m_isAreaAura = true;
481 // caster==NULL in constructor args if target==caster in fact
482 Unit* caster_ptr = caster ? caster : target;
484 m_radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
485 if(Player* modOwner = caster_ptr->GetSpellModOwner())
486 modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
488 switch(spellproto->Effect[eff])
490 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
491 m_areaAuraType = AREA_AURA_PARTY;
492 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
493 m_modifier.m_auraname = SPELL_AURA_NONE;
494 break;
495 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
496 m_areaAuraType = AREA_AURA_RAID;
497 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
498 m_modifier.m_auraname = SPELL_AURA_NONE;
499 // Light's Beacon not applied to caster itself (TODO: more generic check for another simialr spell if any?)
500 else if (target == caster_ptr && m_spellProto->Id == 53651)
501 m_modifier.m_auraname = SPELL_AURA_NONE;
502 break;
503 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
504 m_areaAuraType = AREA_AURA_FRIEND;
505 break;
506 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
507 m_areaAuraType = AREA_AURA_ENEMY;
508 if (target == caster_ptr)
509 m_modifier.m_auraname = SPELL_AURA_NONE; // Do not do any effect on self
510 break;
511 case SPELL_EFFECT_APPLY_AREA_AURA_PET:
512 m_areaAuraType = AREA_AURA_PET;
513 break;
514 case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
515 m_areaAuraType = AREA_AURA_OWNER;
516 if (target == caster_ptr)
517 m_modifier.m_auraname = SPELL_AURA_NONE;
518 break;
519 default:
520 sLog.outError("Wrong spell effect in AreaAura constructor");
521 ASSERT(false);
522 break;
526 AreaAura::~AreaAura()
530 PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
531 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
533 m_isPersistent = true;
536 PersistentAreaAura::~PersistentAreaAura()
540 SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
541 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
543 if (caster)
544 m_casters_target_guid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelection() : caster->GetTargetGUID();
545 else
546 m_casters_target_guid = 0;
549 SingleEnemyTargetAura::~SingleEnemyTargetAura()
553 Unit* SingleEnemyTargetAura::GetTriggerTarget() const
555 return ObjectAccessor::GetUnit(*m_target, m_casters_target_guid);
558 Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem)
560 if (IsAreaAuraEffect(spellproto->Effect[eff]))
561 return new AreaAura(spellproto, eff, currentBasePoints, target, caster, castItem);
563 uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff];
565 if(SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
566 for (int i = 0; i < 3; ++i)
567 if (triggeredSpellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_ENEMY)
568 return new SingleEnemyTargetAura(spellproto, eff, currentBasePoints, target, caster, castItem);
570 return new Aura(spellproto, eff, currentBasePoints, target, caster, castItem);
573 Unit* Aura::GetCaster() const
575 if(m_caster_guid==m_target->GetGUID())
576 return m_target;
578 //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
579 //must return caster even if it's in another grid/map
580 Unit *unit = ObjectAccessor::GetObjectInWorld(m_caster_guid, (Unit*)NULL);
581 return unit && unit->IsInWorld() ? unit : NULL;
584 void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
586 m_modifier.m_auraname = t;
587 m_modifier.m_amount = a;
588 m_modifier.m_miscvalue = miscValue;
589 m_modifier.periodictime = pt;
592 void Aura::Update(uint32 diff)
594 if (m_duration > 0)
596 m_duration -= diff;
597 if (m_duration < 0)
598 m_duration = 0;
599 m_timeCla -= diff;
601 // GetEffIndex()==0 prevent double/triple apply manaPerSecond/manaPerSecondPerLevel to same spell with many auras
602 // all spells with manaPerSecond/manaPerSecondPerLevel have aura in effect 0
603 if(GetEffIndex()==0 && m_timeCla <= 0)
605 if(Unit* caster = GetCaster())
607 Powers powertype = Powers(m_spellProto->powerType);
608 int32 manaPerSecond = m_spellProto->manaPerSecond + m_spellProto->manaPerSecondPerLevel * caster->getLevel();
609 m_timeCla = 1*IN_MILISECONDS;
610 if (manaPerSecond)
612 if(powertype==POWER_HEALTH)
613 caster->ModifyHealth(-manaPerSecond);
614 else
615 caster->ModifyPower(powertype,-manaPerSecond);
621 // Channeled aura required check distance from caster
622 if(IsChanneledSpell(m_spellProto) && m_caster_guid != m_target->GetGUID())
624 Unit* caster = GetCaster();
625 if(!caster)
627 m_target->RemoveAura(GetId(), GetEffIndex());
628 return;
631 // Get spell range
632 float radius;
633 SpellModOp mod;
634 if (m_spellProto->EffectRadiusIndex[GetEffIndex()])
636 radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellProto->EffectRadiusIndex[GetEffIndex()]));
637 mod = SPELLMOD_RADIUS;
639 else
641 radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellProto->rangeIndex));
642 mod = SPELLMOD_RANGE;
645 if(Player* modOwner = caster->GetSpellModOwner())
646 modOwner->ApplySpellMod(GetId(), mod, radius, NULL);
648 if(!caster->IsWithinDistInMap(m_target, radius))
650 m_target->RemoveAura(GetId(), GetEffIndex());
651 return;
655 if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
657 m_periodicTimer -= diff;
658 if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
660 // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls)
661 m_periodicTimer += m_modifier.periodictime;
662 PeriodicTick();
667 void AreaAura::Update(uint32 diff)
669 // update for the caster of the aura
670 if(m_caster_guid == m_target->GetGUID())
672 Unit* caster = m_target;
674 if( !caster->hasUnitState(UNIT_STAT_ISOLATED) )
676 Unit* owner = caster->GetCharmerOrOwner();
677 if (!owner)
678 owner = caster;
679 std::list<Unit *> targets;
681 switch(m_areaAuraType)
683 case AREA_AURA_PARTY:
685 Group *pGroup = NULL;
687 if (owner->GetTypeId() == TYPEID_PLAYER)
688 pGroup = ((Player*)owner)->GetGroup();
690 if( pGroup)
692 uint8 subgroup = ((Player*)owner)->GetSubGroup();
693 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
695 Player* Target = itr->getSource();
696 if(Target && Target->isAlive() && Target->GetSubGroup()==subgroup && caster->IsFriendlyTo(Target))
698 if(caster->IsWithinDistInMap(Target, m_radius))
699 targets.push_back(Target);
700 Pet *pet = Target->GetPet();
701 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
702 targets.push_back(pet);
706 else
708 // add owner
709 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
710 targets.push_back(owner);
711 // add caster's pet
712 Unit* pet = caster->GetPet();
713 if( pet && caster->IsWithinDistInMap(pet, m_radius))
714 targets.push_back(pet);
716 break;
718 case AREA_AURA_RAID:
720 Group *pGroup = NULL;
722 if (owner->GetTypeId() == TYPEID_PLAYER)
723 pGroup = ((Player*)owner)->GetGroup();
725 if( pGroup)
727 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
729 Player* Target = itr->getSource();
730 if(Target && Target->isAlive() && caster->IsFriendlyTo(Target))
732 if(caster->IsWithinDistInMap(Target, m_radius))
733 targets.push_back(Target);
734 Pet *pet = Target->GetPet();
735 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
736 targets.push_back(pet);
740 else
742 // add owner
743 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
744 targets.push_back(owner);
745 // add caster's pet
746 Unit* pet = caster->GetPet();
747 if( pet && caster->IsWithinDistInMap(pet, m_radius))
748 targets.push_back(pet);
750 break;
752 case AREA_AURA_FRIEND:
754 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
755 Cell cell(p);
756 cell.data.Part.reserved = ALL_DISTRICT;
757 cell.SetNoCreate();
759 MaNGOS::AnyFriendlyUnitInObjectRangeCheck u_check(caster, owner, m_radius);
760 MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck> searcher(caster,targets, u_check);
761 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
762 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
763 CellLock<GridReadGuard> cell_lock(cell, p);
764 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap(), *caster, m_radius);
765 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap(), *caster, m_radius);
766 break;
768 case AREA_AURA_ENEMY:
770 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
771 Cell cell(p);
772 cell.data.Part.reserved = ALL_DISTRICT;
773 cell.SetNoCreate();
775 MaNGOS::AnyAoETargetUnitInObjectRangeCheck u_check(caster, owner, m_radius); // No GetCharmer in searcher
776 MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck> searcher(caster, targets, u_check);
777 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
778 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
779 CellLock<GridReadGuard> cell_lock(cell, p);
780 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap(), *caster, m_radius);
781 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap(), *caster, m_radius);
782 break;
784 case AREA_AURA_OWNER:
785 case AREA_AURA_PET:
787 if(owner != caster && caster->IsWithinDistInMap(owner, m_radius))
788 targets.push_back(owner);
789 break;
793 for(std::list<Unit *>::iterator tIter = targets.begin(); tIter != targets.end(); tIter++)
795 // flag for seelction is need apply aura to current iteration target
796 bool apply = true;
798 // we need ignore present caster self applied are auras sometime
799 // in cases if this only auras applied for spell effect
800 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), m_effIndex);
801 for(Unit::AuraMap::const_iterator i = (*tIter)->GetAuras().lower_bound(spair); i != (*tIter)->GetAuras().upper_bound(spair); ++i)
803 if (i->second->IsDeleted())
804 continue;
806 switch(m_areaAuraType)
808 case AREA_AURA_ENEMY:
809 // non caster self-casted auras (non stacked)
810 if(i->second->GetModifier()->m_auraname != SPELL_AURA_NONE)
811 apply = false;
812 break;
813 case AREA_AURA_RAID:
814 // non caster self-casted auras (stacked from diff. casters)
815 if(i->second->GetModifier()->m_auraname != SPELL_AURA_NONE || i->second->GetCasterGUID() == GetCasterGUID())
816 apply = false;
817 break;
818 default:
819 // in generic case not allow stacking area auras
820 apply = false;
821 break;
824 if(!apply)
825 break;
828 if(!apply)
829 continue;
831 if(SpellEntry const *actualSpellInfo = spellmgr.SelectAuraRankForPlayerLevel(GetSpellProto(), (*tIter)->getLevel()))
833 int32 actualBasePoints = m_currentBasePoints;
834 // recalculate basepoints for lower rank (all AreaAura spell not use custom basepoints?)
835 if(actualSpellInfo != GetSpellProto())
836 actualBasePoints = actualSpellInfo->EffectBasePoints[m_effIndex];
837 AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
838 aur->SetAuraDuration(GetAuraDuration());
839 (*tIter)->AddAura(aur);
843 Aura::Update(diff);
845 else // aura at non-caster
847 Unit* caster = GetCaster();
849 Aura::Update(diff);
851 // remove aura if out-of-range from caster (after teleport for example)
852 // or caster is isolated or caster no longer has the aura
853 // or caster is (no longer) friendly
854 bool needFriendly = (m_areaAuraType == AREA_AURA_ENEMY ? false : true);
855 if( !caster || caster->hasUnitState(UNIT_STAT_ISOLATED) ||
856 !caster->IsWithinDistInMap(m_target, m_radius) ||
857 !caster->HasAura(GetId(), GetEffIndex()) ||
858 caster->IsFriendlyTo(m_target) != needFriendly
861 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(),GetCasterGUID());
863 else if( m_areaAuraType == AREA_AURA_PARTY) // check if in same sub group
865 // not check group if target == owner or target == pet
866 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
868 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
870 Group *pGroup = check ? check->GetGroup() : NULL;
871 if( pGroup )
873 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
874 if(!checkTarget || !pGroup->SameSubGroup(check, checkTarget))
875 m_target->RemoveAura(GetId(), GetEffIndex());
877 else
878 m_target->RemoveAura(GetId(), GetEffIndex());
881 else if( m_areaAuraType == AREA_AURA_RAID) // TODO: fix me!
883 // not check group if target == owner or target == pet
884 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
886 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
888 Group *pGroup = check ? check->GetGroup() : NULL;
889 if( pGroup )
891 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
892 if(!checkTarget)
893 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
895 else
896 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
899 else if( m_areaAuraType == AREA_AURA_PET || m_areaAuraType == AREA_AURA_OWNER )
901 if( m_target->GetGUID() != caster->GetCharmerOrOwnerGUID() )
902 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
907 void PersistentAreaAura::Update(uint32 diff)
909 bool remove = false;
911 // remove the aura if its caster or the dynamic object causing it was removed
912 // or if the target moves too far from the dynamic object
913 if(Unit *caster = GetCaster())
915 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
916 if (dynObj)
918 if (!m_target->IsWithinDistInMap(dynObj, dynObj->GetRadius()))
919 remove = true;
921 else
922 remove = true;
924 else
925 remove = true;
927 Aura::Update(diff);
929 if(remove)
930 m_target->RemoveAura(GetId(), GetEffIndex());
933 void Aura::ApplyModifier(bool apply, bool Real)
935 AuraType aura = m_modifier.m_auraname;
937 SetInUse(true);
938 if(aura < TOTAL_AURAS)
939 (*this.*AuraHandler [aura])(apply, Real);
940 SetInUse(false);
943 bool Aura::IsNeedVisibleSlot(Unit const* caster) const
945 bool totemAura = caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem();
947 // passive auras (except totem auras) do not get placed in the slots
948 if (m_isPassive && !totemAura)
949 return false;
951 // generic not caster case
952 if (m_target != caster)
953 return true;
955 // special area auras case at caster
956 switch(m_spellProto->Effect[GetEffIndex()])
958 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
959 return false;
960 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
961 // not sure is totemAura need, just preserve old code results
962 return totemAura || m_modifier.m_auraname != SPELL_AURA_NONE;
963 default: break;
966 return true;
969 void Aura::_AddAura()
971 if (!GetId())
972 return;
973 if(!m_target)
974 return;
976 // Second aura if some spell
977 bool secondaura = false;
978 // Try find slot for aura
979 uint8 slot = NULL_AURA_SLOT;
980 // Lookup for some spell auras (and get slot from it)
981 for(uint8 i = 0; i < m_effIndex; ++i)
983 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
984 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
986 // allow use single slot only by auras from same caster
987 if(itr->second->GetCasterGUID()==GetCasterGUID())
989 slot = itr->second->GetAuraSlot();
990 secondaura = true;
991 break;
994 if (secondaura)
995 break;
997 // Lookup free slot
998 if (!secondaura && m_target->GetVisibleAurasCount() < MAX_AURAS)
1000 Unit::VisibleAuraMap const *visibleAuras = m_target->GetVisibleAuras();
1001 for(uint8 i = 0; i < MAX_AURAS; ++i)
1003 Unit::VisibleAuraMap::const_iterator itr = visibleAuras->find(i);
1004 if(itr == visibleAuras->end())
1006 slot = i;
1007 // update for out of range group members (on 1 slot use)
1008 m_target->UpdateAuraForGroup(slot);
1009 break;
1014 Unit* caster = GetCaster();
1016 // set infinity cooldown state for spells
1017 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1019 if (m_spellProto->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)
1021 Item* castItem = m_castItemGuid ? ((Player*)caster)->GetItemByGuid(m_castItemGuid) : NULL;
1022 ((Player*)caster)->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true);
1026 if (IsNeedVisibleSlot(caster))
1028 SetAuraSlot( slot );
1029 if(slot < MAX_AURAS) // slot found send data to client
1031 SetAura(false);
1032 SetAuraFlags((1 << GetEffIndex()) | AFLAG_NOT_CASTER | ((GetAuraMaxDuration() > 0) ? AFLAG_DURATION : AFLAG_NONE) | (IsPositive() ? AFLAG_POSITIVE : AFLAG_NEGATIVE));
1033 SetAuraLevel(caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
1034 SendAuraUpdate(false);
1037 //*****************************************************
1038 // Update target aura state flag (at 1 aura apply)
1039 // TODO: Make it easer
1040 //*****************************************************
1041 if (!secondaura)
1043 // Sitdown on apply aura req seated
1044 if (m_spellProto->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED && !m_target->IsSitState())
1045 m_target->SetStandState(UNIT_STAND_STATE_SIT);
1047 // register aura diminishing on apply
1048 if (getDiminishGroup() != DIMINISHING_NONE )
1049 m_target->ApplyDiminishingAura(getDiminishGroup(), true);
1051 // Update Seals information
1052 if (IsSealSpell(m_spellProto))
1053 m_target->ModifyAuraState(AURA_STATE_JUDGEMENT, true);
1055 // Conflagrate aura state on Immolate and Shadowflame
1056 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARLOCK &&
1057 // Immolate
1058 ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1059 // Shadowflame
1060 (m_spellProto->SpellFamilyFlags2 & 0x00000002)))
1061 m_target->ModifyAuraState(AURA_STATE_CONFLAGRATE, true);
1063 // Faerie Fire (druid versions)
1064 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
1065 m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE, true);
1067 // Victorious
1068 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARRIOR && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
1069 m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, true);
1071 // Swiftmend state on Regrowth & Rejuvenation
1072 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x50)))
1073 m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, true);
1075 // Deadly poison aura state
1076 if(m_spellProto->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellProto->SpellFamilyFlags & UI64LIT(0x10000)))
1077 m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON, true);
1079 // Enrage aura state
1080 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1081 m_target->ModifyAuraState(AURA_STATE_ENRAGE, true);
1086 bool Aura::_RemoveAura()
1088 // Remove all triggered by aura spells vs unlimited duration
1089 // except same aura replace case
1090 if(m_removeMode!=AURA_REMOVE_BY_STACK)
1091 CleanupTriggeredSpells();
1093 Unit* caster = GetCaster();
1095 if(caster && IsPersistent())
1097 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
1098 if (dynObj)
1099 dynObj->RemoveAffected(m_target);
1102 //passive auras do not get put in slots
1103 // Note: but totem can be not accessible for aura target in time remove (to far for find in grid)
1104 //if(m_isPassive && !(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()))
1105 // return;
1107 uint8 slot = GetAuraSlot();
1109 if(slot >= MAX_AURAS) // slot not set
1110 return false;
1112 if(m_target->GetVisibleAura(slot) == 0)
1113 return false;
1115 bool lastaura = true;
1117 // find other aura in same slot (current already removed from list)
1118 for(uint8 i = 0; i < 3; ++i)
1120 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
1121 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
1123 if(itr->second->GetAuraSlot() == slot)
1125 lastaura = false;
1126 break;
1129 if(!lastaura)
1130 break;
1133 // only remove icon when the last aura of the spell is removed (current aura already removed from list)
1134 if (!lastaura)
1135 return false;
1137 // unregister aura diminishing (and store last time)
1138 if (getDiminishGroup() != DIMINISHING_NONE )
1139 m_target->ApplyDiminishingAura(getDiminishGroup(), false);
1141 SetAura(true);
1142 SetAuraFlags(AFLAG_NONE);
1143 SetAuraLevel(0);
1144 SendAuraUpdate(true);
1146 // update for out of range group members
1147 m_target->UpdateAuraForGroup(slot);
1149 //*****************************************************
1150 // Update target aura state flag (at last aura remove)
1151 //*****************************************************
1152 // Enrage aura state
1153 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1154 m_target->ModifyAuraState(AURA_STATE_ENRAGE, false);
1156 uint32 removeState = 0;
1157 uint64 removeFamilyFlag = m_spellProto->SpellFamilyFlags;
1158 uint32 removeFamilyFlag2 = m_spellProto->SpellFamilyFlags2;
1159 switch(m_spellProto->SpellFamilyName)
1161 case SPELLFAMILY_PALADIN:
1162 if (IsSealSpell(m_spellProto))
1163 removeState = AURA_STATE_JUDGEMENT; // Update Seals information
1164 break;
1165 case SPELLFAMILY_WARLOCK:
1166 // Conflagrate aura state on Immolate and Shadowflame,
1167 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1168 (m_spellProto->SpellFamilyFlags2 & 0x00000002))
1170 removeFamilyFlag = UI64LIT(0x0000000000000004);
1171 removeFamilyFlag2 = 0x00000002;
1172 removeState = AURA_STATE_CONFLAGRATE;
1174 break;
1175 case SPELLFAMILY_DRUID:
1176 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400))
1177 removeState = AURA_STATE_FAERIE_FIRE; // Faerie Fire (druid versions)
1178 else if(m_spellProto->SpellFamilyFlags & UI64LIT(0x50))
1180 removeFamilyFlag = 0x50;
1181 removeState = AURA_STATE_SWIFTMEND; // Swiftmend aura state
1183 break;
1184 case SPELLFAMILY_WARRIOR:
1185 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000))
1186 removeState = AURA_STATE_WARRIOR_VICTORY_RUSH; // Victorious
1187 break;
1188 case SPELLFAMILY_ROGUE:
1189 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x10000))
1190 removeState = AURA_STATE_DEADLY_POISON; // Deadly poison aura state
1191 break;
1192 case SPELLFAMILY_HUNTER:
1193 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
1194 removeState = AURA_STATE_FAERIE_FIRE; // Sting (hunter versions)
1197 // Remove state (but need check other auras for it)
1198 if (removeState)
1200 bool found = false;
1201 Unit::AuraMap& Auras = m_target->GetAuras();
1202 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
1204 SpellEntry const *auraSpellInfo = (*i).second->GetSpellProto();
1205 if(auraSpellInfo->SpellFamilyName == m_spellProto->SpellFamilyName &&
1206 (auraSpellInfo->SpellFamilyFlags & removeFamilyFlag || auraSpellInfo->SpellFamilyFlags2 & removeFamilyFlag2))
1208 found = true;
1209 break;
1212 // this has been last aura
1213 if(!found)
1214 m_target->ModifyAuraState(AuraState(removeState), false);
1217 // reset cooldown state for spells
1218 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1220 if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE )
1221 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
1222 ((Player*)caster)->SendCooldownEvent(GetSpellProto());
1225 return true;
1228 void Aura::SendAuraUpdate(bool remove)
1230 WorldPacket data(SMSG_AURA_UPDATE);
1231 data.append(m_target->GetPackGUID());
1232 data << uint8(GetAuraSlot());
1233 data << uint32(remove ? 0 : GetId());
1235 if(remove)
1237 m_target->SendMessageToSet(&data, true);
1238 return;
1241 uint8 auraFlags = GetAuraFlags();
1242 data << uint8(auraFlags);
1243 data << uint8(GetAuraLevel());
1244 data << uint8(m_procCharges ? m_procCharges*m_stackAmount : m_stackAmount);
1246 if(!(auraFlags & AFLAG_NOT_CASTER))
1248 data << uint8(0); // pguid
1251 if(auraFlags & AFLAG_DURATION)
1253 data << uint32(GetAuraMaxDuration());
1254 data << uint32(GetAuraDuration());
1257 m_target->SendMessageToSet(&data, true);
1260 void Aura::SetStackAmount(uint8 stackAmount)
1262 Unit *target = GetTarget();
1263 Unit *caster = GetCaster();
1264 if (!target || !caster)
1265 return;
1267 bool refresh = stackAmount >= m_stackAmount;
1268 if (stackAmount != m_stackAmount)
1270 m_stackAmount = stackAmount;
1271 int32 amount = m_stackAmount * caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, target);
1272 // Reapply if amount change
1273 if (amount!=m_modifier.m_amount)
1275 ApplyModifier(false, true);
1276 m_modifier.m_amount = amount;
1277 ApplyModifier(true, true);
1281 if (refresh)
1282 // Stack increased refresh duration
1283 RefreshAura();
1284 else
1285 // Stack decreased only send update
1286 SendAuraUpdate(false);
1289 bool Aura::modStackAmount(int32 num)
1291 // Can`t mod
1292 if (!m_spellProto->StackAmount)
1293 return true;
1295 // Modify stack but limit it
1296 int32 stackAmount = m_stackAmount + num;
1297 if (stackAmount > m_spellProto->StackAmount)
1298 stackAmount = m_spellProto->StackAmount;
1299 else if (stackAmount <=0) // Last aura from stack removed
1301 m_stackAmount = 0;
1302 return true; // need remove aura
1305 // Update stack amount
1306 SetStackAmount(stackAmount);
1307 return false;
1310 void Aura::RefreshAura()
1312 m_duration = m_maxduration;
1313 SendAuraUpdate(false);
1316 bool Aura::isAffectedOnSpell(SpellEntry const *spell) const
1318 // Check family name
1319 if (spell->SpellFamilyName != m_spellProto->SpellFamilyName)
1320 return false;
1321 // Check EffectClassMask
1322 uint32 const *ptr = getAuraSpellClassMask();
1323 if (((uint64*)ptr)[0] & spell->SpellFamilyFlags)
1324 return true;
1325 if (ptr[2] & spell->SpellFamilyFlags2)
1326 return true;
1327 return false;
1330 void Aura::ReapplyAffectedPassiveAuras( Unit* target )
1332 std::set<uint32> affectedPassives;
1334 for(Unit::AuraMap::const_iterator itr = target->GetAuras().begin(); itr != target->GetAuras().end(); ++itr)
1336 // permanent passive
1337 if (itr->second->IsPassive() && itr->second->IsPermanent() &&
1338 // non deleted and not same aura (any with same spell id)
1339 !itr->second->IsDeleted() && itr->second->GetId() != GetId() &&
1340 // only applied by self and affected by aura
1341 itr->second->GetCasterGUID() == target->GetGUID() && isAffectedOnSpell(itr->second->GetSpellProto()))
1343 affectedPassives.insert(itr->second->GetId());
1347 for(std::set<uint32>::const_iterator set_itr = affectedPassives.begin(); set_itr != affectedPassives.end(); ++set_itr)
1349 target->RemoveAurasDueToSpell(*set_itr);
1350 target->CastSpell(m_target, *set_itr, true);
1354 /*********************************************************/
1355 /*** BASIC AURA FUNCTION ***/
1356 /*********************************************************/
1357 void Aura::HandleAddModifier(bool apply, bool Real)
1359 if(m_target->GetTypeId() != TYPEID_PLAYER || !Real)
1360 return;
1362 if(m_modifier.m_miscvalue >= MAX_SPELLMOD)
1363 return;
1365 if (apply)
1367 // Add custom charges for some mod aura
1368 switch (m_spellProto->Id)
1370 case 17941: // Shadow Trance
1371 case 22008: // Netherwind Focus
1372 case 31834: // Light's Grace
1373 case 34754: // Clearcasting
1374 case 34936: // Backlash
1375 case 48108: // Hot Streak
1376 case 51124: // Killing Machine
1377 case 54741: // Firestarter
1378 case 57761: // Fireball!
1379 SetAuraCharges(1);
1380 break;
1383 SpellModifier *mod = new SpellModifier;
1384 mod->op = SpellModOp(m_modifier.m_miscvalue);
1385 mod->value = m_modifier.m_amount;
1386 mod->type = SpellModType(m_modifier.m_auraname); // SpellModType value == spell aura types
1387 mod->spellId = GetId();
1389 uint32 const *ptr;
1390 switch (m_effIndex)
1392 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1393 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1394 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1395 default:
1396 return;
1399 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1400 mod->mask2= (uint64)ptr[2];
1401 mod->charges = m_procCharges;
1403 m_spellmod = mod;
1406 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
1408 // reapply talents to own passive persistent auras
1409 ReapplyAffectedPassiveAuras(m_target);
1411 // re-aplly talents and passives applied to pet (it affected by player spellmods)
1412 if(Pet* pet = m_target->GetPet())
1413 ReapplyAffectedPassiveAuras(pet);
1415 for(int i = 0; i < MAX_TOTEM; ++i)
1416 if(m_target->m_TotemSlot[i])
1417 if(Creature* totem = m_target->GetMap()->GetCreature(m_target->m_TotemSlot[i]))
1418 ReapplyAffectedPassiveAuras(totem);
1420 void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
1422 // Use SpellModifier structure for check
1423 // used only fields:
1424 // spellId, mask, mask2
1425 if (apply)
1427 SpellModifier *mod = new SpellModifier;
1428 mod->spellId = GetId();
1430 uint32 const *ptr;
1431 switch (m_effIndex)
1433 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1434 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1435 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1436 default:
1437 return;
1440 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1441 mod->mask2= (uint64)ptr[2];
1442 m_spellmod = mod;
1444 else
1446 delete m_spellmod;
1447 m_spellmod = NULL;
1451 void Aura::TriggerSpell()
1453 Unit* caster = GetCaster();
1454 Unit* target = GetTriggerTarget();
1456 if(!caster || !target)
1457 return;
1459 // generic casting code with custom spells and target/caster customs
1460 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
1462 SpellEntry const *triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1463 SpellEntry const *auraSpellInfo = GetSpellProto();
1464 uint32 auraId = auraSpellInfo->Id;
1466 // specific code for cases with no trigger spell provided in field
1467 if (triggeredSpellInfo == NULL)
1469 switch(auraSpellInfo->SpellFamilyName)
1471 case SPELLFAMILY_GENERIC:
1473 switch(auraId)
1475 // Firestone Passive (1-5 ranks)
1476 case 758:
1477 case 17945:
1478 case 17947:
1479 case 17949:
1480 case 27252:
1482 if (caster->GetTypeId()!=TYPEID_PLAYER)
1483 return;
1484 Item* item = ((Player*)caster)->GetWeaponForAttack(BASE_ATTACK);
1485 if (!item)
1486 return;
1487 uint32 enchant_id = 0;
1488 switch (GetId())
1490 case 758: enchant_id = 1803; break; // Rank 1
1491 case 17945: enchant_id = 1823; break; // Rank 2
1492 case 17947: enchant_id = 1824; break; // Rank 3
1493 case 17949: enchant_id = 1825; break; // Rank 4
1494 case 27252: enchant_id = 2645; break; // Rank 5
1495 default:
1496 return;
1498 // remove old enchanting before applying new
1499 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1500 item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
1501 // add new enchanting
1502 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
1503 return;
1505 // // Periodic Mana Burn
1506 // case 812: break;
1507 // // Polymorphic Ray
1508 // case 6965: break;
1509 // // Fire Nova (1-7 ranks)
1510 // case 8350:
1511 // case 8508:
1512 // case 8509:
1513 // case 11312:
1514 // case 11313:
1515 // case 25540:
1516 // case 25544:
1517 // break;
1518 // Thaumaturgy Channel
1519 case 9712: trigger_spell_id = 21029; break;
1520 // // Egan's Blaster
1521 // case 17368: break;
1522 // // Haunted
1523 // case 18347: break;
1524 // // Ranshalla Waiting
1525 // case 18953: break;
1526 // // Inferno
1527 // case 19695: break;
1528 // // Frostwolf Muzzle DND
1529 // case 21794: break;
1530 // // Alterac Ram Collar DND
1531 // case 21866: break;
1532 // // Celebras Waiting
1533 // case 21916: break;
1534 // Brood Affliction: Bronze
1535 case 23170:
1537 m_target->CastSpell(m_target, 23171, true, 0, this);
1538 return;
1540 // // Mark of Frost
1541 // case 23184: break;
1542 // Restoration
1543 case 23493:
1545 int32 heal = caster->GetMaxHealth() / 10;
1546 caster->DealHeal(caster, heal, auraSpellInfo);
1548 int32 mana = caster->GetMaxPower(POWER_MANA);
1549 if (mana)
1551 mana /= 10;
1552 caster->EnergizeBySpell(caster, 23493, mana, POWER_MANA);
1554 return;
1556 // // Stoneclaw Totem Passive TEST
1557 // case 23792: break;
1558 // // Axe Flurry
1559 // case 24018: break;
1560 // // Mark of Arlokk
1561 // case 24210: break;
1562 // // Restoration
1563 // case 24379: break;
1564 // // Happy Pet
1565 // case 24716: break;
1566 // // Dream Fog
1567 // case 24780: break;
1568 // // Cannon Prep
1569 // case 24832: break;
1570 // // Shadow Bolt Whirl
1571 // case 24834: break;
1572 // // Stink Trap
1573 // case 24918: break;
1574 // // Mark of Nature
1575 // case 25041: break;
1576 // // Agro Drones
1577 // case 25152: break;
1578 // // Consume
1579 // case 25371: break;
1580 // // Pain Spike
1581 // case 25572: break;
1582 // // Rotate 360
1583 // case 26009: break;
1584 // // Rotate -360
1585 // case 26136: break;
1586 // // Consume
1587 // case 26196: break;
1588 // // Berserk
1589 // case 26615: break;
1590 // // Defile
1591 // case 27177: break;
1592 // // Teleport: IF/UC
1593 // case 27601: break;
1594 // // Five Fat Finger Exploding Heart Technique
1595 // case 27673: break;
1596 // // Nitrous Boost
1597 // case 27746: break;
1598 // // Steam Tank Passive
1599 // case 27747: break;
1600 // Frost Blast
1601 case 27808:
1603 int32 bpDamage = target->GetMaxHealth()*26/100;
1604 caster->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this);
1605 return;
1607 // // Detonate Mana
1608 // case 27819: break;
1609 // // Controller Timer
1610 // case 28095: break;
1611 // // Stalagg Chain
1612 // case 28096: break;
1613 // // Stalagg Tesla Passive
1614 // case 28097: break;
1615 // // Feugen Tesla Passive
1616 // case 28109: break;
1617 // // Feugen Chain
1618 // case 28111: break;
1619 // // Mark of Didier
1620 // case 28114: break;
1621 // // Communique Timer, camp
1622 // case 28346: break;
1623 // // Icebolt
1624 // case 28522: break;
1625 // // Silithyst
1626 // case 29519: break;
1627 // Inoculate Nestlewood Owlkin
1628 case 29528:
1629 if(target->GetTypeId() != TYPEID_UNIT)// prevent error reports in case ignored player target
1630 return;
1631 break;
1632 // // Overload
1633 // case 29768: break;
1634 // // Return Fire
1635 // case 29788: break;
1636 // // Return Fire
1637 // case 29793: break;
1638 // // Return Fire
1639 // case 29794: break;
1640 // // Guardian of Icecrown Passive
1641 // case 29897: break;
1642 // Feed Captured Animal
1643 case 29917: trigger_spell_id = 29916; break;
1644 // // Flame Wreath
1645 // case 29946: break;
1646 // // Flame Wreath
1647 // case 29947: break;
1648 // // Mind Exhaustion Passive
1649 // case 30025: break;
1650 // // Nether Beam - Serenity
1651 // case 30401: break;
1652 // Extract Gas
1653 case 30427:
1655 // move loot to player inventory and despawn target
1656 if(caster->GetTypeId() ==TYPEID_PLAYER &&
1657 target->GetTypeId() == TYPEID_UNIT &&
1658 ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
1660 Player* player = (Player*)caster;
1661 Creature* creature = (Creature*)target;
1662 // missing lootid has been reported on startup - just return
1663 if (!creature->GetCreatureInfo()->SkinLootId)
1664 return;
1666 player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true);
1668 creature->ForcedDespawn();
1670 return;
1672 // Quake
1673 case 30576: trigger_spell_id = 30571; break;
1674 // // Burning Maul
1675 // case 30598: break;
1676 // // Regeneration
1677 // case 30799:
1678 // case 30800:
1679 // case 30801:
1680 // break;
1681 // // Despawn Self - Smoke cloud
1682 // case 31269: break;
1683 // // Time Rift Periodic
1684 // case 31320: break;
1685 // // Corrupt Medivh
1686 // case 31326: break;
1687 // Doom
1688 case 31347:
1690 m_target->CastSpell(m_target,31350,true);
1691 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
1692 return;
1694 // Spellcloth
1695 case 31373:
1697 // Summon Elemental after create item
1698 caster->SummonCreature(17870, 0, 0, 0, caster->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
1699 return;
1701 // // Bloodmyst Tesla
1702 // case 31611: break;
1703 // // Doomfire
1704 // case 31944: break;
1705 // // Teleport Test
1706 // case 32236: break;
1707 // // Earthquake
1708 // case 32686: break;
1709 // // Possess
1710 // case 33401: break;
1711 // // Draw Shadows
1712 // case 33563: break;
1713 // // Murmur's Touch
1714 // case 33711: break;
1715 // Flame Quills
1716 case 34229:
1718 // cast 24 spells 34269-34289, 34314-34316
1719 for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
1720 caster->CastSpell(m_target, spell_id, true);
1721 for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
1722 caster->CastSpell(m_target, spell_id, true);
1723 return;
1725 // // Gravity Lapse
1726 // case 34480: break;
1727 // // Tornado
1728 // case 34683: break;
1729 // // Frostbite Rotate
1730 // case 34748: break;
1731 // // Arcane Flurry
1732 // case 34821: break;
1733 // // Interrupt Shutdown
1734 // case 35016: break;
1735 // // Interrupt Shutdown
1736 // case 35176: break;
1737 // // Inferno
1738 // case 35268: break;
1739 // // Salaadin's Tesla
1740 // case 35515: break;
1741 // // Ethereal Channel (Red)
1742 // case 35518: break;
1743 // // Nether Vapor
1744 // case 35879: break;
1745 // // Dark Portal Storm
1746 // case 36018: break;
1747 // // Burning Maul
1748 // case 36056: break;
1749 // // Living Grove Defender Lifespan
1750 // case 36061: break;
1751 // // Professor Dabiri Talks
1752 // case 36064: break;
1753 // // Kael Gaining Power
1754 // case 36091: break;
1755 // // They Must Burn Bomb Aura
1756 // case 36344: break;
1757 // // They Must Burn Bomb Aura (self)
1758 // case 36350: break;
1759 // // Stolen Ravenous Ravager Egg
1760 // case 36401: break;
1761 // // Activated Cannon
1762 // case 36410: break;
1763 // // Stolen Ravenous Ravager Egg
1764 // case 36418: break;
1765 // // Enchanted Weapons
1766 // case 36510: break;
1767 // // Cursed Scarab Periodic
1768 // case 36556: break;
1769 // // Cursed Scarab Despawn Periodic
1770 // case 36561: break;
1771 // // Vision Guide
1772 // case 36573: break;
1773 // // Cannon Charging (platform)
1774 // case 36785: break;
1775 // // Cannon Charging (self)
1776 // case 36860: break;
1777 // Remote Toy
1778 case 37027: trigger_spell_id = 37029; break;
1779 // // Mark of Death
1780 // case 37125: break;
1781 // // Arcane Flurry
1782 // case 37268: break;
1783 // // Spout
1784 // case 37429: break;
1785 // // Spout
1786 // case 37430: break;
1787 // // Karazhan - Chess NPC AI, Snapshot timer
1788 // case 37440: break;
1789 // // Karazhan - Chess NPC AI, action timer
1790 // case 37504: break;
1791 // // Karazhan - Chess: Is Square OCCUPIED aura (DND)
1792 // case 39400: break;
1793 // // Banish
1794 // case 37546: break;
1795 // // Shriveling Gaze
1796 // case 37589: break;
1797 // // Fake Aggro Radius (2 yd)
1798 // case 37815: break;
1799 // // Corrupt Medivh
1800 // case 37853: break;
1801 // Eye of Grillok
1802 case 38495:
1804 m_target->CastSpell(m_target, 38530, true);
1805 return;
1807 // Absorb Eye of Grillok (Zezzak's Shard)
1808 case 38554:
1810 if(m_target->GetTypeId() != TYPEID_UNIT)
1811 return;
1813 caster->CastSpell(caster, 38495, true);
1815 Creature* creatureTarget = (Creature*)m_target;
1817 creatureTarget->ForcedDespawn();
1818 return;
1820 // // Magic Sucker Device timer
1821 // case 38672: break;
1822 // // Tomb Guarding Charging
1823 // case 38751: break;
1824 // // Murmur's Touch
1825 // case 38794: break;
1826 // // Activate Nether-wraith Beacon (31742 Nether-wraith Beacon item)
1827 // case 39105: break;
1828 // // Drain World Tree Visual
1829 // case 39140: break;
1830 // // Quest - Dustin's Undead Dragon Visual aura
1831 // case 39259: break;
1832 // // Hellfire - The Exorcism, Jules releases darkness, aura
1833 // case 39306: break;
1834 // // Inferno
1835 // case 39346: break;
1836 // // Enchanted Weapons
1837 // case 39489: break;
1838 // // Shadow Bolt Whirl
1839 // case 39630: break;
1840 // // Shadow Bolt Whirl
1841 // case 39634: break;
1842 // // Shadow Inferno
1843 // case 39645: break;
1844 // Tear of Azzinoth Summon Channel - it's not really supposed to do anything,and this only prevents the console spam
1845 case 39857: trigger_spell_id = 39856; break;
1846 // // Soulgrinder Ritual Visual (Smashed)
1847 // case 39974: break;
1848 // // Simon Game Pre-game timer
1849 // case 40041: break;
1850 // // Knockdown Fel Cannon: The Aggro Check Aura
1851 // case 40113: break;
1852 // // Spirit Lance
1853 // case 40157: break;
1854 // // Demon Transform 2
1855 // case 40398: break;
1856 // // Demon Transform 1
1857 // case 40511: break;
1858 // // Ancient Flames
1859 // case 40657: break;
1860 // // Ethereal Ring Cannon: Cannon Aura
1861 // case 40734: break;
1862 // // Cage Trap
1863 // case 40760: break;
1864 // // Random Periodic
1865 // case 40867: break;
1866 // // Prismatic Shield
1867 // case 40879: break;
1868 // // Aura of Desire
1869 // case 41350: break;
1870 // // Dementia
1871 // case 41404: break;
1872 // // Chaos Form
1873 // case 41629: break;
1874 // // Alert Drums
1875 // case 42177: break;
1876 // // Spout
1877 // case 42581: break;
1878 // // Spout
1879 // case 42582: break;
1880 // // Return to the Spirit Realm
1881 // case 44035: break;
1882 // // Curse of Boundless Agony
1883 // case 45050: break;
1884 // // Earthquake
1885 // case 46240: break;
1886 // Personalized Weather
1887 case 46736: trigger_spell_id = 46737; break;
1888 // // Stay Submerged
1889 // case 46981: break;
1890 // // Dragonblight Ram
1891 // case 47015: break;
1892 // // Party G.R.E.N.A.D.E.
1893 // case 51510: break;
1894 default:
1895 break;
1897 break;
1899 case SPELLFAMILY_MAGE:
1901 switch(auraId)
1903 // Invisibility
1904 case 66:
1905 // Here need periodic triger reducing threat spell (or do it manually)
1906 return;
1907 default:
1908 break;
1910 break;
1912 // case SPELLFAMILY_WARRIOR:
1913 // {
1914 // switch(auraId)
1915 // {
1916 // // Wild Magic
1917 // case 23410: break;
1918 // // Corrupted Totems
1919 // case 23425: break;
1920 // default:
1921 // break;
1922 // }
1923 // break;
1924 // }
1925 // case SPELLFAMILY_PRIEST:
1926 // {
1927 // switch(auraId)
1928 // {
1929 // // Blue Beam
1930 // case 32930: break;
1931 // // Fury of the Dreghood Elders
1932 // case 35460: break;
1933 // default:
1934 // break;
1935 // }
1936 // break;
1937 // }
1938 case SPELLFAMILY_HUNTER:
1940 switch (auraId)
1942 // Sniper training
1943 case 53302:
1944 case 53303:
1945 case 53304:
1946 if (target->GetTypeId() != TYPEID_PLAYER)
1947 return;
1949 // Reset reapply counter at move
1950 if (((Player*)target)->isMoving())
1952 m_modifier.m_amount = 6;
1953 return;
1956 // We are standing at the moment
1957 if (m_modifier.m_amount > 0)
1959 --m_modifier.m_amount;
1960 return;
1963 // select rank of buff
1964 switch(auraId)
1966 case 53302: trigger_spell_id = 64418; break;
1967 case 53303: trigger_spell_id = 64419; break;
1968 case 53304: trigger_spell_id = 64420; break;
1971 // If aura is active - no need to continue
1972 if (target->HasAura(trigger_spell_id))
1973 return;
1975 break;
1976 default:
1977 break;
1979 break;
1981 case SPELLFAMILY_DRUID:
1983 switch(auraId)
1985 // Cat Form
1986 // trigger_spell_id not set and unknown effect triggered in this case, ignoring for while
1987 case 768:
1988 return;
1989 // Frenzied Regeneration
1990 case 22842:
1991 case 22895:
1992 case 22896:
1993 case 26999:
1995 int32 LifePerRage = GetModifier()->m_amount;
1997 int32 lRage = m_target->GetPower(POWER_RAGE);
1998 if(lRage > 100) // rage stored as rage*10
1999 lRage = 100;
2000 m_target->ModifyPower(POWER_RAGE, -lRage);
2001 int32 FRTriggerBasePoints = int32(lRage*LifePerRage/10);
2002 m_target->CastCustomSpell(m_target, 22845, &FRTriggerBasePoints, NULL, NULL, true, NULL, this);
2003 return;
2005 default:
2006 break;
2008 break;
2011 // case SPELLFAMILY_HUNTER:
2012 // {
2013 // switch(auraId)
2014 // {
2015 // //Frost Trap Aura
2016 // case 13810:
2017 // return;
2018 // //Rizzle's Frost Trap
2019 // case 39900:
2020 // return;
2021 // // Tame spells
2022 // case 19597: // Tame Ice Claw Bear
2023 // case 19676: // Tame Snow Leopard
2024 // case 19677: // Tame Large Crag Boar
2025 // case 19678: // Tame Adult Plainstrider
2026 // case 19679: // Tame Prairie Stalker
2027 // case 19680: // Tame Swoop
2028 // case 19681: // Tame Dire Mottled Boar
2029 // case 19682: // Tame Surf Crawler
2030 // case 19683: // Tame Armored Scorpid
2031 // case 19684: // Tame Webwood Lurker
2032 // case 19685: // Tame Nightsaber Stalker
2033 // case 19686: // Tame Strigid Screecher
2034 // case 30100: // Tame Crazed Dragonhawk
2035 // case 30103: // Tame Elder Springpaw
2036 // case 30104: // Tame Mistbat
2037 // case 30647: // Tame Barbed Crawler
2038 // case 30648: // Tame Greater Timberstrider
2039 // case 30652: // Tame Nightstalker
2040 // return;
2041 // default:
2042 // break;
2043 // }
2044 // break;
2045 // }
2046 case SPELLFAMILY_SHAMAN:
2048 switch(auraId)
2050 // Lightning Shield (The Earthshatterer set trigger after cast Lighting Shield)
2051 case 28820:
2053 // Need remove self if Lightning Shield not active
2054 Unit::AuraMap const& auras = target->GetAuras();
2055 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
2057 SpellEntry const* spell = itr->second->GetSpellProto();
2058 if( spell->SpellFamilyName == SPELLFAMILY_SHAMAN &&
2059 (spell->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
2060 return;
2062 target->RemoveAurasDueToSpell(28820);
2063 return;
2065 // Totemic Mastery (Skyshatter Regalia (Shaman Tier 6) - bonus)
2066 case 38443:
2068 bool all = true;
2069 for(int i = 0; i < MAX_TOTEM; ++i)
2071 if(!caster->m_TotemSlot[i])
2073 all = false;
2074 break;
2078 if(all)
2079 caster->CastSpell(caster, 38437, true);
2080 else
2081 caster->RemoveAurasDueToSpell(38437);
2082 return;
2084 default:
2085 break;
2087 break;
2089 default:
2090 break;
2093 // Reget trigger spell proto
2094 triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
2096 else
2098 // Spell exist but require custom code
2099 switch(auraId)
2101 // Curse of Idiocy
2102 case 1010:
2104 // TODO: spell casted by result in correct way mostly
2105 // BUT:
2106 // 1) target show casting at each triggered cast: target don't must show casting animation for any triggered spell
2107 // but must show affect apply like item casting
2108 // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
2110 // prevent cast by triggered auras
2111 if(m_caster_guid == m_target->GetGUID())
2112 return;
2114 // stop triggering after each affected stats lost > 90
2115 int32 intelectLoss = 0;
2116 int32 spiritLoss = 0;
2118 Unit::AuraList const& mModStat = m_target->GetAurasByType(SPELL_AURA_MOD_STAT);
2119 for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
2121 if ((*i)->GetId() == 1010)
2123 switch((*i)->GetModifier()->m_miscvalue)
2125 case STAT_INTELLECT: intelectLoss += (*i)->GetModifier()->m_amount; break;
2126 case STAT_SPIRIT: spiritLoss += (*i)->GetModifier()->m_amount; break;
2127 default: break;
2132 if(intelectLoss <= -90 && spiritLoss <= -90)
2133 return;
2135 caster = target;
2136 break;
2138 // Mana Tide
2139 case 16191:
2141 caster->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
2142 return;
2144 // Ground Slam
2145 case 33525:
2146 target->CastSpell(target, trigger_spell_id, true);
2147 return;
2148 // Beacon of Light
2149 case 53563:
2150 // original caster must be target (beacon)
2151 m_target->CastSpell(m_target,trigger_spell_id,true,NULL,this,m_target->GetGUID());
2152 return;
2156 // All ok cast by default case
2157 if(triggeredSpellInfo)
2158 caster->CastSpell(target, triggeredSpellInfo, true, 0, this);
2159 else if(target->GetTypeId()!=TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target))
2160 sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
2163 void Aura::TriggerSpellWithValue()
2165 Unit* caster = GetCaster();
2166 Unit* target = GetTriggerTarget();
2168 if(!caster || !target)
2169 return;
2171 // generic casting code with custom spells and target/caster customs
2172 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
2173 int32 basepoints0 = this->GetModifier()->m_amount;
2175 caster->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this);
2178 /*********************************************************/
2179 /*** AURA EFFECTS ***/
2180 /*********************************************************/
2182 void Aura::HandleAuraDummy(bool apply, bool Real)
2184 // spells required only Real aura add/remove
2185 if(!Real)
2186 return;
2188 Unit* caster = GetCaster();
2190 // AT APPLY
2191 if(apply)
2193 switch(GetId())
2195 case 1515: // Tame beast
2196 // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
2197 if( caster && m_target->CanHaveThreatList())
2198 m_target->AddThreat(caster, 10.0f);
2199 return;
2200 case 13139: // net-o-matic
2201 // root to self part of (root_target->charge->root_self sequence
2202 if(caster)
2203 caster->CastSpell(caster, 13138, true, NULL, this);
2204 return;
2205 case 39850: // Rocket Blast
2206 if(roll_chance_i(20)) // backfire stun
2207 m_target->CastSpell(m_target, 51581, true, NULL, this);
2208 return;
2209 case 43873: // Headless Horseman Laugh
2210 m_target->PlayDistanceSound(11965);
2211 return;
2212 case 46354: // Blood Elf Illusion
2213 if(caster)
2215 switch(caster->getGender())
2217 case GENDER_FEMALE:
2218 caster->CastSpell(m_target, 46356, true, NULL, this);
2219 break;
2220 case GENDER_MALE:
2221 caster->CastSpell(m_target, 46355, true, NULL, this);
2222 break;
2223 default:
2224 break;
2227 return;
2228 case 46699: // Requires No Ammo
2229 if(m_target->GetTypeId() == TYPEID_PLAYER)
2230 ((Player*)m_target)->RemoveAmmo(); // not use ammo and not allow use
2231 return;
2234 // Earth Shield
2235 if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x40000000000)))
2237 // prevent double apply bonuses
2238 if(m_target->GetTypeId() != TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2239 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2240 return;
2243 // AT REMOVE
2244 else
2246 if( m_target->GetTypeId() == TYPEID_PLAYER &&
2247 ( GetSpellProto()->Effect[0]==72 || GetSpellProto()->Effect[0]==6 &&
2248 ( GetSpellProto()->EffectApplyAuraName[0]==1 || GetSpellProto()->EffectApplyAuraName[0]==128 ) ) )
2250 // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
2251 ((Player*)m_target)->SetFarSightGUID(0);
2252 WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0);
2253 ((Player*)m_target)->GetSession()->SendPacket(&data);
2254 return;
2257 if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
2259 uint32 finalSpelId = 0;
2260 switch(GetId())
2262 case 19548: finalSpelId = 19597; break;
2263 case 19674: finalSpelId = 19677; break;
2264 case 19687: finalSpelId = 19676; break;
2265 case 19688: finalSpelId = 19678; break;
2266 case 19689: finalSpelId = 19679; break;
2267 case 19692: finalSpelId = 19680; break;
2268 case 19693: finalSpelId = 19684; break;
2269 case 19694: finalSpelId = 19681; break;
2270 case 19696: finalSpelId = 19682; break;
2271 case 19697: finalSpelId = 19683; break;
2272 case 19699: finalSpelId = 19685; break;
2273 case 19700: finalSpelId = 19686; break;
2274 case 30646: finalSpelId = 30647; break;
2275 case 30653: finalSpelId = 30648; break;
2276 case 30654: finalSpelId = 30652; break;
2277 case 30099: finalSpelId = 30100; break;
2278 case 30102: finalSpelId = 30103; break;
2279 case 30105: finalSpelId = 30104; break;
2282 if(finalSpelId)
2283 caster->CastSpell(m_target, finalSpelId, true, NULL, this);
2284 return;
2287 switch(GetId())
2289 case 36730: // Flame Strike
2291 m_target->CastSpell(m_target, 36731, true, NULL, this);
2292 return;
2294 case 44191: // Flame Strike
2296 if (m_target->GetMap()->IsDungeon())
2298 uint32 spellId = m_target->GetMap()->IsHeroic() ? 46163 : 44190;
2300 m_target->CastSpell(m_target, spellId, true, NULL, this);
2302 return;
2304 case 45934: // Dark Fiend
2306 // Kill target if dispelled
2307 if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2308 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2309 return;
2311 case 46308: // Burning Winds
2313 // casted only at creatures at spawn
2314 m_target->CastSpell(m_target, 47287, true, NULL, this);
2315 return;
2319 if (caster && m_removeMode == AURA_REMOVE_BY_DEATH)
2321 // Stop caster Arcane Missle chanelling on death
2322 if (m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE &&
2323 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000800)))
2325 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2326 return;
2328 // Stop caster Penance chanelling on death
2329 if (m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST &&
2330 (m_spellProto->SpellFamilyFlags2 & UI64LIT(0x00000080)))
2332 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2333 return;
2339 // AT APPLY & REMOVE
2341 switch(m_spellProto->SpellFamilyName)
2343 case SPELLFAMILY_GENERIC:
2345 switch(GetId())
2347 // Recently Bandaged
2348 case 11196:
2349 m_target->ApplySpellImmune(GetId(), IMMUNITY_MECHANIC, GetMiscValue(), apply);
2350 return;
2351 // Unstable Power
2352 case 24658:
2354 uint32 spellId = 24659;
2355 if (apply && caster)
2357 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2358 if (!spell)
2359 return;
2361 for (int i=0; i < spell->StackAmount; ++i)
2362 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2363 return;
2365 m_target->RemoveAurasDueToSpell(spellId);
2366 return;
2368 // Restless Strength
2369 case 24661:
2371 uint32 spellId = 24662;
2372 if (apply && caster)
2374 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2375 if (!spell)
2376 return;
2377 for (int i=0; i < spell->StackAmount; ++i)
2378 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2379 return;
2381 m_target->RemoveAurasDueToSpell(spellId);
2382 return;
2384 //Summon Fire Elemental
2385 case 40133:
2387 if (!caster)
2388 return;
2390 Unit *owner = caster->GetOwner();
2391 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2393 if(apply)
2394 owner->CastSpell(owner, 8985, true);
2395 else
2396 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2398 return;
2400 //Summon Earth Elemental
2401 case 40132 :
2403 if (!caster)
2404 return;
2406 Unit *owner = caster->GetOwner();
2407 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2409 if(apply)
2410 owner->CastSpell(owner, 19704, true);
2411 else
2412 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2414 return;
2416 //Dragonmaw Illusion
2417 case 40214 :
2419 if(apply)
2421 m_target->CastSpell(m_target, 40216, true);
2422 m_target->CastSpell(m_target, 42016, true);
2424 else
2426 m_target->RemoveAurasDueToSpell(40216);
2427 m_target->RemoveAurasDueToSpell(42016);
2429 return;
2431 // LK Intro VO (1)
2432 case 58204:
2433 if(m_target->GetTypeId() == TYPEID_PLAYER)
2435 // Play part 1
2436 if(apply)
2437 m_target->PlayDirectSound(14970, (Player *)m_target);
2438 // continue in 58205
2439 else
2440 m_target->CastSpell(m_target, 58205, true);
2442 return;
2443 // LK Intro VO (2)
2444 case 58205:
2445 if(m_target->GetTypeId() == TYPEID_PLAYER)
2447 // Play part 2
2448 if(apply)
2449 m_target->PlayDirectSound(14971, (Player *)m_target);
2450 // Play part 3
2451 else
2452 m_target->PlayDirectSound(14972, (Player *)m_target);
2454 return;
2456 break;
2458 case SPELLFAMILY_MAGE:
2459 break;
2460 case SPELLFAMILY_PRIEST:
2462 // Pain and Suffering
2463 if( m_spellProto->SpellIconID == 2874 && m_target->GetTypeId()==TYPEID_PLAYER )
2465 if(apply)
2467 // Reduce backfire damage (dot damage) from Shadow Word: Death
2468 SpellModifier *mod = new SpellModifier;
2469 mod->op = SPELLMOD_DOT;
2470 mod->value = m_modifier.m_amount;
2471 mod->type = SPELLMOD_PCT;
2472 mod->spellId = GetId();
2473 mod->mask = UI64LIT(0x0000200000000000);
2474 mod->mask2= UI64LIT(0x0);
2475 m_spellmod = mod;
2477 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2478 return;
2480 break;
2482 case SPELLFAMILY_PALADIN:
2483 break;
2484 case SPELLFAMILY_DRUID:
2486 switch(GetId())
2488 case 34246: // Idol of the Emerald Queen
2489 case 60779: // Idol of Lush Moss
2491 if (m_target->GetTypeId() != TYPEID_PLAYER)
2492 return;
2494 if(apply)
2496 SpellModifier *mod = new SpellModifier;
2497 mod->op = SPELLMOD_DOT;
2498 mod->value = m_modifier.m_amount/7;
2499 mod->type = SPELLMOD_FLAT;
2500 mod->spellId = GetId();
2501 mod->mask = UI64LIT(0x001000000000);
2502 mod->mask2= UI64LIT(0x0);
2504 m_spellmod = mod;
2507 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2508 return;
2510 case 52610: // Savage Roar
2512 if(apply)
2514 if(m_target->m_form != FORM_CAT)
2515 return;
2517 m_target->CastSpell(m_target, 62071, true);
2519 else
2520 m_target-> RemoveAurasDueToSpell(62071);
2521 return;
2523 case 61336: // Survival Instincts
2525 if(apply)
2527 if (!m_target->IsInFeralForm())
2528 return;
2530 int32 bp0 = int32(m_target->GetMaxHealth() * m_modifier.m_amount / 100);
2531 m_target->CastCustomSpell(m_target, 50322, &bp0, NULL, NULL, true);
2533 else
2534 m_target-> RemoveAurasDueToSpell(50322);
2535 return;
2539 // Lifebloom
2540 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000))
2542 if ( apply )
2544 if ( caster )
2545 // prevent double apply bonuses
2546 if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2547 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2549 else
2551 // Final heal only on dispelled or duration end
2552 if ( !(GetAuraDuration() <= 0 || m_removeMode == AURA_REMOVE_BY_DISPEL) )
2553 return;
2555 // have a look if there is still some other Lifebloom dummy aura
2556 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2557 for(Unit::AuraList::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
2558 if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2559 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000)))
2560 return;
2562 // final heal
2563 if(m_target->IsInWorld() && m_stackAmount > 0)
2565 int32 amount = m_modifier.m_amount / m_stackAmount;
2566 m_target->CastCustomSpell(m_target, 33778, &amount, NULL, NULL, true, NULL, this, GetCasterGUID());
2568 if (caster)
2570 int32 returnmana = (GetSpellProto()->ManaCostPercentage * caster->GetCreateMana() / 100) * m_stackAmount / 2;
2571 caster->CastCustomSpell(caster, 64372, &returnmana, NULL, NULL, true, NULL, this, GetCasterGUID());
2575 return;
2578 // Predatory Strikes
2579 if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2581 ((Player*)m_target)->UpdateAttackPowerAndDamage();
2582 return;
2585 // Improved Moonkin Form
2586 if(GetSpellProto()->SpellIconID == 2855)
2588 uint32 spell_id;
2589 switch(GetId())
2591 case 48384: spell_id = 50170; break; //Rank 1
2592 case 48395: spell_id = 50171; break; //Rank 2
2593 case 48396: spell_id = 50172; break; //Rank 3
2594 default:
2595 sLog.outError("HandleAuraDummy: Not handled rank of IMF (Spell: %u)",GetId());
2596 return;
2599 if(apply)
2601 if(m_target->m_form != FORM_MOONKIN)
2602 return;
2604 m_target->CastSpell(m_target, spell_id, true);
2606 else
2607 m_target-> RemoveAurasDueToSpell(spell_id);
2608 return;
2610 break;
2612 case SPELLFAMILY_HUNTER:
2613 break;
2614 case SPELLFAMILY_SHAMAN:
2616 // Improved Weapon Totems
2617 if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2619 if(apply)
2621 SpellModifier *mod = new SpellModifier;
2622 mod->op = SPELLMOD_EFFECT1;
2623 mod->value = m_modifier.m_amount;
2624 mod->type = SPELLMOD_PCT;
2625 mod->spellId = GetId();
2626 switch (m_effIndex)
2628 case 0:
2629 // Windfury Totem
2630 mod->mask = UI64LIT(0x00200000000);
2631 mod->mask2= UI64LIT(0x0);
2632 break;
2633 case 1:
2634 // Flametongue Totem
2635 mod->mask = UI64LIT(0x00400000000);
2636 mod->mask2= UI64LIT(0x0);
2637 break;
2640 m_spellmod = mod;
2643 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2644 return;
2646 break;
2650 // pet auras
2651 if(PetAura const* petSpell = spellmgr.GetPetAura(GetId(), m_effIndex))
2653 if(apply)
2654 m_target->AddPetAura(petSpell);
2655 else
2656 m_target->RemovePetAura(petSpell);
2657 return;
2660 if(GetEffIndex()==0 && m_target->GetTypeId()==TYPEID_PLAYER)
2662 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
2663 if(saBounds.first != saBounds.second)
2665 uint32 zone, area;
2666 m_target->GetZoneAndAreaId(zone, area);
2668 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2670 // some auras remove at aura remove
2671 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
2672 m_target->RemoveAurasDueToSpell(itr->second->spellId);
2673 // some auras applied at aura apply
2674 else if(itr->second->autocast)
2676 if( !m_target->HasAura(itr->second->spellId, 0) )
2677 m_target->CastSpell(m_target, itr->second->spellId, true);
2684 void Aura::HandleAuraMounted(bool apply, bool Real)
2686 // only at real add/remove aura
2687 if(!Real)
2688 return;
2690 if(apply)
2692 CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2693 if(!ci)
2695 sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2696 return;
2699 uint32 team = 0;
2700 if (m_target->GetTypeId()==TYPEID_PLAYER)
2701 team = ((Player*)m_target)->GetTeam();
2703 uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2704 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2705 if (minfo)
2706 display_id = minfo->modelid;
2708 m_target->Mount(display_id);
2710 else
2712 m_target->Unmount();
2716 void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2718 // only at real add/remove aura
2719 if(!Real)
2720 return;
2722 WorldPacket data;
2723 if(apply)
2724 data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2725 else
2726 data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2727 data.append(m_target->GetPackGUID());
2728 data << uint32(0);
2729 m_target->SendMessageToSet(&data, true);
2732 void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2734 // only at real add/remove aura
2735 if(!Real)
2736 return;
2738 WorldPacket data;
2739 if(apply)
2740 data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2741 else
2742 data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2743 data.append(m_target->GetPackGUID());
2744 data << uint32(0);
2745 m_target->SendMessageToSet(&data, true);
2747 // start fall from current height
2748 if(!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2749 ((Player*)m_target)->SetFallInformation(0, m_target->GetPositionZ());
2752 void Aura::HandleAuraHover(bool apply, bool Real)
2754 // only at real add/remove aura
2755 if(!Real)
2756 return;
2758 WorldPacket data;
2759 if(apply)
2760 data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2761 else
2762 data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2763 data.append(m_target->GetPackGUID());
2764 data << uint32(0);
2765 m_target->SendMessageToSet(&data, true);
2768 void Aura::HandleWaterBreathing(bool /*apply*/, bool /*Real*/)
2770 // update timers in client
2771 if(m_target->GetTypeId()==TYPEID_PLAYER)
2772 ((Player*)m_target)->UpdateMirrorTimers();
2775 void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2777 if(!Real)
2778 return;
2780 uint32 modelid = 0;
2781 Powers PowerType = POWER_MANA;
2782 ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2783 switch(form)
2785 case FORM_CAT:
2786 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2787 modelid = 892;
2788 else
2789 modelid = 8571;
2790 PowerType = POWER_ENERGY;
2791 break;
2792 case FORM_TRAVEL:
2793 modelid = 632;
2794 break;
2795 case FORM_AQUA:
2796 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2797 modelid = 2428;
2798 else
2799 modelid = 2428;
2800 break;
2801 case FORM_BEAR:
2802 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2803 modelid = 2281;
2804 else
2805 modelid = 2289;
2806 PowerType = POWER_RAGE;
2807 break;
2808 case FORM_GHOUL:
2809 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2810 modelid = 10045;
2811 break;
2812 case FORM_DIREBEAR:
2813 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2814 modelid = 2281;
2815 else
2816 modelid = 2289;
2817 PowerType = POWER_RAGE;
2818 break;
2819 case FORM_CREATUREBEAR:
2820 modelid = 902;
2821 break;
2822 case FORM_GHOSTWOLF:
2823 modelid = 4613;
2824 break;
2825 case FORM_FLIGHT:
2826 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2827 modelid = 20857;
2828 else
2829 modelid = 20872;
2830 break;
2831 case FORM_MOONKIN:
2832 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2833 modelid = 15374;
2834 else
2835 modelid = 15375;
2836 break;
2837 case FORM_FLIGHT_EPIC:
2838 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2839 modelid = 21243;
2840 else
2841 modelid = 21244;
2842 break;
2843 case FORM_METAMORPHOSIS:
2844 modelid = 25277;
2845 break;
2846 case FORM_AMBIENT:
2847 case FORM_SHADOW:
2848 case FORM_STEALTH:
2849 break;
2850 case FORM_TREE:
2851 modelid = 864;
2852 break;
2853 case FORM_BATTLESTANCE:
2854 case FORM_BERSERKERSTANCE:
2855 case FORM_DEFENSIVESTANCE:
2856 PowerType = POWER_RAGE;
2857 break;
2858 case FORM_SPIRITOFREDEMPTION:
2859 modelid = 16031;
2860 break;
2861 default:
2862 sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2865 // remove polymorph before changing display id to keep new display id
2866 switch ( form )
2868 case FORM_CAT:
2869 case FORM_TREE:
2870 case FORM_TRAVEL:
2871 case FORM_AQUA:
2872 case FORM_BEAR:
2873 case FORM_DIREBEAR:
2874 case FORM_FLIGHT_EPIC:
2875 case FORM_FLIGHT:
2876 case FORM_MOONKIN:
2878 // remove movement affects
2879 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2880 Unit::AuraList const& slowingAuras = m_target->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
2881 for (Unit::AuraList::const_iterator iter = slowingAuras.begin(); iter != slowingAuras.end();)
2883 SpellEntry const* aurSpellInfo = (*iter)->GetSpellProto();
2885 uint32 aurMechMask = GetAllSpellMechanicMask(aurSpellInfo);
2887 // If spell that caused this aura has Croud Control or Daze effect
2888 if((aurMechMask & MECHANIC_NOT_REMOVED_BY_SHAPESHIFT) ||
2889 // some Daze spells have these parameters instead of MECHANIC_DAZE (skip snare spells)
2890 aurSpellInfo->SpellIconID == 15 && aurSpellInfo->Dispel == 0 && (aurMechMask & (1 << MECHANIC_SNARE))==0)
2892 ++iter;
2893 continue;
2896 // All OK, remove aura now
2897 m_target->RemoveAurasDueToSpellByCancel(aurSpellInfo->Id);
2898 iter = slowingAuras.begin();
2901 // and polymorphic affects
2902 if(m_target->IsPolymorphed())
2903 m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2905 break;
2907 default:
2908 break;
2911 if(apply)
2913 // remove other shapeshift before applying a new one
2914 if(m_target->m_ShapeShiftFormSpellId)
2915 m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId, this);
2917 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2919 if(modelid > 0)
2920 m_target->SetDisplayId(modelid);
2922 if(PowerType != POWER_MANA)
2924 // reset power to default values only at power change
2925 if(m_target->getPowerType() != PowerType)
2926 m_target->setPowerType(PowerType);
2928 switch(form)
2930 case FORM_CAT:
2931 case FORM_BEAR:
2932 case FORM_DIREBEAR:
2934 // get furor proc chance
2935 uint32 FurorChance = 0;
2936 Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2937 for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2939 if ((*i)->GetSpellProto()->SpellIconID == 238)
2941 FurorChance = (*i)->GetModifier()->m_amount;
2942 break;
2946 if (m_modifier.m_miscvalue == FORM_CAT)
2948 m_target->SetPower(POWER_ENERGY, 0);
2949 if(urand(1,100) <= FurorChance)
2950 m_target->CastSpell(m_target, 17099, true, NULL, this);
2952 else
2954 m_target->SetPower(POWER_RAGE, 0);
2955 if(urand(1,100) <= FurorChance)
2956 m_target->CastSpell(m_target, 17057, true, NULL, this);
2958 break;
2960 case FORM_BATTLESTANCE:
2961 case FORM_DEFENSIVESTANCE:
2962 case FORM_BERSERKERSTANCE:
2964 uint32 Rage_val = 0;
2965 // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2966 if(m_target->GetTypeId() == TYPEID_PLAYER)
2968 PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2969 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2971 if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2972 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2973 if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2974 Rage_val += m_target->CalculateSpellDamage(spellInfo, 0, spellInfo->EffectBasePoints[0], m_target) * 10;
2978 if (m_target->GetPower(POWER_RAGE) > Rage_val)
2979 m_target->SetPower(POWER_RAGE, Rage_val);
2980 break;
2982 default:
2983 break;
2987 m_target->m_ShapeShiftFormSpellId = GetId();
2988 m_target->m_form = form;
2990 else
2992 if(modelid > 0)
2993 m_target->SetDisplayId(m_target->GetNativeDisplayId());
2994 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2995 if(m_target->getClass() == CLASS_DRUID)
2996 m_target->setPowerType(POWER_MANA);
2997 m_target->m_ShapeShiftFormSpellId = 0;
2998 m_target->m_form = FORM_NONE;
3000 switch(form)
3002 // Nordrassil Harness - bonus
3003 case FORM_BEAR:
3004 case FORM_DIREBEAR:
3005 case FORM_CAT:
3006 if(Aura* dummy = m_target->GetDummyAura(37315) )
3007 m_target->CastSpell(m_target, 37316, true, NULL, dummy);
3008 break;
3009 // Nordrassil Regalia - bonus
3010 case FORM_MOONKIN:
3011 if(Aura* dummy = m_target->GetDummyAura(37324) )
3012 m_target->CastSpell(m_target, 37325, true, NULL, dummy);
3013 break;
3014 default:
3015 break;
3019 // adding/removing linked auras
3020 // add/remove the shapeshift aura's boosts
3021 HandleShapeshiftBoosts(apply);
3023 if(m_target->GetTypeId() == TYPEID_PLAYER)
3024 ((Player*)m_target)->InitDataForForm();
3027 void Aura::HandleAuraTransform(bool apply, bool Real)
3029 if (apply)
3031 // special case (spell specific functionality)
3032 if (m_modifier.m_miscvalue == 0)
3034 // player applied only
3035 if (m_target->GetTypeId() != TYPEID_PLAYER)
3036 return;
3038 switch (GetId())
3040 // Orb of Deception
3041 case 16739:
3043 uint32 orb_model = m_target->GetNativeDisplayId();
3044 switch(orb_model)
3046 // Troll Female
3047 case 1479: m_target->SetDisplayId(10134); break;
3048 // Troll Male
3049 case 1478: m_target->SetDisplayId(10135); break;
3050 // Tauren Male
3051 case 59: m_target->SetDisplayId(10136); break;
3052 // Human Male
3053 case 49: m_target->SetDisplayId(10137); break;
3054 // Human Female
3055 case 50: m_target->SetDisplayId(10138); break;
3056 // Orc Male
3057 case 51: m_target->SetDisplayId(10139); break;
3058 // Orc Female
3059 case 52: m_target->SetDisplayId(10140); break;
3060 // Dwarf Male
3061 case 53: m_target->SetDisplayId(10141); break;
3062 // Dwarf Female
3063 case 54: m_target->SetDisplayId(10142); break;
3064 // NightElf Male
3065 case 55: m_target->SetDisplayId(10143); break;
3066 // NightElf Female
3067 case 56: m_target->SetDisplayId(10144); break;
3068 // Undead Female
3069 case 58: m_target->SetDisplayId(10145); break;
3070 // Undead Male
3071 case 57: m_target->SetDisplayId(10146); break;
3072 // Tauren Female
3073 case 60: m_target->SetDisplayId(10147); break;
3074 // Gnome Male
3075 case 1563: m_target->SetDisplayId(10148); break;
3076 // Gnome Female
3077 case 1564: m_target->SetDisplayId(10149); break;
3078 // BloodElf Female
3079 case 15475: m_target->SetDisplayId(17830); break;
3080 // BloodElf Male
3081 case 15476: m_target->SetDisplayId(17829); break;
3082 // Dranei Female
3083 case 16126: m_target->SetDisplayId(17828); break;
3084 // Dranei Male
3085 case 16125: m_target->SetDisplayId(17827); break;
3086 default: break;
3088 break;
3090 // Murloc costume
3091 case 42365: m_target->SetDisplayId(21723); break;
3092 default: break;
3095 else
3097 uint32 model_id;
3099 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
3100 if (!ci)
3102 model_id = 16358; // pig pink ^_^
3103 sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
3105 else
3106 model_id = ci->DisplayID_A[0]; // Will use the default model here
3108 // Polymorph (sheep/penguin case)
3109 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
3110 if (Unit* caster = GetCaster())
3111 if (caster->HasAura(52648)) // Glyph of the Penguin
3112 model_id = 26452;
3114 m_target->SetDisplayId(model_id);
3116 // Dragonmaw Illusion (set mount model also)
3117 if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
3118 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3121 // update active transform spell only not set or not overwriting negative by positive case
3122 if (!m_target->getTransForm() || !IsPositiveSpell(GetId()) || IsPositiveSpell(m_target->getTransForm()))
3123 m_target->setTransForm(GetId());
3125 // polymorph case
3126 if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
3128 // for players, start regeneration after 1s (in polymorph fast regeneration case)
3129 // only if caster is Player (after patch 2.4.2)
3130 if (IS_PLAYER_GUID(GetCasterGUID()) )
3131 ((Player*)m_target)->setRegenTimer(1*IN_MILISECONDS);
3133 //dismount polymorphed target (after patch 2.4.2)
3134 if (m_target->IsMounted())
3135 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
3138 else
3140 // ApplyModifier(true) will reapply it if need
3141 m_target->setTransForm(0);
3142 m_target->SetDisplayId(m_target->GetNativeDisplayId());
3144 // re-aplly some from still active with preference negative cases
3145 Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
3146 if (!otherTransforms.empty())
3148 // look for other transform auras
3149 Aura* handledAura = *otherTransforms.begin();
3150 for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
3152 // negative auras are preferred
3153 if (!IsPositiveSpell((*i)->GetSpellProto()->Id))
3155 handledAura = *i;
3156 break;
3159 handledAura->ApplyModifier(true);
3162 // Dragonmaw Illusion (restore mount model)
3163 if (GetId() == 42016 && m_target->GetMountID() == 16314)
3165 if (!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
3167 uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
3168 if (CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
3170 uint32 team = 0;
3171 if (m_target->GetTypeId() == TYPEID_PLAYER)
3172 team = ((Player*)m_target)->GetTeam();
3174 uint32 display_id = objmgr.ChooseDisplayId(team, ci);
3175 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
3176 if (minfo)
3177 display_id = minfo->modelid;
3179 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, display_id);
3186 void Aura::HandleForceReaction(bool apply, bool Real)
3188 if(m_target->GetTypeId() != TYPEID_PLAYER)
3189 return;
3191 if(!Real)
3192 return;
3194 Player* player = (Player*)m_target;
3196 uint32 faction_id = m_modifier.m_miscvalue;
3197 uint32 faction_rank = m_modifier.m_amount;
3199 player->GetReputationMgr().ApplyForceReaction(faction_id, ReputationRank(faction_rank), apply);
3200 player->GetReputationMgr().SendForceReactions();
3203 void Aura::HandleAuraModSkill(bool apply, bool /*Real*/)
3205 if(m_target->GetTypeId() != TYPEID_PLAYER)
3206 return;
3208 uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
3209 int32 points = GetModifier()->m_amount;
3211 ((Player*)m_target)->ModifySkillBonus(prot, (apply ? points: -points), m_modifier.m_auraname == SPELL_AURA_MOD_SKILL_TALENT);
3212 if(prot == SKILL_DEFENSE)
3213 ((Player*)m_target)->UpdateDefenseBonusesMod();
3216 void Aura::HandleChannelDeathItem(bool apply, bool Real)
3218 if(Real && !apply)
3220 Unit* caster = GetCaster();
3221 Unit* victim = GetTarget();
3222 if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode != AURA_REMOVE_BY_DEATH)
3223 return;
3224 // Item amount
3225 if (m_modifier.m_amount <= 0)
3226 return;
3228 SpellEntry const *spellInfo = GetSpellProto();
3229 if(spellInfo->EffectItemType[m_effIndex] == 0)
3230 return;
3232 // Soul Shard only from non-grey units
3233 if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
3234 (victim->getLevel() <= MaNGOS::XP::GetGrayLevel(caster->getLevel()) ||
3235 victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
3236 return;
3237 //Adding items
3238 uint32 noSpaceForCount = 0;
3239 uint32 count = m_modifier.m_amount;
3241 ItemPosCountVec dest;
3242 uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], count, &noSpaceForCount);
3243 if( msg != EQUIP_ERR_OK )
3245 count-=noSpaceForCount;
3246 ((Player*)caster)->SendEquipError( msg, NULL, NULL );
3247 if (count==0)
3248 return;
3251 Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
3252 ((Player*)caster)->SendNewItem(newitem, count, true, false);
3256 void Aura::HandleBindSight(bool apply, bool /*Real*/)
3258 Unit* caster = GetCaster();
3259 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3260 return;
3262 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3265 void Aura::HandleFarSight(bool apply, bool /*Real*/)
3267 Unit* caster = GetCaster();
3268 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3269 return;
3271 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3274 void Aura::HandleAuraTrackCreatures(bool apply, bool /*Real*/)
3276 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3277 return;
3279 if(apply)
3280 m_target->RemoveNoStackAurasDueToAura(this);
3281 m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
3284 void Aura::HandleAuraTrackResources(bool apply, bool /*Real*/)
3286 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3287 return;
3289 if(apply)
3290 m_target->RemoveNoStackAurasDueToAura(this);
3291 m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
3294 void Aura::HandleAuraTrackStealthed(bool apply, bool /*Real*/)
3296 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3297 return;
3299 if(apply)
3300 m_target->RemoveNoStackAurasDueToAura(this);
3302 m_target->ApplyModFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTE_TRACK_STEALTHED, apply);
3305 void Aura::HandleAuraModScale(bool apply, bool /*Real*/)
3307 m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X, m_modifier.m_amount, apply);
3310 void Aura::HandleModPossess(bool apply, bool Real)
3312 if(!Real)
3313 return;
3315 // not possess yourself
3316 if(GetCasterGUID() == m_target->GetGUID())
3317 return;
3319 Unit* caster = GetCaster();
3320 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3321 return;
3323 Player* p_caster = (Player*)caster;
3326 if( apply )
3328 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3330 m_target->SetCharmerGUID(p_caster->GetGUID());
3331 m_target->setFaction(p_caster->getFaction());
3333 p_caster->SetCharm(m_target);
3335 p_caster->SetFarSightGUID(m_target->GetGUID());
3336 p_caster->SetClientControl(m_target, 1);
3337 p_caster->SetMover(m_target);
3339 m_target->CombatStop();
3340 m_target->DeleteThreatList();
3342 if(m_target->GetTypeId() == TYPEID_UNIT)
3344 m_target->StopMoving();
3345 m_target->GetMotionMaster()->Clear();
3346 m_target->GetMotionMaster()->MoveIdle();
3348 else if(m_target->GetTypeId() == TYPEID_PLAYER)
3350 ((Player*)m_target)->SetClientControl(m_target, 0);
3353 if(CharmInfo *charmInfo = m_target->InitCharmInfo(m_target))
3354 charmInfo->InitPossessCreateSpells();
3356 p_caster->PossessSpellInitialize();
3358 else
3360 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3362 m_target->SetCharmerGUID(0);
3363 p_caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now
3365 if(m_target->GetTypeId() == TYPEID_PLAYER)
3367 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3368 ((Player*)m_target)->SetClientControl(m_target, 1);
3370 else if(m_target->GetTypeId() == TYPEID_UNIT)
3372 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3373 m_target->setFaction(cinfo->faction_A);
3376 p_caster->SetCharm(NULL);
3378 p_caster->SetFarSightGUID(0);
3379 p_caster->SetClientControl(m_target, 0);
3380 p_caster->SetMover(NULL);
3382 p_caster->RemovePetActionBar();
3384 if(m_target->GetTypeId() == TYPEID_UNIT)
3386 ((Creature*)m_target)->AIM_Initialize();
3388 if (((Creature*)m_target)->AI())
3389 ((Creature*)m_target)->AI()->AttackedBy(caster);
3394 void Aura::HandleModPossessPet(bool apply, bool Real)
3396 if(!Real)
3397 return;
3399 Unit* caster = GetCaster();
3400 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3401 return;
3403 Pet *pet = caster->GetPet();
3404 if(!pet || pet != m_target)
3405 return;
3407 Player* p_caster = (Player*)caster;
3409 if(apply)
3410 pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3411 else
3412 pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3414 p_caster->SetFarSightGUID(apply ? pet->GetGUID() : 0);
3415 p_caster->SetCharm(apply ? pet : NULL);
3416 p_caster->SetClientControl(pet, apply ? 1 : 0);
3417 ((Player*)caster)->SetMover(apply ? pet : NULL);
3419 if(apply)
3421 pet->StopMoving();
3422 pet->GetMotionMaster()->Clear();
3423 pet->GetMotionMaster()->MoveIdle();
3425 else
3427 pet->AttackStop();
3428 pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
3429 pet->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
3433 void Aura::HandleAuraModPetTalentsPoints(bool /*Apply*/, bool Real)
3435 if(!Real)
3436 return;
3438 // Recalculate pet talent points
3439 if (Pet *pet=m_target->GetPet())
3440 pet->InitTalentForLevel();
3443 void Aura::HandleModCharm(bool apply, bool Real)
3445 if(!Real)
3446 return;
3448 // not charm yourself
3449 if(GetCasterGUID() == m_target->GetGUID())
3450 return;
3452 Unit* caster = GetCaster();
3453 if(!caster)
3454 return;
3456 if( apply )
3458 m_target->SetCharmerGUID(GetCasterGUID());
3459 m_target->setFaction(caster->getFaction());
3460 m_target->CastStop(m_target == caster ? GetId() : 0);
3461 caster->SetCharm(m_target);
3463 m_target->CombatStop();
3464 m_target->DeleteThreatList();
3466 if(m_target->GetTypeId() == TYPEID_UNIT)
3468 ((Creature*)m_target)->AIM_Initialize();
3469 CharmInfo *charmInfo = m_target->InitCharmInfo(m_target);
3470 charmInfo->InitCharmCreateSpells();
3471 charmInfo->SetReactState( REACT_DEFENSIVE );
3473 if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
3475 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3476 if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
3478 // creature with pet number expected have class set
3479 if(m_target->GetByteValue(UNIT_FIELD_BYTES_0, 1)==0)
3481 if(cinfo->unit_class==0)
3482 sLog.outErrorDb("Creature (Entry: %u) have unit_class = 0 but used in charmed spell, that will be result client crash.",cinfo->Entry);
3483 else
3484 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);
3486 m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, CLASS_MAGE);
3489 //just to enable stat window
3490 charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
3491 //if charmed two demons the same session, the 2nd gets the 1st one's name
3492 m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
3497 if(caster->GetTypeId() == TYPEID_PLAYER)
3498 ((Player*)caster)->CharmSpellInitialize();
3500 else
3502 m_target->SetCharmerGUID(0);
3504 if(m_target->GetTypeId() == TYPEID_PLAYER)
3505 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3506 else
3508 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3510 // restore faction
3511 if(((Creature*)m_target)->isPet())
3513 if(Unit* owner = m_target->GetOwner())
3514 m_target->setFaction(owner->getFaction());
3515 else if(cinfo)
3516 m_target->setFaction(cinfo->faction_A);
3518 else if(cinfo) // normal creature
3519 m_target->setFaction(cinfo->faction_A);
3521 // restore UNIT_FIELD_BYTES_0
3522 if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3524 // DB must have proper class set in field at loading, not req. restore, including workaround case at apply
3525 // m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, cinfo->unit_class);
3527 if(m_target->GetCharmInfo())
3528 m_target->GetCharmInfo()->SetPetNumber(0, true);
3529 else
3530 sLog.outError("Aura::HandleModCharm: target (GUID: %u TypeId: %u) has a charm aura but no charm info!", m_target->GetGUIDLow(), m_target->GetTypeId());
3534 caster->SetCharm(NULL);
3536 if(caster->GetTypeId() == TYPEID_PLAYER)
3537 ((Player*)caster)->RemovePetActionBar();
3539 if(m_target->GetTypeId() == TYPEID_UNIT)
3541 ((Creature*)m_target)->AIM_Initialize();
3542 if (((Creature*)m_target)->AI())
3543 ((Creature*)m_target)->AI()->AttackedBy(caster);
3548 void Aura::HandleModConfuse(bool apply, bool Real)
3550 if(!Real)
3551 return;
3553 m_target->SetConfused(apply, GetCasterGUID(), GetId());
3556 void Aura::HandleModFear(bool apply, bool Real)
3558 if (!Real)
3559 return;
3561 m_target->SetFeared(apply, GetCasterGUID(), GetId());
3564 void Aura::HandleFeignDeath(bool apply, bool Real)
3566 if(!Real)
3567 return;
3569 if(m_target->GetTypeId() != TYPEID_PLAYER)
3570 return;
3572 if( apply )
3575 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3576 data<<m_target->GetGUID();
3577 data<<uint8(0);
3578 m_target->SendMessageToSet(&data,true);
3580 // blizz like 2.0.x
3581 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3582 // blizz like 2.0.x
3583 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3584 // blizz like 2.0.x
3585 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3587 m_target->addUnitState(UNIT_STAT_DIED);
3588 m_target->CombatStop();
3589 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3591 // prevent interrupt message
3592 if (m_caster_guid==m_target->GetGUID())
3593 m_target->FinishSpell(CURRENT_GENERIC_SPELL,false);
3594 m_target->InterruptNonMeleeSpells(true);
3595 m_target->getHostilRefManager().deleteReferences();
3597 else
3600 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3601 data<<m_target->GetGUID();
3602 data<<uint8(1);
3603 m_target->SendMessageToSet(&data,true);
3605 // blizz like 2.0.x
3606 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3607 // blizz like 2.0.x
3608 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3609 // blizz like 2.0.x
3610 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3612 m_target->clearUnitState(UNIT_STAT_DIED);
3616 void Aura::HandleAuraModDisarm(bool apply, bool Real)
3618 if(!Real)
3619 return;
3621 if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3622 return;
3624 // not sure for it's correctness
3625 if(apply)
3626 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3627 else
3628 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3630 // only at real add/remove aura
3631 if (m_target->GetTypeId() != TYPEID_PLAYER)
3632 return;
3634 // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3635 if (m_target->IsInFeralForm())
3636 return;
3638 if (apply)
3639 m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3640 else
3641 ((Player *)m_target)->SetRegularAttackTime();
3643 m_target->UpdateDamagePhysical(BASE_ATTACK);
3646 void Aura::HandleAuraModStun(bool apply, bool Real)
3648 if(!Real)
3649 return;
3651 if (apply)
3653 // Frost stun aura -> freeze/unfreeze target
3654 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3655 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3657 m_target->addUnitState(UNIT_STAT_STUNNED);
3658 m_target->SetTargetGUID(0);
3660 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3661 m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3663 // Creature specific
3664 if(m_target->GetTypeId() != TYPEID_PLAYER)
3665 m_target->StopMoving();
3666 else
3668 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3669 m_target->SetStandState(UNIT_STAND_STATE_STAND);// in 1.5 client
3672 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3673 data.append(m_target->GetPackGUID());
3674 data << uint32(0);
3675 m_target->SendMessageToSet(&data, true);
3677 // Summon the Naj'entus Spine GameObject on target if spell is Impaling Spine
3678 if(GetId() == 39837)
3680 GameObject* pObj = new GameObject;
3681 if(pObj->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 185584, m_target->GetMap(), m_target->GetPhaseMask(),
3682 m_target->GetPositionX(), m_target->GetPositionY(), m_target->GetPositionZ(), m_target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
3684 pObj->SetRespawnTime(GetAuraDuration()/IN_MILISECONDS);
3685 pObj->SetSpellId(GetId());
3686 m_target->AddGameObject(pObj);
3687 m_target->GetMap()->Add(pObj);
3689 else
3690 delete pObj;
3693 else
3695 // Frost stun aura -> freeze/unfreeze target
3696 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3698 bool found_another = false;
3699 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3701 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3702 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3704 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3706 found_another = true;
3707 break;
3710 if(found_another)
3711 break;
3714 if(!found_another)
3715 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3718 // Real remove called after current aura remove from lists, check if other similar auras active
3719 if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3720 return;
3722 m_target->clearUnitState(UNIT_STAT_STUNNED);
3723 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3725 if(!m_target->hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
3727 if(m_target->getVictim() && m_target->isAlive())
3728 m_target->SetTargetGUID(m_target->getVictim()->GetGUID());
3730 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3731 data.append(m_target->GetPackGUID());
3732 data << uint32(0);
3733 m_target->SendMessageToSet(&data, true);
3736 // Wyvern Sting
3737 if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & UI64LIT(0x0000100000000000))
3739 Unit* caster = GetCaster();
3740 if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3741 return;
3743 uint32 spell_id = 0;
3745 switch(GetId())
3747 case 19386: spell_id = 24131; break;
3748 case 24132: spell_id = 24134; break;
3749 case 24133: spell_id = 24135; break;
3750 case 27068: spell_id = 27069; break;
3751 case 49011: spell_id = 49009; break;
3752 case 49012: spell_id = 49010; break;
3753 default:
3754 sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3755 return;
3758 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3760 if(!spellInfo)
3761 return;
3763 caster->CastSpell(m_target,spellInfo,true,NULL,this);
3764 return;
3769 void Aura::HandleModStealth(bool apply, bool Real)
3771 if (apply)
3773 // drop flag at stealth in bg
3774 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3776 // only at real aura add
3777 if (Real)
3779 m_target->SetStandFlags(UNIT_STAND_FLAGS_CREEP);
3781 if (m_target->GetTypeId()==TYPEID_PLAYER)
3782 m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3784 // apply only if not in GM invisibility (and overwrite invisibility state)
3785 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3787 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3788 m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3791 // apply full stealth period bonuses only at first stealth aura in stack
3792 if(m_target->GetAurasByType(SPELL_AURA_MOD_STEALTH).size()<=1)
3794 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3795 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3797 // Master of Subtlety
3798 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3800 m_target->RemoveAurasDueToSpell(31666);
3801 int32 bp = (*i)->GetModifier()->m_amount;
3802 m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3804 // Overkill
3805 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3807 m_target->RemoveAurasDueToSpell(58428);
3808 m_target->CastSpell(m_target, 58427, true);
3814 else
3816 // only at real aura remove of _last_ SPELL_AURA_MOD_STEALTH
3817 if (Real && !m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3819 // if no GM invisibility
3820 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3822 m_target->RemoveStandFlags(UNIT_STAND_FLAGS_CREEP);
3824 if (m_target->GetTypeId()==TYPEID_PLAYER)
3825 m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3827 // restore invisibility if any
3828 if (m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3830 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3831 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3833 else
3834 m_target->SetVisibility(VISIBILITY_ON);
3837 // apply delayed talent bonus remover at last stealth aura remove
3838 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3839 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3841 // Master of Subtlety
3842 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3843 m_target->CastSpell(m_target, 31666, true);
3844 // Overkill
3845 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3846 m_target->CastSpell(m_target, 58428, true);
3852 void Aura::HandleInvisibility(bool apply, bool Real)
3854 if(apply)
3856 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3858 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3860 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3862 // apply glow vision
3863 m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3867 // apply only if not in GM invisibility and not stealth
3868 if(m_target->GetVisibility() == VISIBILITY_ON)
3870 // Aura not added yet but visibility code expect temporary add aura
3871 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3872 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3875 else
3877 // recalculate value at modifier remove (current aura already removed)
3878 m_target->m_invisibilityMask = 0;
3879 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
3880 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3881 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3883 // only at real aura remove and if not have different invisibility auras.
3884 if(Real && m_target->m_invisibilityMask == 0)
3886 // remove glow vision
3887 if(m_target->GetTypeId() == TYPEID_PLAYER)
3888 m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3890 // apply only if not in GM invisibility & not stealthed while invisible
3891 if(m_target->GetVisibility() != VISIBILITY_OFF)
3893 // if have stealth aura then already have stealth visibility
3894 if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3895 m_target->SetVisibility(VISIBILITY_ON);
3901 void Aura::HandleInvisibilityDetect(bool apply, bool Real)
3903 if(apply)
3905 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3907 else
3909 // recalculate value at modifier remove (current aura already removed)
3910 m_target->m_detectInvisibilityMask = 0;
3911 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
3912 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3913 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3915 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3916 ((Player*)m_target)->UpdateVisibilityForPlayer();
3919 void Aura::HandleAuraModRoot(bool apply, bool Real)
3921 // only at real add/remove aura
3922 if(!Real)
3923 return;
3925 if (apply)
3927 // Frost root aura -> freeze/unfreeze target
3928 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3929 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3931 m_target->addUnitState(UNIT_STAT_ROOT);
3932 m_target->SetTargetGUID(0);
3933 // probably wrong (this add skinnable flag)
3934 // TODO: find correct flag
3935 //m_target->SetFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3937 //Save last orientation
3938 if( m_target->getVictim() )
3939 m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
3941 if(m_target->GetTypeId() == TYPEID_PLAYER)
3943 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
3944 data.append(m_target->GetPackGUID());
3945 data << (uint32)2;
3946 m_target->SendMessageToSet(&data, true);
3948 //Clear unit movement flags
3949 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3951 else
3952 m_target->StopMoving();
3954 else
3956 // Frost root aura -> freeze/unfreeze target
3957 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3959 bool found_another = false;
3960 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3962 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3963 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3965 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3967 found_another = true;
3968 break;
3971 if(found_another)
3972 break;
3975 if(!found_another)
3976 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3979 // Real remove called after current aura remove from lists, check if other similar auras active
3980 if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
3981 return;
3983 m_target->clearUnitState(UNIT_STAT_ROOT);
3984 // probably wrong (this add skinnable flag)
3985 // TODO: find correct flag
3986 //m_target->RemoveFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3988 if(!m_target->hasUnitState(UNIT_STAT_STUNNED)) // prevent allow move if have also stun effect
3990 if(m_target->getVictim() && m_target->isAlive())
3991 m_target->SetTargetGUID(m_target->getVictim()->GetGUID());
3993 if(m_target->GetTypeId() == TYPEID_PLAYER)
3995 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
3996 data.append(m_target->GetPackGUID());
3997 data << (uint32)2;
3998 m_target->SendMessageToSet(&data, true);
4004 void Aura::HandleAuraModSilence(bool apply, bool Real)
4006 // only at real add/remove aura
4007 if(!Real)
4008 return;
4010 if(apply)
4012 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
4013 // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
4014 for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4015 if (Spell* spell = m_target->GetCurrentSpell(CurrentSpellTypes(i)))
4016 if(spell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
4017 // Stop spells on prepare or casting state
4018 m_target->InterruptSpell(CurrentSpellTypes(i), false);
4020 else
4022 // Real remove called after current aura remove from lists, check if other similar auras active
4023 if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
4024 return;
4026 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
4030 void Aura::HandleModThreat(bool apply, bool Real)
4032 // only at real add/remove aura
4033 if (!Real)
4034 return;
4036 if (!m_target->isAlive())
4037 return;
4039 Unit* caster = GetCaster();
4041 if (!caster || !caster->isAlive())
4042 return;
4044 int level_diff = 0;
4045 int multiplier = 0;
4046 switch (GetId())
4048 // Arcane Shroud
4049 case 26400:
4050 level_diff = m_target->getLevel() - 60;
4051 multiplier = 2;
4052 break;
4053 // The Eye of Diminution
4054 case 28862:
4055 level_diff = m_target->getLevel() - 60;
4056 multiplier = 1;
4057 break;
4060 if (level_diff > 0)
4061 m_modifier.m_amount += multiplier * level_diff;
4063 if (m_target->GetTypeId() == TYPEID_PLAYER)
4064 for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
4065 if (m_modifier.m_miscvalue & int32(1<<x))
4066 ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_modifier.m_amount, apply);
4069 void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
4071 // only at real add/remove aura
4072 if (!Real)
4073 return;
4075 if (!m_target->isAlive() || m_target->GetTypeId() != TYPEID_PLAYER)
4076 return;
4078 Unit* caster = GetCaster();
4080 if (!caster || !caster->isAlive())
4081 return;
4083 float threatMod = apply ? float(m_modifier.m_amount) : float(-m_modifier.m_amount);
4085 m_target->getHostilRefManager().threatAssist(caster, threatMod);
4088 void Aura::HandleModTaunt(bool apply, bool Real)
4090 // only at real add/remove aura
4091 if (!Real)
4092 return;
4094 if (!m_target->isAlive() || !m_target->CanHaveThreatList())
4095 return;
4097 Unit* caster = GetCaster();
4099 if (!caster || !caster->isAlive())
4100 return;
4102 if (apply)
4103 m_target->TauntApply(caster);
4104 else
4106 // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
4107 m_target->TauntFadeOut(caster);
4111 /*********************************************************/
4112 /*** MODIFY SPEED ***/
4113 /*********************************************************/
4114 void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real)
4116 // all applied/removed only at real aura add/remove
4117 if(!Real)
4118 return;
4120 m_target->UpdateSpeed(MOVE_RUN, true);
4123 void Aura::HandleAuraModIncreaseMountedSpeed(bool /*apply*/, bool Real)
4125 // all applied/removed only at real aura add/remove
4126 if(!Real)
4127 return;
4129 m_target->UpdateSpeed(MOVE_RUN, true);
4132 void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
4134 // all applied/removed only at real aura add/remove
4135 if(!Real)
4136 return;
4138 // Enable Fly mode for flying mounts
4139 if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
4141 WorldPacket data;
4142 if(apply)
4143 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
4144 else
4145 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
4146 data.append(m_target->GetPackGUID());
4147 data << uint32(0); // unknown
4148 m_target->SendMessageToSet(&data, true);
4150 //Players on flying mounts must be immune to polymorph
4151 if (m_target->GetTypeId()==TYPEID_PLAYER)
4152 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
4154 // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
4155 if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
4156 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
4159 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4162 void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real)
4164 // all applied/removed only at real aura add/remove
4165 if(!Real)
4166 return;
4168 m_target->UpdateSpeed(MOVE_SWIM, true);
4171 void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real)
4173 // all applied/removed only at real aura add/remove
4174 if(!Real)
4175 return;
4177 if (apply)
4179 // Gronn Lord's Grasp, becomes stoned
4180 if (GetId() == 33572)
4182 if (GetStackAmount() >= 5 && !m_target->HasAura(33652))
4183 m_target->CastSpell(m_target, 33652, true);
4187 m_target->UpdateSpeed(MOVE_RUN, true);
4188 m_target->UpdateSpeed(MOVE_SWIM, true);
4189 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4192 void Aura::HandleAuraModUseNormalSpeed(bool /*apply*/, bool Real)
4194 // all applied/removed only at real aura add/remove
4195 if(!Real)
4196 return;
4198 m_target->UpdateSpeed(MOVE_RUN, true);
4199 m_target->UpdateSpeed(MOVE_SWIM, true);
4200 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4203 /*********************************************************/
4204 /*** IMMUNITY ***/
4205 /*********************************************************/
4207 void Aura::HandleModMechanicImmunity(bool apply, bool /*Real*/)
4209 uint32 misc = m_modifier.m_miscvalue;
4210 // Forbearance
4211 // in DBC wrong mechanic immune since 3.0.x
4212 if (GetId() == 25771)
4213 misc = MECHANIC_IMMUNE_SHIELD;
4216 if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4218 uint32 mechanic = 1 << misc;
4220 //immune movement impairment and loss of control
4221 if(GetId()==42292 || GetId()==59752)
4222 mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
4224 Unit::AuraMap& Auras = m_target->GetAuras();
4225 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4227 next = iter;
4228 ++next;
4229 SpellEntry const *spell = iter->second->GetSpellProto();
4230 if (!( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) && // spells unaffected by invulnerability
4231 spell->Id != GetId())
4233 //check for mechanic mask
4234 if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & mechanic)
4236 m_target->RemoveAurasDueToSpell(spell->Id);
4237 if(Auras.empty())
4238 break;
4239 else
4240 next = Auras.begin();
4246 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,misc,apply);
4248 // Bestial Wrath
4249 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1680)
4251 // The Beast Within cast on owner if talent present
4252 if (Unit* owner = m_target->GetOwner())
4254 // Search talent
4255 Unit::AuraList const& dummyAuras = owner->GetAurasByType(SPELL_AURA_DUMMY);
4256 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); ++i)
4258 if ((*i)->GetSpellProto()->SpellIconID == 2229)
4260 if (apply)
4261 owner->CastSpell(owner, 34471, true, 0, this);
4262 else
4263 owner->RemoveAurasDueToSpell(34471);
4264 break;
4271 //this method is called whenever we add / remove aura which gives m_target some imunity to some spell effect
4272 void Aura::HandleAuraModEffectImmunity(bool apply, bool /*Real*/)
4274 // when removing flag aura, handle flag drop
4275 if( !apply && m_target->GetTypeId() == TYPEID_PLAYER
4276 && (GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION) )
4278 if( BattleGround *bg = ((Player*)m_target)->GetBattleGround() )
4279 bg->EventPlayerDroppedFlag(((Player*)m_target));
4282 m_target->ApplySpellImmune(GetId(), IMMUNITY_EFFECT, m_modifier.m_miscvalue, apply);
4285 void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
4287 if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4289 Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
4290 for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
4292 if (auraList.front() != this) // skip itself aura (it already added)
4294 m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
4295 itr = auraList.begin();
4297 else
4298 ++itr;
4302 m_target->ApplySpellImmune(GetId(), IMMUNITY_STATE, m_modifier.m_miscvalue, apply);
4305 void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
4307 m_target->ApplySpellImmune(GetId(), IMMUNITY_SCHOOL, m_modifier.m_miscvalue, apply);
4309 // remove all flag auras (they are positive, but they must be removed when you are immune)
4310 if( this->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4311 && this->GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_DAMAGE_REDUCED_SHIELD )
4312 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
4314 // TODO: optimalize this cycle - use RemoveAurasWithInterruptFlags call or something else
4315 if( Real && apply
4316 && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4317 && IsPositiveSpell(GetId()) ) //Only positive immunity removes auras
4319 uint32 school_mask = m_modifier.m_miscvalue;
4320 Unit::AuraMap& Auras = m_target->GetAuras();
4321 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4323 next = iter;
4324 ++next;
4325 SpellEntry const *spell = iter->second->GetSpellProto();
4326 if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
4327 && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) //Spells unaffected by invulnerability
4328 && !iter->second->IsPositive() //Don't remove positive spells
4329 && spell->Id != GetId() ) //Don't remove self
4331 m_target->RemoveAurasDueToSpell(spell->Id);
4332 if(Auras.empty())
4333 break;
4334 else
4335 next = Auras.begin();
4339 if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
4341 if( apply )
4342 m_target->addUnitState(UNIT_STAT_ISOLATED);
4343 else
4344 m_target->clearUnitState(UNIT_STAT_ISOLATED);
4348 void Aura::HandleAuraModDmgImmunity(bool apply, bool /*Real*/)
4350 m_target->ApplySpellImmune(GetId(), IMMUNITY_DAMAGE, m_modifier.m_miscvalue, apply);
4353 void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
4355 // all applied/removed only at real aura add/remove
4356 if(!Real)
4357 return;
4359 m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
4362 void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
4364 if(!Real)
4365 return;
4367 if(apply)
4369 // some spell have charges by functionality not have its in spell data
4370 switch (GetId())
4372 case 28200: // Ascendance (Talisman of Ascendance trinket)
4373 SetAuraCharges(6);
4374 break;
4375 default: break;
4380 void Aura::HandleAuraModStalked(bool apply, bool /*Real*/)
4382 // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
4383 if(apply)
4384 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4385 else
4386 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4389 /*********************************************************/
4390 /*** PERIODIC ***/
4391 /*********************************************************/
4393 void Aura::HandlePeriodicTriggerSpell(bool apply, bool /*Real*/)
4395 m_isPeriodic = apply;
4397 if (!apply)
4399 switch(m_spellProto->Id)
4401 case 66: // Invisibility
4402 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && m_duration<=0)
4403 m_target->CastSpell(m_target, 32612, true, NULL, this);
4405 return;
4406 case 42783: //Wrath of the Astrom...
4407 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && GetEffIndex() + 1 < 3)
4408 m_target->CastSpell(m_target, m_spellProto->CalculateSimpleValue(GetEffIndex()+1), true);
4409 return;
4410 default:
4411 break;
4416 void Aura::HandlePeriodicTriggerSpellWithValue(bool apply, bool /*Real*/)
4418 m_isPeriodic = apply;
4421 void Aura::HandlePeriodicEnergize(bool apply, bool Real)
4423 if (!Real)
4424 return;
4426 m_isPeriodic = apply;
4428 // Replenishment (0.25% from max)
4429 // Infinite Replenishment
4430 if (GetId() == 57669 ||
4431 GetId() == 61782)
4432 m_modifier.m_amount = m_target->GetMaxPower(POWER_MANA) * 25 / 10000;
4435 void Aura::HandleAuraPowerBurn(bool apply, bool /*Real*/)
4437 m_isPeriodic = apply;
4440 void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
4442 // spells required only Real aura add/remove
4443 if(!Real)
4444 return;
4446 // For prevent double apply bonuses
4447 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4449 Unit* caster = GetCaster();
4451 SpellEntry const*spell = GetSpellProto();
4452 switch( spell->SpellFamilyName)
4454 case SPELLFAMILY_ROGUE:
4456 if(!apply)
4458 switch(spell->Id)
4460 // Master of Subtlety
4461 case 31666: m_target->RemoveAurasDueToSpell(31665); break;
4462 // Overkill
4463 case 58428: m_target->RemoveAurasDueToSpell(58427); break;
4466 break;
4468 case SPELLFAMILY_HUNTER:
4470 // Explosive Shot
4471 if (apply && !loading && caster)
4472 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 14 / 100);
4473 break;
4477 m_isPeriodic = apply;
4480 void Aura::HandlePeriodicHeal(bool apply, bool /*Real*/)
4482 m_isPeriodic = apply;
4485 void Aura::HandlePeriodicDamage(bool apply, bool Real)
4487 // spells required only Real aura add/remove
4488 if(!Real)
4489 return;
4491 m_isPeriodic = apply;
4493 // For prevent double apply bonuses
4494 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4496 // Custom damage calculation after
4497 if (apply)
4499 if(loading)
4500 return;
4502 Unit *caster = GetCaster();
4503 if (!caster)
4504 return;
4506 switch (m_spellProto->SpellFamilyName)
4508 case SPELLFAMILY_GENERIC:
4510 // Pounce Bleed
4511 if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual[0] == 0 )
4513 // $AP*0.18/6 bonus per tick
4514 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4515 return;
4517 break;
4519 case SPELLFAMILY_WARRIOR:
4521 // Rend
4522 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000020))
4524 // $0.2*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4525 float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4526 int32 mws = caster->GetAttackTime(BASE_ATTACK);
4527 float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4528 float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4529 m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.2f);
4530 return;
4532 break;
4534 case SPELLFAMILY_DRUID:
4536 // Rake
4537 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellProto->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
4539 // $AP*0.18/3 bonus per tick
4540 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 6 / 100);
4541 return;
4543 // Lacerate
4544 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000010000000000))
4546 // $AP*0.05/5 bonus per tick
4547 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4548 return;
4550 // Rip
4551 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000800000))
4553 // 0.01*$AP*cp
4554 if (caster->GetTypeId() != TYPEID_PLAYER)
4555 return;
4557 uint8 cp = ((Player*)caster)->GetComboPoints();
4559 // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4560 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4561 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4563 if((*itr)->GetId()==34241)
4565 m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4566 break;
4569 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4570 return;
4572 // Lock Jaw
4573 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
4575 // 0.15*$AP
4576 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 15 / 100);
4577 return;
4579 break;
4581 case SPELLFAMILY_ROGUE:
4583 // Rupture
4584 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000100000))
4586 if (caster->GetTypeId() != TYPEID_PLAYER)
4587 return;
4588 //1 point : ${($m1+$b1*1+0.015*$AP)*4} damage over 8 secs
4589 //2 points: ${($m1+$b1*2+0.024*$AP)*5} damage over 10 secs
4590 //3 points: ${($m1+$b1*3+0.03*$AP)*6} damage over 12 secs
4591 //4 points: ${($m1+$b1*4+0.03428571*$AP)*7} damage over 14 secs
4592 //5 points: ${($m1+$b1*5+0.0375*$AP)*8} damage over 16 secs
4593 float AP_per_combo[6] = {0.0f, 0.015f, 0.024f, 0.03f, 0.03428571f, 0.0375f};
4594 uint8 cp = ((Player*)caster)->GetComboPoints();
4595 if (cp > 5) cp = 5;
4596 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * AP_per_combo[cp]);
4597 return;
4599 // Garrote
4600 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000000100))
4602 // $AP*0.07 bonus per tick
4603 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 7 / 100);
4604 return;
4606 // Deadly Poison
4607 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000010000))
4609 // 0.08*$AP / 4 * amount of stack
4610 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 2 * GetStackAmount() / 100);
4611 return;
4613 break;
4615 case SPELLFAMILY_HUNTER:
4617 // Serpent Sting
4618 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000004000))
4620 // $RAP*0.1/5 bonus per tick
4621 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4622 return;
4624 // Immolation Trap
4625 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) && m_spellProto->SpellIconID == 678)
4627 // $RAP*0.1/5 bonus per tick
4628 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4629 return;
4631 break;
4633 default:
4634 break;
4637 // remove time effects
4638 else
4640 // Parasitic Shadowfiend - handle summoning of two Shadowfiends on DoT expire
4641 if(m_spellProto->Id == 41917)
4642 m_target->CastSpell(m_target, 41915, true);
4646 void Aura::HandlePeriodicDamagePCT(bool apply, bool /*Real*/)
4648 m_isPeriodic = apply;
4651 void Aura::HandlePeriodicLeech(bool apply, bool /*Real*/)
4653 m_isPeriodic = apply;
4656 void Aura::HandlePeriodicManaLeech(bool apply, bool /*Real*/)
4658 m_isPeriodic = apply;
4661 void Aura::HandlePeriodicHealthFunnel(bool apply, bool /*Real*/)
4663 m_isPeriodic = apply;
4666 /*********************************************************/
4667 /*** MODIFY STATS ***/
4668 /*********************************************************/
4670 /********************************/
4671 /*** RESISTANCE ***/
4672 /********************************/
4674 void Aura::HandleAuraModResistanceExclusive(bool apply, bool /*Real*/)
4676 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4678 if(m_modifier.m_miscvalue & int32(1<<x))
4680 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4681 if(m_target->GetTypeId() == TYPEID_PLAYER)
4682 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4687 void Aura::HandleAuraModResistance(bool apply, bool /*Real*/)
4689 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4691 if(m_modifier.m_miscvalue & int32(1<<x))
4693 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4694 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4695 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4700 void Aura::HandleAuraModBaseResistancePCT(bool apply, bool /*Real*/)
4702 // only players have base stats
4703 if(m_target->GetTypeId() != TYPEID_PLAYER)
4705 //pets only have base armor
4706 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4707 m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4709 else
4711 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4713 if(m_modifier.m_miscvalue & int32(1<<x))
4714 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4719 void Aura::HandleModResistancePercent(bool apply, bool /*Real*/)
4721 for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4723 if(m_modifier.m_miscvalue & int32(1<<i))
4725 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4726 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4728 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, m_modifier.m_amount, apply);
4729 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, m_modifier.m_amount, apply);
4735 void Aura::HandleModBaseResistance(bool apply, bool /*Real*/)
4737 // only players have base stats
4738 if(m_target->GetTypeId() != TYPEID_PLAYER)
4740 //only pets have base stats
4741 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4742 m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4744 else
4746 for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4747 if(m_modifier.m_miscvalue & (1<<i))
4748 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4752 /********************************/
4753 /*** STAT ***/
4754 /********************************/
4756 void Aura::HandleAuraModStat(bool apply, bool /*Real*/)
4758 if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4760 sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4761 return;
4764 for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4766 // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4767 if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4769 //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4770 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4771 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4772 m_target->ApplyStatBuffMod(Stats(i), m_modifier.m_amount, apply);
4777 void Aura::HandleModPercentStat(bool apply, bool /*Real*/)
4779 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4781 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4782 return;
4785 // only players have base stats
4786 if (m_target->GetTypeId() != TYPEID_PLAYER)
4787 return;
4789 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4791 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4792 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4796 void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool /*Real*/)
4798 if(m_target->GetTypeId() != TYPEID_PLAYER)
4799 return;
4801 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4802 // This information for client side use only
4803 // Recalculate bonus
4804 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4807 void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool /*Real*/)
4809 if(m_target->GetTypeId() != TYPEID_PLAYER)
4810 return;
4812 // Recalculate bonus
4813 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4816 void Aura::HandleAuraModDispelResist(bool apply, bool Real)
4818 if(!Real || !apply)
4819 return;
4821 if(GetId() == 33206)
4822 m_target->CastSpell(m_target, 44416, true, NULL, this, GetCasterGUID());
4825 void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4827 if(m_target->GetTypeId() != TYPEID_PLAYER)
4828 return;
4830 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4831 // This information for client side use only
4832 // Recalculate bonus
4833 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4836 void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4838 if(m_target->GetTypeId() != TYPEID_PLAYER)
4839 return;
4841 // Recalculate bonus
4842 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4845 void Aura::HandleModHealingDone(bool /*apply*/, bool /*Real*/)
4847 if(m_target->GetTypeId() != TYPEID_PLAYER)
4848 return;
4849 // implemented in Unit::SpellHealingBonus
4850 // this information is for client side only
4851 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4854 void Aura::HandleModTotalPercentStat(bool apply, bool /*Real*/)
4856 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4858 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4859 return;
4862 //save current and max HP before applying aura
4863 uint32 curHPValue = m_target->GetHealth();
4864 uint32 maxHPValue = m_target->GetMaxHealth();
4866 for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4868 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4870 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4871 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4872 m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
4876 //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
4877 if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
4879 // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
4880 uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
4881 m_target->SetHealth(newHPValue);
4885 void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool /*Real*/)
4887 if(m_target->GetTypeId() != TYPEID_PLAYER)
4888 return;
4890 if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
4892 // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
4893 // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
4894 sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
4895 return;
4898 // Recalculate Armor
4899 m_target->UpdateArmor();
4902 /********************************/
4903 /*** HEAL & ENERGIZE ***/
4904 /********************************/
4905 void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool /*Real*/)
4907 m_isPeriodic = apply;
4910 void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool /*Real*/)
4912 if(m_modifier.periodictime == 0)
4913 m_modifier.periodictime = 1000;
4915 m_periodicTimer = m_modifier.periodictime;
4916 m_isPeriodic = apply;
4919 void Aura::HandleModRegen(bool apply, bool /*Real*/) // eating
4921 if(m_modifier.periodictime == 0)
4922 m_modifier.periodictime = 5000;
4924 m_periodicTimer = 5000;
4925 m_isPeriodic = apply;
4928 void Aura::HandleModPowerRegen(bool apply, bool Real) // drinking
4930 if (!Real)
4931 return;
4933 Powers pt = m_target->getPowerType();
4934 if(m_modifier.periodictime == 0)
4936 // Anger Management (only spell use this aura for rage)
4937 if (pt == POWER_RAGE)
4938 m_modifier.periodictime = 3000;
4939 else
4940 m_modifier.periodictime = 2000;
4943 m_periodicTimer = 5000;
4945 if (m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
4946 ((Player*)m_target)->UpdateManaRegen();
4948 m_isPeriodic = apply;
4951 void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real)
4953 // spells required only Real aura add/remove
4954 if(!Real)
4955 return;
4957 if (m_target->GetTypeId() != TYPEID_PLAYER)
4958 return;
4960 // Update manaregen value
4961 if (m_modifier.m_miscvalue == POWER_MANA)
4962 ((Player*)m_target)->UpdateManaRegen();
4965 void Aura::HandleModManaRegen(bool /*apply*/, bool Real)
4967 // spells required only Real aura add/remove
4968 if(!Real)
4969 return;
4971 if (m_target->GetTypeId() != TYPEID_PLAYER)
4972 return;
4974 //Note: an increase in regen does NOT cause threat.
4975 ((Player*)m_target)->UpdateManaRegen();
4978 void Aura::HandleComprehendLanguage(bool apply, bool /*Real*/)
4980 if(apply)
4981 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4982 else
4983 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4986 void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
4988 // Special case with temporary increase max/current health
4989 switch(GetId())
4991 case 12976: // Warrior Last Stand triggered spell
4992 case 28726: // Nightmare Seed ( Nightmare Seed )
4993 case 34511: // Valor (Bulwark of Kings, Bulwark of the Ancient Kings)
4994 // FIXME: add case 67596: in 3.2.x
4995 case 44055: case 55915: case 55917: // Tremendous Fortitude (Battlemaster's Alacrity)
4996 case 50322: // Survival Instincts
4997 case 54443: // Demonic Empowerment (Voidwalker)
4999 if(Real)
5001 if(apply)
5003 // Demonic Empowerment (Voidwalker) - special case, store percent in data
5004 // recalculate to full amount at apply for proper remove
5005 if (GetId() == 54443)
5006 m_modifier.m_amount = m_target->GetMaxHealth() * m_modifier.m_amount / 100;
5008 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5009 m_target->ModifyHealth(m_modifier.m_amount);
5011 else
5013 if (int32(m_target->GetHealth()) > m_modifier.m_amount)
5014 m_target->ModifyHealth(-m_modifier.m_amount);
5015 else
5016 m_target->SetHealth(1);
5017 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5020 return;
5024 // generic case
5025 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5028 void Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool /*Real*/)
5030 uint32 oldhealth = m_target->GetHealth();
5031 double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
5033 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5035 // refresh percentage
5036 if(oldhealth > 0)
5038 uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
5039 if(newhealth==0)
5040 newhealth = 1;
5042 m_target->SetHealth(newhealth);
5046 void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
5048 Powers powerType = m_target->getPowerType();
5049 if(int32(powerType) != m_modifier.m_miscvalue)
5050 return;
5052 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5054 // Special case with temporary increase max/current power (percent)
5055 if (GetId()==64904) // Hymn of Hope
5057 if(Real)
5059 uint32 val = m_target->GetPower(powerType);
5060 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5061 m_target->SetPower(powerType, apply ? val*(100+m_modifier.m_amount)/100 : val*100/(100+m_modifier.m_amount));
5063 return;
5066 // generic flat case
5067 m_target->HandleStatModifier(unitMod, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5070 void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool /*Real*/)
5072 Powers powerType = m_target->getPowerType();
5073 if(int32(powerType) != m_modifier.m_miscvalue)
5074 return;
5076 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5078 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5081 void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool /*Real*/)
5083 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
5086 void Aura::HandleAuraIncreaseBaseHealthPercent(bool apply, bool /*Real*/)
5088 m_target->HandleStatModifier(UNIT_MOD_HEALTH, BASE_PCT, float(m_modifier.m_amount), apply);
5091 /********************************/
5092 /*** FIGHT ***/
5093 /********************************/
5095 void Aura::HandleAuraModParryPercent(bool /*apply*/, bool /*Real*/)
5097 if(m_target->GetTypeId() != TYPEID_PLAYER)
5098 return;
5100 ((Player*)m_target)->UpdateParryPercentage();
5103 void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool /*Real*/)
5105 if(m_target->GetTypeId() != TYPEID_PLAYER)
5106 return;
5108 ((Player*)m_target)->UpdateDodgePercentage();
5109 //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
5112 void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool /*Real*/)
5114 if(m_target->GetTypeId() != TYPEID_PLAYER)
5115 return;
5117 ((Player*)m_target)->UpdateBlockPercentage();
5118 //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
5121 void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real)
5123 // spells required only Real aura add/remove
5124 if(!Real)
5125 return;
5127 if(m_target->GetTypeId() != TYPEID_PLAYER)
5128 return;
5130 ((Player*)m_target)->UpdateManaRegen();
5133 void Aura::HandleAuraModCritPercent(bool apply, bool Real)
5135 if(m_target->GetTypeId() != TYPEID_PLAYER)
5136 return;
5138 // apply item specific bonuses for already equipped weapon
5139 if(Real)
5141 for(int i = 0; i < MAX_ATTACK; ++i)
5142 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5143 ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem, WeaponAttackType(i), this, apply);
5146 // mods must be applied base at equipped weapon class and subclass comparison
5147 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5148 // m_modifier.m_miscvalue comparison with item generated damage types
5150 if (GetSpellProto()->EquippedItemClass == -1)
5152 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5153 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5154 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5156 else
5158 // done in Player::_ApplyWeaponDependentAuraMods
5162 void Aura::HandleModHitChance(bool apply, bool /*Real*/)
5164 if(m_target->GetTypeId() == TYPEID_PLAYER)
5166 ((Player*)m_target)->UpdateMeleeHitChances();
5167 ((Player*)m_target)->UpdateRangedHitChances();
5169 else
5171 m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5172 m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5176 void Aura::HandleModSpellHitChance(bool apply, bool /*Real*/)
5178 if(m_target->GetTypeId() == TYPEID_PLAYER)
5180 ((Player*)m_target)->UpdateSpellHitChances();
5182 else
5184 m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
5188 void Aura::HandleModSpellCritChance(bool apply, bool Real)
5190 // spells required only Real aura add/remove
5191 if(!Real)
5192 return;
5194 if(m_target->GetTypeId() == TYPEID_PLAYER)
5196 ((Player*)m_target)->UpdateAllSpellCritChances();
5198 else
5200 m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
5204 void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real)
5206 // spells required only Real aura add/remove
5207 if(!Real)
5208 return;
5210 if(m_target->GetTypeId() != TYPEID_PLAYER)
5211 return;
5213 for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
5214 if (m_modifier.m_miscvalue & (1<<school))
5215 ((Player*)m_target)->UpdateSpellCritChance(school);
5218 /********************************/
5219 /*** ATTACK SPEED ***/
5220 /********************************/
5222 void Aura::HandleModCastingSpeed(bool apply, bool /*Real*/)
5224 m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
5227 void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool /*Real*/)
5229 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5230 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5231 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5234 void Aura::HandleModCombatSpeedPct(bool apply, bool /*Real*/)
5236 m_target->ApplyCastTimePercentMod(m_modifier.m_amount, apply);
5237 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5238 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5239 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5242 void Aura::HandleModAttackSpeed(bool apply, bool /*Real*/)
5244 if(!m_target->isAlive() )
5245 return;
5247 m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
5250 void Aura::HandleHaste(bool apply, bool /*Real*/)
5252 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5253 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5254 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5257 void Aura::HandleAuraModRangedHaste(bool apply, bool /*Real*/)
5259 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5262 void Aura::HandleRangedAmmoHaste(bool apply, bool /*Real*/)
5264 if(m_target->GetTypeId() != TYPEID_PLAYER)
5265 return;
5266 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
5269 /********************************/
5270 /*** ATTACK POWER ***/
5271 /********************************/
5273 void Aura::HandleAuraModAttackPower(bool apply, bool /*Real*/)
5275 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5278 void Aura::HandleAuraModRangedAttackPower(bool apply, bool /*Real*/)
5280 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5281 return;
5283 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5286 void Aura::HandleAuraModAttackPowerPercent(bool apply, bool /*Real*/)
5288 //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
5289 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
5292 void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool /*Real*/)
5294 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5295 return;
5297 //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
5298 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5301 void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5303 // spells required only Real aura add/remove
5304 if(!Real)
5305 return;
5307 // Recalculate bonus
5308 if(m_target->GetTypeId() == TYPEID_PLAYER && !(m_target->getClassMask() & CLASSMASK_WAND_USERS))
5309 ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
5312 void Aura::HandleAuraModAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5314 // spells required only Real aura add/remove
5315 if(!Real)
5316 return;
5318 // Recalculate bonus
5319 if(m_target->GetTypeId() == TYPEID_PLAYER)
5320 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5323 void Aura::HandleAuraModAttackPowerOfArmor(bool /*apply*/, bool Real)
5325 // spells required only Real aura add/remove
5326 if(!Real)
5327 return;
5329 // Recalculate bonus
5330 if(m_target->GetTypeId() == TYPEID_PLAYER)
5331 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5333 /********************************/
5334 /*** DAMAGE BONUS ***/
5335 /********************************/
5336 void Aura::HandleModDamageDone(bool apply, bool Real)
5338 // apply item specific bonuses for already equipped weapon
5339 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5341 for(int i = 0; i < MAX_ATTACK; ++i)
5342 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5343 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5346 // m_modifier.m_miscvalue is bitmask of spell schools
5347 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5348 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
5349 // 127 - full bitmask any damages
5351 // mods must be applied base at equipped weapon class and subclass comparison
5352 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5353 // m_modifier.m_miscvalue comparison with item generated damage types
5355 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5357 // apply generic physical damage bonuses including wand case
5358 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5360 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5361 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5362 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5364 else
5366 // done in Player::_ApplyWeaponDependentAuraMods
5369 if(m_target->GetTypeId() == TYPEID_PLAYER)
5371 if(m_positive)
5372 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS, m_modifier.m_amount, apply);
5373 else
5374 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG, m_modifier.m_amount, apply);
5378 // Skip non magic case for speedup
5379 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5380 return;
5382 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5384 // wand magic case (skip generic to all item spell bonuses)
5385 // done in Player::_ApplyWeaponDependentAuraMods
5387 // Skip item specific requirements for not wand magic damage
5388 return;
5391 // Magic damage modifiers implemented in Unit::SpellDamageBonus
5392 // This information for client side use only
5393 if(m_target->GetTypeId() == TYPEID_PLAYER)
5395 if(m_positive)
5397 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5399 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5400 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, m_modifier.m_amount, apply);
5403 else
5405 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5407 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5408 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, m_modifier.m_amount, apply);
5411 Pet* pet = m_target->GetPet();
5412 if(pet)
5413 pet->UpdateAttackPowerAndDamage();
5417 void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5419 sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5421 // apply item specific bonuses for already equipped weapon
5422 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5424 for(int i = 0; i < MAX_ATTACK; ++i)
5425 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5426 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5429 // m_modifier.m_miscvalue is bitmask of spell schools
5430 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5431 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5432 // 127 - full bitmask any damages
5434 // mods must be applied base at equipped weapon class and subclass comparison
5435 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5436 // m_modifier.m_miscvalue comparison with item generated damage types
5438 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5440 // apply generic physical damage bonuses including wand case
5441 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5443 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5444 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5445 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5447 else
5449 // done in Player::_ApplyWeaponDependentAuraMods
5451 // For show in client
5452 if(m_target->GetTypeId() == TYPEID_PLAYER)
5453 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT, m_modifier.m_amount/100.0f, apply);
5456 // Skip non magic case for speedup
5457 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5458 return;
5460 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5462 // wand magic case (skip generic to all item spell bonuses)
5463 // done in Player::_ApplyWeaponDependentAuraMods
5465 // Skip item specific requirements for not wand magic damage
5466 return;
5469 // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5470 // Send info to client
5471 if(m_target->GetTypeId() == TYPEID_PLAYER)
5472 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5473 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT + i, m_modifier.m_amount/100.0f, apply);
5476 void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5478 // spells required only Real aura add/remove
5479 if(!Real)
5480 return;
5482 sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5484 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5487 /********************************/
5488 /*** POWER COST ***/
5489 /********************************/
5491 void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5493 // spells required only Real aura add/remove
5494 if(!Real)
5495 return;
5497 float amount = m_modifier.m_amount/100.0f;
5498 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5499 if(m_modifier.m_miscvalue & (1<<i))
5500 m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + i, amount, apply);
5503 void Aura::HandleModPowerCost(bool apply, bool Real)
5505 // spells required only Real aura add/remove
5506 if(!Real)
5507 return;
5509 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5510 if(m_modifier.m_miscvalue & (1<<i))
5511 m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + i, m_modifier.m_amount, apply);
5514 void Aura::HandleNoReagentUseAura(bool /*Apply*/, bool Real)
5516 // spells required only Real aura add/remove
5517 if(!Real)
5518 return;
5519 if(m_target->GetTypeId() != TYPEID_PLAYER)
5520 return;
5521 uint32 mask[3] = {0, 0, 0};
5522 Unit::AuraList const& noReagent = m_target->GetAurasByType(SPELL_AURA_NO_REAGENT_USE);
5523 for(Unit::AuraList::const_iterator i = noReagent.begin(); i != noReagent.end(); ++i)
5525 uint32 const *ptr = (*i)->getAuraSpellClassMask();
5526 mask[0] |= ptr[0];
5527 mask[1] |= ptr[1];
5528 mask[2] |= ptr[2];
5531 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+0, mask[0]);
5532 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+1, mask[1]);
5533 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+2, mask[2]);
5536 /*********************************************************/
5537 /*** OTHERS ***/
5538 /*********************************************************/
5540 void Aura::HandleShapeshiftBoosts(bool apply)
5542 uint32 spellId1 = 0;
5543 uint32 spellId2 = 0;
5544 uint32 HotWSpellId = 0;
5545 uint32 MasterShaperSpellId = 0;
5547 uint32 form = GetModifier()->m_miscvalue;
5549 switch(form)
5551 case FORM_CAT:
5552 spellId1 = 3025;
5553 HotWSpellId = 24900;
5554 MasterShaperSpellId = 48420;
5555 break;
5556 case FORM_TREE:
5557 spellId1 = 5420;
5558 spellId2 = 34123;
5559 MasterShaperSpellId = 48422;
5560 break;
5561 case FORM_TRAVEL:
5562 spellId1 = 5419;
5563 break;
5564 case FORM_AQUA:
5565 spellId1 = 5421;
5566 break;
5567 case FORM_BEAR:
5568 spellId1 = 1178;
5569 spellId2 = 21178;
5570 HotWSpellId = 24899;
5571 MasterShaperSpellId = 48418;
5572 break;
5573 case FORM_DIREBEAR:
5574 spellId1 = 9635;
5575 spellId2 = 21178;
5576 HotWSpellId = 24899;
5577 MasterShaperSpellId = 48418;
5578 break;
5579 case FORM_BATTLESTANCE:
5580 spellId1 = 21156;
5581 break;
5582 case FORM_DEFENSIVESTANCE:
5583 spellId1 = 7376;
5584 break;
5585 case FORM_BERSERKERSTANCE:
5586 spellId1 = 7381;
5587 break;
5588 case FORM_MOONKIN:
5589 spellId1 = 24905;
5590 MasterShaperSpellId = 48421;
5591 break;
5592 case FORM_FLIGHT:
5593 spellId1 = 33948;
5594 spellId2 = 34764;
5595 break;
5596 case FORM_FLIGHT_EPIC:
5597 spellId1 = 40122;
5598 spellId2 = 40121;
5599 break;
5600 case FORM_METAMORPHOSIS:
5601 spellId1 = 54817;
5602 spellId2 = 54879;
5603 break;
5604 case FORM_SPIRITOFREDEMPTION:
5605 spellId1 = 27792;
5606 spellId2 = 27795; // must be second, this important at aura remove to prevent to early iterator invalidation.
5607 break;
5608 case FORM_SHADOW:
5609 spellId1 = 49868;
5611 if(m_target->GetTypeId() == TYPEID_PLAYER) // Spell 49868 have same category as main form spell and share cooldown
5612 ((Player*)m_target)->RemoveSpellCooldown(49868);
5613 break;
5614 case FORM_GHOSTWOLF:
5615 case FORM_AMBIENT:
5616 case FORM_GHOUL:
5617 case FORM_STEALTH:
5618 case FORM_CREATURECAT:
5619 case FORM_CREATUREBEAR:
5620 break;
5623 if(apply)
5625 if (spellId1)
5626 m_target->CastSpell(m_target, spellId1, true, NULL, this );
5627 if (spellId2)
5628 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5630 if (m_target->GetTypeId() == TYPEID_PLAYER)
5632 const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5633 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5635 if (itr->second->state == PLAYERSPELL_REMOVED) continue;
5636 if (itr->first==spellId1 || itr->first==spellId2) continue;
5637 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5638 if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7))))
5639 continue;
5640 if (spellInfo->Stances & (1<<(form-1)))
5641 m_target->CastSpell(m_target, itr->first, true, NULL, this);
5644 // Master Shapeshifter
5645 if (MasterShaperSpellId)
5647 Unit::AuraList const& ShapeShifterAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5648 for(Unit::AuraList::const_iterator i = ShapeShifterAuras.begin(); i != ShapeShifterAuras.end(); i++)
5650 if ((*i)->GetSpellProto()->SpellIconID == 2851)
5652 int32 ShiftMod = (*i)->GetModifier()->m_amount;
5653 m_target->CastCustomSpell(m_target, MasterShaperSpellId, &ShiftMod, NULL, NULL, true);
5654 break;
5659 // Leader of the Pack
5660 if (((Player*)m_target)->HasSpell(17007))
5662 SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5663 if (spellInfo && spellInfo->Stances & (1<<(form-1)))
5664 m_target->CastSpell(m_target, 24932, true, NULL, this);
5667 // Savage Roar
5668 if (form == FORM_CAT && ((Player*)m_target)->HasAura(52610))
5669 m_target->CastSpell(m_target, 62071, true);
5671 // Improved Moonkin Form
5672 if (form == FORM_MOONKIN)
5674 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5675 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); i++)
5677 if ((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_DRUID &&
5678 (*i)->GetSpellProto()->SpellIconID == 2855)
5680 uint32 spell_id = 0;
5681 switch((*i)->GetId())
5683 case 48384:spell_id=50170;break;//Rank 1
5684 case 48395:spell_id=50171;break;//Rank 2
5685 case 48396:spell_id=50172;break;//Rank 3
5686 default:
5687 sLog.outError("Aura::HandleShapeshiftBoosts: Not handled rank of IMF (Spell: %u)",(*i)->GetId());
5688 break;
5691 if(spell_id)
5692 m_target->CastSpell(m_target, spell_id, true, NULL, this);
5693 break;
5698 // Heart of the Wild
5699 if (HotWSpellId)
5701 Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5702 for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5704 if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5706 int32 HotWMod = (*i)->GetModifier()->m_amount;
5707 if(GetModifier()->m_miscvalue == FORM_CAT)
5708 HotWMod /= 2;
5710 m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5711 break;
5717 else
5719 if(spellId1)
5720 m_target->RemoveAurasDueToSpell(spellId1);
5721 if(spellId2)
5722 m_target->RemoveAurasDueToSpell(spellId2);
5723 if(MasterShaperSpellId)
5724 m_target->RemoveAurasDueToSpell(MasterShaperSpellId);
5726 Unit::AuraMap& tAuras = m_target->GetAuras();
5727 for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5729 if (itr->second->IsRemovedOnShapeLost())
5731 m_target->RemoveAurasDueToSpell(itr->second->GetId());
5732 itr = tAuras.begin();
5734 else
5735 ++itr;
5740 void Aura::HandleSpellSpecificBoosts(bool apply)
5742 uint32 spellId1 = 0;
5743 uint32 spellId2 = 0;
5744 uint32 spellId3 = 0;
5745 uint32 spellId4 = 0;
5747 switch(GetSpellProto()->SpellFamilyName)
5749 case SPELLFAMILY_WARRIOR:
5751 if(!apply)
5753 // Remove Blood Frenzy only if target no longer has any Deep Wound or Rend (applying is handled by procs)
5754 if (GetSpellProto()->Mechanic != MECHANIC_BLEED)
5755 return;
5757 // If target still has one of Warrior's bleeds, do nothing
5758 Unit::AuraList const& PeriodicDamage = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
5759 for(Unit::AuraList::const_iterator i = PeriodicDamage.begin(); i != PeriodicDamage.end(); ++i)
5760 if( (*i)->GetCasterGUID() == GetCasterGUID() &&
5761 (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARRIOR &&
5762 (*i)->GetSpellProto()->Mechanic == MECHANIC_BLEED)
5763 return;
5765 spellId1 = 30069;
5766 spellId2 = 30070;
5768 break;
5770 case SPELLFAMILY_PRIEST:
5771 // Dispersion mana reg and immunity
5772 if (GetSpellProto()->Id == 47585)
5774 spellId1 = 60069;
5775 spellId2 = 63230;
5777 break;
5778 case SPELLFAMILY_ROGUE:
5779 // Sprint (skip non player casted spells by category)
5780 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000040) && GetSpellProto()->Category == 44)
5782 if(!apply || m_target->HasAura(58039)) // Glyph of Blurred Speed
5783 spellId1 = 61922; // Sprint (waterwalk)
5784 else
5785 return;
5787 else
5788 return;
5789 break;
5790 case SPELLFAMILY_HUNTER:
5792 // The Beast Within and Bestial Wrath - immunity
5793 if (GetId() == 19574 || GetId() == 34471)
5795 spellId1 = 24395;
5796 spellId2 = 24396;
5797 spellId3 = 24397;
5798 spellId4 = 26592;
5800 // Aspect of the Dragonhawk dodge
5801 else if (GetSpellProto()->SpellFamilyFlags2 & 0x00001000)
5803 spellId1 = 61848;
5805 // triggered spell have same category as main spell and cooldown
5806 if (apply && m_target->GetTypeId()==TYPEID_PLAYER)
5807 ((Player*)m_target)->RemoveSpellCooldown(61848);
5809 else
5810 return;
5811 break;
5813 case SPELLFAMILY_PALADIN:
5815 // Only process on player casting paladin aura
5816 // all aura bonuses applied also in aura area effect way to caster
5817 if (GetCasterGUID() != m_target->GetGUID() || !IS_PLAYER_GUID(GetCasterGUID()))
5818 return;
5820 if (GetSpellSpecific(m_spellProto->Id) != SPELL_AURA)
5821 return;
5823 // Sanctified Retribution and Swift Retribution (they share one aura), but not Retribution Aura (already gets modded)
5824 if ((GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000008))==0)
5825 spellId1 = 63531; // placeholder for talent spell mods
5826 // Improved Concentration Aura (auras bonus)
5827 spellId2 = 63510; // placeholder for talent spell mods
5828 // Improved Devotion Aura (auras bonus)
5829 spellId3 = 63514; // placeholder for talent spell mods
5830 break;
5832 case SPELLFAMILY_DEATHKNIGHT:
5834 if (GetSpellSpecific(m_spellProto->Id) != SPELL_PRESENCE)
5835 return;
5837 // Frost Presence health
5838 if (GetId() == 48263)
5839 spellId1 = 61261;
5840 // Unholy Presence move speed
5841 else if (GetId() == 48265)
5842 spellId1 = 49772;
5843 else
5844 return;
5846 break;
5848 default:
5849 return;
5852 // prevent aura deletion, specially in multi-boost case
5853 SetInUse(true);
5855 if (apply)
5857 if (spellId1)
5858 m_target->CastSpell(m_target, spellId1, true, NULL, this);
5859 if (spellId2 && !IsDeleted())
5860 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5861 if (spellId3 && !IsDeleted())
5862 m_target->CastSpell(m_target, spellId3, true, NULL, this);
5863 if (spellId4 && !IsDeleted())
5864 m_target->CastSpell(m_target, spellId4, true, NULL, this);
5866 else
5868 if (spellId1)
5869 m_target->RemoveAurasByCasterSpell(spellId1, GetCasterGUID());
5870 if (spellId2)
5871 m_target->RemoveAurasByCasterSpell(spellId2, GetCasterGUID());
5872 if (spellId3)
5873 m_target->RemoveAurasByCasterSpell(spellId3, GetCasterGUID());
5874 if (spellId4)
5875 m_target->RemoveAurasByCasterSpell(spellId4, GetCasterGUID());
5878 SetInUse(false);
5881 void Aura::HandleAuraEmpathy(bool apply, bool /*Real*/)
5883 if(m_target->GetTypeId() != TYPEID_UNIT)
5884 return;
5886 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5887 if(ci && ci->type == CREATURE_TYPE_BEAST)
5888 m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5891 void Aura::HandleAuraUntrackable(bool apply, bool /*Real*/)
5893 if(apply)
5894 m_target->SetByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5895 else
5896 m_target->RemoveByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5899 void Aura::HandleAuraModPacify(bool apply, bool /*Real*/)
5901 if(m_target->GetTypeId() != TYPEID_PLAYER)
5902 return;
5904 if(apply)
5905 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5906 else
5907 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5910 void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5912 HandleAuraModPacify(apply, Real);
5913 HandleAuraModSilence(apply, Real);
5916 void Aura::HandleAuraGhost(bool apply, bool /*Real*/)
5918 if(m_target->GetTypeId() != TYPEID_PLAYER)
5919 return;
5921 if(apply)
5923 m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5925 else
5927 m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5931 void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5933 // all applied/removed only at real aura add/remove
5934 if(!Real)
5935 return;
5937 // allow fly
5938 WorldPacket data;
5939 if(apply)
5940 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5941 else
5942 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5943 data.append(m_target->GetPackGUID());
5944 data << uint32(0); // unk
5945 m_target->SendMessageToSet(&data, true);
5948 void Aura::HandleModRating(bool apply, bool Real)
5950 // spells required only Real aura add/remove
5951 if(!Real)
5952 return;
5954 if(m_target->GetTypeId() != TYPEID_PLAYER)
5955 return;
5957 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5958 if (m_modifier.m_miscvalue & (1 << rating))
5959 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5962 void Aura::HandleModRatingFromStat(bool apply, bool Real)
5964 // spells required only Real aura add/remove
5965 if(!Real)
5966 return;
5968 if(m_target->GetTypeId() != TYPEID_PLAYER)
5969 return;
5970 // Just recalculate ratings
5971 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5972 if (m_modifier.m_miscvalue & (1 << rating))
5973 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), 0, apply);
5976 void Aura::HandleForceMoveForward(bool apply, bool Real)
5978 if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5979 return;
5980 if(apply)
5981 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5982 else
5983 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5986 void Aura::HandleAuraModExpertise(bool /*apply*/, bool /*Real*/)
5988 if(m_target->GetTypeId() != TYPEID_PLAYER)
5989 return;
5991 ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5992 ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5995 void Aura::HandleModTargetResistance(bool apply, bool Real)
5997 // spells required only Real aura add/remove
5998 if(!Real)
5999 return;
6000 // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
6002 // show armor penetration
6003 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
6004 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE, m_modifier.m_amount, apply);
6006 // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
6007 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
6008 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE, m_modifier.m_amount, apply);
6011 void Aura::HandleShieldBlockValue(bool apply, bool /*Real*/)
6013 BaseModType modType = FLAT_MOD;
6014 if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
6015 modType = PCT_MOD;
6017 if(m_target->GetTypeId() == TYPEID_PLAYER)
6018 ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
6021 void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
6023 // spells required only Real aura add/remove
6024 if(!Real)
6025 return;
6027 if(m_target->GetTypeId() != TYPEID_PLAYER)
6028 return;
6030 Player *target = (Player*)m_target;
6032 // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
6033 // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
6034 if( !apply && m_duration==0 && target->GetComboTarget())
6035 if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
6036 target->AddComboPoints(unit, -m_modifier.m_amount);
6039 void Aura::HandleModUnattackable( bool Apply, bool Real )
6041 if(Real && Apply)
6043 m_target->CombatStop();
6044 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
6046 m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
6049 void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
6051 // spells required only Real aura add/remove
6052 if(!Real)
6053 return;
6055 // prepare spirit state
6056 if(apply)
6058 if(m_target->GetTypeId()==TYPEID_PLAYER)
6060 // disable breath/etc timers
6061 ((Player*)m_target)->StopMirrorTimers();
6063 // set stand state (expected in this form)
6064 if(!m_target->IsStandState())
6065 m_target->SetStandState(UNIT_STAND_STATE_STAND);
6068 m_target->SetHealth(1);
6070 // die at aura end
6071 else
6072 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
6075 void Aura::CleanupTriggeredSpells()
6077 uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
6078 if(!tSpellId)
6079 return;
6081 SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
6082 if(!tProto)
6083 return;
6085 if(GetSpellDuration(tProto) != -1)
6086 return;
6088 // needed for spell 43680, maybe others
6089 // TODO: is there a spell flag, which can solve this in a more sophisticated way?
6090 if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
6091 GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
6092 return;
6093 m_target->RemoveAurasDueToSpell(tSpellId);
6096 void Aura::HandleSchoolAbsorb(bool apply, bool Real)
6098 if(!Real)
6099 return;
6101 Unit* caster = GetCaster();
6102 if(!caster)
6103 return;
6105 if (apply)
6107 // prevent double apply bonuses
6108 if (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
6110 float DoneActualBenefit = 0.0f;
6111 switch(m_spellProto->SpellFamilyName)
6113 case SPELLFAMILY_PRIEST:
6114 // Power Word: Shield
6115 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001))
6116 //+80.68% from +spell bonus
6117 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.8068f;
6118 break;
6119 case SPELLFAMILY_MAGE:
6120 // Frost Ward, Fire Ward
6121 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000108))
6122 //+10% from +spell bonus
6123 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
6124 // Ice Barrier
6125 else if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000100000000))
6126 //+80.67% from +spell bonus
6127 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.8067f;
6128 break;
6129 case SPELLFAMILY_WARLOCK:
6130 // Shadow Ward
6131 if (m_spellProto->SpellFamilyFlags2 & 0x00000040)
6132 //+30% from +spell bonus
6133 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.30f;
6134 break;
6135 case SPELLFAMILY_PALADIN:
6136 // Sacred Shield
6137 // (check not strictly needed, only Sacred Shield has SPELL_AURA_SCHOOL_ABSORB in SPELLFAMILY_PALADIN at this time)
6138 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0008000000000000))
6140 // +75% from spell power
6141 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.75f;
6143 break;
6144 case SPELLFAMILY_DRUID:
6145 // Savage Defense (amount store original percent of attack power applied)
6146 if (m_spellProto->SpellIconID == 50) // only spell with this aura fit
6147 m_modifier.m_amount = int32(m_modifier.m_amount * m_target->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
6148 break;
6149 default:
6150 break;
6153 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6155 m_modifier.m_amount += (int32)DoneActualBenefit;
6157 // now that the correct amount is computed, apply caster aura, if any
6158 switch(m_spellProto->SpellFamilyName)
6160 case SPELLFAMILY_PRIEST:
6161 // Power Word: Shield
6162 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001))
6164 // Glyph of Power Word: Shield
6165 if(Aura* glyph = caster->GetAura(55672,0))
6167 // instant heal glyph m_amount% of the absorbed amount
6168 int32 heal = (glyph->GetModifier()->m_amount * m_modifier.m_amount)/100;
6169 caster->CastCustomSpell(m_target, 56160, &heal, NULL, NULL, true, 0, this);
6172 break;
6173 default:
6174 break;
6178 else
6180 // Ice Barrier (remove effect from Shattered Barrier)
6181 if (m_spellProto->SpellIconID == 32 && m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE)
6183 if (!((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6184 return;
6186 if (m_target->HasAura(44745,0)) // Shattered Barrier, rank 1
6188 if(roll_chance_i(50))
6189 m_target->CastSpell(m_target, 55080, true, NULL, this);
6191 else if (m_target->HasAura(54787,0)) // Shattered Barrier, rank 2
6193 m_target->CastSpell(m_target, 55080, true, NULL, this);
6197 if (caster &&
6198 // Power Word: Shield
6199 m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST && m_spellProto->Mechanic == MECHANIC_SHIELD &&
6200 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001)) &&
6201 // completely absorbed or dispelled
6202 ((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6204 Unit::AuraList const& vDummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6205 for(Unit::AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); itr++)
6207 SpellEntry const* vSpell = (*itr)->GetSpellProto();
6209 // Rapture (main spell)
6210 if(vSpell->SpellFamilyName == SPELLFAMILY_PRIEST && vSpell->SpellIconID == 2894 && vSpell->Effect[1])
6212 switch((*itr)->GetEffIndex())
6214 case 0:
6216 // energize caster
6217 int32 manapct1000 = 5 * ((*itr)->GetModifier()->m_amount + spellmgr.GetSpellRank(vSpell->Id));
6218 int32 basepoints0 = caster->GetMaxPower(POWER_MANA) * manapct1000 / 1000;
6219 caster->CastCustomSpell(caster, 47755, &basepoints0, NULL, NULL, true);
6220 break;
6222 case 1:
6224 // energize target
6225 if (!roll_chance_i((*itr)->GetModifier()->m_amount) || caster->HasAura(63853))
6226 break;
6228 switch(m_target->getPowerType())
6230 case POWER_RUNIC_POWER:
6231 m_target->CastSpell(m_target, 63652, true, NULL, NULL, m_caster_guid);
6232 break;
6233 case POWER_RAGE:
6234 m_target->CastSpell(m_target, 63653, true, NULL, NULL, m_caster_guid);
6235 break;
6236 case POWER_MANA:
6238 int32 basepoints0 = m_target->GetMaxPower(POWER_MANA) * 2 / 100;
6239 m_target->CastCustomSpell(m_target, 63654, &basepoints0, NULL, NULL, true);
6240 break;
6242 case POWER_ENERGY:
6243 m_target->CastSpell(m_target, 63655, true, NULL, NULL, m_caster_guid);
6244 break;
6245 default:
6246 break;
6249 //cooldwon aura
6250 caster->CastSpell(caster, 63853, true);
6251 break;
6253 default:
6254 sLog.outError("Changes in R-dummy spell???: effect 3");
6255 break;
6263 void Aura::PeriodicTick()
6265 if (!m_target->isAlive() != IsDeathOnlySpell(GetSpellProto()))
6266 return;
6268 switch(m_modifier.m_auraname)
6270 case SPELL_AURA_PERIODIC_DAMAGE:
6271 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
6273 Unit *pCaster = GetCaster();
6274 if(!pCaster)
6275 return;
6277 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6278 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6279 return;
6281 // Check for immune (not use charges)
6282 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6283 return;
6285 // some auras remove at specific health level or more
6286 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6288 switch(GetId())
6290 case 43093: case 31956: case 38801:
6291 case 35321: case 38363: case 39215:
6292 if(m_target->GetHealth() == m_target->GetMaxHealth() )
6294 m_target->RemoveAurasDueToSpell(GetId());
6295 return;
6297 break;
6298 case 38772:
6300 uint32 percent =
6301 GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_DUMMY ?
6302 pCaster->CalculateSpellDamage(GetSpellProto(), GetEffIndex() + 1, GetSpellProto()->EffectBasePoints[GetEffIndex() + 1], m_target) :
6303 100;
6304 if(m_target->GetHealth() * 100 >= m_target->GetMaxHealth() * percent )
6306 m_target->RemoveAurasDueToSpell(GetId());
6307 return;
6309 break;
6311 default:
6312 break;
6316 uint32 absorb = 0;
6317 uint32 resist = 0;
6318 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6320 // ignore non positive values (can be result apply spellmods to aura damage
6321 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6323 uint32 pdamage;
6325 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6327 pdamage = amount;
6329 // Calculate armor mitigation if it is a physical spell
6330 // But not for bleed mechanic spells
6331 if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
6332 GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
6334 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6335 cleanDamage.damage += pdamage - pdamageReductedArmor;
6336 pdamage = pdamageReductedArmor;
6339 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6341 // Curse of Agony damage-per-tick calculation
6342 if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000400)) && GetSpellProto()->SpellIconID==544)
6344 // 1..4 ticks, 1/2 from normal tick damage
6345 if (m_duration >= ((m_maxduration-m_modifier.periodictime) * 2 / 3))
6346 pdamage = pdamage/2;
6347 // 9..12 ticks, 3/2 from normal tick damage
6348 else if(m_duration < ((m_maxduration-m_modifier.periodictime) / 3))
6349 pdamage += (pdamage + 1) / 2; // +1 prevent 0.5 damage possible lost at 1..4 ticks
6350 // 5..8 ticks have normal tick damage
6353 else
6354 pdamage = uint32(m_target->GetMaxHealth()*amount/100);
6356 // This method can modify pdamage
6357 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6359 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6360 // Reduce dot damage from resilience for players
6361 if (m_target->GetTypeId() == TYPEID_PLAYER)
6362 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6364 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6366 sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6367 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6369 pCaster->DealDamageMods(m_target, pdamage, &absorb);
6371 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, absorb, resist, 0.0f, isCrit);
6372 m_target->SendPeriodicAuraLog(&pInfo);
6374 // Set trigger flag
6375 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6376 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6377 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage - absorb - resist);
6378 if (pdamage)
6379 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6380 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6382 pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6383 break;
6385 case SPELL_AURA_PERIODIC_LEECH:
6386 case SPELL_AURA_PERIODIC_HEALTH_FUNNEL:
6388 Unit *pCaster = GetCaster();
6389 if(!pCaster)
6390 return;
6392 if(!pCaster->isAlive())
6393 return;
6395 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6396 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6397 return;
6399 // Check for immune
6400 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6401 return;
6403 uint32 absorb=0;
6404 uint32 resist=0;
6405 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6407 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6409 //Calculate armor mitigation if it is a physical spell
6410 if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
6412 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6413 cleanDamage.damage += pdamage - pdamageReductedArmor;
6414 pdamage = pdamageReductedArmor;
6417 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6419 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6420 // Reduce dot damage from resilience for players
6421 if (m_target->GetTypeId()==TYPEID_PLAYER)
6422 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6424 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6426 if(m_target->GetHealth() < pdamage)
6427 pdamage = uint32(m_target->GetHealth());
6429 sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6430 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6432 pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
6434 float multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()] > 0 ? GetSpellProto()->EffectMultipleValue[GetEffIndex()] : 1;
6436 // Set trigger flag
6437 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6438 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6439 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage-absorb-resist);
6440 if (pdamage)
6441 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6442 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6443 int32 new_damage = pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
6445 if (!m_target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
6446 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
6447 if (Spell* spell = pCaster->GetCurrentSpell(CurrentSpellTypes(i)))
6448 if (spell->m_spellInfo->Id == GetId())
6449 spell->cancel();
6452 if(Player *modOwner = pCaster->GetSpellModOwner())
6453 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, multiplier);
6455 uint32 heal = pCaster->SpellHealingBonus(pCaster, GetSpellProto(), uint32(new_damage * multiplier), DOT, GetStackAmount());
6457 int32 gain = pCaster->DealHeal(pCaster, heal, GetSpellProto());
6458 pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, GetSpellProto());
6459 break;
6461 case SPELL_AURA_PERIODIC_HEAL:
6462 case SPELL_AURA_OBS_MOD_HEALTH:
6464 Unit *pCaster = GetCaster();
6465 if(!pCaster)
6466 return;
6468 // heal for caster damage (must be alive)
6469 if(m_target != pCaster && GetSpellProto()->SpellVisual[0] == 163 && !pCaster->isAlive())
6470 return;
6472 // ignore non positive values (can be result apply spellmods to aura damage
6473 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6475 uint32 pdamage;
6477 if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
6478 pdamage = uint32(m_target->GetMaxHealth() * amount / 100);
6479 else
6481 pdamage = amount;
6483 // Wild Growth (1/7 - 6 + 2*ramainTicks) %
6484 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && m_spellProto->SpellIconID == 2864)
6486 int32 ticks = m_maxduration/m_modifier.periodictime;
6487 int32 remainingTicks = int32(float(m_duration) / m_modifier.periodictime + 0.5);
6488 pdamage = int32(pdamage) + int32(amount)*ticks*(-6+2*remainingTicks)/100;
6492 pdamage = pCaster->SpellHealingBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6494 // This method can modify pdamage
6495 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6497 sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
6498 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6500 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f, isCrit);
6501 m_target->SendPeriodicAuraLog(&pInfo);
6503 int32 gain = m_target->ModifyHealth(pdamage);
6505 // add HoTs to amount healed in bgs
6506 if( pCaster->GetTypeId() == TYPEID_PLAYER )
6507 if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
6508 bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
6510 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6512 SpellEntry const* spellProto = GetSpellProto();
6514 // heal for caster damage
6515 if(m_target != pCaster && spellProto->SpellVisual[0] == 163)
6517 uint32 dmg = spellProto->manaPerSecond;
6518 if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
6520 pCaster->RemoveAurasDueToSpell(GetId());
6522 // finish current generic/channeling spells, don't affect autorepeat
6523 pCaster->FinishSpell(CURRENT_GENERIC_SPELL);
6524 pCaster->FinishSpell(CURRENT_CHANNELED_SPELL);
6526 else
6528 uint32 damage = gain;
6529 uint32 absorb = 0;
6530 pCaster->DealDamageMods(pCaster, damage, &absorb);
6531 pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), damage, GetSpellSchoolMask(GetSpellProto()), absorb, 0, false, 0, false);
6533 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6534 pCaster->DealDamage(pCaster, damage, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6538 // uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC;// | PROC_FLAG_SUCCESSFUL_HEAL;
6539 // uint32 procVictim = 0;//ROC_FLAG_ON_TAKE_PERIODIC | PROC_FLAG_TAKEN_HEAL;
6540 // ignore item heals
6541 // if(procSpell && !haveCastItem)
6542 // pCaster->ProcDamageAndSpell(target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, spellProto);
6543 break;
6545 case SPELL_AURA_PERIODIC_MANA_LEECH:
6547 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6548 return;
6550 Powers power = Powers(m_modifier.m_miscvalue);
6552 // power type might have changed between aura applying and tick (druid's shapeshift)
6553 if(m_target->getPowerType() != power)
6554 return;
6556 Unit *pCaster = GetCaster();
6557 if(!pCaster)
6558 return;
6560 if(!pCaster->isAlive())
6561 return;
6563 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6564 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6565 return;
6567 // Check for immune (not use charges)
6568 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6569 return;
6571 // ignore non positive values (can be result apply spellmods to aura damage
6572 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6574 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
6575 // It's mana percent cost spells, m_modifier.m_amount is percent drain from target
6576 if (m_spellProto->ManaCostPercentage)
6578 // max value
6579 uint32 maxmana = pCaster->GetMaxPower(power) * pdamage * 2 / 100;
6580 pdamage = m_target->GetMaxPower(power) * pdamage / 100;
6581 if(pdamage > maxmana)
6582 pdamage = maxmana;
6585 sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
6586 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6588 int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
6590 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6591 if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6592 drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
6594 m_target->ModifyPower(power, -drain_amount);
6596 float gain_multiplier = 0;
6598 if(pCaster->GetMaxPower(power) > 0)
6600 gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
6602 if(Player *modOwner = pCaster->GetSpellModOwner())
6603 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
6606 SpellPeriodicAuraLogInfo pInfo(this, drain_amount, 0, 0, 0, gain_multiplier);
6607 m_target->SendPeriodicAuraLog(&pInfo);
6609 int32 gain_amount = int32(drain_amount * gain_multiplier);
6611 if(gain_amount)
6613 int32 gain = pCaster->ModifyPower(power, gain_amount);
6614 m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
6616 break;
6618 case SPELL_AURA_PERIODIC_ENERGIZE:
6620 // ignore non positive values (can be result apply spellmods to aura damage
6621 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6623 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
6624 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6626 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6627 break;
6629 Powers power = Powers(m_modifier.m_miscvalue);
6631 if(m_target->GetMaxPower(power) == 0)
6632 break;
6634 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6635 m_target->SendPeriodicAuraLog(&pInfo);
6637 int32 gain = m_target->ModifyPower(power,pdamage);
6639 if(Unit* pCaster = GetCaster())
6640 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6641 break;
6643 case SPELL_AURA_OBS_MOD_MANA:
6645 // ignore non positive values (can be result apply spellmods to aura damage
6646 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6648 uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount / 100);
6650 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
6651 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6653 if(m_target->GetMaxPower(POWER_MANA) == 0)
6654 break;
6656 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6657 m_target->SendPeriodicAuraLog(&pInfo);
6659 int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
6661 if(Unit* pCaster = GetCaster())
6662 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6663 break;
6665 case SPELL_AURA_POWER_BURN_MANA:
6667 Unit *pCaster = GetCaster();
6668 if(!pCaster)
6669 return;
6671 // Check for immune (not use charges)
6672 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6673 return;
6675 int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6677 Powers powerType = Powers(m_modifier.m_miscvalue);
6679 if(!m_target->isAlive() || m_target->getPowerType() != powerType)
6680 return;
6682 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6683 if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6684 pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
6686 uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
6688 gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
6690 SpellEntry const* spellProto = GetSpellProto();
6691 // maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
6692 SpellNonMeleeDamage damageInfo(pCaster, m_target, spellProto->Id, spellProto->SchoolMask);
6693 pCaster->CalculateSpellDamage(&damageInfo, gain, spellProto);
6695 pCaster->DealDamageMods(damageInfo.target, damageInfo.damage, &damageInfo.absorb);
6697 pCaster->SendSpellNonMeleeDamageLog(&damageInfo);
6699 // Set trigger flag
6700 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6701 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6702 uint32 procEx = createProcExtendMask(&damageInfo, SPELL_MISS_NONE);
6703 if (damageInfo.damage)
6704 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6706 pCaster->ProcDamageAndSpell(damageInfo.target, procAttacker, procVictim, procEx, damageInfo.damage, BASE_ATTACK, spellProto);
6708 pCaster->DealSpellDamage(&damageInfo, true);
6709 break;
6711 case SPELL_AURA_MOD_REGEN:
6713 int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
6714 if (Unit *caster = GetCaster())
6715 m_target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, GetSpellProto());
6716 break;
6718 case SPELL_AURA_MOD_POWER_REGEN:
6720 Powers pt = m_target->getPowerType();
6721 if(int32(pt) != m_modifier.m_miscvalue)
6722 return;
6724 if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
6726 // eating anim
6727 m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
6729 else if( GetId() == 20577 )
6731 // cannibalize anim
6732 m_target->HandleEmoteCommand(EMOTE_STATE_CANNIBALIZE);
6735 // Anger Management
6736 // amount = 1+ 16 = 17 = 3,4*5 = 10,2*5/3
6737 // so 17 is rounded amount for 5 sec tick grow ~ 1 range grow in 3 sec
6738 if(pt == POWER_RAGE)
6739 m_target->ModifyPower(pt, m_modifier.m_amount * 3 / 5);
6740 break;
6742 // Here tick dummy auras
6743 case SPELL_AURA_PERIODIC_DUMMY:
6745 PeriodicDummyTick();
6746 break;
6748 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
6750 TriggerSpell();
6751 break;
6753 case SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE:
6755 TriggerSpellWithValue();
6756 break;
6758 default:
6759 break;
6763 void Aura::PeriodicDummyTick()
6765 SpellEntry const* spell = GetSpellProto();
6766 switch (spell->SpellFamilyName)
6768 case SPELLFAMILY_GENERIC:
6769 switch (spell->Id)
6771 // Drink
6772 case 430:
6773 case 431:
6774 case 432:
6775 case 1133:
6776 case 1135:
6777 case 1137:
6778 case 10250:
6779 case 22734:
6780 case 27089:
6781 case 34291:
6782 case 43182:
6783 case 43183:
6784 case 43706:
6785 case 46755:
6786 case 49472: // Drink Coffee
6787 case 57073:
6788 case 61830:
6790 if (m_target->GetTypeId() != TYPEID_PLAYER)
6791 return;
6792 // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6793 Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6794 for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6796 if ((*i)->GetId() == GetId())
6798 (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6799 ((Player*)m_target)->UpdateManaRegen();
6800 // Disable continue
6801 m_isPeriodic = false;
6802 return;
6805 return;
6807 // Forsaken Skills
6808 case 7054:
6810 // Possibly need cast one of them (but
6811 // 7038 Forsaken Skill: Swords
6812 // 7039 Forsaken Skill: Axes
6813 // 7040 Forsaken Skill: Daggers
6814 // 7041 Forsaken Skill: Maces
6815 // 7042 Forsaken Skill: Staves
6816 // 7043 Forsaken Skill: Bows
6817 // 7044 Forsaken Skill: Guns
6818 // 7045 Forsaken Skill: 2H Axes
6819 // 7046 Forsaken Skill: 2H Maces
6820 // 7047 Forsaken Skill: 2H Swords
6821 // 7048 Forsaken Skill: Defense
6822 // 7049 Forsaken Skill: Fire
6823 // 7050 Forsaken Skill: Frost
6824 // 7051 Forsaken Skill: Holy
6825 // 7053 Forsaken Skill: Shadow
6826 return;
6828 // // Panda
6829 // case 19230: break;
6830 // // Gossip NPC Periodic - Talk
6831 // case 33208: break;
6832 // // Gossip NPC Periodic - Despawn
6833 // case 33209: break;
6834 // // Steal Weapon
6835 // case 36207: break;
6836 // // Simon Game START timer, (DND)
6837 // case 39993: break;
6838 // // Knockdown Fel Cannon: break; The Aggro Burst
6839 // case 40119: break;
6840 // // Old Mount Spell
6841 // case 40154: break;
6842 // // Magnetic Pull
6843 // case 40581: break;
6844 // // Ethereal Ring: break; The Bolt Burst
6845 // case 40801: break;
6846 // // Crystal Prison
6847 // case 40846: break;
6848 // // Copy Weapon
6849 // case 41054: break;
6850 // // Dementia
6851 // case 41404: break;
6852 // // Ethereal Ring Visual, Lightning Aura
6853 // case 41477: break;
6854 // // Ethereal Ring Visual, Lightning Aura (Fork)
6855 // case 41525: break;
6856 // // Ethereal Ring Visual, Lightning Jumper Aura
6857 // case 41567: break;
6858 // // No Man's Land
6859 // case 41955: break;
6860 // // Headless Horseman - Fire
6861 // case 42074: break;
6862 // // Headless Horseman - Visual - Large Fire
6863 // case 42075: break;
6864 // // Headless Horseman - Start Fire, Periodic Aura
6865 // case 42140: break;
6866 // // Ram Speed Boost
6867 // case 42152: break;
6868 // // Headless Horseman - Fires Out Victory Aura
6869 // case 42235: break;
6870 // // Pumpkin Life Cycle
6871 // case 42280: break;
6872 // // Brewfest Request Chick Chuck Mug Aura
6873 // case 42537: break;
6874 // // Squashling
6875 // case 42596: break;
6876 // // Headless Horseman Climax, Head: Periodic
6877 // case 42603: break;
6878 // // Fire Bomb
6879 // case 42621: break;
6880 // // Headless Horseman - Conflagrate, Periodic Aura
6881 // case 42637: break;
6882 // // Headless Horseman - Create Pumpkin Treats Aura
6883 // case 42774: break;
6884 // // Headless Horseman Climax - Summoning Rhyme Aura
6885 // case 42879: break;
6886 // // Tricky Treat
6887 // case 42919: break;
6888 // // Giddyup!
6889 // case 42924: break;
6890 // // Ram - Trot
6891 // case 42992: break;
6892 // // Ram - Canter
6893 // case 42993: break;
6894 // // Ram - Gallop
6895 // case 42994: break;
6896 // // Ram Level - Neutral
6897 // case 43310: break;
6898 // // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6899 // case 43884: break;
6900 // // Wretched!
6901 // case 43963: break;
6902 // // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6903 // case 44000: break;
6904 // // Energy Feedback
6905 // case 44328: break;
6906 // // Romantic Picnic
6907 // case 45102: break;
6908 // // Romantic Picnic
6909 // case 45123: break;
6910 // // Looking for Love
6911 // case 45124: break;
6912 // // Kite - Lightning Strike Kite Aura
6913 // case 45197: break;
6914 // // Rocket Chicken
6915 // case 45202: break;
6916 // // Copy Offhand Weapon
6917 // case 45205: break;
6918 // // Upper Deck - Kite - Lightning Periodic Aura
6919 // case 45207: break;
6920 // // Kite -Sky Lightning Strike Kite Aura
6921 // case 45251: break;
6922 // // Ribbon Pole Dancer Check Aura
6923 // case 45390: break;
6924 // // Holiday - Midsummer, Ribbon Pole Periodic Visual
6925 // case 45406: break;
6926 // // Parachute
6927 // case 45472: break;
6928 // // Alliance Flag, Extra Damage Debuff
6929 // case 45898: break;
6930 // // Horde Flag, Extra Damage Debuff
6931 // case 45899: break;
6932 // // Ahune - Summoning Rhyme Aura
6933 // case 45926: break;
6934 // // Ahune - Slippery Floor
6935 // case 45945: break;
6936 // // Ahune's Shield
6937 // case 45954: break;
6938 // // Nether Vapor Lightning
6939 // case 45960: break;
6940 // // Darkness
6941 // case 45996: break;
6942 // // Summon Blood Elves Periodic
6943 // case 46041: break;
6944 // // Transform Visual Missile Periodic
6945 // case 46205: break;
6946 // // Find Opening Beam End
6947 // case 46333: break;
6948 // // Ice Spear Control Aura
6949 // case 46371: break;
6950 // // Hailstone Chill
6951 // case 46458: break;
6952 // // Hailstone Chill, Internal
6953 // case 46465: break;
6954 // // Chill, Internal Shifter
6955 // case 46549: break;
6956 // // Summon Ice Spear Knockback Delayer
6957 // case 46878: break;
6958 // // Burninate Effect
6959 // case 47214: break;
6960 // // Fizzcrank Practice Parachute
6961 // case 47228: break;
6962 // // Send Mug Control Aura
6963 // case 47369: break;
6964 // // Direbrew's Disarm (precast)
6965 // case 47407: break;
6966 // // Mole Machine Port Schedule
6967 // case 47489: break;
6968 // case 47941: break; // Crystal Spike
6969 // case 48200: break; // Healer Aura
6970 // case 48630: break; // Summon Gauntlet Mobs Periodic
6971 // case 49313: break; // Proximity Mine Area Aura
6972 // // Mole Machine Portal Schedule
6973 // case 49466: break;
6974 // case 49555: break; // Corpse Explode
6975 // case 49592: break; // Temporal Rift
6976 // case 49957: break; // Cutting Laser
6977 // case 50085: break; // Slow Fall
6978 // // Listening to Music
6979 // case 50493: break;
6980 // // Love Rocket Barrage
6981 // case 50530: break;
6982 // Exist more after, need add later
6983 default:
6984 break;
6986 // Prey on the Weak
6987 if (spell->SpellIconID == 2983)
6989 Unit *target=m_target->getVictim();
6990 if (target && (m_target->GetHealth() * 100 / m_target->GetMaxHealth() > target->GetHealth() * 100 / target->GetMaxHealth()))
6992 if(!m_target->HasAura(58670))
6994 int32 basepoints = GetBasePoints();
6995 m_target->CastCustomSpell(m_target, 58670, &basepoints, 0, 0, true);
6998 else
6999 m_target->RemoveAurasDueToSpell(58670);
7001 break;
7002 case SPELLFAMILY_MAGE:
7004 // Mirror Image
7005 // if (spell->Id == 55342)
7006 // return;
7007 break;
7009 case SPELLFAMILY_DRUID:
7011 switch (spell->Id)
7013 // Frenzied Regeneration
7014 case 22842:
7016 // Converts up to 10 rage per second into health for $d. Each point of rage is converted into ${$m2/10}.1% of max health.
7017 // Should be manauser
7018 if (m_target->getPowerType() != POWER_RAGE)
7019 return;
7020 uint32 rage = m_target->GetPower(POWER_RAGE);
7021 // Nothing todo
7022 if (rage == 0)
7023 return;
7024 int32 mod = (rage < 100) ? rage : 100;
7025 int32 points = m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7026 int32 regen = m_target->GetMaxHealth() * (mod * points / 10) / 1000;
7027 m_target->CastCustomSpell(m_target, 22845, &regen, NULL, NULL, true, NULL, this);
7028 m_target->SetPower(POWER_RAGE, rage-mod);
7029 return;
7031 // Force of Nature
7032 case 33831:
7033 return;
7034 default:
7035 break;
7037 break;
7039 case SPELLFAMILY_ROGUE:
7041 switch (spell->Id)
7043 // Killing Spree
7044 case 51690:
7046 if (m_target->hasUnitState(UNIT_STAT_STUNNED) || m_target->HasAuraType(SPELL_AURA_MOD_FEAR))
7047 return;
7049 std::list<Unit*> targets;
7051 // eff_radius ==0
7052 float radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spell->rangeIndex));
7054 CellPair p(MaNGOS::ComputeCellPair(m_target->GetPositionX(),m_target->GetPositionY()));
7055 Cell cell(p);
7056 cell.data.Part.reserved = ALL_DISTRICT;
7058 MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck u_check(m_target, m_target, radius);
7059 MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck> checker(m_target, targets, u_check);
7061 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker);
7062 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
7064 CellLock<GridReadGuard> cell_lock(cell, p);
7066 cell_lock->Visit(cell_lock, grid_object_checker, *m_target->GetMap(), *m_target, radius);
7067 cell_lock->Visit(cell_lock, world_object_checker, *m_target->GetMap(), *m_target, radius);
7070 if(targets.empty())
7071 return;
7073 std::list<Unit*>::const_iterator itr = targets.begin();
7074 std::advance(itr, rand()%targets.size());
7075 Unit* target = *itr;
7077 m_target->CastSpell(target, 57840, true);
7078 m_target->CastSpell(target, 57841, true);
7079 return;
7081 default:
7082 break;
7084 break;
7086 case SPELLFAMILY_HUNTER:
7088 // Explosive Shot
7089 if (spell->SpellFamilyFlags & UI64LIT(0x8000000000000000))
7091 m_target->CastCustomSpell(m_target, 53352, &m_modifier.m_amount, 0, 0, true, 0, this, GetCasterGUID());
7092 return;
7094 switch (spell->Id)
7096 // Harpooner's Mark
7097 // case 40084:
7098 // return;
7099 // Feeding Frenzy Rank 1
7100 case 53511:
7101 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
7102 m_target->CastSpell(m_target, 60096, true, 0, this);
7103 return;
7104 // Feeding Frenzy Rank 2
7105 case 53512:
7106 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
7107 m_target->CastSpell(m_target, 60097, true, 0, this);
7108 return;
7109 default:
7110 break;
7112 break;
7114 case SPELLFAMILY_SHAMAN:
7116 // Astral Shift
7117 if (spell->Id == 52179)
7119 // Periodic need for remove visual on stun/fear/silence lost
7120 if (!(m_target->GetUInt32Value(UNIT_FIELD_FLAGS)&(UNIT_FLAG_STUNNED|UNIT_FLAG_FLEEING|UNIT_FLAG_SILENCED)))
7121 m_target->RemoveAurasDueToSpell(52179);
7122 return;
7124 break;
7126 case SPELLFAMILY_DEATHKNIGHT:
7128 // Death and Decay
7129 if (spell->SpellFamilyFlags & UI64LIT(0x0000000000000020))
7131 if (Unit *caster = GetCaster())
7132 caster->CastCustomSpell(m_target, 52212, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
7133 return;
7135 // Raise Dead
7136 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000001000))
7137 // return;
7138 // Chains of Ice
7139 if (spell->SpellFamilyFlags & UI64LIT(0x0000400000000000))
7141 // Get 0 effect aura
7142 Aura *slow = m_target->GetAura(GetId(), 0);
7143 if (slow)
7145 slow->ApplyModifier(false, true);
7146 Modifier *mod = slow->GetModifier();
7147 mod->m_amount+= m_modifier.m_amount;
7148 if (mod->m_amount > 0) mod->m_amount = 0;
7149 slow->ApplyModifier(true, true);
7151 return;
7153 // Summon Gargoyle
7154 // if (spell->SpellFamilyFlags & UI64LIT(0x0000008000000000))
7155 // return;
7156 // Death Rune Mastery
7157 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000004000))
7158 // return;
7159 // Bladed Armor
7160 if (spell->SpellIconID == 2653)
7162 // Increases your attack power by $s1 for every $s2 armor value you have.
7163 // Calculate AP bonus (from 1 efect of this spell)
7164 int32 apBonus = m_modifier.m_amount * m_target->GetArmor() / m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7165 m_target->CastCustomSpell(m_target, 61217, &apBonus, &apBonus, NULL, true, NULL, this);
7166 return;
7168 // Reaping
7169 // if (spell->SpellIconID == 22)
7170 // return;
7171 // Blood of the North
7172 // if (spell->SpellIconID == 30412)
7173 // return;
7174 break;
7176 default:
7177 break;
7181 void Aura::HandlePreventFleeing(bool apply, bool Real)
7183 if(!Real)
7184 return;
7186 Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
7187 if( !fearAuras.empty() )
7189 if (apply)
7190 m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
7191 else
7192 m_target->SetFeared(true);
7196 void Aura::HandleManaShield(bool apply, bool Real)
7198 if(!Real)
7199 return;
7201 // prevent double apply bonuses
7202 if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
7204 if(Unit* caster = GetCaster())
7206 float DoneActualBenefit = 0.0f;
7207 switch(m_spellProto->SpellFamilyName)
7209 case SPELLFAMILY_MAGE:
7210 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000008000))
7212 // Mana Shield
7213 // +50% from +spd bonus
7214 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
7215 break;
7217 break;
7218 default:
7219 break;
7222 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
7224 m_modifier.m_amount += (int32)DoneActualBenefit;
7229 void Aura::HandleArenaPreparation(bool apply, bool Real)
7231 if(!Real)
7232 return;
7234 if(apply)
7235 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7236 else
7237 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7241 * Such auras are applied from a caster(=player) to a vehicle.
7242 * This has been verified using spell #49256
7244 void Aura::HandleAuraControlVehicle(bool apply, bool Real)
7246 if(!Real)
7247 return;
7249 Unit *player = GetCaster();
7250 Vehicle *vehicle = dynamic_cast<Vehicle*>(m_target);
7251 if(!player || player->GetTypeId() != TYPEID_PLAYER || !vehicle)
7252 return;
7254 if (apply)
7256 if(Pet *pet = player->GetPet())
7257 pet->Remove(PET_SAVE_AS_CURRENT);
7258 ((Player*)player)->EnterVehicle(vehicle);
7260 else
7262 SpellEntry const *spell = GetSpellProto();
7264 // some SPELL_AURA_CONTROL_VEHICLE auras have a dummy effect on the player - remove them
7265 player->RemoveAurasDueToSpell(spell->Id);
7267 ((Player*)player)->ExitVehicle(vehicle);
7271 void Aura::HandleAuraConvertRune(bool apply, bool Real)
7273 if(!Real)
7274 return;
7276 if(m_target->GetTypeId() != TYPEID_PLAYER)
7277 return;
7279 Player *plr = (Player*)m_target;
7281 if(plr->getClass() != CLASS_DEATH_KNIGHT)
7282 return;
7284 // how to determine what rune need to be converted?
7285 for(uint32 i = 0; i < MAX_RUNES; ++i)
7287 if(apply)
7289 if(!plr->GetRuneCooldown(i))
7291 plr->ConvertRune(i, RuneType(GetSpellProto()->EffectMiscValueB[m_effIndex]));
7292 break;
7295 else
7297 if(plr->GetCurrentRune(i) == RuneType(GetSpellProto()->EffectMiscValueB[m_effIndex]))
7299 plr->ConvertRune(i, plr->GetBaseRune(i));
7300 break;
7306 void Aura::HandlePhase(bool apply, bool Real)
7308 if(!Real)
7309 return;
7311 // always non stackable
7312 if(apply)
7314 Unit::AuraList const& phases = m_target->GetAurasByType(SPELL_AURA_PHASE);
7315 if(!phases.empty())
7316 m_target->RemoveAurasDueToSpell(phases.front()->GetId(), this);
7319 // no-phase is also phase state so same code for apply and remove
7321 // phase auras normally not expected at BG but anyway better check
7322 if(m_target->GetTypeId() == TYPEID_PLAYER)
7324 // drop flag at invisible in bg
7325 if(((Player*)m_target)->InBattleGround())
7326 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
7327 bg->EventPlayerDroppedFlag((Player*)m_target);
7329 // GM-mode have mask 0xFFFFFFFF
7330 if(!((Player*)m_target)->isGameMaster())
7331 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7333 ((Player*)m_target)->GetSession()->SendSetPhaseShift(apply ? GetMiscValue() : PHASEMASK_NORMAL);
7335 if(GetEffIndex()==0)
7337 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
7338 if(saBounds.first != saBounds.second)
7340 uint32 zone, area;
7341 m_target->GetZoneAndAreaId(zone, area);
7343 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
7345 // some auras remove at aura remove
7346 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
7347 m_target->RemoveAurasDueToSpell(itr->second->spellId);
7348 // some auras applied at aura apply
7349 else if(itr->second->autocast)
7351 if( !m_target->HasAura(itr->second->spellId, 0) )
7352 m_target->CastSpell(m_target, itr->second->spellId, true);
7358 else
7359 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7361 // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases)
7362 if(m_target->GetVisibility() != VISIBILITY_OFF)
7363 m_target->SetVisibility(m_target->GetVisibility());
7366 void Aura::UnregisterSingleCastAura()
7368 if (IsSingleTarget())
7370 if(Unit* caster = GetCaster())
7372 caster->GetSingleCastAuras().remove(this);
7374 else
7376 sLog.outError("Couldn't find the caster of the single target aura (SpellId %u), may crash later!", GetId());
7377 assert(false);
7379 m_isSingleTargetAura = false;
7383 void Aura::HandleAuraSafeFall( bool Apply, bool Real )
7385 // implemented in WorldSession::HandleMovementOpcodes
7387 // only special case
7388 if(Apply && Real && GetId() == 32474 && m_target->GetTypeId() == TYPEID_PLAYER)
7389 ((Player*)m_target)->ActivateTaxiPathTo(506, GetId());
7392 bool Aura::IsCritFromAbilityAura(Unit* caster, uint32& damage)
7394 Unit::AuraList const& auras = caster->GetAurasByType(SPELL_AURA_ABILITY_PERIODIC_CRIT);
7395 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
7397 if (!(*itr)->isAffectedOnSpell(m_spellProto))
7398 continue;
7399 if (!caster->isSpellCrit(m_target, m_spellProto, GetSpellSchoolMask(m_spellProto)))
7400 break;
7402 damage = caster->SpellCriticalDamageBonus(m_spellProto, damage, m_target);
7403 return true;
7405 return false;
7408 void Aura::HandleModTargetArmorPct(bool apply, bool Real)
7410 if(m_target->GetTypeId() != TYPEID_PLAYER)
7411 return;
7413 ((Player*)m_target)->UpdateArmorPenetration();
7416 void Aura::HandleAuraModAllCritChance(bool apply, bool Real)
7418 // spells required only Real aura add/remove
7419 if(!Real)
7420 return;
7422 if(m_target->GetTypeId() != TYPEID_PLAYER)
7423 return;
7425 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
7426 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
7427 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
7429 // included in Player::UpdateSpellCritChance calculation
7430 ((Player*)m_target)->UpdateAllSpellCritChances();