root/trunk/src/game/SpellAuras.cpp @ 257

Revision 257, 247.1 kB (checked in by yumileroy, 17 years ago)

*Merge from Mangos. Add MapReference?. Author: hunuza.
*Also re-commit the patches reverted in 255.

Original author: megamage
Date: 2008-11-18 19:40:06-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21#include "Common.h"
22#include "Database/DatabaseEnv.h"
23#include "WorldPacket.h"
24#include "WorldSession.h"
25#include "Opcodes.h"
26#include "Log.h"
27#include "UpdateMask.h"
28#include "World.h"
29#include "ObjectMgr.h"
30#include "SpellMgr.h"
31#include "Player.h"
32#include "Unit.h"
33#include "Spell.h"
34#include "SpellAuras.h"
35#include "DynamicObject.h"
36#include "Group.h"
37#include "UpdateData.h"
38#include "MapManager.h"
39#include "ObjectAccessor.h"
40#include "Policies/SingletonImp.h"
41#include "Totem.h"
42#include "Creature.h"
43#include "Formulas.h"
44#include "BattleGround.h"
45#include "OutdoorPvP.h"
46#include "OutdoorPvPMgr.h"
47#include "CreatureAI.h"
48#include "Util.h"
49#include "GridNotifiers.h"
50#include "GridNotifiersImpl.h"
51#include "CellImpl.h"
52#include "TemporarySummon.h"
53
54#define NULL_AURA_SLOT 0xFF
55
56pAuraHandler AuraHandler[TOTAL_AURAS]=
57{
58    &Aura::HandleNULL,                                      //  0 SPELL_AURA_NONE
59    &Aura::HandleBindSight,                                 //  1 SPELL_AURA_BIND_SIGHT
60    &Aura::HandleModPossess,                                //  2 SPELL_AURA_MOD_POSSESS
61    &Aura::HandlePeriodicDamage,                            //  3 SPELL_AURA_PERIODIC_DAMAGE
62    &Aura::HandleAuraDummy,                                 //  4 SPELL_AURA_DUMMY
63    &Aura::HandleModConfuse,                                //  5 SPELL_AURA_MOD_CONFUSE
64    &Aura::HandleModCharm,                                  //  6 SPELL_AURA_MOD_CHARM
65    &Aura::HandleModFear,                                   //  7 SPELL_AURA_MOD_FEAR
66    &Aura::HandlePeriodicHeal,                              //  8 SPELL_AURA_PERIODIC_HEAL
67    &Aura::HandleModAttackSpeed,                            //  9 SPELL_AURA_MOD_ATTACKSPEED
68    &Aura::HandleModThreat,                                 // 10 SPELL_AURA_MOD_THREAT
69    &Aura::HandleModTaunt,                                  // 11 SPELL_AURA_MOD_TAUNT
70    &Aura::HandleAuraModStun,                               // 12 SPELL_AURA_MOD_STUN
71    &Aura::HandleModDamageDone,                             // 13 SPELL_AURA_MOD_DAMAGE_DONE
72    &Aura::HandleNoImmediateEffect,                         // 14 SPELL_AURA_MOD_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
73    &Aura::HandleNoImmediateEffect,                         // 15 SPELL_AURA_DAMAGE_SHIELD    implemented in Unit::DoAttackDamage
74    &Aura::HandleModStealth,                                // 16 SPELL_AURA_MOD_STEALTH
75    &Aura::HandleNoImmediateEffect,                         // 17 SPELL_AURA_MOD_STEALTH_DETECT
76    &Aura::HandleInvisibility,                              // 18 SPELL_AURA_MOD_INVISIBILITY
77    &Aura::HandleInvisibilityDetect,                        // 19 SPELL_AURA_MOD_INVISIBILITY_DETECTION
78    &Aura::HandleAuraModTotalHealthPercentRegen,            // 20 SPELL_AURA_OBS_MOD_HEALTH
79    &Aura::HandleAuraModTotalManaPercentRegen,              // 21 SPELL_AURA_OBS_MOD_MANA
80    &Aura::HandleAuraModResistance,                         // 22 SPELL_AURA_MOD_RESISTANCE
81    &Aura::HandlePeriodicTriggerSpell,                      // 23 SPELL_AURA_PERIODIC_TRIGGER_SPELL
82    &Aura::HandlePeriodicEnergize,                          // 24 SPELL_AURA_PERIODIC_ENERGIZE
83    &Aura::HandleAuraModPacify,                             // 25 SPELL_AURA_MOD_PACIFY
84    &Aura::HandleAuraModRoot,                               // 26 SPELL_AURA_MOD_ROOT
85    &Aura::HandleAuraModSilence,                            // 27 SPELL_AURA_MOD_SILENCE
86    &Aura::HandleNoImmediateEffect,                         // 28 SPELL_AURA_REFLECT_SPELLS        implement in Unit::SpellHitResult
87    &Aura::HandleAuraModStat,                               // 29 SPELL_AURA_MOD_STAT
88    &Aura::HandleAuraModSkill,                              // 30 SPELL_AURA_MOD_SKILL
89    &Aura::HandleAuraModIncreaseSpeed,                      // 31 SPELL_AURA_MOD_INCREASE_SPEED
90    &Aura::HandleAuraModIncreaseMountedSpeed,               // 32 SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
91    &Aura::HandleAuraModDecreaseSpeed,                      // 33 SPELL_AURA_MOD_DECREASE_SPEED
92    &Aura::HandleAuraModIncreaseHealth,                     // 34 SPELL_AURA_MOD_INCREASE_HEALTH
93    &Aura::HandleAuraModIncreaseEnergy,                     // 35 SPELL_AURA_MOD_INCREASE_ENERGY
94    &Aura::HandleAuraModShapeshift,                         // 36 SPELL_AURA_MOD_SHAPESHIFT
95    &Aura::HandleAuraModEffectImmunity,                     // 37 SPELL_AURA_EFFECT_IMMUNITY
96    &Aura::HandleAuraModStateImmunity,                      // 38 SPELL_AURA_STATE_IMMUNITY
97    &Aura::HandleAuraModSchoolImmunity,                     // 39 SPELL_AURA_SCHOOL_IMMUNITY
98    &Aura::HandleAuraModDmgImmunity,                        // 40 SPELL_AURA_DAMAGE_IMMUNITY
99    &Aura::HandleAuraModDispelImmunity,                     // 41 SPELL_AURA_DISPEL_IMMUNITY
100    &Aura::HandleAuraProcTriggerSpell,                      // 42 SPELL_AURA_PROC_TRIGGER_SPELL  implemented in Unit::ProcDamageAndSpellFor and Unit::HandleProcTriggerSpell
101    &Aura::HandleNoImmediateEffect,                         // 43 SPELL_AURA_PROC_TRIGGER_DAMAGE implemented in Unit::ProcDamageAndSpellFor
102    &Aura::HandleAuraTrackCreatures,                        // 44 SPELL_AURA_TRACK_CREATURES
103    &Aura::HandleAuraTrackResources,                        // 45 SPELL_AURA_TRACK_RESOURCES
104    &Aura::HandleUnused,                                    // 46 SPELL_AURA_MOD_PARRY_SKILL    obsolete?
105    &Aura::HandleAuraModParryPercent,                       // 47 SPELL_AURA_MOD_PARRY_PERCENT
106    &Aura::HandleUnused,                                    // 48 SPELL_AURA_MOD_DODGE_SKILL    obsolete?
107    &Aura::HandleAuraModDodgePercent,                       // 49 SPELL_AURA_MOD_DODGE_PERCENT
108    &Aura::HandleUnused,                                    // 50 SPELL_AURA_MOD_BLOCK_SKILL    obsolete?
109    &Aura::HandleAuraModBlockPercent,                       // 51 SPELL_AURA_MOD_BLOCK_PERCENT
110    &Aura::HandleAuraModCritPercent,                        // 52 SPELL_AURA_MOD_CRIT_PERCENT
111    &Aura::HandlePeriodicLeech,                             // 53 SPELL_AURA_PERIODIC_LEECH
112    &Aura::HandleModHitChance,                              // 54 SPELL_AURA_MOD_HIT_CHANCE
113    &Aura::HandleModSpellHitChance,                         // 55 SPELL_AURA_MOD_SPELL_HIT_CHANCE
114    &Aura::HandleAuraTransform,                             // 56 SPELL_AURA_TRANSFORM
115    &Aura::HandleModSpellCritChance,                        // 57 SPELL_AURA_MOD_SPELL_CRIT_CHANCE
116    &Aura::HandleAuraModIncreaseSwimSpeed,                  // 58 SPELL_AURA_MOD_INCREASE_SWIM_SPEED
117    &Aura::HandleNoImmediateEffect,                         // 59 SPELL_AURA_MOD_DAMAGE_DONE_CREATURE implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
118    &Aura::HandleAuraModPacifyAndSilence,                   // 60 SPELL_AURA_MOD_PACIFY_SILENCE
119    &Aura::HandleAuraModScale,                              // 61 SPELL_AURA_MOD_SCALE
120    &Aura::HandleNULL,                                      // 62 SPELL_AURA_PERIODIC_HEALTH_FUNNEL
121    &Aura::HandleUnused,                                    // 63 SPELL_AURA_PERIODIC_MANA_FUNNEL obsolete?
122    &Aura::HandlePeriodicManaLeech,                         // 64 SPELL_AURA_PERIODIC_MANA_LEECH
123    &Aura::HandleModCastingSpeed,                           // 65 SPELL_AURA_MOD_CASTING_SPEED
124    &Aura::HandleFeignDeath,                                // 66 SPELL_AURA_FEIGN_DEATH
125    &Aura::HandleAuraModDisarm,                             // 67 SPELL_AURA_MOD_DISARM
126    &Aura::HandleAuraModStalked,                            // 68 SPELL_AURA_MOD_STALKED
127    &Aura::HandleSchoolAbsorb,                              // 69 SPELL_AURA_SCHOOL_ABSORB implemented in Unit::CalcAbsorbResist
128    &Aura::HandleUnused,                                    // 70 SPELL_AURA_EXTRA_ATTACKS      Useless, used by only one spell that has only visual effect
129    &Aura::HandleModSpellCritChanceShool,                   // 71 SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
130    &Aura::HandleModPowerCostPCT,                           // 72 SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
131    &Aura::HandleModPowerCost,                              // 73 SPELL_AURA_MOD_POWER_COST_SCHOOL
132    &Aura::HandleNoImmediateEffect,                         // 74 SPELL_AURA_REFLECT_SPELLS_SCHOOL  implemented in Unit::SpellHitResult
133    &Aura::HandleNoImmediateEffect,                         // 75 SPELL_AURA_MOD_LANGUAGE
134    &Aura::HandleFarSight,                                  // 76 SPELL_AURA_FAR_SIGHT
135    &Aura::HandleModMechanicImmunity,                       // 77 SPELL_AURA_MECHANIC_IMMUNITY
136    &Aura::HandleAuraMounted,                               // 78 SPELL_AURA_MOUNTED
137    &Aura::HandleModDamagePercentDone,                      // 79 SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
138    &Aura::HandleModPercentStat,                            // 80 SPELL_AURA_MOD_PERCENT_STAT
139    &Aura::HandleNoImmediateEffect,                         // 81 SPELL_AURA_SPLIT_DAMAGE_PCT
140    &Aura::HandleWaterBreathing,                            // 82 SPELL_AURA_WATER_BREATHING
141    &Aura::HandleModBaseResistance,                         // 83 SPELL_AURA_MOD_BASE_RESISTANCE
142    &Aura::HandleModRegen,                                  // 84 SPELL_AURA_MOD_REGEN
143    &Aura::HandleModPowerRegen,                             // 85 SPELL_AURA_MOD_POWER_REGEN
144    &Aura::HandleChannelDeathItem,                          // 86 SPELL_AURA_CHANNEL_DEATH_ITEM
145    &Aura::HandleNoImmediateEffect,                         // 87 SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
146    &Aura::HandleNoImmediateEffect,                         // 88 SPELL_AURA_MOD_HEALTH_REGEN_PERCENT
147    &Aura::HandlePeriodicDamagePCT,                         // 89 SPELL_AURA_PERIODIC_DAMAGE_PERCENT
148    &Aura::HandleUnused,                                    // 90 SPELL_AURA_MOD_RESIST_CHANCE  Useless
149    &Aura::HandleNoImmediateEffect,                         // 91 SPELL_AURA_MOD_DETECT_RANGE implemented in Creature::GetAttackDistance
150    &Aura::HandlePreventFleeing,                            // 92 SPELL_AURA_PREVENTS_FLEEING
151    &Aura::HandleModUnattackable,                           // 93 SPELL_AURA_MOD_UNATTACKABLE
152    &Aura::HandleNoImmediateEffect,                         // 94 SPELL_AURA_INTERRUPT_REGEN implemented in Player::RegenerateAll
153    &Aura::HandleAuraGhost,                                 // 95 SPELL_AURA_GHOST
154    &Aura::HandleNoImmediateEffect,                         // 96 SPELL_AURA_SPELL_MAGNET implemented in Spell::SelectMagnetTarget
155    &Aura::HandleManaShield,                                // 97 SPELL_AURA_MANA_SHIELD implemented in Unit::CalcAbsorbResist
156    &Aura::HandleAuraModSkill,                              // 98 SPELL_AURA_MOD_SKILL_TALENT
157    &Aura::HandleAuraModAttackPower,                        // 99 SPELL_AURA_MOD_ATTACK_POWER
158    &Aura::HandleUnused,                                    //100 SPELL_AURA_AURAS_VISIBLE obsolete? all player can see all auras now
159    &Aura::HandleModResistancePercent,                      //101 SPELL_AURA_MOD_RESISTANCE_PCT
160    &Aura::HandleNoImmediateEffect,                         //102 SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
161    &Aura::HandleAuraModTotalThreat,                        //103 SPELL_AURA_MOD_TOTAL_THREAT
162    &Aura::HandleAuraWaterWalk,                             //104 SPELL_AURA_WATER_WALK
163    &Aura::HandleAuraFeatherFall,                           //105 SPELL_AURA_FEATHER_FALL
164    &Aura::HandleAuraHover,                                 //106 SPELL_AURA_HOVER
165    &Aura::HandleAddModifier,                               //107 SPELL_AURA_ADD_FLAT_MODIFIER
166    &Aura::HandleAddModifier,                               //108 SPELL_AURA_ADD_PCT_MODIFIER
167    &Aura::HandleNoImmediateEffect,                         //109 SPELL_AURA_ADD_TARGET_TRIGGER
168    &Aura::HandleModPowerRegenPCT,                          //110 SPELL_AURA_MOD_POWER_REGEN_PERCENT
169    &Aura::HandleNULL,                                      //111 SPELL_AURA_ADD_CASTER_HIT_TRIGGER
170    &Aura::HandleNoImmediateEffect,                         //112 SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
171    &Aura::HandleNoImmediateEffect,                         //113 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
172    &Aura::HandleNoImmediateEffect,                         //114 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
173    &Aura::HandleNoImmediateEffect,                         //115 SPELL_AURA_MOD_HEALING                 implemented in Unit::SpellBaseHealingBonusForVictim
174    &Aura::HandleNoImmediateEffect,                         //116 SPELL_AURA_MOD_REGEN_DURING_COMBAT
175    &Aura::HandleNoImmediateEffect,                         //117 SPELL_AURA_MOD_MECHANIC_RESISTANCE     implemented in Unit::MagicSpellHitResult
176    &Aura::HandleNoImmediateEffect,                         //118 SPELL_AURA_MOD_HEALING_PCT             implemented in Unit::SpellHealingBonus
177    &Aura::HandleUnused,                                    //119 SPELL_AURA_SHARE_PET_TRACKING useless
178    &Aura::HandleAuraUntrackable,                           //120 SPELL_AURA_UNTRACKABLE
179    &Aura::HandleAuraEmpathy,                               //121 SPELL_AURA_EMPATHY
180    &Aura::HandleModOffhandDamagePercent,                   //122 SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT
181    &Aura::HandleModTargetResistance,                       //123 SPELL_AURA_MOD_TARGET_RESISTANCE
182    &Aura::HandleAuraModRangedAttackPower,                  //124 SPELL_AURA_MOD_RANGED_ATTACK_POWER
183    &Aura::HandleNoImmediateEffect,                         //125 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
184    &Aura::HandleNoImmediateEffect,                         //126 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
185    &Aura::HandleNoImmediateEffect,                         //127 SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
186    &Aura::HandleModPossessPet,                             //128 SPELL_AURA_MOD_POSSESS_PET
187    &Aura::HandleAuraModIncreaseSpeed,                      //129 SPELL_AURA_MOD_SPEED_ALWAYS
188    &Aura::HandleAuraModIncreaseMountedSpeed,               //130 SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
189    &Aura::HandleNoImmediateEffect,                         //131 SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
190    &Aura::HandleAuraModIncreaseEnergyPercent,              //132 SPELL_AURA_MOD_INCREASE_ENERGY_PERCENT
191    &Aura::HandleAuraModIncreaseHealthPercent,              //133 SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT
192    &Aura::HandleAuraModRegenInterrupt,                     //134 SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
193    &Aura::HandleModHealingDone,                            //135 SPELL_AURA_MOD_HEALING_DONE
194    &Aura::HandleNoImmediateEffect,                         //136 SPELL_AURA_MOD_HEALING_DONE_PERCENT   implemented in Unit::SpellHealingBonus
195    &Aura::HandleModTotalPercentStat,                       //137 SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE
196    &Aura::HandleHaste,                                     //138 SPELL_AURA_MOD_HASTE
197    &Aura::HandleForceReaction,                             //139 SPELL_AURA_FORCE_REACTION
198    &Aura::HandleAuraModRangedHaste,                        //140 SPELL_AURA_MOD_RANGED_HASTE
199    &Aura::HandleRangedAmmoHaste,                           //141 SPELL_AURA_MOD_RANGED_AMMO_HASTE
200    &Aura::HandleAuraModBaseResistancePCT,                  //142 SPELL_AURA_MOD_BASE_RESISTANCE_PCT
201    &Aura::HandleAuraModResistanceExclusive,                //143 SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE
202    &Aura::HandleNoImmediateEffect,                         //144 SPELL_AURA_SAFE_FALL                  implemented in WorldSession::HandleMovementOpcodes
203    &Aura::HandleUnused,                                    //145 SPELL_AURA_CHARISMA obsolete?
204    &Aura::HandleUnused,                                    //146 SPELL_AURA_PERSUADED obsolete?
205    &Aura::HandleNULL,                                      //147 SPELL_AURA_ADD_CREATURE_IMMUNITY
206    &Aura::HandleAuraRetainComboPoints,                     //148 SPELL_AURA_RETAIN_COMBO_POINTS
207    &Aura::HandleNoImmediateEffect,                         //149 SPELL_AURA_RESIST_PUSHBACK
208    &Aura::HandleShieldBlockValue,                          //150 SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT
209    &Aura::HandleAuraTrackStealthed,                        //151 SPELL_AURA_TRACK_STEALTHED
210    &Aura::HandleNoImmediateEffect,                         //152 SPELL_AURA_MOD_DETECTED_RANGE implemented in Creature::GetAttackDistance
211    &Aura::HandleNoImmediateEffect,                         //153 SPELL_AURA_SPLIT_DAMAGE_FLAT
212    &Aura::HandleNoImmediateEffect,                         //154 SPELL_AURA_MOD_STEALTH_LEVEL
213    &Aura::HandleNoImmediateEffect,                         //155 SPELL_AURA_MOD_WATER_BREATHING
214    &Aura::HandleNoImmediateEffect,                         //156 SPELL_AURA_MOD_REPUTATION_GAIN
215    &Aura::HandleNULL,                                      //157 SPELL_AURA_PET_DAMAGE_MULTI
216    &Aura::HandleShieldBlockValue,                          //158 SPELL_AURA_MOD_SHIELD_BLOCKVALUE
217    &Aura::HandleNoImmediateEffect,                         //159 SPELL_AURA_NO_PVP_CREDIT      only for Honorless Target spell
218    &Aura::HandleNoImmediateEffect,                         //160 SPELL_AURA_MOD_AOE_AVOIDANCE                 implemented in Unit::MagicSpellHitResult
219    &Aura::HandleNoImmediateEffect,                         //161 SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
220    &Aura::HandleAuraPowerBurn,                             //162 SPELL_AURA_POWER_BURN_MANA
221    &Aura::HandleNoImmediateEffect,                         //163 SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
222    &Aura::HandleUnused,                                    //164 useless, only one test spell
223    &Aura::HandleNoImmediateEffect,                         //165 SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
224    &Aura::HandleAuraModAttackPowerPercent,                 //166 SPELL_AURA_MOD_ATTACK_POWER_PCT
225    &Aura::HandleAuraModRangedAttackPowerPercent,           //167 SPELL_AURA_MOD_RANGED_ATTACK_POWER_PCT
226    &Aura::HandleNoImmediateEffect,                         //168 SPELL_AURA_MOD_DAMAGE_DONE_VERSUS            implemented in Unit::SpellDamageBonus, Unit::MeleeDamageBonus
227    &Aura::HandleNoImmediateEffect,                         //169 SPELL_AURA_MOD_CRIT_PERCENT_VERSUS           implemented in Unit::DealDamageBySchool, Unit::DoAttackDamage, Unit::SpellCriticalBonus
228    &Aura::HandleNULL,                                      //170 SPELL_AURA_DETECT_AMORE       only for Detect Amore spell
229    &Aura::HandleAuraModIncreaseSpeed,                      //171 SPELL_AURA_MOD_SPEED_NOT_STACK
230    &Aura::HandleAuraModIncreaseMountedSpeed,               //172 SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
231    &Aura::HandleUnused,                                    //173 SPELL_AURA_ALLOW_CHAMPION_SPELLS  only for Proclaim Champion spell
232    &Aura::HandleModSpellDamagePercentFromStat,             //174 SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT  implemented in Unit::SpellBaseDamageBonus (by default intellect, dependent from SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT)
233    &Aura::HandleModSpellHealingPercentFromStat,            //175 SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT implemented in Unit::SpellBaseHealingBonus
234    &Aura::HandleSpiritOfRedemption,                        //176 SPELL_AURA_SPIRIT_OF_REDEMPTION   only for Spirit of Redemption spell, die at aura end
235    &Aura::HandleNULL,                                      //177 SPELL_AURA_AOE_CHARM
236    &Aura::HandleNoImmediateEffect,                         //178 SPELL_AURA_MOD_DEBUFF_RESISTANCE          implemented in Unit::MagicSpellHitResult
237    &Aura::HandleNoImmediateEffect,                         //179 SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE implemented in Unit::SpellCriticalBonus
238    &Aura::HandleNoImmediateEffect,                         //180 SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS   implemented in Unit::SpellDamageBonus
239    &Aura::HandleUnused,                                    //181 SPELL_AURA_MOD_FLAT_SPELL_CRIT_DAMAGE_VERSUS unused
240    &Aura::HandleAuraModResistenceOfStatPercent,            //182 SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT
241    &Aura::HandleNULL,                                      //183 SPELL_AURA_MOD_CRITICAL_THREAT
242    &Aura::HandleNoImmediateEffect,                         //184 SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE  implemented in Unit::RollMeleeOutcomeAgainst
243    &Aura::HandleNoImmediateEffect,                         //185 SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
244    &Aura::HandleNoImmediateEffect,                         //186 SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE  implemented in Unit::MagicSpellHitResult
245    &Aura::HandleNoImmediateEffect,                         //187 SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE  implemented in Unit::GetUnitCriticalChance
246    &Aura::HandleNoImmediateEffect,                         //188 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE implemented in Unit::GetUnitCriticalChance
247    &Aura::HandleModRating,                                 //189 SPELL_AURA_MOD_RATING
248    &Aura::HandleNULL,                                      //190 SPELL_AURA_MOD_FACTION_REPUTATION_GAIN
249    &Aura::HandleAuraModUseNormalSpeed,                     //191 SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
250    &Aura::HandleModMeleeRangedSpeedPct,                    //192 SPELL_AURA_HASTE_MELEE
251    &Aura::HandleModCombatSpeedPct,                         //193 SPELL_AURA_MELEE_SLOW (in fact combat (any type attack) speed pct)
252    &Aura::HandleUnused,                                    //194 SPELL_AURA_MOD_DEPRICATED_1 not used now (old SPELL_AURA_MOD_SPELL_DAMAGE_OF_INTELLECT)
253    &Aura::HandleUnused,                                    //195 SPELL_AURA_MOD_DEPRICATED_2 not used now (old SPELL_AURA_MOD_SPELL_HEALING_OF_INTELLECT)
254    &Aura::HandleNULL,                                      //196 SPELL_AURA_MOD_COOLDOWN
255    &Aura::HandleNoImmediateEffect,                         //197 SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE implemented in Unit::SpellCriticalBonus Unit::GetUnitCriticalChance
256    &Aura::HandleUnused,                                    //198 SPELL_AURA_MOD_ALL_WEAPON_SKILLS
257    &Aura::HandleNoImmediateEffect,                         //199 SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT  implemented in Unit::MagicSpellHitResult
258    &Aura::HandleNoImmediateEffect,                         //200 SPELL_AURA_MOD_XP_PCT implemented in Player::GiveXP
259    &Aura::HandleAuraAllowFlight,                           //201 SPELL_AURA_FLY                             this aura enable flight mode...
260    &Aura::HandleNoImmediateEffect,                         //202 SPELL_AURA_CANNOT_BE_DODGED                implemented in Unit::RollPhysicalOutcomeAgainst
261    &Aura::HandleNoImmediateEffect,                         //203 SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE  implemented in Unit::DoAttackDamage
262    &Aura::HandleNoImmediateEffect,                         //204 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE implemented in Unit::DoAttackDamage
263    &Aura::HandleNULL,                                      //205 vulnerable to school dmg?
264    &Aura::HandleNULL,                                      //206 SPELL_AURA_MOD_SPEED_MOUNTED
265    &Aura::HandleAuraModIncreaseFlightSpeed,                //207 SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
266    &Aura::HandleAuraModIncreaseFlightSpeed,                //208 SPELL_AURA_MOD_SPEED_FLIGHT, used only in spell: Flight Form (Passive)
267    &Aura::HandleAuraModIncreaseFlightSpeed,                //209 SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
268    &Aura::HandleNULL,                                      //210 Commentator's Command
269    &Aura::HandleAuraModIncreaseFlightSpeed,                //211 SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
270    &Aura::HandleAuraModRangedAttackPowerOfStatPercent,     //212 SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT
271    &Aura::HandleNoImmediateEffect,                         //213 SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT implemented in Player::RewardRage
272    &Aura::HandleNULL,                                      //214 Tamed Pet Passive
273    &Aura::HandleArenaPreparation,                          //215 SPELL_AURA_ARENA_PREPARATION
274    &Aura::HandleModCastingSpeed,                           //216 SPELL_AURA_HASTE_SPELLS
275    &Aura::HandleUnused,                                    //217                                   unused
276    &Aura::HandleAuraModRangedHaste,                        //218 SPELL_AURA_HASTE_RANGED
277    &Aura::HandleModManaRegen,                              //219 SPELL_AURA_MOD_MANA_REGEN_FROM_STAT
278    &Aura::HandleNULL,                                      //220 SPELL_AURA_MOD_RATING_FROM_STAT
279    &Aura::HandleNULL,                                      //221 ignored
280    &Aura::HandleUnused,                                    //222 unused
281    &Aura::HandleNULL,                                      //223 Cold Stare
282    &Aura::HandleUnused,                                    //224 unused
283    &Aura::HandleNoImmediateEffect,                         //225 SPELL_AURA_PRAYER_OF_MENDING
284    &Aura::HandleAuraPeriodicDummy,                         //226 SPELL_AURA_PERIODIC_DUMMY
285    &Aura::HandleNULL,                                      //227 periodic trigger spell
286    &Aura::HandleNoImmediateEffect,                         //228 stealth detection
287    &Aura::HandleNULL,                                      //229 SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
288    &Aura::HandleAuraModIncreaseMaxHealth,                  //230 Commanding Shout
289    &Aura::HandleNULL,                                      //231
290    &Aura::HandleNoImmediateEffect,                         //232 SPELL_AURA_MECHANIC_DURATION_MOD           implement in Unit::CalculateSpellDuration
291    &Aura::HandleNULL,                                      //233 set model id to the one of the creature with id m_modifier.m_miscvalue
292    &Aura::HandleNoImmediateEffect,                         //234 SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK implement in Unit::CalculateSpellDuration
293    &Aura::HandleAuraModDispelResist,                       //235 SPELL_AURA_MOD_DISPEL_RESIST               implement in Unit::MagicSpellHitResult
294    &Aura::HandleUnused,                                    //236 unused
295    &Aura::HandleModSpellDamagePercentFromAttackPower,      //237 SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER  implemented in Unit::SpellBaseDamageBonus
296    &Aura::HandleModSpellHealingPercentFromAttackPower,     //238 SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER implemented in Unit::SpellBaseHealingBonus
297    &Aura::HandleAuraModScale,                              //239 SPELL_AURA_MOD_SCALE_2 only in Noggenfogger Elixir (16595) before 2.3.0 aura 61
298    &Aura::HandleAuraModExpertise,                          //240 SPELL_AURA_MOD_EXPERTISE
299    &Aura::HandleForceMoveForward,                          //241 Forces the player to move forward
300    &Aura::HandleUnused,                                    //242 SPELL_AURA_MOD_SPELL_DAMAGE_FROM_HEALING
301    &Aura::HandleUnused,                                    //243 used by two test spells
302    &Aura::HandleComprehendLanguage,                        //244 Comprehend language
303    &Aura::HandleUnused,                                    //245 SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
304    &Aura::HandleUnused,                                    //246 unused
305    &Aura::HandleUnused,                                    //247 unused
306    &Aura::HandleNoImmediateEffect,                         //248 SPELL_AURA_MOD_COMBAT_RESULT_CHANCE         implemented in Unit::RollMeleeOutcomeAgainst
307    &Aura::HandleNULL,                                      //249
308    &Aura::HandleAuraModIncreaseHealth,                     //250 SPELL_AURA_MOD_INCREASE_HEALTH_2
309    &Aura::HandleNULL,                                      //251 SPELL_AURA_MOD_ENEMY_DODGE
310    &Aura::HandleUnused,                                    //252 unused
311    &Aura::HandleUnused,                                    //253 unused
312    &Aura::HandleUnused,                                    //254 unused
313    &Aura::HandleUnused,                                    //255 unused
314    &Aura::HandleUnused,                                    //256 unused
315    &Aura::HandleUnused,                                    //257 unused
316    &Aura::HandleUnused,                                    //258 unused
317    &Aura::HandleUnused,                                    //259 unused
318    &Aura::HandleUnused,                                    //260 unused
319    &Aura::HandleNULL                                       //261 SPELL_AURA_261 some phased state (44856 spell)
320};
321
322Aura::Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem) :
323m_procCharges(0), m_spellmod(NULL), m_effIndex(eff), m_caster_guid(0), m_target(target),
324m_timeCla(1000), m_castItemGuid(castItem?castItem->GetGUID():0), m_auraSlot(MAX_AURAS),
325m_positive(false), m_permanent(false), m_isPeriodic(false), m_isTrigger(false), m_isAreaAura(false),
326m_isPersistent(false), m_updated(false), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_isRemovedOnShapeLost(true), m_in_use(false),
327m_periodicTimer(0), m_PeriodicEventId(0), m_AuraDRGroup(DIMINISHING_NONE)
328{
329    assert(target);
330
331    assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
332
333    m_spellProto = spellproto;
334
335    m_currentBasePoints = currentBasePoints ? *currentBasePoints : m_spellProto->EffectBasePoints[eff];
336
337    m_isPassive = IsPassiveSpell(GetId());
338    m_positive = IsPositiveEffect(GetId(), m_effIndex);
339
340    m_applyTime = time(NULL);
341
342    int32 damage;
343    if(!caster)
344    {
345        m_caster_guid = target->GetGUID();
346        damage = m_currentBasePoints+1;                     // stored value-1
347        m_maxduration = target->CalculateSpellDuration(m_spellProto, m_effIndex, target);
348    }
349    else
350    {
351        m_caster_guid = caster->GetGUID();
352
353        damage        = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target);
354        m_maxduration = caster->CalculateSpellDuration(m_spellProto, m_effIndex, target);
355
356        if (!damage && castItem && castItem->GetItemSuffixFactor())
357        {
358            ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
359            if(item_rand_suffix)
360            {
361                for (int k=0; k<3; k++)
362                {
363                    SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand_suffix->enchant_id[k]);
364                    if(pEnchant)
365                    {
366                        for (int t=0; t<3; t++)
367                            if(pEnchant->spellid[t] == m_spellProto->Id)
368                        {
369                            damage = uint32((item_rand_suffix->prefix[k]*castItem->GetItemSuffixFactor()) / 10000 );
370                            break;
371                        }
372                    }
373
374                    if(damage)
375                        break;
376                }
377            }
378        }
379    }
380
381    if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0)
382        m_permanent = true;
383
384    Player* modOwner = caster ? caster->GetSpellModOwner() : NULL;
385
386    if(!m_permanent && modOwner)
387        modOwner->ApplySpellMod(GetId(), SPELLMOD_DURATION, m_maxduration);
388
389    m_duration = m_maxduration;
390
391    if(modOwner)
392        modOwner->ApplySpellMod(GetId(), SPELLMOD_ACTIVATION_TIME, m_periodicTimer);
393
394    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);
395
396    m_effIndex = eff;
397    SetModifier(AuraType(m_spellProto->EffectApplyAuraName[eff]), damage, m_spellProto->EffectAmplitude[eff], m_spellProto->EffectMiscValue[eff]);
398
399    m_isDeathPersist = IsDeathPersistentSpell(m_spellProto);
400
401    if(m_spellProto->procCharges)
402    {
403        m_procCharges = m_spellProto->procCharges;
404
405        if(modOwner)
406            modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
407    }
408    else
409        m_procCharges = -1;
410
411    m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() && m_spellProto->Stances &&
412                            !(m_spellProto->AttributesEx2 & 0x80000) && !(m_spellProto->Attributes & 0x10000));
413}
414
415Aura::~Aura()
416{
417}
418
419AreaAura::AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
420Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
421{
422    m_isAreaAura = true;
423
424    // caster==NULL in constructor args if target==caster in fact
425    Unit* caster_ptr = caster ? caster : target;
426
427    m_radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
428    if(Player* modOwner = caster_ptr->GetSpellModOwner())
429        modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
430
431    switch(spellproto->Effect[eff])
432    {
433        case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
434            m_areaAuraType = AREA_AURA_PARTY;
435            if(target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
436                m_modifier.m_auraname = SPELL_AURA_NONE;
437            break;
438        case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
439            m_areaAuraType = AREA_AURA_FRIEND;
440            break;
441        case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
442            m_areaAuraType = AREA_AURA_ENEMY;
443            if(target == caster_ptr)
444                m_modifier.m_auraname = SPELL_AURA_NONE;    // Do not do any effect on self
445            break;
446        case SPELL_EFFECT_APPLY_AREA_AURA_PET:
447            m_areaAuraType = AREA_AURA_PET;
448            break;
449        case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
450            m_areaAuraType = AREA_AURA_OWNER;
451            if(target == caster_ptr)
452                m_modifier.m_auraname = SPELL_AURA_NONE;
453            break;
454        default:
455            sLog.outError("Wrong spell effect in AreaAura constructor");
456            ASSERT(false);
457            break;
458    }
459}
460
461AreaAura::~AreaAura()
462{
463}
464
465PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
466Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
467{
468    m_isPersistent = true;
469}
470
471PersistentAreaAura::~PersistentAreaAura()
472{
473}
474
475Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem)
476{
477    if (IsAreaAuraEffect(spellproto->Effect[eff]))
478        return new AreaAura(spellproto, eff, currentBasePoints, target, caster, castItem);
479
480    return new Aura(spellproto, eff, currentBasePoints, target, caster, castItem);
481}
482
483Unit* Aura::GetCaster() const
484{
485    if(m_caster_guid==m_target->GetGUID())
486        return m_target;
487
488    //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
489    //must return caster even if it's in another grid/map
490    Unit *unit = ObjectAccessor::GetObjectInWorld(m_caster_guid, (Unit*)NULL);
491    return unit && unit->IsInWorld() ? unit : NULL;
492}
493
494void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
495{
496    m_modifier.m_auraname = t;
497    m_modifier.m_amount   = a;
498    m_modifier.m_miscvalue = miscValue;
499    m_modifier.periodictime = pt;
500}
501
502void Aura::Update(uint32 diff)
503{
504    if (m_duration > 0)
505    {
506        m_duration -= diff;
507        if (m_duration < 0)
508            m_duration = 0;
509        m_timeCla -= diff;
510
511        // GetEffIndex()==0 prevent double/triple apply manaPerSecond/manaPerSecondPerLevel to same spell with many auras
512        // all spells with manaPerSecond/manaPerSecondPerLevel have aura in effect 0
513        if(GetEffIndex()==0 && m_timeCla <= 0)
514        {
515            if(Unit* caster = GetCaster())
516            {
517                Powers powertype = Powers(m_spellProto->powerType);
518                int32 manaPerSecond = m_spellProto->manaPerSecond + m_spellProto->manaPerSecondPerLevel * caster->getLevel();
519                m_timeCla = 1000;
520                if (manaPerSecond)
521                {
522                    if(powertype==POWER_HEALTH)
523                        caster->ModifyHealth(-manaPerSecond);
524                    else
525                        caster->ModifyPower(powertype,-manaPerSecond);
526                }
527            }
528        }
529    }
530
531    // Channeled aura required check distance from caster except in possessed cases
532    if(IsChanneledSpell(m_spellProto) && m_caster_guid != m_target->GetGUID() && !m_target->isPossessed())
533    {
534        Unit* caster = GetCaster();
535        if(!caster)
536        {
537            m_target->RemoveAura(GetId(),GetEffIndex());
538            return;
539        }
540
541        // Get spell range
542        float radius;
543        SpellModOp mod;
544        if (m_spellProto->EffectRadiusIndex[GetEffIndex()])
545        {
546            radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellProto->EffectRadiusIndex[GetEffIndex()]));
547            mod = SPELLMOD_RADIUS;
548        }
549        else
550        {
551            radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellProto->rangeIndex));
552            mod = SPELLMOD_RANGE;
553        }
554
555        if(Player* modOwner = caster->GetSpellModOwner())
556            modOwner->ApplySpellMod(GetId(), mod, radius,NULL);
557
558        if(!caster->IsWithinDistInMap(m_target,radius))
559        {
560            m_target->RemoveAura(GetId(),GetEffIndex());
561            return;
562        }
563    }
564
565    if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
566    {
567        m_periodicTimer -= diff;
568        if(m_periodicTimer <= 0)                            // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
569        {
570            if( m_modifier.m_auraname == SPELL_AURA_MOD_REGEN ||
571                m_modifier.m_auraname == SPELL_AURA_MOD_POWER_REGEN ||
572                                                            // Cannibalize, eating items and other spells
573                m_modifier.m_auraname == SPELL_AURA_OBS_MOD_HEALTH ||
574                                                            // Eating items and other spells
575                m_modifier.m_auraname == SPELL_AURA_OBS_MOD_MANA )
576            {
577                ApplyModifier(true);
578                return;
579            }
580            // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls)
581            m_periodicTimer += m_modifier.periodictime;
582
583            if(m_isTrigger)
584                TriggerSpell();
585            else
586                PeriodicTick();
587        }
588    }
589}
590
591void AreaAura::Update(uint32 diff)
592{
593    // update for the caster of the aura
594    if(m_caster_guid == m_target->GetGUID())
595    {
596        Unit* caster = m_target;
597
598        if( !caster->hasUnitState(UNIT_STAT_ISOLATED) )
599        {
600            Unit* owner = caster->GetCharmerOrOwner();
601            if (!owner)
602                owner = caster;
603            std::list<Unit *> targets;
604
605            switch(m_areaAuraType)
606            {
607                case AREA_AURA_PARTY:
608                {
609                    Group *pGroup = NULL;
610
611                    if (owner->GetTypeId() == TYPEID_PLAYER)
612                        pGroup = ((Player*)owner)->GetGroup();
613
614                    if( pGroup)
615                    {
616                        uint8 subgroup = ((Player*)owner)->GetSubGroup();
617                        for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
618                        {
619                            Player* Target = itr->getSource();
620                            if(Target && Target->isAlive() && Target->GetSubGroup()==subgroup && caster->IsFriendlyTo(Target))
621                            {
622                                if(caster->IsWithinDistInMap(Target, m_radius))
623                                    targets.push_back(Target);
624                                Pet *pet = Target->GetPet();
625                                if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
626                                    targets.push_back(pet);
627                            }
628                        }
629                    }
630                    else
631                    {
632                        // add owner
633                        if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
634                            targets.push_back(owner);
635                        // add caster's pet
636                        Unit* pet = caster->GetPet();
637                        if( pet && caster->IsWithinDistInMap(pet, m_radius))
638                            targets.push_back(pet);
639                    }
640                    break;
641                }
642                case AREA_AURA_FRIEND:
643                {
644                    CellPair p(Trinity::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
645                    Cell cell(p);
646                    cell.data.Part.reserved = ALL_DISTRICT;
647                    cell.SetNoCreate();
648
649                    Trinity::AnyFriendlyUnitInObjectRangeCheck u_check(caster, owner, m_radius);
650                    Trinity::UnitListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck> searcher(targets, u_check);
651                    TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
652                    TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck>, GridTypeMapContainer >  grid_unit_searcher(searcher);
653                    CellLock<GridReadGuard> cell_lock(cell, p);
654                    cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(caster->GetMapId(), caster));
655                    cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(caster->GetMapId(), caster));
656                    break;
657                }
658                case AREA_AURA_ENEMY:
659                {
660                    CellPair p(Trinity::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
661                    Cell cell(p);
662                    cell.data.Part.reserved = ALL_DISTRICT;
663                    cell.SetNoCreate();
664
665                    Trinity::AnyAoETargetUnitInObjectRangeCheck u_check(caster, owner, m_radius); // No GetCharmer in searcher
666                    Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck> searcher(targets, u_check);
667                    TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
668                    TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer >  grid_unit_searcher(searcher);
669                    CellLock<GridReadGuard> cell_lock(cell, p);
670                    cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(caster->GetMapId(), caster));
671                    cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(caster->GetMapId(), caster));
672                    break;
673                }
674                case AREA_AURA_OWNER:
675                case AREA_AURA_PET:
676                {
677                    if(owner != caster)
678                        targets.push_back(owner);
679                    break;
680                }
681            }
682
683            for(std::list<Unit *>::iterator tIter = targets.begin(); tIter != targets.end(); tIter++)
684            {
685                if((*tIter)->HasAura(GetId(), m_effIndex))
686                    continue;
687
688                if(SpellEntry const *actualSpellInfo = spellmgr.SelectAuraRankForPlayerLevel(GetSpellProto(), (*tIter)->getLevel()))
689                {
690                    int32 actualBasePoints = m_currentBasePoints;
691                    // recalculate basepoints for lower rank (all AreaAura spell not use custom basepoints?)
692                    if(actualSpellInfo != GetSpellProto())
693                        actualBasePoints = actualSpellInfo->EffectBasePoints[m_effIndex];
694                    AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
695                    (*tIter)->AddAura(aur);
696                }
697            }
698        }
699        Aura::Update(diff);
700    }
701    else                                                    // aura at non-caster
702    {
703        Unit * tmp_target = m_target;
704        Unit* caster = GetCaster();
705        uint32 tmp_spellId = GetId(), tmp_effIndex = m_effIndex;
706
707        // WARNING: the aura may get deleted during the update
708        // DO NOT access its members after update!
709        Aura::Update(diff);
710
711        // remove aura if out-of-range from caster (after teleport for example)
712        // or caster is isolated or caster no longer has the aura
713        // or caster is (no longer) friendly
714        bool needFriendly = (m_areaAuraType == AREA_AURA_ENEMY ? false : true);
715        if( !caster || caster->hasUnitState(UNIT_STAT_ISOLATED) ||
716            !caster->IsWithinDistInMap(tmp_target, m_radius)    ||
717            !caster->HasAura(tmp_spellId, tmp_effIndex)         ||
718            caster->IsFriendlyTo(tmp_target) != needFriendly
719           )
720        {
721            tmp_target->RemoveAura(tmp_spellId, tmp_effIndex);
722        }
723        else if( m_areaAuraType == AREA_AURA_PARTY)         // check if in same sub group
724        {
725            // not check group if target == owner or target == pet
726            if (caster->GetCharmerOrOwnerGUID() != tmp_target->GetGUID() && caster->GetGUID() != tmp_target->GetCharmerOrOwnerGUID())
727            {
728                Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
729
730                Group *pGroup = check ? check->GetGroup() : NULL;
731                if( pGroup )
732                {
733                    Player* checkTarget = tmp_target->GetCharmerOrOwnerPlayerOrPlayerItself();
734                    if(!checkTarget || !pGroup->SameSubGroup(check, checkTarget))
735                        tmp_target->RemoveAura(tmp_spellId, tmp_effIndex);
736                }
737                else
738                    tmp_target->RemoveAura(tmp_spellId, tmp_effIndex);
739            }
740        }
741        else if( m_areaAuraType == AREA_AURA_PET || m_areaAuraType == AREA_AURA_OWNER )
742        {
743            if( tmp_target->GetGUID() != caster->GetCharmerOrOwnerGUID() )
744                tmp_target->RemoveAura(tmp_spellId, tmp_effIndex);
745        }
746    }
747}
748
749void PersistentAreaAura::Update(uint32 diff)
750{
751    bool remove = false;
752
753    // remove the aura if its caster or the dynamic object causing it was removed
754    // or if the target moves too far from the dynamic object
755    Unit *caster = GetCaster();
756    if (caster)
757    {
758        DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
759        if (dynObj)
760        {
761            if (!m_target->IsWithinDistInMap(dynObj, dynObj->GetRadius()))
762                remove = true;
763        }
764        else
765            remove = true;
766    }
767    else
768        remove = true;
769
770    Unit *tmp_target = m_target;
771    uint32 tmp_id = GetId(), tmp_index = GetEffIndex();
772
773    // WARNING: the aura may get deleted during the update
774    // DO NOT access its members after update!
775    Aura::Update(diff);
776
777    if(remove)
778        tmp_target->RemoveAura(tmp_id, tmp_index);
779}
780
781void Aura::ApplyModifier(bool apply, bool Real)
782{
783    AuraType aura = m_modifier.m_auraname;
784
785    m_in_use = true;
786    if(aura<TOTAL_AURAS)
787        (*this.*AuraHandler [aura])(apply,Real);
788    m_in_use = false;
789}
790
791void Aura::UpdateAuraDuration()
792{
793    if(m_auraSlot >= MAX_AURAS || m_isPassive)
794        return;
795
796    if( m_target->GetTypeId() == TYPEID_PLAYER)
797    {
798        WorldPacket data(SMSG_UPDATE_AURA_DURATION, 5);
799        data << (uint8)m_auraSlot << (uint32)m_duration;
800        ((Player*)m_target)->SendDirectMessage(&data);
801
802        data.Initialize(SMSG_SET_EXTRA_AURA_INFO, (8+1+4+4+4));
803        data.append(m_target->GetPackGUID());
804        data << uint8(m_auraSlot);
805        data << uint32(GetId());
806        data << uint32(GetAuraMaxDuration());
807        data << uint32(GetAuraDuration());
808        ((Player*)m_target)->SendDirectMessage(&data);
809    }
810
811    // not send in case player loading (will not work anyway until player not added to map), sent in visibility change code
812    if(m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading())
813        return;
814
815    Unit* caster = GetCaster();
816
817    if(caster && caster->GetTypeId() == TYPEID_PLAYER && caster != m_target)
818        SendAuraDurationForCaster((Player*)caster);
819}
820
821void Aura::SendAuraDurationForCaster(Player* caster)
822{
823    WorldPacket data(SMSG_SET_EXTRA_AURA_INFO_NEED_UPDATE, (8+1+4+4+4));
824    data.append(m_target->GetPackGUID());
825    data << uint8(m_auraSlot);
826    data << uint32(GetId());
827    data << uint32(GetAuraMaxDuration());                   // full
828    data << uint32(GetAuraDuration());                      // remain
829    caster->GetSession()->SendPacket(&data);
830}
831
832void Aura::_AddAura()
833{
834    if (!GetId())
835        return;
836    if(!m_target)
837        return;
838
839    // we can found aura in NULL_AURA_SLOT and then need store state instead check slot != NULL_AURA_SLOT
840    bool samespell = false;
841    bool secondaura = false;
842    uint8 slot = NULL_AURA_SLOT;
843
844    for(uint8 i = 0; i < 3; i++)
845    {
846        Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
847        for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
848        {
849            // allow use single slot only by auras from same caster
850            if(itr->second->GetCasterGUID()==GetCasterGUID())
851            {
852                samespell = true;
853                if (m_effIndex > itr->second->GetEffIndex())
854                     secondaura = true;
855                slot = itr->second->GetAuraSlot();
856                break;
857            }
858        }
859
860        if(samespell)
861            break;
862    }
863
864    // not call total regen auras at adding
865    switch (m_modifier.m_auraname)
866    {
867        case SPELL_AURA_OBS_MOD_HEALTH:
868        case SPELL_AURA_OBS_MOD_MANA:
869            m_periodicTimer = m_modifier.periodictime;
870            break;
871        case SPELL_AURA_MOD_REGEN:
872        case SPELL_AURA_MOD_POWER_REGEN:
873        case SPELL_AURA_MOD_MANA_REGEN_FROM_STAT:
874            m_periodicTimer = 5000;
875            break;
876    }
877
878    // register aura
879    if (getDiminishGroup() != DIMINISHING_NONE )
880        m_target->ApplyDiminishingAura(getDiminishGroup(),true);
881
882    Unit* caster = GetCaster();
883
884    // passive auras (except totem auras) do not get placed in the slots
885    // area auras with SPELL_AURA_NONE are not shown on target
886    if((!m_isPassive || (caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem())) &&
887        (m_spellProto->Effect[GetEffIndex()] != SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || m_target != caster))
888    {
889        if(!samespell)                                      // new slot need
890        {
891            if (IsPositive())                               // empty positive slot
892            {
893                for (uint8 i = 0; i < MAX_POSITIVE_AURAS; i++)
894                {
895                    if (m_target->GetUInt32Value((uint16)(UNIT_FIELD_AURA + i)) == 0)
896                    {
897                        slot = i;
898                        break;
899                    }
900                }
901            }
902            else                                            // empty negative slot
903            {
904                for (uint8 i = MAX_POSITIVE_AURAS; i < MAX_AURAS; i++)
905                {
906                    if (m_target->GetUInt32Value((uint16)(UNIT_FIELD_AURA + i)) == 0)
907                    {
908                        slot = i;
909                        break;
910                    }
911                }
912            }
913
914            SetAuraSlot( slot );
915
916            // Not update fields for not first spell's aura, all data already in fields
917            if(!secondaura)
918            {
919                if(slot < MAX_AURAS)                        // slot found
920                {
921                    SetAura(slot, false);
922                    SetAuraFlag(slot, true);
923                    SetAuraLevel(slot,caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
924                    UpdateAuraCharges();
925
926                    // update for out of range group members
927                    m_target->UpdateAuraForGroup(slot);
928                }
929
930                UpdateAuraDuration();
931            }
932        }
933        else                                                // use found slot
934        {
935            SetAuraSlot( slot );
936            // Not recalculate stack count for second aura of the same spell
937            if (!secondaura)
938                UpdateSlotCounterAndDuration(true);
939        }
940
941        // Update Seals information
942        if( IsSealSpell(GetSpellProto()) )
943            m_target->ModifyAuraState(AURA_STATE_JUDGEMENT, true);
944
945        // Conflagrate aura state
946        if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 4))
947            m_target->ModifyAuraState(AURA_STATE_IMMOLATE, true);
948
949        if(GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID
950            && (GetSpellProto()->SpellFamilyFlags == 0x40 || GetSpellProto()->SpellFamilyFlags == 0x10))
951        {
952            m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, true);
953        }
954    }
955}
956
957void Aura::_RemoveAura()
958{
959    // Remove all triggered by aura spells vs unlimited duration
960    // except same aura replace case
961    if(m_removeMode!=AURA_REMOVE_BY_STACK)
962        CleanupTriggeredSpells();
963
964    Unit* caster = GetCaster();
965
966    if(caster && IsPersistent())
967    {
968        DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
969        if (dynObj)
970            dynObj->RemoveAffected(m_target);
971    }
972
973    // unregister aura
974    if (getDiminishGroup() != DIMINISHING_NONE )
975        m_target->ApplyDiminishingAura(getDiminishGroup(),false);
976
977    //passive auras do not get put in slots
978    // Note: but totem can be not accessible for aura target in time remove (to far for find in grid)
979    //if(m_isPassive && !(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()))
980    //    return;
981
982    uint8 slot = GetAuraSlot();
983
984    if(slot >= MAX_AURAS)                                   // slot not set
985        return;
986
987    if(m_target->GetUInt32Value((uint16)(UNIT_FIELD_AURA + slot)) == 0)
988        return;
989
990    bool samespell = false;
991    bool sameaura = false;
992
993    // find other aura in same slot (current already removed from list)
994    for(uint8 i = 0; i < 3; i++)
995    {
996        Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
997        for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
998        {
999            if(itr->second->GetAuraSlot()==slot)
1000            {
1001                samespell = true;
1002
1003                if(GetEffIndex()==i)
1004                    sameaura = true;
1005
1006                break;
1007            }
1008        }
1009        if(samespell)
1010            break;
1011    }
1012
1013    // only remove icon when the last aura of the spell is removed (current aura already removed from list)
1014    if (!samespell)
1015    {
1016        SetAura(slot, true);
1017        SetAuraFlag(slot, false);
1018        SetAuraLevel(slot,caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
1019
1020        SetAuraApplication(slot, 0);
1021        // update for out of range group members
1022        m_target->UpdateAuraForGroup(slot);
1023
1024        if( IsSealSpell(GetSpellProto()) )
1025            m_target->ModifyAuraState(AURA_STATE_JUDGEMENT,false);
1026
1027        // Conflagrate aura state
1028        if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 4))
1029            m_target->ModifyAuraState(AURA_STATE_IMMOLATE, false);
1030
1031        // Swiftmend aura state
1032        if(GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID
1033            && (GetSpellProto()->SpellFamilyFlags == 0x40 || GetSpellProto()->SpellFamilyFlags == 0x10))
1034        {
1035            bool found = false;
1036            Unit::AuraList const& RejorRegr = m_target->GetAurasByType(SPELL_AURA_PERIODIC_HEAL);
1037            for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
1038            {
1039                if((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID
1040                    && ((*i)->GetSpellProto()->SpellFamilyFlags == 0x40 || (*i)->GetSpellProto()->SpellFamilyFlags == 0x10) )
1041                {
1042                    found = true;
1043                    break;
1044                }
1045            }
1046            if(!found)
1047                m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, false);
1048        }
1049
1050        // reset cooldown state for spells
1051        if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1052        {
1053            if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE )
1054                ((Player*)caster)->SendCooldownEvent(GetSpellProto());
1055        }
1056    }
1057    else if(sameaura)                                       // decrease count for spell, only for same aura effect, or this spell auras in remove process.
1058        UpdateSlotCounterAndDuration(false);
1059}
1060
1061void Aura::SetAuraFlag(uint32 slot, bool add)
1062{
1063    uint32 index    = slot / 4;
1064    uint32 byte     = (slot % 4) * 8;
1065    uint32 val      = m_target->GetUInt32Value(UNIT_FIELD_AURAFLAGS + index);
1066    val &= ~((uint32)AFLAG_MASK << byte);
1067    if(add)
1068    {
1069        if (IsPositive())
1070            val |= ((uint32)AFLAG_POSITIVE << byte);
1071        else
1072            val |= ((uint32)AFLAG_NEGATIVE << byte);
1073    }
1074    m_target->SetUInt32Value(UNIT_FIELD_AURAFLAGS + index, val);
1075}
1076
1077void Aura::SetAuraLevel(uint32 slot,uint32 level)
1078{
1079    uint32 index    = slot / 4;
1080    uint32 byte     = (slot % 4) * 8;
1081    uint32 val      = m_target->GetUInt32Value(UNIT_FIELD_AURALEVELS + index);
1082    val &= ~(0xFF << byte);
1083    val |= (level << byte);
1084    m_target->SetUInt32Value(UNIT_FIELD_AURALEVELS + index, val);
1085}
1086
1087void Aura::SetAuraApplication(uint32 slot, int8 count)
1088{
1089    uint32 index    = slot / 4;
1090    uint32 byte     = (slot % 4) * 8;
1091    uint32 val      = m_target->GetUInt32Value(UNIT_FIELD_AURAAPPLICATIONS + index);
1092    val &= ~(0xFF << byte);
1093    val |= ((uint8(count)) << byte);
1094    m_target->SetUInt32Value(UNIT_FIELD_AURAAPPLICATIONS + index, val);
1095}
1096
1097void Aura::UpdateSlotCounterAndDuration(bool add)
1098{
1099    uint8 slot = GetAuraSlot();
1100    if(slot >= MAX_AURAS)
1101        return;
1102
1103    // calculate amount of similar auras by same effect index (similar different spells)
1104    int8 count = 0;
1105
1106    // calculate auras and update durations in case aura adding
1107    Unit::AuraList const& aura_list = m_target->GetAurasByType(GetModifier()->m_auraname);
1108    for(Unit::AuraList::const_iterator i = aura_list.begin();i != aura_list.end(); ++i)
1109    {
1110        if( (*i)->GetId()==GetId() && (*i)->GetEffIndex()==m_effIndex &&
1111            (*i)->GetCasterGUID()==GetCasterGUID() )
1112        {
1113            ++count;
1114
1115            if(add)
1116                (*i)->SetAuraDuration(GetAuraDuration());
1117        }
1118    }
1119
1120    // at aura add aura not added yet, at aura remove aura already removed
1121    // in field stored (count-1)
1122    if(!add)
1123        --count;
1124
1125    SetAuraApplication(slot, count);
1126
1127    UpdateAuraDuration();
1128}
1129
1130/*********************************************************/
1131/***               BASIC AURA FUNCTION                 ***/
1132/*********************************************************/
1133void Aura::HandleAddModifier(bool apply, bool Real)
1134{
1135    if(m_target->GetTypeId() != TYPEID_PLAYER || !Real)
1136        return;
1137
1138    SpellEntry const *spellInfo = GetSpellProto();
1139    if(!spellInfo)
1140        return;
1141
1142    if(m_modifier.m_miscvalue >= MAX_SPELLMOD)
1143        return;
1144
1145    if (apply)
1146    {
1147        // Add custom charges for some mod aura
1148        switch (m_spellProto->Id)
1149        {
1150            case 17941:    // Shadow Trance
1151            case 22008:    // Netherwind Focus
1152            case 34936:    // Backlash
1153                m_procCharges = 1;
1154                break;
1155        }
1156
1157        SpellModifier *mod = new SpellModifier;
1158        mod->op = SpellModOp(m_modifier.m_miscvalue);
1159        mod->value = m_modifier.m_amount;
1160        mod->type = SpellModType(m_modifier.m_auraname);    // SpellModType value == spell aura types
1161        mod->spellId = GetId();
1162        mod->effectId = m_effIndex;
1163        mod->lastAffected = NULL;
1164
1165        uint64 spellAffectMask = spellmgr.GetSpellAffectMask(GetId(), m_effIndex);
1166
1167        if (spellAffectMask)
1168            mod->mask = spellAffectMask;
1169        else
1170            mod->mask = spellInfo->EffectItemType[m_effIndex];
1171
1172        if (m_procCharges > 0)
1173            mod->charges = m_procCharges;
1174        else
1175            mod->charges = 0;
1176
1177        m_spellmod = mod;
1178    }
1179
1180    uint64 spellFamilyMask = m_spellmod->mask;
1181
1182    ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
1183
1184    // reapply some passive spells after add/remove related spellmods
1185    if(spellInfo->SpellFamilyName==SPELLFAMILY_WARRIOR && (spellFamilyMask & 0x0000100000000000LL))
1186    {
1187        m_target->RemoveAurasDueToSpell(45471);
1188
1189        if(apply)
1190            m_target->CastSpell(m_target,45471,true);
1191    }
1192}
1193
1194void Aura::TriggerSpell()
1195{
1196    Unit* caster = GetCaster();
1197    Unit* target = GetTriggerTarget();
1198
1199    if(!caster || !target)
1200        return;
1201
1202    // generic casting code with custom spells and target/caster customs
1203    uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
1204
1205    uint64 originalCasterGUID = GetCasterGUID();
1206
1207    SpellEntry const *triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1208    SpellEntry const *auraSpellInfo = GetSpellProto();
1209    uint32 auraId = auraSpellInfo->Id;
1210
1211    // specific code for cases with no trigger spell provided in field
1212    if (triggeredSpellInfo == NULL)
1213    {
1214        switch(auraSpellInfo->SpellFamilyName)
1215        {
1216            case SPELLFAMILY_GENERIC:
1217            {
1218                switch(auraId)
1219                {
1220                    // Firestone Passive (1-5 ranks)
1221                    case 758:
1222                    case 17945:
1223                    case 17947:
1224                    case 17949:
1225                    case 27252:
1226                    {
1227                        if (caster->GetTypeId()!=TYPEID_PLAYER)
1228                            return;
1229                        Item* item = ((Player*)caster)->GetWeaponForAttack(BASE_ATTACK);
1230                        if (!item)
1231                            return;
1232                        uint32 enchant_id = 0;
1233                        switch (GetId())
1234                        {
1235                             case   758: enchant_id = 1803; break;   // Rank 1
1236                             case 17945: enchant_id = 1823; break;   // Rank 2
1237                             case 17947: enchant_id = 1824; break;   // Rank 3
1238                             case 17949: enchant_id = 1825; break;   // Rank 4
1239                             case 27252: enchant_id = 2645; break;   // Rank 5
1240                             default:
1241                                 return;
1242                        }
1243                        // remove old enchanting before applying new
1244                        ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1245                        item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
1246                        // add new enchanting
1247                        ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
1248                        return;
1249                    }
1250//                    // Periodic Mana Burn
1251//                    case 812: break;
1252//                    // Polymorphic Ray
1253//                    case 6965: break;
1254//                    // Fire Nova (1-7 ranks)
1255//                    case 8350:
1256//                    case 8508:
1257//                    case 8509:
1258//                    case 11312:
1259//                    case 11313:
1260//                    case 25540:
1261//                    case 25544:
1262//                        break;
1263                    // Thaumaturgy Channel
1264                    case 9712: trigger_spell_id = 21029; break;
1265//                    // Egan's Blaster
1266//                    case 17368: break;
1267//                    // Haunted
1268//                    case 18347: break;
1269//                    // Ranshalla Waiting
1270//                    case 18953: break;
1271//                    // Inferno
1272//                    case 19695: break;
1273//                    // Frostwolf Muzzle DND
1274//                    case 21794: break;
1275//                    // Alterac Ram Collar DND
1276//                    case 21866: break;
1277//                    // Celebras Waiting
1278//                    case 21916: break;
1279                    // Brood Affliction: Bronze
1280                    case 23170:
1281                    {
1282                        m_target->CastSpell(m_target, 23171, true, 0, this);
1283                        return;
1284                    }
1285//                    // Mark of Frost
1286//                    case 23184: break;
1287                    // Restoration
1288                    case 23493:
1289                    {
1290                        int32 heal = caster->GetMaxHealth() / 10;
1291                        caster->ModifyHealth( heal );
1292                        caster->SendHealSpellLog(caster, 23493, heal);
1293
1294                        int32 mana = caster->GetMaxPower(POWER_MANA);
1295                        if (mana)
1296                        {
1297                            mana /= 10;
1298                            caster->ModifyPower( POWER_MANA, mana );
1299                            caster->SendEnergizeSpellLog(caster, 23493, mana, POWER_MANA);
1300                        }
1301                        break;
1302                    }
1303//                    // Stoneclaw Totem Passive TEST
1304//                    case 23792: break;
1305//                    // Axe Flurry
1306//                    case 24018: break;
1307//                    // Mark of Arlokk
1308//                    case 24210: break;
1309//                    // Restoration
1310//                    case 24379: break;
1311//                    // Happy Pet
1312//                    case 24716: break;
1313//                    // Dream Fog
1314//                    case 24780: break;
1315//                    // Cannon Prep
1316//                    case 24832: break;
1317//                    // Shadow Bolt Whirl
1318//                    case 24834: break;
1319//                    // Stink Trap
1320//                    case 24918: break;
1321//                    // Mark of Nature
1322//                    case 25041: break;
1323//                    // Agro Drones
1324//                    case 25152: break;
1325//                    // Consume
1326//                    case 25371: break;
1327//                    // Pain Spike
1328//                    case 25572: break;
1329//                    // Rotate 360
1330//                    case 26009: break;
1331//                    // Rotate -360
1332//                    case 26136: break;
1333//                    // Consume
1334//                    case 26196: break;
1335//                    // Berserk
1336//                    case 26615: break;
1337//                    // Defile
1338//                    case 27177: break;
1339//                    // Teleport: IF/UC
1340//                    case 27601: break;
1341//                    // Five Fat Finger Exploding Heart Technique
1342//                    case 27673: break;
1343//                    // Nitrous Boost
1344//                    case 27746: break;
1345//                    // Steam Tank Passive
1346//                    case 27747: break;
1347//                    // Frost Blast
1348//                    case 27808: break;
1349//                    // Detonate Mana
1350//                    case 27819: break;
1351//                    // Controller Timer
1352//                    case 28095: break;
1353//                    // Stalagg Chain
1354//                    case 28096: break;
1355//                    // Stalagg Tesla Passive
1356//                    case 28097: break;
1357//                    // Feugen Tesla Passive
1358//                    case 28109: break;
1359//                    // Feugen Chain
1360//                    case 28111: break;
1361//                    // Mark of Didier
1362//                    case 28114: break;
1363//                    // Communique Timer, camp
1364//                    case 28346: break;
1365//                    // Icebolt
1366//                    case 28522: break;
1367//                    // Silithyst
1368//                    case 29519: break;
1369//                    // Inoculate Nestlewood Owlkin
1370                    case 29528: trigger_spell_id = 28713; break;
1371//                    // Overload
1372//                    case 29768: break;
1373//                    // Return Fire
1374//                    case 29788: break;
1375//                    // Return Fire
1376//                    case 29793: break;
1377//                    // Return Fire
1378//                    case 29794: break;
1379//                    // Guardian of Icecrown Passive
1380//                    case 29897: break;
1381                    // Feed Captured Animal
1382                    case 29917: trigger_spell_id = 29916; break;
1383//                    // Flame Wreath
1384//                    case 29946: break;
1385//                    // Flame Wreath
1386//                    case 29947: break;
1387//                    // Mind Exhaustion Passive
1388//                    case 30025: break;
1389//                    // Nether Beam - Serenity
1390//                    case 30401: break;
1391                    // Extract Gas
1392                    case 30427:
1393                    {
1394                        // move loot to player inventory and despawn target
1395                        if(caster->GetTypeId() ==TYPEID_PLAYER &&
1396                                target->GetTypeId() == TYPEID_UNIT &&
1397                                ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
1398                        {
1399                            Player* player = (Player*)caster;
1400                            Creature* creature = (Creature*)target;
1401                            // missing lootid has been reported on startup - just return
1402                            if (!creature->GetCreatureInfo()->SkinLootId)
1403                            {
1404                                return;
1405                            }
1406                            Loot *loot = &creature->loot;
1407                            loot->clear();
1408                            loot->FillLoot(creature->GetCreatureInfo()->SkinLootId, LootTemplates_Skinning, NULL);
1409                            for(uint8 i=0;i<loot->items.size();i++)
1410                            {
1411                                LootItem *item = loot->LootItemInSlot(i,player);
1412                                ItemPosCountVec dest;
1413                                uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, item->itemid, item->count );
1414                                if ( msg == EQUIP_ERR_OK )
1415                                {
1416                                    Item * newitem = player->StoreNewItem( dest, item->itemid, true, item->randomPropertyId);
1417
1418                                    player->SendNewItem(newitem, uint32(item->count), false, false, true);
1419                                }
1420                                else
1421                                    player->SendEquipError( msg, NULL, NULL );
1422                            }
1423                            creature->setDeathState(JUST_DIED);
1424                            creature->RemoveCorpse();
1425                            creature->SetHealth(0);         // just for nice GM-mode view
1426                        }
1427                        return;
1428                        break;
1429                    }
1430                    // Quake
1431                    case 30576: trigger_spell_id = 30571; break;
1432//                    // Burning Maul
1433//                    case 30598: break;
1434//                    // Regeneration
1435//                    case 30799:
1436//                    case 30800:
1437//                    case 30801:
1438//                        break;
1439//                    // Despawn Self - Smoke cloud
1440//                    case 31269: break;
1441//                    // Time Rift Periodic
1442//                    case 31320: break;
1443//                    // Corrupt Medivh
1444//                    case 31326: break;
1445                    // Doom
1446                    case 31347:
1447                    {
1448                        m_target->CastSpell(m_target,31350,true);
1449                        m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
1450                        return;
1451                    }
1452                    // Spellcloth
1453                    case 31373:
1454                    {
1455                        // Summon Elemental after create item
1456                        caster->SummonCreature(17870, 0, 0, 0, caster->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
1457                        return;
1458                    }
1459//                    // Bloodmyst Tesla
1460//                    case 31611: break;
1461//                    // Doomfire
1462//                    case 31944: break;
1463//                    // Teleport Test
1464//                    case 32236: break;
1465//                    // Earthquake
1466//                    case 32686: break;
1467//                    // Possess
1468//                    case 33401: break;
1469//                    // Draw Shadows
1470//                    case 33563: break;
1471//                    // Murmur's Touch
1472//                    case 33711: break;
1473                    // Flame Quills
1474                    case 34229:
1475                    {
1476                        // cast 24 spells 34269-34289, 34314-34316
1477                        for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
1478                            caster->CastSpell(m_target,spell_id,true);
1479                        for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
1480                            caster->CastSpell(m_target,spell_id,true);
1481                        return;
1482                    }
1483//                    // Gravity Lapse
1484//                    case 34480: break;
1485//                    // Tornado
1486//                    case 34683: break;
1487//                    // Frostbite Rotate
1488//                    case 34748: break;
1489//                    // Arcane Flurry
1490//                    case 34821: break;
1491//                    // Interrupt Shutdown
1492//                    case 35016: break;
1493//                    // Interrupt Shutdown
1494//                    case 35176: break;
1495//                    // Inferno
1496//                    case 35268: break;
1497//                    // Salaadin's Tesla
1498//                    case 35515: break;
1499//                    // Ethereal Channel (Red)
1500//                    case 35518: break;
1501//                    // Nether Vapor
1502//                    case 35879: break;
1503//                    // Dark Portal Storm
1504//                    case 36018: break;
1505//                    // Burning Maul
1506//                    case 36056: break;
1507//                    // Living Grove Defender Lifespan
1508//                    case 36061: break;
1509//                    // Professor Dabiri Talks
1510//                    case 36064: break;
1511//                    // Kael Gaining Power
1512//                    case 36091: break;
1513//                    // They Must Burn Bomb Aura
1514//                    case 36344: break;
1515//                    // They Must Burn Bomb Aura (self)
1516//                    case 36350: break;
1517//                    // Stolen Ravenous Ravager Egg
1518//                    case 36401: break;
1519//                    // Activated Cannon
1520//                    case 36410: break;
1521//                    // Stolen Ravenous Ravager Egg
1522//                    case 36418: break;
1523//                    // Enchanted Weapons
1524//                    case 36510: break;
1525//                    // Cursed Scarab Periodic
1526//                    case 36556: break;
1527//                    // Cursed Scarab Despawn Periodic
1528//                    case 36561: break;
1529//                    // Vision Guide
1530//                    case 36573: break;
1531//                    // Cannon Charging (platform)
1532//                    case 36785: break;
1533//                    // Cannon Charging (self)
1534//                    case 36860: break;
1535                    // Remote Toy
1536                    case 37027: trigger_spell_id = 37029; break;
1537//                    // Mark of Death
1538//                    case 37125: break;
1539//                    // Arcane Flurry
1540//                    case 37268: break;
1541//                    // Spout
1542//                    case 37429: break;
1543//                    // Spout
1544//                    case 37430: break;
1545//                    // Karazhan - Chess NPC AI, Snapshot timer
1546//                    case 37440: break;
1547//                    // Karazhan - Chess NPC AI, action timer
1548//                    case 37504: break;
1549//                    // Karazhan - Chess: Is Square OCCUPIED aura (DND)
1550//                    case 39400: break;
1551//                    // Banish
1552//                    case 37546: break;
1553//                    // Shriveling Gaze
1554//                    case 37589: break;
1555//                    // Fake Aggro Radius (2 yd)
1556//                    case 37815: break;
1557//                    // Corrupt Medivh
1558//                    case 37853: break;
1559                    // Eye of Grillok
1560                    case 38495:
1561                    {
1562                        m_target->CastSpell(m_target, 38530, true);
1563                        return;
1564                    }
1565                    // Absorb Eye of Grillok (Zezzak's Shard)
1566                    case 38554:
1567                    {
1568                        if(m_target->GetTypeId() != TYPEID_UNIT)
1569                            return;
1570
1571                        caster->CastSpell(caster, 38495, true);
1572
1573                        Creature* creatureTarget = (Creature*)m_target;
1574
1575                        creatureTarget->setDeathState(JUST_DIED);
1576                        creatureTarget->RemoveCorpse();
1577                        creatureTarget->SetHealth(0);       // just for nice GM-mode view
1578                        return;
1579                    }
1580//                    // Magic Sucker Device timer
1581//                    case 38672: break;
1582//                    // Tomb Guarding Charging
1583//                    case 38751: break;
1584//                    // Murmur's Touch
1585//                    case 38794: break;
1586//                    // Activate Nether-wraith Beacon (31742 Nether-wraith Beacon item)
1587//                    case 39105: break;
1588//                    // Drain World Tree Visual
1589//                    case 39140: break;
1590//                    // Quest - Dustin's Undead Dragon Visual aura
1591//                    case 39259: break;
1592//                    // Hellfire - The Exorcism, Jules releases darkness, aura
1593//                    case 39306: break;
1594//                    // Inferno
1595//                    case 39346: break;
1596//                    // Enchanted Weapons
1597//                    case 39489: break;
1598//                    // Shadow Bolt Whirl
1599//                    case 39630: break;
1600//                    // Shadow Bolt Whirl
1601//                    case 39634: break;
1602//                    // Shadow Inferno
1603//                    case 39645: break;
1604                    // Tear of Azzinoth Summon Channel - it's not really supposed to do anything,and this only prevents the console spam
1605                    case 39857: trigger_spell_id = 39856; break;
1606//                    // Soulgrinder Ritual Visual (Smashed)
1607//                    case 39974: break;
1608//                    // Simon Game Pre-game timer
1609//                    case 40041: break;
1610//                    // Knockdown Fel Cannon: The Aggro Check Aura
1611//                    case 40113: break;
1612//                    // Spirit Lance
1613//                    case 40157: break;
1614//                    // Demon Transform 2
1615//                    case 40398: break;
1616//                    // Demon Transform 1
1617//                    case 40511: break;
1618//                    // Ancient Flames
1619//                    case 40657: break;
1620//                    // Ethereal Ring Cannon: Cannon Aura
1621//                    case 40734: break;
1622//                    // Cage Trap
1623//                    case 40760: break;
1624//                    // Random Periodic
1625//                    case 40867: break;
1626//                    // Prismatic Shield
1627//                    case 40879: break;
1628                    // Aura of Desire
1629                    case 41350:
1630                    {
1631                        Unit::AuraList const& mMod = m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_ENERGY_PERCENT);
1632                        for(Unit::AuraList::const_iterator i = mMod.begin(); i != mMod.end(); ++i)
1633                        {
1634                            if ((*i)->GetId() == 41350)
1635                            {
1636                                (*i)->ApplyModifier(false);
1637                                (*i)->GetModifier()->m_amount -= 5;
1638                                (*i)->ApplyModifier(true);
1639                                break;
1640                            }
1641                        }                       
1642                    }break;
1643//                    // Dementia
1644//                    case 41404: break;
1645//                    // Chaos Form
1646//                    case 41629: break;
1647//                    // Alert Drums
1648//                    case 42177: break;
1649//                    // Spout
1650//                    case 42581: break;
1651//                    // Spout
1652//                    case 42582: break;
1653//                    // Return to the Spirit Realm
1654//                    case 44035: break;
1655//                    // Curse of Boundless Agony
1656//                    case 45050: break;
1657//                    // Earthquake
1658//                    case 46240: break;
1659                    // Personalized Weather
1660                    case 46736: trigger_spell_id = 46737; break;
1661//                    // Stay Submerged
1662//                    case 46981: break;
1663//                    // Dragonblight Ram
1664//                    case 47015: break;
1665//                    // Party G.R.E.N.A.D.E.
1666//                    case 51510: break;
1667                    default:
1668                        break;
1669                }
1670                break;
1671            }
1672            case SPELLFAMILY_MAGE:
1673            {
1674                switch(auraId)
1675                {
1676                    // Invisibility
1677                    case 66:
1678                    {
1679                        if(!m_duration)
1680                            m_target->CastSpell(m_target, 32612, true, NULL, this);
1681                        return;
1682                    }
1683                    default:
1684                        break;
1685                }
1686                break;
1687            }
1688//            case SPELLFAMILY_WARRIOR:
1689//            {
1690//                switch(auraId)
1691//                {
1692//                    // Wild Magic
1693//                    case 23410: break;
1694//                    // Corrupted Totems
1695//                    case 23425: break;
1696//                    default:
1697//                        break;
1698//                }
1699//                break;
1700//            }
1701//            case SPELLFAMILY_PRIEST:
1702//            {
1703//                switch(auraId)
1704//                {
1705//                    // Blue Beam
1706//                    case 32930: break;
1707//                    // Fury of the Dreghood Elders
1708//                    case 35460: break;
1709//                    default:
1710//                        break;
1711//                }
1712 //               break;
1713 //           }
1714            case SPELLFAMILY_DRUID:
1715            {
1716                switch(auraId)
1717                {
1718                    // Cat Form
1719                    // trigger_spell_id not set and unknown effect triggered in this case, ignoring for while
1720                    case 768:
1721                        return;
1722                    // Frenzied Regeneration
1723                    case 22842:
1724                    case 22895:
1725                    case 22896:
1726                    case 26999:
1727                    {
1728                        int32 LifePerRage = GetModifier()->m_amount;
1729
1730                        int32 lRage = m_target->GetPower(POWER_RAGE);
1731                        if(lRage > 100)                                     // rage stored as rage*10
1732                            lRage = 100;
1733                        m_target->ModifyPower(POWER_RAGE, -lRage);
1734                        int32 FRTriggerBasePoints = int32(lRage*LifePerRage/10);
1735                        m_target->CastCustomSpell(m_target,22845,&FRTriggerBasePoints,NULL,NULL,true,NULL,this);
1736                        return;
1737                    }
1738                    default:
1739                        break;
1740                }
1741                break;
1742            }
1743
1744//            case SPELLFAMILY_HUNTER:
1745//            {
1746//                switch(auraId)
1747//                {
1748//                    //Frost Trap Aura
1749//                    case 13810:
1750//                        return;
1751//                    //Rizzle's Frost Trap
1752//                    case 39900:
1753//                        return;
1754//                    // Tame spells
1755//                    case 19597:         // Tame Ice Claw Bear
1756//                    case 19676:         // Tame Snow Leopard
1757//                    case 19677:         // Tame Large Crag Boar
1758//                    case 19678:         // Tame Adult Plainstrider
1759//                    case 19679:         // Tame Prairie Stalker
1760//                    case 19680:         // Tame Swoop
1761//                    case 19681:         // Tame Dire Mottled Boar
1762//                    case 19682:         // Tame Surf Crawler
1763//                    case 19683:         // Tame Armored Scorpid
1764//                    case 19684:         // Tame Webwood Lurker
1765//                    case 19685:         // Tame Nightsaber Stalker
1766//                    case 19686:         // Tame Strigid Screecher
1767//                    case 30100:         // Tame Crazed Dragonhawk
1768//                    case 30103:         // Tame Elder Springpaw
1769//                    case 30104:         // Tame Mistbat
1770//                    case 30647:         // Tame Barbed Crawler
1771//                    case 30648:         // Tame Greater Timberstrider
1772//                    case 30652:         // Tame Nightstalker
1773//                        return;
1774//                    default:
1775//                        break;
1776//                }
1777//                break;
1778//            }
1779            case SPELLFAMILY_SHAMAN:
1780            {
1781                switch(auraId)
1782                {
1783                    // Lightning Shield (The Earthshatterer set trigger after cast Lighting Shield)
1784                    case 28820:
1785                    {
1786                        // Need remove self if Lightning Shield not active
1787                        Unit::AuraMap const& auras = target->GetAuras();
1788                        for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1789                        {
1790                            SpellEntry const* spell = itr->second->GetSpellProto();
1791                            if( spell->SpellFamilyName == SPELLFAMILY_SHAMAN &&
1792                                spell->SpellFamilyFlags & 0x0000000000000400L)
1793                                return;
1794                        }
1795                        target->RemoveAurasDueToSpell(28820);
1796                        return;
1797                    }
1798                    // Totemic Mastery (Skyshatter Regalia (Shaman Tier 6) - bonus)
1799                    case 38443:
1800                    {
1801                        bool all = true;
1802                        for(int i = 0; i < MAX_TOTEM; ++i)
1803                        {
1804                            if(!caster->m_TotemSlot[i])
1805                            {
1806                                all = false;
1807                                break;
1808                            }
1809                        }
1810
1811                        if(all)
1812                            caster->CastSpell(caster,38437,true);
1813                        else
1814                            caster->RemoveAurasDueToSpell(38437);
1815                        return;
1816                    }
1817                    default:
1818                        break;
1819                }
1820                break;
1821            }
1822            default:
1823                break;
1824        }
1825        // Reget trigger spell proto
1826        triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1827        if(triggeredSpellInfo == NULL)
1828        {
1829            sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
1830            return;
1831        }
1832    }
1833    else
1834    {
1835        // Spell exist but require custom code
1836        switch(auraId)
1837        {
1838            // Curse of Idiocy
1839            case 1010:
1840            {
1841                // TODO: spell casted by result in correct way mostly
1842                // BUT:
1843                // 1) target show casting at each triggered cast: target don't must show casting animation for any triggered spell
1844                //      but must show affect apply like item casting
1845                // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
1846
1847                // prevent cast by triggered auras
1848                if(m_caster_guid == m_target->GetGUID())
1849                    return;
1850
1851                // stop triggering after each affected stats lost > 90
1852                int32 intellectLoss = 0;
1853                int32 spiritLoss = 0;
1854
1855                Unit::AuraList const& mModStat = m_target->GetAurasByType(SPELL_AURA_MOD_STAT);
1856                for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
1857                {
1858                    if ((*i)->GetId() == 1010)
1859                    {
1860                        switch((*i)->GetModifier()->m_miscvalue)
1861                        {
1862                            case STAT_INTELLECT: intellectLoss += (*i)->GetModifier()->m_amount; break;
1863                            case STAT_SPIRIT:    spiritLoss   += (*i)->GetModifier()->m_amount; break;
1864                            default: break;
1865                        }
1866                    }
1867                }
1868
1869                if(intellectLoss <= -90 && spiritLoss <= -90)
1870                    return;
1871
1872                caster = target;
1873                originalCasterGUID = 0;
1874                break;
1875            }
1876            // Mana Tide
1877            case 16191:
1878            {
1879                caster->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this, originalCasterGUID);
1880                return;
1881            }
1882        }
1883    }
1884    m_target->CastSpell(target, triggeredSpellInfo, true, 0, this, originalCasterGUID);
1885}
1886
1887Unit* Aura::GetTriggerTarget() const
1888{
1889    Unit* target = ObjectAccessor::GetUnit(*m_target,
1890        /*m_target->GetTypeId()==TYPEID_PLAYER ?
1891        ((Player*)m_target)->GetSelection() :*/
1892        m_target->GetUInt64Value(UNIT_FIELD_TARGET));
1893    return target ? target : m_target;
1894}
1895
1896/*********************************************************/
1897/***                  AURA EFFECTS                     ***/
1898/*********************************************************/
1899
1900void Aura::HandleAuraDummy(bool apply, bool Real)
1901{
1902    // spells required only Real aura add/remove
1903    if(!Real)
1904        return;
1905
1906    Unit* caster = GetCaster();
1907
1908    // AT APPLY
1909    if(apply)
1910    {
1911        switch(GetId())
1912        {
1913            case 1515:                                      // Tame beast
1914                // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
1915                if( caster && m_target->CanHaveThreatList())
1916                    m_target->AddThreat(caster, 10.0f);
1917                return;
1918            case 13139:                                     // net-o-matic
1919                // root to self part of (root_target->charge->root_self sequence
1920                if(caster)
1921                    caster->CastSpell(caster,13138,true,NULL,this);
1922                return;
1923            case 39850:                                     // Rocket Blast
1924                if(roll_chance_i(20))                       // backfire stun
1925                    m_target->CastSpell(m_target, 51581, true, NULL, this);
1926                return;
1927            case 43873:                                     // Headless Horseman Laugh
1928                if(caster->GetTypeId() == TYPEID_PLAYER)
1929                    ((Player*)caster)->SendPlaySound(11965, false);
1930                return;
1931            case 46354:                                     // Blood Elf Illusion
1932                if(caster)
1933                {
1934                    switch(caster->getGender())
1935                    {
1936                        case GENDER_FEMALE:
1937                            caster->CastSpell(m_target,46356,true,NULL,this);
1938                            break;
1939                        case GENDER_MALE:
1940                            caster->CastSpell(m_target,46355,true,NULL,this);
1941                            break;
1942                        default:
1943                            break;
1944                    }
1945                }
1946                return;
1947            case 46699:                                     // Requires No Ammo
1948                if(m_target->GetTypeId()==TYPEID_PLAYER)
1949                    ((Player*)m_target)->RemoveAmmo();      // not use ammo and not allow use
1950                return;
1951        }
1952
1953        // Earth Shield
1954        if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & 0x40000000000LL))
1955        {
1956            // prevent double apply bonuses
1957            if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
1958                m_modifier.m_amount = caster->SpellHealingBonus(GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE, m_target);
1959            return;
1960        }
1961    }
1962    // AT REMOVE
1963    else
1964    {
1965        if( m_target->GetTypeId() == TYPEID_PLAYER && GetSpellProto()->Effect[0]==72 )
1966        {
1967            // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
1968            ((Player*)m_target)->ClearFarsight();
1969            return;
1970        }
1971
1972        if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
1973        {
1974            uint32 finalSpelId = 0;
1975            switch(GetId())
1976            {
1977                case 19548: finalSpelId = 19597; break;
1978                case 19674: finalSpelId = 19677; break;
1979                case 19687: finalSpelId = 19676; break;
1980                case 19688: finalSpelId = 19678; break;
1981                case 19689: finalSpelId = 19679; break;
1982                case 19692: finalSpelId = 19680; break;
1983                case 19693: finalSpelId = 19684; break;
1984                case 19694: finalSpelId = 19681; break;
1985                case 19696: finalSpelId = 19682; break;
1986                case 19697: finalSpelId = 19683; break;
1987                case 19699: finalSpelId = 19685; break;
1988                case 19700: finalSpelId = 19686; break;
1989                case 30646: finalSpelId = 30647; break;
1990                case 30653: finalSpelId = 30648; break;
1991                case 30654: finalSpelId = 30652; break;
1992                case 30099: finalSpelId = 30100; break;
1993                case 30102: finalSpelId = 30103; break;
1994                case 30105: finalSpelId = 30104; break;
1995            }
1996
1997            if(finalSpelId)
1998                caster->CastSpell(m_target,finalSpelId,true,NULL,this);
1999            return;
2000        }
2001
2002        // Waiting to Resurrect
2003        if(GetId()==2584)
2004        {
2005            // Waiting to resurrect spell cancel, we must remove player from resurrect queue
2006            if(m_target->GetTypeId() == TYPEID_PLAYER)
2007                if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
2008                    bg->RemovePlayerFromResurrectQueue(m_target->GetGUID());
2009            return;
2010        }
2011
2012        // Dark Fiend
2013        if(GetId()==45934)
2014        {
2015            // Kill target if dispelled
2016            if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2017                m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2018            return;
2019        }
2020
2021        // Burning Winds
2022        if(GetId()==46308)                                  // casted only at creatures at spawn
2023        {
2024            m_target->CastSpell(m_target,47287,true,NULL,this);
2025            return;
2026        }
2027
2028        // Eye of Kilrogg, unsummon eye when aura is gone
2029        if(GetId() == 126 && caster->GetTypeId() == TYPEID_PLAYER && caster->GetCharm())
2030        {
2031            ((TemporarySummon*)caster->GetCharm())->UnSummon();
2032            return;
2033        }
2034    }
2035
2036    // AT APPLY & REMOVE
2037
2038    switch(m_spellProto->SpellFamilyName)
2039    {
2040        case SPELLFAMILY_GENERIC:
2041        {
2042            // Unstable Power
2043            if( GetId()==24658 )
2044            {
2045                uint32 spellId = 24659;
2046                if (apply)
2047                {
2048                    const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2049                    if (!spell)
2050                        return;
2051                    for (int i=0; i < spell->StackAmount; ++i)
2052                        caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2053                    return;
2054                }
2055                m_target->RemoveAurasDueToSpell(spellId);
2056                return;
2057            }
2058            // Restless Strength
2059            if( GetId()==24661 )
2060            {
2061                uint32 spellId = 24662;
2062                if (apply)
2063                {
2064                    const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2065                    if (!spell)
2066                        return;
2067                    for (int i=0; i < spell->StackAmount; ++i)
2068                        caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2069                    return;
2070                }
2071                m_target->RemoveAurasDueToSpell(spellId);
2072                return;
2073            }
2074            // Victorious
2075            if(GetId()==32216 && m_target->getClass()==CLASS_WARRIOR)
2076            {
2077                m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, apply);
2078                return;
2079            }
2080            //Summon Fire Elemental
2081            if (GetId() == 40133 && caster)
2082            {
2083                Unit *owner = caster->GetOwner();
2084                if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2085                {
2086                    if(apply)
2087                        owner->CastSpell(owner,8985,true);
2088                    else
2089                        ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2090                }
2091                return;
2092            }
2093
2094            //Summon Earth Elemental
2095            if (GetId() == 40132 && caster)
2096            {
2097                Unit *owner = caster->GetOwner();
2098                if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2099                {
2100                    if(apply)
2101                        owner->CastSpell(owner,19704,true);
2102                    else
2103                        ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2104                }
2105                return;
2106            }
2107            break;
2108        }
2109        case SPELLFAMILY_MAGE:
2110        {
2111            // Hypothermia
2112            if( GetId()==41425 )
2113            {
2114                m_target->ModifyAuraState(AURA_STATE_HYPOTHERMIA,apply);
2115                return;
2116            }
2117            break;
2118        }
2119        case SPELLFAMILY_DRUID:
2120        {
2121            // Lifebloom
2122            if ( GetSpellProto()->SpellFamilyFlags & 0x1000000000LL )
2123            {
2124                if ( apply )
2125                {
2126                    if ( caster )
2127                        // prevent double apply bonuses
2128                        if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2129                            m_modifier.m_amount = caster->SpellHealingBonus(GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE, m_target);
2130                }
2131                else
2132                {
2133                    // Final heal only on dispelled or duration end
2134                    if ( !(GetAuraDuration() <= 0 || m_removeMode==AURA_REMOVE_BY_DISPEL) )
2135                        return;
2136
2137                    // have a look if there is still some other Lifebloom dummy aura
2138                    Unit::AuraList auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2139                    for(Unit::AuraList::iterator itr = auras.begin(); itr!=auras.end(); itr++)
2140                        if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2141                            (*itr)->GetSpellProto()->SpellFamilyFlags & 0x1000000000LL)
2142                            return;
2143
2144                    // final heal
2145                    m_target->CastCustomSpell(m_target,33778,&m_modifier.m_amount,NULL,NULL,true,NULL,this,GetCasterGUID());
2146                }
2147                return;
2148            }
2149
2150            // Predatory Strikes
2151            if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2152            {
2153                ((Player*)m_target)->UpdateAttackPowerAndDamage();
2154                return;
2155            }
2156            // Idol of the Emerald Queen
2157            if ( GetId() == 34246 && m_target->GetTypeId()==TYPEID_PLAYER )
2158            {
2159                if(apply)
2160                {
2161                    SpellModifier *mod = new SpellModifier;
2162                    mod->op = SPELLMOD_DOT;
2163                    mod->value = m_modifier.m_amount/7;
2164                    mod->type = SPELLMOD_FLAT;
2165                    mod->spellId = GetId();
2166                    mod->effectId = m_effIndex;
2167                    mod->lastAffected = NULL;
2168                    mod->mask = 0x001000000000LL;
2169                    mod->charges = 0;
2170
2171                    m_spellmod = mod;
2172                }
2173
2174                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2175                return;
2176            }
2177            break;
2178        }
2179        case SPELLFAMILY_HUNTER:
2180        {
2181            // Improved Aspect of the Viper
2182            if( GetId()==38390 && m_target->GetTypeId()==TYPEID_PLAYER )
2183            {
2184                if(apply)
2185                {
2186                    // + effect value for Aspect of the Viper
2187                    SpellModifier *mod = new SpellModifier;
2188                    mod->op = SPELLMOD_EFFECT1;
2189                    mod->value = m_modifier.m_amount;
2190                    mod->type = SPELLMOD_FLAT;
2191                    mod->spellId = GetId();
2192                    mod->effectId = m_effIndex;
2193                    mod->lastAffected = NULL;
2194                    mod->mask = 0x4000000000000LL;
2195                    mod->charges = 0;
2196
2197                    m_spellmod = mod;
2198                }
2199
2200                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2201                return;
2202            }
2203            break;
2204        }
2205        case SPELLFAMILY_SHAMAN:
2206        {
2207            // Improved Weapon Totems
2208            if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2209            {
2210                if(apply)
2211                {
2212                    SpellModifier *mod = new SpellModifier;
2213                    mod->op = SPELLMOD_EFFECT1;
2214                    mod->value = m_modifier.m_amount;
2215                    mod->type = SPELLMOD_PCT;
2216                    mod->spellId = GetId();
2217                    mod->effectId = m_effIndex;
2218                    mod->lastAffected = NULL;
2219                    switch (m_effIndex)
2220                    {
2221                        case 0:
2222                            mod->mask = 0x00200000000LL;    // Windfury Totem
2223                            break;
2224                        case 1:
2225                            mod->mask = 0x00400000000LL;    // Flametongue Totem
2226                            break;
2227                    }
2228                    mod->charges = 0;
2229
2230                    m_spellmod = mod;
2231                }
2232
2233                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2234                return;
2235            }
2236
2237            // Sentry Totem
2238            if (GetId() == 6495 && caster->GetTypeId() == TYPEID_PLAYER)
2239            {
2240                if (apply)
2241                {
2242                    uint64 guid = caster->m_TotemSlot[3];
2243                    if (guid)
2244                    {
2245                        Creature *totem = ObjectAccessor::GetCreature(*caster, guid);
2246                        if (totem && totem->isTotem())
2247                            totem->AddPlayerToVision((Player*)caster);
2248                    }
2249                } 
2250                else
2251                    ((Player*)caster)->RemoveFarsightTarget();
2252                return;
2253            }
2254            break;
2255        }
2256    }
2257
2258    // pet auras
2259    if(PetAura const* petSpell = spellmgr.GetPetAura(GetId()))
2260    {
2261        if(apply)
2262            m_target->AddPetAura(petSpell);
2263        else
2264            m_target->RemovePetAura(petSpell);
2265        return;
2266    }
2267}
2268
2269void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
2270{
2271    // spells required only Real aura add/remove
2272    if(!Real)
2273        return;
2274
2275    SpellEntry const*spell = GetSpellProto();
2276    switch( spell->SpellFamilyName)
2277    {
2278        case SPELLFAMILY_ROGUE:
2279        {
2280            // Master of Subtlety
2281            if (spell->Id==31666 && !apply && Real)
2282            {
2283                m_target->RemoveAurasDueToSpell(31665);
2284                break;
2285            }
2286            break;
2287        }
2288        case SPELLFAMILY_HUNTER:
2289        {
2290            // Aspect of the Viper
2291            if (spell->SpellFamilyFlags&0x0004000000000000LL)
2292            {
2293                // Update regen on remove
2294                if (!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2295                    ((Player*)m_target)->UpdateManaRegen();
2296                break;
2297            }
2298            break;
2299        }
2300    }
2301
2302    m_isPeriodic = apply;
2303}
2304
2305void Aura::HandleAuraMounted(bool apply, bool Real)
2306{
2307    // only at real add/remove aura
2308    if(!Real)
2309        return;
2310
2311    if(apply)
2312    {
2313        CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2314        if(!ci)
2315        {
2316            sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2317            return;
2318        }
2319
2320        uint32 team = 0;
2321        if (m_target->GetTypeId()==TYPEID_PLAYER)
2322            team = ((Player*)m_target)->GetTeam();
2323
2324        uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2325        CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2326        if (minfo)
2327            display_id = minfo->modelid;
2328
2329        m_target->Mount(display_id);
2330    }
2331    else
2332    {
2333        m_target->Unmount();
2334    }
2335}
2336
2337void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2338{
2339    // only at real add/remove aura
2340    if(!Real)
2341        return;
2342
2343    WorldPacket data;
2344    if(apply)
2345        data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2346    else
2347        data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2348    data.append(m_target->GetPackGUID());
2349    data << uint32(0);
2350    m_target->SendMessageToSet(&data,true);
2351}
2352
2353void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2354{
2355    // only at real add/remove aura
2356    if(!Real)
2357        return;
2358
2359    WorldPacket data;
2360    if(apply)
2361        data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2362    else
2363        data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2364    data.append(m_target->GetPackGUID());
2365    data << (uint32)0;
2366    m_target->SendMessageToSet(&data,true);
2367}
2368
2369void Aura::HandleAuraHover(bool apply, bool Real)
2370{
2371    // only at real add/remove aura
2372    if(!Real)
2373        return;
2374
2375    WorldPacket data;
2376    if(apply)
2377        data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2378    else
2379        data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2380    data.append(m_target->GetPackGUID());
2381    data << uint32(0);
2382    m_target->SendMessageToSet(&data,true);
2383}
2384
2385void Aura::HandleWaterBreathing(bool apply, bool Real)
2386{
2387    if(apply)
2388        m_target->waterbreath = true;
2389    else if(m_target->GetAurasByType(SPELL_AURA_WATER_BREATHING).empty())
2390    {
2391        m_target->waterbreath = false;
2392
2393        // update for enable timer in case not moving target
2394        if(m_target->GetTypeId()==TYPEID_PLAYER && m_target->IsInWorld())
2395        {
2396            ((Player*)m_target)->UpdateUnderwaterState(m_target->GetMap(),m_target->GetPositionX(),m_target->GetPositionY(),m_target->GetPositionZ());
2397            ((Player*)m_target)->HandleDrowning();
2398        }
2399    }
2400}
2401
2402void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2403{
2404    if(!Real)
2405        return;
2406
2407    uint32 modelid = 0;
2408    Powers PowerType = POWER_MANA;
2409    ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2410    switch(form)
2411    {
2412        case FORM_CAT:
2413            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2414                modelid = 892;
2415            else
2416                modelid = 8571;
2417            PowerType = POWER_ENERGY;
2418            break;
2419        case FORM_TRAVEL:
2420            modelid = 632;
2421            break;
2422        case FORM_AQUA:
2423            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2424                modelid = 2428;
2425            else
2426                modelid = 2428;
2427            break;
2428        case FORM_BEAR:
2429            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2430                modelid = 2281;
2431            else
2432                modelid = 2289;
2433            PowerType = POWER_RAGE;
2434            break;
2435        case FORM_GHOUL:
2436            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2437                modelid = 10045;
2438            break;
2439        case FORM_DIREBEAR:
2440            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2441                modelid = 2281;
2442            else
2443                modelid = 2289;
2444            PowerType = POWER_RAGE;
2445            break;
2446        case FORM_CREATUREBEAR:
2447            modelid = 902;
2448            break;
2449        case FORM_GHOSTWOLF:
2450            modelid = 4613;
2451            break;
2452        case FORM_FLIGHT:
2453            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2454                modelid = 20857;
2455            else
2456                modelid = 20872;
2457            break;
2458        case FORM_MOONKIN:
2459            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2460                modelid = 15374;
2461            else
2462                modelid = 15375;
2463            break;
2464        case FORM_FLIGHT_EPIC:
2465            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2466                modelid = 21243;
2467            else
2468                modelid = 21244;
2469            break;
2470        case FORM_AMBIENT:
2471        case FORM_SHADOW:
2472        case FORM_STEALTH:
2473            break;
2474        case FORM_TREE:
2475            modelid = 864;
2476            break;
2477        case FORM_BATTLESTANCE:
2478        case FORM_BERSERKERSTANCE:
2479        case FORM_DEFENSIVESTANCE:
2480            PowerType = POWER_RAGE;
2481            break;
2482        case FORM_SPIRITOFREDEMPTION:
2483            modelid = 16031;
2484            break;
2485        default:
2486            sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2487    }
2488
2489    // remove polymorph before changing display id to keep new display id
2490    switch ( form )
2491    {
2492        case FORM_CAT:
2493        case FORM_TREE:
2494        case FORM_TRAVEL:
2495        case FORM_AQUA:
2496        case FORM_BEAR:
2497        case FORM_DIREBEAR:
2498        case FORM_FLIGHT_EPIC:
2499        case FORM_FLIGHT:
2500        case FORM_MOONKIN:
2501            // remove movement affects
2502            m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2503            m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2504
2505            // and polymorphic affects
2506            if(m_target->IsPolymorphed())
2507                m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2508            break;
2509        default:
2510           break;
2511    }
2512
2513    if(apply)
2514    {
2515        // remove other shapeshift before applying a new one
2516        if(m_target->m_ShapeShiftFormSpellId)
2517            m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId,this);
2518
2519        m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2520
2521        if(modelid > 0)
2522            m_target->SetDisplayId(modelid);
2523
2524        if(PowerType != POWER_MANA)
2525        {
2526            // reset power to default values only at power change
2527            if(m_target->getPowerType()!=PowerType)
2528                m_target->setPowerType(PowerType);
2529
2530            switch(form)
2531            {
2532                case FORM_CAT:
2533                case FORM_BEAR:
2534                case FORM_DIREBEAR:
2535                {
2536                    // get furor proc chance
2537                    uint32 FurorChance = 0;
2538                    Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2539                    for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2540                    {
2541                        if ((*i)->GetSpellProto()->SpellIconID == 238)
2542                        {
2543                            FurorChance = (*i)->GetModifier()->m_amount;
2544                            break;
2545                        }
2546                    }
2547
2548                    if (m_modifier.m_miscvalue == FORM_CAT)
2549                    {
2550                        m_target->SetPower(POWER_ENERGY,0);
2551                        if(urand(1,100) <= FurorChance)
2552                            m_target->CastSpell(m_target,17099,true,NULL,this);
2553                    }
2554                    else
2555                    {
2556                        m_target->SetPower(POWER_RAGE,0);
2557                        if(urand(1,100) <= FurorChance)
2558                            m_target->CastSpell(m_target,17057,true,NULL,this);
2559                    }
2560                    break;
2561                }
2562                case FORM_BATTLESTANCE:
2563                case FORM_DEFENSIVESTANCE:
2564                case FORM_BERSERKERSTANCE:
2565                {
2566                    uint32 Rage_val = 0;
2567                    // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2568                    if(m_target->GetTypeId() == TYPEID_PLAYER)
2569                    {
2570                        PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2571                        for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2572                        {
2573                            if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2574                            SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2575                            if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2576                                Rage_val += m_target->CalculateSpellDamage(spellInfo,0,spellInfo->EffectBasePoints[0],m_target) * 10;
2577                        }
2578                    }
2579
2580                    if (m_target->GetPower(POWER_RAGE) > Rage_val)
2581                        m_target->SetPower(POWER_RAGE,Rage_val);
2582                    break;
2583                }
2584                default:
2585                    break;
2586            }
2587        }
2588
2589        m_target->m_ShapeShiftFormSpellId = GetId();
2590        m_target->m_form = form;
2591    }
2592    else
2593    {
2594        if(modelid > 0)
2595            m_target->SetDisplayId(m_target->GetNativeDisplayId());
2596        m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2597        if(m_target->getClass() == CLASS_DRUID)
2598            m_target->setPowerType(POWER_MANA);
2599        m_target->m_ShapeShiftFormSpellId = 0;
2600        m_target->m_form = FORM_NONE;
2601
2602        switch(form)
2603        {
2604            // Nordrassil Harness - bonus
2605            case FORM_BEAR:
2606            case FORM_DIREBEAR:
2607            case FORM_CAT:
2608            {
2609                if(Aura* dummy = m_target->GetDummyAura(37315) )
2610                    m_target->CastSpell(m_target,37316,true,NULL,dummy);
2611                break;
2612            }
2613            // Nordrassil Regalia - bonus
2614            case FORM_MOONKIN:
2615            {
2616                if(Aura* dummy = m_target->GetDummyAura(37324) )
2617                    m_target->CastSpell(m_target,37325,true,NULL,dummy);
2618                break;
2619            }
2620        }
2621    }
2622
2623    // adding/removing linked auras
2624    // add/remove the shapeshift aura's boosts
2625    HandleShapeshiftBoosts(apply);
2626
2627    if(m_target->GetTypeId()==TYPEID_PLAYER)
2628        ((Player*)m_target)->InitDataForForm();
2629}
2630
2631void Aura::HandleAuraTransform(bool apply, bool Real)
2632{
2633    if (apply)
2634    {
2635        // special case (spell specific functionality)
2636        if(m_modifier.m_miscvalue==0)
2637        {
2638            // player applied only
2639            if(m_target->GetTypeId()!=TYPEID_PLAYER)
2640                return;
2641
2642            switch(GetId())
2643            {
2644                // Orb of Deception
2645                case 16739:
2646                {
2647                    uint32 orb_model = m_target->GetNativeDisplayId();
2648                    switch(orb_model)
2649                    {
2650                        // Troll Female
2651                        case 1479: m_target->SetDisplayId(10134); break;
2652                        // Troll Male
2653                        case 1478: m_target->SetDisplayId(10135); break;
2654                        // Tauren Male
2655                        case 59:   m_target->SetDisplayId(10136); break;
2656                        // Human Male
2657                        case 49:   m_target->SetDisplayId(10137); break;
2658                        // Human Female
2659                        case 50:   m_target->SetDisplayId(10138); break;
2660                        // Orc Male
2661                        case 51:   m_target->SetDisplayId(10139); break;
2662                        // Orc Female
2663                        case 52:   m_target->SetDisplayId(10140); break;
2664                        // Dwarf Male
2665                        case 53:   m_target->SetDisplayId(10141); break;
2666                        // Dwarf Female
2667                        case 54:   m_target->SetDisplayId(10142); break;
2668                        // NightElf Male
2669                        case 55:   m_target->SetDisplayId(10143); break;
2670                        // NightElf Female
2671                        case 56:   m_target->SetDisplayId(10144); break;
2672                        // Undead Female
2673                        case 58:   m_target->SetDisplayId(10145); break;
2674                        // Undead Male
2675                        case 57:   m_target->SetDisplayId(10146); break;
2676                        // Tauren Female
2677                        case 60:   m_target->SetDisplayId(10147); break;
2678                        // Gnome Male
2679                        case 1563: m_target->SetDisplayId(10148); break;
2680                        // Gnome Female
2681                        case 1564: m_target->SetDisplayId(10149); break;
2682                        // BloodElf Female
2683                        case 15475: m_target->SetDisplayId(17830); break;
2684                        // BloodElf Male
2685                        case 15476: m_target->SetDisplayId(17829); break;
2686                        // Dranei Female
2687                        case 16126: m_target->SetDisplayId(17828); break;
2688                        // Dranei Male
2689                        case 16125: m_target->SetDisplayId(17827); break;
2690                        default: break;
2691                    }
2692                    break;
2693                }
2694                // Murloc costume
2695                case 42365: m_target->SetDisplayId(21723); break;
2696                default: break;
2697            }
2698        }
2699        else
2700        {
2701            CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2702            if(!ci)
2703            {
2704                                                            //pig pink ^_^
2705                m_target->SetDisplayId(16358);
2706                sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
2707            }
2708            else
2709            {
2710                                                            // Will use the default model here
2711                if (uint32 modelid = ci->GetRandomValidModelId())
2712                    m_target->SetDisplayId(modelid);
2713
2714                // Dragonmaw Illusion (set mount model also)
2715                if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
2716                    m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
2717            }
2718            m_target->setTransForm(GetId());
2719        }
2720
2721        // polymorph case
2722        if( Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
2723        {
2724            // for players, start regeneration after 1s (in polymorph fast regeneration case)
2725            // only if caster is Player (after patch 2.4.2)
2726            if(IS_PLAYER_GUID(GetCasterGUID()) )
2727                ((Player*)m_target)->setRegenTimer(1000);
2728
2729            //dismount polymorphed target (after patch 2.4.2)
2730            if (m_target->IsMounted())
2731                m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
2732        }
2733    }
2734    else
2735    {
2736        Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
2737        if(otherTransforms.empty())
2738        {
2739            m_target->SetDisplayId(m_target->GetNativeDisplayId());
2740            m_target->setTransForm(0);
2741        }
2742        else
2743        {
2744            // look for other transform auras
2745            Aura* handledAura = *otherTransforms.begin();
2746            for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
2747            {
2748                // negative auras are preferred
2749                if(!IsPositiveSpell((*i)->GetSpellProto()->Id))
2750                {
2751                    handledAura = *i;
2752                    break;
2753                }
2754            }
2755            handledAura->ApplyModifier(true);
2756        }
2757
2758        // Dragonmaw Illusion (restore mount model)
2759        if(GetId()==42016 && m_target->GetMountID()==16314)
2760        {
2761            if(!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
2762            {
2763                uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
2764                if(CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
2765                {
2766                    uint32 team = 0;
2767                    if (m_target->GetTypeId()==TYPEID_PLAYER)
2768                        team = ((Player*)m_target)->GetTeam();
2769
2770                    uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2771                    CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2772                    if (minfo)
2773                        display_id = minfo->modelid;
2774
2775                    m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,display_id);
2776                }
2777            }
2778        }
2779    }
2780}
2781
2782void Aura::HandleForceReaction(bool apply, bool Real)
2783{
2784    if(m_target->GetTypeId() != TYPEID_PLAYER)
2785        return;
2786
2787    if(!Real)
2788        return;
2789
2790    Player* player = (Player*)m_target;
2791
2792    uint32 faction_id = m_modifier.m_miscvalue;
2793    uint32 faction_rank = m_modifier.m_amount;
2794
2795    if(apply)
2796        player->m_forcedReactions[faction_id] = ReputationRank(faction_rank);
2797    else
2798        player->m_forcedReactions.erase(faction_id);
2799
2800    WorldPacket data;
2801    data.Initialize(SMSG_SET_FORCED_REACTIONS, 4+player->m_forcedReactions.size()*(4+4));
2802    data << uint32(player->m_forcedReactions.size());
2803    for(ForcedReactions::const_iterator itr = player->m_forcedReactions.begin(); itr != player->m_forcedReactions.end(); ++itr)
2804    {
2805        data << uint32(itr->first);                         // faction_id (Faction.dbc)
2806        data << uint32(itr->second);                        // reputation rank
2807    }
2808    player->SendDirectMessage(&data);
2809}
2810
2811void Aura::HandleAuraModSkill(bool apply, bool Real)
2812{
2813    if(m_target->GetTypeId() != TYPEID_PLAYER)
2814        return;
2815
2816    uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
2817    int32 points = GetModifier()->m_amount;
2818
2819    ((Player*)m_target)->ModifySkillBonus(prot,(apply ? points: -points),m_modifier.m_auraname==SPELL_AURA_MOD_SKILL_TALENT);
2820    if(prot == SKILL_DEFENSE)
2821        ((Player*)m_target)->UpdateDefenseBonusesMod();
2822}
2823
2824void Aura::HandleChannelDeathItem(bool apply, bool Real)
2825{
2826    if(Real && !apply)
2827    {
2828        Unit* caster = GetCaster();
2829        Unit* victim = GetTarget();
2830        if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode!=AURA_REMOVE_BY_DEATH)
2831            return;
2832
2833        SpellEntry const *spellInfo = GetSpellProto();
2834        if(spellInfo->EffectItemType[m_effIndex] == 0)
2835            return;
2836
2837        // Soul Shard only from non-grey units
2838        if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
2839            (victim->getLevel() <= Trinity::XP::GetGrayLevel(caster->getLevel()) ||
2840             victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
2841            return;
2842        ItemPosCountVec dest;
2843        uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], 1 );
2844        if( msg != EQUIP_ERR_OK )
2845        {
2846            ((Player*)caster)->SendEquipError( msg, NULL, NULL );
2847            return;
2848        }
2849
2850        Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
2851        ((Player*)caster)->SendNewItem(newitem, 1, true, false);
2852    }
2853}
2854
2855void Aura::HandleBindSight(bool apply, bool Real)
2856{
2857    Unit* caster = GetCaster();
2858    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2859        return;
2860
2861    if (apply)
2862        m_target->AddPlayerToVision((Player*)caster);
2863    else
2864        m_target->RemovePlayerFromVision((Player*)caster);
2865}
2866
2867void Aura::HandleFarSight(bool apply, bool Real)
2868{
2869    Unit* caster = GetCaster();
2870    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2871        return;
2872
2873    caster->SetUInt64Value(PLAYER_FARSIGHT,apply ? m_modifier.m_miscvalue : 0);
2874}
2875
2876void Aura::HandleAuraTrackCreatures(bool apply, bool Real)
2877{
2878    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2879        return;
2880
2881    if(apply)
2882        m_target->RemoveNoStackAurasDueToAura(this);
2883    m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
2884}
2885
2886void Aura::HandleAuraTrackResources(bool apply, bool Real)
2887{
2888    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2889        return;
2890
2891    if(apply)
2892        m_target->RemoveNoStackAurasDueToAura(this);
2893    m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
2894}
2895
2896void Aura::HandleAuraTrackStealthed(bool apply, bool Real)
2897{
2898    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2899        return;
2900
2901    if(apply)
2902        m_target->RemoveNoStackAurasDueToAura(this);
2903
2904    m_target->ApplyModFlag(PLAYER_FIELD_BYTES,PLAYER_FIELD_BYTE_TRACK_STEALTHED,apply);
2905}
2906
2907void Aura::HandleAuraModScale(bool apply, bool Real)
2908{
2909    m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X,m_modifier.m_amount,apply);
2910}
2911
2912void Aura::HandleModPossess(bool apply, bool Real)
2913{
2914    if(!Real)
2915        return;
2916
2917    if(m_target->getLevel() > m_modifier.m_amount)
2918        return;
2919
2920    // not possess yourself
2921    if(GetCasterGUID() == m_target->GetGUID())
2922        return;
2923
2924    Unit* caster = GetCaster();
2925    if(!caster)
2926        return;
2927
2928    if( apply )
2929    {
2930        if (caster->GetTypeId() == TYPEID_PLAYER)
2931            ((Player*)caster)->Possess(m_target);
2932    }
2933    else
2934        m_target->UnpossessSelf(true);
2935}
2936
2937void Aura::HandleModPossessPet(bool apply, bool Real)
2938{
2939    if(!Real)
2940        return;
2941
2942    Unit* caster = GetCaster();
2943    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2944        return;
2945    if(caster->GetPet() != m_target)
2946        return;
2947
2948    if(apply)
2949    {
2950        ((Player*)caster)->Possess(m_target);
2951    }
2952    else
2953    {
2954        ((Player*)caster)->RemovePossess(false);
2955    }
2956}
2957
2958void Aura::HandleModCharm(bool apply, bool Real)
2959{
2960    if(!Real)
2961        return;
2962
2963    // not charm yourself
2964    if(GetCasterGUID() == m_target->GetGUID())
2965        return;
2966
2967    Unit* caster = GetCaster();
2968    if(!caster)
2969        return;
2970
2971    if(int32(m_target->getLevel()) <= m_modifier.m_amount)
2972    {
2973        if( apply )
2974        {
2975            m_target->SetCharmerGUID(GetCasterGUID());
2976            m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,caster->getFaction());
2977            m_target->CastStop(m_target==caster ? GetId() : 0);
2978            caster->SetCharm(m_target);
2979
2980            m_target->CombatStop();
2981            m_target->DeleteThreatList();
2982
2983            if(m_target->GetTypeId() == TYPEID_UNIT)
2984            {
2985                ((Creature*)m_target)->AIM_Initialize();
2986                CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target);
2987                charmInfo->InitCharmCreateSpells();
2988                charmInfo->SetReactState( REACT_DEFENSIVE );
2989
2990                if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
2991                {
2992                    CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
2993                    if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
2994                    {
2995                        //to prevent client crash
2996                        m_target->SetFlag(UNIT_FIELD_BYTES_0, 2048);
2997                        //just to enable stat window
2998                        charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
2999                        //if charmed two demons the same session, the 2nd gets the 1st one's name
3000                        m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
3001                    }
3002                }
3003            }
3004
3005            if(caster->GetTypeId() == TYPEID_PLAYER)
3006            {
3007                ((Player*)caster)->CharmSpellInitialize();
3008            }
3009        }
3010        else
3011        {
3012            m_target->SetCharmerGUID(0);
3013
3014            if(m_target->GetTypeId() == TYPEID_PLAYER)
3015                ((Player*)m_target)->setFactionForRace(m_target->getRace());
3016            else
3017            {
3018                CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3019
3020                // restore faction
3021                if(((Creature*)m_target)->isPet())
3022                {
3023                    if(Unit* owner = m_target->GetOwner())
3024                        m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction());
3025                    else if(cinfo)
3026                        m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
3027                }
3028                else if(cinfo)                              // normal creature
3029                    m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
3030
3031                // restore UNIT_FIELD_BYTES_0
3032                if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3033                {
3034                    CreatureDataAddon const *cainfo = ((Creature*)m_target)->GetCreatureAddon();
3035                    if(cainfo && cainfo->bytes0 != 0)
3036                        m_target->SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0);
3037                    else
3038                        m_target->RemoveFlag(UNIT_FIELD_BYTES_0, 2048);
3039
3040                    if(m_target->GetCharmInfo())
3041                        m_target->GetCharmInfo()->SetPetNumber(0, true);
3042                    else
3043                        sLog.outError("Aura::HandleModCharm: target="I64FMTD" with typeid=%d has a charm aura but no charm info!", m_target->GetGUID(), m_target->GetTypeId());
3044                }
3045            }
3046
3047            caster->SetCharm(0);
3048
3049            if(caster->GetTypeId() == TYPEID_PLAYER)
3050            {
3051                WorldPacket data(SMSG_PET_SPELLS, 8);
3052                data << uint64(0);
3053                ((Player*)caster)->GetSession()->SendPacket(&data);
3054            }
3055            if(m_target->GetTypeId() == TYPEID_UNIT)
3056            {
3057                ((Creature*)m_target)->AIM_Initialize();
3058                if (((Creature*)m_target)->AI())
3059                    ((Creature*)m_target)->AI()->AttackStart(caster);
3060            }
3061        }
3062    }
3063}
3064
3065void Aura::HandleModConfuse(bool apply, bool Real)
3066{
3067    if(!Real)
3068        return;
3069
3070    m_target->SetConfused(apply, GetCasterGUID(), GetId());
3071}
3072
3073void Aura::HandleModFear(bool apply, bool Real)
3074{
3075    if (!Real)
3076        return;
3077
3078    m_target->SetFeared(apply, GetCasterGUID(), GetId());
3079}
3080
3081void Aura::HandleFeignDeath(bool apply, bool Real)
3082{
3083    if(!Real)
3084        return;
3085
3086    if(m_target->GetTypeId() != TYPEID_PLAYER)
3087        return;
3088
3089    if( apply )
3090    {
3091        /*
3092        WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3093        data<<m_target->GetGUID();
3094        data<<uint8(0);
3095        m_target->SendMessageToSet(&data,true);
3096        */
3097                                                            // blizz like 2.0.x
3098        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN6);
3099                                                            // blizz like 2.0.x
3100        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3101                                                            // blizz like 2.0.x
3102        m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3103
3104        m_target->addUnitState(UNIT_STAT_DIED);
3105        m_target->CombatStop();
3106        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3107
3108        // prevent interrupt message
3109        if(m_caster_guid==m_target->GetGUID() && m_target->m_currentSpells[CURRENT_GENERIC_SPELL])
3110            m_target->m_currentSpells[CURRENT_GENERIC_SPELL]->finish();
3111        m_target->InterruptNonMeleeSpells(true);
3112        m_target->getHostilRefManager().deleteReferences();
3113    }
3114    else
3115    {
3116        /*
3117        WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3118        data<<m_target->GetGUID();
3119        data<<uint8(1);
3120        m_target->SendMessageToSet(&data,true);
3121        */
3122                                                            // blizz like 2.0.x
3123        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN6);
3124                                                            // blizz like 2.0.x
3125        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3126                                                            // blizz like 2.0.x
3127        m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3128
3129        m_target->clearUnitState(UNIT_STAT_DIED);
3130    }
3131}
3132
3133void Aura::HandleAuraModDisarm(bool apply, bool Real)
3134{
3135    if(!Real)
3136        return;
3137
3138    if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3139        return;
3140
3141    // not sure for it's correctness
3142    if(apply)
3143        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3144    else
3145        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3146
3147    // only at real add/remove aura
3148    if (m_target->GetTypeId() != TYPEID_PLAYER)
3149        return;
3150
3151    // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3152    if (((Player *)m_target)->IsInFeralForm())
3153        return;
3154
3155    if (apply)
3156        m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3157    else
3158        ((Player *)m_target)->SetRegularAttackTime();
3159
3160    m_target->UpdateDamagePhysical(BASE_ATTACK);
3161}
3162
3163void Aura::HandleAuraModStun(bool apply, bool Real)
3164{
3165    if(!Real)
3166        return;
3167
3168    if (apply)
3169    {
3170        m_target->addUnitState(UNIT_STAT_STUNNED);
3171        m_target->SetUInt64Value(UNIT_FIELD_TARGET, 0);
3172
3173        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE);
3174        m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3175
3176        // Creature specific
3177        if(m_target->GetTypeId() != TYPEID_PLAYER)
3178            ((Creature*)m_target)->StopMoving();
3179        else
3180            m_target->SetUnitMovementFlags(0);    //Clear movement flags
3181
3182        WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3183
3184        data.append(m_target->GetPackGUID());
3185        data << uint32(0);
3186        m_target->SendMessageToSet(&data,true);
3187    }
3188    else
3189    {
3190        // Real remove called after current aura remove from lists, check if other similar auras active
3191        if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3192            return;
3193
3194        m_target->clearUnitState(UNIT_STAT_STUNNED);
3195        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE);
3196
3197        if(!m_target->hasUnitState(UNIT_STAT_ROOT))         // prevent allow move if have also root effect
3198        {
3199            if(m_target->getVictim() && m_target->isAlive())
3200                m_target->SetUInt64Value(UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3201
3202            WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3203            data.append(m_target->GetPackGUID());
3204            data << uint32(0);
3205            m_target->SendMessageToSet(&data,true);
3206        }
3207
3208        // Wyvern Sting
3209        if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1721)
3210        {
3211            Unit* caster = GetCaster();
3212            if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3213                return;
3214
3215            uint32 spell_id = 0;
3216
3217            switch(GetId())
3218            {
3219                case 19386: spell_id = 24131; break;
3220                case 24132: spell_id = 24134; break;
3221                case 24133: spell_id = 24135; break;
3222                case 27068: spell_id = 27069; break;
3223                default:
3224                    sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3225                    return;
3226            }
3227
3228            SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3229
3230            if(!spellInfo)
3231                return;
3232
3233            caster->CastSpell(m_target,spellInfo,true,NULL,this);
3234            return;
3235        }
3236    }
3237}
3238
3239void Aura::HandleModStealth(bool apply, bool Real)
3240{
3241    if(apply)
3242    {
3243        if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3244        {
3245            // drop flag at stealth in bg
3246            m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3247
3248            // remove player from the objective's active player count at stealth
3249            if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3250                pvp->HandlePlayerActivityChanged((Player*)m_target);
3251        }
3252
3253        // only at real aura add
3254        if(Real)
3255        {
3256            m_target->SetByteValue(UNIT_FIELD_BYTES_1, 2, 0x02);
3257            if(m_target->GetTypeId()==TYPEID_PLAYER)
3258                m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3259
3260            // apply only if not in GM invisibility (and overwrite invisibility state)
3261            if(m_target->GetVisibility()!=VISIBILITY_OFF)
3262            {
3263                //m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3264                m_target->SetVisibility(VISIBILITY_OFF);
3265                m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3266            }
3267
3268            // for RACE_NIGHTELF stealth
3269            if(m_target->GetTypeId()==TYPEID_PLAYER && GetId()==20580)
3270                m_target->CastSpell(m_target, 21009, true, NULL, this);
3271        }
3272    }
3273    else
3274    {
3275        // only at real aura remove
3276        if(Real)
3277        {
3278            // for RACE_NIGHTELF stealth
3279            if(m_target->GetTypeId()==TYPEID_PLAYER && GetId()==20580)
3280                m_target->RemoveAurasDueToSpell(21009);
3281
3282            // if last SPELL_AURA_MOD_STEALTH and no GM invisibility
3283            if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH) && m_target->GetVisibility()!=VISIBILITY_OFF)
3284            {
3285                m_target->SetByteValue(UNIT_FIELD_BYTES_1, 2, 0x00);
3286                if(m_target->GetTypeId()==TYPEID_PLAYER)
3287                    m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3288
3289                // restore invisibility if any
3290                if(m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3291                {
3292                    //m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3293                    //m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3294                    m_target->SetVisibility(VISIBILITY_ON);
3295                }
3296                else
3297                {
3298                    m_target->SetVisibility(VISIBILITY_ON);
3299                    if(m_target->GetTypeId() == TYPEID_PLAYER)
3300                        if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3301                            pvp->HandlePlayerActivityChanged((Player*)m_target);
3302                }
3303            }
3304        }
3305    }
3306
3307    // Master of Subtlety
3308    Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3309    for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3310    {
3311        if ((*i)->GetSpellProto()->SpellIconID == 2114)
3312        {
3313            if (apply)
3314            {
3315                int32 bp = (*i)->GetModifier()->m_amount;
3316                m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3317            }
3318            else
3319                m_target->CastSpell(m_target,31666,true);
3320            break;
3321        }
3322    }
3323}
3324
3325void Aura::HandleInvisibility(bool apply, bool Real)
3326{
3327    if(apply)
3328    {
3329        m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3330
3331        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3332
3333        if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3334        {
3335            // apply glow vision
3336            m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3337            // remove player from the objective's active player count at invisibility
3338            if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3339                pvp->HandlePlayerActivityChanged((Player*)m_target);
3340        }
3341
3342        // apply only if not in GM invisibility and not stealth
3343        if(m_target->GetVisibility()==VISIBILITY_ON)
3344        {
3345            // Aura not added yet but visibility code expect temporary add aura
3346            //m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3347            //m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3348            m_target->SetVisibility(VISIBILITY_ON);
3349        }
3350    }
3351    else
3352    {
3353        // recalculate value at modifier remove (current aura already removed)
3354        m_target->m_invisibilityMask = 0;
3355        Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
3356        for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3357            m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3358
3359        // only at real aura remove and if not have different invisibility auras.
3360        if(Real && m_target->m_invisibilityMask==0)
3361        {
3362            // remove glow vision
3363            if(m_target->GetTypeId() == TYPEID_PLAYER)
3364                m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3365
3366            // apply only if not in GM invisibility & not stealthed while invisible
3367            if(m_target->GetVisibility()!=VISIBILITY_OFF)
3368            {
3369                // if have stealth aura then already have stealth visibility
3370                if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3371                {
3372                    m_target->SetVisibility(VISIBILITY_ON);
3373                    if(m_target->GetTypeId() == TYPEID_PLAYER)
3374                        if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3375                            pvp->HandlePlayerActivityChanged((Player*)m_target);
3376                }
3377            }
3378        }
3379    }
3380}
3381
3382void Aura::HandleInvisibilityDetect(bool apply, bool Real)
3383{
3384    if(apply)
3385    {
3386        m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3387    }
3388    else
3389    {
3390        // recalculate value at modifier remove (current aura already removed)
3391        m_target->m_detectInvisibilityMask = 0;
3392        Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
3393        for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3394            m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3395    }
3396    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3397        ObjectAccessor::UpdateVisibilityForPlayer((Player*)m_target);
3398}
3399
3400void Aura::HandleAuraModRoot(bool apply, bool Real)
3401{
3402    // only at real add/remove aura
3403    if(!Real)
3404        return;
3405
3406    uint32 apply_stat = UNIT_STAT_ROOT;
3407    if (apply)
3408    {
3409        m_target->addUnitState(UNIT_STAT_ROOT);
3410        m_target->SetUInt64Value (UNIT_FIELD_TARGET, 0);
3411                                                            // probably wrong
3412        m_target->SetFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3413
3414        //Save last orientation
3415        if( m_target->getVictim() )
3416            m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
3417
3418        if(m_target->GetTypeId() == TYPEID_PLAYER)
3419        {
3420            WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
3421            data.append(m_target->GetPackGUID());
3422            data << (uint32)2;
3423            m_target->SendMessageToSet(&data,true);
3424
3425            //Clear unit movement flags
3426            m_target->SetUnitMovementFlags(0);
3427        }
3428        else
3429            ((Creature *)m_target)->StopMoving();
3430    }
3431    else
3432    {
3433        // Real remove called after current aura remove from lists, check if other similar auras active
3434        if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
3435            return;
3436
3437        m_target->clearUnitState(UNIT_STAT_ROOT);
3438                                                            // probably wrong
3439        m_target->RemoveFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3440
3441        if(!m_target->hasUnitState(UNIT_STAT_STUNNED))      // prevent allow move if have also stun effect
3442        {
3443            if(m_target->getVictim() && m_target->isAlive())
3444                m_target->SetUInt64Value (UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3445
3446            if(m_target->GetTypeId() == TYPEID_PLAYER)
3447            {
3448                WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
3449                data.append(m_target->GetPackGUID());
3450                data << (uint32)2;
3451                m_target->SendMessageToSet(&data,true);
3452            }
3453        }
3454    }
3455}
3456
3457void Aura::HandleAuraModSilence(bool apply, bool Real)
3458{
3459    // only at real add/remove aura
3460    if(!Real)
3461        return;
3462
3463    if(apply)
3464    {
3465        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3466        // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
3467        for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL;i++)
3468        {
3469            Spell* currentSpell = m_target->m_currentSpells[i];
3470            if (currentSpell && currentSpell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
3471            {
3472                uint32 state = currentSpell->getState();
3473                // Stop spells on prepare or casting state
3474                if ( state == SPELL_STATE_PREPARING || state == SPELL_STATE_CASTING )
3475                {
3476                    currentSpell->cancel();
3477                    currentSpell->SetReferencedFromCurrent(false);
3478                    m_target->m_currentSpells[i] = NULL;
3479                }
3480            }
3481        }
3482
3483        switch (GetId())
3484        {
3485            // Arcane Torrent (Energy)
3486            case 25046:
3487            {
3488                Unit * caster = GetCaster();
3489                if (!caster)
3490                    return;
3491
3492                // Search Mana Tap auras on caster
3493                int32 energy = 0;
3494                Unit::AuraList const& m_dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
3495                for(Unit::AuraList::const_iterator i = m_dummyAuras.begin(); i != m_dummyAuras.end(); ++i)
3496                    if ((*i)->GetId() == 28734)
3497                        ++energy;
3498                if (energy)
3499                {
3500                    energy *= 10;
3501                    caster->CastCustomSpell(caster, 25048, &energy, NULL, NULL, true);
3502                    caster->RemoveAurasDueToSpell(28734);
3503                }
3504            }
3505        }
3506    }
3507    else
3508    {
3509        // Real remove called after current aura remove from lists, check if other similar auras active
3510        if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
3511            return;
3512
3513        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3514    }
3515}
3516
3517void Aura::HandleModThreat(bool apply, bool Real)
3518{
3519    // only at real add/remove aura
3520    if(!Real)
3521        return;
3522
3523    if(!m_target->isAlive())
3524        return;
3525
3526    Unit* caster = GetCaster();
3527
3528    if(!caster || !caster->isAlive())
3529        return;
3530
3531    int level_diff = 0;
3532    int multiplier = 0;
3533    switch (GetId())
3534    {
3535        // Arcane Shroud
3536        case 26400:
3537            level_diff = m_target->getLevel() - 60;
3538            multiplier = 2;
3539            break;
3540        // The Eye of Diminution
3541        case 28862:
3542            level_diff = m_target->getLevel() - 60;
3543            multiplier = 1;
3544            break;
3545    }
3546    if (level_diff > 0)
3547        m_modifier.m_amount += multiplier * level_diff;
3548
3549    for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
3550    {
3551        if(m_modifier.m_miscvalue & int32(1<<x))
3552        {
3553            if(m_target->GetTypeId() == TYPEID_PLAYER)
3554                ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_positive ? m_modifier.m_amount : -m_modifier.m_amount, apply);
3555        }
3556    }
3557}
3558
3559void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
3560{
3561    // only at real add/remove aura
3562    if(!Real)
3563        return;
3564
3565    if(!m_target->isAlive() || m_target->GetTypeId()!= TYPEID_PLAYER)
3566        return;
3567
3568    Unit* caster = GetCaster();
3569
3570    if(!caster || !caster->isAlive())
3571        return;
3572
3573    float threatMod = 0.0f;
3574    if(apply)
3575        threatMod = float(m_modifier.m_amount);
3576    else
3577        threatMod =  float(-m_modifier.m_amount);
3578
3579    m_target->getHostilRefManager().threatAssist(caster, threatMod);
3580}
3581
3582void Aura::HandleModTaunt(bool apply, bool Real)
3583{
3584    // only at real add/remove aura
3585    if(!Real)
3586        return;
3587
3588    if(!m_target->isAlive() || !m_target->CanHaveThreatList())
3589        return;
3590
3591    Unit* caster = GetCaster();
3592
3593    if(!caster || !caster->isAlive() || caster->GetTypeId() != TYPEID_PLAYER)
3594        return;
3595
3596    if(apply)
3597        m_target->TauntApply(caster);
3598    else
3599    {
3600        // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
3601        m_target->TauntFadeOut(caster);
3602    }
3603}
3604
3605/*********************************************************/
3606/***                  MODIFY SPEED                     ***/
3607/*********************************************************/
3608void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real)
3609{
3610    // all applied/removed only at real aura add/remove
3611    if(!Real)
3612        return;
3613
3614    m_target->UpdateSpeed(MOVE_RUN, true);
3615}
3616
3617void Aura::HandleAuraModIncreaseMountedSpeed(bool /*apply*/, bool Real)
3618{
3619    // all applied/removed only at real aura add/remove
3620    if(!Real)
3621        return;
3622
3623    m_target->UpdateSpeed(MOVE_RUN, true);
3624}
3625
3626void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
3627{
3628    // all applied/removed only at real aura add/remove
3629    if(!Real)
3630        return;
3631
3632    // Enable Fly mode for flying mounts
3633    if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
3634    {
3635        WorldPacket data;
3636        if(apply)
3637            data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
3638        else
3639            data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
3640        data.append(m_target->GetPackGUID());
3641        data << uint32(0);                                      // unknown
3642        m_target->SendMessageToSet(&data, true);
3643
3644        //Players on flying mounts must be immune to polymorph
3645        if (m_target->GetTypeId()==TYPEID_PLAYER)
3646            m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
3647
3648        // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
3649        if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
3650            m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3651    }
3652
3653    m_target->UpdateSpeed(MOVE_FLY, true);
3654}
3655
3656void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real)
3657{
3658    // all applied/removed only at real aura add/remove
3659    if(!Real)
3660        return;
3661
3662    m_target->UpdateSpeed(MOVE_SWIM, true);
3663}
3664
3665void Aura::HandleAuraModDecreaseSpeed(bool /*apply*/, bool Real)
3666{
3667    // all applied/removed only at real aura add/remove
3668    if(!Real)
3669        return;
3670
3671    m_target->UpdateSpeed(MOVE_RUN, true);
3672    m_target->UpdateSpeed(MOVE_SWIM, true);
3673    m_target->UpdateSpeed(MOVE_FLY, true);
3674}
3675
3676void Aura::HandleAuraModUseNormalSpeed(bool /*apply*/, bool Real)
3677{
3678    // all applied/removed only at real aura add/remove
3679    if(!Real)
3680        return;
3681
3682    m_target->UpdateSpeed(MOVE_RUN,  true);
3683    m_target->UpdateSpeed(MOVE_SWIM, true);
3684    m_target->UpdateSpeed(MOVE_FLY,  true);
3685}
3686
3687/*********************************************************/
3688/***                     IMMUNITY                      ***/
3689/*********************************************************/
3690
3691void Aura::HandleModMechanicImmunity(bool apply, bool Real)
3692{
3693    uint32 mechanic = 1 << m_modifier.m_miscvalue;
3694
3695    //immune movement impairment and loss of control
3696    if(GetId()==42292)
3697        mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
3698
3699    if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
3700    {
3701        Unit::AuraMap& Auras = m_target->GetAuras();
3702        for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
3703        {
3704            next = iter;
3705            ++next;
3706            SpellEntry const *spell = iter->second->GetSpellProto();
3707            if (!( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY)  // spells unaffected by invulnerability
3708                && !iter->second->IsPositive()                                    // only remove negative spells
3709                && spell->Id != GetId())
3710            {
3711                //check for mechanic mask
3712                if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & mechanic)
3713                {
3714                    m_target->RemoveAurasDueToSpell(spell->Id);
3715                    if(Auras.empty())
3716                        break;
3717                    else
3718                        next = Auras.begin();
3719                }
3720            }
3721        }
3722    }
3723
3724    m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,m_modifier.m_miscvalue,apply);
3725
3726    // special cases
3727    switch(m_modifier.m_miscvalue)
3728    {
3729        case MECHANIC_INVULNERABILITY:
3730            m_target->ModifyAuraState(AURA_STATE_FORBEARANCE,apply);
3731            break;
3732        case MECHANIC_SHIELD:
3733            m_target->ModifyAuraState(AURA_STATE_WEAKENED_SOUL,apply);
3734            break;
3735    }
3736
3737    // Bestial Wrath
3738    if ( GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->Id == 19574)
3739    {
3740        // The Beast Within cast on owner if talent present
3741        if ( Unit* owner = m_target->GetOwner() )
3742        {
3743            // Search talent
3744            Unit::AuraList const& m_dummyAuras = owner->GetAurasByType(SPELL_AURA_DUMMY);
3745            for(Unit::AuraList::const_iterator i = m_dummyAuras.begin(); i != m_dummyAuras.end(); ++i)
3746            {
3747                if ( (*i)->GetSpellProto()->SpellIconID == 2229 )
3748                {
3749                    if (apply)
3750                        owner->CastSpell(owner, 34471, true, 0, this);
3751                    else
3752                        owner->RemoveAurasDueToSpell(34471);
3753                    break;
3754                }
3755            }
3756        }
3757    }
3758
3759    // The Beast Within and Bestial Wrath - immunity
3760    if(GetId() == 19574 || GetId() == 34471)
3761    {
3762        if(apply)
3763        {
3764            m_target->CastSpell(m_target,24395,true);
3765            m_target->CastSpell(m_target,24396,true);
3766            m_target->CastSpell(m_target,24397,true);
3767            m_target->CastSpell(m_target,26592,true);
3768        }
3769        else
3770        {
3771            m_target->RemoveAurasDueToSpell(24395);
3772            m_target->RemoveAurasDueToSpell(24396);
3773            m_target->RemoveAurasDueToSpell(24397);
3774            m_target->RemoveAurasDueToSpell(26592);
3775        }
3776    }
3777}
3778
3779void Aura::HandleAuraModEffectImmunity(bool apply, bool Real)
3780{
3781    if(!apply)
3782    {
3783        if(m_target->GetTypeId() == TYPEID_PLAYER)
3784        {
3785            if(((Player*)m_target)->InBattleGround())
3786            {
3787                BattleGround *bg = ((Player*)m_target)->GetBattleGround();
3788                if(bg)
3789                {
3790                    switch(bg->GetTypeID())
3791                    {
3792                        case BATTLEGROUND_AV:
3793                        {
3794                            break;
3795                        }
3796                        case BATTLEGROUND_WS:
3797                        {
3798                            // Warsong Flag, horde               // Silverwing Flag, alliance
3799                            if(GetId() == 23333 || GetId() == 23335)
3800                                    bg->EventPlayerDroppedFlag(((Player*)m_target));
3801                            break;
3802                        }
3803                        case BATTLEGROUND_AB:
3804                        {
3805                            break;
3806                        }
3807                        case BATTLEGROUND_EY:
3808                        {
3809                           if(GetId() == 34976)
3810                                bg->EventPlayerDroppedFlag(((Player*)m_target));
3811                            break;
3812                        }
3813                    }
3814                }
3815            }
3816            else
3817                sOutdoorPvPMgr.HandleDropFlag((Player*)m_target,GetSpellProto()->Id);
3818        }
3819    }
3820
3821    m_target->ApplySpellImmune(GetId(),IMMUNITY_EFFECT,m_modifier.m_miscvalue,apply);
3822}
3823
3824void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
3825{
3826    if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
3827    {
3828        Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
3829        for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
3830        {
3831            if (auraList.front() != this)                   // skip itself aura (it already added)
3832            {
3833                m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
3834                itr = auraList.begin();
3835            }
3836            else
3837                ++itr;
3838        }
3839    }
3840
3841    m_target->ApplySpellImmune(GetId(),IMMUNITY_STATE,m_modifier.m_miscvalue,apply);
3842}
3843
3844void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
3845{
3846    if(apply && m_modifier.m_miscvalue == SPELL_SCHOOL_MASK_NORMAL)
3847        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3848 
3849    m_target->ApplySpellImmune(GetId(),IMMUNITY_SCHOOL,m_modifier.m_miscvalue,apply);
3850
3851    if(Real && apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
3852    {
3853        if(IsPositiveSpell(GetId()))                        //Only positive immunity removes auras
3854        {
3855            uint32 school_mask = m_modifier.m_miscvalue;
3856            Unit::AuraMap& Auras = m_target->GetAuras();
3857            for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
3858            {
3859                next = iter;
3860                ++next;
3861                SpellEntry const *spell = iter->second->GetSpellProto();
3862                if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
3863                    && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY)   //Spells unaffected by invulnerability
3864                    && !iter->second->IsPositive()          //Don't remove positive spells
3865                    && spell->Id != GetId() )               //Don't remove self
3866                {
3867                    m_target->RemoveAurasDueToSpell(spell->Id);
3868                    if(Auras.empty())
3869                        break;
3870                    else
3871                        next = Auras.begin();
3872                }
3873            }
3874        }
3875    }
3876    if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
3877    {
3878        if( apply )
3879            m_target->addUnitState(UNIT_STAT_ISOLATED);
3880        else
3881            m_target->clearUnitState(UNIT_STAT_ISOLATED);
3882    }
3883}
3884
3885void Aura::HandleAuraModDmgImmunity(bool apply, bool Real)
3886{
3887    m_target->ApplySpellImmune(GetId(),IMMUNITY_DAMAGE,m_modifier.m_miscvalue,apply);
3888}
3889
3890void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
3891{
3892    // all applied/removed only at real aura add/remove
3893    if(!Real)
3894        return;
3895
3896    m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
3897}
3898
3899void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
3900{
3901    if(!Real)
3902        return;
3903
3904    if(apply)
3905    {
3906        // some spell have charges by functionality not have its in spell data
3907        switch (GetId())
3908        {
3909            case 28200:                                     // Ascendance (Talisman of Ascendance trinket)
3910                m_procCharges = 6;
3911                UpdateAuraCharges();
3912                break;
3913            default: break;
3914        }
3915    }
3916}
3917
3918void Aura::HandleAuraModStalked(bool apply, bool Real)
3919{
3920    // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
3921    if(apply)
3922        m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
3923    else
3924        m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
3925}
3926
3927/*********************************************************/
3928/***                   PERIODIC                        ***/
3929/*********************************************************/
3930
3931void Aura::HandlePeriodicTriggerSpell(bool apply, bool Real)
3932{
3933    if (m_periodicTimer <= 0)
3934        m_periodicTimer += m_modifier.periodictime;
3935
3936    m_isPeriodic = apply;
3937    m_isTrigger = apply;
3938
3939    // Curse of the Plaguebringer
3940    if (!apply && m_spellProto->Id == 29213 && m_removeMode!=AURA_REMOVE_BY_DISPEL)
3941    {
3942        // Cast Wrath of the Plaguebringer if not dispelled
3943        m_target->CastSpell(m_target, 29214, true, 0, this);
3944    }
3945}
3946
3947void Aura::HandlePeriodicEnergize(bool apply, bool Real)
3948{
3949    if (m_periodicTimer <= 0)
3950        m_periodicTimer += m_modifier.periodictime;
3951
3952    m_isPeriodic = apply;
3953}
3954
3955void Aura::HandlePeriodicHeal(bool apply, bool Real)
3956{
3957    if (m_periodicTimer <= 0)
3958        m_periodicTimer += m_modifier.periodictime;
3959
3960    m_isPeriodic = apply;
3961
3962    // only at real apply
3963    if (Real && apply && GetSpellProto()->Mechanic == MECHANIC_BANDAGE)
3964    {
3965        // provided m_target as original caster to prevent apply aura caster selection for this negative buff
3966        m_target->CastSpell(m_target,11196,true,NULL,this,m_target->GetGUID());
3967    }
3968
3969    // For prevent double apply bonuses
3970    bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
3971
3972    if(!loading && apply)
3973    {
3974        switch (m_spellProto->SpellFamilyName)
3975        {
3976            case SPELLFAMILY_DRUID:
3977            {
3978                // Rejuvenation
3979                if(m_spellProto->SpellFamilyFlags & 0x0000000000000010LL)
3980                {
3981                    if(Unit* caster = GetCaster())
3982                    {
3983                        Unit::AuraList const& classScripts = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
3984                        for(Unit::AuraList::const_iterator k = classScripts.begin(); k != classScripts.end(); ++k)
3985                        {
3986                            int32 tickcount = GetSpellDuration(m_spellProto) / m_spellProto->EffectAmplitude[m_effIndex];
3987                            switch((*k)->GetModifier()->m_miscvalue)
3988                            {
3989                                case 4953:                          // Increased Rejuvenation Healing - Harold's Rejuvenating Broach Aura
3990                                case 4415:                          // Increased Rejuvenation Healing - Idol of Rejuvenation Aura
3991                                {
3992                                    m_modifier.m_amount += (*k)->GetModifier()->m_amount / tickcount;
3993                                    break;
3994                                }
3995                            }
3996                        }
3997                    }
3998                }
3999            }
4000        }
4001    }
4002}
4003
4004void Aura::HandlePeriodicDamage(bool apply, bool Real)
4005{
4006    // spells required only Real aura add/remove
4007    if(!Real)
4008        return;
4009
4010    if (m_periodicTimer <= 0)
4011        m_periodicTimer += m_modifier.periodictime;
4012
4013    m_isPeriodic = apply;
4014
4015    // For prevent double apply bonuses
4016    bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4017
4018    Unit *caster = GetCaster();
4019
4020    switch (m_spellProto->SpellFamilyName)
4021    {
4022        case SPELLFAMILY_GENERIC:
4023        {
4024            // Pounce Bleed
4025            if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual == 0 )
4026            {
4027                // $AP*0.18/6 bonus per tick
4028                if (apply && !loading && caster)
4029                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4030                return;
4031            }
4032            break;
4033        }
4034        case SPELLFAMILY_WARRIOR:
4035        {
4036            // Rend
4037            if (m_spellProto->SpellFamilyFlags & 0x0000000000000020LL)
4038            {
4039                // 0.00743*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4040                if (apply && !loading && caster)
4041                {
4042                    float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4043                    int32 mws = caster->GetAttackTime(BASE_ATTACK);
4044                    float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4045                    float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4046                    // WARNING! in 3.0 multiplier 0.00743f change to 0.6
4047                    m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.00743f);
4048                }
4049                return;
4050            }
4051            break;
4052        }
4053        case SPELLFAMILY_DRUID:
4054        {
4055            // Rake
4056            if (m_spellProto->SpellFamilyFlags & 0x0000000000001000LL)
4057            {
4058                // $AP*0.06/3 bonus per tick
4059                if (apply && !loading && caster)
4060                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 2 / 100);
4061                return;
4062            }
4063            // Lacerate
4064            if (m_spellProto->SpellFamilyFlags & 0x000000010000000000LL)
4065            {
4066                // $AP*0.05/5 bonus per tick
4067                if (apply && !loading && caster)
4068                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4069                return;
4070            }
4071            // Rip
4072            if (m_spellProto->SpellFamilyFlags & 0x000000000000800000LL)
4073            {
4074                // $AP * min(0.06*$cp, 0.24)/6 [Yes, there is no difference, whether 4 or 5 CPs are being used]
4075                if (apply && !loading && caster && caster->GetTypeId() == TYPEID_PLAYER)
4076                {
4077                    uint8 cp = ((Player*)caster)->GetComboPoints();
4078
4079                    // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4080                    Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4081                    for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4082                    {
4083                        if((*itr)->GetId()==34241)
4084                        {
4085                            m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4086                            break;
4087                        }
4088                    }
4089
4090                    if (cp > 4) cp = 4;
4091                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4092                }
4093                return;
4094            }
4095            break;
4096        }
4097        case SPELLFAMILY_ROGUE:
4098        {
4099            // Deadly poison aura state
4100            if((m_spellProto->SpellFamilyFlags & 0x10000) && m_spellProto->SpellVisual==5100)
4101            {
4102                if(apply)
4103                    m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON,true);
4104                else
4105                {
4106                    // current aura already removed, search present of another
4107                    bool found = false;
4108                    Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
4109                    for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
4110                    {
4111                        SpellEntry const* itr_spell = (*itr)->GetSpellProto();
4112                        if(itr_spell && itr_spell->SpellFamilyName==SPELLFAMILY_ROGUE && (itr_spell->SpellFamilyFlags & 0x10000) && itr_spell->SpellVisual==5100)
4113                        {
4114                            found = true;
4115                            break;
4116                        }
4117                    }
4118                    // this has been last deadly poison aura
4119                    if(!found)
4120                        m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON,false);
4121                }
4122                return;
4123            }
4124            // Rupture
4125            if (m_spellProto->SpellFamilyFlags & 0x000000000000100000LL)
4126            {
4127                // Dmg/tick = $AP*min(0.01*$cp, 0.03) [Like Rip: only the first three CP increase the contribution from AP]
4128                if (apply && !loading && caster && caster->GetTypeId() == TYPEID_PLAYER)
4129                {
4130                    uint8 cp = ((Player*)caster)->GetComboPoints();
4131                    if (cp > 3) cp = 3;
4132                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4133                }
4134                return;
4135            }
4136            // Garrote
4137            if (m_spellProto->SpellFamilyFlags & 0x000000000000000100LL)
4138            {
4139                // $AP*0.18/6 bonus per tick
4140                if (apply && !loading && caster)
4141                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4142                return;
4143            }
4144            break;
4145        }
4146        case SPELLFAMILY_HUNTER:
4147        {
4148            // Serpent Sting
4149            if (m_spellProto->SpellFamilyFlags & 0x0000000000004000LL)
4150            {
4151                // $RAP*0.1/5 bonus per tick
4152                if (apply && !loading && caster)
4153                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4154                return;
4155            }
4156            // Immolation Trap
4157            if (m_spellProto->SpellFamilyFlags & 0x0000000000000004LL && m_spellProto->SpellIconID == 678)
4158            {
4159                // $RAP*0.1/5 bonus per tick
4160                if (apply && !loading && caster)
4161                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4162                return;
4163            }
4164            break;
4165        }
4166        case SPELLFAMILY_PALADIN:
4167        {
4168            // Consecration
4169            if (m_spellProto->SpellFamilyFlags & 0x0000000000000020LL)
4170            {
4171                if (apply && !loading)
4172                {
4173                    if(Unit* caster = GetCaster())
4174                    {
4175                        Unit::AuraList const& classScripts = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4176                        for(Unit::AuraList::const_iterator k = classScripts.begin(); k != classScripts.end(); ++k)
4177                        {
4178                            int32 tickcount = GetSpellDuration(m_spellProto) / m_spellProto->EffectAmplitude[m_effIndex];
4179                            switch((*k)->GetModifier()->m_miscvalue)
4180                            {
4181                                case 5147:                  // Improved Consecration - Libram of the Eternal Rest
4182                                {
4183                                    m_modifier.m_amount += (*k)->GetModifier()->m_amount / tickcount;
4184                                    break;
4185                                }
4186                            }
4187                        }
4188                    }
4189                }
4190                return;
4191            }
4192            break;
4193        }
4194        default:
4195            break;
4196    }
4197}
4198
4199void Aura::HandlePeriodicDamagePCT(bool apply, bool Real)
4200{
4201    if (m_periodicTimer <= 0)
4202        m_periodicTimer += m_modifier.periodictime;
4203
4204    m_isPeriodic = apply;
4205}
4206
4207void Aura::HandlePeriodicLeech(bool apply, bool Real)
4208{
4209    if (m_periodicTimer <= 0)
4210        m_periodicTimer += m_modifier.periodictime;
4211
4212    m_isPeriodic = apply;
4213}
4214
4215void Aura::HandlePeriodicManaLeech(bool apply, bool Real)
4216{
4217    if (m_periodicTimer <= 0)
4218        m_periodicTimer += m_modifier.periodictime;
4219
4220    m_isPeriodic = apply;
4221}
4222
4223/*********************************************************/
4224/***                  MODIFY STATS                     ***/
4225/*********************************************************/
4226
4227/********************************/
4228/***        RESISTANCE        ***/
4229/********************************/
4230
4231void Aura::HandleAuraModResistanceExclusive(bool apply, bool Real)
4232{
4233    for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4234    {
4235        if(m_modifier.m_miscvalue & int32(1<<x))
4236        {
4237            m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4238            if(m_target->GetTypeId() == TYPEID_PLAYER)
4239                m_target->ApplyResistanceBuffModsMod(SpellSchools(x),m_positive,m_modifier.m_amount, apply);
4240        }
4241    }
4242}
4243
4244void Aura::HandleAuraModResistance(bool apply, bool Real)
4245{
4246    for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4247    {
4248        if(m_modifier.m_miscvalue & int32(1<<x))
4249        {
4250            m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4251            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4252                m_target->ApplyResistanceBuffModsMod(SpellSchools(x),m_positive,m_modifier.m_amount, apply);
4253        }
4254    }
4255
4256    // Faerie Fire (druid versions)
4257    if( m_spellProto->SpellIconID == 109 &&
4258        m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID &&
4259        m_spellProto->SpellFamilyFlags & 0x0000000000000400LL )
4260    {
4261        m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE,apply);
4262    }
4263}
4264
4265void Aura::HandleAuraModBaseResistancePCT(bool apply, bool Real)
4266{
4267    // only players have base stats
4268    if(m_target->GetTypeId() != TYPEID_PLAYER)
4269    {
4270        //pets only have base armor
4271        if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4272            m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4273    }
4274    else
4275    {
4276        for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4277        {
4278            if(m_modifier.m_miscvalue & int32(1<<x))
4279                m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4280        }
4281    }
4282}
4283
4284void Aura::HandleModResistancePercent(bool apply, bool Real)
4285{
4286    for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4287    {
4288        if(m_modifier.m_miscvalue & int32(1<<i))
4289        {
4290            m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4291            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4292            {
4293                m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i),true,m_modifier.m_amount, apply);
4294                m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i),false,m_modifier.m_amount, apply);
4295            }
4296        }
4297    }
4298}
4299
4300void Aura::HandleModBaseResistance(bool apply, bool Real)
4301{
4302    // only players have base stats
4303    if(m_target->GetTypeId() != TYPEID_PLAYER)
4304    {
4305        //only pets have base stats
4306        if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4307            m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4308    }
4309    else
4310    {
4311        for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4312            if(m_modifier.m_miscvalue & (1<<i))
4313                m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4314    }
4315}
4316
4317/********************************/
4318/***           STAT           ***/
4319/********************************/
4320
4321void Aura::HandleAuraModStat(bool apply, bool Real)
4322{
4323    if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4324    {
4325        sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4326        return;
4327    }
4328
4329    for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4330    {
4331        // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4332        if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4333        {
4334            //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4335            m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4336            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4337                m_target->ApplyStatBuffMod(Stats(i),m_modifier.m_amount,apply);
4338        }
4339    }
4340}
4341
4342void Aura::HandleModPercentStat(bool apply, bool Real)
4343{
4344    if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4345    {
4346        sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4347        return;
4348    }
4349
4350    // only players have base stats
4351    if (m_target->GetTypeId() != TYPEID_PLAYER)
4352        return;
4353
4354    for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4355    {
4356        if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4357            m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4358    }
4359}
4360
4361void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool Real)
4362{
4363    if(m_target->GetTypeId() != TYPEID_PLAYER)
4364        return;
4365
4366    // Magic damage modifiers implemented in Unit::SpellDamageBonus
4367    // This information for client side use only
4368    // Recalculate bonus
4369    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4370}
4371
4372void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool Real)
4373{
4374    if(m_target->GetTypeId() != TYPEID_PLAYER)
4375        return;
4376
4377    // Recalculate bonus
4378    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4379}
4380
4381void Aura::HandleAuraModDispelResist(bool apply, bool Real)
4382{
4383    if(!Real || !apply)
4384        return;
4385
4386    if(GetId()==33206)
4387        m_target->CastSpell(m_target,44416,true,NULL,this,GetCasterGUID());
4388}
4389
4390void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool Real)
4391{
4392    if(m_target->GetTypeId() != TYPEID_PLAYER)
4393        return;
4394
4395    // Magic damage modifiers implemented in Unit::SpellDamageBonus
4396    // This information for client side use only
4397    // Recalculate bonus
4398    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4399}
4400
4401void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool Real)
4402{
4403    if(m_target->GetTypeId() != TYPEID_PLAYER)
4404        return;
4405
4406    // Recalculate bonus
4407    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4408}
4409
4410void Aura::HandleModHealingDone(bool /*apply*/, bool Real)
4411{
4412    if(m_target->GetTypeId() != TYPEID_PLAYER)
4413        return;
4414    // implemented in Unit::SpellHealingBonus
4415    // this information is for client side only
4416    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4417}
4418
4419void Aura::HandleModTotalPercentStat(bool apply, bool Real)
4420{
4421    if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4422    {
4423        sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4424        return;
4425    }
4426
4427    //save current and max HP before applying aura
4428    uint32 curHPValue = m_target->GetHealth();
4429    uint32 maxHPValue = m_target->GetMaxHealth();
4430
4431    for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4432    {
4433        if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4434        {
4435            m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4436            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4437                m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
4438        }
4439    }
4440
4441    //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
4442    if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
4443    {
4444        // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
4445        uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
4446        m_target->SetHealth(newHPValue);
4447    }
4448}
4449
4450void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool Real)
4451{
4452    if(m_target->GetTypeId() != TYPEID_PLAYER)
4453        return;
4454
4455    if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
4456    {
4457        // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
4458        // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
4459        sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
4460        return;
4461    }
4462
4463    // Recalculate Armor
4464    m_target->UpdateArmor();
4465}
4466
4467/********************************/
4468/***      HEAL & ENERGIZE     ***/
4469/********************************/
4470void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool Real)
4471{
4472    /*
4473    Need additional checking for auras who reduce or increase healing, magic effect like Dumpen Magic,
4474    so this aura not fully working.
4475    */
4476    if(apply)
4477    {
4478        if(!m_target->isAlive())
4479            return;
4480
4481        if((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) && !m_target->IsSitState())
4482            m_target->SetStandState(PLAYER_STATE_SIT);
4483
4484        if(m_periodicTimer <= 0)
4485        {
4486            m_periodicTimer += m_modifier.periodictime;
4487
4488            if(m_target->GetHealth() < m_target->GetMaxHealth())
4489            {
4490                // PeriodicTick can cast triggered spells with stats changes
4491                PeriodicTick();
4492            }
4493        }
4494    }
4495
4496    m_isPeriodic = apply;
4497}
4498
4499void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool Real)
4500{
4501    if((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) && apply  && !m_target->IsSitState())
4502        m_target->SetStandState(PLAYER_STATE_SIT);
4503    if(apply)
4504    {
4505        if(m_modifier.periodictime == 0)
4506            m_modifier.periodictime = 1000;
4507        if(m_periodicTimer <= 0 && m_target->getPowerType() == POWER_MANA)
4508        {
4509            m_periodicTimer += m_modifier.periodictime;
4510
4511            if(m_target->GetPower(POWER_MANA) < m_target->GetMaxPower(POWER_MANA))
4512            {
4513                // PeriodicTick can cast triggered spells with stats changes
4514                PeriodicTick();
4515            }
4516        }
4517    }
4518
4519    m_isPeriodic = apply;
4520}
4521
4522void Aura::HandleModRegen(bool apply, bool Real)            // eating
4523{
4524    if(apply)
4525    {
4526        if(!m_target->isAlive())
4527            return;
4528
4529        if ((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED)  && !m_target->IsSitState())
4530            m_target->SetStandState(PLAYER_STATE_SIT);
4531
4532        if(m_periodicTimer <= 0)
4533        {
4534            m_periodicTimer += 5000;
4535            int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
4536            Unit *caster = GetCaster();
4537            if (caster)
4538            {
4539                SpellEntry const *spellProto = GetSpellProto();
4540                if (spellProto)
4541                    m_target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, spellProto);
4542            }
4543        }
4544    }
4545
4546    m_isPeriodic = apply;
4547}
4548
4549void Aura::HandleModPowerRegen(bool apply, bool Real)       // drinking
4550{
4551    if ((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) && apply && !m_target->IsSitState())
4552        m_target->SetStandState(PLAYER_STATE_SIT);
4553
4554    if(apply && m_periodicTimer <= 0)
4555    {
4556        m_periodicTimer += 2000;
4557
4558        Powers pt = m_target->getPowerType();
4559        if(int32(pt) != m_modifier.m_miscvalue)
4560            return;
4561
4562        if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
4563        {
4564            // eating anim
4565            m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
4566        }
4567        else if( GetId() == 20577 )
4568        {
4569            // cannibalize anim
4570            m_target->HandleEmoteCommand(398);
4571        }
4572
4573        // Warrior talent, gain 1 rage every 3 seconds while in combat
4574        if(pt == POWER_RAGE && m_target->isInCombat())
4575        {
4576            m_target->ModifyPower(pt, m_modifier.m_amount*10/17);
4577            m_periodicTimer += 1000;
4578        }
4579    }
4580    m_isPeriodic = apply;
4581    if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
4582        ((Player*)m_target)->UpdateManaRegen();
4583}
4584
4585void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real)
4586{
4587    // spells required only Real aura add/remove
4588    if(!Real)
4589        return;
4590
4591    if (m_target->GetTypeId() != TYPEID_PLAYER)
4592        return;
4593
4594    // Update manaregen value
4595    if (m_modifier.m_miscvalue == POWER_MANA)
4596        ((Player*)m_target)->UpdateManaRegen();
4597}
4598
4599void Aura::HandleModManaRegen(bool /*apply*/, bool Real)
4600{
4601    // spells required only Real aura add/remove
4602    if(!Real)
4603        return;
4604
4605    if (m_target->GetTypeId() != TYPEID_PLAYER)
4606        return;
4607
4608    //Note: an increase in regen does NOT cause threat.
4609    ((Player*)m_target)->UpdateManaRegen();
4610}
4611
4612void Aura::HandleComprehendLanguage(bool apply, bool Real)
4613{
4614    if(apply)
4615        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4616    else
4617        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4618}
4619
4620void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
4621{
4622    if(Real)
4623    {
4624        if(apply)
4625        {
4626            m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4627            m_target->ModifyHealth(m_modifier.m_amount);
4628        }
4629        else
4630        {
4631            if (int32(m_target->GetHealth()) > m_modifier.m_amount)
4632                m_target->ModifyHealth(-m_modifier.m_amount);
4633            else
4634                m_target->SetHealth(1);
4635            m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4636        }
4637    }
4638}
4639
4640void  Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool Real)
4641{
4642    uint32 oldhealth = m_target->GetHealth();
4643    double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
4644
4645    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4646
4647    // refresh percentage
4648    if(oldhealth > 0)
4649    {
4650        uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
4651        if(newhealth==0)
4652            newhealth = 1;
4653
4654        m_target->SetHealth(newhealth);
4655    }
4656}
4657
4658void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
4659{
4660    Powers powerType = m_target->getPowerType();
4661    if(int32(powerType) != m_modifier.m_miscvalue)
4662        return;
4663
4664    m_target->HandleStatModifier(UnitMods(UNIT_MOD_POWER_START + powerType), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4665}
4666
4667void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool Real)
4668{
4669    Powers powerType = m_target->getPowerType();
4670    if(int32(powerType) != m_modifier.m_miscvalue)
4671        return;
4672
4673    m_target->HandleStatModifier(UnitMods(UNIT_MOD_POWER_START + powerType), TOTAL_PCT, float(m_modifier.m_amount), apply);
4674}
4675
4676void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool Real)
4677{
4678    //m_target->ApplyMaxHealthPercentMod(m_modifier.m_amount,apply);
4679    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
4680}
4681
4682/********************************/
4683/***          FIGHT           ***/
4684/********************************/
4685
4686void Aura::HandleAuraModParryPercent(bool /*apply*/, bool Real)
4687{
4688    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4689        return;
4690
4691    ((Player*)m_target)->UpdateParryPercentage();
4692}
4693
4694void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool Real)
4695{
4696    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4697        return;
4698
4699    ((Player*)m_target)->UpdateDodgePercentage();
4700    //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
4701}
4702
4703void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool Real)
4704{
4705    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4706        return;
4707
4708    ((Player*)m_target)->UpdateBlockPercentage();
4709    //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
4710}
4711
4712void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real)
4713{
4714    // spells required only Real aura add/remove
4715    if(!Real)
4716        return;
4717
4718    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4719        return;
4720
4721    ((Player*)m_target)->UpdateManaRegen();
4722}
4723
4724void Aura::HandleAuraModCritPercent(bool apply, bool Real)
4725{
4726    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4727        return;
4728
4729    // apply item specific bonuses for already equipped weapon
4730    if(Real)
4731    {
4732        for(int i = 0; i < MAX_ATTACK; ++i)
4733            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4734                ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem,WeaponAttackType(i),this,apply);
4735    }
4736
4737    // mods must be applied base at equipped weapon class and subclass comparison
4738    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
4739    // m_modifier.m_miscvalue comparison with item generated damage types
4740
4741    if (GetSpellProto()->EquippedItemClass == -1)
4742    {
4743        ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE,         FLAT_MOD, float (m_modifier.m_amount), apply);
4744        ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
4745        ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE,  FLAT_MOD, float (m_modifier.m_amount), apply);
4746    }
4747    else
4748    {
4749        // done in Player::_ApplyWeaponDependentAuraMods
4750    }
4751}
4752
4753void Aura::HandleModHitChance(bool apply, bool Real)
4754{
4755    m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
4756    m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
4757}
4758
4759void Aura::HandleModSpellHitChance(bool apply, bool Real)
4760{
4761    m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
4762}
4763
4764void Aura::HandleModSpellCritChance(bool apply, bool Real)
4765{
4766    // spells required only Real aura add/remove
4767    if(!Real)
4768        return;
4769
4770    if(m_target->GetTypeId() == TYPEID_PLAYER)
4771    {
4772        ((Player*)m_target)->UpdateAllSpellCritChances();
4773    }
4774    else
4775    {
4776        m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
4777    }
4778}
4779
4780void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real)
4781{
4782    // spells required only Real aura add/remove
4783    if(!Real)
4784        return;
4785
4786    if(m_target->GetTypeId() != TYPEID_PLAYER)
4787        return;
4788
4789    for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
4790        if (m_modifier.m_miscvalue & (1<<school))
4791            ((Player*)m_target)->UpdateSpellCritChance(school);
4792}
4793
4794/********************************/
4795/***         ATTACK SPEED     ***/
4796/********************************/
4797
4798void Aura::HandleModCastingSpeed(bool apply, bool Real)
4799{
4800    m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
4801}
4802
4803void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool Real)
4804{
4805    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4806    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,m_modifier.m_amount,apply);
4807    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4808}
4809
4810void Aura::HandleModCombatSpeedPct(bool apply, bool Real)
4811{
4812    m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
4813    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4814    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,m_modifier.m_amount,apply);
4815    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4816}
4817
4818void Aura::HandleModAttackSpeed(bool apply, bool Real)
4819{
4820    if(!m_target->isAlive() )
4821        return;
4822
4823    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4824}
4825
4826void Aura::HandleHaste(bool apply, bool Real)
4827{
4828    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,  m_modifier.m_amount,apply);
4829    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,   m_modifier.m_amount,apply);
4830    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount,apply);
4831}
4832
4833void Aura::HandleAuraModRangedHaste(bool apply, bool Real)
4834{
4835    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4836}
4837
4838void Aura::HandleRangedAmmoHaste(bool apply, bool Real)
4839{
4840    if(m_target->GetTypeId() != TYPEID_PLAYER)
4841        return;
4842    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
4843}
4844
4845/********************************/
4846/***        ATTACK POWER      ***/
4847/********************************/
4848
4849void Aura::HandleAuraModAttackPower(bool apply, bool Real)
4850{
4851    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4852}
4853
4854void Aura::HandleAuraModRangedAttackPower(bool apply, bool Real)
4855{
4856    if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4857        return;
4858
4859    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4860}
4861
4862void Aura::HandleAuraModAttackPowerPercent(bool apply, bool Real)
4863{
4864    //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
4865    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
4866}
4867
4868void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool Real)
4869{
4870    if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4871        return;
4872
4873    //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
4874    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
4875}
4876
4877void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool apply, bool Real)
4878{
4879    // spells required only Real aura add/remove
4880    if(!Real)
4881        return;
4882
4883    if(m_target->GetTypeId() == TYPEID_PLAYER && (m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4884        return;
4885
4886    if(m_modifier.m_miscvalue != STAT_INTELLECT)
4887    {
4888        // support required adding UpdateAttackPowerAndDamage calls at stat update
4889        sLog.outError("Aura SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT (212) need support non-intellect stats!");
4890        return;
4891    }
4892
4893    // Recalculate bonus
4894    ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
4895}
4896
4897/********************************/
4898/***        DAMAGE BONUS      ***/
4899/********************************/
4900void Aura::HandleModDamageDone(bool apply, bool Real)
4901{
4902    // apply item specific bonuses for already equipped weapon
4903    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
4904    {
4905        for(int i = 0; i < MAX_ATTACK; ++i)
4906            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4907                ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply);
4908    }
4909
4910    // m_modifier.m_miscvalue is bitmask of spell schools
4911    // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
4912    // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
4913    // 127 - full bitmask any damages
4914    //
4915    // mods must be applied base at equipped weapon class and subclass comparison
4916    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
4917    // m_modifier.m_miscvalue comparison with item generated damage types
4918
4919    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
4920    {
4921        // apply generic physical damage bonuses including wand case
4922        if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
4923        {
4924            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4925            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4926            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4927        }
4928        else
4929        {
4930            // done in Player::_ApplyWeaponDependentAuraMods
4931        }
4932
4933        if(m_target->GetTypeId() == TYPEID_PLAYER)
4934        {
4935            if(m_positive)
4936                m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS,m_modifier.m_amount,apply);
4937            else
4938                m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG,m_modifier.m_amount,apply);
4939        }
4940    }
4941
4942    // Skip non magic case for speedup
4943    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
4944        return;
4945
4946    if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
4947    {
4948        // wand magic case (skip generic to all item spell bonuses)
4949        // done in Player::_ApplyWeaponDependentAuraMods
4950
4951        // Skip item specific requirements for not wand magic damage
4952        return;
4953    }
4954
4955    // Magic damage modifiers implemented in Unit::SpellDamageBonus
4956    // This information for client side use only
4957    if(m_target->GetTypeId() == TYPEID_PLAYER)
4958    {
4959        if(m_positive)
4960        {
4961            for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; i++)
4962            {
4963                if((m_modifier.m_miscvalue & (1<<i)) != 0)
4964                    m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS+i,m_modifier.m_amount,apply);
4965            }
4966        }
4967        else
4968        {
4969            for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; i++)
4970            {
4971                if((m_modifier.m_miscvalue & (1<<i)) != 0)
4972                    m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG+i,m_modifier.m_amount,apply);
4973            }
4974        }
4975        Pet* pet = m_target->GetPet();
4976        if(pet)
4977            pet->UpdateAttackPowerAndDamage();
4978    }
4979}
4980
4981void Aura::HandleModDamagePercentDone(bool apply, bool Real)
4982{
4983    sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
4984
4985    // apply item specific bonuses for already equipped weapon
4986    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
4987    {
4988        for(int i = 0; i < MAX_ATTACK; ++i)
4989            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4990                ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply);
4991    }
4992
4993    // m_modifier.m_miscvalue is bitmask of spell schools
4994    // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
4995    // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
4996    // 127 - full bitmask any damages
4997    //
4998    // mods must be applied base at equipped weapon class and subclass comparison
4999    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5000    // m_modifier.m_miscvalue comparison with item generated damage types
5001
5002    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5003    {
5004        // apply generic physical damage bonuses including wand case
5005        if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5006        {
5007            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5008            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5009            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5010        }
5011        else
5012        {
5013            // done in Player::_ApplyWeaponDependentAuraMods
5014        }
5015        // For show in client
5016        if(m_target->GetTypeId() == TYPEID_PLAYER)
5017            m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT,m_modifier.m_amount/100.0f,apply);
5018    }
5019
5020    // Skip non magic case for speedup
5021    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5022        return;
5023
5024    if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5025    {
5026        // wand magic case (skip generic to all item spell bonuses)
5027        // done in Player::_ApplyWeaponDependentAuraMods
5028
5029        // Skip item specific requirements for not wand magic damage
5030        return;
5031    }
5032
5033    // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5034    // Send info to client
5035    if(m_target->GetTypeId() == TYPEID_PLAYER)
5036        for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5037            m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT+i,m_modifier.m_amount/100.0f,apply);
5038}
5039
5040void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5041{
5042    // spells required only Real aura add/remove
5043    if(!Real)
5044        return;
5045
5046    sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5047
5048    m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5049}
5050
5051/********************************/
5052/***        POWER COST        ***/
5053/********************************/
5054
5055void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5056{
5057    // spells required only Real aura add/remove
5058    if(!Real)
5059        return;
5060
5061    float amount = m_modifier.m_amount/100.0f;
5062    for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5063        if(m_modifier.m_miscvalue & (1<<i))
5064            m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+i,amount,apply);
5065}
5066
5067void Aura::HandleModPowerCost(bool apply, bool Real)
5068{
5069    // spells required only Real aura add/remove
5070    if(!Real)
5071        return;
5072
5073    for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5074        if(m_modifier.m_miscvalue & (1<<i))
5075            m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER+i,m_modifier.m_amount,apply);
5076}
5077
5078/*********************************************************/
5079/***                    OTHERS                         ***/
5080/*********************************************************/
5081
5082void Aura::HandleShapeshiftBoosts(bool apply)
5083{
5084    uint32 spellId = 0;
5085    uint32 spellId2 = 0;
5086    uint32 HotWSpellId = 0;
5087
5088    switch(GetModifier()->m_miscvalue)
5089    {
5090        case FORM_CAT:
5091            spellId = 3025;
5092            HotWSpellId = 24900;
5093            break;
5094        case FORM_TREE:
5095            spellId = 5420;
5096            break;
5097        case FORM_TRAVEL:
5098            spellId = 5419;
5099            break;
5100        case FORM_AQUA:
5101            spellId = 5421;
5102            break;
5103        case FORM_BEAR:
5104            spellId = 1178;
5105            spellId2 = 21178;
5106            HotWSpellId = 24899;
5107            break;
5108        case FORM_DIREBEAR:
5109            spellId = 9635;
5110            spellId2 = 21178;
5111            HotWSpellId = 24899;
5112            break;
5113        case FORM_BATTLESTANCE:
5114            spellId = 21156;
5115            break;
5116        case FORM_DEFENSIVESTANCE:
5117            spellId = 7376;
5118            break;
5119        case FORM_BERSERKERSTANCE:
5120            spellId = 7381;
5121            break;
5122        case FORM_MOONKIN:
5123            spellId = 24905;
5124            // aura from effect trigger spell
5125            spellId2 = 24907;
5126            break;
5127        case FORM_FLIGHT:
5128            spellId = 33948;
5129            break;
5130        case FORM_FLIGHT_EPIC:
5131            spellId  = 40122;
5132            spellId2 = 40121;
5133            break;
5134        case FORM_SPIRITOFREDEMPTION:
5135            spellId  = 27792;
5136            spellId2 = 27795;                               // must be second, this important at aura remove to prevent to early iterator invalidation.
5137            break;
5138        case FORM_GHOSTWOLF:
5139        case FORM_AMBIENT:
5140        case FORM_GHOUL:
5141        case FORM_SHADOW:
5142        case FORM_STEALTH:
5143        case FORM_CREATURECAT:
5144        case FORM_CREATUREBEAR:
5145            spellId = 0;
5146            break;
5147    }
5148
5149    uint32 form = GetModifier()->m_miscvalue-1;
5150
5151    if(apply)
5152    {
5153        if (spellId) m_target->CastSpell(m_target, spellId, true, NULL, this );
5154        if (spellId2) m_target->CastSpell(m_target, spellId2, true, NULL, this);
5155
5156        if(m_target->GetTypeId() == TYPEID_PLAYER)
5157        {
5158            const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5159            for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5160            {
5161                if(itr->second->state == PLAYERSPELL_REMOVED) continue;
5162                if(itr->first==spellId || itr->first==spellId2) continue;
5163                SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5164                if (!spellInfo || !(spellInfo->Attributes & ((1<<6) | (1<<7)))) continue;
5165                if (spellInfo->Stances & (1<<form))
5166                    m_target->CastSpell(m_target, itr->first, true, NULL, this);
5167            }
5168            //LotP
5169            if (((Player*)m_target)->HasSpell(17007))
5170            {
5171                SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5172                if (spellInfo && spellInfo->Stances & (1<<form))
5173                    m_target->CastSpell(m_target, 24932, true, NULL, this);
5174            }
5175            // HotW
5176            if (HotWSpellId)
5177            {
5178                Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5179                for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5180                {
5181                    if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5182                    {
5183                        int32 HotWMod = (*i)->GetModifier()->m_amount;
5184                        if(GetModifier()->m_miscvalue == FORM_CAT)
5185                            HotWMod /= 2;
5186
5187                        m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5188                        break;
5189                    }
5190                }
5191            }
5192        }
5193    }
5194    else
5195    {
5196        m_target->RemoveAurasDueToSpell(spellId);
5197        m_target->RemoveAurasDueToSpell(spellId2);
5198
5199        Unit::AuraMap& tAuras = m_target->GetAuras();
5200        for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5201        {
5202            if (itr->second->IsRemovedOnShapeLost())
5203            {
5204                m_target->RemoveAurasDueToSpell(itr->second->GetId());
5205                itr = tAuras.begin();
5206            }
5207            else
5208            {
5209                ++itr;
5210            }
5211        }
5212    }
5213
5214    /*double healthPercentage = (double)m_target->GetHealth() / (double)m_target->GetMaxHealth();
5215    m_target->SetHealth(uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage)));*/
5216}
5217
5218void Aura::HandleAuraEmpathy(bool apply, bool Real)
5219{
5220    if(m_target->GetTypeId() != TYPEID_UNIT)
5221        return;
5222
5223    CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5224    if(ci && ci->type == CREATURE_TYPE_BEAST)
5225        m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5226}
5227
5228void Aura::HandleAuraUntrackable(bool apply, bool Real)
5229{
5230    if(apply)
5231        m_target->SetFlag(UNIT_FIELD_BYTES_1, PLAYER_STATE_FLAG_UNTRACKABLE);
5232    else
5233        m_target->RemoveFlag(UNIT_FIELD_BYTES_1, PLAYER_STATE_FLAG_UNTRACKABLE);
5234}
5235
5236void Aura::HandleAuraModPacify(bool apply, bool Real)
5237{
5238    if(m_target->GetTypeId() != TYPEID_PLAYER)
5239        return;
5240
5241    if(apply)
5242        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5243    else
5244        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5245}
5246
5247void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5248{
5249    HandleAuraModPacify(apply,Real);
5250    HandleAuraModSilence(apply,Real);
5251}
5252
5253void Aura::HandleAuraGhost(bool apply, bool Real)
5254{
5255    if(m_target->GetTypeId() != TYPEID_PLAYER)
5256        return;
5257
5258    if(apply)
5259    {
5260        m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5261    }
5262    else
5263    {
5264        m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5265    }
5266}
5267
5268void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5269{
5270    // all applied/removed only at real aura add/remove
5271    if(!Real)
5272        return;
5273
5274    // allow fly
5275    WorldPacket data;
5276    if(apply)
5277        data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5278    else
5279        data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5280    data.append(m_target->GetPackGUID());
5281    data << uint32(0);                                      // unk
5282    m_target->SendMessageToSet(&data, true);
5283}
5284
5285void Aura::HandleModRating(bool apply, bool Real)
5286{
5287    // spells required only Real aura add/remove
5288    if(!Real)
5289        return;
5290
5291    if(m_target->GetTypeId() != TYPEID_PLAYER)
5292        return;
5293
5294    for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5295        if (m_modifier.m_miscvalue & (1 << rating))
5296            ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5297}
5298
5299void Aura::HandleForceMoveForward(bool apply, bool Real)
5300{
5301    if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5302        return;
5303    if(apply)
5304        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5305    else
5306        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5307}
5308
5309void Aura::HandleAuraModExpertise(bool /*apply*/, bool Real)
5310{
5311    if(m_target->GetTypeId() != TYPEID_PLAYER)
5312        return;
5313
5314    ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5315    ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5316}
5317
5318void Aura::HandleModTargetResistance(bool apply, bool Real)
5319{
5320    // spells required only Real aura add/remove
5321    if(!Real)
5322        return;
5323    // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
5324
5325    // show armor penetration
5326    if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
5327        m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE,m_modifier.m_amount, apply);
5328
5329    // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
5330    if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
5331        m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE,m_modifier.m_amount, apply);
5332}
5333
5334void Aura::HandleShieldBlockValue(bool apply, bool Real)
5335{
5336    BaseModType modType = FLAT_MOD;
5337    if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
5338        modType = PCT_MOD;
5339
5340    if(m_target->GetTypeId() == TYPEID_PLAYER)
5341        ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
5342}
5343
5344void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
5345{
5346    // spells required only Real aura add/remove
5347    if(!Real)
5348        return;
5349
5350    if(m_target->GetTypeId() != TYPEID_PLAYER)
5351        return;
5352
5353    Player *target = (Player*)m_target;
5354
5355    // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
5356    // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
5357    if( !apply && m_duration==0 && target->GetComboTarget())
5358        if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
5359            target->AddComboPoints(unit, -m_modifier.m_amount);
5360}
5361
5362void Aura::HandleModUnattackable( bool Apply, bool Real )
5363{
5364    if(Real && Apply)
5365    {
5366        m_target->CombatStop();
5367        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
5368    }
5369
5370    m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
5371}
5372
5373void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
5374{
5375    // spells required only Real aura add/remove
5376    if(!Real)
5377        return;
5378
5379    // prepare spirit state
5380    if(apply)
5381    {
5382        if(m_target->GetTypeId()==TYPEID_PLAYER)
5383        {
5384            // disable breath/etc timers
5385            ((Player*)m_target)->StopMirrorTimers();
5386
5387            // set stand state (expected in this form)
5388            if(!m_target->IsStandState())
5389                m_target->SetStandState(PLAYER_STATE_NONE);
5390        }
5391
5392        m_target->SetHealth(1);
5393    }
5394    // die at aura end
5395    else
5396        m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
5397}
5398
5399void Aura::CleanupTriggeredSpells()
5400{
5401    uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
5402    if(!tSpellId)
5403        return;
5404
5405    SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
5406    if(!tProto)
5407        return;
5408
5409    if(GetSpellDuration(tProto) != -1)
5410        return;
5411
5412    // needed for spell 43680, maybe others
5413    // TODO: is there a spell flag, which can solve this in a more sophisticated way?
5414    if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
5415            GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
5416        return;
5417    m_target->RemoveAurasDueToSpell(tSpellId);
5418}
5419
5420void Aura::HandleAuraPowerBurn(bool apply, bool Real)
5421{
5422    if (m_periodicTimer <= 0)
5423        m_periodicTimer += m_modifier.periodictime;
5424
5425    m_isPeriodic = apply;
5426}
5427
5428void Aura::HandleSchoolAbsorb(bool apply, bool Real)
5429{
5430    if(!Real)
5431        return;
5432
5433    // prevent double apply bonuses
5434    if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
5435    {
5436        if(Unit* caster = GetCaster())
5437        {
5438            float DoneActualBenefit = 0.0f;
5439            switch(m_spellProto->SpellFamilyName)
5440            {
5441                case SPELLFAMILY_PRIEST:
5442                    if(m_spellProto->SpellFamilyFlags == 0x1) //PW:S
5443                    {
5444                        //+30% from +healing bonus
5445                        DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.3f;
5446                        break;
5447                    }
5448                    break;
5449                case SPELLFAMILY_MAGE:
5450                    if(m_spellProto->SpellFamilyFlags == 0x80100 || m_spellProto->SpellFamilyFlags == 0x8 || m_spellProto->SpellFamilyFlags == 0x100000000LL)
5451                    {
5452                        //frost ward, fire ward, ice barrier
5453                        //+10% from +spd bonus
5454                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
5455                        break;
5456                    }
5457                    break;
5458                case SPELLFAMILY_WARLOCK:
5459                    if(m_spellProto->SpellFamilyFlags == 0x00)
5460                    {
5461                        //shadow ward
5462                        //+10% from +spd bonus
5463                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
5464                        break;
5465                    }
5466                    break;
5467                default:
5468                    break;
5469            }
5470
5471            DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
5472
5473            m_modifier.m_amount += (int32)DoneActualBenefit;
5474        }
5475    }
5476}
5477
5478void Aura::PeriodicTick()
5479{
5480    if(!m_target->isAlive())
5481        return;
5482
5483    switch(m_modifier.m_auraname)
5484    {
5485        case SPELL_AURA_PERIODIC_DAMAGE:
5486        case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
5487        {
5488            Unit *pCaster = GetCaster();
5489            if(!pCaster)
5490                return;
5491
5492            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5493                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5494                return;
5495
5496            // Check for immune (not use charges)
5497            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5498                return;
5499
5500            // some auras remove at specific health level or more
5501            if(m_modifier.m_auraname==SPELL_AURA_PERIODIC_DAMAGE)
5502            {
5503                switch(GetId())
5504                {
5505                    case 43093: case 31956: case 38801:
5506                    case 35321: case 38363: case 39215:
5507                        if(m_target->GetHealth() == m_target->GetMaxHealth() )
5508                        {
5509                            m_target->RemoveAurasDueToSpell(GetId());
5510                            return;
5511                        }
5512                        break;
5513                    case 38772:
5514                    {
5515                        uint32 percent =
5516                            GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_DUMMY ?
5517                            pCaster->CalculateSpellDamage(GetSpellProto(),GetEffIndex()+1,GetSpellProto()->EffectBasePoints[GetEffIndex()+1],m_target) :
5518                            100;
5519                        if(m_target->GetHealth()*100 >= m_target->GetMaxHealth()*percent )
5520                        {
5521                            m_target->RemoveAurasDueToSpell(GetId());
5522                            return;
5523                        }
5524                        break;
5525                    }
5526                    case 41337:// aura of anger
5527                    {                       
5528                        Unit::AuraList const& mMod = m_target->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE);
5529                        for(Unit::AuraList::const_iterator i = mMod.begin(); i != mMod.end(); ++i)
5530                        {
5531                            if ((*i)->GetId() == 41337)
5532                            {
5533                                (*i)->ApplyModifier(false);
5534                                (*i)->GetModifier()->m_amount += 5;
5535                                (*i)->ApplyModifier(true);
5536                                break;
5537                            }
5538                        }                       
5539                        m_modifier.m_amount += 100;
5540                    }break;
5541                    default:
5542                        break;
5543                }
5544            }
5545
5546            uint32 absorb=0;
5547            uint32 resist=0;
5548            CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5549
5550            // ignore non positive values (can be result apply spellmods to aura damage
5551            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5552
5553            uint32 pdamage;
5554
5555            if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
5556            {
5557                pdamage = amount;
5558
5559                // Calculate armor mitigation if it is a physical spell
5560                // But not for bleed mechanic spells
5561                if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
5562                     GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
5563                {
5564                    uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
5565                    cleanDamage.damage += pdamage - pdamageReductedArmor;
5566                    pdamage = pdamageReductedArmor;
5567                }
5568
5569                pdamage = pCaster->SpellDamageBonus(m_target,GetSpellProto(),pdamage,DOT);
5570
5571                // Curse of Agony damage-per-tick calculation
5572                if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x0000000000000400LL) && GetSpellProto()->SpellIconID==544)
5573                {
5574                    // 1..4 ticks, 1/2 from normal tick damage
5575                    if (m_duration>=((m_maxduration-m_modifier.periodictime)*2/3))
5576                        pdamage = pdamage/2;
5577                    // 9..12 ticks, 3/2 from normal tick damage
5578                    else if(m_duration<((m_maxduration-m_modifier.periodictime)/3))
5579                        pdamage += (pdamage+1)/2;           // +1 prevent 0.5 damage possible lost at 1..4 ticks
5580                    // 5..8 ticks have normal tick damage
5581                }
5582            }
5583            else
5584                pdamage = uint32(m_target->GetMaxHealth()*amount/100);
5585
5586            //As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
5587            // Reduce dot damage from resilience for players
5588            if (m_target->GetTypeId()==TYPEID_PLAYER)
5589                pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
5590
5591            pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
5592
5593            sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
5594                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
5595
5596            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5597            data.append(m_target->GetPackGUID());
5598            data.appendPackGUID(GetCasterGUID());
5599            data << uint32(GetId());
5600            data << uint32(1);
5601            data << uint32(m_modifier.m_auraname);
5602            data << (uint32)pdamage;
5603            data << (uint32)GetSpellSchoolMask(GetSpellProto()); // will be mask in 2.4.x
5604            data << (uint32)absorb;
5605            data << (uint32)resist;
5606            m_target->SendMessageToSet(&data,true);
5607
5608            Unit* target = m_target;                        // aura can be deleted in DealDamage
5609            SpellEntry const* spellProto = GetSpellProto();
5610
5611            pCaster->DealDamage(m_target, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
5612
5613            // DO NOT ACCESS MEMBERS OF THE AURA FROM NOW ON (DealDamage can delete aura)
5614
5615            pCaster->ProcDamageAndSpell(target, PROC_FLAG_NONE, PROC_FLAG_TAKE_DAMAGE, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), GetSpellSchoolMask(spellProto), spellProto);
5616            break;
5617        }
5618        case SPELL_AURA_PERIODIC_LEECH:
5619        {
5620            Unit *pCaster = GetCaster();
5621            if(!pCaster)
5622                return;
5623
5624            if(!pCaster->isAlive())
5625                return;
5626
5627            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5628                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5629                return;
5630
5631            // Check for immune (not use charges)
5632            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5633                return;
5634
5635            uint32 absorb=0;
5636            uint32 resist=0;
5637            CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5638
5639            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5640
5641            //Calculate armor mitigation if it is a physical spell
5642            if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
5643            {
5644                uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
5645                cleanDamage.damage += pdamage - pdamageReductedArmor;
5646                pdamage = pdamageReductedArmor;
5647            }
5648
5649            pdamage = pCaster->SpellDamageBonus(m_target,GetSpellProto(),pdamage,DOT);
5650
5651            // talent Soul Siphon add bonus to Drain Life spells
5652            if( GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x8) )
5653            {
5654                // find talent max bonus percentage
5655                Unit::AuraList const& mClassScriptAuras = pCaster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
5656                for(Unit::AuraList::const_iterator i = mClassScriptAuras.begin(); i != mClassScriptAuras.end(); ++i)
5657                {
5658                    if ((*i)->GetModifier()->m_miscvalue == 4992 || (*i)->GetModifier()->m_miscvalue == 4993)
5659                    {
5660                        if((*i)->GetEffIndex()!=1)
5661                        {
5662                            sLog.outError("Expected spell %u structure change, need code update",(*i)->GetId());
5663                            break;
5664                        }
5665
5666                        // effect 1 m_amount
5667                        int32 maxPercent = (*i)->GetModifier()->m_amount;
5668                        // effect 0 m_amount
5669                        int32 stepPercent = pCaster->CalculateSpellDamage((*i)->GetSpellProto(),0,(*i)->GetSpellProto()->EffectBasePoints[0],pCaster);
5670
5671                        // count affliction effects and calc additional damage in percentage
5672                        int32 modPercent = 0;
5673                        Unit::AuraMap const& victimAuras = m_target->GetAuras();
5674                        for (Unit::AuraMap::const_iterator itr = victimAuras.begin(); itr != victimAuras.end(); ++itr)
5675                        {
5676                            Aura* aura = itr->second;
5677                            if (aura->IsPositive())continue;
5678                            SpellEntry const* m_spell = aura->GetSpellProto();
5679                            if (m_spell->SpellFamilyName != SPELLFAMILY_WARLOCK)
5680                                continue;
5681
5682                            SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(m_spell->Id);
5683                            SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(m_spell->Id);
5684
5685                            for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
5686                            {
5687                                if(_spell_idx->second->skillId == SKILL_AFFLICTION)
5688                                {
5689                                    modPercent += stepPercent;
5690                                    if (modPercent >= maxPercent)
5691                                    {
5692                                        modPercent = maxPercent;
5693                                        break;
5694                                    }
5695                                }
5696                            }
5697                        }
5698                        pdamage += (pdamage*modPercent/100);
5699                        break;
5700                    }
5701                }
5702            }
5703
5704            //As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
5705            // Reduce dot damage from resilience for players
5706            if (m_target->GetTypeId()==TYPEID_PLAYER)
5707                pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
5708
5709            pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
5710
5711            if(m_target->GetHealth() < pdamage)
5712                pdamage = uint32(m_target->GetHealth());
5713
5714            sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
5715                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
5716
5717            pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
5718
5719
5720            Unit* target = m_target;                        // aura can be deleted in DealDamage
5721            SpellEntry const* spellProto = GetSpellProto();
5722            float multiplier = spellProto->EffectMultipleValue[GetEffIndex()] > 0 ? spellProto->EffectMultipleValue[GetEffIndex()] : 1;
5723
5724            uint32 new_damage = pCaster->DealDamage(m_target, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
5725
5726            // DO NOT ACCESS MEMBERS OF THE AURA FROM NOW ON (DealDamage can delete aura)
5727
5728            pCaster->ProcDamageAndSpell(target, PROC_FLAG_HEALED, PROC_FLAG_TAKE_DAMAGE, new_damage, GetSpellSchoolMask(spellProto), spellProto);
5729            if (!target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
5730            {
5731                for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++)
5732                {
5733                    if (pCaster->m_currentSpells[i] && pCaster->m_currentSpells[i]->m_spellInfo->Id == spellProto->Id)
5734                        pCaster->m_currentSpells[i]->cancel();
5735                }
5736            }
5737
5738
5739            if(Player *modOwner = pCaster->GetSpellModOwner())
5740                modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
5741
5742            uint32 heal = pCaster->SpellHealingBonus(spellProto, uint32(new_damage * multiplier), DOT, pCaster);
5743
5744            int32 gain = pCaster->ModifyHealth(heal);
5745            pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, spellProto);
5746
5747            pCaster->SendHealSpellLog(pCaster, spellProto->Id, heal);
5748            break;
5749        }
5750        case SPELL_AURA_PERIODIC_HEAL:
5751        case SPELL_AURA_OBS_MOD_HEALTH:
5752        {
5753            Unit *pCaster = GetCaster();
5754            if(!pCaster)
5755                return;
5756
5757            // heal for caster damage (must be alive)
5758            if(m_target != pCaster && GetSpellProto()->SpellVisual==163 && !pCaster->isAlive())
5759                return;
5760
5761            // ignore non positive values (can be result apply spellmods to aura damage
5762            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5763
5764            uint32 pdamage;
5765
5766            if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
5767                pdamage = uint32(m_target->GetMaxHealth() * amount/100);
5768            else
5769                pdamage = amount;
5770
5771            pdamage = pCaster->SpellHealingBonus(GetSpellProto(), pdamage, DOT, m_target);
5772
5773            sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
5774                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5775
5776            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5777            data.append(m_target->GetPackGUID());
5778            data.appendPackGUID(GetCasterGUID());
5779            data << uint32(GetId());
5780            data << uint32(1);
5781            data << uint32(m_modifier.m_auraname);
5782            data << (uint32)pdamage;
5783            m_target->SendMessageToSet(&data,true);
5784
5785            int32 gain = m_target->ModifyHealth(pdamage);
5786
5787            // add HoTs to amount healed in bgs
5788            if( pCaster->GetTypeId() == TYPEID_PLAYER )
5789                if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
5790                    bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
5791
5792            //Do check before because m_modifier.auraName can be invalidate by DealDamage.
5793            bool procSpell = (m_modifier.m_auraname == SPELL_AURA_PERIODIC_HEAL && m_target != pCaster);
5794
5795            m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5796
5797            Unit* target = m_target;                        // aura can be deleted in DealDamage
5798            SpellEntry const* spellProto = GetSpellProto();
5799            bool haveCastItem = GetCastItemGUID()!=0;
5800
5801            // heal for caster damage
5802            if(m_target!=pCaster && spellProto->SpellVisual==163)
5803            {
5804                uint32 dmg = spellProto->manaPerSecond;
5805                if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
5806                {
5807                    pCaster->RemoveAurasDueToSpell(GetId());
5808
5809                    // finish current generic/channeling spells, don't affect autorepeat
5810                    if(pCaster->m_currentSpells[CURRENT_GENERIC_SPELL])
5811                    {
5812                        pCaster->m_currentSpells[CURRENT_GENERIC_SPELL]->finish();
5813                    }
5814                    if(pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL])
5815                    {
5816                        pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL]->SendChannelUpdate(0);
5817                        pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL]->finish();
5818                    }
5819                }
5820                else
5821                {
5822                    pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), gain, GetSpellSchoolMask(GetSpellProto()), 0, 0, false, 0, false);
5823
5824                    CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5825                    pCaster->DealDamage(pCaster, gain, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
5826                }
5827            }
5828
5829            // ignore item heals
5830            if(procSpell && !haveCastItem)
5831                pCaster->ProcDamageAndSpell(target,PROC_FLAG_NONE, PROC_FLAG_HEALED, pdamage, SPELL_SCHOOL_MASK_NONE, spellProto);
5832            break;
5833        }
5834        case SPELL_AURA_PERIODIC_MANA_LEECH:
5835        {
5836            Unit *pCaster = GetCaster();
5837            if(!pCaster)
5838                return;
5839
5840            if(!pCaster->isAlive())
5841                return;
5842
5843            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5844                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5845                return;
5846
5847            // Check for immune (not use charges)
5848            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5849                return;
5850
5851            // ignore non positive values (can be result apply spellmods to aura damage
5852            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5853
5854            sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
5855                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5856
5857            if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue > 4)
5858                break;
5859
5860            Powers power = Powers(m_modifier.m_miscvalue);
5861
5862            // power type might have changed between aura applying and tick (druid's shapeshift)
5863            if(m_target->getPowerType() != power)
5864                break;
5865
5866            int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
5867
5868            // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
5869            if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
5870                drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
5871
5872            m_target->ModifyPower(power, -drain_amount);
5873
5874            float gain_multiplier = 0;
5875
5876            if(pCaster->GetMaxPower(power) > 0)
5877            {
5878                gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
5879
5880                if(Player *modOwner = pCaster->GetSpellModOwner())
5881                    modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
5882            }
5883
5884            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5885            data.append(m_target->GetPackGUID());
5886            data.appendPackGUID(GetCasterGUID());
5887            data << uint32(GetId());
5888            data << uint32(1);
5889            data << uint32(m_modifier.m_auraname);
5890            data << (uint32)power;                          // power type
5891            data << (uint32)drain_amount;
5892            data << (float)gain_multiplier;
5893            m_target->SendMessageToSet(&data,true);
5894
5895            int32 gain_amount = int32(drain_amount*gain_multiplier);
5896
5897            if(gain_amount)
5898            {
5899                int32 gain = pCaster->ModifyPower(power,gain_amount);
5900                m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
5901            }
5902            break;
5903        }
5904        case SPELL_AURA_PERIODIC_ENERGIZE:
5905        {
5906            // ignore non positive values (can be result apply spellmods to aura damage
5907            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5908
5909            sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
5910                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5911
5912            if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue > 4)
5913                break;
5914
5915            Powers power = Powers(m_modifier.m_miscvalue);
5916
5917            if(m_target->GetMaxPower(power) == 0)
5918                break;
5919
5920            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5921            data.append(m_target->GetPackGUID());
5922            data.appendPackGUID(GetCasterGUID());
5923            data << uint32(GetId());
5924            data << uint32(1);
5925            data << uint32(m_modifier.m_auraname);
5926            data << (uint32)power;                          // power type
5927            data << (uint32)pdamage;
5928            m_target->SendMessageToSet(&data,true);
5929
5930            int32 gain = m_target->ModifyPower(power,pdamage);
5931
5932            if(Unit* pCaster = GetCaster())
5933                m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5934            break;
5935        }
5936        case SPELL_AURA_OBS_MOD_MANA:
5937        {
5938            // ignore non positive values (can be result apply spellmods to aura damage
5939            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5940
5941            uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount/100);
5942
5943            sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
5944                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5945
5946            if(m_target->GetMaxPower(POWER_MANA) == 0)
5947                break;
5948
5949            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5950            data.append(m_target->GetPackGUID());
5951            data.appendPackGUID(GetCasterGUID());
5952            data << uint32(GetId());
5953            data << uint32(1);
5954            data << uint32(m_modifier.m_auraname);
5955            data << (uint32)0;                              // ?
5956            data << (uint32)pdamage;
5957            m_target->SendMessageToSet(&data,true);
5958
5959            int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
5960
5961            if(Unit* pCaster = GetCaster())
5962                m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5963            break;
5964        }
5965        case SPELL_AURA_POWER_BURN_MANA:
5966        {
5967            Unit *pCaster = GetCaster();
5968            if(!pCaster)
5969                return;
5970
5971            // Check for immune (not use charges)
5972            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5973                return;
5974
5975            int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5976
5977            Powers powerType = Powers(m_modifier.m_miscvalue);
5978
5979            if(!m_target->isAlive() || m_target->getPowerType() != powerType)
5980                return;
5981
5982            // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
5983            if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
5984                pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
5985
5986            uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
5987
5988            gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
5989
5990            //maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
5991            pCaster->SpellNonMeleeDamageLog(m_target, GetId(), gain);
5992            break;
5993        }
5994        // Here tick dummy auras
5995        case SPELL_AURA_PERIODIC_DUMMY:
5996        {
5997            PeriodicDummyTick();
5998            break;
5999        }
6000        default:
6001            break;
6002    }
6003}
6004
6005void Aura::PeriodicDummyTick()
6006{
6007    SpellEntry const* spell = GetSpellProto();
6008    switch (spell->Id)
6009    {
6010        // Drink
6011        case 430:
6012        case 431:
6013        case 432:
6014        case 1133:
6015        case 1135:
6016        case 1137:
6017        case 10250:
6018        case 22734:
6019        case 27089:
6020        case 34291:
6021        case 43706:
6022        case 46755:
6023        {
6024            if (m_target->GetTypeId() != TYPEID_PLAYER)
6025                return;
6026            // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6027            Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6028            for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6029            {
6030                if ((*i)->GetId() == GetId())
6031                {
6032                    // Get tick number
6033                    int32 tick = (m_maxduration - m_duration) / m_modifier.periodictime;
6034                    // Default case (not on arenas)
6035                    if (tick == 0)
6036                    {
6037                        (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6038                        ((Player*)m_target)->UpdateManaRegen();
6039                        // Disable continue
6040                        m_isPeriodic = false;
6041                    }
6042                    return;
6043                    //**********************************************
6044                    // Code commended since arena patch not added
6045                    // This feature uses only in arenas
6046                    //**********************************************
6047                    // Here need increase mana regen per tick (6 second rule)
6048                    // on 0 tick -   0  (handled in 2 second)
6049                    // on 1 tick - 166% (handled in 4 second)
6050                    // on 2 tick - 133% (handled in 6 second)
6051                    // Not need update after 3 tick
6052                    /*
6053                    if (tick > 3)
6054                        return;
6055                    // Apply bonus for 0 - 3 tick
6056                    switch (tick)
6057                    {
6058                        case 0:   // 0%
6059                            (*i)->GetModifier()->m_amount = m_modifier.m_amount = 0;
6060                            break;
6061                        case 1:   // 166%
6062                            (*i)->GetModifier()->m_amount = m_modifier.m_amount * 5 / 3;
6063                            break;
6064                        case 2:   // 133%
6065                            (*i)->GetModifier()->m_amount = m_modifier.m_amount * 4 / 3;
6066                            break;
6067                        default:  // 100% - normal regen
6068                            (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6069                            break;
6070                    }
6071                    ((Player*)m_target)->UpdateManaRegen();
6072                    return;*/
6073                }
6074            }
6075            return;
6076        }
6077//        // Panda
6078//        case 19230: break;
6079//        // Master of Subtlety
6080//        case 31666: break;
6081//        // Gossip NPC Periodic - Talk
6082//        case 33208: break;
6083//        // Gossip NPC Periodic - Despawn
6084//        case 33209: break;
6085//        // Force of Nature
6086//        case 33831: break;
6087        // Aspect of the Viper
6088        case 34074:
6089        {
6090            if (m_target->GetTypeId() != TYPEID_PLAYER)
6091                return;
6092            // Should be manauser
6093            if (m_target->getPowerType()!=POWER_MANA)
6094                return;
6095            Unit *caster = GetCaster();
6096            if (!caster)
6097                return;
6098            // Regen amount is max (100% from spell) on 21% or less mana and min on 92.5% or greater mana (20% from spell)
6099            int mana = m_target->GetPower(POWER_MANA);
6100            int max_mana = m_target->GetMaxPower(POWER_MANA);
6101            int32 base_regen = caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, m_target);
6102            float regen_pct = 1.20f - 1.1f * mana / max_mana;
6103            if      (regen_pct > 1.0f) regen_pct = 1.0f;
6104            else if (regen_pct < 0.2f) regen_pct = 0.2f;
6105            m_modifier.m_amount = int32 (base_regen * regen_pct);
6106            ((Player*)m_target)->UpdateManaRegen();
6107            return;
6108        }
6109//        // Steal Weapon
6110//        case 36207: break;
6111//        // Simon Game START timer, (DND)
6112//        case 39993: break;
6113//        // Harpooner's Mark
6114//        case 40084: break;
6115//        // Knockdown Fel Cannon: break; The Aggro Burst
6116//        case 40119: break;
6117//        // Old Mount Spell
6118//        case 40154: break;
6119//        // Magnetic Pull
6120//        case 40581: break;
6121//        // Ethereal Ring: break; The Bolt Burst
6122//        case 40801: break;
6123//        // Crystal Prison
6124//        case 40846: break;
6125//        // Copy Weapon
6126//        case 41054: break;
6127//        // Ethereal Ring Visual, Lightning Aura
6128//        case 41477: break;
6129//        // Ethereal Ring Visual, Lightning Aura (Fork)
6130//        case 41525: break;
6131//        // Ethereal Ring Visual, Lightning Jumper Aura
6132//        case 41567: break;
6133//        // No Man's Land
6134//        case 41955: break;
6135//        // Headless Horseman - Fire
6136//        case 42074: break;
6137//        // Headless Horseman - Visual - Large Fire
6138//        case 42075: break;
6139//        // Headless Horseman - Start Fire, Periodic Aura
6140//        case 42140: break;
6141//        // Ram Speed Boost
6142//        case 42152: break;
6143//        // Headless Horseman - Fires Out Victory Aura
6144//        case 42235: break;
6145//        // Pumpkin Life Cycle
6146//        case 42280: break;
6147//        // Brewfest Request Chick Chuck Mug Aura
6148//        case 42537: break;
6149//        // Squashling
6150//        case 42596: break;
6151//        // Headless Horseman Climax, Head: Periodic
6152//        case 42603: break;
6153//        // Fire Bomb
6154//        case 42621: break;
6155//        // Headless Horseman - Conflagrate, Periodic Aura
6156//        case 42637: break;
6157//        // Headless Horseman - Create Pumpkin Treats Aura
6158//        case 42774: break;
6159//        // Headless Horseman Climax - Summoning Rhyme Aura
6160//        case 42879: break;
6161//        // Tricky Treat
6162//        case 42919: break;
6163//        // Giddyup!
6164//        case 42924: break;
6165//        // Ram - Trot
6166//        case 42992: break;
6167//        // Ram - Canter
6168//        case 42993: break;
6169//        // Ram - Gallop
6170//        case 42994: break;
6171//        // Ram Level - Neutral
6172//        case 43310: break;
6173//        // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6174//        case 43884: break;
6175//        // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6176//        case 44000: break;
6177//        // Energy Feedback
6178//        case 44328: break;
6179//        // Romantic Picnic
6180//        case 45102: break;
6181//        // Romantic Picnic
6182//        case 45123: break;
6183//        // Looking for Love
6184//        case 45124: break;
6185//        // Kite - Lightning Strike Kite Aura
6186//        case 45197: break;
6187//        // Rocket Chicken
6188//        case 45202: break;
6189//        // Copy Offhand Weapon
6190//        case 45205: break;
6191//        // Upper Deck - Kite - Lightning Periodic Aura
6192//        case 45207: break;
6193//        // Kite -Sky  Lightning Strike Kite Aura
6194//        case 45251: break;
6195//        // Ribbon Pole Dancer Check Aura
6196//        case 45390: break;
6197//        // Holiday - Midsummer, Ribbon Pole Periodic Visual
6198//        case 45406: break;
6199//        // Parachute
6200//        case 45472: break;
6201//        // Alliance Flag, Extra Damage Debuff
6202//        case 45898: break;
6203//        // Horde Flag, Extra Damage Debuff
6204//        case 45899: break;
6205//        // Ahune - Summoning Rhyme Aura
6206//        case 45926: break;
6207//        // Ahune - Slippery Floor
6208//        case 45945: break;
6209//        // Ahune's Shield
6210//        case 45954: break;
6211//        // Nether Vapor Lightning
6212//        case 45960: break;
6213//        // Darkness
6214//        case 45996: break;
6215//        // Summon Blood Elves Periodic
6216//        case 46041: break;
6217//        // Transform Visual Missile Periodic
6218//        case 46205: break;
6219//        // Find Opening Beam End
6220//        case 46333: break;
6221//        // Ice Spear Control Aura
6222//        case 46371: break;
6223//        // Hailstone Chill
6224//        case 46458: break;
6225//        // Hailstone Chill, Internal
6226//        case 46465: break;
6227//        // Chill, Internal Shifter
6228//        case 46549: break;
6229//        // Summon Ice Spear Knockback Delayer
6230//        case 46878: break;
6231//        // Burninate Effect
6232//        case 47214: break;
6233//        // Fizzcrank Practice Parachute
6234//        case 47228: break;
6235//        // Send Mug Control Aura
6236//        case 47369: break;
6237//        // Direbrew's Disarm (precast)
6238//        case 47407: break;
6239//        // Mole Machine Port Schedule
6240//        case 47489: break;
6241//        // Mole Machine Portal Schedule
6242//        case 49466: break;
6243//        // Drink Coffee
6244//        case 49472: break;
6245//        // Listening to Music
6246//        case 50493: break;
6247//        // Love Rocket Barrage
6248//        case 50530: break;
6249        default:
6250            break;
6251    }
6252}
6253
6254void Aura::HandlePreventFleeing(bool apply, bool Real)
6255{
6256    if(!Real)
6257        return;
6258
6259    Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
6260    if( !fearAuras.empty() )
6261    {
6262        if (apply)
6263            m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
6264        else
6265            m_target->SetFeared(true);
6266    }
6267}
6268
6269void Aura::HandleManaShield(bool apply, bool Real)
6270{
6271    if(!Real)
6272        return;
6273
6274    // prevent double apply bonuses
6275    if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
6276    {
6277        if(Unit* caster = GetCaster())
6278        {
6279            float DoneActualBenefit = 0.0f;
6280            switch(m_spellProto->SpellFamilyName)
6281            {
6282                case SPELLFAMILY_MAGE:
6283                    if(m_spellProto->SpellFamilyFlags & 0x8000)
6284                    {
6285                        // Mana Shield
6286                        // +50% from +spd bonus
6287                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
6288                        break;
6289                    }
6290                    break;
6291                default:
6292                    break;
6293            }
6294
6295            DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6296
6297            m_modifier.m_amount += (int32)DoneActualBenefit;
6298        }
6299    }
6300}
6301
6302void Aura::HandleArenaPreparation(bool apply, bool Real)
6303{
6304    if(!Real)
6305        return;
6306
6307    if(apply)
6308        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
6309    else
6310        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
6311}
Note: See TracBrowser for help on using the browser.