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

Revision 139, 249.6 kB (checked in by yumileroy, 17 years ago)

[svn] Spell target selection improvement. Remove most mangos hacks in spell target selection. (work almost done)
Merge mangos svn rev 6744.

Original author: megamage
Date: 2008-10-31 11:04:32-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "Common.h"
22#include "Database/DatabaseEnv.h"
23#include "WorldPacket.h"
24#include "WorldSession.h"
25#include "Opcodes.h"
26#include "Log.h"
27#include "UpdateMask.h"
28#include "World.h"
29#include "ObjectMgr.h"
30#include "SpellMgr.h"
31#include "Player.h"
32#include "Unit.h"
33#include "Spell.h"
34#include "SpellAuras.h"
35#include "DynamicObject.h"
36#include "Group.h"
37#include "UpdateData.h"
38#include "MapManager.h"
39#include "ObjectAccessor.h"
40#include "Policies/SingletonImp.h"
41#include "Totem.h"
42#include "Creature.h"
43#include "Formulas.h"
44#include "BattleGround.h"
45#include "OutdoorPvP.h"
46#include "OutdoorPvPMgr.h"
47#include "CreatureAI.h"
48#include "Util.h"
49#include "GridNotifiers.h"
50#include "GridNotifiersImpl.h"
51#include "CellImpl.h"
52
53#define NULL_AURA_SLOT 0xFF
54
55pAuraHandler AuraHandler[TOTAL_AURAS]=
56{
57    &Aura::HandleNULL,                                      //  0 SPELL_AURA_NONE
58    &Aura::HandleBindSight,                                 //  1 SPELL_AURA_BIND_SIGHT
59    &Aura::HandleModPossess,                                //  2 SPELL_AURA_MOD_POSSESS
60    &Aura::HandlePeriodicDamage,                            //  3 SPELL_AURA_PERIODIC_DAMAGE
61    &Aura::HandleAuraDummy,                                 //  4 SPELL_AURA_DUMMY
62    &Aura::HandleModConfuse,                                //  5 SPELL_AURA_MOD_CONFUSE
63    &Aura::HandleModCharm,                                  //  6 SPELL_AURA_MOD_CHARM
64    &Aura::HandleModFear,                                   //  7 SPELL_AURA_MOD_FEAR
65    &Aura::HandlePeriodicHeal,                              //  8 SPELL_AURA_PERIODIC_HEAL
66    &Aura::HandleModAttackSpeed,                            //  9 SPELL_AURA_MOD_ATTACKSPEED
67    &Aura::HandleModThreat,                                 // 10 SPELL_AURA_MOD_THREAT
68    &Aura::HandleModTaunt,                                  // 11 SPELL_AURA_MOD_TAUNT
69    &Aura::HandleAuraModStun,                               // 12 SPELL_AURA_MOD_STUN
70    &Aura::HandleModDamageDone,                             // 13 SPELL_AURA_MOD_DAMAGE_DONE
71    &Aura::HandleNoImmediateEffect,                         // 14 SPELL_AURA_MOD_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
72    &Aura::HandleNoImmediateEffect,                         // 15 SPELL_AURA_DAMAGE_SHIELD    implemented in Unit::DoAttackDamage
73    &Aura::HandleModStealth,                                // 16 SPELL_AURA_MOD_STEALTH
74    &Aura::HandleNoImmediateEffect,                         // 17 SPELL_AURA_MOD_STEALTH_DETECT
75    &Aura::HandleInvisibility,                              // 18 SPELL_AURA_MOD_INVISIBILITY
76    &Aura::HandleInvisibilityDetect,                        // 19 SPELL_AURA_MOD_INVISIBILITY_DETECTION
77    &Aura::HandleAuraModTotalHealthPercentRegen,            // 20 SPELL_AURA_OBS_MOD_HEALTH
78    &Aura::HandleAuraModTotalManaPercentRegen,              // 21 SPELL_AURA_OBS_MOD_MANA
79    &Aura::HandleAuraModResistance,                         // 22 SPELL_AURA_MOD_RESISTANCE
80    &Aura::HandlePeriodicTriggerSpell,                      // 23 SPELL_AURA_PERIODIC_TRIGGER_SPELL
81    &Aura::HandlePeriodicEnergize,                          // 24 SPELL_AURA_PERIODIC_ENERGIZE
82    &Aura::HandleAuraModPacify,                             // 25 SPELL_AURA_MOD_PACIFY
83    &Aura::HandleAuraModRoot,                               // 26 SPELL_AURA_MOD_ROOT
84    &Aura::HandleAuraModSilence,                            // 27 SPELL_AURA_MOD_SILENCE
85    &Aura::HandleNoImmediateEffect,                         // 28 SPELL_AURA_REFLECT_SPELLS        implement in Unit::SpellHitResult
86    &Aura::HandleAuraModStat,                               // 29 SPELL_AURA_MOD_STAT
87    &Aura::HandleAuraModSkill,                              // 30 SPELL_AURA_MOD_SKILL
88    &Aura::HandleAuraModIncreaseSpeed,                      // 31 SPELL_AURA_MOD_INCREASE_SPEED
89    &Aura::HandleAuraModIncreaseMountedSpeed,               // 32 SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
90    &Aura::HandleAuraModDecreaseSpeed,                      // 33 SPELL_AURA_MOD_DECREASE_SPEED
91    &Aura::HandleAuraModIncreaseHealth,                     // 34 SPELL_AURA_MOD_INCREASE_HEALTH
92    &Aura::HandleAuraModIncreaseEnergy,                     // 35 SPELL_AURA_MOD_INCREASE_ENERGY
93    &Aura::HandleAuraModShapeshift,                         // 36 SPELL_AURA_MOD_SHAPESHIFT
94    &Aura::HandleAuraModEffectImmunity,                     // 37 SPELL_AURA_EFFECT_IMMUNITY
95    &Aura::HandleAuraModStateImmunity,                      // 38 SPELL_AURA_STATE_IMMUNITY
96    &Aura::HandleAuraModSchoolImmunity,                     // 39 SPELL_AURA_SCHOOL_IMMUNITY
97    &Aura::HandleAuraModDmgImmunity,                        // 40 SPELL_AURA_DAMAGE_IMMUNITY
98    &Aura::HandleAuraModDispelImmunity,                     // 41 SPELL_AURA_DISPEL_IMMUNITY
99    &Aura::HandleAuraProcTriggerSpell,                      // 42 SPELL_AURA_PROC_TRIGGER_SPELL  implemented in Unit::ProcDamageAndSpellFor and Unit::HandleProcTriggerSpell
100    &Aura::HandleNoImmediateEffect,                         // 43 SPELL_AURA_PROC_TRIGGER_DAMAGE implemented in Unit::ProcDamageAndSpellFor
101    &Aura::HandleAuraTrackCreatures,                        // 44 SPELL_AURA_TRACK_CREATURES
102    &Aura::HandleAuraTrackResources,                        // 45 SPELL_AURA_TRACK_RESOURCES
103    &Aura::HandleUnused,                                    // 46 SPELL_AURA_MOD_PARRY_SKILL    obsolete?
104    &Aura::HandleAuraModParryPercent,                       // 47 SPELL_AURA_MOD_PARRY_PERCENT
105    &Aura::HandleUnused,                                    // 48 SPELL_AURA_MOD_DODGE_SKILL    obsolete?
106    &Aura::HandleAuraModDodgePercent,                       // 49 SPELL_AURA_MOD_DODGE_PERCENT
107    &Aura::HandleUnused,                                    // 50 SPELL_AURA_MOD_BLOCK_SKILL    obsolete?
108    &Aura::HandleAuraModBlockPercent,                       // 51 SPELL_AURA_MOD_BLOCK_PERCENT
109    &Aura::HandleAuraModCritPercent,                        // 52 SPELL_AURA_MOD_CRIT_PERCENT
110    &Aura::HandlePeriodicLeech,                             // 53 SPELL_AURA_PERIODIC_LEECH
111    &Aura::HandleModHitChance,                              // 54 SPELL_AURA_MOD_HIT_CHANCE
112    &Aura::HandleModSpellHitChance,                         // 55 SPELL_AURA_MOD_SPELL_HIT_CHANCE
113    &Aura::HandleAuraTransform,                             // 56 SPELL_AURA_TRANSFORM
114    &Aura::HandleModSpellCritChance,                        // 57 SPELL_AURA_MOD_SPELL_CRIT_CHANCE
115    &Aura::HandleAuraModIncreaseSwimSpeed,                  // 58 SPELL_AURA_MOD_INCREASE_SWIM_SPEED
116    &Aura::HandleNoImmediateEffect,                         // 59 SPELL_AURA_MOD_DAMAGE_DONE_CREATURE implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
117    &Aura::HandleAuraModPacifyAndSilence,                   // 60 SPELL_AURA_MOD_PACIFY_SILENCE
118    &Aura::HandleAuraModScale,                              // 61 SPELL_AURA_MOD_SCALE
119    &Aura::HandleNULL,                                      // 62 SPELL_AURA_PERIODIC_HEALTH_FUNNEL
120    &Aura::HandleUnused,                                    // 63 SPELL_AURA_PERIODIC_MANA_FUNNEL obsolete?
121    &Aura::HandlePeriodicManaLeech,                         // 64 SPELL_AURA_PERIODIC_MANA_LEECH
122    &Aura::HandleModCastingSpeed,                           // 65 SPELL_AURA_MOD_CASTING_SPEED
123    &Aura::HandleFeignDeath,                                // 66 SPELL_AURA_FEIGN_DEATH
124    &Aura::HandleAuraModDisarm,                             // 67 SPELL_AURA_MOD_DISARM
125    &Aura::HandleAuraModStalked,                            // 68 SPELL_AURA_MOD_STALKED
126    &Aura::HandleSchoolAbsorb,                              // 69 SPELL_AURA_SCHOOL_ABSORB implemented in Unit::CalcAbsorbResist
127    &Aura::HandleUnused,                                    // 70 SPELL_AURA_EXTRA_ATTACKS      Useless, used by only one spell that has only visual effect
128    &Aura::HandleModSpellCritChanceShool,                   // 71 SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
129    &Aura::HandleModPowerCostPCT,                           // 72 SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
130    &Aura::HandleModPowerCost,                              // 73 SPELL_AURA_MOD_POWER_COST_SCHOOL
131    &Aura::HandleNoImmediateEffect,                         // 74 SPELL_AURA_REFLECT_SPELLS_SCHOOL  implemented in Unit::SpellHitResult
132    &Aura::HandleNoImmediateEffect,                         // 75 SPELL_AURA_MOD_LANGUAGE
133    &Aura::HandleFarSight,                                  // 76 SPELL_AURA_FAR_SIGHT
134    &Aura::HandleModMechanicImmunity,                       // 77 SPELL_AURA_MECHANIC_IMMUNITY
135    &Aura::HandleAuraMounted,                               // 78 SPELL_AURA_MOUNTED
136    &Aura::HandleModDamagePercentDone,                      // 79 SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
137    &Aura::HandleModPercentStat,                            // 80 SPELL_AURA_MOD_PERCENT_STAT
138    &Aura::HandleNoImmediateEffect,                         // 81 SPELL_AURA_SPLIT_DAMAGE_PCT
139    &Aura::HandleWaterBreathing,                            // 82 SPELL_AURA_WATER_BREATHING
140    &Aura::HandleModBaseResistance,                         // 83 SPELL_AURA_MOD_BASE_RESISTANCE
141    &Aura::HandleModRegen,                                  // 84 SPELL_AURA_MOD_REGEN
142    &Aura::HandleModPowerRegen,                             // 85 SPELL_AURA_MOD_POWER_REGEN
143    &Aura::HandleChannelDeathItem,                          // 86 SPELL_AURA_CHANNEL_DEATH_ITEM
144    &Aura::HandleNoImmediateEffect,                         // 87 SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
145    &Aura::HandleNoImmediateEffect,                         // 88 SPELL_AURA_MOD_HEALTH_REGEN_PERCENT
146    &Aura::HandlePeriodicDamagePCT,                         // 89 SPELL_AURA_PERIODIC_DAMAGE_PERCENT
147    &Aura::HandleUnused,                                    // 90 SPELL_AURA_MOD_RESIST_CHANCE  Useless
148    &Aura::HandleNoImmediateEffect,                         // 91 SPELL_AURA_MOD_DETECT_RANGE implemented in Creature::GetAttackDistance
149    &Aura::HandlePreventFleeing,                            // 92 SPELL_AURA_PREVENTS_FLEEING
150    &Aura::HandleModUnattackable,                           // 93 SPELL_AURA_MOD_UNATTACKABLE
151    &Aura::HandleNoImmediateEffect,                         // 94 SPELL_AURA_INTERRUPT_REGEN implemented in Player::RegenerateAll
152    &Aura::HandleAuraGhost,                                 // 95 SPELL_AURA_GHOST
153    &Aura::HandleNoImmediateEffect,                         // 96 SPELL_AURA_SPELL_MAGNET implemented in Spell::SelectMagnetTarget
154    &Aura::HandleManaShield,                                // 97 SPELL_AURA_MANA_SHIELD implemented in Unit::CalcAbsorbResist
155    &Aura::HandleAuraModSkill,                              // 98 SPELL_AURA_MOD_SKILL_TALENT
156    &Aura::HandleAuraModAttackPower,                        // 99 SPELL_AURA_MOD_ATTACK_POWER
157    &Aura::HandleUnused,                                    //100 SPELL_AURA_AURAS_VISIBLE obsolete? all player can see all auras now
158    &Aura::HandleModResistancePercent,                      //101 SPELL_AURA_MOD_RESISTANCE_PCT
159    &Aura::HandleNoImmediateEffect,                         //102 SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
160    &Aura::HandleAuraModTotalThreat,                        //103 SPELL_AURA_MOD_TOTAL_THREAT
161    &Aura::HandleAuraWaterWalk,                             //104 SPELL_AURA_WATER_WALK
162    &Aura::HandleAuraFeatherFall,                           //105 SPELL_AURA_FEATHER_FALL
163    &Aura::HandleAuraHover,                                 //106 SPELL_AURA_HOVER
164    &Aura::HandleAddModifier,                               //107 SPELL_AURA_ADD_FLAT_MODIFIER
165    &Aura::HandleAddModifier,                               //108 SPELL_AURA_ADD_PCT_MODIFIER
166    &Aura::HandleNoImmediateEffect,                         //109 SPELL_AURA_ADD_TARGET_TRIGGER
167    &Aura::HandleModPowerRegenPCT,                          //110 SPELL_AURA_MOD_POWER_REGEN_PERCENT
168    &Aura::HandleNULL,                                      //111 SPELL_AURA_ADD_CASTER_HIT_TRIGGER
169    &Aura::HandleNoImmediateEffect,                         //112 SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
170    &Aura::HandleNoImmediateEffect,                         //113 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
171    &Aura::HandleNoImmediateEffect,                         //114 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
172    &Aura::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    // All ok cast by default case
1884    Spell *spell = new Spell(m_target, triggredSpellInfo, true, originalCasterGUID );
1885
1886    SpellCastTargets targets;
1887    targets.setUnitTarget( target );
1888
1889    // if spell create dynamic object extract area from it
1890    if(DynamicObject* dynObj = caster->GetDynObject(GetId()))
1891        targets.setDestination(dynObj->GetPositionX(),dynObj->GetPositionY(),dynObj->GetPositionZ());
1892
1893    spell->prepare(&targets, this);
1894}
1895
1896/*********************************************************/
1897/***                  AURA EFFECTS                     ***/
1898/*********************************************************/
1899
1900void Aura::HandleAuraDummy(bool apply, bool Real)
1901{
1902    // spells required only Real aura add/remove
1903    if(!Real)
1904        return;
1905
1906    Unit* caster = GetCaster();
1907
1908    // AT APPLY
1909    if(apply)
1910    {
1911        switch(GetId())
1912        {
1913            case 1515:                                      // Tame beast
1914                // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
1915                if( caster && m_target->CanHaveThreatList())
1916                    m_target->AddThreat(caster, 10.0f);
1917                return;
1918            case 13139:                                     // net-o-matic
1919                // root to self part of (root_target->charge->root_self sequence
1920                if(caster)
1921                    caster->CastSpell(caster,13138,true,NULL,this);
1922                return;
1923            case 39850:                                     // Rocket Blast
1924                if(roll_chance_i(20))                       // backfire stun
1925                    m_target->CastSpell(m_target, 51581, true, NULL, this);
1926                return;
1927            case 43873:                                     // Headless Horseman Laugh
1928                if(caster->GetTypeId() == TYPEID_PLAYER)
1929                    ((Player*)caster)->SendPlaySound(11965, false);
1930                return;
1931            case 46354:                                     // Blood Elf Illusion
1932                if(caster)
1933                {
1934                    switch(caster->getGender())
1935                    {
1936                        case GENDER_FEMALE:
1937                            caster->CastSpell(m_target,46356,true,NULL,this);
1938                            break;
1939                        case GENDER_MALE:
1940                            caster->CastSpell(m_target,46355,true,NULL,this);
1941                            break;
1942                        default:
1943                            break;
1944                    }
1945                }
1946                return;
1947            case 46699:                                     // Requires No Ammo
1948                if(m_target->GetTypeId()==TYPEID_PLAYER)
1949                    ((Player*)m_target)->RemoveAmmo();      // not use ammo and not allow use
1950                return;
1951        }
1952
1953        // Earth Shield
1954        if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & 0x40000000000LL))
1955        {
1956            // prevent double apply bonuses
1957            if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
1958                m_modifier.m_amount = caster->SpellHealingBonus(GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE, m_target);
1959            return;
1960        }
1961    }
1962    // AT REMOVE
1963    else
1964    {
1965        if( m_target->GetTypeId() == TYPEID_PLAYER &&
1966            ( GetSpellProto()->Effect[0]==72 || GetSpellProto()->Effect[0]==6 &&
1967            ( GetSpellProto()->EffectApplyAuraName[0]==1 || GetSpellProto()->EffectApplyAuraName[0]==128 ) ) )
1968        {
1969            // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
1970            m_target->SetUInt64Value(PLAYER_FARSIGHT, 0);
1971            WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0);
1972            ((Player*)m_target)->GetSession()->SendPacket(&data);
1973            return;
1974        }
1975
1976        if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
1977        {
1978            uint32 finalSpelId = 0;
1979            switch(GetId())
1980            {
1981                case 19548: finalSpelId = 19597; break;
1982                case 19674: finalSpelId = 19677; break;
1983                case 19687: finalSpelId = 19676; break;
1984                case 19688: finalSpelId = 19678; break;
1985                case 19689: finalSpelId = 19679; break;
1986                case 19692: finalSpelId = 19680; break;
1987                case 19693: finalSpelId = 19684; break;
1988                case 19694: finalSpelId = 19681; break;
1989                case 19696: finalSpelId = 19682; break;
1990                case 19697: finalSpelId = 19683; break;
1991                case 19699: finalSpelId = 19685; break;
1992                case 19700: finalSpelId = 19686; break;
1993                case 30646: finalSpelId = 30647; break;
1994                case 30653: finalSpelId = 30648; break;
1995                case 30654: finalSpelId = 30652; break;
1996                case 30099: finalSpelId = 30100; break;
1997                case 30102: finalSpelId = 30103; break;
1998                case 30105: finalSpelId = 30104; break;
1999            }
2000
2001            if(finalSpelId)
2002                caster->CastSpell(m_target,finalSpelId,true,NULL,this);
2003            return;
2004        }
2005        // Dark Fiend
2006        if(GetId()==45934)
2007        {
2008            // Kill target if dispeled
2009            if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2010                m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2011            return;
2012        }
2013
2014        // Burning Winds
2015        if(GetId()==46308)                                  // casted only at creatures at spawn
2016        {
2017            m_target->CastSpell(m_target,47287,true,NULL,this);
2018            return;
2019        }
2020    }
2021
2022    // AT APPLY & REMOVE
2023
2024    switch(m_spellProto->SpellFamilyName)
2025    {
2026        case SPELLFAMILY_GENERIC:
2027        {
2028            // Unstable Power
2029            if( GetId()==24658 )
2030            {
2031                uint32 spellId = 24659;
2032                if (apply)
2033                {
2034                    const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2035                    if (!spell)
2036                        return;
2037                    for (int i=0; i < spell->StackAmount; ++i)
2038                        caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2039                    return;
2040                }
2041                m_target->RemoveAurasDueToSpell(spellId);
2042                return;
2043            }
2044            // Restless Strength
2045            if( GetId()==24661 )
2046            {
2047                uint32 spellId = 24662;
2048                if (apply)
2049                {
2050                    const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2051                    if (!spell)
2052                        return;
2053                    for (int i=0; i < spell->StackAmount; ++i)
2054                        caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2055                    return;
2056                }
2057                m_target->RemoveAurasDueToSpell(spellId);
2058                return;
2059            }
2060            // Victorious
2061            if(GetId()==32216 && m_target->getClass()==CLASS_WARRIOR)
2062            {
2063                m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, apply);
2064                return;
2065            }
2066            //Summon Fire Elemental
2067            if (GetId() == 40133 && caster)
2068            {
2069                Unit *owner = caster->GetOwner();
2070                if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2071                {
2072                    if(apply)
2073                        owner->CastSpell(owner,8985,true);
2074                    else
2075                        ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2076                }
2077                return;
2078            }
2079
2080            //Summon Earth Elemental
2081            if (GetId() == 40132 && caster)
2082            {
2083                Unit *owner = caster->GetOwner();
2084                if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2085                {
2086                    if(apply)
2087                        owner->CastSpell(owner,19704,true);
2088                    else
2089                        ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2090                }
2091                return;
2092            }
2093            break;
2094        }
2095        case SPELLFAMILY_MAGE:
2096        {
2097            // Hypothermia
2098            if( GetId()==41425 )
2099            {
2100                m_target->ModifyAuraState(AURA_STATE_HYPOTHERMIA,apply);
2101                return;
2102            }
2103            break;
2104        }
2105        case SPELLFAMILY_DRUID:
2106        {
2107            // Lifebloom
2108            if ( GetSpellProto()->SpellFamilyFlags & 0x1000000000LL )
2109            {
2110                if ( apply )
2111                {
2112                    if ( caster )
2113                        // prevent double apply bonuses
2114                        if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2115                            m_modifier.m_amount = caster->SpellHealingBonus(GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE, m_target);
2116                }
2117                else
2118                {
2119                    // Final heal only on dispelled or duration end
2120                    if ( !(GetAuraDuration() <= 0 || m_removeMode==AURA_REMOVE_BY_DISPEL) )
2121                        return;
2122
2123                    // have a look if there is still some other Lifebloom dummy aura
2124                    Unit::AuraList auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2125                    for(Unit::AuraList::iterator itr = auras.begin(); itr!=auras.end(); itr++)
2126                        if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2127                            (*itr)->GetSpellProto()->SpellFamilyFlags & 0x1000000000LL)
2128                            return;
2129
2130                    // final heal
2131                    m_target->CastCustomSpell(m_target,33778,&m_modifier.m_amount,NULL,NULL,true,NULL,this,GetCasterGUID());
2132                }
2133                return;
2134            }
2135
2136            // Predatory Strikes
2137            if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2138            {
2139                ((Player*)m_target)->UpdateAttackPowerAndDamage();
2140                return;
2141            }
2142            // Idol of the Emerald Queen
2143            if ( GetId() == 34246 && m_target->GetTypeId()==TYPEID_PLAYER )
2144            {
2145                if(apply)
2146                {
2147                    SpellModifier *mod = new SpellModifier;
2148                    mod->op = SPELLMOD_DOT;
2149                    mod->value = m_modifier.m_amount/7;
2150                    mod->type = SPELLMOD_FLAT;
2151                    mod->spellId = GetId();
2152                    mod->effectId = m_effIndex;
2153                    mod->lastAffected = NULL;
2154                    mod->mask = 0x001000000000LL;
2155                    mod->charges = 0;
2156
2157                    m_spellmod = mod;
2158                }
2159
2160                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2161                return;
2162            }
2163            break;
2164        }
2165        case SPELLFAMILY_HUNTER:
2166        {
2167            // Improved Aspect of the Viper
2168            if( GetId()==38390 && m_target->GetTypeId()==TYPEID_PLAYER )
2169            {
2170                if(apply)
2171                {
2172                    // + effect value for Aspect of the Viper
2173                    SpellModifier *mod = new SpellModifier;
2174                    mod->op = SPELLMOD_EFFECT1;
2175                    mod->value = m_modifier.m_amount;
2176                    mod->type = SPELLMOD_FLAT;
2177                    mod->spellId = GetId();
2178                    mod->effectId = m_effIndex;
2179                    mod->lastAffected = NULL;
2180                    mod->mask = 0x4000000000000LL;
2181                    mod->charges = 0;
2182
2183                    m_spellmod = mod;
2184                }
2185
2186                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2187                return;
2188            }
2189            break;
2190        }
2191        case SPELLFAMILY_SHAMAN:
2192        {
2193            // Improved Weapon Totems
2194            if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2195            {
2196                if(apply)
2197                {
2198                    SpellModifier *mod = new SpellModifier;
2199                    mod->op = SPELLMOD_EFFECT1;
2200                    mod->value = m_modifier.m_amount;
2201                    mod->type = SPELLMOD_PCT;
2202                    mod->spellId = GetId();
2203                    mod->effectId = m_effIndex;
2204                    mod->lastAffected = NULL;
2205                    switch (m_effIndex)
2206                    {
2207                        case 0:
2208                            mod->mask = 0x00200000000LL;    // Windfury Totem
2209                            break;
2210                        case 1:
2211                            mod->mask = 0x00400000000LL;    // Flametongue Totem
2212                            break;
2213                    }
2214                    mod->charges = 0;
2215
2216                    m_spellmod = mod;
2217                }
2218
2219                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2220                return;
2221            }
2222            break;
2223        }
2224    }
2225
2226    // pet auras
2227    if(PetAura const* petSpell = spellmgr.GetPetAura(GetId()))
2228    {
2229        if(apply)
2230            m_target->AddPetAura(petSpell);
2231        else
2232            m_target->RemovePetAura(petSpell);
2233        return;
2234    }
2235}
2236
2237void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
2238{
2239    // spells required only Real aura add/remove
2240    if(!Real)
2241        return;
2242
2243    SpellEntry const*spell = GetSpellProto();
2244    switch( spell->SpellFamilyName)
2245    {
2246        case SPELLFAMILY_ROGUE:
2247        {
2248            // Master of Subtlety
2249            if (spell->Id==31666 && !apply && Real)
2250            {
2251                m_target->RemoveAurasDueToSpell(31665);
2252                break;
2253            }
2254            break;
2255        }
2256        case SPELLFAMILY_HUNTER:
2257        {
2258            // Aspect of the Viper
2259            if (spell->SpellFamilyFlags&0x0004000000000000LL)
2260            {
2261                // Update regen on remove
2262                if (!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2263                    ((Player*)m_target)->UpdateManaRegen();
2264                break;
2265            }
2266            break;
2267        }
2268    }
2269
2270    m_isPeriodic = apply;
2271}
2272
2273void Aura::HandleAuraMounted(bool apply, bool Real)
2274{
2275    if(apply)
2276    {
2277        CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2278        if(!ci)
2279        {
2280            sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2281            return;
2282        }
2283
2284        uint32 team = 0;
2285        if (m_target->GetTypeId()==TYPEID_PLAYER)
2286            team = ((Player*)m_target)->GetTeam();
2287
2288        uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2289        CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2290        if (minfo)
2291            display_id = minfo->modelid;
2292
2293        m_target->Mount(display_id);
2294    }
2295    else
2296    {
2297        m_target->Unmount();
2298    }
2299}
2300
2301void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2302{
2303    // only at real add/remove aura
2304    if(!Real)
2305        return;
2306
2307    WorldPacket data;
2308    if(apply)
2309        data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2310    else
2311        data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2312    data.append(m_target->GetPackGUID());
2313    data << uint32(0);
2314    m_target->SendMessageToSet(&data,true);
2315}
2316
2317void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2318{
2319    // only at real add/remove aura
2320    if(!Real)
2321        return;
2322
2323    WorldPacket data;
2324    if(apply)
2325        data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2326    else
2327        data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2328    data.append(m_target->GetPackGUID());
2329    data << (uint32)0;
2330    m_target->SendMessageToSet(&data,true);
2331}
2332
2333void Aura::HandleAuraHover(bool apply, bool Real)
2334{
2335    // only at real add/remove aura
2336    if(!Real)
2337        return;
2338
2339    WorldPacket data;
2340    if(apply)
2341        data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2342    else
2343        data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2344    data.append(m_target->GetPackGUID());
2345    data << uint32(0);
2346    m_target->SendMessageToSet(&data,true);
2347}
2348
2349void Aura::HandleWaterBreathing(bool apply, bool Real)
2350{
2351    if(apply)
2352        m_target->waterbreath = true;
2353    else if(m_target->GetAurasByType(SPELL_AURA_WATER_BREATHING).empty())
2354    {
2355        m_target->waterbreath = false;
2356
2357        // update for enable timer in case not moving target
2358        if(m_target->GetTypeId()==TYPEID_PLAYER && m_target->IsInWorld())
2359        {
2360            ((Player*)m_target)->UpdateUnderwaterState(m_target->GetMap(),m_target->GetPositionX(),m_target->GetPositionY(),m_target->GetPositionZ());
2361            ((Player*)m_target)->HandleDrowning();
2362        }
2363    }
2364}
2365
2366void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2367{
2368    if(!Real)
2369        return;
2370
2371    uint32 modelid = 0;
2372    Powers PowerType = POWER_MANA;
2373    ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2374    switch(form)
2375    {
2376        case FORM_CAT:
2377            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2378                modelid = 892;
2379            else
2380                modelid = 8571;
2381            PowerType = POWER_ENERGY;
2382            break;
2383        case FORM_TRAVEL:
2384            modelid = 632;
2385            break;
2386        case FORM_AQUA:
2387            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2388                modelid = 2428;
2389            else
2390                modelid = 2428;
2391            break;
2392        case FORM_BEAR:
2393            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2394                modelid = 2281;
2395            else
2396                modelid = 2289;
2397            PowerType = POWER_RAGE;
2398            break;
2399        case FORM_GHOUL:
2400            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2401                modelid = 10045;
2402            break;
2403        case FORM_DIREBEAR:
2404            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2405                modelid = 2281;
2406            else
2407                modelid = 2289;
2408            PowerType = POWER_RAGE;
2409            break;
2410        case FORM_CREATUREBEAR:
2411            modelid = 902;
2412            break;
2413        case FORM_GHOSTWOLF:
2414            modelid = 4613;
2415            break;
2416        case FORM_FLIGHT:
2417            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2418                modelid = 20857;
2419            else
2420                modelid = 20872;
2421            break;
2422        case FORM_MOONKIN:
2423            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2424                modelid = 15374;
2425            else
2426                modelid = 15375;
2427            break;
2428        case FORM_FLIGHT_EPIC:
2429            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2430                modelid = 21243;
2431            else
2432                modelid = 21244;
2433            break;
2434        case FORM_AMBIENT:
2435        case FORM_SHADOW:
2436        case FORM_STEALTH:
2437            break;
2438        case FORM_TREE:
2439            modelid = 864;
2440            break;
2441        case FORM_BATTLESTANCE:
2442        case FORM_BERSERKERSTANCE:
2443        case FORM_DEFENSIVESTANCE:
2444            PowerType = POWER_RAGE;
2445            break;
2446        case FORM_SPIRITOFREDEMPTION:
2447            modelid = 16031;
2448            break;
2449        default:
2450            sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2451    }
2452
2453    // remove polymorph before changing display id to keep new display id
2454    switch ( form )
2455    {
2456        case FORM_CAT:
2457        case FORM_TREE:
2458        case FORM_TRAVEL:
2459        case FORM_AQUA:
2460        case FORM_BEAR:
2461        case FORM_DIREBEAR:
2462        case FORM_FLIGHT_EPIC:
2463        case FORM_FLIGHT:
2464        case FORM_MOONKIN:
2465            // remove movement affects
2466            m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2467            m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2468
2469            // and polymorphic affects
2470            if(m_target->IsPolymorphed())
2471                m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2472            break;
2473        default:
2474           break;
2475    }
2476
2477    if(apply)
2478    {
2479        // remove other shapeshift before applying a new one
2480        if(m_target->m_ShapeShiftFormSpellId)
2481            m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId,this);
2482
2483        m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2484
2485        if(modelid > 0)
2486            m_target->SetDisplayId(modelid);
2487
2488        if(PowerType != POWER_MANA)
2489        {
2490            // reset power to default values only at power change
2491            if(m_target->getPowerType()!=PowerType)
2492                m_target->setPowerType(PowerType);
2493
2494            switch(form)
2495            {
2496                case FORM_CAT:
2497                case FORM_BEAR:
2498                case FORM_DIREBEAR:
2499                {
2500                    // get furor proc chance
2501                    uint32 FurorChance = 0;
2502                    Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2503                    for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2504                    {
2505                        if ((*i)->GetSpellProto()->SpellIconID == 238)
2506                        {
2507                            FurorChance = (*i)->GetModifier()->m_amount;
2508                            break;
2509                        }
2510                    }
2511
2512                    if (m_modifier.m_miscvalue == FORM_CAT)
2513                    {
2514                        m_target->SetPower(POWER_ENERGY,0);
2515                        if(urand(1,100) <= FurorChance)
2516                            m_target->CastSpell(m_target,17099,true,NULL,this);
2517                    }
2518                    else
2519                    {
2520                        m_target->SetPower(POWER_RAGE,0);
2521                        if(urand(1,100) <= FurorChance)
2522                            m_target->CastSpell(m_target,17057,true,NULL,this);
2523                    }
2524                    break;
2525                }
2526                case FORM_BATTLESTANCE:
2527                case FORM_DEFENSIVESTANCE:
2528                case FORM_BERSERKERSTANCE:
2529                {
2530                    uint32 Rage_val = 0;
2531                    // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2532                    if(m_target->GetTypeId() == TYPEID_PLAYER)
2533                    {
2534                        PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2535                        for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2536                        {
2537                            if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2538                            SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2539                            if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2540                                Rage_val += m_target->CalculateSpellDamage(spellInfo,0,spellInfo->EffectBasePoints[0],m_target) * 10;
2541                        }
2542                    }
2543
2544                    if (m_target->GetPower(POWER_RAGE) > Rage_val)
2545                        m_target->SetPower(POWER_RAGE,Rage_val);
2546                    break;
2547                }
2548                default:
2549                    break;
2550            }
2551        }
2552
2553        m_target->m_ShapeShiftFormSpellId = GetId();
2554        m_target->m_form = form;
2555    }
2556    else
2557    {
2558        m_target->SetDisplayId(m_target->GetNativeDisplayId());
2559        m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2560        if(m_target->getClass() == CLASS_DRUID)
2561            m_target->setPowerType(POWER_MANA);
2562        m_target->m_ShapeShiftFormSpellId = 0;
2563        m_target->m_form = FORM_NONE;
2564
2565        switch(form)
2566        {
2567            // Nordrassil Harness - bonus
2568            case FORM_BEAR:
2569            case FORM_DIREBEAR:
2570            case FORM_CAT:
2571            {
2572                if(Aura* dummy = m_target->GetDummyAura(37315) )
2573                    m_target->CastSpell(m_target,37316,true,NULL,dummy);
2574                break;
2575            }
2576            // Nordrassil Regalia - bonus
2577            case FORM_MOONKIN:
2578            {
2579                if(Aura* dummy = m_target->GetDummyAura(37324) )
2580                    m_target->CastSpell(m_target,37325,true,NULL,dummy);
2581                break;
2582            }
2583        }
2584    }
2585
2586    // adding/removing linked auras
2587    // add/remove the shapeshift aura's boosts
2588    HandleShapeshiftBoosts(apply);
2589
2590    if(m_target->GetTypeId()==TYPEID_PLAYER)
2591        ((Player*)m_target)->InitDataForForm();
2592}
2593
2594void Aura::HandleAuraTransform(bool apply, bool Real)
2595{
2596    if (apply)
2597    {
2598        // special case (spell specific functionality)
2599        if(m_modifier.m_miscvalue==0)
2600        {
2601            // player applied only
2602            if(m_target->GetTypeId()!=TYPEID_PLAYER)
2603                return;
2604
2605            switch(GetId())
2606            {
2607                // Orb of Deception
2608                case 16739:
2609                {
2610                    uint32 orb_model = m_target->GetNativeDisplayId();
2611                    switch(orb_model)
2612                    {
2613                        // Troll Female
2614                        case 1479: m_target->SetDisplayId(10134); break;
2615                        // Troll Male
2616                        case 1478: m_target->SetDisplayId(10135); break;
2617                        // Tauren Male
2618                        case 59:   m_target->SetDisplayId(10136); break;
2619                        // Human Male
2620                        case 49:   m_target->SetDisplayId(10137); break;
2621                        // Human Female
2622                        case 50:   m_target->SetDisplayId(10138); break;
2623                        // Orc Male
2624                        case 51:   m_target->SetDisplayId(10139); break;
2625                        // Orc Female
2626                        case 52:   m_target->SetDisplayId(10140); break;
2627                        // Dwarf Male
2628                        case 53:   m_target->SetDisplayId(10141); break;
2629                        // Dwarf Female
2630                        case 54:   m_target->SetDisplayId(10142); break;
2631                        // NightElf Male
2632                        case 55:   m_target->SetDisplayId(10143); break;
2633                        // NightElf Female
2634                        case 56:   m_target->SetDisplayId(10144); break;
2635                        // Undead Female
2636                        case 58:   m_target->SetDisplayId(10145); break;
2637                        // Undead Male
2638                        case 57:   m_target->SetDisplayId(10146); break;
2639                        // Tauren Female
2640                        case 60:   m_target->SetDisplayId(10147); break;
2641                        // Gnome Male
2642                        case 1563: m_target->SetDisplayId(10148); break;
2643                        // Gnome Female
2644                        case 1564: m_target->SetDisplayId(10149); break;
2645                        // BloodElf Female
2646                        case 15475: m_target->SetDisplayId(17830); break;
2647                        // BloodElf Male
2648                        case 15476: m_target->SetDisplayId(17829); break;
2649                        // Dranei Female
2650                        case 16126: m_target->SetDisplayId(17828); break;
2651                        // Dranei Male
2652                        case 16125: m_target->SetDisplayId(17827); break;
2653                        default: break;
2654                    }
2655                    break;
2656                }
2657                // Murloc costume
2658                case 42365: m_target->SetDisplayId(21723); break;
2659                default: break;
2660            }
2661        }
2662        else
2663        {
2664            CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2665            if(!ci)
2666            {
2667                                                            //pig pink ^_^
2668                m_target->SetDisplayId(16358);
2669                sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
2670            }
2671            else
2672            {
2673                if (uint32 modelid = ci->GetRandomValidModelId()) m_target->SetDisplayId(modelid);
2674
2675                // Dragonmaw Illusion (set mount model also)
2676                if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
2677                    m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
2678            }
2679            m_target->setTransForm(GetId());
2680        }
2681
2682        // polymorph case
2683        if( Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
2684        {
2685            // for players, start regeneration after 1s (in polymorph fast regeneration case)
2686            // only if caster is Player (after patch 2.4.2)
2687            if(IS_PLAYER_GUID(GetCasterGUID()) )
2688                ((Player*)m_target)->setRegenTimer(1000);
2689
2690            //dismount polymorphed target (after patch 2.4.2)
2691            if (m_target->IsMounted())
2692                m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
2693        }
2694    }
2695    else
2696    {
2697        Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
2698        if(otherTransforms.empty())
2699        {
2700            m_target->SetDisplayId(m_target->GetNativeDisplayId());
2701            m_target->setTransForm(0);
2702        }
2703        else
2704        {
2705            // look for other transform auras
2706            Aura* handledAura = *otherTransforms.begin();
2707            for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
2708            {
2709                // negative auras are prefered
2710                if(!IsPositiveSpell((*i)->GetSpellProto()->Id))
2711                {
2712                    handledAura = *i;
2713                    break;
2714                }
2715            }
2716            handledAura->ApplyModifier(true);
2717        }
2718
2719        // Dragonmaw Illusion (restore mount model)
2720        if(GetId()==42016 && m_target->GetMountID()==16314)
2721        {
2722            if(!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
2723            {
2724                uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
2725                if(CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
2726                {
2727                    uint32 team = 0;
2728                    if (m_target->GetTypeId()==TYPEID_PLAYER)
2729                        team = ((Player*)m_target)->GetTeam();
2730
2731                    uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2732                    CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2733                    if (minfo)
2734                        display_id = minfo->modelid;
2735
2736                    m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,display_id);
2737                }
2738            }
2739        }
2740    }
2741}
2742
2743void Aura::HandleForceReaction(bool apply, bool Real)
2744{
2745    if(m_target->GetTypeId() != TYPEID_PLAYER)
2746        return;
2747
2748    if(!Real)
2749        return;
2750
2751    Player* player = (Player*)m_target;
2752
2753    uint32 faction_id = m_modifier.m_miscvalue;
2754    uint32 faction_rank = m_modifier.m_amount;
2755
2756    if(apply)
2757        player->m_forcedReactions[faction_id] = ReputationRank(faction_rank);
2758    else
2759        player->m_forcedReactions.erase(faction_id);
2760
2761    WorldPacket data;
2762    data.Initialize(SMSG_SET_FORCED_REACTIONS, 4+player->m_forcedReactions.size()*(4+4));
2763    data << uint32(player->m_forcedReactions.size());
2764    for(ForcedReactions::const_iterator itr = player->m_forcedReactions.begin(); itr != player->m_forcedReactions.end(); ++itr)
2765    {
2766        data << uint32(itr->first);                         // faction_id (Faction.dbc)
2767        data << uint32(itr->second);                        // reputation rank
2768    }
2769    player->SendDirectMessage(&data);
2770}
2771
2772void Aura::HandleAuraModSkill(bool apply, bool Real)
2773{
2774    if(m_target->GetTypeId() != TYPEID_PLAYER)
2775        return;
2776
2777    uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
2778    int32 points = GetModifier()->m_amount;
2779
2780    ((Player*)m_target)->ModifySkillBonus(prot,(apply ? points: -points),m_modifier.m_auraname==SPELL_AURA_MOD_SKILL_TALENT);
2781    if(prot == SKILL_DEFENSE)
2782        ((Player*)m_target)->UpdateDefenseBonusesMod();
2783}
2784
2785void Aura::HandleChannelDeathItem(bool apply, bool Real)
2786{
2787    if(Real && !apply)
2788    {
2789        Unit* caster = GetCaster();
2790        Unit* victim = GetTarget();
2791        if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode!=AURA_REMOVE_BY_DEATH)
2792            return;
2793
2794        SpellEntry const *spellInfo = GetSpellProto();
2795        if(spellInfo->EffectItemType[m_effIndex] == 0)
2796            return;
2797
2798        // Soul Shard only from non-grey units
2799        if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
2800            (victim->getLevel() <= Trinity::XP::GetGrayLevel(caster->getLevel()) ||
2801             victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
2802            return;
2803        ItemPosCountVec dest;
2804        uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], 1 );
2805        if( msg != EQUIP_ERR_OK )
2806        {
2807            ((Player*)caster)->SendEquipError( msg, NULL, NULL );
2808            return;
2809        }
2810
2811        Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
2812        ((Player*)caster)->SendNewItem(newitem, 1, true, false);
2813    }
2814}
2815
2816void Aura::HandleBindSight(bool apply, bool Real)
2817{
2818    Unit* caster = GetCaster();
2819    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2820        return;
2821
2822    caster->SetUInt64Value(PLAYER_FARSIGHT,apply ? m_target->GetGUID() : 0);
2823}
2824
2825void Aura::HandleFarSight(bool apply, bool Real)
2826{
2827    Unit* caster = GetCaster();
2828    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2829        return;
2830
2831    caster->SetUInt64Value(PLAYER_FARSIGHT,apply ? m_modifier.m_miscvalue : 0);
2832}
2833
2834void Aura::HandleAuraTrackCreatures(bool apply, bool Real)
2835{
2836    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2837        return;
2838
2839    if(apply)
2840        m_target->RemoveNoStackAurasDueToAura(this);
2841    m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
2842}
2843
2844void Aura::HandleAuraTrackResources(bool apply, bool Real)
2845{
2846    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2847        return;
2848
2849    if(apply)
2850        m_target->RemoveNoStackAurasDueToAura(this);
2851    m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
2852}
2853
2854void Aura::HandleAuraTrackStealthed(bool apply, bool Real)
2855{
2856    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2857        return;
2858
2859    if(apply)
2860        m_target->RemoveNoStackAurasDueToAura(this);
2861
2862    m_target->ApplyModFlag(PLAYER_FIELD_BYTES,PLAYER_FIELD_BYTE_TRACK_STEALTHED,apply);
2863}
2864
2865void Aura::HandleAuraModScale(bool apply, bool Real)
2866{
2867    m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X,m_modifier.m_amount,apply);
2868}
2869
2870void Aura::HandleModPossess(bool apply, bool Real)
2871{
2872    if(!Real)
2873        return;
2874
2875    if(m_target->getLevel() > m_modifier.m_amount)
2876        return;
2877
2878    // not possess yourself
2879    if(GetCasterGUID() == m_target->GetGUID())
2880        return;
2881
2882    Unit* caster = GetCaster();
2883    if(!caster)
2884        return;
2885
2886    if( apply )
2887    {
2888        m_target->SetCharmerGUID(GetCasterGUID());
2889        m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,caster->getFaction());
2890        caster->SetCharm(m_target);
2891
2892        m_target->CombatStop();
2893        m_target->DeleteThreatList();
2894        if(m_target->GetTypeId() == TYPEID_UNIT)
2895        {
2896            m_target->StopMoving();
2897            m_target->GetMotionMaster()->Clear();
2898            m_target->GetMotionMaster()->MoveIdle();
2899            CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target);
2900            charmInfo->InitPossessCreateSpells();
2901        }
2902
2903        if(caster->GetTypeId() == TYPEID_PLAYER)
2904        {
2905            ((Player*)caster)->PossessSpellInitialize();
2906        }
2907    }
2908    else
2909    {
2910        m_target->SetCharmerGUID(0);
2911
2912        if(m_target->GetTypeId() == TYPEID_PLAYER)
2913            ((Player*)m_target)->setFactionForRace(m_target->getRace());
2914
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->SetDeletable(true);
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    // Special case with temporary increase max/current health
4628    switch(GetId())
4629    {
4630        case 12976:                                         // Warrior Last Stand triggered spell
4631        case 28726:                                         // Nightmare Seed ( Nightmare Seed )
4632        case 34511:                                         // Valor (Bulwark of Kings, Bulwark of the Ancient Kings)
4633        case 44055:                                         // Tremendous Fortitude (Battlemaster's Alacrity)
4634        {
4635            if(Real)
4636            {
4637                if(apply)
4638                {
4639                    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4640                    m_target->ModifyHealth(m_modifier.m_amount);
4641                }
4642                else
4643                {
4644                    if (int32(m_target->GetHealth()) > m_modifier.m_amount)
4645                        m_target->ModifyHealth(-m_modifier.m_amount);
4646                    else
4647                        m_target->SetHealth(1);
4648                    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4649                }
4650            }
4651            return;
4652        }
4653    }
4654
4655    // generic case
4656    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4657}
4658
4659void  Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool Real)
4660{
4661    uint32 oldhealth = m_target->GetHealth();
4662    double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
4663
4664    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4665
4666    // refresh percentage
4667    if(oldhealth > 0)
4668    {
4669        uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
4670        if(newhealth==0)
4671            newhealth = 1;
4672
4673        m_target->SetHealth(newhealth);
4674    }
4675}
4676
4677void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
4678{
4679    Powers powerType = m_target->getPowerType();
4680    if(int32(powerType) != m_modifier.m_miscvalue)
4681        return;
4682
4683    m_target->HandleStatModifier(UnitMods(UNIT_MOD_POWER_START + powerType), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4684}
4685
4686void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool Real)
4687{
4688    Powers powerType = m_target->getPowerType();
4689    if(int32(powerType) != m_modifier.m_miscvalue)
4690        return;
4691
4692    m_target->HandleStatModifier(UnitMods(UNIT_MOD_POWER_START + powerType), TOTAL_PCT, float(m_modifier.m_amount), apply);
4693}
4694
4695void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool Real)
4696{
4697    //m_target->ApplyMaxHealthPercentMod(m_modifier.m_amount,apply);
4698    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
4699}
4700
4701/********************************/
4702/***          FIGHT           ***/
4703/********************************/
4704
4705void Aura::HandleAuraModParryPercent(bool apply, bool Real)
4706{
4707    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4708        return;
4709
4710    ((Player*)m_target)->UpdateParryPercentage();
4711}
4712
4713void Aura::HandleAuraModDodgePercent(bool apply, bool Real)
4714{
4715    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4716        return;
4717
4718    ((Player*)m_target)->UpdateDodgePercentage();
4719    //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
4720}
4721
4722void Aura::HandleAuraModBlockPercent(bool apply, bool Real)
4723{
4724    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4725        return;
4726
4727    ((Player*)m_target)->UpdateBlockPercentage();
4728    //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
4729}
4730
4731void Aura::HandleAuraModRegenInterrupt(bool apply, bool Real)
4732{
4733    // spells required only Real aura add/remove
4734    if(!Real)
4735        return;
4736
4737    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4738        return;
4739
4740    ((Player*)m_target)->UpdateManaRegen();
4741}
4742
4743void Aura::HandleAuraModCritPercent(bool apply, bool Real)
4744{
4745    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4746        return;
4747
4748    // apply item specific bonuses for already equipped weapon
4749    if(Real)
4750    {
4751        for(int i = 0; i < MAX_ATTACK; ++i)
4752            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4753                ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem,WeaponAttackType(i),this,apply);
4754    }
4755
4756    // mods must be applied base at equipped weapon class and subclass comparison
4757    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
4758    // m_modifier.m_miscvalue comparison with item generated damage types
4759
4760    if (GetSpellProto()->EquippedItemClass == -1)
4761    {
4762        ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE,         FLAT_MOD, float (m_modifier.m_amount), apply);
4763        ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
4764        ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE,  FLAT_MOD, float (m_modifier.m_amount), apply);
4765    }
4766    else
4767    {
4768        // done in Player::_ApplyWeaponDependentAuraMods
4769    }
4770}
4771
4772void Aura::HandleModHitChance(bool apply, bool Real)
4773{
4774    m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
4775    m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
4776}
4777
4778void Aura::HandleModSpellHitChance(bool apply, bool Real)
4779{
4780    m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
4781}
4782
4783void Aura::HandleModSpellCritChance(bool apply, bool Real)
4784{
4785    // spells required only Real aura add/remove
4786    if(!Real)
4787        return;
4788
4789    if(m_target->GetTypeId() == TYPEID_PLAYER)
4790    {
4791        ((Player*)m_target)->UpdateAllSpellCritChances();
4792    }
4793    else
4794    {
4795        m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
4796    }
4797}
4798
4799void Aura::HandleModSpellCritChanceShool(bool apply, bool Real)
4800{
4801    // spells required only Real aura add/remove
4802    if(!Real)
4803        return;
4804
4805    if(m_target->GetTypeId() != TYPEID_PLAYER)
4806        return;
4807
4808    for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
4809        if (m_modifier.m_miscvalue & (1<<school))
4810            ((Player*)m_target)->UpdateSpellCritChance(school);
4811}
4812
4813/********************************/
4814/***         ATTACK SPEED     ***/
4815/********************************/
4816
4817void Aura::HandleModCastingSpeed(bool apply, bool Real)
4818{
4819    m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
4820}
4821
4822void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool Real)
4823{
4824    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4825    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,m_modifier.m_amount,apply);
4826    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4827}
4828
4829void Aura::HandleModCombatSpeedPct(bool apply, bool Real)
4830{
4831    m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
4832    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4833    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,m_modifier.m_amount,apply);
4834    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4835}
4836
4837void Aura::HandleModAttackSpeed(bool apply, bool Real)
4838{
4839    if(!m_target->isAlive() )
4840        return;
4841
4842    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4843}
4844
4845void Aura::HandleHaste(bool apply, bool Real)
4846{
4847    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,  m_modifier.m_amount,apply);
4848    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,   m_modifier.m_amount,apply);
4849    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount,apply);
4850}
4851
4852void Aura::HandleAuraModRangedHaste(bool apply, bool Real)
4853{
4854    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4855}
4856
4857void Aura::HandleRangedAmmoHaste(bool apply, bool Real)
4858{
4859    if(m_target->GetTypeId() != TYPEID_PLAYER)
4860        return;
4861    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
4862}
4863
4864/********************************/
4865/***        ATTACK POWER      ***/
4866/********************************/
4867
4868void Aura::HandleAuraModAttackPower(bool apply, bool Real)
4869{
4870    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4871}
4872
4873void Aura::HandleAuraModRangedAttackPower(bool apply, bool Real)
4874{
4875    if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4876        return;
4877
4878    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4879}
4880
4881void Aura::HandleAuraAttackPowerAttacker(bool apply, bool Real)
4882{
4883    // spells required only Real aura add/remove
4884    if(!Real)
4885        return;
4886    Unit *caster = GetCaster();
4887
4888    if (!caster)
4889        return;
4890
4891    // Hunter's Mark
4892    if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & 0x0000000000000400LL)
4893    {
4894        // Check Improved Hunter's Mark bonus on caster
4895        Unit::AuraList const& mOverrideClassScript = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4896        for(Unit::AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i)
4897        {
4898            Modifier* mod = (*i)->GetModifier();
4899            // mproved Hunter's Mark script from 5236 to 5240
4900            if (mod->m_miscvalue >= 5236 && mod->m_miscvalue <= 5240)
4901            {
4902                // Get amount of ranged bonus for this spell..
4903                int32 ranged_bonus = caster->CalculateSpellDamage(m_spellProto, 1, m_spellProto->EffectBasePoints[1], m_target);
4904                // Set melee attack power bonus % from ranged depends from Improved mask aura
4905                m_modifier.m_amount = mod->m_amount * ranged_bonus / 100;
4906                m_currentBasePoints = m_modifier.m_amount;
4907                break;
4908            }
4909        }
4910        return;
4911    }
4912}
4913
4914void Aura::HandleAuraModAttackPowerPercent(bool apply, bool Real)
4915{
4916    //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
4917    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
4918}
4919
4920void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool Real)
4921{
4922    if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4923        return;
4924
4925    //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
4926    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
4927}
4928
4929void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool apply, bool Real)
4930{
4931    // spells required only Real aura add/remove
4932    if(!Real)
4933        return;
4934
4935    if(m_target->GetTypeId() == TYPEID_PLAYER && (m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4936        return;
4937
4938    if(m_modifier.m_miscvalue != STAT_INTELLECT)
4939    {
4940        // support required adding UpdateAttackPowerAndDamage calls at stat update
4941        sLog.outError("Aura SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT (212) need support non-intelect stats!");
4942        return;
4943    }
4944
4945    // Recalculate bonus
4946    ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
4947}
4948
4949/********************************/
4950/***        DAMAGE BONUS      ***/
4951/********************************/
4952void Aura::HandleModDamageDone(bool apply, bool Real)
4953{
4954    // apply item specific bonuses for already equipped weapon
4955    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
4956    {
4957        for(int i = 0; i < MAX_ATTACK; ++i)
4958            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4959                ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply);
4960    }
4961
4962    // m_modifier.m_miscvalue is bitmask of spell schools
4963    // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
4964    // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
4965    // 127 - full bitmask any damages
4966    //
4967    // mods must be applied base at equipped weapon class and subclass comparison
4968    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
4969    // m_modifier.m_miscvalue comparison with item generated damage types
4970
4971    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
4972    {
4973        // apply generic physical damage bonuses including wand case
4974        if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
4975        {
4976            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4977            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4978            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4979        }
4980        else
4981        {
4982            // done in Player::_ApplyWeaponDependentAuraMods
4983        }
4984
4985        if(m_target->GetTypeId() == TYPEID_PLAYER)
4986        {
4987            if(m_positive)
4988                m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS,m_modifier.m_amount,apply);
4989            else
4990                m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG,m_modifier.m_amount,apply);
4991        }
4992    }
4993
4994    // Skip non magic case for speedup
4995    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
4996        return;
4997
4998    if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
4999    {
5000        // wand magic case (skip generic to all item spell bonuses)
5001        // done in Player::_ApplyWeaponDependentAuraMods
5002
5003        // Skip item specific requirements for not wand magic damage
5004        return;
5005    }
5006
5007    // Magic damage modifiers implemented in Unit::SpellDamageBonus
5008    // This information for client side use only
5009    if(m_target->GetTypeId() == TYPEID_PLAYER)
5010    {
5011        if(m_positive)
5012        {
5013            for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; i++)
5014            {
5015                if((m_modifier.m_miscvalue & (1<<i)) != 0)
5016                    m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS+i,m_modifier.m_amount,apply);
5017            }
5018        }
5019        else
5020        {
5021            for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; i++)
5022            {
5023                if((m_modifier.m_miscvalue & (1<<i)) != 0)
5024                    m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG+i,m_modifier.m_amount,apply);
5025            }
5026        }
5027        Pet* pet = m_target->GetPet();
5028        if(pet)
5029            pet->UpdateAttackPowerAndDamage();
5030    }
5031}
5032
5033void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5034{
5035    sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5036
5037    // apply item specific bonuses for already equipped weapon
5038    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
5039    {
5040        for(int i = 0; i < MAX_ATTACK; ++i)
5041            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5042                ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply);
5043    }
5044
5045    // m_modifier.m_miscvalue is bitmask of spell schools
5046    // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5047    // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5048    // 127 - full bitmask any damages
5049    //
5050    // mods must be applied base at equipped weapon class and subclass comparison
5051    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5052    // m_modifier.m_miscvalue comparison with item generated damage types
5053
5054    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5055    {
5056        // apply generic physical damage bonuses including wand case
5057        if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5058        {
5059            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5060            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5061            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5062        }
5063        else
5064        {
5065            // done in Player::_ApplyWeaponDependentAuraMods
5066        }
5067        // For show in client
5068        if(m_target->GetTypeId() == TYPEID_PLAYER)
5069            m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT,m_modifier.m_amount/100.0f,apply);
5070    }
5071
5072    // Skip non magic case for speedup
5073    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5074        return;
5075
5076    if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5077    {
5078        // wand magic case (skip generic to all item spell bonuses)
5079        // done in Player::_ApplyWeaponDependentAuraMods
5080
5081        // Skip item specific requirements for not wand magic damage
5082        return;
5083    }
5084
5085    // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5086    // Send info to client
5087    if(m_target->GetTypeId() == TYPEID_PLAYER)
5088        for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5089            m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT+i,m_modifier.m_amount/100.0f,apply);
5090}
5091
5092void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5093{
5094    // spells required only Real aura add/remove
5095    if(!Real)
5096        return;
5097
5098    sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5099
5100    m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5101}
5102
5103/********************************/
5104/***        POWER COST        ***/
5105/********************************/
5106
5107void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5108{
5109    // spells required only Real aura add/remove
5110    if(!Real)
5111        return;
5112
5113    float amount = m_modifier.m_amount/100.0f;
5114    for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5115        if(m_modifier.m_miscvalue & (1<<i))
5116            m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+i,amount,apply);
5117}
5118
5119void Aura::HandleModPowerCost(bool apply, bool Real)
5120{
5121    // spells required only Real aura add/remove
5122    if(!Real)
5123        return;
5124
5125    for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5126        if(m_modifier.m_miscvalue & (1<<i))
5127            m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER+i,m_modifier.m_amount,apply);
5128}
5129
5130/*********************************************************/
5131/***                    OTHERS                         ***/
5132/*********************************************************/
5133
5134void Aura::HandleShapeshiftBoosts(bool apply)
5135{
5136    uint32 spellId = 0;
5137    uint32 spellId2 = 0;
5138    uint32 HotWSpellId = 0;
5139
5140    switch(GetModifier()->m_miscvalue)
5141    {
5142        case FORM_CAT:
5143            spellId = 3025;
5144            HotWSpellId = 24900;
5145            break;
5146        case FORM_TREE:
5147            spellId = 5420;
5148            break;
5149        case FORM_TRAVEL:
5150            spellId = 5419;
5151            break;
5152        case FORM_AQUA:
5153            spellId = 5421;
5154            break;
5155        case FORM_BEAR:
5156            spellId = 1178;
5157            spellId2 = 21178;
5158            HotWSpellId = 24899;
5159            break;
5160        case FORM_DIREBEAR:
5161            spellId = 9635;
5162            spellId2 = 21178;
5163            HotWSpellId = 24899;
5164            break;
5165        case FORM_BATTLESTANCE:
5166            spellId = 21156;
5167            break;
5168        case FORM_DEFENSIVESTANCE:
5169            spellId = 7376;
5170            break;
5171        case FORM_BERSERKERSTANCE:
5172            spellId = 7381;
5173            break;
5174        case FORM_MOONKIN:
5175            spellId = 24905;
5176            // aura from effect trigger spell
5177            spellId2 = 24907;
5178            break;
5179        case FORM_FLIGHT:
5180            spellId = 33948;
5181            break;
5182        case FORM_FLIGHT_EPIC:
5183            spellId  = 40122;
5184            spellId2 = 40121;
5185            break;
5186        case FORM_SPIRITOFREDEMPTION:
5187            spellId  = 27792;
5188            spellId2 = 27795;                               // must be second, this important at aura remove to prevent to early iterator invalidation.
5189            break;
5190        case FORM_GHOSTWOLF:
5191        case FORM_AMBIENT:
5192        case FORM_GHOUL:
5193        case FORM_SHADOW:
5194        case FORM_STEALTH:
5195        case FORM_CREATURECAT:
5196        case FORM_CREATUREBEAR:
5197            spellId = 0;
5198            break;
5199    }
5200
5201    uint32 form = GetModifier()->m_miscvalue-1;
5202
5203    if(apply)
5204    {
5205        if (spellId) m_target->CastSpell(m_target, spellId, true, NULL, this );
5206        if (spellId2) m_target->CastSpell(m_target, spellId2, true, NULL, this);
5207
5208        if(m_target->GetTypeId() == TYPEID_PLAYER)
5209        {
5210            const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5211            for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5212            {
5213                if(itr->second->state == PLAYERSPELL_REMOVED) continue;
5214                if(itr->first==spellId || itr->first==spellId2) continue;
5215                SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5216                if (!spellInfo || !(spellInfo->Attributes & ((1<<6) | (1<<7)))) continue;
5217                if (spellInfo->Stances & (1<<form))
5218                    m_target->CastSpell(m_target, itr->first, true, NULL, this);
5219            }
5220            //LotP
5221            if (((Player*)m_target)->HasSpell(17007))
5222            {
5223                SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5224                if (spellInfo && spellInfo->Stances & (1<<form))
5225                    m_target->CastSpell(m_target, 24932, true, NULL, this);
5226            }
5227            // HotW
5228            if (HotWSpellId)
5229            {
5230                Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5231                for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5232                {
5233                    if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5234                    {
5235                        int32 HotWMod = (*i)->GetModifier()->m_amount;
5236                        if(GetModifier()->m_miscvalue == FORM_CAT)
5237                            HotWMod /= 2;
5238
5239                        m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5240                        break;
5241                    }
5242                }
5243            }
5244        }
5245    }
5246    else
5247    {
5248        m_target->RemoveAurasDueToSpell(spellId);
5249        m_target->RemoveAurasDueToSpell(spellId2);
5250
5251        Unit::AuraMap& tAuras = m_target->GetAuras();
5252        for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5253        {
5254            if (itr->second->IsRemovedOnShapeLost())
5255            {
5256                m_target->RemoveAurasDueToSpell(itr->second->GetId());
5257                itr = tAuras.begin();
5258            }
5259            else
5260            {
5261                ++itr;
5262            }
5263        }
5264    }
5265
5266    /*double healthPercentage = (double)m_target->GetHealth() / (double)m_target->GetMaxHealth();
5267    m_target->SetHealth(uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage)));*/
5268}
5269
5270void Aura::HandleAuraEmpathy(bool apply, bool Real)
5271{
5272    if(m_target->GetTypeId() != TYPEID_UNIT)
5273        return;
5274
5275    CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5276    if(ci && ci->type == CREATURE_TYPE_BEAST)
5277        m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5278}
5279
5280void Aura::HandleAuraUntrackable(bool apply, bool Real)
5281{
5282    if(apply)
5283        m_target->SetFlag(UNIT_FIELD_BYTES_1, PLAYER_STATE_FLAG_UNTRACKABLE);
5284    else
5285        m_target->RemoveFlag(UNIT_FIELD_BYTES_1, PLAYER_STATE_FLAG_UNTRACKABLE);
5286}
5287
5288void Aura::HandleAuraModPacify(bool apply, bool Real)
5289{
5290    if(m_target->GetTypeId() != TYPEID_PLAYER)
5291        return;
5292
5293    if(apply)
5294        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5295    else
5296        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5297}
5298
5299void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5300{
5301    HandleAuraModPacify(apply,Real);
5302    HandleAuraModSilence(apply,Real);
5303}
5304
5305void Aura::HandleAuraGhost(bool apply, bool Real)
5306{
5307    if(m_target->GetTypeId() != TYPEID_PLAYER)
5308        return;
5309
5310    if(apply)
5311    {
5312        m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5313    }
5314    else
5315    {
5316        m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5317    }
5318}
5319
5320void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5321{
5322    // all applied/removed only at real aura add/remove
5323    if(!Real)
5324        return;
5325
5326    // allow fly
5327    WorldPacket data;
5328    if(apply)
5329        data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5330    else
5331        data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5332    data.append(m_target->GetPackGUID());
5333    data << uint32(0);                                      // unk
5334    m_target->SendMessageToSet(&data, true);
5335}
5336
5337void Aura::HandleModRating(bool apply, bool Real)
5338{
5339    // spells required only Real aura add/remove
5340    if(!Real)
5341        return;
5342
5343    if(m_target->GetTypeId() != TYPEID_PLAYER)
5344        return;
5345
5346    for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5347        if (m_modifier.m_miscvalue & (1 << rating))
5348            ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5349}
5350
5351void Aura::HandleForceMoveForward(bool apply, bool Real)
5352{
5353    if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5354        return;
5355    if(apply)
5356        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5357    else
5358        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5359}
5360
5361void Aura::HandleAuraModExpertise(bool apply, bool Real)
5362{
5363    if(m_target->GetTypeId() != TYPEID_PLAYER)
5364        return;
5365
5366    ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5367    ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5368}
5369
5370void Aura::HandleModTargetResistance(bool apply, bool Real)
5371{
5372    // spells required only Real aura add/remove
5373    if(!Real)
5374        return;
5375    // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
5376
5377    // show armor penetration
5378    if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
5379        m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE,m_modifier.m_amount, apply);
5380
5381    // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
5382    if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
5383        m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE,m_modifier.m_amount, apply);
5384}
5385
5386//HandleNoImmediateEffect auras implementation to support new stat system
5387void Aura::HandleAuraHealing(bool apply, bool Real)
5388{
5389    //m_target->HandleStatModifier(UNIT_MOD_HEALING, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5390}
5391
5392void Aura::HandleAuraHealingPct(bool apply, bool Real)
5393{
5394    //m_target->HandleStatModifier(UNIT_MOD_HEALING, TOTAL_PCT, float(m_modifier.m_amount), apply);
5395}
5396
5397void Aura::HandleShieldBlockValue(bool apply, bool Real)
5398{
5399    BaseModType modType = FLAT_MOD;
5400    if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
5401        modType = PCT_MOD;
5402
5403    if(m_target->GetTypeId() == TYPEID_PLAYER)
5404        ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
5405}
5406
5407void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
5408{
5409    // spells required only Real aura add/remove
5410    if(!Real)
5411        return;
5412
5413    if(m_target->GetTypeId() != TYPEID_PLAYER)
5414        return;
5415
5416    Player *target = (Player*)m_target;
5417
5418    // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
5419    // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
5420    if( !apply && m_duration==0 && target->GetComboTarget())
5421        if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
5422            target->AddComboPoints(unit, -m_modifier.m_amount);
5423}
5424
5425void Aura::HandleModUnattackable( bool Apply, bool Real )
5426{
5427    if(Real && Apply)
5428        m_target->CombatStop();
5429
5430    m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
5431}
5432
5433void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
5434{
5435    // spells required only Real aura add/remove
5436    if(!Real)
5437        return;
5438
5439    // prepare spirit state
5440    if(apply)
5441    {
5442        if(m_target->GetTypeId()==TYPEID_PLAYER)
5443        {
5444            // disable breath/etc timers
5445            ((Player*)m_target)->StopMirrorTimers();
5446
5447            // set stand state (expected in this form)
5448            if(!m_target->IsStandState())
5449                m_target->SetStandState(PLAYER_STATE_NONE);
5450        }
5451
5452        m_target->SetHealth(1);
5453    }
5454    // die at aura end
5455    else
5456        m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
5457}
5458
5459void Aura::CleanupTriggeredSpells()
5460{
5461    uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
5462    if(!tSpellId)
5463        return;
5464
5465    SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
5466    if(!tProto)
5467        return;
5468
5469    if(GetSpellDuration(tProto) != -1)
5470        return;
5471
5472    // needed for spell 43680, maybe others
5473    // TODO: is there a spell flag, which can solve this in a more sophisticated way?
5474    if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
5475            GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
5476        return;
5477    m_target->RemoveAurasDueToSpell(tSpellId);
5478}
5479
5480void Aura::HandleAuraPowerBurn(bool apply, bool Real)
5481{
5482    if (m_periodicTimer <= 0)
5483        m_periodicTimer += m_modifier.periodictime;
5484
5485    m_isPeriodic = apply;
5486}
5487
5488void Aura::HandleSchoolAbsorb(bool apply, bool Real)
5489{
5490    if(!Real)
5491        return;
5492
5493    // prevent double apply bonuses
5494    if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
5495    {
5496        if(Unit* caster = GetCaster())
5497        {
5498            float DoneActualBenefit = 0.0f;
5499            switch(m_spellProto->SpellFamilyName)
5500            {
5501                case SPELLFAMILY_PRIEST:
5502                    if(m_spellProto->SpellFamilyFlags == 0x1) //PW:S
5503                    {
5504                        //+30% from +healing bonus
5505                        DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.3f;
5506                        break;
5507                    }
5508                    break;
5509                case SPELLFAMILY_MAGE:
5510                    if(m_spellProto->SpellFamilyFlags == 0x80100 || m_spellProto->SpellFamilyFlags == 0x8 || m_spellProto->SpellFamilyFlags == 0x100000000LL)
5511                    {
5512                        //frost ward, fire ward, ice barrier
5513                        //+10% from +spd bonus
5514                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
5515                        break;
5516                    }
5517                    break;
5518                case SPELLFAMILY_WARLOCK:
5519                    if(m_spellProto->SpellFamilyFlags == 0x00)
5520                    {
5521                        //shadow ward
5522                        //+10% from +spd bonus
5523                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
5524                        break;
5525                    }
5526                    break;
5527                default:
5528                    break;
5529            }
5530
5531            DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
5532
5533            m_modifier.m_amount += (int32)DoneActualBenefit;
5534        }
5535    }
5536}
5537
5538void Aura::PeriodicTick()
5539{
5540    if(!m_target->isAlive())
5541        return;
5542
5543    switch(m_modifier.m_auraname)
5544    {
5545        case SPELL_AURA_PERIODIC_DAMAGE:
5546        case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
5547        {
5548            Unit *pCaster = GetCaster();
5549            if(!pCaster)
5550                return;
5551
5552            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5553                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5554                return;
5555
5556            // Check for immune (not use charges)
5557            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5558                return;
5559
5560            // some auras remove at specific health level or more
5561            if(m_modifier.m_auraname==SPELL_AURA_PERIODIC_DAMAGE)
5562            {
5563                switch(GetId())
5564                {
5565                    case 43093: case 31956: case 38801:
5566                    case 35321: case 38363: case 39215:
5567                        if(m_target->GetHealth() == m_target->GetMaxHealth() )
5568                        {
5569                            m_target->RemoveAurasDueToSpell(GetId());
5570                            return;
5571                        }
5572                        break;
5573                    case 38772:
5574                    {
5575                        uint32 percent =
5576                            GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_DUMMY ?
5577                            pCaster->CalculateSpellDamage(GetSpellProto(),GetEffIndex()+1,GetSpellProto()->EffectBasePoints[GetEffIndex()+1],m_target) :
5578                            100;
5579                        if(m_target->GetHealth()*100 >= m_target->GetMaxHealth()*percent )
5580                        {
5581                            m_target->RemoveAurasDueToSpell(GetId());
5582                            return;
5583                        }
5584                        break;
5585                    }
5586                    case 41337:// aura of anger
5587                    {                       
5588                        Unit::AuraList const& mMod = m_target->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE);
5589                        for(Unit::AuraList::const_iterator i = mMod.begin(); i != mMod.end(); ++i)
5590                        {
5591                            if ((*i)->GetId() == 41337)
5592                            {
5593                                (*i)->ApplyModifier(false);
5594                                (*i)->GetModifier()->m_amount += 5;
5595                                (*i)->ApplyModifier(true);
5596                                break;
5597                            }
5598                        }                       
5599                        m_modifier.m_amount += 100;
5600                    }break;
5601                    default:
5602                        break;
5603                }
5604            }
5605
5606            uint32 absorb=0;
5607            uint32 resist=0;
5608            CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5609
5610            // ignore non positive values (can be result apply spellmods to aura damage
5611            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5612
5613            uint32 pdamage;
5614
5615            if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
5616            {
5617                pdamage = amount;
5618
5619                // Calculate armor mitigation if it is a physical spell
5620                // But not for bleed mechanic spells
5621                if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
5622                     GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
5623                {
5624                    uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
5625                    cleanDamage.damage += pdamage - pdamageReductedArmor;
5626                    pdamage = pdamageReductedArmor;
5627                }
5628
5629                pdamage = pCaster->SpellDamageBonus(m_target,GetSpellProto(),pdamage,DOT);
5630
5631                // Curse of Agony damage-per-tick calculation
5632                if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x0000000000000400LL) && GetSpellProto()->SpellIconID==544)
5633                {
5634                    // 1..4 ticks, 1/2 from normal tick damage
5635                    if (m_duration>=((m_maxduration-m_modifier.periodictime)*2/3))
5636                        pdamage = pdamage/2;
5637                    // 9..12 ticks, 3/2 from normal tick damage
5638                    else if(m_duration<((m_maxduration-m_modifier.periodictime)/3))
5639                        pdamage += (pdamage+1)/2;           // +1 prevent 0.5 damage possible lost at 1..4 ticks
5640                    // 5..8 ticks have normal tick damage
5641                }
5642            }
5643            else
5644                pdamage = uint32(m_target->GetMaxHealth()*amount/100);
5645
5646            //As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
5647            // Reduce dot damage from resilience for players
5648            if (m_target->GetTypeId()==TYPEID_PLAYER)
5649                pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
5650
5651            pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
5652
5653            sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
5654                GetCasterGUID(), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
5655
5656            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5657            data.append(m_target->GetPackGUID());
5658            data.appendPackGUID(GetCasterGUID());
5659            data << uint32(GetId());
5660            data << uint32(1);
5661            data << uint32(m_modifier.m_auraname);
5662            data << (uint32)pdamage;
5663            data << (uint32)GetSpellSchoolMask(GetSpellProto()); // will be mask in 2.4.x
5664            data << (uint32)absorb;
5665            data << (uint32)resist;
5666            m_target->SendMessageToSet(&data,true);
5667
5668            Unit* target = m_target;                        // aura can be deleted in DealDamage
5669            SpellEntry const* spellProto = GetSpellProto();
5670
5671            pCaster->DealDamage(m_target, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
5672
5673            // DO NOT ACCESS MEMBERS OF THE AURA FROM NOW ON (DealDamage can delete aura)
5674
5675            pCaster->ProcDamageAndSpell(target, PROC_FLAG_HIT_SPELL, PROC_FLAG_TAKE_DAMAGE, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), GetSpellSchoolMask(spellProto), spellProto);
5676            break;
5677        }
5678        case SPELL_AURA_PERIODIC_LEECH:
5679        {
5680            Unit *pCaster = GetCaster();
5681            if(!pCaster)
5682                return;
5683
5684            if(!pCaster->isAlive())
5685                return;
5686
5687            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5688                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5689                return;
5690
5691            // Check for immune (not use charges)
5692            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5693                return;
5694
5695            uint32 absorb=0;
5696            uint32 resist=0;
5697            CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5698
5699            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5700
5701            //Calculate armor mitigation if it is a physical spell
5702            if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
5703            {
5704                uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
5705                cleanDamage.damage += pdamage - pdamageReductedArmor;
5706                pdamage = pdamageReductedArmor;
5707            }
5708
5709            pdamage = pCaster->SpellDamageBonus(m_target,GetSpellProto(),pdamage,DOT);
5710
5711            // talent Soul Siphon add bonus to Drain Life spells
5712            if( GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x8) )
5713            {
5714                // find talent max bonus percentage
5715                Unit::AuraList const& mClassScriptAuras = pCaster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
5716                for(Unit::AuraList::const_iterator i = mClassScriptAuras.begin(); i != mClassScriptAuras.end(); ++i)
5717                {
5718                    if ((*i)->GetModifier()->m_miscvalue == 4992 || (*i)->GetModifier()->m_miscvalue == 4993)
5719                    {
5720                        if((*i)->GetEffIndex()!=1)
5721                        {
5722                            sLog.outError("Expected spell %u structure change, need code update",(*i)->GetId());
5723                            break;
5724                        }
5725
5726                        // effect 1 m_amount
5727                        int32 maxPercent = (*i)->GetModifier()->m_amount;
5728                        // effect 0 m_amount
5729                        int32 stepPercent = pCaster->CalculateSpellDamage((*i)->GetSpellProto(),0,(*i)->GetSpellProto()->EffectBasePoints[0],pCaster);
5730
5731                        // count affliction effects and calc additional damage in percentage
5732                        int32 modPercent = 0;
5733                        Unit::AuraMap const& victimAuras = m_target->GetAuras();
5734                        for (Unit::AuraMap::const_iterator itr = victimAuras.begin(); itr != victimAuras.end(); ++itr)
5735                        {
5736                            Aura* aura = itr->second;
5737                            if (aura->IsPositive())continue;
5738                            SpellEntry const* m_spell = aura->GetSpellProto();
5739                            if (m_spell->SpellFamilyName != SPELLFAMILY_WARLOCK)
5740                                continue;
5741
5742                            SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(m_spell->Id);
5743                            SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(m_spell->Id);
5744
5745                            for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
5746                            {
5747                                if(_spell_idx->second->skillId == SKILL_AFFLICTION)
5748                                {
5749                                    modPercent += stepPercent;
5750                                    if (modPercent >= maxPercent)
5751                                    {
5752                                        modPercent = maxPercent;
5753                                        break;
5754                                    }
5755                                }
5756                            }
5757                        }
5758                        pdamage += (pdamage*modPercent/100);
5759                        break;
5760                    }
5761                }
5762            }
5763
5764            //As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
5765            // Reduce dot damage from resilience for players
5766            if (m_target->GetTypeId()==TYPEID_PLAYER)
5767                pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
5768
5769            pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
5770
5771            if(m_target->GetHealth() < pdamage)
5772                pdamage = uint32(m_target->GetHealth());
5773
5774            sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
5775                GetCasterGUID(), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
5776
5777            pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
5778
5779
5780            Unit* target = m_target;                        // aura can be deleted in DealDamage
5781            SpellEntry const* spellProto = GetSpellProto();
5782            float multiplier = spellProto->EffectMultipleValue[GetEffIndex()] > 0 ? spellProto->EffectMultipleValue[GetEffIndex()] : 1;
5783
5784            uint32 new_damage = pCaster->DealDamage(m_target, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
5785
5786            // DO NOT ACCESS MEMBERS OF THE AURA FROM NOW ON (DealDamage can delete aura)
5787
5788            pCaster->ProcDamageAndSpell(target, PROC_FLAG_HIT_SPELL, PROC_FLAG_TAKE_DAMAGE, new_damage, GetSpellSchoolMask(spellProto), spellProto);
5789            if (!target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
5790            {
5791                for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++)
5792                {
5793                    if (pCaster->m_currentSpells[i] && pCaster->m_currentSpells[i]->m_spellInfo->Id == spellProto->Id)
5794                        pCaster->m_currentSpells[i]->cancel();
5795                }
5796            }
5797
5798
5799            if(Player *modOwner = pCaster->GetSpellModOwner())
5800                modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
5801
5802            uint32 heal = pCaster->SpellHealingBonus(spellProto, uint32(new_damage * multiplier), DOT, pCaster);
5803
5804            int32 gain = pCaster->ModifyHealth(heal);
5805            pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, spellProto);
5806
5807            pCaster->SendHealSpellLog(pCaster, spellProto->Id, heal);
5808            break;
5809        }
5810        case SPELL_AURA_PERIODIC_HEAL:
5811        case SPELL_AURA_OBS_MOD_HEALTH:
5812        {
5813            Unit *pCaster = GetCaster();
5814            if(!pCaster)
5815                return;
5816
5817            // heal for caster damage (must be alive)
5818            if(m_target != pCaster && GetSpellProto()->SpellVisual==163 && !pCaster->isAlive())
5819                return;
5820
5821            // ignore non positive values (can be result apply spellmods to aura damage
5822            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5823
5824            uint32 pdamage;
5825
5826            if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
5827                pdamage = uint32(m_target->GetMaxHealth() * amount/100);
5828            else
5829                pdamage = amount;
5830
5831            pdamage = pCaster->SpellHealingBonus(GetSpellProto(), pdamage, DOT, m_target);
5832
5833            sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
5834                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5835
5836            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5837            data.append(m_target->GetPackGUID());
5838            data.appendPackGUID(GetCasterGUID());
5839            data << uint32(GetId());
5840            data << uint32(1);
5841            data << uint32(m_modifier.m_auraname);
5842            data << (uint32)pdamage;
5843            m_target->SendMessageToSet(&data,true);
5844
5845            int32 gain = m_target->ModifyHealth(pdamage);
5846
5847            // add HoTs to amount healed in bgs
5848            if( pCaster->GetTypeId() == TYPEID_PLAYER )
5849                if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
5850                    bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
5851
5852            //Do check before because m_modifier.auraName can be invalidate by DealDamage.
5853            bool procSpell = (m_modifier.m_auraname == SPELL_AURA_PERIODIC_HEAL && m_target != pCaster);
5854
5855            m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5856
5857            Unit* target = m_target;                        // aura can be deleted in DealDamage
5858            SpellEntry const* spellProto = GetSpellProto();
5859            bool haveCastItem = GetCastItemGUID()!=0;
5860
5861            // heal for caster damage
5862            if(m_target!=pCaster && spellProto->SpellVisual==163)
5863            {
5864                uint32 dmg = spellProto->manaPerSecond;
5865                if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
5866                {
5867                    pCaster->RemoveAurasDueToSpell(GetId());
5868
5869                    // finish current generic/channeling spells, don't affect autorepeat
5870                    if(pCaster->m_currentSpells[CURRENT_GENERIC_SPELL])
5871                    {
5872                        pCaster->m_currentSpells[CURRENT_GENERIC_SPELL]->finish();
5873                    }
5874                    if(pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL])
5875                    {
5876                        pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL]->SendChannelUpdate(0);
5877                        pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL]->finish();
5878                    }
5879                }
5880                else
5881                {
5882                    pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), gain, GetSpellSchoolMask(GetSpellProto()), 0, 0, false, 0, false);
5883
5884                    CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5885                    pCaster->DealDamage(pCaster, gain, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
5886                }
5887            }
5888
5889            // ignore item heals
5890            if(procSpell && !haveCastItem)
5891                pCaster->ProcDamageAndSpell(target,PROC_FLAG_HEAL, PROC_FLAG_HEALED, pdamage, SPELL_SCHOOL_MASK_NONE, spellProto);
5892            break;
5893        }
5894        case SPELL_AURA_PERIODIC_MANA_LEECH:
5895        {
5896            Unit *pCaster = GetCaster();
5897            if(!pCaster)
5898                return;
5899
5900            if(!pCaster->isAlive())
5901                return;
5902
5903            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5904                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5905                return;
5906
5907            // Check for immune (not use charges)
5908            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5909                return;
5910
5911            // ignore non positive values (can be result apply spellmods to aura damage
5912            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5913
5914            sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
5915                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5916
5917            if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue > 4)
5918                break;
5919
5920            Powers power = Powers(m_modifier.m_miscvalue);
5921
5922            // power type might have changed between aura applying and tick (druid's shapeshift)
5923            if(m_target->getPowerType() != power)
5924                break;
5925
5926            int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
5927
5928            // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
5929            if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
5930                drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
5931
5932            m_target->ModifyPower(power, -drain_amount);
5933
5934            float gain_multiplier = 0;
5935
5936            if(pCaster->GetMaxPower(power) > 0)
5937            {
5938                gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
5939
5940                if(Player *modOwner = pCaster->GetSpellModOwner())
5941                    modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
5942            }
5943
5944            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5945            data.append(m_target->GetPackGUID());
5946            data.appendPackGUID(GetCasterGUID());
5947            data << uint32(GetId());
5948            data << uint32(1);
5949            data << uint32(m_modifier.m_auraname);
5950            data << (uint32)power;                          // power type
5951            data << (uint32)drain_amount;
5952            data << (float)gain_multiplier;
5953            m_target->SendMessageToSet(&data,true);
5954
5955            int32 gain_amount = int32(drain_amount*gain_multiplier);
5956
5957            if(gain_amount)
5958            {
5959                int32 gain = pCaster->ModifyPower(power,gain_amount);
5960                m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
5961            }
5962            break;
5963        }
5964        case SPELL_AURA_PERIODIC_ENERGIZE:
5965        {
5966            // ignore non positive values (can be result apply spellmods to aura damage
5967            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5968
5969            sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
5970                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5971
5972            if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue > 4)
5973                break;
5974
5975            Powers power = Powers(m_modifier.m_miscvalue);
5976
5977            if(m_target->GetMaxPower(power) == 0)
5978                break;
5979
5980            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5981            data.append(m_target->GetPackGUID());
5982            data.appendPackGUID(GetCasterGUID());
5983            data << uint32(GetId());
5984            data << uint32(1);
5985            data << uint32(m_modifier.m_auraname);
5986            data << (uint32)power;                          // power type
5987            data << (uint32)pdamage;
5988            m_target->SendMessageToSet(&data,true);
5989
5990            int32 gain = m_target->ModifyPower(power,pdamage);
5991
5992            if(Unit* pCaster = GetCaster())
5993                m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5994            break;
5995        }
5996        case SPELL_AURA_OBS_MOD_MANA:
5997        {
5998            // ignore non positive values (can be result apply spellmods to aura damage
5999            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6000
6001            uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount/100);
6002
6003            sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
6004                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6005
6006            if(m_target->GetMaxPower(POWER_MANA) == 0)
6007                break;
6008
6009            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
6010            data.append(m_target->GetPackGUID());
6011            data.appendPackGUID(GetCasterGUID());
6012            data << uint32(GetId());
6013            data << uint32(1);
6014            data << uint32(m_modifier.m_auraname);
6015            data << (uint32)0;                              // ?
6016            data << (uint32)pdamage;
6017            m_target->SendMessageToSet(&data,true);
6018
6019            int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
6020
6021            if(Unit* pCaster = GetCaster())
6022                m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6023            break;
6024        }
6025        case SPELL_AURA_POWER_BURN_MANA:
6026        {
6027            Unit *pCaster = GetCaster();
6028            if(!pCaster)
6029                return;
6030
6031            // Check for immune (not use charges)
6032            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6033                return;
6034
6035            int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6036
6037            Powers powerType = Powers(m_modifier.m_miscvalue);
6038
6039            if(!m_target->isAlive() || m_target->getPowerType() != powerType)
6040                return;
6041
6042            // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6043            if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6044                pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
6045
6046            uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
6047
6048            gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
6049
6050            //maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
6051            pCaster->SpellNonMeleeDamageLog(m_target, GetId(), gain);
6052            break;
6053        }
6054        // Here tick dummy auras
6055        case SPELL_AURA_PERIODIC_DUMMY:
6056        {
6057            PeriodicDummyTick();
6058            break;
6059        }
6060        default:
6061            break;
6062    }
6063}
6064
6065void Aura::PeriodicDummyTick()
6066{
6067    SpellEntry const* spell = GetSpellProto();
6068    switch (spell->Id)
6069    {
6070        // Drink
6071        case 430:
6072        case 431:
6073        case 432:
6074        case 1133:
6075        case 1135:
6076        case 1137:
6077        case 10250:
6078        case 22734:
6079        case 27089:
6080        case 34291:
6081        case 43706:
6082        case 46755:
6083        {
6084            if (m_target->GetTypeId() != TYPEID_PLAYER)
6085                return;
6086            // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6087            Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6088            for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6089            {
6090                if ((*i)->GetId() == GetId())
6091                {
6092                    // Get tick number
6093                    int32 tick = (m_maxduration - m_duration) / m_modifier.periodictime;
6094                    // Default case (not on arenas)
6095                    if (tick == 0)
6096                    {
6097                        (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6098                        ((Player*)m_target)->UpdateManaRegen();
6099                        // Disable continue
6100                        m_isPeriodic = false;
6101                    }
6102                    return;
6103                    //**********************************************
6104                    // Code commended since arena patch not added
6105                    // This feature uses only in arenas
6106                    //**********************************************
6107                    // Here need increase mana regen per tick (6 second rule)
6108                    // on 0 tick -   0  (handled in 2 second)
6109                    // on 1 tick - 166% (handled in 4 second)
6110                    // on 2 tick - 133% (handled in 6 second)
6111                    // Not need update after 3 tick
6112                    /*
6113                    if (tick > 3)
6114                        return;
6115                    // Apply bonus for 0 - 3 tick
6116                    switch (tick)
6117                    {
6118                        case 0:   // 0%
6119                            (*i)->GetModifier()->m_amount = m_modifier.m_amount = 0;
6120                            break;
6121                        case 1:   // 166%
6122                            (*i)->GetModifier()->m_amount = m_modifier.m_amount * 5 / 3;
6123                            break;
6124                        case 2:   // 133%
6125                            (*i)->GetModifier()->m_amount = m_modifier.m_amount * 4 / 3;
6126                            break;
6127                        default:  // 100% - normal regen
6128                            (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6129                            break;
6130                    }
6131                    ((Player*)m_target)->UpdateManaRegen();
6132                    return;*/
6133                }
6134            }
6135            return;
6136        }
6137//        // Panda
6138//        case 19230: break;
6139//        // Master of Subtlety
6140//        case 31666: break;
6141//        // Gossip NPC Periodic - Talk
6142//        case 33208: break;
6143//        // Gossip NPC Periodic - Despawn
6144//        case 33209: break;
6145//        // Force of Nature
6146//        case 33831: break;
6147        // Aspect of the Viper
6148        case 34074:
6149        {
6150            if (m_target->GetTypeId() != TYPEID_PLAYER)
6151                return;
6152            // Should be manauser
6153            if (m_target->getPowerType()!=POWER_MANA)
6154                return;
6155            Unit *caster = GetCaster();
6156            if (!caster)
6157                return;
6158            // Regen amount is max (100% from spell) on 21% or less mana and min on 92.5% or greater mana (20% from spell)
6159            int mana = m_target->GetPower(POWER_MANA);
6160            int max_mana = m_target->GetMaxPower(POWER_MANA);
6161            int32 base_regen = caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, m_target);
6162            float regen_pct = 1.20f - 1.1f * mana / max_mana;
6163            if      (regen_pct > 1.0f) regen_pct = 1.0f;
6164            else if (regen_pct < 0.2f) regen_pct = 0.2f;
6165            m_modifier.m_amount = int32 (base_regen * regen_pct);
6166            ((Player*)m_target)->UpdateManaRegen();
6167            return;
6168        }
6169//        // Steal Weapon
6170//        case 36207: break;
6171//        // Simon Game START timer, (DND)
6172//        case 39993: break;
6173//        // Harpooner's Mark
6174//        case 40084: break;
6175//        // Knockdown Fel Cannon: break; The Aggro Burst
6176//        case 40119: break;
6177//        // Old Mount Spell
6178//        case 40154: break;
6179//        // Magnetic Pull
6180//        case 40581: break;
6181//        // Ethereal Ring: break; The Bolt Burst
6182//        case 40801: break;
6183//        // Crystal Prison
6184//        case 40846: break;
6185//        // Copy Weapon
6186//        case 41054: break;
6187//        // Ethereal Ring Visual, Lightning Aura
6188//        case 41477: break;
6189//        // Ethereal Ring Visual, Lightning Aura (Fork)
6190//        case 41525: break;
6191//        // Ethereal Ring Visual, Lightning Jumper Aura
6192//        case 41567: break;
6193//        // No Man's Land
6194//        case 41955: break;
6195//        // Headless Horseman - Fire
6196//        case 42074: break;
6197//        // Headless Horseman - Visual - Large Fire
6198//        case 42075: break;
6199//        // Headless Horseman - Start Fire, Periodic Aura
6200//        case 42140: break;
6201//        // Ram Speed Boost
6202//        case 42152: break;
6203//        // Headless Horseman - Fires Out Victory Aura
6204//        case 42235: break;
6205//        // Pumpkin Life Cycle
6206//        case 42280: break;
6207//        // Brewfest Request Chick Chuck Mug Aura
6208//        case 42537: break;
6209//        // Squashling
6210//        case 42596: break;
6211//        // Headless Horseman Climax, Head: Periodic
6212//        case 42603: break;
6213//        // Fire Bomb
6214//        case 42621: break;
6215//        // Headless Horseman - Conflagrate, Periodic Aura
6216//        case 42637: break;
6217//        // Headless Horseman - Create Pumpkin Treats Aura
6218//        case 42774: break;
6219//        // Headless Horseman Climax - Summoning Rhyme Aura
6220//        case 42879: break;
6221//        // Tricky Treat
6222//        case 42919: break;
6223//        // Giddyup!
6224//        case 42924: break;
6225//        // Ram - Trot
6226//        case 42992: break;
6227//        // Ram - Canter
6228//        case 42993: break;
6229//        // Ram - Gallop
6230//        case 42994: break;
6231//        // Ram Level - Neutral
6232//        case 43310: break;
6233//        // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6234//        case 43884: break;
6235//        // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6236//        case 44000: break;
6237//        // Energy Feedback
6238//        case 44328: break;
6239//        // Romantic Picnic
6240//        case 45102: break;
6241//        // Romantic Picnic
6242//        case 45123: break;
6243//        // Looking for Love
6244//        case 45124: break;
6245//        // Kite - Lightning Strike Kite Aura
6246//        case 45197: break;
6247//        // Rocket Chicken
6248//        case 45202: break;
6249//        // Copy Offhand Weapon
6250//        case 45205: break;
6251//        // Upper Deck - Kite - Lightning Periodic Aura
6252//        case 45207: break;
6253//        // Kite -Sky  Lightning Strike Kite Aura
6254//        case 45251: break;
6255//        // Ribbon Pole Dancer Check Aura
6256//        case 45390: break;
6257//        // Holiday - Midsummer, Ribbon Pole Periodic Visual
6258//        case 45406: break;
6259//        // Parachute
6260//        case 45472: break;
6261//        // Alliance Flag, Extra Damage Debuff
6262//        case 45898: break;
6263//        // Horde Flag, Extra Damage Debuff
6264//        case 45899: break;
6265//        // Ahune - Summoning Rhyme Aura
6266//        case 45926: break;
6267//        // Ahune - Slippery Floor
6268//        case 45945: break;
6269//        // Ahune's Shield
6270//        case 45954: break;
6271//        // Nether Vapor Lightning
6272//        case 45960: break;
6273//        // Darkness
6274//        case 45996: break;
6275//        // Summon Blood Elves Periodic
6276//        case 46041: break;
6277//        // Transform Visual Missile Periodic
6278//        case 46205: break;
6279//        // Find Opening Beam End
6280//        case 46333: break;
6281//        // Ice Spear Control Aura
6282//        case 46371: break;
6283//        // Hailstone Chill
6284//        case 46458: break;
6285//        // Hailstone Chill, Internal
6286//        case 46465: break;
6287//        // Chill, Internal Shifter
6288//        case 46549: break;
6289//        // Summon Ice Spear Knockback Delayer
6290//        case 46878: break;
6291//        // Burninate Effect
6292//        case 47214: break;
6293//        // Fizzcrank Practice Parachute
6294//        case 47228: break;
6295//        // Send Mug Control Aura
6296//        case 47369: break;
6297//        // Direbrew's Disarm (precast)
6298//        case 47407: break;
6299//        // Mole Machine Port Schedule
6300//        case 47489: break;
6301//        // Mole Machine Portal Schedule
6302//        case 49466: break;
6303//        // Drink Coffee
6304//        case 49472: break;
6305//        // Listening to Music
6306//        case 50493: break;
6307//        // Love Rocket Barrage
6308//        case 50530: break;
6309        default:
6310            break;
6311    }
6312}
6313
6314void Aura::HandlePreventFleeing(bool apply, bool Real)
6315{
6316    if(!Real)
6317        return;
6318
6319    Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
6320    if( !fearAuras.empty() )
6321    {
6322        if (apply)
6323            m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
6324        else
6325            m_target->SetFeared(true);
6326    }
6327}
6328
6329void Aura::HandleManaShield(bool apply, bool Real)
6330{
6331    if(!Real)
6332        return;
6333
6334    // prevent double apply bonuses
6335    if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
6336    {
6337        if(Unit* caster = GetCaster())
6338        {
6339            float DoneActualBenefit = 0.0f;
6340            switch(m_spellProto->SpellFamilyName)
6341            {
6342                case SPELLFAMILY_MAGE:
6343                    if(m_spellProto->SpellFamilyFlags & 0x8000)
6344                    {
6345                        // Mana Shield
6346                        // +50% from +spd bonus
6347                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
6348                        break;
6349                    }
6350                    break;
6351                default:
6352                    break;
6353            }
6354
6355            DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6356
6357            m_modifier.m_amount += (int32)DoneActualBenefit;
6358        }
6359    }
6360}
6361
6362void Aura::HandleArenaPreparation(bool apply, bool Real)
6363{
6364    if(!Real)
6365        return;
6366
6367    if(apply)
6368        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
6369    else
6370        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
6371}
Note: See TracBrowser for help on using the browser.