Merge branch 'master' into 320
[getmangos.git] / src / game / SpellAuras.cpp
blobe16e532106405c5a85d2d4768a1f415ac6fedeb0
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::HandleUnused, //290 3 spells
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));
465 Aura::~Aura()
469 AreaAura::AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
470 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
472 m_isAreaAura = true;
474 // caster==NULL in constructor args if target==caster in fact
475 Unit* caster_ptr = caster ? caster : target;
477 m_radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
478 if(Player* modOwner = caster_ptr->GetSpellModOwner())
479 modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
481 switch(spellproto->Effect[eff])
483 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
484 m_areaAuraType = AREA_AURA_PARTY;
485 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
486 m_modifier.m_auraname = SPELL_AURA_NONE;
487 break;
488 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
489 m_areaAuraType = AREA_AURA_RAID;
490 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
491 m_modifier.m_auraname = SPELL_AURA_NONE;
492 break;
493 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
494 m_areaAuraType = AREA_AURA_FRIEND;
495 break;
496 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
497 m_areaAuraType = AREA_AURA_ENEMY;
498 if (target == caster_ptr)
499 m_modifier.m_auraname = SPELL_AURA_NONE; // Do not do any effect on self
500 break;
501 case SPELL_EFFECT_APPLY_AREA_AURA_PET:
502 m_areaAuraType = AREA_AURA_PET;
503 break;
504 case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
505 m_areaAuraType = AREA_AURA_OWNER;
506 if (target == caster_ptr)
507 m_modifier.m_auraname = SPELL_AURA_NONE;
508 break;
509 default:
510 sLog.outError("Wrong spell effect in AreaAura constructor");
511 ASSERT(false);
512 break;
516 AreaAura::~AreaAura()
520 PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
521 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
523 m_isPersistent = true;
526 PersistentAreaAura::~PersistentAreaAura()
530 SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
531 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
533 if (caster)
534 m_casters_target_guid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelection() : caster->GetUInt64Value(UNIT_FIELD_TARGET);
535 else
536 m_casters_target_guid = 0;
539 SingleEnemyTargetAura::~SingleEnemyTargetAura()
543 Unit* SingleEnemyTargetAura::GetTriggerTarget() const
545 return ObjectAccessor::GetUnit(*m_target, m_casters_target_guid);
548 Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem)
550 if (IsAreaAuraEffect(spellproto->Effect[eff]))
551 return new AreaAura(spellproto, eff, currentBasePoints, target, caster, castItem);
553 uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff];
555 if(SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
556 for (int i = 0; i < 3; ++i)
557 if (triggeredSpellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_ENEMY)
558 return new SingleEnemyTargetAura(spellproto, eff, currentBasePoints, target, caster, castItem);
560 return new Aura(spellproto, eff, currentBasePoints, target, caster, castItem);
563 Unit* Aura::GetCaster() const
565 if(m_caster_guid==m_target->GetGUID())
566 return m_target;
568 //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
569 //must return caster even if it's in another grid/map
570 Unit *unit = ObjectAccessor::GetObjectInWorld(m_caster_guid, (Unit*)NULL);
571 return unit && unit->IsInWorld() ? unit : NULL;
574 void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
576 m_modifier.m_auraname = t;
577 m_modifier.m_amount = a;
578 m_modifier.m_miscvalue = miscValue;
579 m_modifier.periodictime = pt;
582 void Aura::Update(uint32 diff)
584 if (m_duration > 0)
586 m_duration -= diff;
587 if (m_duration < 0)
588 m_duration = 0;
589 m_timeCla -= diff;
591 // GetEffIndex()==0 prevent double/triple apply manaPerSecond/manaPerSecondPerLevel to same spell with many auras
592 // all spells with manaPerSecond/manaPerSecondPerLevel have aura in effect 0
593 if(GetEffIndex()==0 && m_timeCla <= 0)
595 if(Unit* caster = GetCaster())
597 Powers powertype = Powers(m_spellProto->powerType);
598 int32 manaPerSecond = m_spellProto->manaPerSecond + m_spellProto->manaPerSecondPerLevel * caster->getLevel();
599 m_timeCla = 1*IN_MILISECONDS;
600 if (manaPerSecond)
602 if(powertype==POWER_HEALTH)
603 caster->ModifyHealth(-manaPerSecond);
604 else
605 caster->ModifyPower(powertype,-manaPerSecond);
611 // Channeled aura required check distance from caster
612 if(IsChanneledSpell(m_spellProto) && m_caster_guid != m_target->GetGUID())
614 Unit* caster = GetCaster();
615 if(!caster)
617 m_target->RemoveAura(GetId(), GetEffIndex());
618 return;
621 // Get spell range
622 float radius;
623 SpellModOp mod;
624 if (m_spellProto->EffectRadiusIndex[GetEffIndex()])
626 radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellProto->EffectRadiusIndex[GetEffIndex()]));
627 mod = SPELLMOD_RADIUS;
629 else
631 radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellProto->rangeIndex));
632 mod = SPELLMOD_RANGE;
635 if(Player* modOwner = caster->GetSpellModOwner())
636 modOwner->ApplySpellMod(GetId(), mod, radius, NULL);
638 if(!caster->IsWithinDistInMap(m_target, radius))
640 m_target->RemoveAura(GetId(), GetEffIndex());
641 return;
645 if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
647 m_periodicTimer -= diff;
648 if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
650 // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls)
651 m_periodicTimer += m_modifier.periodictime;
652 PeriodicTick();
657 void AreaAura::Update(uint32 diff)
659 // update for the caster of the aura
660 if(m_caster_guid == m_target->GetGUID())
662 Unit* caster = m_target;
664 if( !caster->hasUnitState(UNIT_STAT_ISOLATED) )
666 Unit* owner = caster->GetCharmerOrOwner();
667 if (!owner)
668 owner = caster;
669 std::list<Unit *> targets;
671 switch(m_areaAuraType)
673 case AREA_AURA_PARTY:
675 Group *pGroup = NULL;
677 if (owner->GetTypeId() == TYPEID_PLAYER)
678 pGroup = ((Player*)owner)->GetGroup();
680 if( pGroup)
682 uint8 subgroup = ((Player*)owner)->GetSubGroup();
683 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
685 Player* Target = itr->getSource();
686 if(Target && Target->isAlive() && Target->GetSubGroup()==subgroup && caster->IsFriendlyTo(Target))
688 if(caster->IsWithinDistInMap(Target, m_radius))
689 targets.push_back(Target);
690 Pet *pet = Target->GetPet();
691 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
692 targets.push_back(pet);
696 else
698 // add owner
699 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
700 targets.push_back(owner);
701 // add caster's pet
702 Unit* pet = caster->GetPet();
703 if( pet && caster->IsWithinDistInMap(pet, m_radius))
704 targets.push_back(pet);
706 break;
708 case AREA_AURA_RAID:
710 Group *pGroup = NULL;
712 if (owner->GetTypeId() == TYPEID_PLAYER)
713 pGroup = ((Player*)owner)->GetGroup();
715 if( pGroup)
717 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
719 Player* Target = itr->getSource();
720 if(Target && Target->isAlive() && caster->IsFriendlyTo(Target))
722 if(caster->IsWithinDistInMap(Target, m_radius))
723 targets.push_back(Target);
724 Pet *pet = Target->GetPet();
725 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
726 targets.push_back(pet);
730 else
732 // add owner
733 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
734 targets.push_back(owner);
735 // add caster's pet
736 Unit* pet = caster->GetPet();
737 if( pet && caster->IsWithinDistInMap(pet, m_radius))
738 targets.push_back(pet);
740 break;
742 case AREA_AURA_FRIEND:
744 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
745 Cell cell(p);
746 cell.data.Part.reserved = ALL_DISTRICT;
747 cell.SetNoCreate();
749 MaNGOS::AnyFriendlyUnitInObjectRangeCheck u_check(caster, owner, m_radius);
750 MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck> searcher(caster,targets, u_check);
751 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
752 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
753 CellLock<GridReadGuard> cell_lock(cell, p);
754 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap());
755 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap());
756 break;
758 case AREA_AURA_ENEMY:
760 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
761 Cell cell(p);
762 cell.data.Part.reserved = ALL_DISTRICT;
763 cell.SetNoCreate();
765 MaNGOS::AnyAoETargetUnitInObjectRangeCheck u_check(caster, owner, m_radius); // No GetCharmer in searcher
766 MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck> searcher(caster, targets, u_check);
767 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
768 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
769 CellLock<GridReadGuard> cell_lock(cell, p);
770 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap());
771 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap());
772 break;
774 case AREA_AURA_OWNER:
775 case AREA_AURA_PET:
777 if(owner != caster)
778 targets.push_back(owner);
779 break;
783 for(std::list<Unit *>::iterator tIter = targets.begin(); tIter != targets.end(); tIter++)
785 if((*tIter)->HasAura(GetId(), m_effIndex))
786 continue;
788 if(SpellEntry const *actualSpellInfo = spellmgr.SelectAuraRankForPlayerLevel(GetSpellProto(), (*tIter)->getLevel()))
790 int32 actualBasePoints = m_currentBasePoints;
791 // recalculate basepoints for lower rank (all AreaAura spell not use custom basepoints?)
792 if(actualSpellInfo != GetSpellProto())
793 actualBasePoints = actualSpellInfo->EffectBasePoints[m_effIndex];
794 AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
795 aur->SetAuraDuration(GetAuraDuration());
796 (*tIter)->AddAura(aur);
800 Aura::Update(diff);
802 else // aura at non-caster
804 Unit* caster = GetCaster();
806 Aura::Update(diff);
808 // remove aura if out-of-range from caster (after teleport for example)
809 // or caster is isolated or caster no longer has the aura
810 // or caster is (no longer) friendly
811 bool needFriendly = (m_areaAuraType == AREA_AURA_ENEMY ? false : true);
812 if( !caster || caster->hasUnitState(UNIT_STAT_ISOLATED) ||
813 !caster->IsWithinDistInMap(m_target, m_radius) ||
814 !caster->HasAura(GetId(), GetEffIndex()) ||
815 caster->IsFriendlyTo(m_target) != needFriendly
818 m_target->RemoveAura(GetId(), GetEffIndex());
820 else if( m_areaAuraType == AREA_AURA_PARTY) // check if in same sub group
822 // not check group if target == owner or target == pet
823 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
825 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
827 Group *pGroup = check ? check->GetGroup() : NULL;
828 if( pGroup )
830 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
831 if(!checkTarget || !pGroup->SameSubGroup(check, checkTarget))
832 m_target->RemoveAura(GetId(), GetEffIndex());
834 else
835 m_target->RemoveAura(GetId(), GetEffIndex());
838 else if( m_areaAuraType == AREA_AURA_RAID) // TODO: fix me!
840 // not check group if target == owner or target == pet
841 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
843 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
845 Group *pGroup = check ? check->GetGroup() : NULL;
846 if( pGroup )
848 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
849 if(!checkTarget)
850 m_target->RemoveAura(GetId(), GetEffIndex());
852 else
853 m_target->RemoveAura(GetId(), GetEffIndex());
856 else if( m_areaAuraType == AREA_AURA_PET || m_areaAuraType == AREA_AURA_OWNER )
858 if( m_target->GetGUID() != caster->GetCharmerOrOwnerGUID() )
859 m_target->RemoveAura(GetId(), GetEffIndex());
864 void PersistentAreaAura::Update(uint32 diff)
866 bool remove = false;
868 // remove the aura if its caster or the dynamic object causing it was removed
869 // or if the target moves too far from the dynamic object
870 if(Unit *caster = GetCaster())
872 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
873 if (dynObj)
875 if (!m_target->IsWithinDistInMap(dynObj, dynObj->GetRadius()))
876 remove = true;
878 else
879 remove = true;
881 else
882 remove = true;
884 Aura::Update(diff);
886 if(remove)
887 m_target->RemoveAura(GetId(), GetEffIndex());
890 void Aura::ApplyModifier(bool apply, bool Real)
892 AuraType aura = m_modifier.m_auraname;
894 SetInUse(true);
895 if(aura < TOTAL_AURAS)
896 (*this.*AuraHandler [aura])(apply, Real);
897 SetInUse(false);
900 void Aura::_AddAura()
902 if (!GetId())
903 return;
904 if(!m_target)
905 return;
907 // Second aura if some spell
908 bool secondaura = false;
909 // Try find slot for aura
910 uint8 slot = NULL_AURA_SLOT;
911 // Lookup for some spell auras (and get slot from it)
912 for(uint8 i = 0; i < m_effIndex; ++i)
914 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
915 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
917 // allow use single slot only by auras from same caster
918 if(itr->second->GetCasterGUID()==GetCasterGUID())
920 slot = itr->second->GetAuraSlot();
921 secondaura = true;
922 break;
925 if (secondaura)
926 break;
928 // Lookup free slot
929 if (!secondaura && m_target->GetVisibleAurasCount() < MAX_AURAS)
931 Unit::VisibleAuraMap const *visibleAuras = m_target->GetVisibleAuras();
932 for(uint8 i = 0; i < MAX_AURAS; ++i)
934 Unit::VisibleAuraMap::const_iterator itr = visibleAuras->find(i);
935 if(itr == visibleAuras->end())
937 slot = i;
938 // update for out of range group members (on 1 slot use)
939 m_target->UpdateAuraForGroup(slot);
940 break;
945 Unit* caster = GetCaster();
947 // set infinity cooldown state for spells
948 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
950 if (m_spellProto->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)
952 Item* castItem = m_castItemGuid ? ((Player*)caster)->GetItemByGuid(m_castItemGuid) : NULL;
953 ((Player*)caster)->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true);
957 // passive auras (except totem auras) do not get placed in the slots
958 // area auras with SPELL_AURA_NONE are not shown on target
959 if((!m_isPassive || (caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem())) &&
960 (m_spellProto->Effect[GetEffIndex()] != SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || m_target != caster))
962 SetAuraSlot( slot );
963 if(slot < MAX_AURAS) // slot found send data to client
965 SetAura(false);
966 SetAuraFlags((1 << GetEffIndex()) | AFLAG_NOT_CASTER | ((GetAuraMaxDuration() > 0) ? AFLAG_DURATION : AFLAG_NONE) | (IsPositive() ? AFLAG_POSITIVE : AFLAG_NEGATIVE));
967 SetAuraLevel(caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
968 SendAuraUpdate(false);
971 //*****************************************************
972 // Update target aura state flag (at 1 aura apply)
973 // TODO: Make it easer
974 //*****************************************************
975 if (!secondaura)
977 // Sitdown on apply aura req seated
978 if (m_spellProto->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED && !m_target->IsSitState())
979 m_target->SetStandState(UNIT_STAND_STATE_SIT);
981 // register aura diminishing on apply
982 if (getDiminishGroup() != DIMINISHING_NONE )
983 m_target->ApplyDiminishingAura(getDiminishGroup(), true);
985 // Update Seals information
986 if (IsSealSpell(m_spellProto))
987 m_target->ModifyAuraState(AURA_STATE_JUDGEMENT, true);
989 // Conflagrate aura state on Immolate and Shadowflame
990 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARLOCK &&
991 // Immolate
992 ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
993 // Shadowflame
994 (m_spellProto->SpellFamilyFlags2 & 0x00000002)))
995 m_target->ModifyAuraState(AURA_STATE_CONFLAGRATE, true);
997 // Faerie Fire (druid versions)
998 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
999 m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE, true);
1001 // Victorious
1002 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARRIOR && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
1003 m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, true);
1005 // Swiftmend state on Regrowth & Rejuvenation
1006 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x50)))
1007 m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, true);
1009 // Deadly poison aura state
1010 if(m_spellProto->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellProto->SpellFamilyFlags & UI64LIT(0x10000)))
1011 m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON, true);
1013 // Enrage aura state
1014 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1015 m_target->ModifyAuraState(AURA_STATE_ENRAGE, true);
1020 bool Aura::_RemoveAura()
1022 // Remove all triggered by aura spells vs unlimited duration
1023 // except same aura replace case
1024 if(m_removeMode!=AURA_REMOVE_BY_STACK)
1025 CleanupTriggeredSpells();
1027 Unit* caster = GetCaster();
1029 if(caster && IsPersistent())
1031 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
1032 if (dynObj)
1033 dynObj->RemoveAffected(m_target);
1036 //passive auras do not get put in slots
1037 // Note: but totem can be not accessible for aura target in time remove (to far for find in grid)
1038 //if(m_isPassive && !(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()))
1039 // return;
1041 uint8 slot = GetAuraSlot();
1043 if(slot >= MAX_AURAS) // slot not set
1044 return false;
1046 if(m_target->GetVisibleAura(slot) == 0)
1047 return false;
1049 bool lastaura = true;
1051 // find other aura in same slot (current already removed from list)
1052 for(uint8 i = 0; i < 3; ++i)
1054 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
1055 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
1057 if(itr->second->GetAuraSlot() == slot)
1059 lastaura = false;
1060 break;
1063 if(!lastaura)
1064 break;
1067 // only remove icon when the last aura of the spell is removed (current aura already removed from list)
1068 if (!lastaura)
1069 return false;
1071 // unregister aura diminishing (and store last time)
1072 if (getDiminishGroup() != DIMINISHING_NONE )
1073 m_target->ApplyDiminishingAura(getDiminishGroup(), false);
1075 SetAura(true);
1076 SetAuraFlags(AFLAG_NONE);
1077 SetAuraLevel(0);
1078 SendAuraUpdate(true);
1080 // update for out of range group members
1081 m_target->UpdateAuraForGroup(slot);
1083 //*****************************************************
1084 // Update target aura state flag (at last aura remove)
1085 //*****************************************************
1086 // Enrage aura state
1087 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1088 m_target->ModifyAuraState(AURA_STATE_ENRAGE, false);
1090 uint32 removeState = 0;
1091 uint64 removeFamilyFlag = m_spellProto->SpellFamilyFlags;
1092 uint32 removeFamilyFlag2 = m_spellProto->SpellFamilyFlags2;
1093 switch(m_spellProto->SpellFamilyName)
1095 case SPELLFAMILY_PALADIN:
1096 if (IsSealSpell(m_spellProto))
1097 removeState = AURA_STATE_JUDGEMENT; // Update Seals information
1098 break;
1099 case SPELLFAMILY_WARLOCK:
1100 // Conflagrate aura state on Immolate and Shadowflame,
1101 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1102 (m_spellProto->SpellFamilyFlags2 & 0x00000002))
1104 removeFamilyFlag = UI64LIT(0x0000000000000004);
1105 removeFamilyFlag2 = 0x00000002;
1106 removeState = AURA_STATE_CONFLAGRATE;
1108 break;
1109 case SPELLFAMILY_DRUID:
1110 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400))
1111 removeState = AURA_STATE_FAERIE_FIRE; // Faerie Fire (druid versions)
1112 else if(m_spellProto->SpellFamilyFlags & UI64LIT(0x50))
1114 removeFamilyFlag = 0x50;
1115 removeState = AURA_STATE_SWIFTMEND; // Swiftmend aura state
1117 break;
1118 case SPELLFAMILY_WARRIOR:
1119 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000))
1120 removeState = AURA_STATE_WARRIOR_VICTORY_RUSH; // Victorious
1121 break;
1122 case SPELLFAMILY_ROGUE:
1123 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x10000))
1124 removeState = AURA_STATE_DEADLY_POISON; // Deadly poison aura state
1125 break;
1126 case SPELLFAMILY_HUNTER:
1127 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
1128 removeState = AURA_STATE_FAERIE_FIRE; // Sting (hunter versions)
1131 // Remove state (but need check other auras for it)
1132 if (removeState)
1134 bool found = false;
1135 Unit::AuraMap& Auras = m_target->GetAuras();
1136 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
1138 SpellEntry const *auraSpellInfo = (*i).second->GetSpellProto();
1139 if(auraSpellInfo->SpellFamilyName == m_spellProto->SpellFamilyName &&
1140 (auraSpellInfo->SpellFamilyFlags & removeFamilyFlag || auraSpellInfo->SpellFamilyFlags2 & removeFamilyFlag2))
1142 found = true;
1143 break;
1146 // this has been last aura
1147 if(!found)
1148 m_target->ModifyAuraState(AuraState(removeState), false);
1151 // reset cooldown state for spells
1152 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1154 if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE )
1155 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
1156 ((Player*)caster)->SendCooldownEvent(GetSpellProto());
1159 return true;
1162 void Aura::SendAuraUpdate(bool remove)
1164 WorldPacket data(SMSG_AURA_UPDATE);
1165 data.append(m_target->GetPackGUID());
1166 data << uint8(GetAuraSlot());
1167 data << uint32(remove ? 0 : GetId());
1169 if(remove)
1171 m_target->SendMessageToSet(&data, true);
1172 return;
1175 uint8 auraFlags = GetAuraFlags();
1176 data << uint8(auraFlags);
1177 data << uint8(GetAuraLevel());
1178 data << uint8(m_procCharges ? m_procCharges*m_stackAmount : m_stackAmount);
1180 if(!(auraFlags & AFLAG_NOT_CASTER))
1182 data << uint8(0); // pguid
1185 if(auraFlags & AFLAG_DURATION)
1187 data << uint32(GetAuraMaxDuration());
1188 data << uint32(GetAuraDuration());
1191 m_target->SendMessageToSet(&data, true);
1194 void Aura::SetStackAmount(uint8 stackAmount)
1196 Unit *target = GetTarget();
1197 Unit *caster = GetCaster();
1198 if (!target || !caster)
1199 return;
1201 bool refresh = stackAmount >= m_stackAmount;
1202 if (stackAmount != m_stackAmount)
1204 m_stackAmount = stackAmount;
1205 int32 amount = m_stackAmount * caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, target);
1206 // Reapply if amount change
1207 if (amount!=m_modifier.m_amount)
1209 ApplyModifier(false, true);
1210 m_modifier.m_amount = amount;
1211 ApplyModifier(true, true);
1215 if (refresh)
1216 // Stack increased refresh duration
1217 RefreshAura();
1218 else
1219 // Stack decreased only send update
1220 SendAuraUpdate(false);
1223 bool Aura::modStackAmount(int32 num)
1225 // Can`t mod
1226 if (!m_spellProto->StackAmount)
1227 return true;
1229 // Modify stack but limit it
1230 int32 stackAmount = m_stackAmount + num;
1231 if (stackAmount > m_spellProto->StackAmount)
1232 stackAmount = m_spellProto->StackAmount;
1233 else if (stackAmount <=0) // Last aura from stack removed
1235 m_stackAmount = 0;
1236 return true; // need remove aura
1239 // Update stack amount
1240 SetStackAmount(stackAmount);
1241 return false;
1244 void Aura::RefreshAura()
1246 m_duration = m_maxduration;
1247 SendAuraUpdate(false);
1250 bool Aura::isAffectedOnSpell(SpellEntry const *spell) const
1252 // Check family name
1253 if (spell->SpellFamilyName != m_spellProto->SpellFamilyName)
1254 return false;
1255 // Check EffectClassMask
1256 uint32 const *ptr = getAuraSpellClassMask();
1257 if (((uint64*)ptr)[0] & spell->SpellFamilyFlags)
1258 return true;
1259 if (ptr[2] & spell->SpellFamilyFlags2)
1260 return true;
1261 return false;
1264 void Aura::ReapplyAffectedPassiveAuras( Unit* target )
1266 std::set<uint32> affectedPassives;
1268 for(Unit::AuraMap::const_iterator itr = target->GetAuras().begin(); itr != target->GetAuras().end(); ++itr)
1270 // permanent passive
1271 if (itr->second->IsPassive() && itr->second->IsPermanent() &&
1272 // non deleted and not same aura (any with same spell id)
1273 !itr->second->IsDeleted() && itr->second->GetId() != GetId() &&
1274 // only applied by self and affected by aura
1275 itr->second->GetCasterGUID() == target->GetGUID() && isAffectedOnSpell(itr->second->GetSpellProto()))
1277 affectedPassives.insert(itr->second->GetId());
1281 for(std::set<uint32>::const_iterator set_itr = affectedPassives.begin(); set_itr != affectedPassives.end(); ++set_itr)
1283 target->RemoveAurasDueToSpell(*set_itr);
1284 target->CastSpell(m_target, *set_itr, true);
1288 /*********************************************************/
1289 /*** BASIC AURA FUNCTION ***/
1290 /*********************************************************/
1291 void Aura::HandleAddModifier(bool apply, bool Real)
1293 if(m_target->GetTypeId() != TYPEID_PLAYER || !Real)
1294 return;
1296 if(m_modifier.m_miscvalue >= MAX_SPELLMOD)
1297 return;
1299 if (apply)
1301 // Add custom charges for some mod aura
1302 switch (m_spellProto->Id)
1304 case 17941: // Shadow Trance
1305 case 22008: // Netherwind Focus
1306 case 31834: // Light's Grace
1307 case 34754: // Clearcasting
1308 case 34936: // Backlash
1309 case 48108: // Hot Streak
1310 case 51124: // Killing Machine
1311 case 54741: // Firestarter
1312 case 57761: // Fireball!
1313 SetAuraCharges(1);
1314 break;
1317 SpellModifier *mod = new SpellModifier;
1318 mod->op = SpellModOp(m_modifier.m_miscvalue);
1319 mod->value = m_modifier.m_amount;
1320 mod->type = SpellModType(m_modifier.m_auraname); // SpellModType value == spell aura types
1321 mod->spellId = GetId();
1323 uint32 const *ptr;
1324 switch (m_effIndex)
1326 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1327 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1328 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1329 default:
1330 return;
1333 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1334 mod->mask2= (uint64)ptr[2];
1335 mod->charges = m_procCharges;
1337 m_spellmod = mod;
1340 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
1342 // reapply talents to own passive persistent auras
1343 ReapplyAffectedPassiveAuras(m_target);
1345 // re-aplly talents and passives applied to pet (it affected by player spellmods)
1346 if(Pet* pet = m_target->GetPet())
1347 ReapplyAffectedPassiveAuras(pet);
1349 for(int i = 0; i < MAX_TOTEM; ++i)
1350 if(m_target->m_TotemSlot[i])
1351 if(Creature* totem = m_target->GetMap()->GetCreature(m_target->m_TotemSlot[i]))
1352 ReapplyAffectedPassiveAuras(totem);
1354 void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
1356 // Use SpellModifier structure for check
1357 // used only fields:
1358 // spellId, mask, mask2
1359 if (apply)
1361 SpellModifier *mod = new SpellModifier;
1362 mod->spellId = GetId();
1364 uint32 const *ptr;
1365 switch (m_effIndex)
1367 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1368 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1369 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1370 default:
1371 return;
1374 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1375 mod->mask2= (uint64)ptr[2];
1376 m_spellmod = mod;
1378 else
1380 delete m_spellmod;
1381 m_spellmod = NULL;
1385 void Aura::TriggerSpell()
1387 Unit* caster = GetCaster();
1388 Unit* target = GetTriggerTarget();
1390 if(!caster || !target)
1391 return;
1393 // generic casting code with custom spells and target/caster customs
1394 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
1396 SpellEntry const *triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1397 SpellEntry const *auraSpellInfo = GetSpellProto();
1398 uint32 auraId = auraSpellInfo->Id;
1400 // specific code for cases with no trigger spell provided in field
1401 if (triggeredSpellInfo == NULL)
1403 switch(auraSpellInfo->SpellFamilyName)
1405 case SPELLFAMILY_GENERIC:
1407 switch(auraId)
1409 // Firestone Passive (1-5 ranks)
1410 case 758:
1411 case 17945:
1412 case 17947:
1413 case 17949:
1414 case 27252:
1416 if (caster->GetTypeId()!=TYPEID_PLAYER)
1417 return;
1418 Item* item = ((Player*)caster)->GetWeaponForAttack(BASE_ATTACK);
1419 if (!item)
1420 return;
1421 uint32 enchant_id = 0;
1422 switch (GetId())
1424 case 758: enchant_id = 1803; break; // Rank 1
1425 case 17945: enchant_id = 1823; break; // Rank 2
1426 case 17947: enchant_id = 1824; break; // Rank 3
1427 case 17949: enchant_id = 1825; break; // Rank 4
1428 case 27252: enchant_id = 2645; break; // Rank 5
1429 default:
1430 return;
1432 // remove old enchanting before applying new
1433 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1434 item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
1435 // add new enchanting
1436 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
1437 return;
1439 // // Periodic Mana Burn
1440 // case 812: break;
1441 // // Polymorphic Ray
1442 // case 6965: break;
1443 // // Fire Nova (1-7 ranks)
1444 // case 8350:
1445 // case 8508:
1446 // case 8509:
1447 // case 11312:
1448 // case 11313:
1449 // case 25540:
1450 // case 25544:
1451 // break;
1452 // Thaumaturgy Channel
1453 case 9712: trigger_spell_id = 21029; break;
1454 // // Egan's Blaster
1455 // case 17368: break;
1456 // // Haunted
1457 // case 18347: break;
1458 // // Ranshalla Waiting
1459 // case 18953: break;
1460 // // Inferno
1461 // case 19695: break;
1462 // // Frostwolf Muzzle DND
1463 // case 21794: break;
1464 // // Alterac Ram Collar DND
1465 // case 21866: break;
1466 // // Celebras Waiting
1467 // case 21916: break;
1468 // Brood Affliction: Bronze
1469 case 23170:
1471 m_target->CastSpell(m_target, 23171, true, 0, this);
1472 return;
1474 // // Mark of Frost
1475 // case 23184: break;
1476 // Restoration
1477 case 23493:
1479 int32 heal = caster->GetMaxHealth() / 10;
1480 caster->DealHeal(caster, heal, auraSpellInfo);
1482 int32 mana = caster->GetMaxPower(POWER_MANA);
1483 if (mana)
1485 mana /= 10;
1486 caster->EnergizeBySpell(caster, 23493, mana, POWER_MANA);
1488 return;
1490 // // Stoneclaw Totem Passive TEST
1491 // case 23792: break;
1492 // // Axe Flurry
1493 // case 24018: break;
1494 // // Mark of Arlokk
1495 // case 24210: break;
1496 // // Restoration
1497 // case 24379: break;
1498 // // Happy Pet
1499 // case 24716: break;
1500 // // Dream Fog
1501 // case 24780: break;
1502 // // Cannon Prep
1503 // case 24832: break;
1504 // // Shadow Bolt Whirl
1505 // case 24834: break;
1506 // // Stink Trap
1507 // case 24918: break;
1508 // // Mark of Nature
1509 // case 25041: break;
1510 // // Agro Drones
1511 // case 25152: break;
1512 // // Consume
1513 // case 25371: break;
1514 // // Pain Spike
1515 // case 25572: break;
1516 // // Rotate 360
1517 // case 26009: break;
1518 // // Rotate -360
1519 // case 26136: break;
1520 // // Consume
1521 // case 26196: break;
1522 // // Berserk
1523 // case 26615: break;
1524 // // Defile
1525 // case 27177: break;
1526 // // Teleport: IF/UC
1527 // case 27601: break;
1528 // // Five Fat Finger Exploding Heart Technique
1529 // case 27673: break;
1530 // // Nitrous Boost
1531 // case 27746: break;
1532 // // Steam Tank Passive
1533 // case 27747: break;
1534 // Frost Blast
1535 case 27808:
1537 int32 bpDamage = target->GetMaxHealth()*26/100;
1538 caster->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this);
1539 return;
1541 // // Detonate Mana
1542 // case 27819: break;
1543 // // Controller Timer
1544 // case 28095: break;
1545 // // Stalagg Chain
1546 // case 28096: break;
1547 // // Stalagg Tesla Passive
1548 // case 28097: break;
1549 // // Feugen Tesla Passive
1550 // case 28109: break;
1551 // // Feugen Chain
1552 // case 28111: break;
1553 // // Mark of Didier
1554 // case 28114: break;
1555 // // Communique Timer, camp
1556 // case 28346: break;
1557 // // Icebolt
1558 // case 28522: break;
1559 // // Silithyst
1560 // case 29519: break;
1561 // Inoculate Nestlewood Owlkin
1562 case 29528:
1563 if(target->GetTypeId() != TYPEID_UNIT)// prevent error reports in case ignored player target
1564 return;
1565 break;
1566 // // Overload
1567 // case 29768: break;
1568 // // Return Fire
1569 // case 29788: break;
1570 // // Return Fire
1571 // case 29793: break;
1572 // // Return Fire
1573 // case 29794: break;
1574 // // Guardian of Icecrown Passive
1575 // case 29897: break;
1576 // Feed Captured Animal
1577 case 29917: trigger_spell_id = 29916; break;
1578 // // Flame Wreath
1579 // case 29946: break;
1580 // // Flame Wreath
1581 // case 29947: break;
1582 // // Mind Exhaustion Passive
1583 // case 30025: break;
1584 // // Nether Beam - Serenity
1585 // case 30401: break;
1586 // Extract Gas
1587 case 30427:
1589 // move loot to player inventory and despawn target
1590 if(caster->GetTypeId() ==TYPEID_PLAYER &&
1591 target->GetTypeId() == TYPEID_UNIT &&
1592 ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
1594 Player* player = (Player*)caster;
1595 Creature* creature = (Creature*)target;
1596 // missing lootid has been reported on startup - just return
1597 if (!creature->GetCreatureInfo()->SkinLootId)
1598 return;
1600 player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true);
1602 creature->ForcedDespawn();
1604 return;
1606 // Quake
1607 case 30576: trigger_spell_id = 30571; break;
1608 // // Burning Maul
1609 // case 30598: break;
1610 // // Regeneration
1611 // case 30799:
1612 // case 30800:
1613 // case 30801:
1614 // break;
1615 // // Despawn Self - Smoke cloud
1616 // case 31269: break;
1617 // // Time Rift Periodic
1618 // case 31320: break;
1619 // // Corrupt Medivh
1620 // case 31326: break;
1621 // Doom
1622 case 31347:
1624 m_target->CastSpell(m_target,31350,true);
1625 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
1626 return;
1628 // Spellcloth
1629 case 31373:
1631 // Summon Elemental after create item
1632 caster->SummonCreature(17870, 0, 0, 0, caster->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
1633 return;
1635 // // Bloodmyst Tesla
1636 // case 31611: break;
1637 // // Doomfire
1638 // case 31944: break;
1639 // // Teleport Test
1640 // case 32236: break;
1641 // // Earthquake
1642 // case 32686: break;
1643 // // Possess
1644 // case 33401: break;
1645 // // Draw Shadows
1646 // case 33563: break;
1647 // // Murmur's Touch
1648 // case 33711: break;
1649 // Flame Quills
1650 case 34229:
1652 // cast 24 spells 34269-34289, 34314-34316
1653 for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
1654 caster->CastSpell(m_target, spell_id, true);
1655 for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
1656 caster->CastSpell(m_target, spell_id, true);
1657 return;
1659 // // Gravity Lapse
1660 // case 34480: break;
1661 // // Tornado
1662 // case 34683: break;
1663 // // Frostbite Rotate
1664 // case 34748: break;
1665 // // Arcane Flurry
1666 // case 34821: break;
1667 // // Interrupt Shutdown
1668 // case 35016: break;
1669 // // Interrupt Shutdown
1670 // case 35176: break;
1671 // // Inferno
1672 // case 35268: break;
1673 // // Salaadin's Tesla
1674 // case 35515: break;
1675 // // Ethereal Channel (Red)
1676 // case 35518: break;
1677 // // Nether Vapor
1678 // case 35879: break;
1679 // // Dark Portal Storm
1680 // case 36018: break;
1681 // // Burning Maul
1682 // case 36056: break;
1683 // // Living Grove Defender Lifespan
1684 // case 36061: break;
1685 // // Professor Dabiri Talks
1686 // case 36064: break;
1687 // // Kael Gaining Power
1688 // case 36091: break;
1689 // // They Must Burn Bomb Aura
1690 // case 36344: break;
1691 // // They Must Burn Bomb Aura (self)
1692 // case 36350: break;
1693 // // Stolen Ravenous Ravager Egg
1694 // case 36401: break;
1695 // // Activated Cannon
1696 // case 36410: break;
1697 // // Stolen Ravenous Ravager Egg
1698 // case 36418: break;
1699 // // Enchanted Weapons
1700 // case 36510: break;
1701 // // Cursed Scarab Periodic
1702 // case 36556: break;
1703 // // Cursed Scarab Despawn Periodic
1704 // case 36561: break;
1705 // // Vision Guide
1706 // case 36573: break;
1707 // // Cannon Charging (platform)
1708 // case 36785: break;
1709 // // Cannon Charging (self)
1710 // case 36860: break;
1711 // Remote Toy
1712 case 37027: trigger_spell_id = 37029; break;
1713 // // Mark of Death
1714 // case 37125: break;
1715 // // Arcane Flurry
1716 // case 37268: break;
1717 // // Spout
1718 // case 37429: break;
1719 // // Spout
1720 // case 37430: break;
1721 // // Karazhan - Chess NPC AI, Snapshot timer
1722 // case 37440: break;
1723 // // Karazhan - Chess NPC AI, action timer
1724 // case 37504: break;
1725 // // Karazhan - Chess: Is Square OCCUPIED aura (DND)
1726 // case 39400: break;
1727 // // Banish
1728 // case 37546: break;
1729 // // Shriveling Gaze
1730 // case 37589: break;
1731 // // Fake Aggro Radius (2 yd)
1732 // case 37815: break;
1733 // // Corrupt Medivh
1734 // case 37853: break;
1735 // Eye of Grillok
1736 case 38495:
1738 m_target->CastSpell(m_target, 38530, true);
1739 return;
1741 // Absorb Eye of Grillok (Zezzak's Shard)
1742 case 38554:
1744 if(m_target->GetTypeId() != TYPEID_UNIT)
1745 return;
1747 caster->CastSpell(caster, 38495, true);
1749 Creature* creatureTarget = (Creature*)m_target;
1751 creatureTarget->ForcedDespawn();
1752 return;
1754 // // Magic Sucker Device timer
1755 // case 38672: break;
1756 // // Tomb Guarding Charging
1757 // case 38751: break;
1758 // // Murmur's Touch
1759 // case 38794: break;
1760 // // Activate Nether-wraith Beacon (31742 Nether-wraith Beacon item)
1761 // case 39105: break;
1762 // // Drain World Tree Visual
1763 // case 39140: break;
1764 // // Quest - Dustin's Undead Dragon Visual aura
1765 // case 39259: break;
1766 // // Hellfire - The Exorcism, Jules releases darkness, aura
1767 // case 39306: break;
1768 // // Inferno
1769 // case 39346: break;
1770 // // Enchanted Weapons
1771 // case 39489: break;
1772 // // Shadow Bolt Whirl
1773 // case 39630: break;
1774 // // Shadow Bolt Whirl
1775 // case 39634: break;
1776 // // Shadow Inferno
1777 // case 39645: break;
1778 // Tear of Azzinoth Summon Channel - it's not really supposed to do anything,and this only prevents the console spam
1779 case 39857: trigger_spell_id = 39856; break;
1780 // // Soulgrinder Ritual Visual (Smashed)
1781 // case 39974: break;
1782 // // Simon Game Pre-game timer
1783 // case 40041: break;
1784 // // Knockdown Fel Cannon: The Aggro Check Aura
1785 // case 40113: break;
1786 // // Spirit Lance
1787 // case 40157: break;
1788 // // Demon Transform 2
1789 // case 40398: break;
1790 // // Demon Transform 1
1791 // case 40511: break;
1792 // // Ancient Flames
1793 // case 40657: break;
1794 // // Ethereal Ring Cannon: Cannon Aura
1795 // case 40734: break;
1796 // // Cage Trap
1797 // case 40760: break;
1798 // // Random Periodic
1799 // case 40867: break;
1800 // // Prismatic Shield
1801 // case 40879: break;
1802 // // Aura of Desire
1803 // case 41350: break;
1804 // // Dementia
1805 // case 41404: break;
1806 // // Chaos Form
1807 // case 41629: break;
1808 // // Alert Drums
1809 // case 42177: break;
1810 // // Spout
1811 // case 42581: break;
1812 // // Spout
1813 // case 42582: break;
1814 // // Return to the Spirit Realm
1815 // case 44035: break;
1816 // // Curse of Boundless Agony
1817 // case 45050: break;
1818 // // Earthquake
1819 // case 46240: break;
1820 // Personalized Weather
1821 case 46736: trigger_spell_id = 46737; break;
1822 // // Stay Submerged
1823 // case 46981: break;
1824 // // Dragonblight Ram
1825 // case 47015: break;
1826 // // Party G.R.E.N.A.D.E.
1827 // case 51510: break;
1828 default:
1829 break;
1831 break;
1833 case SPELLFAMILY_MAGE:
1835 switch(auraId)
1837 // Invisibility
1838 case 66:
1839 // Here need periodic triger reducing threat spell (or do it manually)
1840 return;
1841 default:
1842 break;
1844 break;
1846 // case SPELLFAMILY_WARRIOR:
1847 // {
1848 // switch(auraId)
1849 // {
1850 // // Wild Magic
1851 // case 23410: break;
1852 // // Corrupted Totems
1853 // case 23425: break;
1854 // default:
1855 // break;
1856 // }
1857 // break;
1858 // }
1859 // case SPELLFAMILY_PRIEST:
1860 // {
1861 // switch(auraId)
1862 // {
1863 // // Blue Beam
1864 // case 32930: break;
1865 // // Fury of the Dreghood Elders
1866 // case 35460: break;
1867 // default:
1868 // break;
1869 // }
1870 // break;
1871 // }
1872 case SPELLFAMILY_HUNTER:
1874 switch (auraId)
1876 // Sniper training
1877 case 53302:
1878 case 53303:
1879 case 53304:
1880 if (target->GetTypeId() != TYPEID_PLAYER)
1881 return;
1883 // Reset reapply counter at move
1884 if (((Player*)target)->isMoving())
1886 m_modifier.m_amount = 6;
1887 return;
1890 // We are standing at the moment
1891 if (m_modifier.m_amount > 0)
1893 --m_modifier.m_amount;
1894 return;
1897 // select rank of buff
1898 switch(auraId)
1900 case 53302: trigger_spell_id = 64418; break;
1901 case 53303: trigger_spell_id = 64419; break;
1902 case 53304: trigger_spell_id = 64420; break;
1905 // If aura is active - no need to continue
1906 if (target->HasAura(trigger_spell_id))
1907 return;
1909 break;
1910 default:
1911 break;
1913 break;
1915 case SPELLFAMILY_DRUID:
1917 switch(auraId)
1919 // Cat Form
1920 // trigger_spell_id not set and unknown effect triggered in this case, ignoring for while
1921 case 768:
1922 return;
1923 // Frenzied Regeneration
1924 case 22842:
1925 case 22895:
1926 case 22896:
1927 case 26999:
1929 int32 LifePerRage = GetModifier()->m_amount;
1931 int32 lRage = m_target->GetPower(POWER_RAGE);
1932 if(lRage > 100) // rage stored as rage*10
1933 lRage = 100;
1934 m_target->ModifyPower(POWER_RAGE, -lRage);
1935 int32 FRTriggerBasePoints = int32(lRage*LifePerRage/10);
1936 m_target->CastCustomSpell(m_target, 22845, &FRTriggerBasePoints, NULL, NULL, true, NULL, this);
1937 return;
1939 default:
1940 break;
1942 break;
1945 // case SPELLFAMILY_HUNTER:
1946 // {
1947 // switch(auraId)
1948 // {
1949 // //Frost Trap Aura
1950 // case 13810:
1951 // return;
1952 // //Rizzle's Frost Trap
1953 // case 39900:
1954 // return;
1955 // // Tame spells
1956 // case 19597: // Tame Ice Claw Bear
1957 // case 19676: // Tame Snow Leopard
1958 // case 19677: // Tame Large Crag Boar
1959 // case 19678: // Tame Adult Plainstrider
1960 // case 19679: // Tame Prairie Stalker
1961 // case 19680: // Tame Swoop
1962 // case 19681: // Tame Dire Mottled Boar
1963 // case 19682: // Tame Surf Crawler
1964 // case 19683: // Tame Armored Scorpid
1965 // case 19684: // Tame Webwood Lurker
1966 // case 19685: // Tame Nightsaber Stalker
1967 // case 19686: // Tame Strigid Screecher
1968 // case 30100: // Tame Crazed Dragonhawk
1969 // case 30103: // Tame Elder Springpaw
1970 // case 30104: // Tame Mistbat
1971 // case 30647: // Tame Barbed Crawler
1972 // case 30648: // Tame Greater Timberstrider
1973 // case 30652: // Tame Nightstalker
1974 // return;
1975 // default:
1976 // break;
1977 // }
1978 // break;
1979 // }
1980 case SPELLFAMILY_SHAMAN:
1982 switch(auraId)
1984 // Lightning Shield (The Earthshatterer set trigger after cast Lighting Shield)
1985 case 28820:
1987 // Need remove self if Lightning Shield not active
1988 Unit::AuraMap const& auras = target->GetAuras();
1989 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1991 SpellEntry const* spell = itr->second->GetSpellProto();
1992 if( spell->SpellFamilyName == SPELLFAMILY_SHAMAN &&
1993 (spell->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
1994 return;
1996 target->RemoveAurasDueToSpell(28820);
1997 return;
1999 // Totemic Mastery (Skyshatter Regalia (Shaman Tier 6) - bonus)
2000 case 38443:
2002 bool all = true;
2003 for(int i = 0; i < MAX_TOTEM; ++i)
2005 if(!caster->m_TotemSlot[i])
2007 all = false;
2008 break;
2012 if(all)
2013 caster->CastSpell(caster, 38437, true);
2014 else
2015 caster->RemoveAurasDueToSpell(38437);
2016 return;
2018 default:
2019 break;
2021 break;
2023 default:
2024 break;
2027 // Reget trigger spell proto
2028 triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
2030 else
2032 // Spell exist but require custom code
2033 switch(auraId)
2035 // Curse of Idiocy
2036 case 1010:
2038 // TODO: spell casted by result in correct way mostly
2039 // BUT:
2040 // 1) target show casting at each triggered cast: target don't must show casting animation for any triggered spell
2041 // but must show affect apply like item casting
2042 // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
2044 // prevent cast by triggered auras
2045 if(m_caster_guid == m_target->GetGUID())
2046 return;
2048 // stop triggering after each affected stats lost > 90
2049 int32 intelectLoss = 0;
2050 int32 spiritLoss = 0;
2052 Unit::AuraList const& mModStat = m_target->GetAurasByType(SPELL_AURA_MOD_STAT);
2053 for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
2055 if ((*i)->GetId() == 1010)
2057 switch((*i)->GetModifier()->m_miscvalue)
2059 case STAT_INTELLECT: intelectLoss += (*i)->GetModifier()->m_amount; break;
2060 case STAT_SPIRIT: spiritLoss += (*i)->GetModifier()->m_amount; break;
2061 default: break;
2066 if(intelectLoss <= -90 && spiritLoss <= -90)
2067 return;
2069 caster = target;
2070 break;
2072 // Mana Tide
2073 case 16191:
2075 caster->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
2076 return;
2078 // Ground Slam
2079 case 33525:
2080 target->CastSpell(target, trigger_spell_id, true);
2081 return;
2085 // All ok cast by default case
2086 if(triggeredSpellInfo)
2087 caster->CastSpell(target, triggeredSpellInfo, true, 0, this);
2088 else if(target->GetTypeId()!=TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target))
2089 sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
2092 void Aura::TriggerSpellWithValue()
2094 Unit* caster = GetCaster();
2095 Unit* target = GetTriggerTarget();
2097 if(!caster || !target)
2098 return;
2100 // generic casting code with custom spells and target/caster customs
2101 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
2102 int32 basepoints0 = this->GetModifier()->m_amount;
2104 caster->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this);
2107 /*********************************************************/
2108 /*** AURA EFFECTS ***/
2109 /*********************************************************/
2111 void Aura::HandleAuraDummy(bool apply, bool Real)
2113 // spells required only Real aura add/remove
2114 if(!Real)
2115 return;
2117 Unit* caster = GetCaster();
2119 // AT APPLY
2120 if(apply)
2122 switch(GetId())
2124 case 1515: // Tame beast
2125 // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
2126 if( caster && m_target->CanHaveThreatList())
2127 m_target->AddThreat(caster, 10.0f);
2128 return;
2129 case 13139: // net-o-matic
2130 // root to self part of (root_target->charge->root_self sequence
2131 if(caster)
2132 caster->CastSpell(caster, 13138, true, NULL, this);
2133 return;
2134 case 39850: // Rocket Blast
2135 if(roll_chance_i(20)) // backfire stun
2136 m_target->CastSpell(m_target, 51581, true, NULL, this);
2137 return;
2138 case 43873: // Headless Horseman Laugh
2139 m_target->PlayDistanceSound(11965);
2140 return;
2141 case 46354: // Blood Elf Illusion
2142 if(caster)
2144 switch(caster->getGender())
2146 case GENDER_FEMALE:
2147 caster->CastSpell(m_target, 46356, true, NULL, this);
2148 break;
2149 case GENDER_MALE:
2150 caster->CastSpell(m_target, 46355, true, NULL, this);
2151 break;
2152 default:
2153 break;
2156 return;
2157 case 46699: // Requires No Ammo
2158 if(m_target->GetTypeId() == TYPEID_PLAYER)
2159 ((Player*)m_target)->RemoveAmmo(); // not use ammo and not allow use
2160 return;
2163 // Earth Shield
2164 if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x40000000000)))
2166 // prevent double apply bonuses
2167 if(m_target->GetTypeId() != TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2168 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2169 return;
2172 // AT REMOVE
2173 else
2175 if( m_target->GetTypeId() == TYPEID_PLAYER &&
2176 ( GetSpellProto()->Effect[0]==72 || GetSpellProto()->Effect[0]==6 &&
2177 ( GetSpellProto()->EffectApplyAuraName[0]==1 || GetSpellProto()->EffectApplyAuraName[0]==128 ) ) )
2179 // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
2180 ((Player*)m_target)->SetFarSightGUID(0);
2181 WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0);
2182 ((Player*)m_target)->GetSession()->SendPacket(&data);
2183 return;
2186 if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
2188 uint32 finalSpelId = 0;
2189 switch(GetId())
2191 case 19548: finalSpelId = 19597; break;
2192 case 19674: finalSpelId = 19677; break;
2193 case 19687: finalSpelId = 19676; break;
2194 case 19688: finalSpelId = 19678; break;
2195 case 19689: finalSpelId = 19679; break;
2196 case 19692: finalSpelId = 19680; break;
2197 case 19693: finalSpelId = 19684; break;
2198 case 19694: finalSpelId = 19681; break;
2199 case 19696: finalSpelId = 19682; break;
2200 case 19697: finalSpelId = 19683; break;
2201 case 19699: finalSpelId = 19685; break;
2202 case 19700: finalSpelId = 19686; break;
2203 case 30646: finalSpelId = 30647; break;
2204 case 30653: finalSpelId = 30648; break;
2205 case 30654: finalSpelId = 30652; break;
2206 case 30099: finalSpelId = 30100; break;
2207 case 30102: finalSpelId = 30103; break;
2208 case 30105: finalSpelId = 30104; break;
2211 if(finalSpelId)
2212 caster->CastSpell(m_target, finalSpelId, true, NULL, this);
2213 return;
2216 switch(GetId())
2218 case 2584: // Waiting to Resurrect
2220 // Waiting to resurrect spell cancel, we must remove player from resurrect queue
2221 if(m_target->GetTypeId() == TYPEID_PLAYER)
2222 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
2223 bg->RemovePlayerFromResurrectQueue(m_target->GetGUID());
2224 return;
2226 case 36730: // Flame Strike
2228 m_target->CastSpell(m_target, 36731, true, NULL, this);
2229 return;
2231 case 44191: // Flame Strike
2233 if (m_target->GetMap()->IsDungeon())
2235 uint32 spellId = m_target->GetMap()->IsHeroic() ? 46163 : 44190;
2237 m_target->CastSpell(m_target, spellId, true, NULL, this);
2239 return;
2241 case 45934: // Dark Fiend
2243 // Kill target if dispelled
2244 if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2245 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2246 return;
2248 case 46308: // Burning Winds
2250 // casted only at creatures at spawn
2251 m_target->CastSpell(m_target, 47287, true, NULL, this);
2252 return;
2256 if (caster && m_removeMode == AURA_REMOVE_BY_DEATH)
2258 // Stop caster Arcane Missle chanelling on death
2259 if (m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE &&
2260 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000800)))
2262 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2263 return;
2265 // Stop caster Penance chanelling on death
2266 if (m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST &&
2267 (m_spellProto->SpellFamilyFlags2 & UI64LIT(0x00000080)))
2269 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2270 return;
2276 // AT APPLY & REMOVE
2278 switch(m_spellProto->SpellFamilyName)
2280 case SPELLFAMILY_GENERIC:
2282 switch(GetId())
2284 // Recently Bandaged
2285 case 11196:
2286 m_target->ApplySpellImmune(GetId(), IMMUNITY_MECHANIC, GetMiscValue(), apply);
2287 return;
2288 // Unstable Power
2289 case 24658:
2291 uint32 spellId = 24659;
2292 if (apply && caster)
2294 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2295 if (!spell)
2296 return;
2298 for (int i=0; i < spell->StackAmount; ++i)
2299 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2300 return;
2302 m_target->RemoveAurasDueToSpell(spellId);
2303 return;
2305 // Restless Strength
2306 case 24661:
2308 uint32 spellId = 24662;
2309 if (apply && caster)
2311 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2312 if (!spell)
2313 return;
2314 for (int i=0; i < spell->StackAmount; ++i)
2315 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2316 return;
2318 m_target->RemoveAurasDueToSpell(spellId);
2319 return;
2321 //Summon Fire Elemental
2322 case 40133:
2324 if (!caster)
2325 return;
2327 Unit *owner = caster->GetOwner();
2328 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2330 if(apply)
2331 owner->CastSpell(owner, 8985, true);
2332 else
2333 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2335 return;
2337 //Summon Earth Elemental
2338 case 40132 :
2340 if (!caster)
2341 return;
2343 Unit *owner = caster->GetOwner();
2344 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2346 if(apply)
2347 owner->CastSpell(owner, 19704, true);
2348 else
2349 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2351 return;
2353 //Dragonmaw Illusion
2354 case 40214 :
2356 if(apply)
2358 m_target->CastSpell(m_target, 40216, true);
2359 m_target->CastSpell(m_target, 42016, true);
2361 else
2363 m_target->RemoveAurasDueToSpell(40216);
2364 m_target->RemoveAurasDueToSpell(42016);
2366 return;
2368 // LK Intro VO (1)
2369 case 58204:
2370 if(m_target->GetTypeId() == TYPEID_PLAYER)
2372 // Play part 1
2373 if(apply)
2374 m_target->PlayDirectSound(14970, (Player *)m_target);
2375 // continue in 58205
2376 else
2377 m_target->CastSpell(m_target, 58205, true);
2379 return;
2380 // LK Intro VO (2)
2381 case 58205:
2382 if(m_target->GetTypeId() == TYPEID_PLAYER)
2384 // Play part 2
2385 if(apply)
2386 m_target->PlayDirectSound(14971, (Player *)m_target);
2387 // Play part 3
2388 else
2389 m_target->PlayDirectSound(14972, (Player *)m_target);
2391 return;
2393 break;
2395 case SPELLFAMILY_MAGE:
2397 break;
2399 case SPELLFAMILY_PRIEST:
2401 // Pain and Suffering
2402 if( m_spellProto->SpellIconID == 2874 && m_target->GetTypeId()==TYPEID_PLAYER )
2404 if(apply)
2406 // Reduce backfire damage (dot damage) from Shadow Word: Death
2407 SpellModifier *mod = new SpellModifier;
2408 mod->op = SPELLMOD_DOT;
2409 mod->value = m_modifier.m_amount;
2410 mod->type = SPELLMOD_PCT;
2411 mod->spellId = GetId();
2412 mod->mask = UI64LIT(0x0000200000000000);
2413 mod->mask2= UI64LIT(0x0);
2414 m_spellmod = mod;
2416 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2417 return;
2419 break;
2421 case SPELLFAMILY_DRUID:
2423 switch(GetId())
2425 case 34246: // Idol of the Emerald Queen
2426 case 60779: // Idol of Lush Moss
2428 if (m_target->GetTypeId() != TYPEID_PLAYER)
2429 return;
2431 if(apply)
2433 SpellModifier *mod = new SpellModifier;
2434 mod->op = SPELLMOD_DOT;
2435 mod->value = m_modifier.m_amount/7;
2436 mod->type = SPELLMOD_FLAT;
2437 mod->spellId = GetId();
2438 mod->mask = UI64LIT(0x001000000000);
2439 mod->mask2= UI64LIT(0x0);
2441 m_spellmod = mod;
2444 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2445 return;
2447 case 52610: // Savage Roar
2449 if(apply)
2451 if(m_target->m_form != FORM_CAT)
2452 return;
2454 m_target->CastSpell(m_target, 62071, true);
2456 else
2457 m_target-> RemoveAurasDueToSpell(62071);
2458 return;
2460 case 61336: // Survival Instincts
2462 if(apply)
2464 if (!m_target->IsInFeralForm())
2465 return;
2467 int32 bp0 = int32(m_target->GetMaxHealth() * m_modifier.m_amount / 100);
2468 m_target->CastCustomSpell(m_target, 50322, &bp0, NULL, NULL, true);
2470 else
2471 m_target-> RemoveAurasDueToSpell(50322);
2472 return;
2476 // Lifebloom
2477 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000))
2479 if ( apply )
2481 if ( caster )
2482 // prevent double apply bonuses
2483 if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2484 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2486 else
2488 // Final heal only on dispelled or duration end
2489 if ( !(GetAuraDuration() <= 0 || m_removeMode == AURA_REMOVE_BY_DISPEL) )
2490 return;
2492 // have a look if there is still some other Lifebloom dummy aura
2493 Unit::AuraList auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2494 for(Unit::AuraList::iterator itr = auras.begin(); itr!=auras.end(); ++itr)
2495 if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2496 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000)))
2497 return;
2499 // final heal
2500 if(m_target->IsInWorld() && m_stackAmount > 0)
2502 int32 amount = m_modifier.m_amount / m_stackAmount;
2503 m_target->CastCustomSpell(m_target, 33778, &amount, NULL, NULL, true, NULL, this, GetCasterGUID());
2505 if (caster)
2507 int32 returnmana = (GetSpellProto()->ManaCostPercentage * caster->GetCreateMana() / 100) * m_stackAmount / 2;
2508 caster->CastCustomSpell(caster, 64372, &returnmana, NULL, NULL, true, NULL, this, GetCasterGUID());
2512 return;
2515 // Predatory Strikes
2516 if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2518 ((Player*)m_target)->UpdateAttackPowerAndDamage();
2519 return;
2522 // Improved Moonkin Form
2523 if(GetSpellProto()->SpellIconID == 2855)
2525 uint32 spell_id;
2526 switch(GetId())
2528 case 48384: spell_id = 50170; break; //Rank 1
2529 case 48395: spell_id = 50171; break; //Rank 2
2530 case 48396: spell_id = 50172; break; //Rank 3
2531 default:
2532 sLog.outError("HandleAuraDummy: Not handled rank of IMF (Spell: %u)",GetId());
2533 return;
2536 if(apply)
2538 if(m_target->m_form != FORM_MOONKIN)
2539 return;
2541 m_target->CastSpell(m_target, spell_id, true);
2543 else
2544 m_target-> RemoveAurasDueToSpell(spell_id);
2545 return;
2547 break;
2549 case SPELLFAMILY_HUNTER:
2550 break;
2551 case SPELLFAMILY_SHAMAN:
2553 // Improved Weapon Totems
2554 if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2556 if(apply)
2558 SpellModifier *mod = new SpellModifier;
2559 mod->op = SPELLMOD_EFFECT1;
2560 mod->value = m_modifier.m_amount;
2561 mod->type = SPELLMOD_PCT;
2562 mod->spellId = GetId();
2563 switch (m_effIndex)
2565 case 0:
2566 // Windfury Totem
2567 mod->mask = UI64LIT(0x00200000000);
2568 mod->mask2= UI64LIT(0x0);
2569 break;
2570 case 1:
2571 // Flametongue Totem
2572 mod->mask = UI64LIT(0x00400000000);
2573 mod->mask2= UI64LIT(0x0);
2574 break;
2577 m_spellmod = mod;
2580 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2581 return;
2583 break;
2587 // pet auras
2588 if(PetAura const* petSpell = spellmgr.GetPetAura(GetId(), m_effIndex))
2590 if(apply)
2591 m_target->AddPetAura(petSpell);
2592 else
2593 m_target->RemovePetAura(petSpell);
2594 return;
2597 if(GetEffIndex()==0 && m_target->GetTypeId()==TYPEID_PLAYER)
2599 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
2600 if(saBounds.first != saBounds.second)
2602 uint32 zone, area;
2603 m_target->GetZoneAndAreaId(zone, area);
2605 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2607 // some auras remove at aura remove
2608 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
2609 m_target->RemoveAurasDueToSpell(itr->second->spellId);
2610 // some auras applied at aura apply
2611 else if(itr->second->autocast)
2613 if( !m_target->HasAura(itr->second->spellId, 0) )
2614 m_target->CastSpell(m_target, itr->second->spellId, true);
2621 void Aura::HandleAuraMounted(bool apply, bool Real)
2623 // only at real add/remove aura
2624 if(!Real)
2625 return;
2627 if(apply)
2629 CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2630 if(!ci)
2632 sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2633 return;
2636 uint32 team = 0;
2637 if (m_target->GetTypeId()==TYPEID_PLAYER)
2638 team = ((Player*)m_target)->GetTeam();
2640 uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2641 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2642 if (minfo)
2643 display_id = minfo->modelid;
2645 m_target->Mount(display_id);
2647 else
2649 m_target->Unmount();
2653 void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2655 // only at real add/remove aura
2656 if(!Real)
2657 return;
2659 WorldPacket data;
2660 if(apply)
2661 data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2662 else
2663 data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2664 data.append(m_target->GetPackGUID());
2665 data << uint32(0);
2666 m_target->SendMessageToSet(&data, true);
2669 void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2671 // only at real add/remove aura
2672 if(!Real)
2673 return;
2675 WorldPacket data;
2676 if(apply)
2677 data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2678 else
2679 data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2680 data.append(m_target->GetPackGUID());
2681 data << uint32(0);
2682 m_target->SendMessageToSet(&data, true);
2684 // start fall from current height
2685 if(!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2686 ((Player*)m_target)->SetFallInformation(0, m_target->GetPositionZ());
2689 void Aura::HandleAuraHover(bool apply, bool Real)
2691 // only at real add/remove aura
2692 if(!Real)
2693 return;
2695 WorldPacket data;
2696 if(apply)
2697 data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2698 else
2699 data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2700 data.append(m_target->GetPackGUID());
2701 data << uint32(0);
2702 m_target->SendMessageToSet(&data, true);
2705 void Aura::HandleWaterBreathing(bool /*apply*/, bool /*Real*/)
2707 // update timers in client
2708 if(m_target->GetTypeId()==TYPEID_PLAYER)
2709 ((Player*)m_target)->UpdateMirrorTimers();
2712 void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2714 if(!Real)
2715 return;
2717 uint32 modelid = 0;
2718 Powers PowerType = POWER_MANA;
2719 ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2720 switch(form)
2722 case FORM_CAT:
2723 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2724 modelid = 892;
2725 else
2726 modelid = 8571;
2727 PowerType = POWER_ENERGY;
2728 break;
2729 case FORM_TRAVEL:
2730 modelid = 632;
2731 break;
2732 case FORM_AQUA:
2733 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2734 modelid = 2428;
2735 else
2736 modelid = 2428;
2737 break;
2738 case FORM_BEAR:
2739 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2740 modelid = 2281;
2741 else
2742 modelid = 2289;
2743 PowerType = POWER_RAGE;
2744 break;
2745 case FORM_GHOUL:
2746 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2747 modelid = 10045;
2748 break;
2749 case FORM_DIREBEAR:
2750 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2751 modelid = 2281;
2752 else
2753 modelid = 2289;
2754 PowerType = POWER_RAGE;
2755 break;
2756 case FORM_CREATUREBEAR:
2757 modelid = 902;
2758 break;
2759 case FORM_GHOSTWOLF:
2760 modelid = 4613;
2761 break;
2762 case FORM_FLIGHT:
2763 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2764 modelid = 20857;
2765 else
2766 modelid = 20872;
2767 break;
2768 case FORM_MOONKIN:
2769 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2770 modelid = 15374;
2771 else
2772 modelid = 15375;
2773 break;
2774 case FORM_FLIGHT_EPIC:
2775 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2776 modelid = 21243;
2777 else
2778 modelid = 21244;
2779 break;
2780 case FORM_METAMORPHOSIS:
2781 modelid = 25277;
2782 break;
2783 case FORM_AMBIENT:
2784 case FORM_SHADOW:
2785 case FORM_STEALTH:
2786 break;
2787 case FORM_TREE:
2788 modelid = 864;
2789 break;
2790 case FORM_BATTLESTANCE:
2791 case FORM_BERSERKERSTANCE:
2792 case FORM_DEFENSIVESTANCE:
2793 PowerType = POWER_RAGE;
2794 break;
2795 case FORM_SPIRITOFREDEMPTION:
2796 modelid = 16031;
2797 break;
2798 default:
2799 sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2802 // remove polymorph before changing display id to keep new display id
2803 switch ( form )
2805 case FORM_CAT:
2806 case FORM_TREE:
2807 case FORM_TRAVEL:
2808 case FORM_AQUA:
2809 case FORM_BEAR:
2810 case FORM_DIREBEAR:
2811 case FORM_FLIGHT_EPIC:
2812 case FORM_FLIGHT:
2813 case FORM_MOONKIN:
2815 // remove movement affects
2816 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2817 Unit::AuraList const& slowingAuras = m_target->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
2818 for (Unit::AuraList::const_iterator iter = slowingAuras.begin(); iter != slowingAuras.end();)
2820 SpellEntry const* aurSpellInfo = (*iter)->GetSpellProto();
2822 uint32 aurMechMask = GetAllSpellMechanicMask(aurSpellInfo);
2824 // If spell that caused this aura has Croud Control or Daze effect
2825 if((aurMechMask & MECHANIC_NOT_REMOVED_BY_SHAPESHIFT) ||
2826 // some Daze spells have these parameters instead of MECHANIC_DAZE (skip snare spells)
2827 aurSpellInfo->SpellIconID == 15 && aurSpellInfo->Dispel == 0 && (aurMechMask & (1 << MECHANIC_SNARE))==0)
2829 ++iter;
2830 continue;
2833 // All OK, remove aura now
2834 m_target->RemoveAurasDueToSpellByCancel(aurSpellInfo->Id);
2835 iter = slowingAuras.begin();
2838 // and polymorphic affects
2839 if(m_target->IsPolymorphed())
2840 m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2842 break;
2844 default:
2845 break;
2848 if(apply)
2850 // remove other shapeshift before applying a new one
2851 if(m_target->m_ShapeShiftFormSpellId)
2852 m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId, this);
2854 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2856 if(modelid > 0)
2857 m_target->SetDisplayId(modelid);
2859 if(PowerType != POWER_MANA)
2861 // reset power to default values only at power change
2862 if(m_target->getPowerType() != PowerType)
2863 m_target->setPowerType(PowerType);
2865 switch(form)
2867 case FORM_CAT:
2868 case FORM_BEAR:
2869 case FORM_DIREBEAR:
2871 // get furor proc chance
2872 uint32 FurorChance = 0;
2873 Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2874 for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2876 if ((*i)->GetSpellProto()->SpellIconID == 238)
2878 FurorChance = (*i)->GetModifier()->m_amount;
2879 break;
2883 if (m_modifier.m_miscvalue == FORM_CAT)
2885 m_target->SetPower(POWER_ENERGY, 0);
2886 if(urand(1,100) <= FurorChance)
2887 m_target->CastSpell(m_target, 17099, true, NULL, this);
2889 else
2891 m_target->SetPower(POWER_RAGE, 0);
2892 if(urand(1,100) <= FurorChance)
2893 m_target->CastSpell(m_target, 17057, true, NULL, this);
2895 break;
2897 case FORM_BATTLESTANCE:
2898 case FORM_DEFENSIVESTANCE:
2899 case FORM_BERSERKERSTANCE:
2901 uint32 Rage_val = 0;
2902 // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2903 if(m_target->GetTypeId() == TYPEID_PLAYER)
2905 PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2906 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2908 if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2909 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2910 if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2911 Rage_val += m_target->CalculateSpellDamage(spellInfo, 0, spellInfo->EffectBasePoints[0], m_target) * 10;
2915 if (m_target->GetPower(POWER_RAGE) > Rage_val)
2916 m_target->SetPower(POWER_RAGE, Rage_val);
2917 break;
2919 default:
2920 break;
2924 m_target->m_ShapeShiftFormSpellId = GetId();
2925 m_target->m_form = form;
2927 else
2929 if(modelid > 0)
2930 m_target->SetDisplayId(m_target->GetNativeDisplayId());
2931 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2932 if(m_target->getClass() == CLASS_DRUID)
2933 m_target->setPowerType(POWER_MANA);
2934 m_target->m_ShapeShiftFormSpellId = 0;
2935 m_target->m_form = FORM_NONE;
2937 switch(form)
2939 // Nordrassil Harness - bonus
2940 case FORM_BEAR:
2941 case FORM_DIREBEAR:
2942 case FORM_CAT:
2943 if(Aura* dummy = m_target->GetDummyAura(37315) )
2944 m_target->CastSpell(m_target, 37316, true, NULL, dummy);
2945 break;
2946 // Nordrassil Regalia - bonus
2947 case FORM_MOONKIN:
2948 if(Aura* dummy = m_target->GetDummyAura(37324) )
2949 m_target->CastSpell(m_target, 37325, true, NULL, dummy);
2950 break;
2951 default:
2952 break;
2956 // adding/removing linked auras
2957 // add/remove the shapeshift aura's boosts
2958 HandleShapeshiftBoosts(apply);
2960 if(m_target->GetTypeId() == TYPEID_PLAYER)
2961 ((Player*)m_target)->InitDataForForm();
2964 void Aura::HandleAuraTransform(bool apply, bool Real)
2966 if (apply)
2968 // special case (spell specific functionality)
2969 if (m_modifier.m_miscvalue == 0)
2971 // player applied only
2972 if (m_target->GetTypeId() != TYPEID_PLAYER)
2973 return;
2975 switch (GetId())
2977 // Orb of Deception
2978 case 16739:
2980 uint32 orb_model = m_target->GetNativeDisplayId();
2981 switch(orb_model)
2983 // Troll Female
2984 case 1479: m_target->SetDisplayId(10134); break;
2985 // Troll Male
2986 case 1478: m_target->SetDisplayId(10135); break;
2987 // Tauren Male
2988 case 59: m_target->SetDisplayId(10136); break;
2989 // Human Male
2990 case 49: m_target->SetDisplayId(10137); break;
2991 // Human Female
2992 case 50: m_target->SetDisplayId(10138); break;
2993 // Orc Male
2994 case 51: m_target->SetDisplayId(10139); break;
2995 // Orc Female
2996 case 52: m_target->SetDisplayId(10140); break;
2997 // Dwarf Male
2998 case 53: m_target->SetDisplayId(10141); break;
2999 // Dwarf Female
3000 case 54: m_target->SetDisplayId(10142); break;
3001 // NightElf Male
3002 case 55: m_target->SetDisplayId(10143); break;
3003 // NightElf Female
3004 case 56: m_target->SetDisplayId(10144); break;
3005 // Undead Female
3006 case 58: m_target->SetDisplayId(10145); break;
3007 // Undead Male
3008 case 57: m_target->SetDisplayId(10146); break;
3009 // Tauren Female
3010 case 60: m_target->SetDisplayId(10147); break;
3011 // Gnome Male
3012 case 1563: m_target->SetDisplayId(10148); break;
3013 // Gnome Female
3014 case 1564: m_target->SetDisplayId(10149); break;
3015 // BloodElf Female
3016 case 15475: m_target->SetDisplayId(17830); break;
3017 // BloodElf Male
3018 case 15476: m_target->SetDisplayId(17829); break;
3019 // Dranei Female
3020 case 16126: m_target->SetDisplayId(17828); break;
3021 // Dranei Male
3022 case 16125: m_target->SetDisplayId(17827); break;
3023 default: break;
3025 break;
3027 // Murloc costume
3028 case 42365: m_target->SetDisplayId(21723); break;
3029 default: break;
3032 else
3034 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
3035 if (!ci)
3037 //pig pink ^_^
3038 m_target->SetDisplayId(16358);
3039 sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
3041 else
3043 // Will use the default model here
3044 m_target->SetDisplayId(ci->DisplayID_A[0]);
3046 // Dragonmaw Illusion (set mount model also)
3047 if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
3048 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3052 // update active transform spell only not set or not overwriting negative by positive case
3053 if (!m_target->getTransForm() || !IsPositiveSpell(GetId()) || IsPositiveSpell(m_target->getTransForm()))
3054 m_target->setTransForm(GetId());
3056 // polymorph case
3057 if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
3059 // for players, start regeneration after 1s (in polymorph fast regeneration case)
3060 // only if caster is Player (after patch 2.4.2)
3061 if (IS_PLAYER_GUID(GetCasterGUID()) )
3062 ((Player*)m_target)->setRegenTimer(1*IN_MILISECONDS);
3064 //dismount polymorphed target (after patch 2.4.2)
3065 if (m_target->IsMounted())
3066 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
3069 else
3071 // ApplyModifier(true) will reapply it if need
3072 m_target->setTransForm(0);
3073 m_target->SetDisplayId(m_target->GetNativeDisplayId());
3075 // re-aplly some from still active with preference negative cases
3076 Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
3077 if (!otherTransforms.empty())
3079 // look for other transform auras
3080 Aura* handledAura = *otherTransforms.begin();
3081 for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
3083 // negative auras are preferred
3084 if (!IsPositiveSpell((*i)->GetSpellProto()->Id))
3086 handledAura = *i;
3087 break;
3090 handledAura->ApplyModifier(true);
3093 // Dragonmaw Illusion (restore mount model)
3094 if (GetId() == 42016 && m_target->GetMountID() == 16314)
3096 if (!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
3098 uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
3099 if (CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
3101 uint32 team = 0;
3102 if (m_target->GetTypeId() == TYPEID_PLAYER)
3103 team = ((Player*)m_target)->GetTeam();
3105 uint32 display_id = objmgr.ChooseDisplayId(team, ci);
3106 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
3107 if (minfo)
3108 display_id = minfo->modelid;
3110 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, display_id);
3117 void Aura::HandleForceReaction(bool apply, bool Real)
3119 if(m_target->GetTypeId() != TYPEID_PLAYER)
3120 return;
3122 if(!Real)
3123 return;
3125 Player* player = (Player*)m_target;
3127 uint32 faction_id = m_modifier.m_miscvalue;
3128 uint32 faction_rank = m_modifier.m_amount;
3130 player->GetReputationMgr().ApplyForceReaction(faction_id, ReputationRank(faction_rank), apply);
3131 player->GetReputationMgr().SendForceReactions();
3134 void Aura::HandleAuraModSkill(bool apply, bool /*Real*/)
3136 if(m_target->GetTypeId() != TYPEID_PLAYER)
3137 return;
3139 uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
3140 int32 points = GetModifier()->m_amount;
3142 ((Player*)m_target)->ModifySkillBonus(prot, (apply ? points: -points), m_modifier.m_auraname == SPELL_AURA_MOD_SKILL_TALENT);
3143 if(prot == SKILL_DEFENSE)
3144 ((Player*)m_target)->UpdateDefenseBonusesMod();
3147 void Aura::HandleChannelDeathItem(bool apply, bool Real)
3149 if(Real && !apply)
3151 Unit* caster = GetCaster();
3152 Unit* victim = GetTarget();
3153 if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode != AURA_REMOVE_BY_DEATH)
3154 return;
3155 // Item amount
3156 if (m_modifier.m_amount <= 0)
3157 return;
3159 SpellEntry const *spellInfo = GetSpellProto();
3160 if(spellInfo->EffectItemType[m_effIndex] == 0)
3161 return;
3163 // Soul Shard only from non-grey units
3164 if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
3165 (victim->getLevel() <= MaNGOS::XP::GetGrayLevel(caster->getLevel()) ||
3166 victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
3167 return;
3168 //Adding items
3169 uint32 noSpaceForCount = 0;
3170 uint32 count = m_modifier.m_amount;
3172 ItemPosCountVec dest;
3173 uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], count, &noSpaceForCount);
3174 if( msg != EQUIP_ERR_OK )
3176 count-=noSpaceForCount;
3177 ((Player*)caster)->SendEquipError( msg, NULL, NULL );
3178 if (count==0)
3179 return;
3182 Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
3183 ((Player*)caster)->SendNewItem(newitem, count, true, false);
3187 void Aura::HandleBindSight(bool apply, bool /*Real*/)
3189 Unit* caster = GetCaster();
3190 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3191 return;
3193 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3196 void Aura::HandleFarSight(bool apply, bool /*Real*/)
3198 Unit* caster = GetCaster();
3199 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3200 return;
3202 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3205 void Aura::HandleAuraTrackCreatures(bool apply, bool /*Real*/)
3207 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3208 return;
3210 if(apply)
3211 m_target->RemoveNoStackAurasDueToAura(this);
3212 m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
3215 void Aura::HandleAuraTrackResources(bool apply, bool /*Real*/)
3217 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3218 return;
3220 if(apply)
3221 m_target->RemoveNoStackAurasDueToAura(this);
3222 m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
3225 void Aura::HandleAuraTrackStealthed(bool apply, bool /*Real*/)
3227 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3228 return;
3230 if(apply)
3231 m_target->RemoveNoStackAurasDueToAura(this);
3233 m_target->ApplyModFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTE_TRACK_STEALTHED, apply);
3236 void Aura::HandleAuraModScale(bool apply, bool /*Real*/)
3238 m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X, m_modifier.m_amount, apply);
3241 void Aura::HandleModPossess(bool apply, bool Real)
3243 if(!Real)
3244 return;
3246 // not possess yourself
3247 if(GetCasterGUID() == m_target->GetGUID())
3248 return;
3250 Unit* caster = GetCaster();
3251 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3252 return;
3254 Player* p_caster = (Player*)caster;
3257 if( apply )
3259 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3261 m_target->SetCharmerGUID(p_caster->GetGUID());
3262 m_target->setFaction(p_caster->getFaction());
3264 p_caster->SetCharm(m_target);
3266 p_caster->SetFarSightGUID(m_target->GetGUID());
3267 p_caster->SetClientControl(m_target, 1);
3268 p_caster->SetMover(m_target);
3270 m_target->CombatStop();
3271 m_target->DeleteThreatList();
3273 if(m_target->GetTypeId() == TYPEID_UNIT)
3275 m_target->StopMoving();
3276 m_target->GetMotionMaster()->Clear();
3277 m_target->GetMotionMaster()->MoveIdle();
3279 else if(m_target->GetTypeId() == TYPEID_PLAYER)
3281 ((Player*)m_target)->SetClientControl(m_target, 0);
3284 if(CharmInfo *charmInfo = m_target->InitCharmInfo(m_target))
3285 charmInfo->InitPossessCreateSpells();
3287 p_caster->PossessSpellInitialize();
3289 else
3291 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3293 m_target->SetCharmerGUID(0);
3294 p_caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now
3296 if(m_target->GetTypeId() == TYPEID_PLAYER)
3298 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3299 ((Player*)m_target)->SetClientControl(m_target, 1);
3301 else if(m_target->GetTypeId() == TYPEID_UNIT)
3303 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3304 m_target->setFaction(cinfo->faction_A);
3307 p_caster->SetCharm(NULL);
3309 p_caster->SetFarSightGUID(0);
3310 p_caster->SetClientControl(m_target, 0);
3311 p_caster->SetMover(NULL);
3313 p_caster->RemovePetActionBar();
3315 if(m_target->GetTypeId() == TYPEID_UNIT)
3317 ((Creature*)m_target)->AIM_Initialize();
3319 if (((Creature*)m_target)->AI())
3320 ((Creature*)m_target)->AI()->AttackedBy(caster);
3325 void Aura::HandleModPossessPet(bool apply, bool Real)
3327 if(!Real)
3328 return;
3330 Unit* caster = GetCaster();
3331 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3332 return;
3334 Pet *pet = caster->GetPet();
3335 if(!pet || pet != m_target)
3336 return;
3338 Player* p_caster = (Player*)caster;
3340 if(apply)
3341 pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3342 else
3343 pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3345 p_caster->SetFarSightGUID(apply ? pet->GetGUID() : 0);
3346 p_caster->SetCharm(apply ? pet : NULL);
3347 p_caster->SetClientControl(pet, apply ? 1 : 0);
3348 ((Player*)caster)->SetMover(apply ? pet : NULL);
3350 if(apply)
3352 pet->StopMoving();
3353 pet->GetMotionMaster()->Clear();
3354 pet->GetMotionMaster()->MoveIdle();
3356 else
3358 pet->AttackStop();
3359 pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
3360 pet->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
3364 void Aura::HandleAuraModPetTalentsPoints(bool /*Apply*/, bool Real)
3366 if(!Real)
3367 return;
3369 // Recalculate pet talent points
3370 if (Pet *pet=m_target->GetPet())
3371 pet->InitTalentForLevel();
3374 void Aura::HandleModCharm(bool apply, bool Real)
3376 if(!Real)
3377 return;
3379 // not charm yourself
3380 if(GetCasterGUID() == m_target->GetGUID())
3381 return;
3383 Unit* caster = GetCaster();
3384 if(!caster)
3385 return;
3387 if( apply )
3389 m_target->SetCharmerGUID(GetCasterGUID());
3390 m_target->setFaction(caster->getFaction());
3391 m_target->CastStop(m_target == caster ? GetId() : 0);
3392 caster->SetCharm(m_target);
3394 m_target->CombatStop();
3395 m_target->DeleteThreatList();
3397 if(m_target->GetTypeId() == TYPEID_UNIT)
3399 ((Creature*)m_target)->AIM_Initialize();
3400 CharmInfo *charmInfo = m_target->InitCharmInfo(m_target);
3401 charmInfo->InitCharmCreateSpells();
3402 charmInfo->SetReactState( REACT_DEFENSIVE );
3404 if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
3406 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3407 if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
3409 // creature with pet number expected have class set
3410 if(m_target->GetByteValue(UNIT_FIELD_BYTES_0, 1)==0)
3412 if(cinfo->unit_class==0)
3413 sLog.outErrorDb("Creature (Entry: %u) have unit_class = 0 but used in charmed spell, that will be result client crash.",cinfo->Entry);
3414 else
3415 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);
3417 m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, CLASS_MAGE);
3420 //just to enable stat window
3421 charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
3422 //if charmed two demons the same session, the 2nd gets the 1st one's name
3423 m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
3428 if(caster->GetTypeId() == TYPEID_PLAYER)
3429 ((Player*)caster)->CharmSpellInitialize();
3431 else
3433 m_target->SetCharmerGUID(0);
3435 if(m_target->GetTypeId() == TYPEID_PLAYER)
3436 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3437 else
3439 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3441 // restore faction
3442 if(((Creature*)m_target)->isPet())
3444 if(Unit* owner = m_target->GetOwner())
3445 m_target->setFaction(owner->getFaction());
3446 else if(cinfo)
3447 m_target->setFaction(cinfo->faction_A);
3449 else if(cinfo) // normal creature
3450 m_target->setFaction(cinfo->faction_A);
3452 // restore UNIT_FIELD_BYTES_0
3453 if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3455 // DB must have proper class set in field at loading, not req. restore, including workaround case at apply
3456 // m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, cinfo->unit_class);
3458 if(m_target->GetCharmInfo())
3459 m_target->GetCharmInfo()->SetPetNumber(0, true);
3460 else
3461 sLog.outError("Aura::HandleModCharm: target (GUID: %u TypeId: %u) has a charm aura but no charm info!", m_target->GetGUIDLow(), m_target->GetTypeId());
3465 caster->SetCharm(NULL);
3467 if(caster->GetTypeId() == TYPEID_PLAYER)
3468 ((Player*)caster)->RemovePetActionBar();
3470 if(m_target->GetTypeId() == TYPEID_UNIT)
3472 ((Creature*)m_target)->AIM_Initialize();
3473 if (((Creature*)m_target)->AI())
3474 ((Creature*)m_target)->AI()->AttackedBy(caster);
3479 void Aura::HandleModConfuse(bool apply, bool Real)
3481 if(!Real)
3482 return;
3484 m_target->SetConfused(apply, GetCasterGUID(), GetId());
3487 void Aura::HandleModFear(bool apply, bool Real)
3489 if (!Real)
3490 return;
3492 m_target->SetFeared(apply, GetCasterGUID(), GetId());
3495 void Aura::HandleFeignDeath(bool apply, bool Real)
3497 if(!Real)
3498 return;
3500 if(m_target->GetTypeId() != TYPEID_PLAYER)
3501 return;
3503 if( apply )
3506 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3507 data<<m_target->GetGUID();
3508 data<<uint8(0);
3509 m_target->SendMessageToSet(&data,true);
3511 // blizz like 2.0.x
3512 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3513 // blizz like 2.0.x
3514 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3515 // blizz like 2.0.x
3516 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3518 m_target->addUnitState(UNIT_STAT_DIED);
3519 m_target->CombatStop();
3520 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3522 // prevent interrupt message
3523 if (m_caster_guid==m_target->GetGUID())
3524 m_target->FinishSpell(CURRENT_GENERIC_SPELL,false);
3525 m_target->InterruptNonMeleeSpells(true);
3526 m_target->getHostilRefManager().deleteReferences();
3528 else
3531 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3532 data<<m_target->GetGUID();
3533 data<<uint8(1);
3534 m_target->SendMessageToSet(&data,true);
3536 // blizz like 2.0.x
3537 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3538 // blizz like 2.0.x
3539 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3540 // blizz like 2.0.x
3541 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3543 m_target->clearUnitState(UNIT_STAT_DIED);
3547 void Aura::HandleAuraModDisarm(bool apply, bool Real)
3549 if(!Real)
3550 return;
3552 if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3553 return;
3555 // not sure for it's correctness
3556 if(apply)
3557 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3558 else
3559 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3561 // only at real add/remove aura
3562 if (m_target->GetTypeId() != TYPEID_PLAYER)
3563 return;
3565 // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3566 if (m_target->IsInFeralForm())
3567 return;
3569 if (apply)
3570 m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3571 else
3572 ((Player *)m_target)->SetRegularAttackTime();
3574 m_target->UpdateDamagePhysical(BASE_ATTACK);
3577 void Aura::HandleAuraModStun(bool apply, bool Real)
3579 if(!Real)
3580 return;
3582 if (apply)
3584 // Frost stun aura -> freeze/unfreeze target
3585 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3586 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3588 m_target->addUnitState(UNIT_STAT_STUNNED);
3589 m_target->SetUInt64Value(UNIT_FIELD_TARGET, 0);
3591 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3592 m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3594 // Creature specific
3595 if(m_target->GetTypeId() != TYPEID_PLAYER)
3596 m_target->StopMoving();
3597 else
3599 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3600 m_target->SetStandState(UNIT_STAND_STATE_STAND);// in 1.5 client
3603 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3604 data.append(m_target->GetPackGUID());
3605 data << uint32(0);
3606 m_target->SendMessageToSet(&data, true);
3608 // Summon the Naj'entus Spine GameObject on target if spell is Impaling Spine
3609 if(GetId() == 39837)
3611 GameObject* pObj = new GameObject;
3612 if(pObj->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 185584, m_target->GetMap(), m_target->GetPhaseMask(),
3613 m_target->GetPositionX(), m_target->GetPositionY(), m_target->GetPositionZ(), m_target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
3615 pObj->SetRespawnTime(GetAuraDuration()/IN_MILISECONDS);
3616 pObj->SetSpellId(GetId());
3617 m_target->AddGameObject(pObj);
3618 m_target->GetMap()->Add(pObj);
3620 else
3621 delete pObj;
3624 else
3626 // Frost stun aura -> freeze/unfreeze target
3627 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3629 bool found_another = false;
3630 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3632 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3633 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3635 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3637 found_another = true;
3638 break;
3641 if(found_another)
3642 break;
3645 if(!found_another)
3646 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3649 // Real remove called after current aura remove from lists, check if other similar auras active
3650 if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3651 return;
3653 m_target->clearUnitState(UNIT_STAT_STUNNED);
3654 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3656 if(!m_target->hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
3658 if(m_target->getVictim() && m_target->isAlive())
3659 m_target->SetUInt64Value(UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3661 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3662 data.append(m_target->GetPackGUID());
3663 data << uint32(0);
3664 m_target->SendMessageToSet(&data, true);
3667 // Wyvern Sting
3668 if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & UI64LIT(0x0000100000000000))
3670 Unit* caster = GetCaster();
3671 if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3672 return;
3674 uint32 spell_id = 0;
3676 switch(GetId())
3678 case 19386: spell_id = 24131; break;
3679 case 24132: spell_id = 24134; break;
3680 case 24133: spell_id = 24135; break;
3681 case 27068: spell_id = 27069; break;
3682 case 49011: spell_id = 49009; break;
3683 case 49012: spell_id = 49010; break;
3684 default:
3685 sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3686 return;
3689 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3691 if(!spellInfo)
3692 return;
3694 caster->CastSpell(m_target,spellInfo,true,NULL,this);
3695 return;
3700 void Aura::HandleModStealth(bool apply, bool Real)
3702 if (apply)
3704 // drop flag at stealth in bg
3705 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3707 // only at real aura add
3708 if (Real)
3710 m_target->SetStandFlags(UNIT_STAND_FLAGS_CREEP);
3712 if (m_target->GetTypeId()==TYPEID_PLAYER)
3713 m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3715 // apply only if not in GM invisibility (and overwrite invisibility state)
3716 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3718 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3719 m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3722 // apply full stealth period bonuses only at first stealth aura in stack
3723 if(m_target->GetAurasByType(SPELL_AURA_MOD_STEALTH).size()<=1)
3725 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3726 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3728 // Master of Subtlety
3729 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3731 m_target->RemoveAurasDueToSpell(31666);
3732 int32 bp = (*i)->GetModifier()->m_amount;
3733 m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3735 // Overkill
3736 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3738 m_target->RemoveAurasDueToSpell(58428);
3739 m_target->CastSpell(m_target, 58427, true);
3745 else
3747 // only at real aura remove of _last_ SPELL_AURA_MOD_STEALTH
3748 if (Real && !m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3750 // if no GM invisibility
3751 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3753 m_target->RemoveStandFlags(UNIT_STAND_FLAGS_CREEP);
3755 if (m_target->GetTypeId()==TYPEID_PLAYER)
3756 m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3758 // restore invisibility if any
3759 if (m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3761 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3762 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3764 else
3765 m_target->SetVisibility(VISIBILITY_ON);
3768 // apply delayed talent bonus remover at last stealth aura remove
3769 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3770 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3772 // Master of Subtlety
3773 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3774 m_target->CastSpell(m_target, 31666, true);
3775 // Overkill
3776 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3777 m_target->CastSpell(m_target, 58428, true);
3783 void Aura::HandleInvisibility(bool apply, bool Real)
3785 if(apply)
3787 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3789 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3791 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3793 // apply glow vision
3794 m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3798 // apply only if not in GM invisibility and not stealth
3799 if(m_target->GetVisibility() == VISIBILITY_ON)
3801 // Aura not added yet but visibility code expect temporary add aura
3802 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3803 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3806 else
3808 // recalculate value at modifier remove (current aura already removed)
3809 m_target->m_invisibilityMask = 0;
3810 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
3811 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3812 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3814 // only at real aura remove and if not have different invisibility auras.
3815 if(Real && m_target->m_invisibilityMask == 0)
3817 // remove glow vision
3818 if(m_target->GetTypeId() == TYPEID_PLAYER)
3819 m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3821 // apply only if not in GM invisibility & not stealthed while invisible
3822 if(m_target->GetVisibility() != VISIBILITY_OFF)
3824 // if have stealth aura then already have stealth visibility
3825 if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3826 m_target->SetVisibility(VISIBILITY_ON);
3832 void Aura::HandleInvisibilityDetect(bool apply, bool Real)
3834 if(apply)
3836 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3838 else
3840 // recalculate value at modifier remove (current aura already removed)
3841 m_target->m_detectInvisibilityMask = 0;
3842 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
3843 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3844 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3846 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3847 ObjectAccessor::UpdateVisibilityForPlayer((Player*)m_target);
3850 void Aura::HandleAuraModRoot(bool apply, bool Real)
3852 // only at real add/remove aura
3853 if(!Real)
3854 return;
3856 if (apply)
3858 // Frost root aura -> freeze/unfreeze target
3859 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3860 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3862 m_target->addUnitState(UNIT_STAT_ROOT);
3863 m_target->SetUInt64Value (UNIT_FIELD_TARGET, 0);
3864 // probably wrong (this add skinable flag)
3865 // TODO: find correct flag
3866 //m_target->SetFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3868 //Save last orientation
3869 if( m_target->getVictim() )
3870 m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
3872 if(m_target->GetTypeId() == TYPEID_PLAYER)
3874 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
3875 data.append(m_target->GetPackGUID());
3876 data << (uint32)2;
3877 m_target->SendMessageToSet(&data, true);
3879 //Clear unit movement flags
3880 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3882 else
3883 m_target->StopMoving();
3885 else
3887 // Frost root aura -> freeze/unfreeze target
3888 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3890 bool found_another = false;
3891 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3893 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3894 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3896 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3898 found_another = true;
3899 break;
3902 if(found_another)
3903 break;
3906 if(!found_another)
3907 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3910 // Real remove called after current aura remove from lists, check if other similar auras active
3911 if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
3912 return;
3914 m_target->clearUnitState(UNIT_STAT_ROOT);
3915 // probably wrong (this add skinable flag)
3916 // TODO: find correct flag
3917 //m_target->RemoveFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3919 if(!m_target->hasUnitState(UNIT_STAT_STUNNED)) // prevent allow move if have also stun effect
3921 if(m_target->getVictim() && m_target->isAlive())
3922 m_target->SetUInt64Value (UNIT_FIELD_TARGET, m_target->getVictim()->GetGUID() );
3924 if(m_target->GetTypeId() == TYPEID_PLAYER)
3926 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
3927 data.append(m_target->GetPackGUID());
3928 data << (uint32)2;
3929 m_target->SendMessageToSet(&data, true);
3935 void Aura::HandleAuraModSilence(bool apply, bool Real)
3937 // only at real add/remove aura
3938 if(!Real)
3939 return;
3941 if(apply)
3943 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3944 // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
3945 for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
3946 if (Spell* spell = m_target->GetCurrentSpell(CurrentSpellTypes(i)))
3947 if(spell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
3948 // Stop spells on prepare or casting state
3949 m_target->InterruptSpell(CurrentSpellTypes(i), false);
3951 else
3953 // Real remove called after current aura remove from lists, check if other similar auras active
3954 if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
3955 return;
3957 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3961 void Aura::HandleModThreat(bool apply, bool Real)
3963 // only at real add/remove aura
3964 if (!Real)
3965 return;
3967 if (!m_target->isAlive())
3968 return;
3970 Unit* caster = GetCaster();
3972 if (!caster || !caster->isAlive())
3973 return;
3975 int level_diff = 0;
3976 int multiplier = 0;
3977 switch (GetId())
3979 // Arcane Shroud
3980 case 26400:
3981 level_diff = m_target->getLevel() - 60;
3982 multiplier = 2;
3983 break;
3984 // The Eye of Diminution
3985 case 28862:
3986 level_diff = m_target->getLevel() - 60;
3987 multiplier = 1;
3988 break;
3991 if (level_diff > 0)
3992 m_modifier.m_amount += multiplier * level_diff;
3994 if (m_target->GetTypeId() == TYPEID_PLAYER)
3995 for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
3996 if (m_modifier.m_miscvalue & int32(1<<x))
3997 ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_modifier.m_amount, apply);
4000 void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
4002 // only at real add/remove aura
4003 if (!Real)
4004 return;
4006 if (!m_target->isAlive() || m_target->GetTypeId() != TYPEID_PLAYER)
4007 return;
4009 Unit* caster = GetCaster();
4011 if (!caster || !caster->isAlive())
4012 return;
4014 float threatMod = apply ? float(m_modifier.m_amount) : float(-m_modifier.m_amount);
4016 m_target->getHostilRefManager().threatAssist(caster, threatMod);
4019 void Aura::HandleModTaunt(bool apply, bool Real)
4021 // only at real add/remove aura
4022 if (!Real)
4023 return;
4025 if (!m_target->isAlive() || !m_target->CanHaveThreatList())
4026 return;
4028 Unit* caster = GetCaster();
4030 if (!caster || !caster->isAlive())
4031 return;
4033 if (apply)
4034 m_target->TauntApply(caster);
4035 else
4037 // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
4038 m_target->TauntFadeOut(caster);
4042 /*********************************************************/
4043 /*** MODIFY SPEED ***/
4044 /*********************************************************/
4045 void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real)
4047 // all applied/removed only at real aura add/remove
4048 if(!Real)
4049 return;
4051 m_target->UpdateSpeed(MOVE_RUN, true);
4054 void Aura::HandleAuraModIncreaseMountedSpeed(bool /*apply*/, bool Real)
4056 // all applied/removed only at real aura add/remove
4057 if(!Real)
4058 return;
4060 m_target->UpdateSpeed(MOVE_RUN, true);
4063 void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
4065 // all applied/removed only at real aura add/remove
4066 if(!Real)
4067 return;
4069 // Enable Fly mode for flying mounts
4070 if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
4072 WorldPacket data;
4073 if(apply)
4074 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
4075 else
4076 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
4077 data.append(m_target->GetPackGUID());
4078 data << uint32(0); // unknown
4079 m_target->SendMessageToSet(&data, true);
4081 //Players on flying mounts must be immune to polymorph
4082 if (m_target->GetTypeId()==TYPEID_PLAYER)
4083 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
4085 // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
4086 if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
4087 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
4090 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4093 void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real)
4095 // all applied/removed only at real aura add/remove
4096 if(!Real)
4097 return;
4099 m_target->UpdateSpeed(MOVE_SWIM, true);
4102 void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real)
4104 // all applied/removed only at real aura add/remove
4105 if(!Real)
4106 return;
4108 if (apply)
4110 // Gronn Lord's Grasp, becomes stoned
4111 if (GetId() == 33572)
4113 if (GetStackAmount() >= 5 && !m_target->HasAura(33652))
4114 m_target->CastSpell(m_target, 33652, true);
4118 m_target->UpdateSpeed(MOVE_RUN, true);
4119 m_target->UpdateSpeed(MOVE_SWIM, true);
4120 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4123 void Aura::HandleAuraModUseNormalSpeed(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);
4130 m_target->UpdateSpeed(MOVE_SWIM, true);
4131 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4134 /*********************************************************/
4135 /*** IMMUNITY ***/
4136 /*********************************************************/
4138 void Aura::HandleModMechanicImmunity(bool apply, bool /*Real*/)
4140 uint32 misc = m_modifier.m_miscvalue;
4141 // Forbearance
4142 // in DBC wrong mechanic immune since 3.0.x
4143 if (GetId() == 25771)
4144 misc = MECHANIC_IMMUNE_SHIELD;
4147 if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4149 uint32 mechanic = 1 << misc;
4151 //immune movement impairment and loss of control
4152 if(GetId()==42292 || GetId()==59752)
4153 mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
4155 Unit::AuraMap& Auras = m_target->GetAuras();
4156 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4158 next = iter;
4159 ++next;
4160 SpellEntry const *spell = iter->second->GetSpellProto();
4161 if (!( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) && // spells unaffected by invulnerability
4162 spell->Id != GetId())
4164 //check for mechanic mask
4165 if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & mechanic)
4167 m_target->RemoveAurasDueToSpell(spell->Id);
4168 if(Auras.empty())
4169 break;
4170 else
4171 next = Auras.begin();
4177 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,misc,apply);
4179 // Bestial Wrath
4180 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1680)
4182 // The Beast Within cast on owner if talent present
4183 if (Unit* owner = m_target->GetOwner())
4185 // Search talent
4186 Unit::AuraList const& dummyAuras = owner->GetAurasByType(SPELL_AURA_DUMMY);
4187 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); ++i)
4189 if ((*i)->GetSpellProto()->SpellIconID == 2229)
4191 if (apply)
4192 owner->CastSpell(owner, 34471, true, 0, this);
4193 else
4194 owner->RemoveAurasDueToSpell(34471);
4195 break;
4202 //this method is called whenever we add / remove aura which gives m_target some imunity to some spell effect
4203 void Aura::HandleAuraModEffectImmunity(bool apply, bool /*Real*/)
4205 // when removing flag aura, handle flag drop
4206 if( !apply && m_target->GetTypeId() == TYPEID_PLAYER
4207 && (GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION) )
4209 if( BattleGround *bg = ((Player*)m_target)->GetBattleGround() )
4210 bg->EventPlayerDroppedFlag(((Player*)m_target));
4213 m_target->ApplySpellImmune(GetId(), IMMUNITY_EFFECT, m_modifier.m_miscvalue, apply);
4216 void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
4218 if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4220 Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
4221 for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
4223 if (auraList.front() != this) // skip itself aura (it already added)
4225 m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
4226 itr = auraList.begin();
4228 else
4229 ++itr;
4233 m_target->ApplySpellImmune(GetId(), IMMUNITY_STATE, m_modifier.m_miscvalue, apply);
4236 void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
4238 m_target->ApplySpellImmune(GetId(), IMMUNITY_SCHOOL, m_modifier.m_miscvalue, apply);
4240 // remove all flag auras (they are positive, but they must be removed when you are immune)
4241 if( this->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4242 && this->GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_DAMAGE_REDUCED_SHIELD )
4243 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
4245 // TODO: optimalize this cycle - use RemoveAurasWithInterruptFlags call or something else
4246 if( Real && apply
4247 && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4248 && IsPositiveSpell(GetId()) ) //Only positive immunity removes auras
4250 uint32 school_mask = m_modifier.m_miscvalue;
4251 Unit::AuraMap& Auras = m_target->GetAuras();
4252 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4254 next = iter;
4255 ++next;
4256 SpellEntry const *spell = iter->second->GetSpellProto();
4257 if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
4258 && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) //Spells unaffected by invulnerability
4259 && !iter->second->IsPositive() //Don't remove positive spells
4260 && spell->Id != GetId() ) //Don't remove self
4262 m_target->RemoveAurasDueToSpell(spell->Id);
4263 if(Auras.empty())
4264 break;
4265 else
4266 next = Auras.begin();
4270 if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
4272 if( apply )
4273 m_target->addUnitState(UNIT_STAT_ISOLATED);
4274 else
4275 m_target->clearUnitState(UNIT_STAT_ISOLATED);
4279 void Aura::HandleAuraModDmgImmunity(bool apply, bool /*Real*/)
4281 m_target->ApplySpellImmune(GetId(), IMMUNITY_DAMAGE, m_modifier.m_miscvalue, apply);
4284 void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
4286 // all applied/removed only at real aura add/remove
4287 if(!Real)
4288 return;
4290 m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
4293 void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
4295 if(!Real)
4296 return;
4298 if(apply)
4300 // some spell have charges by functionality not have its in spell data
4301 switch (GetId())
4303 case 28200: // Ascendance (Talisman of Ascendance trinket)
4304 SetAuraCharges(6);
4305 break;
4306 default: break;
4311 void Aura::HandleAuraModStalked(bool apply, bool /*Real*/)
4313 // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
4314 if(apply)
4315 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4316 else
4317 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4320 /*********************************************************/
4321 /*** PERIODIC ***/
4322 /*********************************************************/
4324 void Aura::HandlePeriodicTriggerSpell(bool apply, bool /*Real*/)
4326 m_isPeriodic = apply;
4328 if (!apply)
4330 switch(m_spellProto->Id)
4332 case 66: // Invisibility
4333 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && m_duration<=0)
4334 m_target->CastSpell(m_target, 32612, true, NULL, this);
4336 return;
4337 case 42783: //Wrath of the Astrom...
4338 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && GetEffIndex() + 1 < 3)
4339 m_target->CastSpell(m_target, m_spellProto->CalculateSimpleValue(GetEffIndex()+1), true);
4340 return;
4341 default:
4342 break;
4347 void Aura::HandlePeriodicTriggerSpellWithValue(bool apply, bool /*Real*/)
4349 m_isPeriodic = apply;
4352 void Aura::HandlePeriodicEnergize(bool apply, bool Real)
4354 if (!Real)
4355 return;
4357 m_isPeriodic = apply;
4359 // Replenishment (0.25% from max)
4360 // Infinite Replenishment
4361 if (GetId() == 57669 ||
4362 GetId() == 61782)
4363 m_modifier.m_amount = m_target->GetMaxPower(POWER_MANA) * 25 / 10000;
4366 void Aura::HandleAuraPowerBurn(bool apply, bool /*Real*/)
4368 m_isPeriodic = apply;
4371 void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
4373 // spells required only Real aura add/remove
4374 if(!Real)
4375 return;
4377 // For prevent double apply bonuses
4378 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4380 Unit* caster = GetCaster();
4382 SpellEntry const*spell = GetSpellProto();
4383 switch( spell->SpellFamilyName)
4385 case SPELLFAMILY_ROGUE:
4387 if(!apply)
4389 switch(spell->Id)
4391 // Master of Subtlety
4392 case 31666: m_target->RemoveAurasDueToSpell(31665); break;
4393 // Overkill
4394 case 58428: m_target->RemoveAurasDueToSpell(58427); break;
4397 break;
4399 case SPELLFAMILY_HUNTER:
4401 // Explosive Shot
4402 if (apply && !loading && caster)
4403 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 14 / 100);
4404 break;
4408 m_isPeriodic = apply;
4411 void Aura::HandlePeriodicHeal(bool apply, bool /*Real*/)
4413 m_isPeriodic = apply;
4416 void Aura::HandlePeriodicDamage(bool apply, bool Real)
4418 // spells required only Real aura add/remove
4419 if(!Real)
4420 return;
4422 m_isPeriodic = apply;
4424 // For prevent double apply bonuses
4425 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4427 // Custom damage calculation after
4428 if (apply)
4430 if(loading)
4431 return;
4433 Unit *caster = GetCaster();
4434 if (!caster)
4435 return;
4437 switch (m_spellProto->SpellFamilyName)
4439 case SPELLFAMILY_GENERIC:
4441 // Pounce Bleed
4442 if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual[0] == 0 )
4444 // $AP*0.18/6 bonus per tick
4445 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4446 return;
4448 break;
4450 case SPELLFAMILY_WARRIOR:
4452 // Rend
4453 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000020))
4455 // $0.2*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4456 float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4457 int32 mws = caster->GetAttackTime(BASE_ATTACK);
4458 float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4459 float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4460 m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.2f);
4461 return;
4463 break;
4465 case SPELLFAMILY_DRUID:
4467 // Rake
4468 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellProto->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
4470 // $AP*0.18/3 bonus per tick
4471 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 6 / 100);
4472 return;
4474 // Lacerate
4475 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000010000000000))
4477 // $AP*0.05/5 bonus per tick
4478 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4479 return;
4481 // Rip
4482 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000800000))
4484 // 0.01*$AP*cp
4485 if (caster->GetTypeId() != TYPEID_PLAYER)
4486 return;
4488 uint8 cp = ((Player*)caster)->GetComboPoints();
4490 // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4491 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4492 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4494 if((*itr)->GetId()==34241)
4496 m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4497 break;
4500 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4501 return;
4503 // Lock Jaw
4504 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
4506 // 0.15*$AP
4507 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 15 / 100);
4508 return;
4510 break;
4512 case SPELLFAMILY_ROGUE:
4514 // Rupture
4515 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000100000))
4517 if (caster->GetTypeId() != TYPEID_PLAYER)
4518 return;
4519 //1 point : ${($m1+$b1*1+0.015*$AP)*4} damage over 8 secs
4520 //2 points: ${($m1+$b1*2+0.024*$AP)*5} damage over 10 secs
4521 //3 points: ${($m1+$b1*3+0.03*$AP)*6} damage over 12 secs
4522 //4 points: ${($m1+$b1*4+0.03428571*$AP)*7} damage over 14 secs
4523 //5 points: ${($m1+$b1*5+0.0375*$AP)*8} damage over 16 secs
4524 float AP_per_combo[6] = {0.0f, 0.015f, 0.024f, 0.03f, 0.03428571f, 0.0375f};
4525 uint8 cp = ((Player*)caster)->GetComboPoints();
4526 if (cp > 5) cp = 5;
4527 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * AP_per_combo[cp]);
4528 return;
4530 // Garrote
4531 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000000100))
4533 // $AP*0.07 bonus per tick
4534 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 7 / 100);
4535 return;
4537 // Deadly Poison
4538 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000010000))
4540 // 0.08*$AP / 4 * amount of stack
4541 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 2 * GetStackAmount() / 100);
4542 return;
4544 break;
4546 case SPELLFAMILY_HUNTER:
4548 // Serpent Sting
4549 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000004000))
4551 // $RAP*0.1/5 bonus per tick
4552 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4553 return;
4555 // Immolation Trap
4556 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) && m_spellProto->SpellIconID == 678)
4558 // $RAP*0.1/5 bonus per tick
4559 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4560 return;
4562 break;
4564 default:
4565 break;
4568 // remove time effects
4569 else
4571 // Parasitic Shadowfiend - handle summoning of two Shadowfiends on DoT expire
4572 if(m_spellProto->Id == 41917)
4573 m_target->CastSpell(m_target, 41915, true);
4577 void Aura::HandlePeriodicDamagePCT(bool apply, bool /*Real*/)
4579 m_isPeriodic = apply;
4582 void Aura::HandlePeriodicLeech(bool apply, bool /*Real*/)
4584 m_isPeriodic = apply;
4587 void Aura::HandlePeriodicManaLeech(bool apply, bool /*Real*/)
4589 m_isPeriodic = apply;
4592 void Aura::HandlePeriodicHealthFunnel(bool apply, bool /*Real*/)
4594 m_isPeriodic = apply;
4597 /*********************************************************/
4598 /*** MODIFY STATS ***/
4599 /*********************************************************/
4601 /********************************/
4602 /*** RESISTANCE ***/
4603 /********************************/
4605 void Aura::HandleAuraModResistanceExclusive(bool apply, bool /*Real*/)
4607 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4609 if(m_modifier.m_miscvalue & int32(1<<x))
4611 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4612 if(m_target->GetTypeId() == TYPEID_PLAYER)
4613 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4618 void Aura::HandleAuraModResistance(bool apply, bool /*Real*/)
4620 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4622 if(m_modifier.m_miscvalue & int32(1<<x))
4624 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4625 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4626 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4631 void Aura::HandleAuraModBaseResistancePCT(bool apply, bool /*Real*/)
4633 // only players have base stats
4634 if(m_target->GetTypeId() != TYPEID_PLAYER)
4636 //pets only have base armor
4637 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4638 m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4640 else
4642 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4644 if(m_modifier.m_miscvalue & int32(1<<x))
4645 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4650 void Aura::HandleModResistancePercent(bool apply, bool /*Real*/)
4652 for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4654 if(m_modifier.m_miscvalue & int32(1<<i))
4656 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4657 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4659 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, m_modifier.m_amount, apply);
4660 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, m_modifier.m_amount, apply);
4666 void Aura::HandleModBaseResistance(bool apply, bool /*Real*/)
4668 // only players have base stats
4669 if(m_target->GetTypeId() != TYPEID_PLAYER)
4671 //only pets have base stats
4672 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4673 m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4675 else
4677 for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4678 if(m_modifier.m_miscvalue & (1<<i))
4679 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4683 /********************************/
4684 /*** STAT ***/
4685 /********************************/
4687 void Aura::HandleAuraModStat(bool apply, bool /*Real*/)
4689 if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4691 sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4692 return;
4695 for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4697 // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4698 if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4700 //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4701 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4702 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4703 m_target->ApplyStatBuffMod(Stats(i), m_modifier.m_amount, apply);
4708 void Aura::HandleModPercentStat(bool apply, bool /*Real*/)
4710 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4712 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4713 return;
4716 // only players have base stats
4717 if (m_target->GetTypeId() != TYPEID_PLAYER)
4718 return;
4720 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4722 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4723 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4727 void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool /*Real*/)
4729 if(m_target->GetTypeId() != TYPEID_PLAYER)
4730 return;
4732 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4733 // This information for client side use only
4734 // Recalculate bonus
4735 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4738 void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool /*Real*/)
4740 if(m_target->GetTypeId() != TYPEID_PLAYER)
4741 return;
4743 // Recalculate bonus
4744 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4747 void Aura::HandleAuraModDispelResist(bool apply, bool Real)
4749 if(!Real || !apply)
4750 return;
4752 if(GetId() == 33206)
4753 m_target->CastSpell(m_target, 44416, true, NULL, this, GetCasterGUID());
4756 void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4758 if(m_target->GetTypeId() != TYPEID_PLAYER)
4759 return;
4761 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4762 // This information for client side use only
4763 // Recalculate bonus
4764 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4767 void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4769 if(m_target->GetTypeId() != TYPEID_PLAYER)
4770 return;
4772 // Recalculate bonus
4773 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4776 void Aura::HandleModHealingDone(bool /*apply*/, bool /*Real*/)
4778 if(m_target->GetTypeId() != TYPEID_PLAYER)
4779 return;
4780 // implemented in Unit::SpellHealingBonus
4781 // this information is for client side only
4782 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4785 void Aura::HandleModTotalPercentStat(bool apply, bool /*Real*/)
4787 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4789 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4790 return;
4793 //save current and max HP before applying aura
4794 uint32 curHPValue = m_target->GetHealth();
4795 uint32 maxHPValue = m_target->GetMaxHealth();
4797 for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4799 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4801 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4802 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4803 m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
4807 //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
4808 if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
4810 // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
4811 uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
4812 m_target->SetHealth(newHPValue);
4816 void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool /*Real*/)
4818 if(m_target->GetTypeId() != TYPEID_PLAYER)
4819 return;
4821 if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
4823 // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
4824 // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
4825 sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
4826 return;
4829 // Recalculate Armor
4830 m_target->UpdateArmor();
4833 /********************************/
4834 /*** HEAL & ENERGIZE ***/
4835 /********************************/
4836 void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool /*Real*/)
4838 m_isPeriodic = apply;
4841 void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool /*Real*/)
4843 if(m_modifier.periodictime == 0)
4844 m_modifier.periodictime = 1000;
4846 m_periodicTimer = m_modifier.periodictime;
4847 m_isPeriodic = apply;
4850 void Aura::HandleModRegen(bool apply, bool /*Real*/) // eating
4852 if(m_modifier.periodictime == 0)
4853 m_modifier.periodictime = 5000;
4855 m_periodicTimer = 5000;
4856 m_isPeriodic = apply;
4859 void Aura::HandleModPowerRegen(bool apply, bool Real) // drinking
4861 if (!Real)
4862 return;
4864 Powers pt = m_target->getPowerType();
4865 if(m_modifier.periodictime == 0)
4867 // Anger Management (only spell use this aura for rage)
4868 if (pt == POWER_RAGE)
4869 m_modifier.periodictime = 3000;
4870 else
4871 m_modifier.periodictime = 2000;
4874 m_periodicTimer = 5000;
4876 if (m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
4877 ((Player*)m_target)->UpdateManaRegen();
4879 m_isPeriodic = apply;
4882 void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real)
4884 // spells required only Real aura add/remove
4885 if(!Real)
4886 return;
4888 if (m_target->GetTypeId() != TYPEID_PLAYER)
4889 return;
4891 // Update manaregen value
4892 if (m_modifier.m_miscvalue == POWER_MANA)
4893 ((Player*)m_target)->UpdateManaRegen();
4896 void Aura::HandleModManaRegen(bool /*apply*/, bool Real)
4898 // spells required only Real aura add/remove
4899 if(!Real)
4900 return;
4902 if (m_target->GetTypeId() != TYPEID_PLAYER)
4903 return;
4905 //Note: an increase in regen does NOT cause threat.
4906 ((Player*)m_target)->UpdateManaRegen();
4909 void Aura::HandleComprehendLanguage(bool apply, bool /*Real*/)
4911 if(apply)
4912 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4913 else
4914 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4917 void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
4919 // Special case with temporary increase max/current health
4920 switch(GetId())
4922 case 12976: // Warrior Last Stand triggered spell
4923 case 28726: // Nightmare Seed ( Nightmare Seed )
4924 case 34511: // Valor (Bulwark of Kings, Bulwark of the Ancient Kings)
4925 case 44055: // Tremendous Fortitude (Battlemaster's Alacrity)
4926 case 50322: // Survival Instincts
4927 case 54443: // Demonic Empowerment (Voidwalker)
4929 if(Real)
4931 if(apply)
4933 // Demonic Empowerment (Voidwalker) - special case, store percent in data
4934 // recalculate to full amount at apply for proper remove
4935 if (GetId() == 54443)
4936 m_modifier.m_amount = m_target->GetMaxHealth() * m_modifier.m_amount / 100;
4938 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4939 m_target->ModifyHealth(m_modifier.m_amount);
4941 else
4943 if (int32(m_target->GetHealth()) > m_modifier.m_amount)
4944 m_target->ModifyHealth(-m_modifier.m_amount);
4945 else
4946 m_target->SetHealth(1);
4947 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4950 return;
4954 // generic case
4955 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4958 void Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool /*Real*/)
4960 uint32 oldhealth = m_target->GetHealth();
4961 double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
4963 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4965 // refresh percentage
4966 if(oldhealth > 0)
4968 uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
4969 if(newhealth==0)
4970 newhealth = 1;
4972 m_target->SetHealth(newhealth);
4976 void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
4978 Powers powerType = m_target->getPowerType();
4979 if(int32(powerType) != m_modifier.m_miscvalue)
4980 return;
4982 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
4984 // Special case with temporary increase max/current power (percent)
4985 if (GetId()==64904) // Hymn of Hope
4987 if(Real)
4989 uint32 val = m_target->GetPower(powerType);
4990 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
4991 m_target->SetPower(powerType, apply ? val*(100+m_modifier.m_amount)/100 : val*100/(100+m_modifier.m_amount));
4993 return;
4996 // generic flat case
4997 m_target->HandleStatModifier(unitMod, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5000 void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool /*Real*/)
5002 Powers powerType = m_target->getPowerType();
5003 if(int32(powerType) != m_modifier.m_miscvalue)
5004 return;
5006 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5008 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5011 void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool /*Real*/)
5013 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
5016 void Aura::HandleAuraIncreaseBaseHealthPercent(bool apply, bool /*Real*/)
5018 m_target->HandleStatModifier(UNIT_MOD_HEALTH, BASE_PCT, float(m_modifier.m_amount), apply);
5021 /********************************/
5022 /*** FIGHT ***/
5023 /********************************/
5025 void Aura::HandleAuraModParryPercent(bool /*apply*/, bool /*Real*/)
5027 if(m_target->GetTypeId() != TYPEID_PLAYER)
5028 return;
5030 ((Player*)m_target)->UpdateParryPercentage();
5033 void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool /*Real*/)
5035 if(m_target->GetTypeId() != TYPEID_PLAYER)
5036 return;
5038 ((Player*)m_target)->UpdateDodgePercentage();
5039 //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
5042 void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool /*Real*/)
5044 if(m_target->GetTypeId() != TYPEID_PLAYER)
5045 return;
5047 ((Player*)m_target)->UpdateBlockPercentage();
5048 //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
5051 void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real)
5053 // spells required only Real aura add/remove
5054 if(!Real)
5055 return;
5057 if(m_target->GetTypeId() != TYPEID_PLAYER)
5058 return;
5060 ((Player*)m_target)->UpdateManaRegen();
5063 void Aura::HandleAuraModCritPercent(bool apply, bool Real)
5065 if(m_target->GetTypeId() != TYPEID_PLAYER)
5066 return;
5068 // apply item specific bonuses for already equipped weapon
5069 if(Real)
5071 for(int i = 0; i < MAX_ATTACK; ++i)
5072 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5073 ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem, WeaponAttackType(i), this, apply);
5076 // mods must be applied base at equipped weapon class and subclass comparison
5077 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5078 // m_modifier.m_miscvalue comparison with item generated damage types
5080 if (GetSpellProto()->EquippedItemClass == -1)
5082 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5083 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5084 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5086 else
5088 // done in Player::_ApplyWeaponDependentAuraMods
5092 void Aura::HandleModHitChance(bool apply, bool /*Real*/)
5094 if(m_target->GetTypeId() == TYPEID_PLAYER)
5096 ((Player*)m_target)->UpdateMeleeHitChances();
5097 ((Player*)m_target)->UpdateRangedHitChances();
5099 else
5101 m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5102 m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5106 void Aura::HandleModSpellHitChance(bool apply, bool /*Real*/)
5108 if(m_target->GetTypeId() == TYPEID_PLAYER)
5110 ((Player*)m_target)->UpdateSpellHitChances();
5112 else
5114 m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
5118 void Aura::HandleModSpellCritChance(bool apply, bool Real)
5120 // spells required only Real aura add/remove
5121 if(!Real)
5122 return;
5124 if(m_target->GetTypeId() == TYPEID_PLAYER)
5126 ((Player*)m_target)->UpdateAllSpellCritChances();
5128 else
5130 m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
5134 void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real)
5136 // spells required only Real aura add/remove
5137 if(!Real)
5138 return;
5140 if(m_target->GetTypeId() != TYPEID_PLAYER)
5141 return;
5143 for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
5144 if (m_modifier.m_miscvalue & (1<<school))
5145 ((Player*)m_target)->UpdateSpellCritChance(school);
5148 /********************************/
5149 /*** ATTACK SPEED ***/
5150 /********************************/
5152 void Aura::HandleModCastingSpeed(bool apply, bool /*Real*/)
5154 m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
5157 void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool /*Real*/)
5159 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5160 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5161 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5164 void Aura::HandleModCombatSpeedPct(bool apply, bool /*Real*/)
5166 m_target->ApplyCastTimePercentMod(m_modifier.m_amount, apply);
5167 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5168 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5169 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5172 void Aura::HandleModAttackSpeed(bool apply, bool /*Real*/)
5174 if(!m_target->isAlive() )
5175 return;
5177 m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
5180 void Aura::HandleHaste(bool apply, bool /*Real*/)
5182 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5183 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5184 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5187 void Aura::HandleAuraModRangedHaste(bool apply, bool /*Real*/)
5189 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5192 void Aura::HandleRangedAmmoHaste(bool apply, bool /*Real*/)
5194 if(m_target->GetTypeId() != TYPEID_PLAYER)
5195 return;
5196 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
5199 /********************************/
5200 /*** ATTACK POWER ***/
5201 /********************************/
5203 void Aura::HandleAuraModAttackPower(bool apply, bool /*Real*/)
5205 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5208 void Aura::HandleAuraModRangedAttackPower(bool apply, bool /*Real*/)
5210 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5211 return;
5213 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5216 void Aura::HandleAuraModAttackPowerPercent(bool apply, bool /*Real*/)
5218 //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
5219 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
5222 void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool /*Real*/)
5224 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5225 return;
5227 //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
5228 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5231 void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5233 // spells required only Real aura add/remove
5234 if(!Real)
5235 return;
5237 // Recalculate bonus
5238 if(m_target->GetTypeId() == TYPEID_PLAYER && !(m_target->getClassMask() & CLASSMASK_WAND_USERS))
5239 ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
5242 void Aura::HandleAuraModAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5244 // spells required only Real aura add/remove
5245 if(!Real)
5246 return;
5248 // Recalculate bonus
5249 if(m_target->GetTypeId() == TYPEID_PLAYER)
5250 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5253 void Aura::HandleAuraModAttackPowerOfArmor(bool /*apply*/, bool Real)
5255 // spells required only Real aura add/remove
5256 if(!Real)
5257 return;
5259 // Recalculate bonus
5260 if(m_target->GetTypeId() == TYPEID_PLAYER)
5261 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5263 /********************************/
5264 /*** DAMAGE BONUS ***/
5265 /********************************/
5266 void Aura::HandleModDamageDone(bool apply, bool Real)
5268 // apply item specific bonuses for already equipped weapon
5269 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5271 for(int i = 0; i < MAX_ATTACK; ++i)
5272 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5273 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5276 // m_modifier.m_miscvalue is bitmask of spell schools
5277 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5278 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
5279 // 127 - full bitmask any damages
5281 // mods must be applied base at equipped weapon class and subclass comparison
5282 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5283 // m_modifier.m_miscvalue comparison with item generated damage types
5285 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5287 // apply generic physical damage bonuses including wand case
5288 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5290 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5291 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5292 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5294 else
5296 // done in Player::_ApplyWeaponDependentAuraMods
5299 if(m_target->GetTypeId() == TYPEID_PLAYER)
5301 if(m_positive)
5302 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS, m_modifier.m_amount, apply);
5303 else
5304 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG, m_modifier.m_amount, apply);
5308 // Skip non magic case for speedup
5309 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5310 return;
5312 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5314 // wand magic case (skip generic to all item spell bonuses)
5315 // done in Player::_ApplyWeaponDependentAuraMods
5317 // Skip item specific requirements for not wand magic damage
5318 return;
5321 // Magic damage modifiers implemented in Unit::SpellDamageBonus
5322 // This information for client side use only
5323 if(m_target->GetTypeId() == TYPEID_PLAYER)
5325 if(m_positive)
5327 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5329 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5330 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, m_modifier.m_amount, apply);
5333 else
5335 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5337 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5338 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, m_modifier.m_amount, apply);
5341 Pet* pet = m_target->GetPet();
5342 if(pet)
5343 pet->UpdateAttackPowerAndDamage();
5347 void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5349 sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5351 // apply item specific bonuses for already equipped weapon
5352 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5354 for(int i = 0; i < MAX_ATTACK; ++i)
5355 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5356 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5359 // m_modifier.m_miscvalue is bitmask of spell schools
5360 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5361 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5362 // 127 - full bitmask any damages
5364 // mods must be applied base at equipped weapon class and subclass comparison
5365 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5366 // m_modifier.m_miscvalue comparison with item generated damage types
5368 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5370 // apply generic physical damage bonuses including wand case
5371 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5373 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5374 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5375 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5377 else
5379 // done in Player::_ApplyWeaponDependentAuraMods
5381 // For show in client
5382 if(m_target->GetTypeId() == TYPEID_PLAYER)
5383 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT, m_modifier.m_amount/100.0f, apply);
5386 // Skip non magic case for speedup
5387 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5388 return;
5390 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5392 // wand magic case (skip generic to all item spell bonuses)
5393 // done in Player::_ApplyWeaponDependentAuraMods
5395 // Skip item specific requirements for not wand magic damage
5396 return;
5399 // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5400 // Send info to client
5401 if(m_target->GetTypeId() == TYPEID_PLAYER)
5402 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5403 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT + i, m_modifier.m_amount/100.0f, apply);
5406 void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5408 // spells required only Real aura add/remove
5409 if(!Real)
5410 return;
5412 sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5414 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5417 /********************************/
5418 /*** POWER COST ***/
5419 /********************************/
5421 void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5423 // spells required only Real aura add/remove
5424 if(!Real)
5425 return;
5427 float amount = m_modifier.m_amount/100.0f;
5428 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5429 if(m_modifier.m_miscvalue & (1<<i))
5430 m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + i, amount, apply);
5433 void Aura::HandleModPowerCost(bool apply, bool Real)
5435 // spells required only Real aura add/remove
5436 if(!Real)
5437 return;
5439 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5440 if(m_modifier.m_miscvalue & (1<<i))
5441 m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + i, m_modifier.m_amount, apply);
5444 void Aura::HandleNoReagentUseAura(bool /*Apply*/, bool Real)
5446 // spells required only Real aura add/remove
5447 if(!Real)
5448 return;
5449 if(m_target->GetTypeId() != TYPEID_PLAYER)
5450 return;
5451 uint32 mask[3] = {0, 0, 0};
5452 Unit::AuraList const& noReagent = m_target->GetAurasByType(SPELL_AURA_NO_REAGENT_USE);
5453 for(Unit::AuraList::const_iterator i = noReagent.begin(); i != noReagent.end(); ++i)
5455 uint32 const *ptr = (*i)->getAuraSpellClassMask();
5456 mask[0] |= ptr[0];
5457 mask[1] |= ptr[1];
5458 mask[2] |= ptr[2];
5461 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+0, mask[0]);
5462 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+1, mask[1]);
5463 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+2, mask[2]);
5466 /*********************************************************/
5467 /*** OTHERS ***/
5468 /*********************************************************/
5470 void Aura::HandleShapeshiftBoosts(bool apply)
5472 uint32 spellId1 = 0;
5473 uint32 spellId2 = 0;
5474 uint32 HotWSpellId = 0;
5475 uint32 MasterShaperSpellId = 0;
5477 uint32 form = GetModifier()->m_miscvalue;
5479 switch(form)
5481 case FORM_CAT:
5482 spellId1 = 3025;
5483 HotWSpellId = 24900;
5484 MasterShaperSpellId = 48420;
5485 break;
5486 case FORM_TREE:
5487 spellId1 = 5420;
5488 spellId2 = 34123;
5489 MasterShaperSpellId = 48422;
5490 break;
5491 case FORM_TRAVEL:
5492 spellId1 = 5419;
5493 break;
5494 case FORM_AQUA:
5495 spellId1 = 5421;
5496 break;
5497 case FORM_BEAR:
5498 spellId1 = 1178;
5499 spellId2 = 21178;
5500 HotWSpellId = 24899;
5501 MasterShaperSpellId = 48418;
5502 break;
5503 case FORM_DIREBEAR:
5504 spellId1 = 9635;
5505 spellId2 = 21178;
5506 HotWSpellId = 24899;
5507 MasterShaperSpellId = 48418;
5508 break;
5509 case FORM_BATTLESTANCE:
5510 spellId1 = 21156;
5511 break;
5512 case FORM_DEFENSIVESTANCE:
5513 spellId1 = 7376;
5514 break;
5515 case FORM_BERSERKERSTANCE:
5516 spellId1 = 7381;
5517 break;
5518 case FORM_MOONKIN:
5519 spellId1 = 24905;
5520 MasterShaperSpellId = 48421;
5521 break;
5522 case FORM_FLIGHT:
5523 spellId1 = 33948;
5524 spellId2 = 34764;
5525 break;
5526 case FORM_FLIGHT_EPIC:
5527 spellId1 = 40122;
5528 spellId2 = 40121;
5529 break;
5530 case FORM_METAMORPHOSIS:
5531 spellId1 = 54817;
5532 spellId2 = 54879;
5533 break;
5534 case FORM_SPIRITOFREDEMPTION:
5535 spellId1 = 27792;
5536 spellId2 = 27795; // must be second, this important at aura remove to prevent to early iterator invalidation.
5537 break;
5538 case FORM_SHADOW:
5539 spellId1 = 49868;
5541 if(m_target->GetTypeId() == TYPEID_PLAYER) // Spell 49868 have same category as main form spell and share cooldown
5542 ((Player*)m_target)->RemoveSpellCooldown(49868);
5543 break;
5544 case FORM_GHOSTWOLF:
5545 case FORM_AMBIENT:
5546 case FORM_GHOUL:
5547 case FORM_STEALTH:
5548 case FORM_CREATURECAT:
5549 case FORM_CREATUREBEAR:
5550 break;
5553 if(apply)
5555 if (spellId1)
5556 m_target->CastSpell(m_target, spellId1, true, NULL, this );
5557 if (spellId2)
5558 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5560 if (m_target->GetTypeId() == TYPEID_PLAYER)
5562 const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5563 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5565 if (itr->second->state == PLAYERSPELL_REMOVED) continue;
5566 if (itr->first==spellId1 || itr->first==spellId2) continue;
5567 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5568 if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7))))
5569 continue;
5570 if (spellInfo->Stances & (1<<(form-1)))
5571 m_target->CastSpell(m_target, itr->first, true, NULL, this);
5574 // Master Shapeshifter
5575 if (MasterShaperSpellId)
5577 Unit::AuraList const& ShapeShifterAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5578 for(Unit::AuraList::const_iterator i = ShapeShifterAuras.begin(); i != ShapeShifterAuras.end(); i++)
5580 if ((*i)->GetSpellProto()->SpellIconID == 2851)
5582 int32 ShiftMod = (*i)->GetModifier()->m_amount;
5583 m_target->CastCustomSpell(m_target, MasterShaperSpellId, &ShiftMod, NULL, NULL, true);
5584 break;
5589 // Leader of the Pack
5590 if (((Player*)m_target)->HasSpell(17007))
5592 SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5593 if (spellInfo && spellInfo->Stances & (1<<(form-1)))
5594 m_target->CastSpell(m_target, 24932, true, NULL, this);
5597 // Savage Roar
5598 if (form == FORM_CAT && ((Player*)m_target)->HasAura(52610))
5599 m_target->CastSpell(m_target, 62071, true);
5601 // Improved Moonkin Form
5602 if (form == FORM_MOONKIN)
5604 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5605 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); i++)
5607 if ((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_DRUID &&
5608 (*i)->GetSpellProto()->SpellIconID == 2855)
5610 uint32 spell_id = 0;
5611 switch((*i)->GetId())
5613 case 48384:spell_id=50170;break;//Rank 1
5614 case 48395:spell_id=50171;break;//Rank 2
5615 case 48396:spell_id=50172;break;//Rank 3
5616 default:
5617 sLog.outError("Aura::HandleShapeshiftBoosts: Not handled rank of IMF (Spell: %u)",(*i)->GetId());
5618 break;
5621 if(spell_id)
5622 m_target->CastSpell(m_target, spell_id, true, NULL, this);
5623 break;
5628 // Heart of the Wild
5629 if (HotWSpellId)
5631 Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5632 for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5634 if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5636 int32 HotWMod = (*i)->GetModifier()->m_amount;
5637 if(GetModifier()->m_miscvalue == FORM_CAT)
5638 HotWMod /= 2;
5640 m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5641 break;
5647 else
5649 if(spellId1)
5650 m_target->RemoveAurasDueToSpell(spellId1);
5651 if(spellId2)
5652 m_target->RemoveAurasDueToSpell(spellId2);
5653 if(MasterShaperSpellId)
5654 m_target->RemoveAurasDueToSpell(MasterShaperSpellId);
5656 Unit::AuraMap& tAuras = m_target->GetAuras();
5657 for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5659 if (itr->second->IsRemovedOnShapeLost())
5661 m_target->RemoveAurasDueToSpell(itr->second->GetId());
5662 itr = tAuras.begin();
5664 else
5665 ++itr;
5670 void Aura::HandleSpellSpecificBoosts(bool apply)
5672 uint32 spellId1 = 0;
5673 uint32 spellId2 = 0;
5674 uint32 spellId3 = 0;
5675 uint32 spellId4 = 0;
5677 switch(GetSpellProto()->SpellFamilyName)
5679 case SPELLFAMILY_WARRIOR:
5681 if(!apply)
5683 // Remove Blood Frenzy only if target no longer has any Deep Wound or Rend (applying is handled by procs)
5684 if (GetSpellProto()->Mechanic != MECHANIC_BLEED)
5685 return;
5687 // If target still has one of Warrior's bleeds, do nothing
5688 Unit::AuraList const& PeriodicDamage = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
5689 for(Unit::AuraList::const_iterator i = PeriodicDamage.begin(); i != PeriodicDamage.end(); ++i)
5690 if( (*i)->GetCasterGUID() == GetCasterGUID() &&
5691 (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARRIOR &&
5692 (*i)->GetSpellProto()->Mechanic == MECHANIC_BLEED)
5693 return;
5695 spellId1 = 30069;
5696 spellId2 = 30070;
5698 break;
5700 case SPELLFAMILY_ROGUE:
5701 // Sprint (skip non player casted spells by category)
5702 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000040) && GetSpellProto()->Category == 44)
5704 if(!apply || m_target->HasAura(58039)) // Glyph of Blurred Speed
5705 spellId1 = 61922; // Sprint (waterwalk)
5706 else
5707 return;
5709 else
5710 return;
5711 break;
5712 case SPELLFAMILY_HUNTER:
5714 // The Beast Within and Bestial Wrath - immunity
5715 if (GetId() == 19574 || GetId() == 34471)
5717 spellId1 = 24395;
5718 spellId2 = 24396;
5719 spellId3 = 24397;
5720 spellId4 = 26592;
5722 // Aspect of the Dragonhawk dodge
5723 else if (GetSpellProto()->SpellFamilyFlags2 & 0x00001000)
5725 spellId1 = 61848;
5727 // triggered spell have same category as main spell and cooldown
5728 if (apply && m_target->GetTypeId()==TYPEID_PLAYER)
5729 ((Player*)m_target)->RemoveSpellCooldown(61848);
5731 else
5732 return;
5733 break;
5735 case SPELLFAMILY_PALADIN:
5737 // Only process on player casting paladin aura
5738 // all aura bonuses applied also in aura area effect way to caster
5739 if (GetCasterGUID() != m_target->GetGUID() || !IS_PLAYER_GUID(GetCasterGUID()))
5740 return;
5742 if (GetSpellSpecific(m_spellProto->Id) != SPELL_AURA)
5743 return;
5745 // Sanctified Retribution and Swift Retribution (they share one aura), but not Retribution Aura (already gets modded)
5746 if ((GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000008))==0)
5747 spellId1 = 63531; // placeholder for talent spell mods
5748 // Improved Concentration Aura (auras bonus)
5749 spellId2 = 63510; // placeholder for talent spell mods
5750 // Improved Devotion Aura (auras bonus)
5751 spellId3 = 63514; // placeholder for talent spell mods
5752 break;
5754 case SPELLFAMILY_DEATHKNIGHT:
5756 if (GetSpellSpecific(m_spellProto->Id) != SPELL_PRESENCE)
5757 return;
5759 // Frost Presence health
5760 if (GetId() == 48263)
5761 spellId1 = 61261;
5762 // Unholy Presence move speed
5763 else if (GetId() == 48265)
5764 spellId1 = 49772;
5765 else
5766 return;
5768 break;
5770 default:
5771 return;
5774 // prevent aura deletion, specially in multi-boost case
5775 SetInUse(true);
5777 if (apply)
5779 if (spellId1)
5780 m_target->CastSpell(m_target, spellId1, true, NULL, this);
5781 if (spellId2 && !IsDeleted())
5782 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5783 if (spellId3 && !IsDeleted())
5784 m_target->CastSpell(m_target, spellId3, true, NULL, this);
5785 if (spellId4 && !IsDeleted())
5786 m_target->CastSpell(m_target, spellId4, true, NULL, this);
5788 else
5790 if (spellId1)
5791 m_target->RemoveAurasByCasterSpell(spellId1, GetCasterGUID());
5792 if (spellId2)
5793 m_target->RemoveAurasByCasterSpell(spellId2, GetCasterGUID());
5794 if (spellId3)
5795 m_target->RemoveAurasByCasterSpell(spellId3, GetCasterGUID());
5796 if (spellId4)
5797 m_target->RemoveAurasByCasterSpell(spellId4, GetCasterGUID());
5800 SetInUse(false);
5803 void Aura::HandleAuraEmpathy(bool apply, bool /*Real*/)
5805 if(m_target->GetTypeId() != TYPEID_UNIT)
5806 return;
5808 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5809 if(ci && ci->type == CREATURE_TYPE_BEAST)
5810 m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5813 void Aura::HandleAuraUntrackable(bool apply, bool /*Real*/)
5815 if(apply)
5816 m_target->SetByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5817 else
5818 m_target->RemoveByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5821 void Aura::HandleAuraModPacify(bool apply, bool /*Real*/)
5823 if(m_target->GetTypeId() != TYPEID_PLAYER)
5824 return;
5826 if(apply)
5827 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5828 else
5829 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5832 void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5834 HandleAuraModPacify(apply, Real);
5835 HandleAuraModSilence(apply, Real);
5838 void Aura::HandleAuraGhost(bool apply, bool /*Real*/)
5840 if(m_target->GetTypeId() != TYPEID_PLAYER)
5841 return;
5843 if(apply)
5845 m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5847 else
5849 m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5853 void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5855 // all applied/removed only at real aura add/remove
5856 if(!Real)
5857 return;
5859 // allow fly
5860 WorldPacket data;
5861 if(apply)
5862 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5863 else
5864 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5865 data.append(m_target->GetPackGUID());
5866 data << uint32(0); // unk
5867 m_target->SendMessageToSet(&data, true);
5870 void Aura::HandleModRating(bool apply, bool Real)
5872 // spells required only Real aura add/remove
5873 if(!Real)
5874 return;
5876 if(m_target->GetTypeId() != TYPEID_PLAYER)
5877 return;
5879 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5880 if (m_modifier.m_miscvalue & (1 << rating))
5881 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5884 void Aura::HandleModRatingFromStat(bool apply, bool Real)
5886 // spells required only Real aura add/remove
5887 if(!Real)
5888 return;
5890 if(m_target->GetTypeId() != TYPEID_PLAYER)
5891 return;
5892 // Just recalculate ratings
5893 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5894 if (m_modifier.m_miscvalue & (1 << rating))
5895 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), 0, apply);
5898 void Aura::HandleForceMoveForward(bool apply, bool Real)
5900 if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5901 return;
5902 if(apply)
5903 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5904 else
5905 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5908 void Aura::HandleAuraModExpertise(bool /*apply*/, bool /*Real*/)
5910 if(m_target->GetTypeId() != TYPEID_PLAYER)
5911 return;
5913 ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5914 ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5917 void Aura::HandleModTargetResistance(bool apply, bool Real)
5919 // spells required only Real aura add/remove
5920 if(!Real)
5921 return;
5922 // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
5924 // show armor penetration
5925 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
5926 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE, m_modifier.m_amount, apply);
5928 // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
5929 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
5930 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE, m_modifier.m_amount, apply);
5933 void Aura::HandleShieldBlockValue(bool apply, bool /*Real*/)
5935 BaseModType modType = FLAT_MOD;
5936 if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
5937 modType = PCT_MOD;
5939 if(m_target->GetTypeId() == TYPEID_PLAYER)
5940 ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
5943 void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
5945 // spells required only Real aura add/remove
5946 if(!Real)
5947 return;
5949 if(m_target->GetTypeId() != TYPEID_PLAYER)
5950 return;
5952 Player *target = (Player*)m_target;
5954 // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
5955 // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
5956 if( !apply && m_duration==0 && target->GetComboTarget())
5957 if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
5958 target->AddComboPoints(unit, -m_modifier.m_amount);
5961 void Aura::HandleModUnattackable( bool Apply, bool Real )
5963 if(Real && Apply)
5965 m_target->CombatStop();
5966 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
5968 m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
5971 void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
5973 // spells required only Real aura add/remove
5974 if(!Real)
5975 return;
5977 // prepare spirit state
5978 if(apply)
5980 if(m_target->GetTypeId()==TYPEID_PLAYER)
5982 // disable breath/etc timers
5983 ((Player*)m_target)->StopMirrorTimers();
5985 // set stand state (expected in this form)
5986 if(!m_target->IsStandState())
5987 m_target->SetStandState(UNIT_STAND_STATE_STAND);
5990 m_target->SetHealth(1);
5992 // die at aura end
5993 else
5994 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
5997 void Aura::CleanupTriggeredSpells()
5999 uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
6000 if(!tSpellId)
6001 return;
6003 SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
6004 if(!tProto)
6005 return;
6007 if(GetSpellDuration(tProto) != -1)
6008 return;
6010 // needed for spell 43680, maybe others
6011 // TODO: is there a spell flag, which can solve this in a more sophisticated way?
6012 if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
6013 GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
6014 return;
6015 m_target->RemoveAurasDueToSpell(tSpellId);
6018 void Aura::HandleSchoolAbsorb(bool apply, bool Real)
6020 if(!Real)
6021 return;
6023 Unit* caster = GetCaster();
6024 if(!caster)
6025 return;
6027 if (apply)
6029 // prevent double apply bonuses
6030 if (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
6032 float DoneActualBenefit = 0.0f;
6033 switch(m_spellProto->SpellFamilyName)
6035 case SPELLFAMILY_PRIEST:
6036 // Power Word: Shield
6037 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001))
6038 //+80.68% from +spell bonus
6039 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.8068f;
6040 break;
6041 case SPELLFAMILY_MAGE:
6042 // Frost Ward, Fire Ward
6043 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000108))
6044 //+10% from +spell bonus
6045 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
6046 // Ice Barrier
6047 else if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000100000000))
6048 //+80.67% from +spell bonus
6049 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.8067f;
6050 break;
6051 case SPELLFAMILY_WARLOCK:
6052 // Shadow Ward
6053 if (m_spellProto->SpellFamilyFlags2 & 0x00000040)
6054 //+30% from +spell bonus
6055 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.30f;
6056 break;
6057 case SPELLFAMILY_DRUID:
6058 // Savage Defense (amount store original percent of attack power applied)
6059 if (m_spellProto->SpellIconID == 50) // only spell with this aura fit
6060 m_modifier.m_amount = int32(m_modifier.m_amount * m_target->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
6061 break;
6062 default:
6063 break;
6066 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6068 m_modifier.m_amount += (int32)DoneActualBenefit;
6071 else
6073 // Ice Barrier (remove effect from Shattered Barrier)
6074 if (m_spellProto->SpellIconID == 32 && m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE)
6076 if (!((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6077 return;
6079 if (m_target->HasAura(44745,0)) // Shattered Barrier, rank 1
6081 if(roll_chance_i(50))
6082 m_target->CastSpell(m_target, 55080, true, NULL, this);
6084 else if (m_target->HasAura(54787,0)) // Shattered Barrier, rank 2
6086 m_target->CastSpell(m_target, 55080, true, NULL, this);
6090 if (caster &&
6091 // Power Word: Shield
6092 m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST && m_spellProto->Mechanic == MECHANIC_SHIELD &&
6093 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001)) &&
6094 // completely absorbed or dispelled
6095 ((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6097 Unit::AuraList const& vDummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6098 for(Unit::AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); itr++)
6100 SpellEntry const* vSpell = (*itr)->GetSpellProto();
6102 // Rapture (main spell)
6103 if(vSpell->SpellFamilyName == SPELLFAMILY_PRIEST && vSpell->SpellIconID == 2894 && vSpell->Effect[1])
6105 switch((*itr)->GetEffIndex())
6107 case 0:
6109 // energize caster
6110 int32 manapct1000 = 5 * ((*itr)->GetModifier()->m_amount + spellmgr.GetSpellRank(vSpell->Id));
6111 int32 basepoints0 = caster->GetMaxPower(POWER_MANA) * manapct1000 / 1000;
6112 caster->CastCustomSpell(caster, 47755, &basepoints0, NULL, NULL, true);
6113 break;
6115 case 1:
6117 // energize target
6118 if (!roll_chance_i((*itr)->GetModifier()->m_amount) || caster->HasAura(63853))
6119 break;
6121 switch(m_target->getPowerType())
6123 case POWER_RUNIC_POWER:
6124 m_target->CastSpell(m_target, 63652, true, NULL, NULL, m_caster_guid);
6125 break;
6126 case POWER_RAGE:
6127 m_target->CastSpell(m_target, 63653, true, NULL, NULL, m_caster_guid);
6128 break;
6129 case POWER_MANA:
6131 int32 basepoints0 = m_target->GetMaxPower(POWER_MANA) * 2 / 100;
6132 m_target->CastCustomSpell(m_target, 63654, &basepoints0, NULL, NULL, true);
6133 break;
6135 case POWER_ENERGY:
6136 m_target->CastSpell(m_target, 63655, true, NULL, NULL, m_caster_guid);
6137 break;
6138 default:
6139 break;
6142 //cooldwon aura
6143 caster->CastSpell(caster, 63853, true);
6144 break;
6146 default:
6147 sLog.outError("Changes in R-dummy spell???: effect 3");
6148 break;
6156 void Aura::PeriodicTick()
6158 if(!m_target->isAlive())
6159 return;
6161 switch(m_modifier.m_auraname)
6163 case SPELL_AURA_PERIODIC_DAMAGE:
6164 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
6166 Unit *pCaster = GetCaster();
6167 if(!pCaster)
6168 return;
6170 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6171 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6172 return;
6174 // Check for immune (not use charges)
6175 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6176 return;
6178 // some auras remove at specific health level or more
6179 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6181 switch(GetId())
6183 case 43093: case 31956: case 38801:
6184 case 35321: case 38363: case 39215:
6185 if(m_target->GetHealth() == m_target->GetMaxHealth() )
6187 m_target->RemoveAurasDueToSpell(GetId());
6188 return;
6190 break;
6191 case 38772:
6193 uint32 percent =
6194 GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_DUMMY ?
6195 pCaster->CalculateSpellDamage(GetSpellProto(), GetEffIndex() + 1, GetSpellProto()->EffectBasePoints[GetEffIndex() + 1], m_target) :
6196 100;
6197 if(m_target->GetHealth() * 100 >= m_target->GetMaxHealth() * percent )
6199 m_target->RemoveAurasDueToSpell(GetId());
6200 return;
6202 break;
6204 default:
6205 break;
6209 uint32 absorb = 0;
6210 uint32 resist = 0;
6211 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6213 // ignore non positive values (can be result apply spellmods to aura damage
6214 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6216 uint32 pdamage;
6218 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6220 pdamage = amount;
6222 // Calculate armor mitigation if it is a physical spell
6223 // But not for bleed mechanic spells
6224 if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
6225 GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
6227 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6228 cleanDamage.damage += pdamage - pdamageReductedArmor;
6229 pdamage = pdamageReductedArmor;
6232 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6234 // Curse of Agony damage-per-tick calculation
6235 if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000400)) && GetSpellProto()->SpellIconID==544)
6237 // 1..4 ticks, 1/2 from normal tick damage
6238 if (m_duration >= ((m_maxduration-m_modifier.periodictime) * 2 / 3))
6239 pdamage = pdamage/2;
6240 // 9..12 ticks, 3/2 from normal tick damage
6241 else if(m_duration < ((m_maxduration-m_modifier.periodictime) / 3))
6242 pdamage += (pdamage + 1) / 2; // +1 prevent 0.5 damage possible lost at 1..4 ticks
6243 // 5..8 ticks have normal tick damage
6246 else
6247 pdamage = uint32(m_target->GetMaxHealth()*amount/100);
6249 // This method can modify pdamage
6250 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6252 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6253 // Reduce dot damage from resilience for players
6254 if (m_target->GetTypeId() == TYPEID_PLAYER)
6255 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6257 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6259 sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6260 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6262 pCaster->DealDamageMods(m_target, pdamage, &absorb);
6264 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, absorb, resist, 0.0f, isCrit);
6265 m_target->SendPeriodicAuraLog(&pInfo);
6267 // Set trigger flag
6268 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6269 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6270 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage - absorb - resist);
6271 if (pdamage)
6272 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6273 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6275 pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6276 break;
6278 case SPELL_AURA_PERIODIC_LEECH:
6279 case SPELL_AURA_PERIODIC_HEALTH_FUNNEL:
6281 Unit *pCaster = GetCaster();
6282 if(!pCaster)
6283 return;
6285 if(!pCaster->isAlive())
6286 return;
6288 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6289 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6290 return;
6292 // Check for immune
6293 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6294 return;
6296 uint32 absorb=0;
6297 uint32 resist=0;
6298 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6300 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6302 //Calculate armor mitigation if it is a physical spell
6303 if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
6305 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6306 cleanDamage.damage += pdamage - pdamageReductedArmor;
6307 pdamage = pdamageReductedArmor;
6310 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6312 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6313 // Reduce dot damage from resilience for players
6314 if (m_target->GetTypeId()==TYPEID_PLAYER)
6315 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6317 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6319 if(m_target->GetHealth() < pdamage)
6320 pdamage = uint32(m_target->GetHealth());
6322 sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6323 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6325 pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
6327 float multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()] > 0 ? GetSpellProto()->EffectMultipleValue[GetEffIndex()] : 1;
6329 // Set trigger flag
6330 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6331 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6332 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage-absorb-resist);
6333 if (pdamage)
6334 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6335 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6336 int32 new_damage = pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
6338 if (!m_target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
6339 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
6340 if (Spell* spell = pCaster->GetCurrentSpell(CurrentSpellTypes(i)))
6341 if (spell->m_spellInfo->Id == GetId())
6342 spell->cancel();
6345 if(Player *modOwner = pCaster->GetSpellModOwner())
6346 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, multiplier);
6348 uint32 heal = pCaster->SpellHealingBonus(pCaster, GetSpellProto(), uint32(new_damage * multiplier), DOT, GetStackAmount());
6350 int32 gain = pCaster->DealHeal(pCaster, heal, GetSpellProto());
6351 pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, GetSpellProto());
6352 break;
6354 case SPELL_AURA_PERIODIC_HEAL:
6355 case SPELL_AURA_OBS_MOD_HEALTH:
6357 Unit *pCaster = GetCaster();
6358 if(!pCaster)
6359 return;
6361 // heal for caster damage (must be alive)
6362 if(m_target != pCaster && GetSpellProto()->SpellVisual[0] == 163 && !pCaster->isAlive())
6363 return;
6365 // ignore non positive values (can be result apply spellmods to aura damage
6366 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6368 uint32 pdamage;
6370 if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
6371 pdamage = uint32(m_target->GetMaxHealth() * amount / 100);
6372 else
6374 pdamage = amount;
6376 // Wild Growth (1/7 - 6 + 2*ramainTicks) %
6377 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && m_spellProto->SpellIconID == 2864)
6379 int32 ticks = m_maxduration/m_modifier.periodictime;
6380 int32 remainingTicks = int32(float(m_duration) / m_modifier.periodictime + 0.5);
6381 pdamage = int32(pdamage) + int32(amount)*ticks*(-6+2*remainingTicks)/100;
6385 pdamage = pCaster->SpellHealingBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6387 // This method can modify pdamage
6388 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6390 sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
6391 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6393 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f, isCrit);
6394 m_target->SendPeriodicAuraLog(&pInfo);
6396 int32 gain = m_target->ModifyHealth(pdamage);
6398 // add HoTs to amount healed in bgs
6399 if( pCaster->GetTypeId() == TYPEID_PLAYER )
6400 if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
6401 bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
6403 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6405 SpellEntry const* spellProto = GetSpellProto();
6407 // heal for caster damage
6408 if(m_target != pCaster && spellProto->SpellVisual[0] == 163)
6410 uint32 dmg = spellProto->manaPerSecond;
6411 if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
6413 pCaster->RemoveAurasDueToSpell(GetId());
6415 // finish current generic/channeling spells, don't affect autorepeat
6416 pCaster->FinishSpell(CURRENT_GENERIC_SPELL);
6417 pCaster->FinishSpell(CURRENT_CHANNELED_SPELL);
6419 else
6421 uint32 damage = gain;
6422 uint32 absorb = 0;
6423 pCaster->DealDamageMods(pCaster, damage, &absorb);
6424 pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), damage, GetSpellSchoolMask(GetSpellProto()), absorb, 0, false, 0, false);
6426 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6427 pCaster->DealDamage(pCaster, damage, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6431 // uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC;// | PROC_FLAG_SUCCESSFUL_HEAL;
6432 // uint32 procVictim = 0;//ROC_FLAG_ON_TAKE_PERIODIC | PROC_FLAG_TAKEN_HEAL;
6433 // ignore item heals
6434 // if(procSpell && !haveCastItem)
6435 // pCaster->ProcDamageAndSpell(target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, spellProto);
6436 break;
6438 case SPELL_AURA_PERIODIC_MANA_LEECH:
6440 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6441 return;
6443 Powers power = Powers(m_modifier.m_miscvalue);
6445 // power type might have changed between aura applying and tick (druid's shapeshift)
6446 if(m_target->getPowerType() != power)
6447 return;
6449 Unit *pCaster = GetCaster();
6450 if(!pCaster)
6451 return;
6453 if(!pCaster->isAlive())
6454 return;
6456 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6457 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6458 return;
6460 // Check for immune (not use charges)
6461 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6462 return;
6464 // ignore non positive values (can be result apply spellmods to aura damage
6465 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6467 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
6468 // It's mana percent cost spells, m_modifier.m_amount is percent drain from target
6469 if (m_spellProto->ManaCostPercentage)
6471 // max value
6472 uint32 maxmana = pCaster->GetMaxPower(power) * pdamage * 2 / 100;
6473 pdamage = m_target->GetMaxPower(power) * pdamage / 100;
6474 if(pdamage > maxmana)
6475 pdamage = maxmana;
6478 sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
6479 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6481 int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
6483 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6484 if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6485 drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
6487 m_target->ModifyPower(power, -drain_amount);
6489 float gain_multiplier = 0;
6491 if(pCaster->GetMaxPower(power) > 0)
6493 gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
6495 if(Player *modOwner = pCaster->GetSpellModOwner())
6496 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
6499 SpellPeriodicAuraLogInfo pInfo(this, drain_amount, 0, 0, 0, gain_multiplier);
6500 m_target->SendPeriodicAuraLog(&pInfo);
6502 int32 gain_amount = int32(drain_amount * gain_multiplier);
6504 if(gain_amount)
6506 int32 gain = pCaster->ModifyPower(power, gain_amount);
6507 m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
6509 break;
6511 case SPELL_AURA_PERIODIC_ENERGIZE:
6513 // ignore non positive values (can be result apply spellmods to aura damage
6514 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6516 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
6517 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6519 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6520 break;
6522 Powers power = Powers(m_modifier.m_miscvalue);
6524 if(m_target->GetMaxPower(power) == 0)
6525 break;
6527 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6528 m_target->SendPeriodicAuraLog(&pInfo);
6530 int32 gain = m_target->ModifyPower(power,pdamage);
6532 if(Unit* pCaster = GetCaster())
6533 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6534 break;
6536 case SPELL_AURA_OBS_MOD_MANA:
6538 // ignore non positive values (can be result apply spellmods to aura damage
6539 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6541 uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount / 100);
6543 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
6544 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6546 if(m_target->GetMaxPower(POWER_MANA) == 0)
6547 break;
6549 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6550 m_target->SendPeriodicAuraLog(&pInfo);
6552 int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
6554 if(Unit* pCaster = GetCaster())
6555 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6556 break;
6558 case SPELL_AURA_POWER_BURN_MANA:
6560 Unit *pCaster = GetCaster();
6561 if(!pCaster)
6562 return;
6564 // Check for immune (not use charges)
6565 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6566 return;
6568 int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6570 Powers powerType = Powers(m_modifier.m_miscvalue);
6572 if(!m_target->isAlive() || m_target->getPowerType() != powerType)
6573 return;
6575 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6576 if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6577 pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
6579 uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
6581 gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
6583 SpellEntry const* spellProto = GetSpellProto();
6584 // maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
6585 SpellNonMeleeDamage damageInfo(pCaster, m_target, spellProto->Id, spellProto->SchoolMask);
6586 pCaster->CalculateSpellDamage(&damageInfo, gain, spellProto);
6588 pCaster->DealDamageMods(damageInfo.target, damageInfo.damage, &damageInfo.absorb);
6590 pCaster->SendSpellNonMeleeDamageLog(&damageInfo);
6592 // Set trigger flag
6593 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6594 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6595 uint32 procEx = createProcExtendMask(&damageInfo, SPELL_MISS_NONE);
6596 if (damageInfo.damage)
6597 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6599 pCaster->ProcDamageAndSpell(damageInfo.target, procAttacker, procVictim, procEx, damageInfo.damage, BASE_ATTACK, spellProto);
6601 pCaster->DealSpellDamage(&damageInfo, true);
6602 break;
6604 case SPELL_AURA_MOD_REGEN:
6606 int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
6607 if (Unit *caster = GetCaster())
6608 m_target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, GetSpellProto());
6609 break;
6611 case SPELL_AURA_MOD_POWER_REGEN:
6613 Powers pt = m_target->getPowerType();
6614 if(int32(pt) != m_modifier.m_miscvalue)
6615 return;
6617 if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
6619 // eating anim
6620 m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
6622 else if( GetId() == 20577 )
6624 // cannibalize anim
6625 m_target->HandleEmoteCommand(EMOTE_STATE_CANNIBALIZE);
6628 // Anger Management
6629 // amount = 1+ 16 = 17 = 3,4*5 = 10,2*5/3
6630 // so 17 is rounded amount for 5 sec tick grow ~ 1 range grow in 3 sec
6631 if(pt == POWER_RAGE)
6632 m_target->ModifyPower(pt, m_modifier.m_amount * 3 / 5);
6633 break;
6635 // Here tick dummy auras
6636 case SPELL_AURA_PERIODIC_DUMMY:
6638 PeriodicDummyTick();
6639 break;
6641 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
6643 TriggerSpell();
6644 break;
6646 case SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE:
6648 TriggerSpellWithValue();
6649 break;
6651 default:
6652 break;
6656 void Aura::PeriodicDummyTick()
6658 Unit *caster = GetCaster();
6659 SpellEntry const* spell = GetSpellProto();
6660 switch (spell->SpellFamilyName)
6662 case SPELLFAMILY_GENERIC:
6663 switch (spell->Id)
6665 // Drink
6666 case 430:
6667 case 431:
6668 case 432:
6669 case 1133:
6670 case 1135:
6671 case 1137:
6672 case 10250:
6673 case 22734:
6674 case 27089:
6675 case 34291:
6676 case 43182:
6677 case 43183:
6678 case 43706:
6679 case 46755:
6680 case 49472: // Drink Coffee
6681 case 57073:
6682 case 61830:
6684 if (m_target->GetTypeId() != TYPEID_PLAYER)
6685 return;
6686 // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6687 Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6688 for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6690 if ((*i)->GetId() == GetId())
6692 (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6693 ((Player*)m_target)->UpdateManaRegen();
6694 // Disable continue
6695 m_isPeriodic = false;
6696 return;
6699 return;
6701 // Forsaken Skills
6702 case 7054:
6704 // Possibly need cast one of them (but
6705 // 7038 Forsaken Skill: Swords
6706 // 7039 Forsaken Skill: Axes
6707 // 7040 Forsaken Skill: Daggers
6708 // 7041 Forsaken Skill: Maces
6709 // 7042 Forsaken Skill: Staves
6710 // 7043 Forsaken Skill: Bows
6711 // 7044 Forsaken Skill: Guns
6712 // 7045 Forsaken Skill: 2H Axes
6713 // 7046 Forsaken Skill: 2H Maces
6714 // 7047 Forsaken Skill: 2H Swords
6715 // 7048 Forsaken Skill: Defense
6716 // 7049 Forsaken Skill: Fire
6717 // 7050 Forsaken Skill: Frost
6718 // 7051 Forsaken Skill: Holy
6719 // 7053 Forsaken Skill: Shadow
6720 return;
6722 // // Panda
6723 // case 19230: break;
6724 // // Gossip NPC Periodic - Talk
6725 // case 33208: break;
6726 // // Gossip NPC Periodic - Despawn
6727 // case 33209: break;
6728 // // Steal Weapon
6729 // case 36207: break;
6730 // // Simon Game START timer, (DND)
6731 // case 39993: break;
6732 // // Knockdown Fel Cannon: break; The Aggro Burst
6733 // case 40119: break;
6734 // // Old Mount Spell
6735 // case 40154: break;
6736 // // Magnetic Pull
6737 // case 40581: break;
6738 // // Ethereal Ring: break; The Bolt Burst
6739 // case 40801: break;
6740 // // Crystal Prison
6741 // case 40846: break;
6742 // // Copy Weapon
6743 // case 41054: break;
6744 // // Dementia
6745 // case 41404: break;
6746 // // Ethereal Ring Visual, Lightning Aura
6747 // case 41477: break;
6748 // // Ethereal Ring Visual, Lightning Aura (Fork)
6749 // case 41525: break;
6750 // // Ethereal Ring Visual, Lightning Jumper Aura
6751 // case 41567: break;
6752 // // No Man's Land
6753 // case 41955: break;
6754 // // Headless Horseman - Fire
6755 // case 42074: break;
6756 // // Headless Horseman - Visual - Large Fire
6757 // case 42075: break;
6758 // // Headless Horseman - Start Fire, Periodic Aura
6759 // case 42140: break;
6760 // // Ram Speed Boost
6761 // case 42152: break;
6762 // // Headless Horseman - Fires Out Victory Aura
6763 // case 42235: break;
6764 // // Pumpkin Life Cycle
6765 // case 42280: break;
6766 // // Brewfest Request Chick Chuck Mug Aura
6767 // case 42537: break;
6768 // // Squashling
6769 // case 42596: break;
6770 // // Headless Horseman Climax, Head: Periodic
6771 // case 42603: break;
6772 // // Fire Bomb
6773 // case 42621: break;
6774 // // Headless Horseman - Conflagrate, Periodic Aura
6775 // case 42637: break;
6776 // // Headless Horseman - Create Pumpkin Treats Aura
6777 // case 42774: break;
6778 // // Headless Horseman Climax - Summoning Rhyme Aura
6779 // case 42879: break;
6780 // // Tricky Treat
6781 // case 42919: break;
6782 // // Giddyup!
6783 // case 42924: break;
6784 // // Ram - Trot
6785 // case 42992: break;
6786 // // Ram - Canter
6787 // case 42993: break;
6788 // // Ram - Gallop
6789 // case 42994: break;
6790 // // Ram Level - Neutral
6791 // case 43310: break;
6792 // // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6793 // case 43884: break;
6794 // // Wretched!
6795 // case 43963: break;
6796 // // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6797 // case 44000: break;
6798 // // Energy Feedback
6799 // case 44328: break;
6800 // // Romantic Picnic
6801 // case 45102: break;
6802 // // Romantic Picnic
6803 // case 45123: break;
6804 // // Looking for Love
6805 // case 45124: break;
6806 // // Kite - Lightning Strike Kite Aura
6807 // case 45197: break;
6808 // // Rocket Chicken
6809 // case 45202: break;
6810 // // Copy Offhand Weapon
6811 // case 45205: break;
6812 // // Upper Deck - Kite - Lightning Periodic Aura
6813 // case 45207: break;
6814 // // Kite -Sky Lightning Strike Kite Aura
6815 // case 45251: break;
6816 // // Ribbon Pole Dancer Check Aura
6817 // case 45390: break;
6818 // // Holiday - Midsummer, Ribbon Pole Periodic Visual
6819 // case 45406: break;
6820 // // Parachute
6821 // case 45472: break;
6822 // // Alliance Flag, Extra Damage Debuff
6823 // case 45898: break;
6824 // // Horde Flag, Extra Damage Debuff
6825 // case 45899: break;
6826 // // Ahune - Summoning Rhyme Aura
6827 // case 45926: break;
6828 // // Ahune - Slippery Floor
6829 // case 45945: break;
6830 // // Ahune's Shield
6831 // case 45954: break;
6832 // // Nether Vapor Lightning
6833 // case 45960: break;
6834 // // Darkness
6835 // case 45996: break;
6836 // // Summon Blood Elves Periodic
6837 // case 46041: break;
6838 // // Transform Visual Missile Periodic
6839 // case 46205: break;
6840 // // Find Opening Beam End
6841 // case 46333: break;
6842 // // Ice Spear Control Aura
6843 // case 46371: break;
6844 // // Hailstone Chill
6845 // case 46458: break;
6846 // // Hailstone Chill, Internal
6847 // case 46465: break;
6848 // // Chill, Internal Shifter
6849 // case 46549: break;
6850 // // Summon Ice Spear Knockback Delayer
6851 // case 46878: break;
6852 // // Burninate Effect
6853 // case 47214: break;
6854 // // Fizzcrank Practice Parachute
6855 // case 47228: break;
6856 // // Send Mug Control Aura
6857 // case 47369: break;
6858 // // Direbrew's Disarm (precast)
6859 // case 47407: break;
6860 // // Mole Machine Port Schedule
6861 // case 47489: break;
6862 // case 47941: break; // Crystal Spike
6863 // case 48200: break; // Healer Aura
6864 // case 48630: break; // Summon Gauntlet Mobs Periodic
6865 // case 49313: break; // Proximity Mine Area Aura
6866 // // Mole Machine Portal Schedule
6867 // case 49466: break;
6868 // case 49555: break; // Corpse Explode
6869 // case 49592: break; // Temporal Rift
6870 // case 49957: break; // Cutting Laser
6871 // case 50085: break; // Slow Fall
6872 // // Listening to Music
6873 // case 50493: break;
6874 // // Love Rocket Barrage
6875 // case 50530: break;
6876 // Exist more after, need add later
6877 default:
6878 break;
6880 break;
6881 case SPELLFAMILY_MAGE:
6883 // Mirror Image
6884 // if (spell->Id == 55342)
6885 // return;
6886 break;
6888 case SPELLFAMILY_DRUID:
6890 switch (spell->Id)
6892 // Frenzied Regeneration
6893 case 22842:
6895 // Converts up to 10 rage per second into health for $d. Each point of rage is converted into ${$m2/10}.1% of max health.
6896 // Should be manauser
6897 if (m_target->getPowerType() != POWER_RAGE)
6898 return;
6899 uint32 rage = m_target->GetPower(POWER_RAGE);
6900 // Nothing todo
6901 if (rage == 0)
6902 return;
6903 int32 mod = (rage < 100) ? rage : 100;
6904 int32 points = m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
6905 int32 regen = m_target->GetMaxHealth() * (mod * points / 10) / 1000;
6906 m_target->CastCustomSpell(m_target, 22845, &regen, NULL, NULL, true, NULL, this);
6907 m_target->SetPower(POWER_RAGE, rage-mod);
6908 return;
6910 // Force of Nature
6911 case 33831:
6912 return;
6913 default:
6914 break;
6916 break;
6918 case SPELLFAMILY_ROGUE:
6920 switch (spell->Id)
6922 case 51690:
6924 std::list<Unit*> targets;
6926 // eff_radius ==0
6927 float radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spell->rangeIndex));
6929 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(),caster->GetPositionY()));
6930 Cell cell(p);
6931 cell.data.Part.reserved = ALL_DISTRICT;
6933 MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck u_check(caster, caster, radius);
6934 MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck> checker(caster,targets, u_check);
6936 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker);
6937 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
6939 CellLock<GridReadGuard> cell_lock(cell, p);
6941 cell_lock->Visit(cell_lock, grid_object_checker, *caster->GetMap());
6942 cell_lock->Visit(cell_lock, world_object_checker, *caster->GetMap());
6945 if(targets.empty())
6946 return;
6948 std::list<Unit*>::const_iterator itr = targets.begin();
6949 std::advance(itr, rand()%targets.size());
6950 Unit* target = *itr;
6952 caster->CastSpell(target, 57840, true);
6953 caster->CastSpell(target, 57841, true);
6954 return;
6956 // Master of Subtlety
6957 // case 31666: break;
6958 // Killing Spree
6959 // case 51690: break;
6960 // Overkill
6961 // case 58428: break;
6962 // default:
6963 // break;
6965 break;
6967 case SPELLFAMILY_HUNTER:
6969 // Explosive Shot
6970 if (spell->SpellFamilyFlags & UI64LIT(0x8000000000000000))
6972 m_target->CastCustomSpell(m_target, 53352, &m_modifier.m_amount, 0, 0, true, 0, this, GetCasterGUID());
6973 return;
6975 switch (spell->Id)
6977 // Harpooner's Mark
6978 // case 40084:
6979 // return;
6980 // Feeding Frenzy Rank 1
6981 case 53511:
6982 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
6983 m_target->CastSpell(m_target, 60096, true, 0, this);
6984 return;
6985 // Feeding Frenzy Rank 2
6986 case 53512:
6987 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
6988 m_target->CastSpell(m_target, 60097, true, 0, this);
6989 return;
6990 default:
6991 break;
6993 break;
6995 case SPELLFAMILY_SHAMAN:
6997 // Astral Shift
6998 if (spell->Id == 52179)
7000 // Periodic need for remove visual on stun/fear/silence lost
7001 if (!(m_target->GetUInt32Value(UNIT_FIELD_FLAGS)&(UNIT_FLAG_STUNNED|UNIT_FLAG_FLEEING|UNIT_FLAG_SILENCED)))
7002 m_target->RemoveAurasDueToSpell(52179);
7003 return;
7005 break;
7007 case SPELLFAMILY_DEATHKNIGHT:
7009 // Death and Decay
7010 if (spell->SpellFamilyFlags & UI64LIT(0x0000000000000020))
7012 if (caster)
7013 caster->CastCustomSpell(m_target, 52212, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
7014 return;
7016 // Raise Dead
7017 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000001000))
7018 // return;
7019 // Chains of Ice
7020 if (spell->SpellFamilyFlags & UI64LIT(0x0000400000000000))
7022 // Get 0 effect aura
7023 Aura *slow = m_target->GetAura(GetId(), 0);
7024 if (slow)
7026 slow->ApplyModifier(false, true);
7027 Modifier *mod = slow->GetModifier();
7028 mod->m_amount+= m_modifier.m_amount;
7029 if (mod->m_amount > 0) mod->m_amount = 0;
7030 slow->ApplyModifier(true, true);
7032 return;
7034 // Summon Gargoyle
7035 // if (spell->SpellFamilyFlags & UI64LIT(0x0000008000000000))
7036 // return;
7037 // Death Rune Mastery
7038 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000004000))
7039 // return;
7040 // Bladed Armor
7041 if (spell->SpellIconID == 2653)
7043 // Increases your attack power by $s1 for every $s2 armor value you have.
7044 // Calculate AP bonus (from 1 efect of this spell)
7045 int32 apBonus = m_modifier.m_amount * m_target->GetArmor() / m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7046 m_target->CastCustomSpell(m_target, 61217, &apBonus, &apBonus, NULL, true, NULL, this);
7047 return;
7049 // Reaping
7050 // if (spell->SpellIconID == 22)
7051 // return;
7052 // Blood of the North
7053 // if (spell->SpellIconID == 30412)
7054 // return;
7055 break;
7057 default:
7058 break;
7062 void Aura::HandlePreventFleeing(bool apply, bool Real)
7064 if(!Real)
7065 return;
7067 Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
7068 if( !fearAuras.empty() )
7070 if (apply)
7071 m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
7072 else
7073 m_target->SetFeared(true);
7077 void Aura::HandleManaShield(bool apply, bool Real)
7079 if(!Real)
7080 return;
7082 // prevent double apply bonuses
7083 if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
7085 if(Unit* caster = GetCaster())
7087 float DoneActualBenefit = 0.0f;
7088 switch(m_spellProto->SpellFamilyName)
7090 case SPELLFAMILY_MAGE:
7091 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x8000))
7093 // Mana Shield
7094 // +50% from +spd bonus
7095 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
7096 break;
7098 break;
7099 default:
7100 break;
7103 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
7105 m_modifier.m_amount += (int32)DoneActualBenefit;
7110 void Aura::HandleArenaPreparation(bool apply, bool Real)
7112 if(!Real)
7113 return;
7115 if(apply)
7116 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7117 else
7118 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7122 * Such auras are applied from a caster(=player) to a vehicle.
7123 * This has been verified using spell #49256
7125 void Aura::HandleAuraControlVehicle(bool apply, bool Real)
7127 if(!Real)
7128 return;
7130 Unit *player = GetCaster();
7131 Vehicle *vehicle = dynamic_cast<Vehicle*>(m_target);
7132 if(!player || player->GetTypeId() != TYPEID_PLAYER || !vehicle)
7133 return;
7135 if (apply)
7137 if(Pet *pet = player->GetPet())
7138 pet->Remove(PET_SAVE_AS_CURRENT);
7139 ((Player*)player)->EnterVehicle(vehicle);
7141 else
7143 SpellEntry const *spell = GetSpellProto();
7145 // some SPELL_AURA_CONTROL_VEHICLE auras have a dummy effect on the player - remove them
7146 player->RemoveAurasDueToSpell(spell->Id);
7148 ((Player*)player)->ExitVehicle(vehicle);
7152 void Aura::HandleAuraConvertRune(bool apply, bool Real)
7154 if(!Real)
7155 return;
7157 if(m_target->GetTypeId() != TYPEID_PLAYER)
7158 return;
7160 Player *plr = (Player*)m_target;
7162 if(plr->getClass() != CLASS_DEATH_KNIGHT)
7163 return;
7165 // how to determine what rune need to be converted?
7166 for(uint32 i = 0; i < MAX_RUNES; ++i)
7168 if(apply)
7170 if(!plr->GetRuneCooldown(i))
7172 plr->ConvertRune(i, GetSpellProto()->EffectMiscValueB[m_effIndex]);
7173 break;
7176 else
7178 if(plr->GetCurrentRune(i) == GetSpellProto()->EffectMiscValueB[m_effIndex])
7180 plr->ConvertRune(i, plr->GetBaseRune(i));
7181 break;
7187 void Aura::HandlePhase(bool apply, bool Real)
7189 if(!Real)
7190 return;
7192 // always non stackable
7193 if(apply)
7195 Unit::AuraList const& phases = m_target->GetAurasByType(SPELL_AURA_PHASE);
7196 if(!phases.empty())
7197 m_target->RemoveAurasDueToSpell(phases.front()->GetId(), this);
7200 // no-phase is also phase state so same code for apply and remove
7202 // phase auras normally not expected at BG but anyway better check
7203 if(m_target->GetTypeId() == TYPEID_PLAYER)
7205 // drop flag at invisible in bg
7206 if(((Player*)m_target)->InBattleGround())
7207 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
7208 bg->EventPlayerDroppedFlag((Player*)m_target);
7210 // GM-mode have mask 0xFFFFFFFF
7211 if(!((Player*)m_target)->isGameMaster())
7212 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7214 ((Player*)m_target)->GetSession()->SendSetPhaseShift(apply ? GetMiscValue() : PHASEMASK_NORMAL);
7216 if(GetEffIndex()==0)
7218 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
7219 if(saBounds.first != saBounds.second)
7221 uint32 zone, area;
7222 m_target->GetZoneAndAreaId(zone, area);
7224 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
7226 // some auras remove at aura remove
7227 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
7228 m_target->RemoveAurasDueToSpell(itr->second->spellId);
7229 // some auras applied at aura apply
7230 else if(itr->second->autocast)
7232 if( !m_target->HasAura(itr->second->spellId, 0) )
7233 m_target->CastSpell(m_target, itr->second->spellId, true);
7239 else
7240 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7242 // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases)
7243 if(m_target->GetVisibility() != VISIBILITY_OFF)
7244 m_target->SetVisibility(m_target->GetVisibility());
7247 void Aura::UnregisterSingleCastAura()
7249 if (IsSingleTarget())
7251 if(Unit* caster = GetCaster())
7253 caster->GetSingleCastAuras().remove(this);
7255 else
7257 sLog.outError("Couldn't find the caster of the single target aura (SpellId %u), may crash later!", GetId());
7258 assert(false);
7260 m_isSingleTargetAura = false;
7264 void Aura::HandleAuraSafeFall( bool Apply, bool Real )
7266 // implemented in WorldSession::HandleMovementOpcodes
7268 // only special case
7269 if(Apply && Real && GetId() == 32474 && m_target->GetTypeId() == TYPEID_PLAYER)
7270 ((Player*)m_target)->ActivateTaxiPathTo(506, GetId());
7273 bool Aura::IsCritFromAbilityAura(Unit* caster, uint32& damage)
7275 Unit::AuraList const& auras = caster->GetAurasByType(SPELL_AURA_ABILITY_PERIODIC_CRIT);
7276 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
7278 if (!(*itr)->isAffectedOnSpell(m_spellProto))
7279 continue;
7280 if (!caster->isSpellCrit(m_target, m_spellProto, GetSpellSchoolMask(m_spellProto)))
7281 break;
7283 damage = caster->SpellCriticalDamageBonus(m_spellProto, damage, m_target);
7284 return true;
7286 return false;
7289 void Aura::HandleModTargetArmorPct(bool apply, bool Real)
7291 if(m_target->GetTypeId() != TYPEID_PLAYER)
7292 return;
7294 ((Player*)m_target)->UpdateArmorPenetration();