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

Revision 289, 247.3 kB (checked in by yumileroy, 17 years ago)

Implemented mana cost for tonk spell 27746. (Note: speed increase still needs to be fixed)

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