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

Revision 207, 247.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Improve some arena team related DB access
* Cache GM tickets on server startup.
* Remove unused src/game/HateMatrix.h and references.
* Better check client inventory pos data received in some client packets to
skip invalid cases

Original author: KingPin?
Date: 2008-11-10 09:04:23-06:00

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