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

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

[svn] Fix some aura_interrupt_flag to correctly remove auras.
Add interrupt_flag_unattackable. Source: mangos forum. Adapted by F636y623.
Add function CombatStart?().

Original author: megamage
Date: 2008-11-11 17:49:51-06:00

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