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

Revision 284, 246.8 kB (checked in by yumileroy, 17 years ago)

Merge with 284 (54b0e67d97fe).

Original author: megamage
Date: 2008-11-21 19:49:54-06:00

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