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

Revision 173, 248.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Avoid access to bag item prototype for getting bag size, use related item update field instead as more fast source.
* Better check client inventory pos data received in some client packets to skip invalid cases.
* Removed some unnecessary database queries.
* Make guid lookup for adding ignore async.
* Added two parameter versions of the AsyncQuery? function
* Make queries for adding friends async. - Hunuza
* Replace some PQuery() calls with more simple Query() - Hunuza
* Mark spell as executed instead of deleteable to solve crash.
*** Source mangos.

**Its a big commit. so test with care... or without care.... whatever floats your boat.

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