[8509] Some absorb shield aura fixes for specific spells.
[getmangos.git] / src / game / SpellAuras.cpp
blobf50a8a1f51e2385b9df3d9ff0d0d82bf6d1e7e76
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 undetactable invisibility? implemented in Unit::isVisibleForOrDetect
315 &Aura::HandleNULL, //262
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
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 not used by any spells (3.08a)
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 not used by any spells (3.09) except 1 test spell.
342 &Aura::HandleUnused, //289 unused
343 &Aura::HandleUnused, //290 unused
344 &Aura::HandleUnused, //291 unused
345 &Aura::HandleNULL, //292 call stabled pet
346 &Aura::HandleNULL, //293 2 test spells
347 &Aura::HandleNULL //294 2 spells, possible prevent mana regen
350 static AuraType const frozenAuraTypes[] = { SPELL_AURA_MOD_ROOT, SPELL_AURA_MOD_STUN, SPELL_AURA_NONE };
352 Aura::Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem) :
353 m_spellmod(NULL), m_caster_guid(0), m_target(target), m_castItemGuid(castItem?castItem->GetGUID():0),
354 m_timeCla(1000), m_periodicTimer(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE),
355 m_effIndex(eff), m_auraSlot(MAX_AURAS), m_auraFlags(AFLAG_NONE), m_auraLevel(1), m_procCharges(0), m_stackAmount(1),
356 m_positive(false), m_permanent(false), m_isPeriodic(false), m_isAreaAura(false), m_isPersistent(false),
357 m_isRemovedOnShapeLost(true), m_in_use(0), m_deleted(false)
359 assert(target);
361 assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
363 m_spellProto = spellproto;
365 m_currentBasePoints = currentBasePoints ? *currentBasePoints : m_spellProto->EffectBasePoints[eff];
367 m_isPassive = IsPassiveSpell(GetId());
368 m_positive = IsPositiveEffect(GetId(), m_effIndex);
370 m_isSingleTargetAura = IsSingleTargetSpell(m_spellProto);
372 m_applyTime = time(NULL);
374 int32 damage;
375 if(!caster)
377 m_caster_guid = target->GetGUID();
378 damage = m_currentBasePoints+1; // stored value-1
379 m_maxduration = target->CalculateSpellDuration(m_spellProto, m_effIndex, target);
381 else
383 m_caster_guid = caster->GetGUID();
385 damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target);
386 m_maxduration = caster->CalculateSpellDuration(m_spellProto, m_effIndex, target);
388 if (!damage && castItem && castItem->GetItemSuffixFactor())
390 ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
391 if(item_rand_suffix)
393 for (int k = 0; k < 3; ++k)
395 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand_suffix->enchant_id[k]);
396 if(pEnchant)
398 for (int t = 0; t < 3; ++t)
399 if(pEnchant->spellid[t] == m_spellProto->Id)
401 damage = uint32((item_rand_suffix->prefix[k]*castItem->GetItemSuffixFactor()) / 10000 );
402 break;
406 if(damage)
407 break;
413 if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0)
414 m_permanent = true;
416 Player* modOwner = caster ? caster->GetSpellModOwner() : NULL;
418 if(!m_permanent && modOwner)
420 modOwner->ApplySpellMod(GetId(), SPELLMOD_DURATION, m_maxduration);
421 // Get zero duration aura after - need set m_maxduration > 0 for apply/remove aura work
422 if (m_maxduration<=0)
423 m_maxduration = 1;
426 m_duration = m_maxduration;
428 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);
430 m_effIndex = eff;
431 SetModifier(AuraType(m_spellProto->EffectApplyAuraName[eff]), damage, m_spellProto->EffectAmplitude[eff], m_spellProto->EffectMiscValue[eff]);
433 // Apply periodic time mod
434 if(modOwner && m_modifier.periodictime)
435 modOwner->ApplySpellMod(GetId(), SPELLMOD_ACTIVATION_TIME, m_modifier.periodictime);
437 // Start periodic on next tick or at aura apply
438 if (!(m_spellProto->AttributesEx5 & SPELL_ATTR_EX5_START_PERIODIC_AT_APPLY))
439 m_periodicTimer += m_modifier.periodictime;
441 m_isDeathPersist = IsDeathPersistentSpell(m_spellProto);
443 m_procCharges = m_spellProto->procCharges;
444 if(modOwner)
445 modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
447 m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() &&
448 m_spellProto->Stances &&
449 !(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) &&
450 !(m_spellProto->Attributes & SPELL_ATTR_NOT_SHAPESHIFT));
453 Aura::~Aura()
457 AreaAura::AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
458 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
460 m_isAreaAura = true;
462 // caster==NULL in constructor args if target==caster in fact
463 Unit* caster_ptr = caster ? caster : target;
465 m_radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
466 if(Player* modOwner = caster_ptr->GetSpellModOwner())
467 modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
469 switch(spellproto->Effect[eff])
471 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
472 m_areaAuraType = AREA_AURA_PARTY;
473 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
474 m_modifier.m_auraname = SPELL_AURA_NONE;
475 break;
476 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
477 m_areaAuraType = AREA_AURA_RAID;
478 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
479 m_modifier.m_auraname = SPELL_AURA_NONE;
480 // Light's Beacon not applied to caster itself (TODO: more generic check for another simialr spell if any?)
481 else if (target == caster_ptr && m_spellProto->Id == 53651)
482 m_modifier.m_auraname = SPELL_AURA_NONE;
483 break;
484 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
485 m_areaAuraType = AREA_AURA_FRIEND;
486 break;
487 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
488 m_areaAuraType = AREA_AURA_ENEMY;
489 if (target == caster_ptr)
490 m_modifier.m_auraname = SPELL_AURA_NONE; // Do not do any effect on self
491 break;
492 case SPELL_EFFECT_APPLY_AREA_AURA_PET:
493 m_areaAuraType = AREA_AURA_PET;
494 break;
495 case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
496 m_areaAuraType = AREA_AURA_OWNER;
497 if (target == caster_ptr)
498 m_modifier.m_auraname = SPELL_AURA_NONE;
499 break;
500 default:
501 sLog.outError("Wrong spell effect in AreaAura constructor");
502 ASSERT(false);
503 break;
507 AreaAura::~AreaAura()
511 PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
512 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
514 m_isPersistent = true;
517 PersistentAreaAura::~PersistentAreaAura()
521 SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
522 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
524 if (caster)
525 m_casters_target_guid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelection() : caster->GetUInt64Value(UNIT_FIELD_TARGET);
526 else
527 m_casters_target_guid = 0;
530 SingleEnemyTargetAura::~SingleEnemyTargetAura()
534 Unit* SingleEnemyTargetAura::GetTriggerTarget() const
536 return ObjectAccessor::GetUnit(*m_target, m_casters_target_guid);
539 Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem)
541 if (IsAreaAuraEffect(spellproto->Effect[eff]))
542 return new AreaAura(spellproto, eff, currentBasePoints, target, caster, castItem);
544 uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff];
546 if(SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
547 for (int i = 0; i < 3; ++i)
548 if (triggeredSpellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_ENEMY)
549 return new SingleEnemyTargetAura(spellproto, eff, currentBasePoints, target, caster, castItem);
551 return new Aura(spellproto, eff, currentBasePoints, target, caster, castItem);
554 Unit* Aura::GetCaster() const
556 if(m_caster_guid==m_target->GetGUID())
557 return m_target;
559 //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
560 //must return caster even if it's in another grid/map
561 Unit *unit = ObjectAccessor::GetObjectInWorld(m_caster_guid, (Unit*)NULL);
562 return unit && unit->IsInWorld() ? unit : NULL;
565 void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
567 m_modifier.m_auraname = t;
568 m_modifier.m_amount = a;
569 m_modifier.m_miscvalue = miscValue;
570 m_modifier.periodictime = pt;
573 void Aura::Update(uint32 diff)
575 if (m_duration > 0)
577 m_duration -= diff;
578 if (m_duration < 0)
579 m_duration = 0;
580 m_timeCla -= diff;
582 // GetEffIndex()==0 prevent double/triple apply manaPerSecond/manaPerSecondPerLevel to same spell with many auras
583 // all spells with manaPerSecond/manaPerSecondPerLevel have aura in effect 0
584 if(GetEffIndex()==0 && m_timeCla <= 0)
586 if(Unit* caster = GetCaster())
588 Powers powertype = Powers(m_spellProto->powerType);
589 int32 manaPerSecond = m_spellProto->manaPerSecond + m_spellProto->manaPerSecondPerLevel * caster->getLevel();
590 m_timeCla = 1*IN_MILISECONDS;
591 if (manaPerSecond)
593 if(powertype==POWER_HEALTH)
594 caster->ModifyHealth(-manaPerSecond);
595 else
596 caster->ModifyPower(powertype,-manaPerSecond);
602 // Channeled aura required check distance from caster
603 if(IsChanneledSpell(m_spellProto) && m_caster_guid != m_target->GetGUID())
605 Unit* caster = GetCaster();
606 if(!caster)
608 m_target->RemoveAura(GetId(), GetEffIndex());
609 return;
612 // Get spell range
613 float radius;
614 SpellModOp mod;
615 if (m_spellProto->EffectRadiusIndex[GetEffIndex()])
617 radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellProto->EffectRadiusIndex[GetEffIndex()]));
618 mod = SPELLMOD_RADIUS;
620 else
622 radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellProto->rangeIndex));
623 mod = SPELLMOD_RANGE;
626 if(Player* modOwner = caster->GetSpellModOwner())
627 modOwner->ApplySpellMod(GetId(), mod, radius, NULL);
629 if(!caster->IsWithinDistInMap(m_target, radius))
631 m_target->RemoveAura(GetId(), GetEffIndex());
632 return;
636 if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
638 m_periodicTimer -= diff;
639 if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
641 // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls)
642 m_periodicTimer += m_modifier.periodictime;
643 PeriodicTick();
648 void AreaAura::Update(uint32 diff)
650 // update for the caster of the aura
651 if(m_caster_guid == m_target->GetGUID())
653 Unit* caster = m_target;
655 if( !caster->hasUnitState(UNIT_STAT_ISOLATED) )
657 Unit* owner = caster->GetCharmerOrOwner();
658 if (!owner)
659 owner = caster;
660 std::list<Unit *> targets;
662 switch(m_areaAuraType)
664 case AREA_AURA_PARTY:
666 Group *pGroup = NULL;
668 if (owner->GetTypeId() == TYPEID_PLAYER)
669 pGroup = ((Player*)owner)->GetGroup();
671 if( pGroup)
673 uint8 subgroup = ((Player*)owner)->GetSubGroup();
674 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
676 Player* Target = itr->getSource();
677 if(Target && Target->isAlive() && Target->GetSubGroup()==subgroup && caster->IsFriendlyTo(Target))
679 if(caster->IsWithinDistInMap(Target, m_radius))
680 targets.push_back(Target);
681 Pet *pet = Target->GetPet();
682 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
683 targets.push_back(pet);
687 else
689 // add owner
690 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
691 targets.push_back(owner);
692 // add caster's pet
693 Unit* pet = caster->GetPet();
694 if( pet && caster->IsWithinDistInMap(pet, m_radius))
695 targets.push_back(pet);
697 break;
699 case AREA_AURA_RAID:
701 Group *pGroup = NULL;
703 if (owner->GetTypeId() == TYPEID_PLAYER)
704 pGroup = ((Player*)owner)->GetGroup();
706 if( pGroup)
708 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
710 Player* Target = itr->getSource();
711 if(Target && Target->isAlive() && caster->IsFriendlyTo(Target))
713 if(caster->IsWithinDistInMap(Target, m_radius))
714 targets.push_back(Target);
715 Pet *pet = Target->GetPet();
716 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
717 targets.push_back(pet);
721 else
723 // add owner
724 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
725 targets.push_back(owner);
726 // add caster's pet
727 Unit* pet = caster->GetPet();
728 if( pet && caster->IsWithinDistInMap(pet, m_radius))
729 targets.push_back(pet);
731 break;
733 case AREA_AURA_FRIEND:
735 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
736 Cell cell(p);
737 cell.data.Part.reserved = ALL_DISTRICT;
738 cell.SetNoCreate();
740 MaNGOS::AnyFriendlyUnitInObjectRangeCheck u_check(caster, owner, m_radius);
741 MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck> searcher(caster,targets, u_check);
742 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
743 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
744 CellLock<GridReadGuard> cell_lock(cell, p);
745 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap());
746 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap());
747 break;
749 case AREA_AURA_ENEMY:
751 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
752 Cell cell(p);
753 cell.data.Part.reserved = ALL_DISTRICT;
754 cell.SetNoCreate();
756 MaNGOS::AnyAoETargetUnitInObjectRangeCheck u_check(caster, owner, m_radius); // No GetCharmer in searcher
757 MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck> searcher(caster, targets, u_check);
758 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
759 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
760 CellLock<GridReadGuard> cell_lock(cell, p);
761 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap());
762 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap());
763 break;
765 case AREA_AURA_OWNER:
766 case AREA_AURA_PET:
768 if(owner != caster)
769 targets.push_back(owner);
770 break;
774 for(std::list<Unit *>::iterator tIter = targets.begin(); tIter != targets.end(); tIter++)
776 // flag for seelction is need apply aura to current iteration target
777 bool apply = true;
779 // we need ignore present caster self applied are auras sometime
780 // in cases if this only auras applied for spell effect
781 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), m_effIndex);
782 for(Unit::AuraMap::const_iterator i = (*tIter)->GetAuras().lower_bound(spair); i != (*tIter)->GetAuras().upper_bound(spair); ++i)
784 if (i->second->IsDeleted())
785 continue;
787 switch(m_areaAuraType)
789 case AREA_AURA_ENEMY:
790 // non caster self-casted auras (non stacked)
791 if(i->second->GetModifier()->m_auraname != SPELL_AURA_NONE)
792 apply = false;
793 break;
794 case AREA_AURA_RAID:
795 // non caster self-casted auras (stacked from diff. casters)
796 if(i->second->GetModifier()->m_auraname != SPELL_AURA_NONE || i->second->GetCasterGUID() == GetCasterGUID())
797 apply = false;
798 break;
799 default:
800 // in generic case not allow stacking area auras
801 apply = false;
802 break;
805 if(!apply)
806 break;
809 if(!apply)
810 continue;
812 if(SpellEntry const *actualSpellInfo = spellmgr.SelectAuraRankForPlayerLevel(GetSpellProto(), (*tIter)->getLevel()))
814 int32 actualBasePoints = m_currentBasePoints;
815 // recalculate basepoints for lower rank (all AreaAura spell not use custom basepoints?)
816 if(actualSpellInfo != GetSpellProto())
817 actualBasePoints = actualSpellInfo->EffectBasePoints[m_effIndex];
818 AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
819 aur->SetAuraDuration(GetAuraDuration());
820 (*tIter)->AddAura(aur);
824 Aura::Update(diff);
826 else // aura at non-caster
828 Unit* caster = GetCaster();
830 Aura::Update(diff);
832 // remove aura if out-of-range from caster (after teleport for example)
833 // or caster is isolated or caster no longer has the aura
834 // or caster is (no longer) friendly
835 bool needFriendly = (m_areaAuraType == AREA_AURA_ENEMY ? false : true);
836 if( !caster || caster->hasUnitState(UNIT_STAT_ISOLATED) ||
837 !caster->IsWithinDistInMap(m_target, m_radius) ||
838 !caster->HasAura(GetId(), GetEffIndex()) ||
839 caster->IsFriendlyTo(m_target) != needFriendly
842 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(),GetCasterGUID());
844 else if( m_areaAuraType == AREA_AURA_PARTY) // check if in same sub group
846 // not check group if target == owner or target == pet
847 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
849 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
851 Group *pGroup = check ? check->GetGroup() : NULL;
852 if( pGroup )
854 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
855 if(!checkTarget || !pGroup->SameSubGroup(check, checkTarget))
856 m_target->RemoveAura(GetId(), GetEffIndex());
858 else
859 m_target->RemoveAura(GetId(), GetEffIndex());
862 else if( m_areaAuraType == AREA_AURA_RAID) // TODO: fix me!
864 // not check group if target == owner or target == pet
865 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
867 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
869 Group *pGroup = check ? check->GetGroup() : NULL;
870 if( pGroup )
872 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
873 if(!checkTarget)
874 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
876 else
877 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
880 else if( m_areaAuraType == AREA_AURA_PET || m_areaAuraType == AREA_AURA_OWNER )
882 if( m_target->GetGUID() != caster->GetCharmerOrOwnerGUID() )
883 m_target->RemoveAurasByCasterSpell(GetId(), GetEffIndex(), GetCasterGUID());
888 void PersistentAreaAura::Update(uint32 diff)
890 bool remove = false;
892 // remove the aura if its caster or the dynamic object causing it was removed
893 // or if the target moves too far from the dynamic object
894 if(Unit *caster = GetCaster())
896 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
897 if (dynObj)
899 if (!m_target->IsWithinDistInMap(dynObj, dynObj->GetRadius()))
900 remove = true;
902 else
903 remove = true;
905 else
906 remove = true;
908 Aura::Update(diff);
910 if(remove)
911 m_target->RemoveAura(GetId(), GetEffIndex());
914 void Aura::ApplyModifier(bool apply, bool Real)
916 AuraType aura = m_modifier.m_auraname;
918 SetInUse(true);
919 if(aura < TOTAL_AURAS)
920 (*this.*AuraHandler [aura])(apply, Real);
921 SetInUse(false);
924 bool Aura::IsNeedVisibleSlot(Unit const* caster) const
926 bool totemAura = caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem();
928 // passive auras (except totem auras) do not get placed in the slots
929 if (m_isPassive && !totemAura)
930 return false;
932 // generic not caster case
933 if (m_target != caster)
934 return true;
936 // special area auras case at caster
937 switch(m_spellProto->Effect[GetEffIndex()])
939 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
940 return false;
941 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
942 // not sure is totemAura need, just preserve old code results
943 return totemAura || m_modifier.m_auraname != SPELL_AURA_NONE;
944 default: break;
947 return true;
950 void Aura::_AddAura()
952 if (!GetId())
953 return;
954 if(!m_target)
955 return;
957 // Second aura if some spell
958 bool secondaura = false;
959 // Try find slot for aura
960 uint8 slot = NULL_AURA_SLOT;
961 // Lookup for some spell auras (and get slot from it)
962 for(uint8 i = 0; i < m_effIndex; ++i)
964 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
965 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
967 // allow use single slot only by auras from same caster
968 if(itr->second->GetCasterGUID()==GetCasterGUID())
970 slot = itr->second->GetAuraSlot();
971 secondaura = true;
972 break;
975 if (secondaura)
976 break;
978 // Lookup free slot
979 if (!secondaura && m_target->GetVisibleAurasCount() < MAX_AURAS)
981 Unit::VisibleAuraMap const *visibleAuras = m_target->GetVisibleAuras();
982 for(uint8 i = 0; i < MAX_AURAS; ++i)
984 Unit::VisibleAuraMap::const_iterator itr = visibleAuras->find(i);
985 if(itr == visibleAuras->end())
987 slot = i;
988 // update for out of range group members (on 1 slot use)
989 m_target->UpdateAuraForGroup(slot);
990 break;
995 Unit* caster = GetCaster();
997 // set infinity cooldown state for spells
998 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1000 if (m_spellProto->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)
1002 Item* castItem = m_castItemGuid ? ((Player*)caster)->GetItemByGuid(m_castItemGuid) : NULL;
1003 ((Player*)caster)->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true);
1007 if (IsNeedVisibleSlot(caster))
1009 SetAuraSlot( slot );
1010 if(slot < MAX_AURAS) // slot found send data to client
1012 SetAura(false);
1013 SetAuraFlags((1 << GetEffIndex()) | AFLAG_NOT_CASTER | ((GetAuraMaxDuration() > 0) ? AFLAG_DURATION : AFLAG_NONE) | (IsPositive() ? AFLAG_POSITIVE : AFLAG_NEGATIVE));
1014 SetAuraLevel(caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
1015 SendAuraUpdate(false);
1018 //*****************************************************
1019 // Update target aura state flag (at 1 aura apply)
1020 // TODO: Make it easer
1021 //*****************************************************
1022 if (!secondaura)
1024 // Sitdown on apply aura req seated
1025 if (m_spellProto->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED && !m_target->IsSitState())
1026 m_target->SetStandState(UNIT_STAND_STATE_SIT);
1028 // register aura diminishing on apply
1029 if (getDiminishGroup() != DIMINISHING_NONE )
1030 m_target->ApplyDiminishingAura(getDiminishGroup(), true);
1032 // Update Seals information
1033 if (IsSealSpell(m_spellProto))
1034 m_target->ModifyAuraState(AURA_STATE_JUDGEMENT, true);
1036 // Conflagrate aura state on Immolate and Shadowflame
1037 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARLOCK &&
1038 // Immolate
1039 ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1040 // Shadowflame
1041 (m_spellProto->SpellFamilyFlags2 & 0x00000002)))
1042 m_target->ModifyAuraState(AURA_STATE_CONFLAGRATE, true);
1044 // Faerie Fire (druid versions)
1045 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
1046 m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE, true);
1048 // Victorious
1049 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARRIOR && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
1050 m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, true);
1052 // Swiftmend state on Regrowth & Rejuvenation
1053 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x50)))
1054 m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, true);
1056 // Deadly poison aura state
1057 if(m_spellProto->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellProto->SpellFamilyFlags & UI64LIT(0x10000)))
1058 m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON, true);
1060 // Enrage aura state
1061 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1062 m_target->ModifyAuraState(AURA_STATE_ENRAGE, true);
1067 bool Aura::_RemoveAura()
1069 // Remove all triggered by aura spells vs unlimited duration
1070 // except same aura replace case
1071 if(m_removeMode!=AURA_REMOVE_BY_STACK)
1072 CleanupTriggeredSpells();
1074 Unit* caster = GetCaster();
1076 if(caster && IsPersistent())
1078 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
1079 if (dynObj)
1080 dynObj->RemoveAffected(m_target);
1083 //passive auras do not get put in slots
1084 // Note: but totem can be not accessible for aura target in time remove (to far for find in grid)
1085 //if(m_isPassive && !(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()))
1086 // return;
1088 uint8 slot = GetAuraSlot();
1090 if(slot >= MAX_AURAS) // slot not set
1091 return false;
1093 if(m_target->GetVisibleAura(slot) == 0)
1094 return false;
1096 bool lastaura = true;
1098 // find other aura in same slot (current already removed from list)
1099 for(uint8 i = 0; i < 3; ++i)
1101 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
1102 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
1104 if(itr->second->GetAuraSlot() == slot)
1106 lastaura = false;
1107 break;
1110 if(!lastaura)
1111 break;
1114 // only remove icon when the last aura of the spell is removed (current aura already removed from list)
1115 if (!lastaura)
1116 return false;
1118 // unregister aura diminishing (and store last time)
1119 if (getDiminishGroup() != DIMINISHING_NONE )
1120 m_target->ApplyDiminishingAura(getDiminishGroup(), false);
1122 SetAura(true);
1123 SetAuraFlags(AFLAG_NONE);
1124 SetAuraLevel(0);
1125 SendAuraUpdate(true);
1127 // update for out of range group members
1128 m_target->UpdateAuraForGroup(slot);
1130 //*****************************************************
1131 // Update target aura state flag (at last aura remove)
1132 //*****************************************************
1133 // Enrage aura state
1134 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1135 m_target->ModifyAuraState(AURA_STATE_ENRAGE, false);
1137 uint32 removeState = 0;
1138 uint64 removeFamilyFlag = m_spellProto->SpellFamilyFlags;
1139 uint32 removeFamilyFlag2 = m_spellProto->SpellFamilyFlags2;
1140 switch(m_spellProto->SpellFamilyName)
1142 case SPELLFAMILY_PALADIN:
1143 if (IsSealSpell(m_spellProto))
1144 removeState = AURA_STATE_JUDGEMENT; // Update Seals information
1145 break;
1146 case SPELLFAMILY_WARLOCK:
1147 // Conflagrate aura state on Immolate and Shadowflame,
1148 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1149 (m_spellProto->SpellFamilyFlags2 & 0x00000002))
1151 removeFamilyFlag = UI64LIT(0x0000000000000004);
1152 removeFamilyFlag2 = 0x00000002;
1153 removeState = AURA_STATE_CONFLAGRATE;
1155 break;
1156 case SPELLFAMILY_DRUID:
1157 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400))
1158 removeState = AURA_STATE_FAERIE_FIRE; // Faerie Fire (druid versions)
1159 else if(m_spellProto->SpellFamilyFlags & UI64LIT(0x50))
1161 removeFamilyFlag = 0x50;
1162 removeState = AURA_STATE_SWIFTMEND; // Swiftmend aura state
1164 break;
1165 case SPELLFAMILY_WARRIOR:
1166 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000))
1167 removeState = AURA_STATE_WARRIOR_VICTORY_RUSH; // Victorious
1168 break;
1169 case SPELLFAMILY_ROGUE:
1170 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x10000))
1171 removeState = AURA_STATE_DEADLY_POISON; // Deadly poison aura state
1172 break;
1173 case SPELLFAMILY_HUNTER:
1174 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
1175 removeState = AURA_STATE_FAERIE_FIRE; // Sting (hunter versions)
1178 // Remove state (but need check other auras for it)
1179 if (removeState)
1181 bool found = false;
1182 Unit::AuraMap& Auras = m_target->GetAuras();
1183 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
1185 SpellEntry const *auraSpellInfo = (*i).second->GetSpellProto();
1186 if(auraSpellInfo->SpellFamilyName == m_spellProto->SpellFamilyName &&
1187 (auraSpellInfo->SpellFamilyFlags & removeFamilyFlag || auraSpellInfo->SpellFamilyFlags2 & removeFamilyFlag2))
1189 found = true;
1190 break;
1193 // this has been last aura
1194 if(!found)
1195 m_target->ModifyAuraState(AuraState(removeState), false);
1198 // reset cooldown state for spells
1199 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1201 if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE )
1202 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
1203 ((Player*)caster)->SendCooldownEvent(GetSpellProto());
1206 return true;
1209 void Aura::SendAuraUpdate(bool remove)
1211 WorldPacket data(SMSG_AURA_UPDATE);
1212 data.append(m_target->GetPackGUID());
1213 data << uint8(GetAuraSlot());
1214 data << uint32(remove ? 0 : GetId());
1216 if(remove)
1218 m_target->SendMessageToSet(&data, true);
1219 return;
1222 uint8 auraFlags = GetAuraFlags();
1223 data << uint8(auraFlags);
1224 data << uint8(GetAuraLevel());
1225 data << uint8(m_procCharges ? m_procCharges*m_stackAmount : m_stackAmount);
1227 if(!(auraFlags & AFLAG_NOT_CASTER))
1229 data << uint8(0); // pguid
1232 if(auraFlags & AFLAG_DURATION)
1234 data << uint32(GetAuraMaxDuration());
1235 data << uint32(GetAuraDuration());
1238 m_target->SendMessageToSet(&data, true);
1241 void Aura::SetStackAmount(uint8 stackAmount)
1243 Unit *target = GetTarget();
1244 Unit *caster = GetCaster();
1245 if (!target || !caster)
1246 return;
1248 bool refresh = stackAmount >= m_stackAmount;
1249 if (stackAmount != m_stackAmount)
1251 m_stackAmount = stackAmount;
1252 int32 amount = m_stackAmount * caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, target);
1253 // Reapply if amount change
1254 if (amount!=m_modifier.m_amount)
1256 ApplyModifier(false, true);
1257 m_modifier.m_amount = amount;
1258 ApplyModifier(true, true);
1262 if (refresh)
1263 // Stack increased refresh duration
1264 RefreshAura();
1265 else
1266 // Stack decreased only send update
1267 SendAuraUpdate(false);
1270 bool Aura::modStackAmount(int32 num)
1272 // Can`t mod
1273 if (!m_spellProto->StackAmount)
1274 return true;
1276 // Modify stack but limit it
1277 int32 stackAmount = m_stackAmount + num;
1278 if (stackAmount > m_spellProto->StackAmount)
1279 stackAmount = m_spellProto->StackAmount;
1280 else if (stackAmount <=0) // Last aura from stack removed
1282 m_stackAmount = 0;
1283 return true; // need remove aura
1286 // Update stack amount
1287 SetStackAmount(stackAmount);
1288 return false;
1291 void Aura::RefreshAura()
1293 m_duration = m_maxduration;
1294 SendAuraUpdate(false);
1297 bool Aura::isAffectedOnSpell(SpellEntry const *spell) const
1299 // Check family name
1300 if (spell->SpellFamilyName != m_spellProto->SpellFamilyName)
1301 return false;
1302 // Check EffectClassMask
1303 uint32 const *ptr = getAuraSpellClassMask();
1304 if (((uint64*)ptr)[0] & spell->SpellFamilyFlags)
1305 return true;
1306 if (ptr[2] & spell->SpellFamilyFlags2)
1307 return true;
1308 return false;
1311 void Aura::ReapplyAffectedPassiveAuras( Unit* target )
1313 std::set<uint32> affectedPassives;
1315 for(Unit::AuraMap::const_iterator itr = target->GetAuras().begin(); itr != target->GetAuras().end(); ++itr)
1317 // permanent passive
1318 if (itr->second->IsPassive() && itr->second->IsPermanent() &&
1319 // non deleted and not same aura (any with same spell id)
1320 !itr->second->IsDeleted() && itr->second->GetId() != GetId() &&
1321 // only applied by self and affected by aura
1322 itr->second->GetCasterGUID() == target->GetGUID() && isAffectedOnSpell(itr->second->GetSpellProto()))
1324 affectedPassives.insert(itr->second->GetId());
1328 for(std::set<uint32>::const_iterator set_itr = affectedPassives.begin(); set_itr != affectedPassives.end(); ++set_itr)
1330 target->RemoveAurasDueToSpell(*set_itr);
1331 target->CastSpell(m_target, *set_itr, true);
1335 /*********************************************************/
1336 /*** BASIC AURA FUNCTION ***/
1337 /*********************************************************/
1338 void Aura::HandleAddModifier(bool apply, bool Real)
1340 if(m_target->GetTypeId() != TYPEID_PLAYER || !Real)
1341 return;
1343 if(m_modifier.m_miscvalue >= MAX_SPELLMOD)
1344 return;
1346 if (apply)
1348 // Add custom charges for some mod aura
1349 switch (m_spellProto->Id)
1351 case 17941: // Shadow Trance
1352 case 22008: // Netherwind Focus
1353 case 31834: // Light's Grace
1354 case 34754: // Clearcasting
1355 case 34936: // Backlash
1356 case 48108: // Hot Streak
1357 case 51124: // Killing Machine
1358 case 54741: // Firestarter
1359 case 57761: // Fireball!
1360 SetAuraCharges(1);
1361 break;
1364 SpellModifier *mod = new SpellModifier;
1365 mod->op = SpellModOp(m_modifier.m_miscvalue);
1366 mod->value = m_modifier.m_amount;
1367 mod->type = SpellModType(m_modifier.m_auraname); // SpellModType value == spell aura types
1368 mod->spellId = GetId();
1370 uint32 const *ptr;
1371 switch (m_effIndex)
1373 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1374 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1375 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1376 default:
1377 return;
1380 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1381 mod->mask2= (uint64)ptr[2];
1382 mod->charges = m_procCharges;
1384 m_spellmod = mod;
1387 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
1389 // reapply talents to own passive persistent auras
1390 ReapplyAffectedPassiveAuras(m_target);
1392 // re-aplly talents and passives applied to pet (it affected by player spellmods)
1393 if(Pet* pet = m_target->GetPet())
1394 ReapplyAffectedPassiveAuras(pet);
1396 for(int i = 0; i < MAX_TOTEM; ++i)
1397 if(m_target->m_TotemSlot[i])
1398 if(Creature* totem = m_target->GetMap()->GetCreature(m_target->m_TotemSlot[i]))
1399 ReapplyAffectedPassiveAuras(totem);
1401 void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
1403 // Use SpellModifier structure for check
1404 // used only fields:
1405 // spellId, mask, mask2
1406 if (apply)
1408 SpellModifier *mod = new SpellModifier;
1409 mod->spellId = GetId();
1411 uint32 const *ptr;
1412 switch (m_effIndex)
1414 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1415 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1416 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1417 default:
1418 return;
1421 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1422 mod->mask2= (uint64)ptr[2];
1423 m_spellmod = mod;
1425 else
1427 delete m_spellmod;
1428 m_spellmod = NULL;
1432 void Aura::TriggerSpell()
1434 Unit* caster = GetCaster();
1435 Unit* target = GetTriggerTarget();
1437 if(!caster || !target)
1438 return;
1440 // generic casting code with custom spells and target/caster customs
1441 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
1443 SpellEntry const *triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1444 SpellEntry const *auraSpellInfo = GetSpellProto();
1445 uint32 auraId = auraSpellInfo->Id;
1447 // specific code for cases with no trigger spell provided in field
1448 if (triggeredSpellInfo == NULL)
1450 switch(auraSpellInfo->SpellFamilyName)
1452 case SPELLFAMILY_GENERIC:
1454 switch(auraId)
1456 // Firestone Passive (1-5 ranks)
1457 case 758:
1458 case 17945:
1459 case 17947:
1460 case 17949:
1461 case 27252:
1463 if (caster->GetTypeId()!=TYPEID_PLAYER)
1464 return;
1465 Item* item = ((Player*)caster)->GetWeaponForAttack(BASE_ATTACK);
1466 if (!item)
1467 return;
1468 uint32 enchant_id = 0;
1469 switch (GetId())
1471 case 758: enchant_id = 1803; break; // Rank 1
1472 case 17945: enchant_id = 1823; break; // Rank 2
1473 case 17947: enchant_id = 1824; break; // Rank 3
1474 case 17949: enchant_id = 1825; break; // Rank 4
1475 case 27252: enchant_id = 2645; break; // Rank 5
1476 default:
1477 return;
1479 // remove old enchanting before applying new
1480 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1481 item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
1482 // add new enchanting
1483 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
1484 return;
1486 // // Periodic Mana Burn
1487 // case 812: break;
1488 // // Polymorphic Ray
1489 // case 6965: break;
1490 // // Fire Nova (1-7 ranks)
1491 // case 8350:
1492 // case 8508:
1493 // case 8509:
1494 // case 11312:
1495 // case 11313:
1496 // case 25540:
1497 // case 25544:
1498 // break;
1499 // Thaumaturgy Channel
1500 case 9712: trigger_spell_id = 21029; break;
1501 // // Egan's Blaster
1502 // case 17368: break;
1503 // // Haunted
1504 // case 18347: break;
1505 // // Ranshalla Waiting
1506 // case 18953: break;
1507 // // Inferno
1508 // case 19695: break;
1509 // // Frostwolf Muzzle DND
1510 // case 21794: break;
1511 // // Alterac Ram Collar DND
1512 // case 21866: break;
1513 // // Celebras Waiting
1514 // case 21916: break;
1515 // Brood Affliction: Bronze
1516 case 23170:
1518 m_target->CastSpell(m_target, 23171, true, 0, this);
1519 return;
1521 // // Mark of Frost
1522 // case 23184: break;
1523 // Restoration
1524 case 23493:
1526 int32 heal = caster->GetMaxHealth() / 10;
1527 caster->DealHeal(caster, heal, auraSpellInfo);
1529 int32 mana = caster->GetMaxPower(POWER_MANA);
1530 if (mana)
1532 mana /= 10;
1533 caster->EnergizeBySpell(caster, 23493, mana, POWER_MANA);
1535 return;
1537 // // Stoneclaw Totem Passive TEST
1538 // case 23792: break;
1539 // // Axe Flurry
1540 // case 24018: break;
1541 // // Mark of Arlokk
1542 // case 24210: break;
1543 // // Restoration
1544 // case 24379: break;
1545 // // Happy Pet
1546 // case 24716: break;
1547 // // Dream Fog
1548 // case 24780: break;
1549 // // Cannon Prep
1550 // case 24832: break;
1551 // // Shadow Bolt Whirl
1552 // case 24834: break;
1553 // // Stink Trap
1554 // case 24918: break;
1555 // // Mark of Nature
1556 // case 25041: break;
1557 // // Agro Drones
1558 // case 25152: break;
1559 // // Consume
1560 // case 25371: break;
1561 // // Pain Spike
1562 // case 25572: break;
1563 // // Rotate 360
1564 // case 26009: break;
1565 // // Rotate -360
1566 // case 26136: break;
1567 // // Consume
1568 // case 26196: break;
1569 // // Berserk
1570 // case 26615: break;
1571 // // Defile
1572 // case 27177: break;
1573 // // Teleport: IF/UC
1574 // case 27601: break;
1575 // // Five Fat Finger Exploding Heart Technique
1576 // case 27673: break;
1577 // // Nitrous Boost
1578 // case 27746: break;
1579 // // Steam Tank Passive
1580 // case 27747: break;
1581 // Frost Blast
1582 case 27808:
1584 int32 bpDamage = target->GetMaxHealth()*26/100;
1585 caster->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this);
1586 return;
1588 // // Detonate Mana
1589 // case 27819: break;
1590 // // Controller Timer
1591 // case 28095: break;
1592 // // Stalagg Chain
1593 // case 28096: break;
1594 // // Stalagg Tesla Passive
1595 // case 28097: break;
1596 // // Feugen Tesla Passive
1597 // case 28109: break;
1598 // // Feugen Chain
1599 // case 28111: break;
1600 // // Mark of Didier
1601 // case 28114: break;
1602 // // Communique Timer, camp
1603 // case 28346: break;
1604 // // Icebolt
1605 // case 28522: break;
1606 // // Silithyst
1607 // case 29519: break;
1608 // Inoculate Nestlewood Owlkin
1609 case 29528:
1610 if(target->GetTypeId() != TYPEID_UNIT)// prevent error reports in case ignored player target
1611 return;
1612 break;
1613 // // Overload
1614 // case 29768: break;
1615 // // Return Fire
1616 // case 29788: break;
1617 // // Return Fire
1618 // case 29793: break;
1619 // // Return Fire
1620 // case 29794: break;
1621 // // Guardian of Icecrown Passive
1622 // case 29897: break;
1623 // Feed Captured Animal
1624 case 29917: trigger_spell_id = 29916; break;
1625 // // Flame Wreath
1626 // case 29946: break;
1627 // // Flame Wreath
1628 // case 29947: break;
1629 // // Mind Exhaustion Passive
1630 // case 30025: break;
1631 // // Nether Beam - Serenity
1632 // case 30401: break;
1633 // Extract Gas
1634 case 30427:
1636 // move loot to player inventory and despawn target
1637 if(caster->GetTypeId() ==TYPEID_PLAYER &&
1638 target->GetTypeId() == TYPEID_UNIT &&
1639 ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
1641 Player* player = (Player*)caster;
1642 Creature* creature = (Creature*)target;
1643 // missing lootid has been reported on startup - just return
1644 if (!creature->GetCreatureInfo()->SkinLootId)
1645 return;
1647 player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true);
1649 creature->ForcedDespawn();
1651 return;
1653 // Quake
1654 case 30576: trigger_spell_id = 30571; break;
1655 // // Burning Maul
1656 // case 30598: break;
1657 // // Regeneration
1658 // case 30799:
1659 // case 30800:
1660 // case 30801:
1661 // break;
1662 // // Despawn Self - Smoke cloud
1663 // case 31269: break;
1664 // // Time Rift Periodic
1665 // case 31320: break;
1666 // // Corrupt Medivh
1667 // case 31326: break;
1668 // Doom
1669 case 31347:
1671 m_target->CastSpell(m_target,31350,true);
1672 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
1673 return;
1675 // Spellcloth
1676 case 31373:
1678 // Summon Elemental after create item
1679 caster->SummonCreature(17870, 0, 0, 0, caster->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
1680 return;
1682 // // Bloodmyst Tesla
1683 // case 31611: break;
1684 // // Doomfire
1685 // case 31944: break;
1686 // // Teleport Test
1687 // case 32236: break;
1688 // // Earthquake
1689 // case 32686: break;
1690 // // Possess
1691 // case 33401: break;
1692 // // Draw Shadows
1693 // case 33563: break;
1694 // // Murmur's Touch
1695 // case 33711: break;
1696 // Flame Quills
1697 case 34229:
1699 // cast 24 spells 34269-34289, 34314-34316
1700 for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
1701 caster->CastSpell(m_target, spell_id, true);
1702 for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
1703 caster->CastSpell(m_target, spell_id, true);
1704 return;
1706 // // Gravity Lapse
1707 // case 34480: break;
1708 // // Tornado
1709 // case 34683: break;
1710 // // Frostbite Rotate
1711 // case 34748: break;
1712 // // Arcane Flurry
1713 // case 34821: break;
1714 // // Interrupt Shutdown
1715 // case 35016: break;
1716 // // Interrupt Shutdown
1717 // case 35176: break;
1718 // // Inferno
1719 // case 35268: break;
1720 // // Salaadin's Tesla
1721 // case 35515: break;
1722 // // Ethereal Channel (Red)
1723 // case 35518: break;
1724 // // Nether Vapor
1725 // case 35879: break;
1726 // // Dark Portal Storm
1727 // case 36018: break;
1728 // // Burning Maul
1729 // case 36056: break;
1730 // // Living Grove Defender Lifespan
1731 // case 36061: break;
1732 // // Professor Dabiri Talks
1733 // case 36064: break;
1734 // // Kael Gaining Power
1735 // case 36091: break;
1736 // // They Must Burn Bomb Aura
1737 // case 36344: break;
1738 // // They Must Burn Bomb Aura (self)
1739 // case 36350: break;
1740 // // Stolen Ravenous Ravager Egg
1741 // case 36401: break;
1742 // // Activated Cannon
1743 // case 36410: break;
1744 // // Stolen Ravenous Ravager Egg
1745 // case 36418: break;
1746 // // Enchanted Weapons
1747 // case 36510: break;
1748 // // Cursed Scarab Periodic
1749 // case 36556: break;
1750 // // Cursed Scarab Despawn Periodic
1751 // case 36561: break;
1752 // // Vision Guide
1753 // case 36573: break;
1754 // // Cannon Charging (platform)
1755 // case 36785: break;
1756 // // Cannon Charging (self)
1757 // case 36860: break;
1758 // Remote Toy
1759 case 37027: trigger_spell_id = 37029; break;
1760 // // Mark of Death
1761 // case 37125: break;
1762 // // Arcane Flurry
1763 // case 37268: break;
1764 // // Spout
1765 // case 37429: break;
1766 // // Spout
1767 // case 37430: break;
1768 // // Karazhan - Chess NPC AI, Snapshot timer
1769 // case 37440: break;
1770 // // Karazhan - Chess NPC AI, action timer
1771 // case 37504: break;
1772 // // Karazhan - Chess: Is Square OCCUPIED aura (DND)
1773 // case 39400: break;
1774 // // Banish
1775 // case 37546: break;
1776 // // Shriveling Gaze
1777 // case 37589: break;
1778 // // Fake Aggro Radius (2 yd)
1779 // case 37815: break;
1780 // // Corrupt Medivh
1781 // case 37853: break;
1782 // Eye of Grillok
1783 case 38495:
1785 m_target->CastSpell(m_target, 38530, true);
1786 return;
1788 // Absorb Eye of Grillok (Zezzak's Shard)
1789 case 38554:
1791 if(m_target->GetTypeId() != TYPEID_UNIT)
1792 return;
1794 caster->CastSpell(caster, 38495, true);
1796 Creature* creatureTarget = (Creature*)m_target;
1798 creatureTarget->ForcedDespawn();
1799 return;
1801 // // Magic Sucker Device timer
1802 // case 38672: break;
1803 // // Tomb Guarding Charging
1804 // case 38751: break;
1805 // // Murmur's Touch
1806 // case 38794: break;
1807 // // Activate Nether-wraith Beacon (31742 Nether-wraith Beacon item)
1808 // case 39105: break;
1809 // // Drain World Tree Visual
1810 // case 39140: break;
1811 // // Quest - Dustin's Undead Dragon Visual aura
1812 // case 39259: break;
1813 // // Hellfire - The Exorcism, Jules releases darkness, aura
1814 // case 39306: break;
1815 // // Inferno
1816 // case 39346: break;
1817 // // Enchanted Weapons
1818 // case 39489: break;
1819 // // Shadow Bolt Whirl
1820 // case 39630: break;
1821 // // Shadow Bolt Whirl
1822 // case 39634: break;
1823 // // Shadow Inferno
1824 // case 39645: break;
1825 // Tear of Azzinoth Summon Channel - it's not really supposed to do anything,and this only prevents the console spam
1826 case 39857: trigger_spell_id = 39856; break;
1827 // // Soulgrinder Ritual Visual (Smashed)
1828 // case 39974: break;
1829 // // Simon Game Pre-game timer
1830 // case 40041: break;
1831 // // Knockdown Fel Cannon: The Aggro Check Aura
1832 // case 40113: break;
1833 // // Spirit Lance
1834 // case 40157: break;
1835 // // Demon Transform 2
1836 // case 40398: break;
1837 // // Demon Transform 1
1838 // case 40511: break;
1839 // // Ancient Flames
1840 // case 40657: break;
1841 // // Ethereal Ring Cannon: Cannon Aura
1842 // case 40734: break;
1843 // // Cage Trap
1844 // case 40760: break;
1845 // // Random Periodic
1846 // case 40867: break;
1847 // // Prismatic Shield
1848 // case 40879: break;
1849 // // Aura of Desire
1850 // case 41350: break;
1851 // // Dementia
1852 // case 41404: break;
1853 // // Chaos Form
1854 // case 41629: break;
1855 // // Alert Drums
1856 // case 42177: break;
1857 // // Spout
1858 // case 42581: break;
1859 // // Spout
1860 // case 42582: break;
1861 // // Return to the Spirit Realm
1862 // case 44035: break;
1863 // // Curse of Boundless Agony
1864 // case 45050: break;
1865 // // Earthquake
1866 // case 46240: break;
1867 // Personalized Weather
1868 case 46736: trigger_spell_id = 46737; break;
1869 // // Stay Submerged
1870 // case 46981: break;
1871 // // Dragonblight Ram
1872 // case 47015: break;
1873 // // Party G.R.E.N.A.D.E.
1874 // case 51510: break;
1875 default:
1876 break;
1878 break;
1880 case SPELLFAMILY_MAGE:
1882 switch(auraId)
1884 // Invisibility
1885 case 66:
1886 // Here need periodic triger reducing threat spell (or do it manually)
1887 return;
1888 default:
1889 break;
1891 break;
1893 // case SPELLFAMILY_WARRIOR:
1894 // {
1895 // switch(auraId)
1896 // {
1897 // // Wild Magic
1898 // case 23410: break;
1899 // // Corrupted Totems
1900 // case 23425: break;
1901 // default:
1902 // break;
1903 // }
1904 // break;
1905 // }
1906 // case SPELLFAMILY_PRIEST:
1907 // {
1908 // switch(auraId)
1909 // {
1910 // // Blue Beam
1911 // case 32930: break;
1912 // // Fury of the Dreghood Elders
1913 // case 35460: break;
1914 // default:
1915 // break;
1916 // }
1917 // break;
1918 // }
1919 case SPELLFAMILY_HUNTER:
1921 switch (auraId)
1923 // Sniper training
1924 case 53302:
1925 case 53303:
1926 case 53304:
1927 if (target->GetTypeId() != TYPEID_PLAYER)
1928 return;
1930 // Reset reapply counter at move
1931 if (((Player*)target)->isMoving())
1933 m_modifier.m_amount = 6;
1934 return;
1937 // We are standing at the moment
1938 if (m_modifier.m_amount > 0)
1940 --m_modifier.m_amount;
1941 return;
1944 // select rank of buff
1945 switch(auraId)
1947 case 53302: trigger_spell_id = 64418; break;
1948 case 53303: trigger_spell_id = 64419; break;
1949 case 53304: trigger_spell_id = 64420; break;
1952 // If aura is active - no need to continue
1953 if (target->HasAura(trigger_spell_id))
1954 return;
1956 break;
1957 default:
1958 break;
1960 break;
1962 case SPELLFAMILY_DRUID:
1964 switch(auraId)
1966 // Cat Form
1967 // trigger_spell_id not set and unknown effect triggered in this case, ignoring for while
1968 case 768:
1969 return;
1970 // Frenzied Regeneration
1971 case 22842:
1972 case 22895:
1973 case 22896:
1974 case 26999:
1976 int32 LifePerRage = GetModifier()->m_amount;
1978 int32 lRage = m_target->GetPower(POWER_RAGE);
1979 if(lRage > 100) // rage stored as rage*10
1980 lRage = 100;
1981 m_target->ModifyPower(POWER_RAGE, -lRage);
1982 int32 FRTriggerBasePoints = int32(lRage*LifePerRage/10);
1983 m_target->CastCustomSpell(m_target, 22845, &FRTriggerBasePoints, NULL, NULL, true, NULL, this);
1984 return;
1986 default:
1987 break;
1989 break;
1992 // case SPELLFAMILY_HUNTER:
1993 // {
1994 // switch(auraId)
1995 // {
1996 // //Frost Trap Aura
1997 // case 13810:
1998 // return;
1999 // //Rizzle's Frost Trap
2000 // case 39900:
2001 // return;
2002 // // Tame spells
2003 // case 19597: // Tame Ice Claw Bear
2004 // case 19676: // Tame Snow Leopard
2005 // case 19677: // Tame Large Crag Boar
2006 // case 19678: // Tame Adult Plainstrider
2007 // case 19679: // Tame Prairie Stalker
2008 // case 19680: // Tame Swoop
2009 // case 19681: // Tame Dire Mottled Boar
2010 // case 19682: // Tame Surf Crawler
2011 // case 19683: // Tame Armored Scorpid
2012 // case 19684: // Tame Webwood Lurker
2013 // case 19685: // Tame Nightsaber Stalker
2014 // case 19686: // Tame Strigid Screecher
2015 // case 30100: // Tame Crazed Dragonhawk
2016 // case 30103: // Tame Elder Springpaw
2017 // case 30104: // Tame Mistbat
2018 // case 30647: // Tame Barbed Crawler
2019 // case 30648: // Tame Greater Timberstrider
2020 // case 30652: // Tame Nightstalker
2021 // return;
2022 // default:
2023 // break;
2024 // }
2025 // break;
2026 // }
2027 case SPELLFAMILY_SHAMAN:
2029 switch(auraId)
2031 // Lightning Shield (The Earthshatterer set trigger after cast Lighting Shield)
2032 case 28820:
2034 // Need remove self if Lightning Shield not active
2035 Unit::AuraMap const& auras = target->GetAuras();
2036 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
2038 SpellEntry const* spell = itr->second->GetSpellProto();
2039 if( spell->SpellFamilyName == SPELLFAMILY_SHAMAN &&
2040 (spell->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
2041 return;
2043 target->RemoveAurasDueToSpell(28820);
2044 return;
2046 // Totemic Mastery (Skyshatter Regalia (Shaman Tier 6) - bonus)
2047 case 38443:
2049 bool all = true;
2050 for(int i = 0; i < MAX_TOTEM; ++i)
2052 if(!caster->m_TotemSlot[i])
2054 all = false;
2055 break;
2059 if(all)
2060 caster->CastSpell(caster, 38437, true);
2061 else
2062 caster->RemoveAurasDueToSpell(38437);
2063 return;
2065 default:
2066 break;
2068 break;
2070 default:
2071 break;
2074 // Reget trigger spell proto
2075 triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
2077 else
2079 // Spell exist but require custom code
2080 switch(auraId)
2082 // Curse of Idiocy
2083 case 1010:
2085 // TODO: spell casted by result in correct way mostly
2086 // BUT:
2087 // 1) target show casting at each triggered cast: target don't must show casting animation for any triggered spell
2088 // but must show affect apply like item casting
2089 // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
2091 // prevent cast by triggered auras
2092 if(m_caster_guid == m_target->GetGUID())
2093 return;
2095 // stop triggering after each affected stats lost > 90
2096 int32 intelectLoss = 0;
2097 int32 spiritLoss = 0;
2099 Unit::AuraList const& mModStat = m_target->GetAurasByType(SPELL_AURA_MOD_STAT);
2100 for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
2102 if ((*i)->GetId() == 1010)
2104 switch((*i)->GetModifier()->m_miscvalue)
2106 case STAT_INTELLECT: intelectLoss += (*i)->GetModifier()->m_amount; break;
2107 case STAT_SPIRIT: spiritLoss += (*i)->GetModifier()->m_amount; break;
2108 default: break;
2113 if(intelectLoss <= -90 && spiritLoss <= -90)
2114 return;
2116 caster = target;
2117 break;
2119 // Mana Tide
2120 case 16191:
2122 caster->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
2123 return;
2125 // Ground Slam
2126 case 33525:
2127 target->CastSpell(target, trigger_spell_id, true);
2128 return;
2132 // All ok cast by default case
2133 if(triggeredSpellInfo)
2134 caster->CastSpell(target, triggeredSpellInfo, true, 0, this);
2135 else if(target->GetTypeId()!=TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target))
2136 sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
2139 void Aura::TriggerSpellWithValue()
2141 Unit* caster = GetCaster();
2142 Unit* target = GetTriggerTarget();
2144 if(!caster || !target)
2145 return;
2147 // generic casting code with custom spells and target/caster customs
2148 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
2149 int32 basepoints0 = this->GetModifier()->m_amount;
2151 caster->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this);
2154 /*********************************************************/
2155 /*** AURA EFFECTS ***/
2156 /*********************************************************/
2158 void Aura::HandleAuraDummy(bool apply, bool Real)
2160 // spells required only Real aura add/remove
2161 if(!Real)
2162 return;
2164 Unit* caster = GetCaster();
2166 // AT APPLY
2167 if(apply)
2169 switch(GetId())
2171 case 1515: // Tame beast
2172 // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
2173 if( caster && m_target->CanHaveThreatList())
2174 m_target->AddThreat(caster, 10.0f);
2175 return;
2176 case 13139: // net-o-matic
2177 // root to self part of (root_target->charge->root_self sequence
2178 if(caster)
2179 caster->CastSpell(caster, 13138, true, NULL, this);
2180 return;
2181 case 39850: // Rocket Blast
2182 if(roll_chance_i(20)) // backfire stun
2183 m_target->CastSpell(m_target, 51581, true, NULL, this);
2184 return;
2185 case 43873: // Headless Horseman Laugh
2186 m_target->PlayDistanceSound(11965);
2187 return;
2188 case 46354: // Blood Elf Illusion
2189 if(caster)
2191 switch(caster->getGender())
2193 case GENDER_FEMALE:
2194 caster->CastSpell(m_target, 46356, true, NULL, this);
2195 break;
2196 case GENDER_MALE:
2197 caster->CastSpell(m_target, 46355, true, NULL, this);
2198 break;
2199 default:
2200 break;
2203 return;
2204 case 46699: // Requires No Ammo
2205 if(m_target->GetTypeId() == TYPEID_PLAYER)
2206 ((Player*)m_target)->RemoveAmmo(); // not use ammo and not allow use
2207 return;
2210 // Earth Shield
2211 if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x40000000000)))
2213 // prevent double apply bonuses
2214 if(m_target->GetTypeId() != TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2215 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2216 return;
2219 // AT REMOVE
2220 else
2222 if( m_target->GetTypeId() == TYPEID_PLAYER &&
2223 ( GetSpellProto()->Effect[0]==72 || GetSpellProto()->Effect[0]==6 &&
2224 ( GetSpellProto()->EffectApplyAuraName[0]==1 || GetSpellProto()->EffectApplyAuraName[0]==128 ) ) )
2226 // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
2227 ((Player*)m_target)->SetFarSightGUID(0);
2228 WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0);
2229 ((Player*)m_target)->GetSession()->SendPacket(&data);
2230 return;
2233 if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
2235 uint32 finalSpelId = 0;
2236 switch(GetId())
2238 case 19548: finalSpelId = 19597; break;
2239 case 19674: finalSpelId = 19677; break;
2240 case 19687: finalSpelId = 19676; break;
2241 case 19688: finalSpelId = 19678; break;
2242 case 19689: finalSpelId = 19679; break;
2243 case 19692: finalSpelId = 19680; break;
2244 case 19693: finalSpelId = 19684; break;
2245 case 19694: finalSpelId = 19681; break;
2246 case 19696: finalSpelId = 19682; break;
2247 case 19697: finalSpelId = 19683; break;
2248 case 19699: finalSpelId = 19685; break;
2249 case 19700: finalSpelId = 19686; break;
2250 case 30646: finalSpelId = 30647; break;
2251 case 30653: finalSpelId = 30648; break;
2252 case 30654: finalSpelId = 30652; break;
2253 case 30099: finalSpelId = 30100; break;
2254 case 30102: finalSpelId = 30103; break;
2255 case 30105: finalSpelId = 30104; break;
2258 if(finalSpelId)
2259 caster->CastSpell(m_target, finalSpelId, true, NULL, this);
2260 return;
2263 switch(GetId())
2265 case 2584: // Waiting to Resurrect
2267 // Waiting to resurrect spell cancel, we must remove player from resurrect queue
2268 if(m_target->GetTypeId() == TYPEID_PLAYER)
2269 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
2270 bg->RemovePlayerFromResurrectQueue(m_target->GetGUID());
2271 return;
2273 case 36730: // Flame Strike
2275 m_target->CastSpell(m_target, 36731, true, NULL, this);
2276 return;
2278 case 44191: // Flame Strike
2280 if (m_target->GetMap()->IsDungeon())
2282 uint32 spellId = m_target->GetMap()->IsHeroic() ? 46163 : 44190;
2284 m_target->CastSpell(m_target, spellId, true, NULL, this);
2286 return;
2288 case 45934: // Dark Fiend
2290 // Kill target if dispelled
2291 if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2292 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2293 return;
2295 case 46308: // Burning Winds
2297 // casted only at creatures at spawn
2298 m_target->CastSpell(m_target, 47287, true, NULL, this);
2299 return;
2303 if (caster && m_removeMode == AURA_REMOVE_BY_DEATH)
2305 // Stop caster Arcane Missle chanelling on death
2306 if (m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE &&
2307 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000800)))
2309 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2310 return;
2312 // Stop caster Penance chanelling on death
2313 if (m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST &&
2314 (m_spellProto->SpellFamilyFlags2 & UI64LIT(0x00000080)))
2316 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2317 return;
2323 // AT APPLY & REMOVE
2325 switch(m_spellProto->SpellFamilyName)
2327 case SPELLFAMILY_GENERIC:
2329 switch(GetId())
2331 // Recently Bandaged
2332 case 11196:
2333 m_target->ApplySpellImmune(GetId(), IMMUNITY_MECHANIC, GetMiscValue(), apply);
2334 return;
2335 // Unstable Power
2336 case 24658:
2338 uint32 spellId = 24659;
2339 if (apply && caster)
2341 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2342 if (!spell)
2343 return;
2345 for (int i=0; i < spell->StackAmount; ++i)
2346 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2347 return;
2349 m_target->RemoveAurasDueToSpell(spellId);
2350 return;
2352 // Restless Strength
2353 case 24661:
2355 uint32 spellId = 24662;
2356 if (apply && caster)
2358 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2359 if (!spell)
2360 return;
2361 for (int i=0; i < spell->StackAmount; ++i)
2362 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2363 return;
2365 m_target->RemoveAurasDueToSpell(spellId);
2366 return;
2368 //Summon Fire Elemental
2369 case 40133:
2371 if (!caster)
2372 return;
2374 Unit *owner = caster->GetOwner();
2375 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2377 if(apply)
2378 owner->CastSpell(owner, 8985, true);
2379 else
2380 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2382 return;
2384 //Summon Earth Elemental
2385 case 40132 :
2387 if (!caster)
2388 return;
2390 Unit *owner = caster->GetOwner();
2391 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2393 if(apply)
2394 owner->CastSpell(owner, 19704, true);
2395 else
2396 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2398 return;
2400 //Dragonmaw Illusion
2401 case 40214 :
2403 if(apply)
2405 m_target->CastSpell(m_target, 40216, true);
2406 m_target->CastSpell(m_target, 42016, true);
2408 else
2410 m_target->RemoveAurasDueToSpell(40216);
2411 m_target->RemoveAurasDueToSpell(42016);
2413 return;
2415 // LK Intro VO (1)
2416 case 58204:
2417 if(m_target->GetTypeId() == TYPEID_PLAYER)
2419 // Play part 1
2420 if(apply)
2421 m_target->PlayDirectSound(14970, (Player *)m_target);
2422 // continue in 58205
2423 else
2424 m_target->CastSpell(m_target, 58205, true);
2426 return;
2427 // LK Intro VO (2)
2428 case 58205:
2429 if(m_target->GetTypeId() == TYPEID_PLAYER)
2431 // Play part 2
2432 if(apply)
2433 m_target->PlayDirectSound(14971, (Player *)m_target);
2434 // Play part 3
2435 else
2436 m_target->PlayDirectSound(14972, (Player *)m_target);
2438 return;
2440 break;
2442 case SPELLFAMILY_MAGE:
2444 break;
2446 case SPELLFAMILY_PRIEST:
2448 // Pain and Suffering
2449 if( m_spellProto->SpellIconID == 2874 && m_target->GetTypeId()==TYPEID_PLAYER )
2451 if(apply)
2453 // Reduce backfire damage (dot damage) from Shadow Word: Death
2454 SpellModifier *mod = new SpellModifier;
2455 mod->op = SPELLMOD_DOT;
2456 mod->value = m_modifier.m_amount;
2457 mod->type = SPELLMOD_PCT;
2458 mod->spellId = GetId();
2459 mod->mask = UI64LIT(0x0000200000000000);
2460 mod->mask2= UI64LIT(0x0);
2461 m_spellmod = mod;
2463 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2464 return;
2466 break;
2468 case SPELLFAMILY_PALADIN:
2470 // Beacon of Light
2471 if (GetId() == 53563)
2473 if(apply)
2474 // original caster must be target (beacon)
2475 m_target->CastSpell(m_target,53651,true,NULL,this,m_target->GetGUID());
2476 else
2477 m_target->RemoveAurasByCasterSpell(53651,m_target->GetGUID());
2478 return;
2480 break;
2482 case SPELLFAMILY_DRUID:
2484 switch(GetId())
2486 case 34246: // Idol of the Emerald Queen
2487 case 60779: // Idol of Lush Moss
2489 if (m_target->GetTypeId() != TYPEID_PLAYER)
2490 return;
2492 if(apply)
2494 SpellModifier *mod = new SpellModifier;
2495 mod->op = SPELLMOD_DOT;
2496 mod->value = m_modifier.m_amount/7;
2497 mod->type = SPELLMOD_FLAT;
2498 mod->spellId = GetId();
2499 mod->mask = UI64LIT(0x001000000000);
2500 mod->mask2= UI64LIT(0x0);
2502 m_spellmod = mod;
2505 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2506 return;
2508 case 52610: // Savage Roar
2510 if(apply)
2512 if(m_target->m_form != FORM_CAT)
2513 return;
2515 m_target->CastSpell(m_target, 62071, true);
2517 else
2518 m_target-> RemoveAurasDueToSpell(62071);
2519 return;
2521 case 61336: // Survival Instincts
2523 if(apply)
2525 if (!m_target->IsInFeralForm())
2526 return;
2528 int32 bp0 = int32(m_target->GetMaxHealth() * m_modifier.m_amount / 100);
2529 m_target->CastCustomSpell(m_target, 50322, &bp0, NULL, NULL, true);
2531 else
2532 m_target-> RemoveAurasDueToSpell(50322);
2533 return;
2537 // Lifebloom
2538 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000))
2540 if ( apply )
2542 if ( caster )
2543 // prevent double apply bonuses
2544 if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2545 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2547 else
2549 // Final heal only on dispelled or duration end
2550 if ( !(GetAuraDuration() <= 0 || m_removeMode == AURA_REMOVE_BY_DISPEL) )
2551 return;
2553 // have a look if there is still some other Lifebloom dummy aura
2554 Unit::AuraList auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2555 for(Unit::AuraList::iterator itr = auras.begin(); itr!=auras.end(); ++itr)
2556 if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2557 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000)))
2558 return;
2560 // final heal
2561 if(m_target->IsInWorld() && m_stackAmount > 0)
2563 int32 amount = m_modifier.m_amount / m_stackAmount;
2564 m_target->CastCustomSpell(m_target, 33778, &amount, NULL, NULL, true, NULL, this, GetCasterGUID());
2566 if (caster)
2568 int32 returnmana = (GetSpellProto()->ManaCostPercentage * caster->GetCreateMana() / 100) * m_stackAmount / 2;
2569 caster->CastCustomSpell(caster, 64372, &returnmana, NULL, NULL, true, NULL, this, GetCasterGUID());
2573 return;
2576 // Predatory Strikes
2577 if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2579 ((Player*)m_target)->UpdateAttackPowerAndDamage();
2580 return;
2583 // Improved Moonkin Form
2584 if(GetSpellProto()->SpellIconID == 2855)
2586 uint32 spell_id;
2587 switch(GetId())
2589 case 48384: spell_id = 50170; break; //Rank 1
2590 case 48395: spell_id = 50171; break; //Rank 2
2591 case 48396: spell_id = 50172; break; //Rank 3
2592 default:
2593 sLog.outError("HandleAuraDummy: Not handled rank of IMF (Spell: %u)",GetId());
2594 return;
2597 if(apply)
2599 if(m_target->m_form != FORM_MOONKIN)
2600 return;
2602 m_target->CastSpell(m_target, spell_id, true);
2604 else
2605 m_target-> RemoveAurasDueToSpell(spell_id);
2606 return;
2608 break;
2610 case SPELLFAMILY_HUNTER:
2611 break;
2612 case SPELLFAMILY_SHAMAN:
2614 // Improved Weapon Totems
2615 if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2617 if(apply)
2619 SpellModifier *mod = new SpellModifier;
2620 mod->op = SPELLMOD_EFFECT1;
2621 mod->value = m_modifier.m_amount;
2622 mod->type = SPELLMOD_PCT;
2623 mod->spellId = GetId();
2624 switch (m_effIndex)
2626 case 0:
2627 // Windfury Totem
2628 mod->mask = UI64LIT(0x00200000000);
2629 mod->mask2= UI64LIT(0x0);
2630 break;
2631 case 1:
2632 // Flametongue Totem
2633 mod->mask = UI64LIT(0x00400000000);
2634 mod->mask2= UI64LIT(0x0);
2635 break;
2638 m_spellmod = mod;
2641 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2642 return;
2644 break;
2648 // pet auras
2649 if(PetAura const* petSpell = spellmgr.GetPetAura(GetId(), m_effIndex))
2651 if(apply)
2652 m_target->AddPetAura(petSpell);
2653 else
2654 m_target->RemovePetAura(petSpell);
2655 return;
2658 if(GetEffIndex()==0 && m_target->GetTypeId()==TYPEID_PLAYER)
2660 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
2661 if(saBounds.first != saBounds.second)
2663 uint32 zone, area;
2664 m_target->GetZoneAndAreaId(zone, area);
2666 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2668 // some auras remove at aura remove
2669 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
2670 m_target->RemoveAurasDueToSpell(itr->second->spellId);
2671 // some auras applied at aura apply
2672 else if(itr->second->autocast)
2674 if( !m_target->HasAura(itr->second->spellId, 0) )
2675 m_target->CastSpell(m_target, itr->second->spellId, true);
2682 void Aura::HandleAuraMounted(bool apply, bool Real)
2684 // only at real add/remove aura
2685 if(!Real)
2686 return;
2688 if(apply)
2690 CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2691 if(!ci)
2693 sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2694 return;
2697 uint32 team = 0;
2698 if (m_target->GetTypeId()==TYPEID_PLAYER)
2699 team = ((Player*)m_target)->GetTeam();
2701 uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2702 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2703 if (minfo)
2704 display_id = minfo->modelid;
2706 m_target->Mount(display_id);
2708 else
2710 m_target->Unmount();
2714 void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2716 // only at real add/remove aura
2717 if(!Real)
2718 return;
2720 WorldPacket data;
2721 if(apply)
2722 data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2723 else
2724 data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2725 data.append(m_target->GetPackGUID());
2726 data << uint32(0);
2727 m_target->SendMessageToSet(&data, true);
2730 void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2732 // only at real add/remove aura
2733 if(!Real)
2734 return;
2736 WorldPacket data;
2737 if(apply)
2738 data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2739 else
2740 data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2741 data.append(m_target->GetPackGUID());
2742 data << uint32(0);
2743 m_target->SendMessageToSet(&data, true);
2745 // start fall from current height
2746 if(!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2747 ((Player*)m_target)->SetFallInformation(0, m_target->GetPositionZ());
2750 void Aura::HandleAuraHover(bool apply, bool Real)
2752 // only at real add/remove aura
2753 if(!Real)
2754 return;
2756 WorldPacket data;
2757 if(apply)
2758 data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2759 else
2760 data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2761 data.append(m_target->GetPackGUID());
2762 data << uint32(0);
2763 m_target->SendMessageToSet(&data, true);
2766 void Aura::HandleWaterBreathing(bool /*apply*/, bool /*Real*/)
2768 // update timers in client
2769 if(m_target->GetTypeId()==TYPEID_PLAYER)
2770 ((Player*)m_target)->UpdateMirrorTimers();
2773 void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2775 if(!Real)
2776 return;
2778 uint32 modelid = 0;
2779 Powers PowerType = POWER_MANA;
2780 ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2781 switch(form)
2783 case FORM_CAT:
2784 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2785 modelid = 892;
2786 else
2787 modelid = 8571;
2788 PowerType = POWER_ENERGY;
2789 break;
2790 case FORM_TRAVEL:
2791 modelid = 632;
2792 break;
2793 case FORM_AQUA:
2794 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2795 modelid = 2428;
2796 else
2797 modelid = 2428;
2798 break;
2799 case FORM_BEAR:
2800 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2801 modelid = 2281;
2802 else
2803 modelid = 2289;
2804 PowerType = POWER_RAGE;
2805 break;
2806 case FORM_GHOUL:
2807 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2808 modelid = 10045;
2809 break;
2810 case FORM_DIREBEAR:
2811 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2812 modelid = 2281;
2813 else
2814 modelid = 2289;
2815 PowerType = POWER_RAGE;
2816 break;
2817 case FORM_CREATUREBEAR:
2818 modelid = 902;
2819 break;
2820 case FORM_GHOSTWOLF:
2821 modelid = 4613;
2822 break;
2823 case FORM_FLIGHT:
2824 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2825 modelid = 20857;
2826 else
2827 modelid = 20872;
2828 break;
2829 case FORM_MOONKIN:
2830 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2831 modelid = 15374;
2832 else
2833 modelid = 15375;
2834 break;
2835 case FORM_FLIGHT_EPIC:
2836 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2837 modelid = 21243;
2838 else
2839 modelid = 21244;
2840 break;
2841 case FORM_METAMORPHOSIS:
2842 modelid = 25277;
2843 break;
2844 case FORM_AMBIENT:
2845 case FORM_SHADOW:
2846 case FORM_STEALTH:
2847 break;
2848 case FORM_TREE:
2849 modelid = 864;
2850 break;
2851 case FORM_BATTLESTANCE:
2852 case FORM_BERSERKERSTANCE:
2853 case FORM_DEFENSIVESTANCE:
2854 PowerType = POWER_RAGE;
2855 break;
2856 case FORM_SPIRITOFREDEMPTION:
2857 modelid = 16031;
2858 break;
2859 default:
2860 sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2863 // remove polymorph before changing display id to keep new display id
2864 switch ( form )
2866 case FORM_CAT:
2867 case FORM_TREE:
2868 case FORM_TRAVEL:
2869 case FORM_AQUA:
2870 case FORM_BEAR:
2871 case FORM_DIREBEAR:
2872 case FORM_FLIGHT_EPIC:
2873 case FORM_FLIGHT:
2874 case FORM_MOONKIN:
2876 // remove movement affects
2877 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2878 Unit::AuraList const& slowingAuras = m_target->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
2879 for (Unit::AuraList::const_iterator iter = slowingAuras.begin(); iter != slowingAuras.end();)
2881 SpellEntry const* aurSpellInfo = (*iter)->GetSpellProto();
2883 uint32 aurMechMask = GetAllSpellMechanicMask(aurSpellInfo);
2885 // If spell that caused this aura has Croud Control or Daze effect
2886 if((aurMechMask & MECHANIC_NOT_REMOVED_BY_SHAPESHIFT) ||
2887 // some Daze spells have these parameters instead of MECHANIC_DAZE (skip snare spells)
2888 aurSpellInfo->SpellIconID == 15 && aurSpellInfo->Dispel == 0 && (aurMechMask & (1 << MECHANIC_SNARE))==0)
2890 ++iter;
2891 continue;
2894 // All OK, remove aura now
2895 m_target->RemoveAurasDueToSpellByCancel(aurSpellInfo->Id);
2896 iter = slowingAuras.begin();
2899 // and polymorphic affects
2900 if(m_target->IsPolymorphed())
2901 m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2903 break;
2905 default:
2906 break;
2909 if(apply)
2911 // remove other shapeshift before applying a new one
2912 if(m_target->m_ShapeShiftFormSpellId)
2913 m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId, this);
2915 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2917 if(modelid > 0)
2918 m_target->SetDisplayId(modelid);
2920 if(PowerType != POWER_MANA)
2922 // reset power to default values only at power change
2923 if(m_target->getPowerType() != PowerType)
2924 m_target->setPowerType(PowerType);
2926 switch(form)
2928 case FORM_CAT:
2929 case FORM_BEAR:
2930 case FORM_DIREBEAR:
2932 // get furor proc chance
2933 uint32 FurorChance = 0;
2934 Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2935 for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2937 if ((*i)->GetSpellProto()->SpellIconID == 238)
2939 FurorChance = (*i)->GetModifier()->m_amount;
2940 break;
2944 if (m_modifier.m_miscvalue == FORM_CAT)
2946 m_target->SetPower(POWER_ENERGY, 0);
2947 if(urand(1,100) <= FurorChance)
2948 m_target->CastSpell(m_target, 17099, true, NULL, this);
2950 else
2952 m_target->SetPower(POWER_RAGE, 0);
2953 if(urand(1,100) <= FurorChance)
2954 m_target->CastSpell(m_target, 17057, true, NULL, this);
2956 break;
2958 case FORM_BATTLESTANCE:
2959 case FORM_DEFENSIVESTANCE:
2960 case FORM_BERSERKERSTANCE:
2962 uint32 Rage_val = 0;
2963 // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2964 if(m_target->GetTypeId() == TYPEID_PLAYER)
2966 PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2967 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2969 if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2970 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2971 if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2972 Rage_val += m_target->CalculateSpellDamage(spellInfo, 0, spellInfo->EffectBasePoints[0], m_target) * 10;
2976 if (m_target->GetPower(POWER_RAGE) > Rage_val)
2977 m_target->SetPower(POWER_RAGE, Rage_val);
2978 break;
2980 default:
2981 break;
2985 m_target->m_ShapeShiftFormSpellId = GetId();
2986 m_target->m_form = form;
2988 else
2990 if(modelid > 0)
2991 m_target->SetDisplayId(m_target->GetNativeDisplayId());
2992 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2993 if(m_target->getClass() == CLASS_DRUID)
2994 m_target->setPowerType(POWER_MANA);
2995 m_target->m_ShapeShiftFormSpellId = 0;
2996 m_target->m_form = FORM_NONE;
2998 switch(form)
3000 // Nordrassil Harness - bonus
3001 case FORM_BEAR:
3002 case FORM_DIREBEAR:
3003 case FORM_CAT:
3004 if(Aura* dummy = m_target->GetDummyAura(37315) )
3005 m_target->CastSpell(m_target, 37316, true, NULL, dummy);
3006 break;
3007 // Nordrassil Regalia - bonus
3008 case FORM_MOONKIN:
3009 if(Aura* dummy = m_target->GetDummyAura(37324) )
3010 m_target->CastSpell(m_target, 37325, true, NULL, dummy);
3011 break;
3012 default:
3013 break;
3017 // adding/removing linked auras
3018 // add/remove the shapeshift aura's boosts
3019 HandleShapeshiftBoosts(apply);
3021 if(m_target->GetTypeId() == TYPEID_PLAYER)
3022 ((Player*)m_target)->InitDataForForm();
3025 void Aura::HandleAuraTransform(bool apply, bool Real)
3027 if (apply)
3029 // special case (spell specific functionality)
3030 if (m_modifier.m_miscvalue == 0)
3032 // player applied only
3033 if (m_target->GetTypeId() != TYPEID_PLAYER)
3034 return;
3036 switch (GetId())
3038 // Orb of Deception
3039 case 16739:
3041 uint32 orb_model = m_target->GetNativeDisplayId();
3042 switch(orb_model)
3044 // Troll Female
3045 case 1479: m_target->SetDisplayId(10134); break;
3046 // Troll Male
3047 case 1478: m_target->SetDisplayId(10135); break;
3048 // Tauren Male
3049 case 59: m_target->SetDisplayId(10136); break;
3050 // Human Male
3051 case 49: m_target->SetDisplayId(10137); break;
3052 // Human Female
3053 case 50: m_target->SetDisplayId(10138); break;
3054 // Orc Male
3055 case 51: m_target->SetDisplayId(10139); break;
3056 // Orc Female
3057 case 52: m_target->SetDisplayId(10140); break;
3058 // Dwarf Male
3059 case 53: m_target->SetDisplayId(10141); break;
3060 // Dwarf Female
3061 case 54: m_target->SetDisplayId(10142); break;
3062 // NightElf Male
3063 case 55: m_target->SetDisplayId(10143); break;
3064 // NightElf Female
3065 case 56: m_target->SetDisplayId(10144); break;
3066 // Undead Female
3067 case 58: m_target->SetDisplayId(10145); break;
3068 // Undead Male
3069 case 57: m_target->SetDisplayId(10146); break;
3070 // Tauren Female
3071 case 60: m_target->SetDisplayId(10147); break;
3072 // Gnome Male
3073 case 1563: m_target->SetDisplayId(10148); break;
3074 // Gnome Female
3075 case 1564: m_target->SetDisplayId(10149); break;
3076 // BloodElf Female
3077 case 15475: m_target->SetDisplayId(17830); break;
3078 // BloodElf Male
3079 case 15476: m_target->SetDisplayId(17829); break;
3080 // Dranei Female
3081 case 16126: m_target->SetDisplayId(17828); break;
3082 // Dranei Male
3083 case 16125: m_target->SetDisplayId(17827); break;
3084 default: break;
3086 break;
3088 // Murloc costume
3089 case 42365: m_target->SetDisplayId(21723); break;
3090 default: break;
3093 else
3095 uint32 model_id;
3097 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
3098 if (!ci)
3100 model_id = 16358; // pig pink ^_^
3101 sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
3103 else
3104 model_id = ci->DisplayID_A[0]; // Will use the default model here
3106 // Polymorph (sheep/penguin case)
3107 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
3108 if (Unit* caster = GetCaster())
3109 if (caster->HasAura(52648)) // Glyph of the Penguin
3110 model_id = 26452;
3112 m_target->SetDisplayId(model_id);
3114 // Dragonmaw Illusion (set mount model also)
3115 if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
3116 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3119 // update active transform spell only not set or not overwriting negative by positive case
3120 if (!m_target->getTransForm() || !IsPositiveSpell(GetId()) || IsPositiveSpell(m_target->getTransForm()))
3121 m_target->setTransForm(GetId());
3123 // polymorph case
3124 if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
3126 // for players, start regeneration after 1s (in polymorph fast regeneration case)
3127 // only if caster is Player (after patch 2.4.2)
3128 if (IS_PLAYER_GUID(GetCasterGUID()) )
3129 ((Player*)m_target)->setRegenTimer(1*IN_MILISECONDS);
3131 //dismount polymorphed target (after patch 2.4.2)
3132 if (m_target->IsMounted())
3133 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
3136 else
3138 // ApplyModifier(true) will reapply it if need
3139 m_target->setTransForm(0);
3140 m_target->SetDisplayId(m_target->GetNativeDisplayId());
3142 // re-aplly some from still active with preference negative cases
3143 Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
3144 if (!otherTransforms.empty())
3146 // look for other transform auras
3147 Aura* handledAura = *otherTransforms.begin();
3148 for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
3150 // negative auras are preferred
3151 if (!IsPositiveSpell((*i)->GetSpellProto()->Id))
3153 handledAura = *i;
3154 break;
3157 handledAura->ApplyModifier(true);
3160 // Dragonmaw Illusion (restore mount model)
3161 if (GetId() == 42016 && m_target->GetMountID() == 16314)
3163 if (!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
3165 uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
3166 if (CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
3168 uint32 team = 0;
3169 if (m_target->GetTypeId() == TYPEID_PLAYER)
3170 team = ((Player*)m_target)->GetTeam();
3172 uint32 display_id = objmgr.ChooseDisplayId(team, ci);
3173 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
3174 if (minfo)
3175 display_id = minfo->modelid;
3177 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, display_id);
3184 void Aura::HandleForceReaction(bool apply, bool Real)
3186 if(m_target->GetTypeId() != TYPEID_PLAYER)
3187 return;
3189 if(!Real)
3190 return;
3192 Player* player = (Player*)m_target;
3194 uint32 faction_id = m_modifier.m_miscvalue;
3195 uint32 faction_rank = m_modifier.m_amount;
3197 player->GetReputationMgr().ApplyForceReaction(faction_id, ReputationRank(faction_rank), apply);
3198 player->GetReputationMgr().SendForceReactions();
3201 void Aura::HandleAuraModSkill(bool apply, bool /*Real*/)
3203 if(m_target->GetTypeId() != TYPEID_PLAYER)
3204 return;
3206 uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
3207 int32 points = GetModifier()->m_amount;
3209 ((Player*)m_target)->ModifySkillBonus(prot, (apply ? points: -points), m_modifier.m_auraname == SPELL_AURA_MOD_SKILL_TALENT);
3210 if(prot == SKILL_DEFENSE)
3211 ((Player*)m_target)->UpdateDefenseBonusesMod();
3214 void Aura::HandleChannelDeathItem(bool apply, bool Real)
3216 if(Real && !apply)
3218 Unit* caster = GetCaster();
3219 Unit* victim = GetTarget();
3220 if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode != AURA_REMOVE_BY_DEATH)
3221 return;
3222 // Item amount
3223 if (m_modifier.m_amount <= 0)
3224 return;
3226 SpellEntry const *spellInfo = GetSpellProto();
3227 if(spellInfo->EffectItemType[m_effIndex] == 0)
3228 return;
3230 // Soul Shard only from non-grey units
3231 if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
3232 (victim->getLevel() <= MaNGOS::XP::GetGrayLevel(caster->getLevel()) ||
3233 victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
3234 return;
3235 //Adding items
3236 uint32 noSpaceForCount = 0;
3237 uint32 count = m_modifier.m_amount;
3239 ItemPosCountVec dest;
3240 uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], count, &noSpaceForCount);
3241 if( msg != EQUIP_ERR_OK )
3243 count-=noSpaceForCount;
3244 ((Player*)caster)->SendEquipError( msg, NULL, NULL );
3245 if (count==0)
3246 return;
3249 Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
3250 ((Player*)caster)->SendNewItem(newitem, count, true, false);
3254 void Aura::HandleBindSight(bool apply, bool /*Real*/)
3256 Unit* caster = GetCaster();
3257 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3258 return;
3260 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3263 void Aura::HandleFarSight(bool apply, bool /*Real*/)
3265 Unit* caster = GetCaster();
3266 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3267 return;
3269 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3272 void Aura::HandleAuraTrackCreatures(bool apply, bool /*Real*/)
3274 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3275 return;
3277 if(apply)
3278 m_target->RemoveNoStackAurasDueToAura(this);
3279 m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
3282 void Aura::HandleAuraTrackResources(bool apply, bool /*Real*/)
3284 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3285 return;
3287 if(apply)
3288 m_target->RemoveNoStackAurasDueToAura(this);
3289 m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
3292 void Aura::HandleAuraTrackStealthed(bool apply, bool /*Real*/)
3294 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3295 return;
3297 if(apply)
3298 m_target->RemoveNoStackAurasDueToAura(this);
3300 m_target->ApplyModFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTE_TRACK_STEALTHED, apply);
3303 void Aura::HandleAuraModScale(bool apply, bool /*Real*/)
3305 m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X, m_modifier.m_amount, apply);
3308 void Aura::HandleModPossess(bool apply, bool Real)
3310 if(!Real)
3311 return;
3313 // not possess yourself
3314 if(GetCasterGUID() == m_target->GetGUID())
3315 return;
3317 Unit* caster = GetCaster();
3318 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3319 return;
3321 Player* p_caster = (Player*)caster;
3324 if( apply )
3326 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3328 m_target->SetCharmerGUID(p_caster->GetGUID());
3329 m_target->setFaction(p_caster->getFaction());
3331 p_caster->SetCharm(m_target);
3333 p_caster->SetFarSightGUID(m_target->GetGUID());
3334 p_caster->SetClientControl(m_target, 1);
3335 p_caster->SetMover(m_target);
3337 m_target->CombatStop();
3338 m_target->DeleteThreatList();
3340 if(m_target->GetTypeId() == TYPEID_UNIT)
3342 m_target->StopMoving();
3343 m_target->GetMotionMaster()->Clear();
3344 m_target->GetMotionMaster()->MoveIdle();
3346 else if(m_target->GetTypeId() == TYPEID_PLAYER)
3348 ((Player*)m_target)->SetClientControl(m_target, 0);
3351 if(CharmInfo *charmInfo = m_target->InitCharmInfo(m_target))
3352 charmInfo->InitPossessCreateSpells();
3354 p_caster->PossessSpellInitialize();
3356 else
3358 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3360 m_target->SetCharmerGUID(0);
3361 p_caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now
3363 if(m_target->GetTypeId() == TYPEID_PLAYER)
3365 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3366 ((Player*)m_target)->SetClientControl(m_target, 1);
3368 else if(m_target->GetTypeId() == TYPEID_UNIT)
3370 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3371 m_target->setFaction(cinfo->faction_A);
3374 p_caster->SetCharm(NULL);
3376 p_caster->SetFarSightGUID(0);
3377 p_caster->SetClientControl(m_target, 0);
3378 p_caster->SetMover(NULL);
3380 p_caster->RemovePetActionBar();
3382 if(m_target->GetTypeId() == TYPEID_UNIT)
3384 ((Creature*)m_target)->AIM_Initialize();
3386 if (((Creature*)m_target)->AI())
3387 ((Creature*)m_target)->AI()->AttackedBy(caster);
3392 void Aura::HandleModPossessPet(bool apply, bool Real)
3394 if(!Real)
3395 return;
3397 Unit* caster = GetCaster();
3398 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3399 return;
3401 Pet *pet = caster->GetPet();
3402 if(!pet || pet != m_target)
3403 return;
3405 Player* p_caster = (Player*)caster;
3407 if(apply)
3408 pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3409 else
3410 pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3412 p_caster->SetFarSightGUID(apply ? pet->GetGUID() : 0);
3413 p_caster->SetCharm(apply ? pet : NULL);
3414 p_caster->SetClientControl(pet, apply ? 1 : 0);
3415 ((Player*)caster)->SetMover(apply ? pet : NULL);
3417 if(apply)
3419 pet->StopMoving();
3420 pet->GetMotionMaster()->Clear();
3421 pet->GetMotionMaster()->MoveIdle();
3423 else
3425 pet->AttackStop();
3426 pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
3427 pet->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
3431 void Aura::HandleAuraModPetTalentsPoints(bool /*Apply*/, bool Real)
3433 if(!Real)
3434 return;
3436 // Recalculate pet talent points
3437 if (Pet *pet=m_target->GetPet())
3438 pet->InitTalentForLevel();
3441 void Aura::HandleModCharm(bool apply, bool Real)
3443 if(!Real)
3444 return;
3446 // not charm yourself
3447 if(GetCasterGUID() == m_target->GetGUID())
3448 return;
3450 Unit* caster = GetCaster();
3451 if(!caster)
3452 return;
3454 if( apply )
3456 m_target->SetCharmerGUID(GetCasterGUID());
3457 m_target->setFaction(caster->getFaction());
3458 m_target->CastStop(m_target == caster ? GetId() : 0);
3459 caster->SetCharm(m_target);
3461 m_target->CombatStop();
3462 m_target->DeleteThreatList();
3464 if(m_target->GetTypeId() == TYPEID_UNIT)
3466 ((Creature*)m_target)->AIM_Initialize();
3467 CharmInfo *charmInfo = m_target->InitCharmInfo(m_target);
3468 charmInfo->InitCharmCreateSpells();
3469 charmInfo->SetReactState( REACT_DEFENSIVE );
3471 if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
3473 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3474 if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
3476 // creature with pet number expected have class set
3477 if(m_target->GetByteValue(UNIT_FIELD_BYTES_0, 1)==0)
3479 if(cinfo->unit_class==0)
3480 sLog.outErrorDb("Creature (Entry: %u) have unit_class = 0 but used in charmed spell, that will be result client crash.",cinfo->Entry);
3481 else
3482 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);
3484 m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, CLASS_MAGE);
3487 //just to enable stat window
3488 charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
3489 //if charmed two demons the same session, the 2nd gets the 1st one's name
3490 m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
3495 if(caster->GetTypeId() == TYPEID_PLAYER)
3496 ((Player*)caster)->CharmSpellInitialize();
3498 else
3500 m_target->SetCharmerGUID(0);
3502 if(m_target->GetTypeId() == TYPEID_PLAYER)
3503 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3504 else
3506 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3508 // restore faction
3509 if(((Creature*)m_target)->isPet())
3511 if(Unit* owner = m_target->GetOwner())
3512 m_target->setFaction(owner->getFaction());
3513 else if(cinfo)
3514 m_target->setFaction(cinfo->faction_A);
3516 else if(cinfo) // normal creature
3517 m_target->setFaction(cinfo->faction_A);
3519 // restore UNIT_FIELD_BYTES_0
3520 if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3522 // DB must have proper class set in field at loading, not req. restore, including workaround case at apply
3523 // m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, cinfo->unit_class);
3525 if(m_target->GetCharmInfo())
3526 m_target->GetCharmInfo()->SetPetNumber(0, true);
3527 else
3528 sLog.outError("Aura::HandleModCharm: target (GUID: %u TypeId: %u) has a charm aura but no charm info!", m_target->GetGUIDLow(), m_target->GetTypeId());
3532 caster->SetCharm(NULL);
3534 if(caster->GetTypeId() == TYPEID_PLAYER)
3535 ((Player*)caster)->RemovePetActionBar();
3537 if(m_target->GetTypeId() == TYPEID_UNIT)
3539 ((Creature*)m_target)->AIM_Initialize();
3540 if (((Creature*)m_target)->AI())
3541 ((Creature*)m_target)->AI()->AttackedBy(caster);
3546 void Aura::HandleModConfuse(bool apply, bool Real)
3548 if(!Real)
3549 return;
3551 m_target->SetConfused(apply, GetCasterGUID(), GetId());
3554 void Aura::HandleModFear(bool apply, bool Real)
3556 if (!Real)
3557 return;
3559 m_target->SetFeared(apply, GetCasterGUID(), GetId());
3562 void Aura::HandleFeignDeath(bool apply, bool Real)
3564 if(!Real)
3565 return;
3567 if(m_target->GetTypeId() != TYPEID_PLAYER)
3568 return;
3570 if( apply )
3573 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3574 data<<m_target->GetGUID();
3575 data<<uint8(0);
3576 m_target->SendMessageToSet(&data,true);
3578 // blizz like 2.0.x
3579 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3580 // blizz like 2.0.x
3581 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3582 // blizz like 2.0.x
3583 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3585 m_target->addUnitState(UNIT_STAT_DIED);
3586 m_target->CombatStop();
3587 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3589 // prevent interrupt message
3590 if (m_caster_guid==m_target->GetGUID())
3591 m_target->FinishSpell(CURRENT_GENERIC_SPELL,false);
3592 m_target->InterruptNonMeleeSpells(true);
3593 m_target->getHostilRefManager().deleteReferences();
3595 else
3598 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3599 data<<m_target->GetGUID();
3600 data<<uint8(1);
3601 m_target->SendMessageToSet(&data,true);
3603 // blizz like 2.0.x
3604 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3605 // blizz like 2.0.x
3606 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3607 // blizz like 2.0.x
3608 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3610 m_target->clearUnitState(UNIT_STAT_DIED);
3614 void Aura::HandleAuraModDisarm(bool apply, bool Real)
3616 if(!Real)
3617 return;
3619 if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3620 return;
3622 // not sure for it's correctness
3623 if(apply)
3624 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3625 else
3626 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3628 // only at real add/remove aura
3629 if (m_target->GetTypeId() != TYPEID_PLAYER)
3630 return;
3632 // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3633 if (m_target->IsInFeralForm())
3634 return;
3636 if (apply)
3637 m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3638 else
3639 ((Player *)m_target)->SetRegularAttackTime();
3641 m_target->UpdateDamagePhysical(BASE_ATTACK);
3644 void Aura::HandleAuraModStun(bool apply, bool Real)
3646 if(!Real)
3647 return;
3649 if (apply)
3651 // Frost stun aura -> freeze/unfreeze target
3652 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3653 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3655 m_target->addUnitState(UNIT_STAT_STUNNED);
3656 m_target->SetUInt64Value(UNIT_FIELD_TARGET, 0);
3658 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3659 m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3661 // Creature specific
3662 if(m_target->GetTypeId() != TYPEID_PLAYER)
3663 m_target->StopMoving();
3664 else
3666 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3667 m_target->SetStandState(UNIT_STAND_STATE_STAND);// in 1.5 client
3670 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3671 data.append(m_target->GetPackGUID());
3672 data << uint32(0);
3673 m_target->SendMessageToSet(&data, true);
3675 // Summon the Naj'entus Spine GameObject on target if spell is Impaling Spine
3676 if(GetId() == 39837)
3678 GameObject* pObj = new GameObject;
3679 if(pObj->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 185584, m_target->GetMap(), m_target->GetPhaseMask(),
3680 m_target->GetPositionX(), m_target->GetPositionY(), m_target->GetPositionZ(), m_target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
3682 pObj->SetRespawnTime(GetAuraDuration()/IN_MILISECONDS);
3683 pObj->SetSpellId(GetId());
3684 m_target->AddGameObject(pObj);
3685 m_target->GetMap()->Add(pObj);
3687 else
3688 delete pObj;
3691 else
3693 // Frost stun aura -> freeze/unfreeze target
3694 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3696 bool found_another = false;
3697 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3699 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3700 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3702 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3704 found_another = true;
3705 break;
3708 if(found_another)
3709 break;
3712 if(!found_another)
3713 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3716 // Real remove called after current aura remove from lists, check if other similar auras active
3717 if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3718 return;
3720 m_target->clearUnitState(UNIT_STAT_STUNNED);
3721 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3723 if(!m_target->hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
3725 if(m_target->getVictim() && m_target->isAlive())
3726 m_target->SetUInt64Value(UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3728 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3729 data.append(m_target->GetPackGUID());
3730 data << uint32(0);
3731 m_target->SendMessageToSet(&data, true);
3734 // Wyvern Sting
3735 if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & UI64LIT(0x0000100000000000))
3737 Unit* caster = GetCaster();
3738 if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3739 return;
3741 uint32 spell_id = 0;
3743 switch(GetId())
3745 case 19386: spell_id = 24131; break;
3746 case 24132: spell_id = 24134; break;
3747 case 24133: spell_id = 24135; break;
3748 case 27068: spell_id = 27069; break;
3749 case 49011: spell_id = 49009; break;
3750 case 49012: spell_id = 49010; break;
3751 default:
3752 sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3753 return;
3756 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3758 if(!spellInfo)
3759 return;
3761 caster->CastSpell(m_target,spellInfo,true,NULL,this);
3762 return;
3767 void Aura::HandleModStealth(bool apply, bool Real)
3769 if (apply)
3771 // drop flag at stealth in bg
3772 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3774 // only at real aura add
3775 if (Real)
3777 m_target->SetStandFlags(UNIT_STAND_FLAGS_CREEP);
3779 if (m_target->GetTypeId()==TYPEID_PLAYER)
3780 m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3782 // apply only if not in GM invisibility (and overwrite invisibility state)
3783 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3785 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3786 m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3789 // apply full stealth period bonuses only at first stealth aura in stack
3790 if(m_target->GetAurasByType(SPELL_AURA_MOD_STEALTH).size()<=1)
3792 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3793 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3795 // Master of Subtlety
3796 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3798 m_target->RemoveAurasDueToSpell(31666);
3799 int32 bp = (*i)->GetModifier()->m_amount;
3800 m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3802 // Overkill
3803 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3805 m_target->RemoveAurasDueToSpell(58428);
3806 m_target->CastSpell(m_target, 58427, true);
3812 else
3814 // only at real aura remove of _last_ SPELL_AURA_MOD_STEALTH
3815 if (Real && !m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3817 // if no GM invisibility
3818 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3820 m_target->RemoveStandFlags(UNIT_STAND_FLAGS_CREEP);
3822 if (m_target->GetTypeId()==TYPEID_PLAYER)
3823 m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3825 // restore invisibility if any
3826 if (m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3828 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3829 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3831 else
3832 m_target->SetVisibility(VISIBILITY_ON);
3835 // apply delayed talent bonus remover at last stealth aura remove
3836 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3837 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3839 // Master of Subtlety
3840 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3841 m_target->CastSpell(m_target, 31666, true);
3842 // Overkill
3843 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3844 m_target->CastSpell(m_target, 58428, true);
3850 void Aura::HandleInvisibility(bool apply, bool Real)
3852 if(apply)
3854 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3856 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3858 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3860 // apply glow vision
3861 m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3865 // apply only if not in GM invisibility and not stealth
3866 if(m_target->GetVisibility() == VISIBILITY_ON)
3868 // Aura not added yet but visibility code expect temporary add aura
3869 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3870 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3873 else
3875 // recalculate value at modifier remove (current aura already removed)
3876 m_target->m_invisibilityMask = 0;
3877 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
3878 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3879 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3881 // only at real aura remove and if not have different invisibility auras.
3882 if(Real && m_target->m_invisibilityMask == 0)
3884 // remove glow vision
3885 if(m_target->GetTypeId() == TYPEID_PLAYER)
3886 m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3888 // apply only if not in GM invisibility & not stealthed while invisible
3889 if(m_target->GetVisibility() != VISIBILITY_OFF)
3891 // if have stealth aura then already have stealth visibility
3892 if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3893 m_target->SetVisibility(VISIBILITY_ON);
3899 void Aura::HandleInvisibilityDetect(bool apply, bool Real)
3901 if(apply)
3903 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3905 else
3907 // recalculate value at modifier remove (current aura already removed)
3908 m_target->m_detectInvisibilityMask = 0;
3909 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
3910 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3911 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3913 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3914 ObjectAccessor::UpdateVisibilityForPlayer((Player*)m_target);
3917 void Aura::HandleAuraModRoot(bool apply, bool Real)
3919 // only at real add/remove aura
3920 if(!Real)
3921 return;
3923 if (apply)
3925 // Frost root aura -> freeze/unfreeze target
3926 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3927 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3929 m_target->addUnitState(UNIT_STAT_ROOT);
3930 m_target->SetUInt64Value (UNIT_FIELD_TARGET, 0);
3931 // probably wrong (this add skinable flag)
3932 // TODO: find correct flag
3933 //m_target->SetFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3935 //Save last orientation
3936 if( m_target->getVictim() )
3937 m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
3939 if(m_target->GetTypeId() == TYPEID_PLAYER)
3941 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
3942 data.append(m_target->GetPackGUID());
3943 data << (uint32)2;
3944 m_target->SendMessageToSet(&data, true);
3946 //Clear unit movement flags
3947 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3949 else
3950 m_target->StopMoving();
3952 else
3954 // Frost root aura -> freeze/unfreeze target
3955 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3957 bool found_another = false;
3958 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3960 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3961 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3963 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3965 found_another = true;
3966 break;
3969 if(found_another)
3970 break;
3973 if(!found_another)
3974 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3977 // Real remove called after current aura remove from lists, check if other similar auras active
3978 if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
3979 return;
3981 m_target->clearUnitState(UNIT_STAT_ROOT);
3982 // probably wrong (this add skinable flag)
3983 // TODO: find correct flag
3984 //m_target->RemoveFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3986 if(!m_target->hasUnitState(UNIT_STAT_STUNNED)) // prevent allow move if have also stun effect
3988 if(m_target->getVictim() && m_target->isAlive())
3989 m_target->SetUInt64Value (UNIT_FIELD_TARGET, m_target->getVictim()->GetGUID() );
3991 if(m_target->GetTypeId() == TYPEID_PLAYER)
3993 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
3994 data.append(m_target->GetPackGUID());
3995 data << (uint32)2;
3996 m_target->SendMessageToSet(&data, true);
4002 void Aura::HandleAuraModSilence(bool apply, bool Real)
4004 // only at real add/remove aura
4005 if(!Real)
4006 return;
4008 if(apply)
4010 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
4011 // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
4012 for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4013 if (Spell* spell = m_target->GetCurrentSpell(CurrentSpellTypes(i)))
4014 if(spell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
4015 // Stop spells on prepare or casting state
4016 m_target->InterruptSpell(CurrentSpellTypes(i), false);
4018 else
4020 // Real remove called after current aura remove from lists, check if other similar auras active
4021 if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
4022 return;
4024 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
4028 void Aura::HandleModThreat(bool apply, bool Real)
4030 // only at real add/remove aura
4031 if (!Real)
4032 return;
4034 if (!m_target->isAlive())
4035 return;
4037 Unit* caster = GetCaster();
4039 if (!caster || !caster->isAlive())
4040 return;
4042 int level_diff = 0;
4043 int multiplier = 0;
4044 switch (GetId())
4046 // Arcane Shroud
4047 case 26400:
4048 level_diff = m_target->getLevel() - 60;
4049 multiplier = 2;
4050 break;
4051 // The Eye of Diminution
4052 case 28862:
4053 level_diff = m_target->getLevel() - 60;
4054 multiplier = 1;
4055 break;
4058 if (level_diff > 0)
4059 m_modifier.m_amount += multiplier * level_diff;
4061 if (m_target->GetTypeId() == TYPEID_PLAYER)
4062 for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
4063 if (m_modifier.m_miscvalue & int32(1<<x))
4064 ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_modifier.m_amount, apply);
4067 void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
4069 // only at real add/remove aura
4070 if (!Real)
4071 return;
4073 if (!m_target->isAlive() || m_target->GetTypeId() != TYPEID_PLAYER)
4074 return;
4076 Unit* caster = GetCaster();
4078 if (!caster || !caster->isAlive())
4079 return;
4081 float threatMod = apply ? float(m_modifier.m_amount) : float(-m_modifier.m_amount);
4083 m_target->getHostilRefManager().threatAssist(caster, threatMod);
4086 void Aura::HandleModTaunt(bool apply, bool Real)
4088 // only at real add/remove aura
4089 if (!Real)
4090 return;
4092 if (!m_target->isAlive() || !m_target->CanHaveThreatList())
4093 return;
4095 Unit* caster = GetCaster();
4097 if (!caster || !caster->isAlive())
4098 return;
4100 if (apply)
4101 m_target->TauntApply(caster);
4102 else
4104 // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
4105 m_target->TauntFadeOut(caster);
4109 /*********************************************************/
4110 /*** MODIFY SPEED ***/
4111 /*********************************************************/
4112 void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real)
4114 // all applied/removed only at real aura add/remove
4115 if(!Real)
4116 return;
4118 m_target->UpdateSpeed(MOVE_RUN, true);
4121 void Aura::HandleAuraModIncreaseMountedSpeed(bool /*apply*/, bool Real)
4123 // all applied/removed only at real aura add/remove
4124 if(!Real)
4125 return;
4127 m_target->UpdateSpeed(MOVE_RUN, true);
4130 void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
4132 // all applied/removed only at real aura add/remove
4133 if(!Real)
4134 return;
4136 // Enable Fly mode for flying mounts
4137 if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
4139 WorldPacket data;
4140 if(apply)
4141 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
4142 else
4143 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
4144 data.append(m_target->GetPackGUID());
4145 data << uint32(0); // unknown
4146 m_target->SendMessageToSet(&data, true);
4148 //Players on flying mounts must be immune to polymorph
4149 if (m_target->GetTypeId()==TYPEID_PLAYER)
4150 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
4152 // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
4153 if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
4154 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
4157 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4160 void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real)
4162 // all applied/removed only at real aura add/remove
4163 if(!Real)
4164 return;
4166 m_target->UpdateSpeed(MOVE_SWIM, true);
4169 void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real)
4171 // all applied/removed only at real aura add/remove
4172 if(!Real)
4173 return;
4175 if (apply)
4177 // Gronn Lord's Grasp, becomes stoned
4178 if (GetId() == 33572)
4180 if (GetStackAmount() >= 5 && !m_target->HasAura(33652))
4181 m_target->CastSpell(m_target, 33652, true);
4185 m_target->UpdateSpeed(MOVE_RUN, true);
4186 m_target->UpdateSpeed(MOVE_SWIM, true);
4187 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4190 void Aura::HandleAuraModUseNormalSpeed(bool /*apply*/, bool Real)
4192 // all applied/removed only at real aura add/remove
4193 if(!Real)
4194 return;
4196 m_target->UpdateSpeed(MOVE_RUN, true);
4197 m_target->UpdateSpeed(MOVE_SWIM, true);
4198 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4201 /*********************************************************/
4202 /*** IMMUNITY ***/
4203 /*********************************************************/
4205 void Aura::HandleModMechanicImmunity(bool apply, bool /*Real*/)
4207 uint32 misc = m_modifier.m_miscvalue;
4208 // Forbearance
4209 // in DBC wrong mechanic immune since 3.0.x
4210 if (GetId() == 25771)
4211 misc = MECHANIC_IMMUNE_SHIELD;
4214 if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4216 uint32 mechanic = 1 << misc;
4218 //immune movement impairment and loss of control
4219 if(GetId()==42292 || GetId()==59752)
4220 mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
4222 Unit::AuraMap& Auras = m_target->GetAuras();
4223 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4225 next = iter;
4226 ++next;
4227 SpellEntry const *spell = iter->second->GetSpellProto();
4228 if (!( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) && // spells unaffected by invulnerability
4229 spell->Id != GetId())
4231 //check for mechanic mask
4232 if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & mechanic)
4234 m_target->RemoveAurasDueToSpell(spell->Id);
4235 if(Auras.empty())
4236 break;
4237 else
4238 next = Auras.begin();
4244 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,misc,apply);
4246 // Bestial Wrath
4247 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1680)
4249 // The Beast Within cast on owner if talent present
4250 if (Unit* owner = m_target->GetOwner())
4252 // Search talent
4253 Unit::AuraList const& dummyAuras = owner->GetAurasByType(SPELL_AURA_DUMMY);
4254 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); ++i)
4256 if ((*i)->GetSpellProto()->SpellIconID == 2229)
4258 if (apply)
4259 owner->CastSpell(owner, 34471, true, 0, this);
4260 else
4261 owner->RemoveAurasDueToSpell(34471);
4262 break;
4269 //this method is called whenever we add / remove aura which gives m_target some imunity to some spell effect
4270 void Aura::HandleAuraModEffectImmunity(bool apply, bool /*Real*/)
4272 // when removing flag aura, handle flag drop
4273 if( !apply && m_target->GetTypeId() == TYPEID_PLAYER
4274 && (GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION) )
4276 if( BattleGround *bg = ((Player*)m_target)->GetBattleGround() )
4277 bg->EventPlayerDroppedFlag(((Player*)m_target));
4280 m_target->ApplySpellImmune(GetId(), IMMUNITY_EFFECT, m_modifier.m_miscvalue, apply);
4283 void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
4285 if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4287 Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
4288 for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
4290 if (auraList.front() != this) // skip itself aura (it already added)
4292 m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
4293 itr = auraList.begin();
4295 else
4296 ++itr;
4300 m_target->ApplySpellImmune(GetId(), IMMUNITY_STATE, m_modifier.m_miscvalue, apply);
4303 void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
4305 m_target->ApplySpellImmune(GetId(), IMMUNITY_SCHOOL, m_modifier.m_miscvalue, apply);
4307 // remove all flag auras (they are positive, but they must be removed when you are immune)
4308 if( this->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4309 && this->GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_DAMAGE_REDUCED_SHIELD )
4310 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
4312 // TODO: optimalize this cycle - use RemoveAurasWithInterruptFlags call or something else
4313 if( Real && apply
4314 && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4315 && IsPositiveSpell(GetId()) ) //Only positive immunity removes auras
4317 uint32 school_mask = m_modifier.m_miscvalue;
4318 Unit::AuraMap& Auras = m_target->GetAuras();
4319 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4321 next = iter;
4322 ++next;
4323 SpellEntry const *spell = iter->second->GetSpellProto();
4324 if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
4325 && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) //Spells unaffected by invulnerability
4326 && !iter->second->IsPositive() //Don't remove positive spells
4327 && spell->Id != GetId() ) //Don't remove self
4329 m_target->RemoveAurasDueToSpell(spell->Id);
4330 if(Auras.empty())
4331 break;
4332 else
4333 next = Auras.begin();
4337 if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
4339 if( apply )
4340 m_target->addUnitState(UNIT_STAT_ISOLATED);
4341 else
4342 m_target->clearUnitState(UNIT_STAT_ISOLATED);
4346 void Aura::HandleAuraModDmgImmunity(bool apply, bool /*Real*/)
4348 m_target->ApplySpellImmune(GetId(), IMMUNITY_DAMAGE, m_modifier.m_miscvalue, apply);
4351 void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
4353 // all applied/removed only at real aura add/remove
4354 if(!Real)
4355 return;
4357 m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
4360 void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
4362 if(!Real)
4363 return;
4365 if(apply)
4367 // some spell have charges by functionality not have its in spell data
4368 switch (GetId())
4370 case 28200: // Ascendance (Talisman of Ascendance trinket)
4371 SetAuraCharges(6);
4372 break;
4373 default: break;
4378 void Aura::HandleAuraModStalked(bool apply, bool /*Real*/)
4380 // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
4381 if(apply)
4382 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4383 else
4384 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4387 /*********************************************************/
4388 /*** PERIODIC ***/
4389 /*********************************************************/
4391 void Aura::HandlePeriodicTriggerSpell(bool apply, bool /*Real*/)
4393 m_isPeriodic = apply;
4395 if (!apply)
4397 switch(m_spellProto->Id)
4399 case 66: // Invisibility
4400 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && m_duration<=0)
4401 m_target->CastSpell(m_target, 32612, true, NULL, this);
4403 return;
4404 case 42783: //Wrath of the Astrom...
4405 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && GetEffIndex() + 1 < 3)
4406 m_target->CastSpell(m_target, m_spellProto->CalculateSimpleValue(GetEffIndex()+1), true);
4407 return;
4408 default:
4409 break;
4414 void Aura::HandlePeriodicTriggerSpellWithValue(bool apply, bool /*Real*/)
4416 m_isPeriodic = apply;
4419 void Aura::HandlePeriodicEnergize(bool apply, bool Real)
4421 if (!Real)
4422 return;
4424 m_isPeriodic = apply;
4426 // Replenishment (0.25% from max)
4427 // Infinite Replenishment
4428 if (GetId() == 57669 ||
4429 GetId() == 61782)
4430 m_modifier.m_amount = m_target->GetMaxPower(POWER_MANA) * 25 / 10000;
4433 void Aura::HandleAuraPowerBurn(bool apply, bool /*Real*/)
4435 m_isPeriodic = apply;
4438 void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
4440 // spells required only Real aura add/remove
4441 if(!Real)
4442 return;
4444 // For prevent double apply bonuses
4445 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4447 Unit* caster = GetCaster();
4449 SpellEntry const*spell = GetSpellProto();
4450 switch( spell->SpellFamilyName)
4452 case SPELLFAMILY_ROGUE:
4454 if(!apply)
4456 switch(spell->Id)
4458 // Master of Subtlety
4459 case 31666: m_target->RemoveAurasDueToSpell(31665); break;
4460 // Overkill
4461 case 58428: m_target->RemoveAurasDueToSpell(58427); break;
4464 break;
4466 case SPELLFAMILY_HUNTER:
4468 // Explosive Shot
4469 if (apply && !loading && caster)
4470 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 14 / 100);
4471 break;
4475 m_isPeriodic = apply;
4478 void Aura::HandlePeriodicHeal(bool apply, bool /*Real*/)
4480 m_isPeriodic = apply;
4483 void Aura::HandlePeriodicDamage(bool apply, bool Real)
4485 // spells required only Real aura add/remove
4486 if(!Real)
4487 return;
4489 m_isPeriodic = apply;
4491 // For prevent double apply bonuses
4492 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4494 // Custom damage calculation after
4495 if (apply)
4497 if(loading)
4498 return;
4500 Unit *caster = GetCaster();
4501 if (!caster)
4502 return;
4504 switch (m_spellProto->SpellFamilyName)
4506 case SPELLFAMILY_GENERIC:
4508 // Pounce Bleed
4509 if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual[0] == 0 )
4511 // $AP*0.18/6 bonus per tick
4512 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4513 return;
4515 break;
4517 case SPELLFAMILY_WARRIOR:
4519 // Rend
4520 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000020))
4522 // $0.2*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4523 float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4524 int32 mws = caster->GetAttackTime(BASE_ATTACK);
4525 float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4526 float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4527 m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.2f);
4528 return;
4530 break;
4532 case SPELLFAMILY_DRUID:
4534 // Rake
4535 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellProto->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
4537 // $AP*0.18/3 bonus per tick
4538 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 6 / 100);
4539 return;
4541 // Lacerate
4542 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000010000000000))
4544 // $AP*0.05/5 bonus per tick
4545 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4546 return;
4548 // Rip
4549 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000800000))
4551 // 0.01*$AP*cp
4552 if (caster->GetTypeId() != TYPEID_PLAYER)
4553 return;
4555 uint8 cp = ((Player*)caster)->GetComboPoints();
4557 // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4558 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4559 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4561 if((*itr)->GetId()==34241)
4563 m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4564 break;
4567 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4568 return;
4570 // Lock Jaw
4571 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
4573 // 0.15*$AP
4574 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 15 / 100);
4575 return;
4577 break;
4579 case SPELLFAMILY_ROGUE:
4581 // Rupture
4582 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000100000))
4584 if (caster->GetTypeId() != TYPEID_PLAYER)
4585 return;
4586 //1 point : ${($m1+$b1*1+0.015*$AP)*4} damage over 8 secs
4587 //2 points: ${($m1+$b1*2+0.024*$AP)*5} damage over 10 secs
4588 //3 points: ${($m1+$b1*3+0.03*$AP)*6} damage over 12 secs
4589 //4 points: ${($m1+$b1*4+0.03428571*$AP)*7} damage over 14 secs
4590 //5 points: ${($m1+$b1*5+0.0375*$AP)*8} damage over 16 secs
4591 float AP_per_combo[6] = {0.0f, 0.015f, 0.024f, 0.03f, 0.03428571f, 0.0375f};
4592 uint8 cp = ((Player*)caster)->GetComboPoints();
4593 if (cp > 5) cp = 5;
4594 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * AP_per_combo[cp]);
4595 return;
4597 // Garrote
4598 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000000100))
4600 // $AP*0.07 bonus per tick
4601 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 7 / 100);
4602 return;
4604 // Deadly Poison
4605 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000010000))
4607 // 0.08*$AP / 4 * amount of stack
4608 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 2 * GetStackAmount() / 100);
4609 return;
4611 break;
4613 case SPELLFAMILY_HUNTER:
4615 // Serpent Sting
4616 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000004000))
4618 // $RAP*0.1/5 bonus per tick
4619 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4620 return;
4622 // Immolation Trap
4623 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) && m_spellProto->SpellIconID == 678)
4625 // $RAP*0.1/5 bonus per tick
4626 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4627 return;
4629 break;
4631 default:
4632 break;
4635 // remove time effects
4636 else
4638 // Parasitic Shadowfiend - handle summoning of two Shadowfiends on DoT expire
4639 if(m_spellProto->Id == 41917)
4640 m_target->CastSpell(m_target, 41915, true);
4644 void Aura::HandlePeriodicDamagePCT(bool apply, bool /*Real*/)
4646 m_isPeriodic = apply;
4649 void Aura::HandlePeriodicLeech(bool apply, bool /*Real*/)
4651 m_isPeriodic = apply;
4654 void Aura::HandlePeriodicManaLeech(bool apply, bool /*Real*/)
4656 m_isPeriodic = apply;
4659 void Aura::HandlePeriodicHealthFunnel(bool apply, bool /*Real*/)
4661 m_isPeriodic = apply;
4664 /*********************************************************/
4665 /*** MODIFY STATS ***/
4666 /*********************************************************/
4668 /********************************/
4669 /*** RESISTANCE ***/
4670 /********************************/
4672 void Aura::HandleAuraModResistanceExclusive(bool apply, bool /*Real*/)
4674 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4676 if(m_modifier.m_miscvalue & int32(1<<x))
4678 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4679 if(m_target->GetTypeId() == TYPEID_PLAYER)
4680 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4685 void Aura::HandleAuraModResistance(bool apply, bool /*Real*/)
4687 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4689 if(m_modifier.m_miscvalue & int32(1<<x))
4691 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4692 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4693 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4698 void Aura::HandleAuraModBaseResistancePCT(bool apply, bool /*Real*/)
4700 // only players have base stats
4701 if(m_target->GetTypeId() != TYPEID_PLAYER)
4703 //pets only have base armor
4704 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4705 m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4707 else
4709 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4711 if(m_modifier.m_miscvalue & int32(1<<x))
4712 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4717 void Aura::HandleModResistancePercent(bool apply, bool /*Real*/)
4719 for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4721 if(m_modifier.m_miscvalue & int32(1<<i))
4723 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4724 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4726 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, m_modifier.m_amount, apply);
4727 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, m_modifier.m_amount, apply);
4733 void Aura::HandleModBaseResistance(bool apply, bool /*Real*/)
4735 // only players have base stats
4736 if(m_target->GetTypeId() != TYPEID_PLAYER)
4738 //only pets have base stats
4739 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4740 m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4742 else
4744 for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4745 if(m_modifier.m_miscvalue & (1<<i))
4746 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4750 /********************************/
4751 /*** STAT ***/
4752 /********************************/
4754 void Aura::HandleAuraModStat(bool apply, bool /*Real*/)
4756 if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4758 sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4759 return;
4762 for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4764 // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4765 if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4767 //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4768 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4769 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4770 m_target->ApplyStatBuffMod(Stats(i), m_modifier.m_amount, apply);
4775 void Aura::HandleModPercentStat(bool apply, bool /*Real*/)
4777 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4779 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4780 return;
4783 // only players have base stats
4784 if (m_target->GetTypeId() != TYPEID_PLAYER)
4785 return;
4787 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4789 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4790 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4794 void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool /*Real*/)
4796 if(m_target->GetTypeId() != TYPEID_PLAYER)
4797 return;
4799 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4800 // This information for client side use only
4801 // Recalculate bonus
4802 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4805 void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool /*Real*/)
4807 if(m_target->GetTypeId() != TYPEID_PLAYER)
4808 return;
4810 // Recalculate bonus
4811 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4814 void Aura::HandleAuraModDispelResist(bool apply, bool Real)
4816 if(!Real || !apply)
4817 return;
4819 if(GetId() == 33206)
4820 m_target->CastSpell(m_target, 44416, true, NULL, this, GetCasterGUID());
4823 void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4825 if(m_target->GetTypeId() != TYPEID_PLAYER)
4826 return;
4828 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4829 // This information for client side use only
4830 // Recalculate bonus
4831 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4834 void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4836 if(m_target->GetTypeId() != TYPEID_PLAYER)
4837 return;
4839 // Recalculate bonus
4840 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4843 void Aura::HandleModHealingDone(bool /*apply*/, bool /*Real*/)
4845 if(m_target->GetTypeId() != TYPEID_PLAYER)
4846 return;
4847 // implemented in Unit::SpellHealingBonus
4848 // this information is for client side only
4849 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4852 void Aura::HandleModTotalPercentStat(bool apply, bool /*Real*/)
4854 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4856 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4857 return;
4860 //save current and max HP before applying aura
4861 uint32 curHPValue = m_target->GetHealth();
4862 uint32 maxHPValue = m_target->GetMaxHealth();
4864 for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4866 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4868 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4869 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4870 m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
4874 //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
4875 if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
4877 // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
4878 uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
4879 m_target->SetHealth(newHPValue);
4883 void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool /*Real*/)
4885 if(m_target->GetTypeId() != TYPEID_PLAYER)
4886 return;
4888 if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
4890 // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
4891 // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
4892 sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
4893 return;
4896 // Recalculate Armor
4897 m_target->UpdateArmor();
4900 /********************************/
4901 /*** HEAL & ENERGIZE ***/
4902 /********************************/
4903 void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool /*Real*/)
4905 m_isPeriodic = apply;
4908 void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool /*Real*/)
4910 if(m_modifier.periodictime == 0)
4911 m_modifier.periodictime = 1000;
4913 m_periodicTimer = m_modifier.periodictime;
4914 m_isPeriodic = apply;
4917 void Aura::HandleModRegen(bool apply, bool /*Real*/) // eating
4919 if(m_modifier.periodictime == 0)
4920 m_modifier.periodictime = 5000;
4922 m_periodicTimer = 5000;
4923 m_isPeriodic = apply;
4926 void Aura::HandleModPowerRegen(bool apply, bool Real) // drinking
4928 if (!Real)
4929 return;
4931 Powers pt = m_target->getPowerType();
4932 if(m_modifier.periodictime == 0)
4934 // Anger Management (only spell use this aura for rage)
4935 if (pt == POWER_RAGE)
4936 m_modifier.periodictime = 3000;
4937 else
4938 m_modifier.periodictime = 2000;
4941 m_periodicTimer = 5000;
4943 if (m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
4944 ((Player*)m_target)->UpdateManaRegen();
4946 m_isPeriodic = apply;
4949 void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real)
4951 // spells required only Real aura add/remove
4952 if(!Real)
4953 return;
4955 if (m_target->GetTypeId() != TYPEID_PLAYER)
4956 return;
4958 // Update manaregen value
4959 if (m_modifier.m_miscvalue == POWER_MANA)
4960 ((Player*)m_target)->UpdateManaRegen();
4963 void Aura::HandleModManaRegen(bool /*apply*/, bool Real)
4965 // spells required only Real aura add/remove
4966 if(!Real)
4967 return;
4969 if (m_target->GetTypeId() != TYPEID_PLAYER)
4970 return;
4972 //Note: an increase in regen does NOT cause threat.
4973 ((Player*)m_target)->UpdateManaRegen();
4976 void Aura::HandleComprehendLanguage(bool apply, bool /*Real*/)
4978 if(apply)
4979 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4980 else
4981 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4984 void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
4986 // Special case with temporary increase max/current health
4987 switch(GetId())
4989 case 12976: // Warrior Last Stand triggered spell
4990 case 28726: // Nightmare Seed ( Nightmare Seed )
4991 case 34511: // Valor (Bulwark of Kings, Bulwark of the Ancient Kings)
4992 case 44055: // Tremendous Fortitude (Battlemaster's Alacrity)
4993 case 50322: // Survival Instincts
4994 case 54443: // Demonic Empowerment (Voidwalker)
4996 if(Real)
4998 if(apply)
5000 // Demonic Empowerment (Voidwalker) - special case, store percent in data
5001 // recalculate to full amount at apply for proper remove
5002 if (GetId() == 54443)
5003 m_modifier.m_amount = m_target->GetMaxHealth() * m_modifier.m_amount / 100;
5005 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5006 m_target->ModifyHealth(m_modifier.m_amount);
5008 else
5010 if (int32(m_target->GetHealth()) > m_modifier.m_amount)
5011 m_target->ModifyHealth(-m_modifier.m_amount);
5012 else
5013 m_target->SetHealth(1);
5014 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5017 return;
5021 // generic case
5022 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5025 void Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool /*Real*/)
5027 uint32 oldhealth = m_target->GetHealth();
5028 double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
5030 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5032 // refresh percentage
5033 if(oldhealth > 0)
5035 uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
5036 if(newhealth==0)
5037 newhealth = 1;
5039 m_target->SetHealth(newhealth);
5043 void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
5045 Powers powerType = m_target->getPowerType();
5046 if(int32(powerType) != m_modifier.m_miscvalue)
5047 return;
5049 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5051 // Special case with temporary increase max/current power (percent)
5052 if (GetId()==64904) // Hymn of Hope
5054 if(Real)
5056 uint32 val = m_target->GetPower(powerType);
5057 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5058 m_target->SetPower(powerType, apply ? val*(100+m_modifier.m_amount)/100 : val*100/(100+m_modifier.m_amount));
5060 return;
5063 // generic flat case
5064 m_target->HandleStatModifier(unitMod, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5067 void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool /*Real*/)
5069 Powers powerType = m_target->getPowerType();
5070 if(int32(powerType) != m_modifier.m_miscvalue)
5071 return;
5073 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5075 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5078 void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool /*Real*/)
5080 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
5083 void Aura::HandleAuraIncreaseBaseHealthPercent(bool apply, bool /*Real*/)
5085 m_target->HandleStatModifier(UNIT_MOD_HEALTH, BASE_PCT, float(m_modifier.m_amount), apply);
5088 /********************************/
5089 /*** FIGHT ***/
5090 /********************************/
5092 void Aura::HandleAuraModParryPercent(bool /*apply*/, bool /*Real*/)
5094 if(m_target->GetTypeId() != TYPEID_PLAYER)
5095 return;
5097 ((Player*)m_target)->UpdateParryPercentage();
5100 void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool /*Real*/)
5102 if(m_target->GetTypeId() != TYPEID_PLAYER)
5103 return;
5105 ((Player*)m_target)->UpdateDodgePercentage();
5106 //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
5109 void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool /*Real*/)
5111 if(m_target->GetTypeId() != TYPEID_PLAYER)
5112 return;
5114 ((Player*)m_target)->UpdateBlockPercentage();
5115 //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
5118 void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real)
5120 // spells required only Real aura add/remove
5121 if(!Real)
5122 return;
5124 if(m_target->GetTypeId() != TYPEID_PLAYER)
5125 return;
5127 ((Player*)m_target)->UpdateManaRegen();
5130 void Aura::HandleAuraModCritPercent(bool apply, bool Real)
5132 if(m_target->GetTypeId() != TYPEID_PLAYER)
5133 return;
5135 // apply item specific bonuses for already equipped weapon
5136 if(Real)
5138 for(int i = 0; i < MAX_ATTACK; ++i)
5139 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5140 ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem, WeaponAttackType(i), this, apply);
5143 // mods must be applied base at equipped weapon class and subclass comparison
5144 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5145 // m_modifier.m_miscvalue comparison with item generated damage types
5147 if (GetSpellProto()->EquippedItemClass == -1)
5149 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5150 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5151 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5153 else
5155 // done in Player::_ApplyWeaponDependentAuraMods
5159 void Aura::HandleModHitChance(bool apply, bool /*Real*/)
5161 if(m_target->GetTypeId() == TYPEID_PLAYER)
5163 ((Player*)m_target)->UpdateMeleeHitChances();
5164 ((Player*)m_target)->UpdateRangedHitChances();
5166 else
5168 m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5169 m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5173 void Aura::HandleModSpellHitChance(bool apply, bool /*Real*/)
5175 if(m_target->GetTypeId() == TYPEID_PLAYER)
5177 ((Player*)m_target)->UpdateSpellHitChances();
5179 else
5181 m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
5185 void Aura::HandleModSpellCritChance(bool apply, bool Real)
5187 // spells required only Real aura add/remove
5188 if(!Real)
5189 return;
5191 if(m_target->GetTypeId() == TYPEID_PLAYER)
5193 ((Player*)m_target)->UpdateAllSpellCritChances();
5195 else
5197 m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
5201 void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real)
5203 // spells required only Real aura add/remove
5204 if(!Real)
5205 return;
5207 if(m_target->GetTypeId() != TYPEID_PLAYER)
5208 return;
5210 for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
5211 if (m_modifier.m_miscvalue & (1<<school))
5212 ((Player*)m_target)->UpdateSpellCritChance(school);
5215 /********************************/
5216 /*** ATTACK SPEED ***/
5217 /********************************/
5219 void Aura::HandleModCastingSpeed(bool apply, bool /*Real*/)
5221 m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
5224 void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool /*Real*/)
5226 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5227 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5228 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5231 void Aura::HandleModCombatSpeedPct(bool apply, bool /*Real*/)
5233 m_target->ApplyCastTimePercentMod(m_modifier.m_amount, apply);
5234 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5235 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5236 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5239 void Aura::HandleModAttackSpeed(bool apply, bool /*Real*/)
5241 if(!m_target->isAlive() )
5242 return;
5244 m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
5247 void Aura::HandleHaste(bool apply, bool /*Real*/)
5249 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5250 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5251 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5254 void Aura::HandleAuraModRangedHaste(bool apply, bool /*Real*/)
5256 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5259 void Aura::HandleRangedAmmoHaste(bool apply, bool /*Real*/)
5261 if(m_target->GetTypeId() != TYPEID_PLAYER)
5262 return;
5263 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
5266 /********************************/
5267 /*** ATTACK POWER ***/
5268 /********************************/
5270 void Aura::HandleAuraModAttackPower(bool apply, bool /*Real*/)
5272 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5275 void Aura::HandleAuraModRangedAttackPower(bool apply, bool /*Real*/)
5277 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5278 return;
5280 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5283 void Aura::HandleAuraModAttackPowerPercent(bool apply, bool /*Real*/)
5285 //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
5286 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
5289 void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool /*Real*/)
5291 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5292 return;
5294 //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
5295 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5298 void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5300 // spells required only Real aura add/remove
5301 if(!Real)
5302 return;
5304 // Recalculate bonus
5305 if(m_target->GetTypeId() == TYPEID_PLAYER && !(m_target->getClassMask() & CLASSMASK_WAND_USERS))
5306 ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
5309 void Aura::HandleAuraModAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5311 // spells required only Real aura add/remove
5312 if(!Real)
5313 return;
5315 // Recalculate bonus
5316 if(m_target->GetTypeId() == TYPEID_PLAYER)
5317 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5320 void Aura::HandleAuraModAttackPowerOfArmor(bool /*apply*/, bool Real)
5322 // spells required only Real aura add/remove
5323 if(!Real)
5324 return;
5326 // Recalculate bonus
5327 if(m_target->GetTypeId() == TYPEID_PLAYER)
5328 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5330 /********************************/
5331 /*** DAMAGE BONUS ***/
5332 /********************************/
5333 void Aura::HandleModDamageDone(bool apply, bool Real)
5335 // apply item specific bonuses for already equipped weapon
5336 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5338 for(int i = 0; i < MAX_ATTACK; ++i)
5339 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5340 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5343 // m_modifier.m_miscvalue is bitmask of spell schools
5344 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5345 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
5346 // 127 - full bitmask any damages
5348 // mods must be applied base at equipped weapon class and subclass comparison
5349 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5350 // m_modifier.m_miscvalue comparison with item generated damage types
5352 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5354 // apply generic physical damage bonuses including wand case
5355 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5357 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5358 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5359 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5361 else
5363 // done in Player::_ApplyWeaponDependentAuraMods
5366 if(m_target->GetTypeId() == TYPEID_PLAYER)
5368 if(m_positive)
5369 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS, m_modifier.m_amount, apply);
5370 else
5371 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG, m_modifier.m_amount, apply);
5375 // Skip non magic case for speedup
5376 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5377 return;
5379 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5381 // wand magic case (skip generic to all item spell bonuses)
5382 // done in Player::_ApplyWeaponDependentAuraMods
5384 // Skip item specific requirements for not wand magic damage
5385 return;
5388 // Magic damage modifiers implemented in Unit::SpellDamageBonus
5389 // This information for client side use only
5390 if(m_target->GetTypeId() == TYPEID_PLAYER)
5392 if(m_positive)
5394 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5396 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5397 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, m_modifier.m_amount, apply);
5400 else
5402 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5404 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5405 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, m_modifier.m_amount, apply);
5408 Pet* pet = m_target->GetPet();
5409 if(pet)
5410 pet->UpdateAttackPowerAndDamage();
5414 void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5416 sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5418 // apply item specific bonuses for already equipped weapon
5419 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5421 for(int i = 0; i < MAX_ATTACK; ++i)
5422 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5423 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5426 // m_modifier.m_miscvalue is bitmask of spell schools
5427 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5428 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5429 // 127 - full bitmask any damages
5431 // mods must be applied base at equipped weapon class and subclass comparison
5432 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5433 // m_modifier.m_miscvalue comparison with item generated damage types
5435 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5437 // apply generic physical damage bonuses including wand case
5438 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5440 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5441 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5442 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5444 else
5446 // done in Player::_ApplyWeaponDependentAuraMods
5448 // For show in client
5449 if(m_target->GetTypeId() == TYPEID_PLAYER)
5450 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT, m_modifier.m_amount/100.0f, apply);
5453 // Skip non magic case for speedup
5454 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5455 return;
5457 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5459 // wand magic case (skip generic to all item spell bonuses)
5460 // done in Player::_ApplyWeaponDependentAuraMods
5462 // Skip item specific requirements for not wand magic damage
5463 return;
5466 // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5467 // Send info to client
5468 if(m_target->GetTypeId() == TYPEID_PLAYER)
5469 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5470 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT + i, m_modifier.m_amount/100.0f, apply);
5473 void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5475 // spells required only Real aura add/remove
5476 if(!Real)
5477 return;
5479 sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5481 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5484 /********************************/
5485 /*** POWER COST ***/
5486 /********************************/
5488 void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5490 // spells required only Real aura add/remove
5491 if(!Real)
5492 return;
5494 float amount = m_modifier.m_amount/100.0f;
5495 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5496 if(m_modifier.m_miscvalue & (1<<i))
5497 m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + i, amount, apply);
5500 void Aura::HandleModPowerCost(bool apply, bool Real)
5502 // spells required only Real aura add/remove
5503 if(!Real)
5504 return;
5506 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5507 if(m_modifier.m_miscvalue & (1<<i))
5508 m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + i, m_modifier.m_amount, apply);
5511 void Aura::HandleNoReagentUseAura(bool /*Apply*/, bool Real)
5513 // spells required only Real aura add/remove
5514 if(!Real)
5515 return;
5516 if(m_target->GetTypeId() != TYPEID_PLAYER)
5517 return;
5518 uint32 mask[3] = {0, 0, 0};
5519 Unit::AuraList const& noReagent = m_target->GetAurasByType(SPELL_AURA_NO_REAGENT_USE);
5520 for(Unit::AuraList::const_iterator i = noReagent.begin(); i != noReagent.end(); ++i)
5522 uint32 const *ptr = (*i)->getAuraSpellClassMask();
5523 mask[0] |= ptr[0];
5524 mask[1] |= ptr[1];
5525 mask[2] |= ptr[2];
5528 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+0, mask[0]);
5529 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+1, mask[1]);
5530 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+2, mask[2]);
5533 /*********************************************************/
5534 /*** OTHERS ***/
5535 /*********************************************************/
5537 void Aura::HandleShapeshiftBoosts(bool apply)
5539 uint32 spellId1 = 0;
5540 uint32 spellId2 = 0;
5541 uint32 HotWSpellId = 0;
5542 uint32 MasterShaperSpellId = 0;
5544 uint32 form = GetModifier()->m_miscvalue;
5546 switch(form)
5548 case FORM_CAT:
5549 spellId1 = 3025;
5550 HotWSpellId = 24900;
5551 MasterShaperSpellId = 48420;
5552 break;
5553 case FORM_TREE:
5554 spellId1 = 5420;
5555 spellId2 = 34123;
5556 MasterShaperSpellId = 48422;
5557 break;
5558 case FORM_TRAVEL:
5559 spellId1 = 5419;
5560 break;
5561 case FORM_AQUA:
5562 spellId1 = 5421;
5563 break;
5564 case FORM_BEAR:
5565 spellId1 = 1178;
5566 spellId2 = 21178;
5567 HotWSpellId = 24899;
5568 MasterShaperSpellId = 48418;
5569 break;
5570 case FORM_DIREBEAR:
5571 spellId1 = 9635;
5572 spellId2 = 21178;
5573 HotWSpellId = 24899;
5574 MasterShaperSpellId = 48418;
5575 break;
5576 case FORM_BATTLESTANCE:
5577 spellId1 = 21156;
5578 break;
5579 case FORM_DEFENSIVESTANCE:
5580 spellId1 = 7376;
5581 break;
5582 case FORM_BERSERKERSTANCE:
5583 spellId1 = 7381;
5584 break;
5585 case FORM_MOONKIN:
5586 spellId1 = 24905;
5587 MasterShaperSpellId = 48421;
5588 break;
5589 case FORM_FLIGHT:
5590 spellId1 = 33948;
5591 spellId2 = 34764;
5592 break;
5593 case FORM_FLIGHT_EPIC:
5594 spellId1 = 40122;
5595 spellId2 = 40121;
5596 break;
5597 case FORM_METAMORPHOSIS:
5598 spellId1 = 54817;
5599 spellId2 = 54879;
5600 break;
5601 case FORM_SPIRITOFREDEMPTION:
5602 spellId1 = 27792;
5603 spellId2 = 27795; // must be second, this important at aura remove to prevent to early iterator invalidation.
5604 break;
5605 case FORM_SHADOW:
5606 spellId1 = 49868;
5608 if(m_target->GetTypeId() == TYPEID_PLAYER) // Spell 49868 have same category as main form spell and share cooldown
5609 ((Player*)m_target)->RemoveSpellCooldown(49868);
5610 break;
5611 case FORM_GHOSTWOLF:
5612 case FORM_AMBIENT:
5613 case FORM_GHOUL:
5614 case FORM_STEALTH:
5615 case FORM_CREATURECAT:
5616 case FORM_CREATUREBEAR:
5617 break;
5620 if(apply)
5622 if (spellId1)
5623 m_target->CastSpell(m_target, spellId1, true, NULL, this );
5624 if (spellId2)
5625 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5627 if (m_target->GetTypeId() == TYPEID_PLAYER)
5629 const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5630 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5632 if (itr->second->state == PLAYERSPELL_REMOVED) continue;
5633 if (itr->first==spellId1 || itr->first==spellId2) continue;
5634 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5635 if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7))))
5636 continue;
5637 if (spellInfo->Stances & (1<<(form-1)))
5638 m_target->CastSpell(m_target, itr->first, true, NULL, this);
5641 // Master Shapeshifter
5642 if (MasterShaperSpellId)
5644 Unit::AuraList const& ShapeShifterAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5645 for(Unit::AuraList::const_iterator i = ShapeShifterAuras.begin(); i != ShapeShifterAuras.end(); i++)
5647 if ((*i)->GetSpellProto()->SpellIconID == 2851)
5649 int32 ShiftMod = (*i)->GetModifier()->m_amount;
5650 m_target->CastCustomSpell(m_target, MasterShaperSpellId, &ShiftMod, NULL, NULL, true);
5651 break;
5656 // Leader of the Pack
5657 if (((Player*)m_target)->HasSpell(17007))
5659 SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5660 if (spellInfo && spellInfo->Stances & (1<<(form-1)))
5661 m_target->CastSpell(m_target, 24932, true, NULL, this);
5664 // Savage Roar
5665 if (form == FORM_CAT && ((Player*)m_target)->HasAura(52610))
5666 m_target->CastSpell(m_target, 62071, true);
5668 // Improved Moonkin Form
5669 if (form == FORM_MOONKIN)
5671 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5672 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); i++)
5674 if ((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_DRUID &&
5675 (*i)->GetSpellProto()->SpellIconID == 2855)
5677 uint32 spell_id = 0;
5678 switch((*i)->GetId())
5680 case 48384:spell_id=50170;break;//Rank 1
5681 case 48395:spell_id=50171;break;//Rank 2
5682 case 48396:spell_id=50172;break;//Rank 3
5683 default:
5684 sLog.outError("Aura::HandleShapeshiftBoosts: Not handled rank of IMF (Spell: %u)",(*i)->GetId());
5685 break;
5688 if(spell_id)
5689 m_target->CastSpell(m_target, spell_id, true, NULL, this);
5690 break;
5695 // Heart of the Wild
5696 if (HotWSpellId)
5698 Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5699 for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5701 if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5703 int32 HotWMod = (*i)->GetModifier()->m_amount;
5704 if(GetModifier()->m_miscvalue == FORM_CAT)
5705 HotWMod /= 2;
5707 m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5708 break;
5714 else
5716 if(spellId1)
5717 m_target->RemoveAurasDueToSpell(spellId1);
5718 if(spellId2)
5719 m_target->RemoveAurasDueToSpell(spellId2);
5720 if(MasterShaperSpellId)
5721 m_target->RemoveAurasDueToSpell(MasterShaperSpellId);
5723 Unit::AuraMap& tAuras = m_target->GetAuras();
5724 for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5726 if (itr->second->IsRemovedOnShapeLost())
5728 m_target->RemoveAurasDueToSpell(itr->second->GetId());
5729 itr = tAuras.begin();
5731 else
5732 ++itr;
5737 void Aura::HandleSpellSpecificBoosts(bool apply)
5739 uint32 spellId1 = 0;
5740 uint32 spellId2 = 0;
5741 uint32 spellId3 = 0;
5742 uint32 spellId4 = 0;
5744 switch(GetSpellProto()->SpellFamilyName)
5746 case SPELLFAMILY_WARRIOR:
5748 if(!apply)
5750 // Remove Blood Frenzy only if target no longer has any Deep Wound or Rend (applying is handled by procs)
5751 if (GetSpellProto()->Mechanic != MECHANIC_BLEED)
5752 return;
5754 // If target still has one of Warrior's bleeds, do nothing
5755 Unit::AuraList const& PeriodicDamage = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
5756 for(Unit::AuraList::const_iterator i = PeriodicDamage.begin(); i != PeriodicDamage.end(); ++i)
5757 if( (*i)->GetCasterGUID() == GetCasterGUID() &&
5758 (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARRIOR &&
5759 (*i)->GetSpellProto()->Mechanic == MECHANIC_BLEED)
5760 return;
5762 spellId1 = 30069;
5763 spellId2 = 30070;
5765 break;
5767 case SPELLFAMILY_PRIEST:
5768 // Dispersion mana reg and immunity
5769 if (GetSpellProto()->Id == 47585)
5771 spellId1 = 60069;
5772 spellId2 = 63230;
5774 break;
5775 case SPELLFAMILY_ROGUE:
5776 // Sprint (skip non player casted spells by category)
5777 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000040) && GetSpellProto()->Category == 44)
5779 if(!apply || m_target->HasAura(58039)) // Glyph of Blurred Speed
5780 spellId1 = 61922; // Sprint (waterwalk)
5781 else
5782 return;
5784 else
5785 return;
5786 break;
5787 case SPELLFAMILY_HUNTER:
5789 // The Beast Within and Bestial Wrath - immunity
5790 if (GetId() == 19574 || GetId() == 34471)
5792 spellId1 = 24395;
5793 spellId2 = 24396;
5794 spellId3 = 24397;
5795 spellId4 = 26592;
5797 // Aspect of the Dragonhawk dodge
5798 else if (GetSpellProto()->SpellFamilyFlags2 & 0x00001000)
5800 spellId1 = 61848;
5802 // triggered spell have same category as main spell and cooldown
5803 if (apply && m_target->GetTypeId()==TYPEID_PLAYER)
5804 ((Player*)m_target)->RemoveSpellCooldown(61848);
5806 else
5807 return;
5808 break;
5810 case SPELLFAMILY_PALADIN:
5812 // Only process on player casting paladin aura
5813 // all aura bonuses applied also in aura area effect way to caster
5814 if (GetCasterGUID() != m_target->GetGUID() || !IS_PLAYER_GUID(GetCasterGUID()))
5815 return;
5817 if (GetSpellSpecific(m_spellProto->Id) != SPELL_AURA)
5818 return;
5820 // Sanctified Retribution and Swift Retribution (they share one aura), but not Retribution Aura (already gets modded)
5821 if ((GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000008))==0)
5822 spellId1 = 63531; // placeholder for talent spell mods
5823 // Improved Concentration Aura (auras bonus)
5824 spellId2 = 63510; // placeholder for talent spell mods
5825 // Improved Devotion Aura (auras bonus)
5826 spellId3 = 63514; // placeholder for talent spell mods
5827 break;
5829 case SPELLFAMILY_DEATHKNIGHT:
5831 if (GetSpellSpecific(m_spellProto->Id) != SPELL_PRESENCE)
5832 return;
5834 // Frost Presence health
5835 if (GetId() == 48263)
5836 spellId1 = 61261;
5837 // Unholy Presence move speed
5838 else if (GetId() == 48265)
5839 spellId1 = 49772;
5840 else
5841 return;
5843 break;
5845 default:
5846 return;
5849 // prevent aura deletion, specially in multi-boost case
5850 SetInUse(true);
5852 if (apply)
5854 if (spellId1)
5855 m_target->CastSpell(m_target, spellId1, true, NULL, this);
5856 if (spellId2 && !IsDeleted())
5857 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5858 if (spellId3 && !IsDeleted())
5859 m_target->CastSpell(m_target, spellId3, true, NULL, this);
5860 if (spellId4 && !IsDeleted())
5861 m_target->CastSpell(m_target, spellId4, true, NULL, this);
5863 else
5865 if (spellId1)
5866 m_target->RemoveAurasByCasterSpell(spellId1, GetCasterGUID());
5867 if (spellId2)
5868 m_target->RemoveAurasByCasterSpell(spellId2, GetCasterGUID());
5869 if (spellId3)
5870 m_target->RemoveAurasByCasterSpell(spellId3, GetCasterGUID());
5871 if (spellId4)
5872 m_target->RemoveAurasByCasterSpell(spellId4, GetCasterGUID());
5875 SetInUse(false);
5878 void Aura::HandleAuraEmpathy(bool apply, bool /*Real*/)
5880 if(m_target->GetTypeId() != TYPEID_UNIT)
5881 return;
5883 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5884 if(ci && ci->type == CREATURE_TYPE_BEAST)
5885 m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5888 void Aura::HandleAuraUntrackable(bool apply, bool /*Real*/)
5890 if(apply)
5891 m_target->SetByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5892 else
5893 m_target->RemoveByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5896 void Aura::HandleAuraModPacify(bool apply, bool /*Real*/)
5898 if(m_target->GetTypeId() != TYPEID_PLAYER)
5899 return;
5901 if(apply)
5902 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5903 else
5904 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5907 void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5909 HandleAuraModPacify(apply, Real);
5910 HandleAuraModSilence(apply, Real);
5913 void Aura::HandleAuraGhost(bool apply, bool /*Real*/)
5915 if(m_target->GetTypeId() != TYPEID_PLAYER)
5916 return;
5918 if(apply)
5920 m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5922 else
5924 m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5928 void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5930 // all applied/removed only at real aura add/remove
5931 if(!Real)
5932 return;
5934 // allow fly
5935 WorldPacket data;
5936 if(apply)
5937 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5938 else
5939 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5940 data.append(m_target->GetPackGUID());
5941 data << uint32(0); // unk
5942 m_target->SendMessageToSet(&data, true);
5945 void Aura::HandleModRating(bool apply, bool Real)
5947 // spells required only Real aura add/remove
5948 if(!Real)
5949 return;
5951 if(m_target->GetTypeId() != TYPEID_PLAYER)
5952 return;
5954 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5955 if (m_modifier.m_miscvalue & (1 << rating))
5956 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5959 void Aura::HandleModRatingFromStat(bool apply, bool Real)
5961 // spells required only Real aura add/remove
5962 if(!Real)
5963 return;
5965 if(m_target->GetTypeId() != TYPEID_PLAYER)
5966 return;
5967 // Just recalculate ratings
5968 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5969 if (m_modifier.m_miscvalue & (1 << rating))
5970 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), 0, apply);
5973 void Aura::HandleForceMoveForward(bool apply, bool Real)
5975 if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5976 return;
5977 if(apply)
5978 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5979 else
5980 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5983 void Aura::HandleAuraModExpertise(bool /*apply*/, bool /*Real*/)
5985 if(m_target->GetTypeId() != TYPEID_PLAYER)
5986 return;
5988 ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5989 ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5992 void Aura::HandleModTargetResistance(bool apply, bool Real)
5994 // spells required only Real aura add/remove
5995 if(!Real)
5996 return;
5997 // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
5999 // show armor penetration
6000 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
6001 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE, m_modifier.m_amount, apply);
6003 // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
6004 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
6005 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE, m_modifier.m_amount, apply);
6008 void Aura::HandleShieldBlockValue(bool apply, bool /*Real*/)
6010 BaseModType modType = FLAT_MOD;
6011 if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
6012 modType = PCT_MOD;
6014 if(m_target->GetTypeId() == TYPEID_PLAYER)
6015 ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
6018 void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
6020 // spells required only Real aura add/remove
6021 if(!Real)
6022 return;
6024 if(m_target->GetTypeId() != TYPEID_PLAYER)
6025 return;
6027 Player *target = (Player*)m_target;
6029 // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
6030 // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
6031 if( !apply && m_duration==0 && target->GetComboTarget())
6032 if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
6033 target->AddComboPoints(unit, -m_modifier.m_amount);
6036 void Aura::HandleModUnattackable( bool Apply, bool Real )
6038 if(Real && Apply)
6040 m_target->CombatStop();
6041 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
6043 m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
6046 void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
6048 // spells required only Real aura add/remove
6049 if(!Real)
6050 return;
6052 // prepare spirit state
6053 if(apply)
6055 if(m_target->GetTypeId()==TYPEID_PLAYER)
6057 // disable breath/etc timers
6058 ((Player*)m_target)->StopMirrorTimers();
6060 // set stand state (expected in this form)
6061 if(!m_target->IsStandState())
6062 m_target->SetStandState(UNIT_STAND_STATE_STAND);
6065 m_target->SetHealth(1);
6067 // die at aura end
6068 else
6069 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
6072 void Aura::CleanupTriggeredSpells()
6074 uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
6075 if(!tSpellId)
6076 return;
6078 SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
6079 if(!tProto)
6080 return;
6082 if(GetSpellDuration(tProto) != -1)
6083 return;
6085 // needed for spell 43680, maybe others
6086 // TODO: is there a spell flag, which can solve this in a more sophisticated way?
6087 if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
6088 GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
6089 return;
6090 m_target->RemoveAurasDueToSpell(tSpellId);
6093 void Aura::HandleSchoolAbsorb(bool apply, bool Real)
6095 if(!Real)
6096 return;
6098 Unit* caster = GetCaster();
6099 if(!caster)
6100 return;
6102 if (apply)
6104 // prevent double apply bonuses
6105 if (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
6107 float DoneActualBenefit = 0.0f;
6108 switch(m_spellProto->SpellFamilyName)
6110 case SPELLFAMILY_PRIEST:
6111 // Power Word: Shield
6112 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001))
6113 //+80.68% from +spell bonus
6114 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.8068f;
6115 break;
6116 case SPELLFAMILY_MAGE:
6117 // Frost Ward, Fire Ward
6118 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000108))
6119 //+10% from +spell bonus
6120 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
6121 // Ice Barrier
6122 else if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000100000000))
6123 //+80.67% from +spell bonus
6124 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.8067f;
6125 break;
6126 case SPELLFAMILY_WARLOCK:
6127 // Shadow Ward
6128 if (m_spellProto->SpellFamilyFlags2 & 0x00000040)
6129 //+30% from +spell bonus
6130 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.30f;
6131 break;
6132 case SPELLFAMILY_PALADIN:
6133 // Sacred Shield
6134 // (check not strictly needed, only Sacred Shield has SPELL_AURA_SCHOOL_ABSORB in SPELLFAMILY_PALADIN at this time)
6135 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0008000000000000))
6137 // +75% from spell power
6138 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.75f;
6140 break;
6141 case SPELLFAMILY_DRUID:
6142 // Savage Defense (amount store original percent of attack power applied)
6143 if (m_spellProto->SpellIconID == 50) // only spell with this aura fit
6144 m_modifier.m_amount = int32(m_modifier.m_amount * m_target->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
6145 break;
6146 default:
6147 break;
6150 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6152 m_modifier.m_amount += (int32)DoneActualBenefit;
6155 else
6157 // Ice Barrier (remove effect from Shattered Barrier)
6158 if (m_spellProto->SpellIconID == 32 && m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE)
6160 if (!((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6161 return;
6163 if (m_target->HasAura(44745,0)) // Shattered Barrier, rank 1
6165 if(roll_chance_i(50))
6166 m_target->CastSpell(m_target, 55080, true, NULL, this);
6168 else if (m_target->HasAura(54787,0)) // Shattered Barrier, rank 2
6170 m_target->CastSpell(m_target, 55080, true, NULL, this);
6174 if (caster &&
6175 // Power Word: Shield
6176 m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST && m_spellProto->Mechanic == MECHANIC_SHIELD &&
6177 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001)) &&
6178 // completely absorbed or dispelled
6179 ((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6181 Unit::AuraList const& vDummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6182 for(Unit::AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); itr++)
6184 SpellEntry const* vSpell = (*itr)->GetSpellProto();
6186 // Rapture (main spell)
6187 if(vSpell->SpellFamilyName == SPELLFAMILY_PRIEST && vSpell->SpellIconID == 2894 && vSpell->Effect[1])
6189 switch((*itr)->GetEffIndex())
6191 case 0:
6193 // energize caster
6194 int32 manapct1000 = 5 * ((*itr)->GetModifier()->m_amount + spellmgr.GetSpellRank(vSpell->Id));
6195 int32 basepoints0 = caster->GetMaxPower(POWER_MANA) * manapct1000 / 1000;
6196 caster->CastCustomSpell(caster, 47755, &basepoints0, NULL, NULL, true);
6197 break;
6199 case 1:
6201 // energize target
6202 if (!roll_chance_i((*itr)->GetModifier()->m_amount) || caster->HasAura(63853))
6203 break;
6205 switch(m_target->getPowerType())
6207 case POWER_RUNIC_POWER:
6208 m_target->CastSpell(m_target, 63652, true, NULL, NULL, m_caster_guid);
6209 break;
6210 case POWER_RAGE:
6211 m_target->CastSpell(m_target, 63653, true, NULL, NULL, m_caster_guid);
6212 break;
6213 case POWER_MANA:
6215 int32 basepoints0 = m_target->GetMaxPower(POWER_MANA) * 2 / 100;
6216 m_target->CastCustomSpell(m_target, 63654, &basepoints0, NULL, NULL, true);
6217 break;
6219 case POWER_ENERGY:
6220 m_target->CastSpell(m_target, 63655, true, NULL, NULL, m_caster_guid);
6221 break;
6222 default:
6223 break;
6226 //cooldwon aura
6227 caster->CastSpell(caster, 63853, true);
6228 break;
6230 default:
6231 sLog.outError("Changes in R-dummy spell???: effect 3");
6232 break;
6240 void Aura::PeriodicTick()
6242 if(!m_target->isAlive())
6243 return;
6245 switch(m_modifier.m_auraname)
6247 case SPELL_AURA_PERIODIC_DAMAGE:
6248 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
6250 Unit *pCaster = GetCaster();
6251 if(!pCaster)
6252 return;
6254 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6255 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6256 return;
6258 // Check for immune (not use charges)
6259 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6260 return;
6262 // some auras remove at specific health level or more
6263 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6265 switch(GetId())
6267 case 43093: case 31956: case 38801:
6268 case 35321: case 38363: case 39215:
6269 if(m_target->GetHealth() == m_target->GetMaxHealth() )
6271 m_target->RemoveAurasDueToSpell(GetId());
6272 return;
6274 break;
6275 case 38772:
6277 uint32 percent =
6278 GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_DUMMY ?
6279 pCaster->CalculateSpellDamage(GetSpellProto(), GetEffIndex() + 1, GetSpellProto()->EffectBasePoints[GetEffIndex() + 1], m_target) :
6280 100;
6281 if(m_target->GetHealth() * 100 >= m_target->GetMaxHealth() * percent )
6283 m_target->RemoveAurasDueToSpell(GetId());
6284 return;
6286 break;
6288 default:
6289 break;
6293 uint32 absorb = 0;
6294 uint32 resist = 0;
6295 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6297 // ignore non positive values (can be result apply spellmods to aura damage
6298 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6300 uint32 pdamage;
6302 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6304 pdamage = amount;
6306 // Calculate armor mitigation if it is a physical spell
6307 // But not for bleed mechanic spells
6308 if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
6309 GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
6311 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6312 cleanDamage.damage += pdamage - pdamageReductedArmor;
6313 pdamage = pdamageReductedArmor;
6316 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6318 // Curse of Agony damage-per-tick calculation
6319 if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000400)) && GetSpellProto()->SpellIconID==544)
6321 // 1..4 ticks, 1/2 from normal tick damage
6322 if (m_duration >= ((m_maxduration-m_modifier.periodictime) * 2 / 3))
6323 pdamage = pdamage/2;
6324 // 9..12 ticks, 3/2 from normal tick damage
6325 else if(m_duration < ((m_maxduration-m_modifier.periodictime) / 3))
6326 pdamage += (pdamage + 1) / 2; // +1 prevent 0.5 damage possible lost at 1..4 ticks
6327 // 5..8 ticks have normal tick damage
6330 else
6331 pdamage = uint32(m_target->GetMaxHealth()*amount/100);
6333 // This method can modify pdamage
6334 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6336 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6337 // Reduce dot damage from resilience for players
6338 if (m_target->GetTypeId() == TYPEID_PLAYER)
6339 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6341 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6343 sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6344 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6346 pCaster->DealDamageMods(m_target, pdamage, &absorb);
6348 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, absorb, resist, 0.0f, isCrit);
6349 m_target->SendPeriodicAuraLog(&pInfo);
6351 // Set trigger flag
6352 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6353 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6354 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage - absorb - resist);
6355 if (pdamage)
6356 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6357 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6359 pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6360 break;
6362 case SPELL_AURA_PERIODIC_LEECH:
6363 case SPELL_AURA_PERIODIC_HEALTH_FUNNEL:
6365 Unit *pCaster = GetCaster();
6366 if(!pCaster)
6367 return;
6369 if(!pCaster->isAlive())
6370 return;
6372 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6373 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6374 return;
6376 // Check for immune
6377 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6378 return;
6380 uint32 absorb=0;
6381 uint32 resist=0;
6382 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6384 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6386 //Calculate armor mitigation if it is a physical spell
6387 if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
6389 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6390 cleanDamage.damage += pdamage - pdamageReductedArmor;
6391 pdamage = pdamageReductedArmor;
6394 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6396 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6397 // Reduce dot damage from resilience for players
6398 if (m_target->GetTypeId()==TYPEID_PLAYER)
6399 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6401 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6403 if(m_target->GetHealth() < pdamage)
6404 pdamage = uint32(m_target->GetHealth());
6406 sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6407 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6409 pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
6411 float multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()] > 0 ? GetSpellProto()->EffectMultipleValue[GetEffIndex()] : 1;
6413 // Set trigger flag
6414 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6415 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6416 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage-absorb-resist);
6417 if (pdamage)
6418 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6419 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6420 int32 new_damage = pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
6422 if (!m_target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
6423 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
6424 if (Spell* spell = pCaster->GetCurrentSpell(CurrentSpellTypes(i)))
6425 if (spell->m_spellInfo->Id == GetId())
6426 spell->cancel();
6429 if(Player *modOwner = pCaster->GetSpellModOwner())
6430 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, multiplier);
6432 uint32 heal = pCaster->SpellHealingBonus(pCaster, GetSpellProto(), uint32(new_damage * multiplier), DOT, GetStackAmount());
6434 int32 gain = pCaster->DealHeal(pCaster, heal, GetSpellProto());
6435 pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, GetSpellProto());
6436 break;
6438 case SPELL_AURA_PERIODIC_HEAL:
6439 case SPELL_AURA_OBS_MOD_HEALTH:
6441 Unit *pCaster = GetCaster();
6442 if(!pCaster)
6443 return;
6445 // heal for caster damage (must be alive)
6446 if(m_target != pCaster && GetSpellProto()->SpellVisual[0] == 163 && !pCaster->isAlive())
6447 return;
6449 // ignore non positive values (can be result apply spellmods to aura damage
6450 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6452 uint32 pdamage;
6454 if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
6455 pdamage = uint32(m_target->GetMaxHealth() * amount / 100);
6456 else
6458 pdamage = amount;
6460 // Wild Growth (1/7 - 6 + 2*ramainTicks) %
6461 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && m_spellProto->SpellIconID == 2864)
6463 int32 ticks = m_maxduration/m_modifier.periodictime;
6464 int32 remainingTicks = int32(float(m_duration) / m_modifier.periodictime + 0.5);
6465 pdamage = int32(pdamage) + int32(amount)*ticks*(-6+2*remainingTicks)/100;
6469 pdamage = pCaster->SpellHealingBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6471 // This method can modify pdamage
6472 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6474 sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
6475 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6477 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f, isCrit);
6478 m_target->SendPeriodicAuraLog(&pInfo);
6480 int32 gain = m_target->ModifyHealth(pdamage);
6482 // add HoTs to amount healed in bgs
6483 if( pCaster->GetTypeId() == TYPEID_PLAYER )
6484 if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
6485 bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
6487 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6489 SpellEntry const* spellProto = GetSpellProto();
6491 // heal for caster damage
6492 if(m_target != pCaster && spellProto->SpellVisual[0] == 163)
6494 uint32 dmg = spellProto->manaPerSecond;
6495 if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
6497 pCaster->RemoveAurasDueToSpell(GetId());
6499 // finish current generic/channeling spells, don't affect autorepeat
6500 pCaster->FinishSpell(CURRENT_GENERIC_SPELL);
6501 pCaster->FinishSpell(CURRENT_CHANNELED_SPELL);
6503 else
6505 uint32 damage = gain;
6506 uint32 absorb = 0;
6507 pCaster->DealDamageMods(pCaster, damage, &absorb);
6508 pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), damage, GetSpellSchoolMask(GetSpellProto()), absorb, 0, false, 0, false);
6510 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6511 pCaster->DealDamage(pCaster, damage, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6515 // uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC;// | PROC_FLAG_SUCCESSFUL_HEAL;
6516 // uint32 procVictim = 0;//ROC_FLAG_ON_TAKE_PERIODIC | PROC_FLAG_TAKEN_HEAL;
6517 // ignore item heals
6518 // if(procSpell && !haveCastItem)
6519 // pCaster->ProcDamageAndSpell(target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, spellProto);
6520 break;
6522 case SPELL_AURA_PERIODIC_MANA_LEECH:
6524 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6525 return;
6527 Powers power = Powers(m_modifier.m_miscvalue);
6529 // power type might have changed between aura applying and tick (druid's shapeshift)
6530 if(m_target->getPowerType() != power)
6531 return;
6533 Unit *pCaster = GetCaster();
6534 if(!pCaster)
6535 return;
6537 if(!pCaster->isAlive())
6538 return;
6540 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6541 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6542 return;
6544 // Check for immune (not use charges)
6545 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6546 return;
6548 // ignore non positive values (can be result apply spellmods to aura damage
6549 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6551 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
6552 // It's mana percent cost spells, m_modifier.m_amount is percent drain from target
6553 if (m_spellProto->ManaCostPercentage)
6555 // max value
6556 uint32 maxmana = pCaster->GetMaxPower(power) * pdamage * 2 / 100;
6557 pdamage = m_target->GetMaxPower(power) * pdamage / 100;
6558 if(pdamage > maxmana)
6559 pdamage = maxmana;
6562 sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
6563 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6565 int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
6567 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6568 if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6569 drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
6571 m_target->ModifyPower(power, -drain_amount);
6573 float gain_multiplier = 0;
6575 if(pCaster->GetMaxPower(power) > 0)
6577 gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
6579 if(Player *modOwner = pCaster->GetSpellModOwner())
6580 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
6583 SpellPeriodicAuraLogInfo pInfo(this, drain_amount, 0, 0, 0, gain_multiplier);
6584 m_target->SendPeriodicAuraLog(&pInfo);
6586 int32 gain_amount = int32(drain_amount * gain_multiplier);
6588 if(gain_amount)
6590 int32 gain = pCaster->ModifyPower(power, gain_amount);
6591 m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
6593 break;
6595 case SPELL_AURA_PERIODIC_ENERGIZE:
6597 // ignore non positive values (can be result apply spellmods to aura damage
6598 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6600 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
6601 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6603 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6604 break;
6606 Powers power = Powers(m_modifier.m_miscvalue);
6608 if(m_target->GetMaxPower(power) == 0)
6609 break;
6611 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6612 m_target->SendPeriodicAuraLog(&pInfo);
6614 int32 gain = m_target->ModifyPower(power,pdamage);
6616 if(Unit* pCaster = GetCaster())
6617 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6618 break;
6620 case SPELL_AURA_OBS_MOD_MANA:
6622 // ignore non positive values (can be result apply spellmods to aura damage
6623 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6625 uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount / 100);
6627 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
6628 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6630 if(m_target->GetMaxPower(POWER_MANA) == 0)
6631 break;
6633 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6634 m_target->SendPeriodicAuraLog(&pInfo);
6636 int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
6638 if(Unit* pCaster = GetCaster())
6639 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6640 break;
6642 case SPELL_AURA_POWER_BURN_MANA:
6644 Unit *pCaster = GetCaster();
6645 if(!pCaster)
6646 return;
6648 // Check for immune (not use charges)
6649 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6650 return;
6652 int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6654 Powers powerType = Powers(m_modifier.m_miscvalue);
6656 if(!m_target->isAlive() || m_target->getPowerType() != powerType)
6657 return;
6659 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6660 if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6661 pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
6663 uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
6665 gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
6667 SpellEntry const* spellProto = GetSpellProto();
6668 // maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
6669 SpellNonMeleeDamage damageInfo(pCaster, m_target, spellProto->Id, spellProto->SchoolMask);
6670 pCaster->CalculateSpellDamage(&damageInfo, gain, spellProto);
6672 pCaster->DealDamageMods(damageInfo.target, damageInfo.damage, &damageInfo.absorb);
6674 pCaster->SendSpellNonMeleeDamageLog(&damageInfo);
6676 // Set trigger flag
6677 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6678 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6679 uint32 procEx = createProcExtendMask(&damageInfo, SPELL_MISS_NONE);
6680 if (damageInfo.damage)
6681 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6683 pCaster->ProcDamageAndSpell(damageInfo.target, procAttacker, procVictim, procEx, damageInfo.damage, BASE_ATTACK, spellProto);
6685 pCaster->DealSpellDamage(&damageInfo, true);
6686 break;
6688 case SPELL_AURA_MOD_REGEN:
6690 int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
6691 if (Unit *caster = GetCaster())
6692 m_target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, GetSpellProto());
6693 break;
6695 case SPELL_AURA_MOD_POWER_REGEN:
6697 Powers pt = m_target->getPowerType();
6698 if(int32(pt) != m_modifier.m_miscvalue)
6699 return;
6701 if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
6703 // eating anim
6704 m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
6706 else if( GetId() == 20577 )
6708 // cannibalize anim
6709 m_target->HandleEmoteCommand(EMOTE_STATE_CANNIBALIZE);
6712 // Anger Management
6713 // amount = 1+ 16 = 17 = 3,4*5 = 10,2*5/3
6714 // so 17 is rounded amount for 5 sec tick grow ~ 1 range grow in 3 sec
6715 if(pt == POWER_RAGE)
6716 m_target->ModifyPower(pt, m_modifier.m_amount * 3 / 5);
6717 break;
6719 // Here tick dummy auras
6720 case SPELL_AURA_PERIODIC_DUMMY:
6722 PeriodicDummyTick();
6723 break;
6725 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
6727 TriggerSpell();
6728 break;
6730 case SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE:
6732 TriggerSpellWithValue();
6733 break;
6735 default:
6736 break;
6740 void Aura::PeriodicDummyTick()
6742 Unit *caster = GetCaster();
6743 SpellEntry const* spell = GetSpellProto();
6744 switch (spell->SpellFamilyName)
6746 case SPELLFAMILY_GENERIC:
6747 switch (spell->Id)
6749 // Drink
6750 case 430:
6751 case 431:
6752 case 432:
6753 case 1133:
6754 case 1135:
6755 case 1137:
6756 case 10250:
6757 case 22734:
6758 case 27089:
6759 case 34291:
6760 case 43182:
6761 case 43183:
6762 case 43706:
6763 case 46755:
6764 case 49472: // Drink Coffee
6765 case 57073:
6766 case 61830:
6768 if (m_target->GetTypeId() != TYPEID_PLAYER)
6769 return;
6770 // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6771 Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6772 for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6774 if ((*i)->GetId() == GetId())
6776 (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6777 ((Player*)m_target)->UpdateManaRegen();
6778 // Disable continue
6779 m_isPeriodic = false;
6780 return;
6783 return;
6785 // Forsaken Skills
6786 case 7054:
6788 // Possibly need cast one of them (but
6789 // 7038 Forsaken Skill: Swords
6790 // 7039 Forsaken Skill: Axes
6791 // 7040 Forsaken Skill: Daggers
6792 // 7041 Forsaken Skill: Maces
6793 // 7042 Forsaken Skill: Staves
6794 // 7043 Forsaken Skill: Bows
6795 // 7044 Forsaken Skill: Guns
6796 // 7045 Forsaken Skill: 2H Axes
6797 // 7046 Forsaken Skill: 2H Maces
6798 // 7047 Forsaken Skill: 2H Swords
6799 // 7048 Forsaken Skill: Defense
6800 // 7049 Forsaken Skill: Fire
6801 // 7050 Forsaken Skill: Frost
6802 // 7051 Forsaken Skill: Holy
6803 // 7053 Forsaken Skill: Shadow
6804 return;
6806 // // Panda
6807 // case 19230: break;
6808 // // Gossip NPC Periodic - Talk
6809 // case 33208: break;
6810 // // Gossip NPC Periodic - Despawn
6811 // case 33209: break;
6812 // // Steal Weapon
6813 // case 36207: break;
6814 // // Simon Game START timer, (DND)
6815 // case 39993: break;
6816 // // Knockdown Fel Cannon: break; The Aggro Burst
6817 // case 40119: break;
6818 // // Old Mount Spell
6819 // case 40154: break;
6820 // // Magnetic Pull
6821 // case 40581: break;
6822 // // Ethereal Ring: break; The Bolt Burst
6823 // case 40801: break;
6824 // // Crystal Prison
6825 // case 40846: break;
6826 // // Copy Weapon
6827 // case 41054: break;
6828 // // Dementia
6829 // case 41404: break;
6830 // // Ethereal Ring Visual, Lightning Aura
6831 // case 41477: break;
6832 // // Ethereal Ring Visual, Lightning Aura (Fork)
6833 // case 41525: break;
6834 // // Ethereal Ring Visual, Lightning Jumper Aura
6835 // case 41567: break;
6836 // // No Man's Land
6837 // case 41955: break;
6838 // // Headless Horseman - Fire
6839 // case 42074: break;
6840 // // Headless Horseman - Visual - Large Fire
6841 // case 42075: break;
6842 // // Headless Horseman - Start Fire, Periodic Aura
6843 // case 42140: break;
6844 // // Ram Speed Boost
6845 // case 42152: break;
6846 // // Headless Horseman - Fires Out Victory Aura
6847 // case 42235: break;
6848 // // Pumpkin Life Cycle
6849 // case 42280: break;
6850 // // Brewfest Request Chick Chuck Mug Aura
6851 // case 42537: break;
6852 // // Squashling
6853 // case 42596: break;
6854 // // Headless Horseman Climax, Head: Periodic
6855 // case 42603: break;
6856 // // Fire Bomb
6857 // case 42621: break;
6858 // // Headless Horseman - Conflagrate, Periodic Aura
6859 // case 42637: break;
6860 // // Headless Horseman - Create Pumpkin Treats Aura
6861 // case 42774: break;
6862 // // Headless Horseman Climax - Summoning Rhyme Aura
6863 // case 42879: break;
6864 // // Tricky Treat
6865 // case 42919: break;
6866 // // Giddyup!
6867 // case 42924: break;
6868 // // Ram - Trot
6869 // case 42992: break;
6870 // // Ram - Canter
6871 // case 42993: break;
6872 // // Ram - Gallop
6873 // case 42994: break;
6874 // // Ram Level - Neutral
6875 // case 43310: break;
6876 // // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6877 // case 43884: break;
6878 // // Wretched!
6879 // case 43963: break;
6880 // // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6881 // case 44000: break;
6882 // // Energy Feedback
6883 // case 44328: break;
6884 // // Romantic Picnic
6885 // case 45102: break;
6886 // // Romantic Picnic
6887 // case 45123: break;
6888 // // Looking for Love
6889 // case 45124: break;
6890 // // Kite - Lightning Strike Kite Aura
6891 // case 45197: break;
6892 // // Rocket Chicken
6893 // case 45202: break;
6894 // // Copy Offhand Weapon
6895 // case 45205: break;
6896 // // Upper Deck - Kite - Lightning Periodic Aura
6897 // case 45207: break;
6898 // // Kite -Sky Lightning Strike Kite Aura
6899 // case 45251: break;
6900 // // Ribbon Pole Dancer Check Aura
6901 // case 45390: break;
6902 // // Holiday - Midsummer, Ribbon Pole Periodic Visual
6903 // case 45406: break;
6904 // // Parachute
6905 // case 45472: break;
6906 // // Alliance Flag, Extra Damage Debuff
6907 // case 45898: break;
6908 // // Horde Flag, Extra Damage Debuff
6909 // case 45899: break;
6910 // // Ahune - Summoning Rhyme Aura
6911 // case 45926: break;
6912 // // Ahune - Slippery Floor
6913 // case 45945: break;
6914 // // Ahune's Shield
6915 // case 45954: break;
6916 // // Nether Vapor Lightning
6917 // case 45960: break;
6918 // // Darkness
6919 // case 45996: break;
6920 // // Summon Blood Elves Periodic
6921 // case 46041: break;
6922 // // Transform Visual Missile Periodic
6923 // case 46205: break;
6924 // // Find Opening Beam End
6925 // case 46333: break;
6926 // // Ice Spear Control Aura
6927 // case 46371: break;
6928 // // Hailstone Chill
6929 // case 46458: break;
6930 // // Hailstone Chill, Internal
6931 // case 46465: break;
6932 // // Chill, Internal Shifter
6933 // case 46549: break;
6934 // // Summon Ice Spear Knockback Delayer
6935 // case 46878: break;
6936 // // Burninate Effect
6937 // case 47214: break;
6938 // // Fizzcrank Practice Parachute
6939 // case 47228: break;
6940 // // Send Mug Control Aura
6941 // case 47369: break;
6942 // // Direbrew's Disarm (precast)
6943 // case 47407: break;
6944 // // Mole Machine Port Schedule
6945 // case 47489: break;
6946 // case 47941: break; // Crystal Spike
6947 // case 48200: break; // Healer Aura
6948 // case 48630: break; // Summon Gauntlet Mobs Periodic
6949 // case 49313: break; // Proximity Mine Area Aura
6950 // // Mole Machine Portal Schedule
6951 // case 49466: break;
6952 // case 49555: break; // Corpse Explode
6953 // case 49592: break; // Temporal Rift
6954 // case 49957: break; // Cutting Laser
6955 // case 50085: break; // Slow Fall
6956 // // Listening to Music
6957 // case 50493: break;
6958 // // Love Rocket Barrage
6959 // case 50530: break;
6960 // Exist more after, need add later
6961 default:
6962 break;
6964 break;
6965 case SPELLFAMILY_MAGE:
6967 // Mirror Image
6968 // if (spell->Id == 55342)
6969 // return;
6970 break;
6972 case SPELLFAMILY_DRUID:
6974 switch (spell->Id)
6976 // Frenzied Regeneration
6977 case 22842:
6979 // Converts up to 10 rage per second into health for $d. Each point of rage is converted into ${$m2/10}.1% of max health.
6980 // Should be manauser
6981 if (m_target->getPowerType() != POWER_RAGE)
6982 return;
6983 uint32 rage = m_target->GetPower(POWER_RAGE);
6984 // Nothing todo
6985 if (rage == 0)
6986 return;
6987 int32 mod = (rage < 100) ? rage : 100;
6988 int32 points = m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
6989 int32 regen = m_target->GetMaxHealth() * (mod * points / 10) / 1000;
6990 m_target->CastCustomSpell(m_target, 22845, &regen, NULL, NULL, true, NULL, this);
6991 m_target->SetPower(POWER_RAGE, rage-mod);
6992 return;
6994 // Force of Nature
6995 case 33831:
6996 return;
6997 default:
6998 break;
7000 break;
7002 case SPELLFAMILY_ROGUE:
7004 switch (spell->Id)
7006 case 51690:
7008 std::list<Unit*> targets;
7010 // eff_radius ==0
7011 float radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spell->rangeIndex));
7013 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(),caster->GetPositionY()));
7014 Cell cell(p);
7015 cell.data.Part.reserved = ALL_DISTRICT;
7017 MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck u_check(caster, caster, radius);
7018 MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck> checker(caster,targets, u_check);
7020 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker);
7021 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
7023 CellLock<GridReadGuard> cell_lock(cell, p);
7025 cell_lock->Visit(cell_lock, grid_object_checker, *caster->GetMap());
7026 cell_lock->Visit(cell_lock, world_object_checker, *caster->GetMap());
7029 if(targets.empty())
7030 return;
7032 std::list<Unit*>::const_iterator itr = targets.begin();
7033 std::advance(itr, rand()%targets.size());
7034 Unit* target = *itr;
7036 caster->CastSpell(target, 57840, true);
7037 caster->CastSpell(target, 57841, true);
7038 return;
7040 // Master of Subtlety
7041 // case 31666: break;
7042 // Killing Spree
7043 // case 51690: break;
7044 // Overkill
7045 // case 58428: break;
7046 // default:
7047 // break;
7049 break;
7051 case SPELLFAMILY_HUNTER:
7053 // Explosive Shot
7054 if (spell->SpellFamilyFlags & UI64LIT(0x8000000000000000))
7056 m_target->CastCustomSpell(m_target, 53352, &m_modifier.m_amount, 0, 0, true, 0, this, GetCasterGUID());
7057 return;
7059 switch (spell->Id)
7061 // Harpooner's Mark
7062 // case 40084:
7063 // return;
7064 // Feeding Frenzy Rank 1
7065 case 53511:
7066 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
7067 m_target->CastSpell(m_target, 60096, true, 0, this);
7068 return;
7069 // Feeding Frenzy Rank 2
7070 case 53512:
7071 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
7072 m_target->CastSpell(m_target, 60097, true, 0, this);
7073 return;
7074 default:
7075 break;
7077 break;
7079 case SPELLFAMILY_SHAMAN:
7081 // Astral Shift
7082 if (spell->Id == 52179)
7084 // Periodic need for remove visual on stun/fear/silence lost
7085 if (!(m_target->GetUInt32Value(UNIT_FIELD_FLAGS)&(UNIT_FLAG_STUNNED|UNIT_FLAG_FLEEING|UNIT_FLAG_SILENCED)))
7086 m_target->RemoveAurasDueToSpell(52179);
7087 return;
7089 break;
7091 case SPELLFAMILY_DEATHKNIGHT:
7093 // Death and Decay
7094 if (spell->SpellFamilyFlags & UI64LIT(0x0000000000000020))
7096 if (caster)
7097 caster->CastCustomSpell(m_target, 52212, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
7098 return;
7100 // Raise Dead
7101 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000001000))
7102 // return;
7103 // Chains of Ice
7104 if (spell->SpellFamilyFlags & UI64LIT(0x0000400000000000))
7106 // Get 0 effect aura
7107 Aura *slow = m_target->GetAura(GetId(), 0);
7108 if (slow)
7110 slow->ApplyModifier(false, true);
7111 Modifier *mod = slow->GetModifier();
7112 mod->m_amount+= m_modifier.m_amount;
7113 if (mod->m_amount > 0) mod->m_amount = 0;
7114 slow->ApplyModifier(true, true);
7116 return;
7118 // Summon Gargoyle
7119 // if (spell->SpellFamilyFlags & UI64LIT(0x0000008000000000))
7120 // return;
7121 // Death Rune Mastery
7122 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000004000))
7123 // return;
7124 // Bladed Armor
7125 if (spell->SpellIconID == 2653)
7127 // Increases your attack power by $s1 for every $s2 armor value you have.
7128 // Calculate AP bonus (from 1 efect of this spell)
7129 int32 apBonus = m_modifier.m_amount * m_target->GetArmor() / m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7130 m_target->CastCustomSpell(m_target, 61217, &apBonus, &apBonus, NULL, true, NULL, this);
7131 return;
7133 // Reaping
7134 // if (spell->SpellIconID == 22)
7135 // return;
7136 // Blood of the North
7137 // if (spell->SpellIconID == 30412)
7138 // return;
7139 break;
7141 default:
7142 break;
7146 void Aura::HandlePreventFleeing(bool apply, bool Real)
7148 if(!Real)
7149 return;
7151 Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
7152 if( !fearAuras.empty() )
7154 if (apply)
7155 m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
7156 else
7157 m_target->SetFeared(true);
7161 void Aura::HandleManaShield(bool apply, bool Real)
7163 if(!Real)
7164 return;
7166 // prevent double apply bonuses
7167 if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
7169 if(Unit* caster = GetCaster())
7171 float DoneActualBenefit = 0.0f;
7172 switch(m_spellProto->SpellFamilyName)
7174 case SPELLFAMILY_MAGE:
7175 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x8000))
7177 // Mana Shield
7178 // +50% from +spd bonus
7179 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
7180 break;
7182 break;
7183 default:
7184 break;
7187 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
7189 m_modifier.m_amount += (int32)DoneActualBenefit;
7194 void Aura::HandleArenaPreparation(bool apply, bool Real)
7196 if(!Real)
7197 return;
7199 if(apply)
7200 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7201 else
7202 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7206 * Such auras are applied from a caster(=player) to a vehicle.
7207 * This has been verified using spell #49256
7209 void Aura::HandleAuraControlVehicle(bool apply, bool Real)
7211 if(!Real)
7212 return;
7214 Unit *player = GetCaster();
7215 Vehicle *vehicle = dynamic_cast<Vehicle*>(m_target);
7216 if(!player || player->GetTypeId() != TYPEID_PLAYER || !vehicle)
7217 return;
7219 if (apply)
7221 if(Pet *pet = player->GetPet())
7222 pet->Remove(PET_SAVE_AS_CURRENT);
7223 ((Player*)player)->EnterVehicle(vehicle);
7225 else
7227 SpellEntry const *spell = GetSpellProto();
7229 // some SPELL_AURA_CONTROL_VEHICLE auras have a dummy effect on the player - remove them
7230 player->RemoveAurasDueToSpell(spell->Id);
7232 ((Player*)player)->ExitVehicle(vehicle);
7236 void Aura::HandleAuraConvertRune(bool apply, bool Real)
7238 if(!Real)
7239 return;
7241 if(m_target->GetTypeId() != TYPEID_PLAYER)
7242 return;
7244 Player *plr = (Player*)m_target;
7246 if(plr->getClass() != CLASS_DEATH_KNIGHT)
7247 return;
7249 // how to determine what rune need to be converted?
7250 for(uint32 i = 0; i < MAX_RUNES; ++i)
7252 if(apply)
7254 if(!plr->GetRuneCooldown(i))
7256 plr->ConvertRune(i, GetSpellProto()->EffectMiscValueB[m_effIndex]);
7257 break;
7260 else
7262 if(plr->GetCurrentRune(i) == GetSpellProto()->EffectMiscValueB[m_effIndex])
7264 plr->ConvertRune(i, plr->GetBaseRune(i));
7265 break;
7271 void Aura::HandlePhase(bool apply, bool Real)
7273 if(!Real)
7274 return;
7276 // always non stackable
7277 if(apply)
7279 Unit::AuraList const& phases = m_target->GetAurasByType(SPELL_AURA_PHASE);
7280 if(!phases.empty())
7281 m_target->RemoveAurasDueToSpell(phases.front()->GetId(), this);
7284 // no-phase is also phase state so same code for apply and remove
7286 // phase auras normally not expected at BG but anyway better check
7287 if(m_target->GetTypeId() == TYPEID_PLAYER)
7289 // drop flag at invisible in bg
7290 if(((Player*)m_target)->InBattleGround())
7291 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
7292 bg->EventPlayerDroppedFlag((Player*)m_target);
7294 // GM-mode have mask 0xFFFFFFFF
7295 if(!((Player*)m_target)->isGameMaster())
7296 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7298 ((Player*)m_target)->GetSession()->SendSetPhaseShift(apply ? GetMiscValue() : PHASEMASK_NORMAL);
7300 if(GetEffIndex()==0)
7302 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
7303 if(saBounds.first != saBounds.second)
7305 uint32 zone, area;
7306 m_target->GetZoneAndAreaId(zone, area);
7308 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
7310 // some auras remove at aura remove
7311 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
7312 m_target->RemoveAurasDueToSpell(itr->second->spellId);
7313 // some auras applied at aura apply
7314 else if(itr->second->autocast)
7316 if( !m_target->HasAura(itr->second->spellId, 0) )
7317 m_target->CastSpell(m_target, itr->second->spellId, true);
7323 else
7324 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7326 // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases)
7327 if(m_target->GetVisibility() != VISIBILITY_OFF)
7328 m_target->SetVisibility(m_target->GetVisibility());
7331 void Aura::UnregisterSingleCastAura()
7333 if (IsSingleTarget())
7335 if(Unit* caster = GetCaster())
7337 caster->GetSingleCastAuras().remove(this);
7339 else
7341 sLog.outError("Couldn't find the caster of the single target aura (SpellId %u), may crash later!", GetId());
7342 assert(false);
7344 m_isSingleTargetAura = false;
7348 void Aura::HandleAuraSafeFall( bool Apply, bool Real )
7350 // implemented in WorldSession::HandleMovementOpcodes
7352 // only special case
7353 if(Apply && Real && GetId() == 32474 && m_target->GetTypeId() == TYPEID_PLAYER)
7354 ((Player*)m_target)->ActivateTaxiPathTo(506, GetId());
7357 bool Aura::IsCritFromAbilityAura(Unit* caster, uint32& damage)
7359 Unit::AuraList const& auras = caster->GetAurasByType(SPELL_AURA_ABILITY_PERIODIC_CRIT);
7360 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
7362 if (!(*itr)->isAffectedOnSpell(m_spellProto))
7363 continue;
7364 if (!caster->isSpellCrit(m_target, m_spellProto, GetSpellSchoolMask(m_spellProto)))
7365 break;
7367 damage = caster->SpellCriticalDamageBonus(m_spellProto, damage, m_target);
7368 return true;
7370 return false;
7373 void Aura::HandleModTargetArmorPct(bool apply, bool Real)
7375 if(m_target->GetTypeId() != TYPEID_PLAYER)
7376 return;
7378 ((Player*)m_target)->UpdateArmorPenetration();