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

Revision 251, 254.6 kB (checked in by yumileroy, 17 years ago)

*Merge from Mangos
*[6833] More correct aura cancel for channeled spells. By VladimirMangos?.
*[6820] Cleanup spell proc event code. Avoid send same information by 2 ways to function. By VladimirMangos?.

Original author: megamage
Date: 2008-11-17 19:39:24-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                 implemented 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 default intellect, 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  implemented 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 process.
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 *triggeredSpellInfo = 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 (triggeredSpellInfo == NULL)
1213    {
1214        switch(auraSpellInfo->SpellFamilyName)
1215        {
1216            case SPELLFAMILY_GENERIC:
1217            {
1218                switch(auraId)
1219                {
1220                    // Firestone Passive (1-5 ranks)
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 ranks)
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        triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1827        if(triggeredSpellInfo == 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 custom 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 instead 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 intellectLoss = 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: intellectLoss += (*i)->GetModifier()->m_amount; break;
1863                            case STAT_SPIRIT:    spiritLoss   += (*i)->GetModifier()->m_amount; break;
1864                            default: break;
1865                        }
1866                    }
1867                }
1868
1869                if(intellectLoss <= -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, triggeredSpellInfo, true, 0, this, originalCasterGUID);
1885}
1886
1887Unit* Aura::GetTriggerTarget() const
1888{
1889    Unit* target = ObjectAccessor::GetUnit(*m_target,
1890        /*m_target->GetTypeId()==TYPEID_PLAYER ?
1891        ((Player*)m_target)->GetSelection() :*/
1892        m_target->GetUInt64Value(UNIT_FIELD_TARGET));
1893    return target ? target : m_target;
1894}
1895
1896/*********************************************************/
1897/***                  AURA EFFECTS                     ***/
1898/*********************************************************/
1899
1900void Aura::HandleAuraDummy(bool apply, bool Real)
1901{
1902    // spells required only Real aura add/remove
1903    if(!Real)
1904        return;
1905
1906    Unit* caster = GetCaster();
1907
1908    // AT APPLY
1909    if(apply)
1910    {
1911        switch(GetId())
1912        {
1913            case 1515:                                      // Tame beast
1914                // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
1915                if( caster && m_target->CanHaveThreatList())
1916                    m_target->AddThreat(caster, 10.0f);
1917                return;
1918            case 13139:                                     // net-o-matic
1919                // root to self part of (root_target->charge->root_self sequence
1920                if(caster)
1921                    caster->CastSpell(caster,13138,true,NULL,this);
1922                return;
1923            case 39850:                                     // Rocket Blast
1924                if(roll_chance_i(20))                       // backfire stun
1925                    m_target->CastSpell(m_target, 51581, true, NULL, this);
1926                return;
1927            case 43873:                                     // Headless Horseman Laugh
1928                if(caster->GetTypeId() == TYPEID_PLAYER)
1929                    ((Player*)caster)->SendPlaySound(11965, false);
1930                return;
1931            case 46354:                                     // Blood Elf Illusion
1932                if(caster)
1933                {
1934                    switch(caster->getGender())
1935                    {
1936                        case GENDER_FEMALE:
1937                            caster->CastSpell(m_target,46356,true,NULL,this);
1938                            break;
1939                        case GENDER_MALE:
1940                            caster->CastSpell(m_target,46355,true,NULL,this);
1941                            break;
1942                        default:
1943                            break;
1944                    }
1945                }
1946                return;
1947            case 46699:                                     // Requires No Ammo
1948                if(m_target->GetTypeId()==TYPEID_PLAYER)
1949                    ((Player*)m_target)->RemoveAmmo();      // not use ammo and not allow use
1950                return;
1951        }
1952
1953        // Earth Shield
1954        if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & 0x40000000000LL))
1955        {
1956            // prevent double apply bonuses
1957            if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
1958                m_modifier.m_amount = caster->SpellHealingBonus(GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE, m_target);
1959            return;
1960        }
1961    }
1962    // AT REMOVE
1963    else
1964    {
1965        if( m_target->GetTypeId() == TYPEID_PLAYER && GetSpellProto()->Effect[0]==72 )
1966        {
1967            // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
1968            ((Player*)m_target)->ClearFarsight();
1969            return;
1970        }
1971
1972        if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
1973        {
1974            uint32 finalSpelId = 0;
1975            switch(GetId())
1976            {
1977                case 19548: finalSpelId = 19597; break;
1978                case 19674: finalSpelId = 19677; break;
1979                case 19687: finalSpelId = 19676; break;
1980                case 19688: finalSpelId = 19678; break;
1981                case 19689: finalSpelId = 19679; break;
1982                case 19692: finalSpelId = 19680; break;
1983                case 19693: finalSpelId = 19684; break;
1984                case 19694: finalSpelId = 19681; break;
1985                case 19696: finalSpelId = 19682; break;
1986                case 19697: finalSpelId = 19683; break;
1987                case 19699: finalSpelId = 19685; break;
1988                case 19700: finalSpelId = 19686; break;
1989                case 30646: finalSpelId = 30647; break;
1990                case 30653: finalSpelId = 30648; break;
1991                case 30654: finalSpelId = 30652; break;
1992                case 30099: finalSpelId = 30100; break;
1993                case 30102: finalSpelId = 30103; break;
1994                case 30105: finalSpelId = 30104; break;
1995            }
1996
1997            if(finalSpelId)
1998                caster->CastSpell(m_target,finalSpelId,true,NULL,this);
1999            return;
2000        }
2001
2002        // Waiting to Resurrect
2003        if(GetId()==2584)
2004        {
2005            // Waiting to resurrect spell cancel, we must remove player from resurrect queue
2006            if(m_target->GetTypeId() == TYPEID_PLAYER)
2007                if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
2008                    bg->RemovePlayerFromResurrectQueue(m_target->GetGUID());
2009            return;
2010        }
2011
2012        // Dark Fiend
2013        /*if(GetId()==45934)
2014        {
2015            // Kill target if dispelled
2016            if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2017                m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2018            return;
2019        }*/
2020
2021        // Burning Winds
2022        if(GetId()==46308)                                  // casted only at creatures at spawn
2023        {
2024            m_target->CastSpell(m_target,47287,true,NULL,this);
2025            return;
2026        }
2027
2028        // Eye of Kilrogg, unsummon eye when aura is gone
2029        if(GetId() == 126 && caster->GetTypeId() == TYPEID_PLAYER && caster->GetCharm())
2030        {
2031            ((TemporarySummon*)caster->GetCharm())->UnSummon();
2032            return;
2033        }
2034    }
2035
2036    // AT APPLY & REMOVE
2037
2038    switch(m_spellProto->SpellFamilyName)
2039    {
2040        case SPELLFAMILY_GENERIC:
2041        {
2042            // Unstable Power
2043            if( GetId()==24658 )
2044            {
2045                uint32 spellId = 24659;
2046                if (apply)
2047                {
2048                    const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2049                    if (!spell)
2050                        return;
2051                    for (int i=0; i < spell->StackAmount; ++i)
2052                        caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2053                    return;
2054                }
2055                m_target->RemoveAurasDueToSpell(spellId);
2056                return;
2057            }
2058            // Restless Strength
2059            if( GetId()==24661 )
2060            {
2061                uint32 spellId = 24662;
2062                if (apply)
2063                {
2064                    const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2065                    if (!spell)
2066                        return;
2067                    for (int i=0; i < spell->StackAmount; ++i)
2068                        caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2069                    return;
2070                }
2071                m_target->RemoveAurasDueToSpell(spellId);
2072                return;
2073            }
2074            // Victorious
2075            if(GetId()==32216 && m_target->getClass()==CLASS_WARRIOR)
2076            {
2077                m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, apply);
2078                return;
2079            }
2080            //Summon Fire Elemental
2081            if (GetId() == 40133 && caster)
2082            {
2083                Unit *owner = caster->GetOwner();
2084                if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2085                {
2086                    if(apply)
2087                        owner->CastSpell(owner,8985,true);
2088                    else
2089                        ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2090                }
2091                return;
2092            }
2093
2094            //Summon Earth Elemental
2095            if (GetId() == 40132 && caster)
2096            {
2097                Unit *owner = caster->GetOwner();
2098                if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2099                {
2100                    if(apply)
2101                        owner->CastSpell(owner,19704,true);
2102                    else
2103                        ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2104                }
2105                return;
2106            }
2107            break;
2108        }
2109        case SPELLFAMILY_MAGE:
2110        {
2111            // Hypothermia
2112            if( GetId()==41425 )
2113            {
2114                m_target->ModifyAuraState(AURA_STATE_HYPOTHERMIA,apply);
2115                return;
2116            }
2117            break;
2118        }
2119        case SPELLFAMILY_DRUID:
2120        {
2121            // Lifebloom
2122            if ( GetSpellProto()->SpellFamilyFlags & 0x1000000000LL )
2123            {
2124                if ( apply )
2125                {
2126                    if ( caster )
2127                        // prevent double apply bonuses
2128                        if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2129                            m_modifier.m_amount = caster->SpellHealingBonus(GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE, m_target);
2130                }
2131                else
2132                {
2133                    // Final heal only on dispelled or duration end
2134                    if ( !(GetAuraDuration() <= 0 || m_removeMode==AURA_REMOVE_BY_DISPEL) )
2135                        return;
2136
2137                    // have a look if there is still some other Lifebloom dummy aura
2138                    Unit::AuraList auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2139                    for(Unit::AuraList::iterator itr = auras.begin(); itr!=auras.end(); itr++)
2140                        if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2141                            (*itr)->GetSpellProto()->SpellFamilyFlags & 0x1000000000LL)
2142                            return;
2143
2144                    // final heal
2145                    m_target->CastCustomSpell(m_target,33778,&m_modifier.m_amount,NULL,NULL,true,NULL,this,GetCasterGUID());
2146                }
2147                return;
2148            }
2149
2150            // Predatory Strikes
2151            if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2152            {
2153                ((Player*)m_target)->UpdateAttackPowerAndDamage();
2154                return;
2155            }
2156            // Idol of the Emerald Queen
2157            if ( GetId() == 34246 && m_target->GetTypeId()==TYPEID_PLAYER )
2158            {
2159                if(apply)
2160                {
2161                    SpellModifier *mod = new SpellModifier;
2162                    mod->op = SPELLMOD_DOT;
2163                    mod->value = m_modifier.m_amount/7;
2164                    mod->type = SPELLMOD_FLAT;
2165                    mod->spellId = GetId();
2166                    mod->effectId = m_effIndex;
2167                    mod->lastAffected = NULL;
2168                    mod->mask = 0x001000000000LL;
2169                    mod->charges = 0;
2170
2171                    m_spellmod = mod;
2172                }
2173
2174                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2175                return;
2176            }
2177            break;
2178        }
2179        case SPELLFAMILY_HUNTER:
2180        {
2181            // Improved Aspect of the Viper
2182            if( GetId()==38390 && m_target->GetTypeId()==TYPEID_PLAYER )
2183            {
2184                if(apply)
2185                {
2186                    // + effect value for Aspect of the Viper
2187                    SpellModifier *mod = new SpellModifier;
2188                    mod->op = SPELLMOD_EFFECT1;
2189                    mod->value = m_modifier.m_amount;
2190                    mod->type = SPELLMOD_FLAT;
2191                    mod->spellId = GetId();
2192                    mod->effectId = m_effIndex;
2193                    mod->lastAffected = NULL;
2194                    mod->mask = 0x4000000000000LL;
2195                    mod->charges = 0;
2196
2197                    m_spellmod = mod;
2198                }
2199
2200                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2201                return;
2202            }
2203            break;
2204        }
2205        case SPELLFAMILY_SHAMAN:
2206        {
2207            // Improved Weapon Totems
2208            if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2209            {
2210                if(apply)
2211                {
2212                    SpellModifier *mod = new SpellModifier;
2213                    mod->op = SPELLMOD_EFFECT1;
2214                    mod->value = m_modifier.m_amount;
2215                    mod->type = SPELLMOD_PCT;
2216                    mod->spellId = GetId();
2217                    mod->effectId = m_effIndex;
2218                    mod->lastAffected = NULL;
2219                    switch (m_effIndex)
2220                    {
2221                        case 0:
2222                            mod->mask = 0x00200000000LL;    // Windfury Totem
2223                            break;
2224                        case 1:
2225                            mod->mask = 0x00400000000LL;    // Flametongue Totem
2226                            break;
2227                    }
2228                    mod->charges = 0;
2229
2230                    m_spellmod = mod;
2231                }
2232
2233                ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2234                return;
2235            }
2236
2237            // Sentry Totem
2238            if (GetId() == 6495 && caster->GetTypeId() == TYPEID_PLAYER)
2239            {
2240                if (apply)
2241                {
2242                    uint64 guid = caster->m_TotemSlot[3];
2243                    if (guid)
2244                    {
2245                        Creature *totem = ObjectAccessor::GetCreature(*caster, guid);
2246                        if (totem && totem->isTotem())
2247                            totem->AddPlayerToVision((Player*)caster);
2248                    }
2249                } 
2250                else
2251                    ((Player*)caster)->RemoveFarsightTarget();
2252                return;
2253            }
2254            break;
2255        }
2256    }
2257
2258    // pet auras
2259    if(PetAura const* petSpell = spellmgr.GetPetAura(GetId()))
2260    {
2261        if(apply)
2262            m_target->AddPetAura(petSpell);
2263        else
2264            m_target->RemovePetAura(petSpell);
2265        return;
2266    }
2267}
2268
2269void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
2270{
2271    // spells required only Real aura add/remove
2272    if(!Real)
2273        return;
2274
2275    SpellEntry const*spell = GetSpellProto();
2276    switch( spell->SpellFamilyName)
2277    {
2278        case SPELLFAMILY_ROGUE:
2279        {
2280            // Master of Subtlety
2281            if (spell->Id==31666 && !apply && Real)
2282            {
2283                m_target->RemoveAurasDueToSpell(31665);
2284                break;
2285            }
2286            break;
2287        }
2288        case SPELLFAMILY_HUNTER:
2289        {
2290            // Aspect of the Viper
2291            if (spell->SpellFamilyFlags&0x0004000000000000LL)
2292            {
2293                // Update regen on remove
2294                if (!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2295                    ((Player*)m_target)->UpdateManaRegen();
2296                break;
2297            }
2298            break;
2299        }
2300    }
2301
2302    m_isPeriodic = apply;
2303}
2304
2305void Aura::HandleAuraMounted(bool apply, bool Real)
2306{
2307    if(apply)
2308    {
2309        CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2310        if(!ci)
2311        {
2312            sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2313            return;
2314        }
2315
2316        uint32 team = 0;
2317        if (m_target->GetTypeId()==TYPEID_PLAYER)
2318            team = ((Player*)m_target)->GetTeam();
2319
2320        uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2321        CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2322        if (minfo)
2323            display_id = minfo->modelid;
2324
2325        m_target->Mount(display_id);
2326    }
2327    else
2328    {
2329        m_target->Unmount();
2330    }
2331}
2332
2333void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2334{
2335    // only at real add/remove aura
2336    if(!Real)
2337        return;
2338
2339    WorldPacket data;
2340    if(apply)
2341        data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2342    else
2343        data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2344    data.append(m_target->GetPackGUID());
2345    data << uint32(0);
2346    m_target->SendMessageToSet(&data,true);
2347}
2348
2349void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2350{
2351    // only at real add/remove aura
2352    if(!Real)
2353        return;
2354
2355    WorldPacket data;
2356    if(apply)
2357        data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2358    else
2359        data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2360    data.append(m_target->GetPackGUID());
2361    data << (uint32)0;
2362    m_target->SendMessageToSet(&data,true);
2363}
2364
2365void Aura::HandleAuraHover(bool apply, bool Real)
2366{
2367    // only at real add/remove aura
2368    if(!Real)
2369        return;
2370
2371    WorldPacket data;
2372    if(apply)
2373        data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2374    else
2375        data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2376    data.append(m_target->GetPackGUID());
2377    data << uint32(0);
2378    m_target->SendMessageToSet(&data,true);
2379}
2380
2381void Aura::HandleWaterBreathing(bool apply, bool Real)
2382{
2383    if(apply)
2384        m_target->waterbreath = true;
2385    else if(m_target->GetAurasByType(SPELL_AURA_WATER_BREATHING).empty())
2386    {
2387        m_target->waterbreath = false;
2388
2389        // update for enable timer in case not moving target
2390        if(m_target->GetTypeId()==TYPEID_PLAYER && m_target->IsInWorld())
2391        {
2392            ((Player*)m_target)->UpdateUnderwaterState(m_target->GetMap(),m_target->GetPositionX(),m_target->GetPositionY(),m_target->GetPositionZ());
2393            ((Player*)m_target)->HandleDrowning();
2394        }
2395    }
2396}
2397
2398void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2399{
2400    if(!Real)
2401        return;
2402
2403    uint32 modelid = 0;
2404    Powers PowerType = POWER_MANA;
2405    ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2406    switch(form)
2407    {
2408        case FORM_CAT:
2409            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2410                modelid = 892;
2411            else
2412                modelid = 8571;
2413            PowerType = POWER_ENERGY;
2414            break;
2415        case FORM_TRAVEL:
2416            modelid = 632;
2417            break;
2418        case FORM_AQUA:
2419            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2420                modelid = 2428;
2421            else
2422                modelid = 2428;
2423            break;
2424        case FORM_BEAR:
2425            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2426                modelid = 2281;
2427            else
2428                modelid = 2289;
2429            PowerType = POWER_RAGE;
2430            break;
2431        case FORM_GHOUL:
2432            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2433                modelid = 10045;
2434            break;
2435        case FORM_DIREBEAR:
2436            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2437                modelid = 2281;
2438            else
2439                modelid = 2289;
2440            PowerType = POWER_RAGE;
2441            break;
2442        case FORM_CREATUREBEAR:
2443            modelid = 902;
2444            break;
2445        case FORM_GHOSTWOLF:
2446            modelid = 4613;
2447            break;
2448        case FORM_FLIGHT:
2449            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2450                modelid = 20857;
2451            else
2452                modelid = 20872;
2453            break;
2454        case FORM_MOONKIN:
2455            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2456                modelid = 15374;
2457            else
2458                modelid = 15375;
2459            break;
2460        case FORM_FLIGHT_EPIC:
2461            if(Player::TeamForRace(m_target->getRace())==ALLIANCE)
2462                modelid = 21243;
2463            else
2464                modelid = 21244;
2465            break;
2466        case FORM_AMBIENT:
2467        case FORM_SHADOW:
2468        case FORM_STEALTH:
2469            break;
2470        case FORM_TREE:
2471            modelid = 864;
2472            break;
2473        case FORM_BATTLESTANCE:
2474        case FORM_BERSERKERSTANCE:
2475        case FORM_DEFENSIVESTANCE:
2476            PowerType = POWER_RAGE;
2477            break;
2478        case FORM_SPIRITOFREDEMPTION:
2479            modelid = 16031;
2480            break;
2481        default:
2482            sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2483    }
2484
2485    // remove polymorph before changing display id to keep new display id
2486    switch ( form )
2487    {
2488        case FORM_CAT:
2489        case FORM_TREE:
2490        case FORM_TRAVEL:
2491        case FORM_AQUA:
2492        case FORM_BEAR:
2493        case FORM_DIREBEAR:
2494        case FORM_FLIGHT_EPIC:
2495        case FORM_FLIGHT:
2496        case FORM_MOONKIN:
2497            // remove movement affects
2498            m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2499            m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2500
2501            // and polymorphic affects
2502            if(m_target->IsPolymorphed())
2503                m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2504            break;
2505        default:
2506           break;
2507    }
2508
2509    if(apply)
2510    {
2511        // remove other shapeshift before applying a new one
2512        if(m_target->m_ShapeShiftFormSpellId)
2513            m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId,this);
2514
2515        m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2516
2517        if(modelid > 0)
2518            m_target->SetDisplayId(modelid);
2519
2520        if(PowerType != POWER_MANA)
2521        {
2522            // reset power to default values only at power change
2523            if(m_target->getPowerType()!=PowerType)
2524                m_target->setPowerType(PowerType);
2525
2526            switch(form)
2527            {
2528                case FORM_CAT:
2529                case FORM_BEAR:
2530                case FORM_DIREBEAR:
2531                {
2532                    // get furor proc chance
2533                    uint32 FurorChance = 0;
2534                    Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2535                    for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2536                    {
2537                        if ((*i)->GetSpellProto()->SpellIconID == 238)
2538                        {
2539                            FurorChance = (*i)->GetModifier()->m_amount;
2540                            break;
2541                        }
2542                    }
2543
2544                    if (m_modifier.m_miscvalue == FORM_CAT)
2545                    {
2546                        m_target->SetPower(POWER_ENERGY,0);
2547                        if(urand(1,100) <= FurorChance)
2548                            m_target->CastSpell(m_target,17099,true,NULL,this);
2549                    }
2550                    else
2551                    {
2552                        m_target->SetPower(POWER_RAGE,0);
2553                        if(urand(1,100) <= FurorChance)
2554                            m_target->CastSpell(m_target,17057,true,NULL,this);
2555                    }
2556                    break;
2557                }
2558                case FORM_BATTLESTANCE:
2559                case FORM_DEFENSIVESTANCE:
2560                case FORM_BERSERKERSTANCE:
2561                {
2562                    uint32 Rage_val = 0;
2563                    // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2564                    if(m_target->GetTypeId() == TYPEID_PLAYER)
2565                    {
2566                        PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2567                        for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2568                        {
2569                            if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2570                            SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2571                            if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2572                                Rage_val += m_target->CalculateSpellDamage(spellInfo,0,spellInfo->EffectBasePoints[0],m_target) * 10;
2573                        }
2574                    }
2575
2576                    if (m_target->GetPower(POWER_RAGE) > Rage_val)
2577                        m_target->SetPower(POWER_RAGE,Rage_val);
2578                    break;
2579                }
2580                default:
2581                    break;
2582            }
2583        }
2584
2585        m_target->m_ShapeShiftFormSpellId = GetId();
2586        m_target->m_form = form;
2587    }
2588    else
2589    {
2590        if(modelid > 0)
2591            m_target->SetDisplayId(m_target->GetNativeDisplayId());
2592        m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2593        if(m_target->getClass() == CLASS_DRUID)
2594            m_target->setPowerType(POWER_MANA);
2595        m_target->m_ShapeShiftFormSpellId = 0;
2596        m_target->m_form = FORM_NONE;
2597
2598        switch(form)
2599        {
2600            // Nordrassil Harness - bonus
2601            case FORM_BEAR:
2602            case FORM_DIREBEAR:
2603            case FORM_CAT:
2604            {
2605                if(Aura* dummy = m_target->GetDummyAura(37315) )
2606                    m_target->CastSpell(m_target,37316,true,NULL,dummy);
2607                break;
2608            }
2609            // Nordrassil Regalia - bonus
2610            case FORM_MOONKIN:
2611            {
2612                if(Aura* dummy = m_target->GetDummyAura(37324) )
2613                    m_target->CastSpell(m_target,37325,true,NULL,dummy);
2614                break;
2615            }
2616        }
2617    }
2618
2619    // adding/removing linked auras
2620    // add/remove the shapeshift aura's boosts
2621    HandleShapeshiftBoosts(apply);
2622
2623    if(m_target->GetTypeId()==TYPEID_PLAYER)
2624        ((Player*)m_target)->InitDataForForm();
2625}
2626
2627void Aura::HandleAuraTransform(bool apply, bool Real)
2628{
2629    if (apply)
2630    {
2631        // special case (spell specific functionality)
2632        if(m_modifier.m_miscvalue==0)
2633        {
2634            // player applied only
2635            if(m_target->GetTypeId()!=TYPEID_PLAYER)
2636                return;
2637
2638            switch(GetId())
2639            {
2640                // Orb of Deception
2641                case 16739:
2642                {
2643                    uint32 orb_model = m_target->GetNativeDisplayId();
2644                    switch(orb_model)
2645                    {
2646                        // Troll Female
2647                        case 1479: m_target->SetDisplayId(10134); break;
2648                        // Troll Male
2649                        case 1478: m_target->SetDisplayId(10135); break;
2650                        // Tauren Male
2651                        case 59:   m_target->SetDisplayId(10136); break;
2652                        // Human Male
2653                        case 49:   m_target->SetDisplayId(10137); break;
2654                        // Human Female
2655                        case 50:   m_target->SetDisplayId(10138); break;
2656                        // Orc Male
2657                        case 51:   m_target->SetDisplayId(10139); break;
2658                        // Orc Female
2659                        case 52:   m_target->SetDisplayId(10140); break;
2660                        // Dwarf Male
2661                        case 53:   m_target->SetDisplayId(10141); break;
2662                        // Dwarf Female
2663                        case 54:   m_target->SetDisplayId(10142); break;
2664                        // NightElf Male
2665                        case 55:   m_target->SetDisplayId(10143); break;
2666                        // NightElf Female
2667                        case 56:   m_target->SetDisplayId(10144); break;
2668                        // Undead Female
2669                        case 58:   m_target->SetDisplayId(10145); break;
2670                        // Undead Male
2671                        case 57:   m_target->SetDisplayId(10146); break;
2672                        // Tauren Female
2673                        case 60:   m_target->SetDisplayId(10147); break;
2674                        // Gnome Male
2675                        case 1563: m_target->SetDisplayId(10148); break;
2676                        // Gnome Female
2677                        case 1564: m_target->SetDisplayId(10149); break;
2678                        // BloodElf Female
2679                        case 15475: m_target->SetDisplayId(17830); break;
2680                        // BloodElf Male
2681                        case 15476: m_target->SetDisplayId(17829); break;
2682                        // Dranei Female
2683                        case 16126: m_target->SetDisplayId(17828); break;
2684                        // Dranei Male
2685                        case 16125: m_target->SetDisplayId(17827); break;
2686                        default: break;
2687                    }
2688                    break;
2689                }
2690                // Murloc costume
2691                case 42365: m_target->SetDisplayId(21723); break;
2692                default: break;
2693            }
2694        }
2695        else
2696        {
2697            CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2698            if(!ci)
2699            {
2700                                                            //pig pink ^_^
2701                m_target->SetDisplayId(16358);
2702                sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
2703            }
2704            else
2705            {
2706                if (uint32 modelid = ci->GetRandomValidModelId()) m_target->SetDisplayId(modelid);
2707
2708                // Dragonmaw Illusion (set mount model also)
2709                if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
2710                    m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
2711            }
2712            m_target->setTransForm(GetId());
2713        }
2714
2715        // polymorph case
2716        if( Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
2717        {
2718            // for players, start regeneration after 1s (in polymorph fast regeneration case)
2719            // only if caster is Player (after patch 2.4.2)
2720            if(IS_PLAYER_GUID(GetCasterGUID()) )
2721                ((Player*)m_target)->setRegenTimer(1000);
2722
2723            //dismount polymorphed target (after patch 2.4.2)
2724            if (m_target->IsMounted())
2725                m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
2726        }
2727    }
2728    else
2729    {
2730        Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
2731        if(otherTransforms.empty())
2732        {
2733            m_target->SetDisplayId(m_target->GetNativeDisplayId());
2734            m_target->setTransForm(0);
2735        }
2736        else
2737        {
2738            // look for other transform auras
2739            Aura* handledAura = *otherTransforms.begin();
2740            for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
2741            {
2742                // negative auras are preferred
2743                if(!IsPositiveSpell((*i)->GetSpellProto()->Id))
2744                {
2745                    handledAura = *i;
2746                    break;
2747                }
2748            }
2749            handledAura->ApplyModifier(true);
2750        }
2751
2752        // Dragonmaw Illusion (restore mount model)
2753        if(GetId()==42016 && m_target->GetMountID()==16314)
2754        {
2755            if(!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
2756            {
2757                uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
2758                if(CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
2759                {
2760                    uint32 team = 0;
2761                    if (m_target->GetTypeId()==TYPEID_PLAYER)
2762                        team = ((Player*)m_target)->GetTeam();
2763
2764                    uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2765                    CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2766                    if (minfo)
2767                        display_id = minfo->modelid;
2768
2769                    m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,display_id);
2770                }
2771            }
2772        }
2773    }
2774}
2775
2776void Aura::HandleForceReaction(bool apply, bool Real)
2777{
2778    if(m_target->GetTypeId() != TYPEID_PLAYER)
2779        return;
2780
2781    if(!Real)
2782        return;
2783
2784    Player* player = (Player*)m_target;
2785
2786    uint32 faction_id = m_modifier.m_miscvalue;
2787    uint32 faction_rank = m_modifier.m_amount;
2788
2789    if(apply)
2790        player->m_forcedReactions[faction_id] = ReputationRank(faction_rank);
2791    else
2792        player->m_forcedReactions.erase(faction_id);
2793
2794    WorldPacket data;
2795    data.Initialize(SMSG_SET_FORCED_REACTIONS, 4+player->m_forcedReactions.size()*(4+4));
2796    data << uint32(player->m_forcedReactions.size());
2797    for(ForcedReactions::const_iterator itr = player->m_forcedReactions.begin(); itr != player->m_forcedReactions.end(); ++itr)
2798    {
2799        data << uint32(itr->first);                         // faction_id (Faction.dbc)
2800        data << uint32(itr->second);                        // reputation rank
2801    }
2802    player->SendDirectMessage(&data);
2803}
2804
2805void Aura::HandleAuraModSkill(bool apply, bool Real)
2806{
2807    if(m_target->GetTypeId() != TYPEID_PLAYER)
2808        return;
2809
2810    uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
2811    int32 points = GetModifier()->m_amount;
2812
2813    ((Player*)m_target)->ModifySkillBonus(prot,(apply ? points: -points),m_modifier.m_auraname==SPELL_AURA_MOD_SKILL_TALENT);
2814    if(prot == SKILL_DEFENSE)
2815        ((Player*)m_target)->UpdateDefenseBonusesMod();
2816}
2817
2818void Aura::HandleChannelDeathItem(bool apply, bool Real)
2819{
2820    if(Real && !apply)
2821    {
2822        Unit* caster = GetCaster();
2823        Unit* victim = GetTarget();
2824        if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode!=AURA_REMOVE_BY_DEATH)
2825            return;
2826
2827        SpellEntry const *spellInfo = GetSpellProto();
2828        if(spellInfo->EffectItemType[m_effIndex] == 0)
2829            return;
2830
2831        // Soul Shard only from non-grey units
2832        if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
2833            (victim->getLevel() <= Trinity::XP::GetGrayLevel(caster->getLevel()) ||
2834             victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
2835            return;
2836        ItemPosCountVec dest;
2837        uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], 1 );
2838        if( msg != EQUIP_ERR_OK )
2839        {
2840            ((Player*)caster)->SendEquipError( msg, NULL, NULL );
2841            return;
2842        }
2843
2844        Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
2845        ((Player*)caster)->SendNewItem(newitem, 1, true, false);
2846    }
2847}
2848
2849void Aura::HandleBindSight(bool apply, bool Real)
2850{
2851    Unit* caster = GetCaster();
2852    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2853        return;
2854
2855    if (apply)
2856        m_target->AddPlayerToVision((Player*)caster);
2857    else
2858        m_target->RemovePlayerFromVision((Player*)caster);
2859}
2860
2861void Aura::HandleFarSight(bool apply, bool Real)
2862{
2863    Unit* caster = GetCaster();
2864    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2865        return;
2866
2867    caster->SetUInt64Value(PLAYER_FARSIGHT,apply ? m_modifier.m_miscvalue : 0);
2868}
2869
2870void Aura::HandleAuraTrackCreatures(bool apply, bool Real)
2871{
2872    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2873        return;
2874
2875    if(apply)
2876        m_target->RemoveNoStackAurasDueToAura(this);
2877    m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
2878}
2879
2880void Aura::HandleAuraTrackResources(bool apply, bool Real)
2881{
2882    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2883        return;
2884
2885    if(apply)
2886        m_target->RemoveNoStackAurasDueToAura(this);
2887    m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
2888}
2889
2890void Aura::HandleAuraTrackStealthed(bool apply, bool Real)
2891{
2892    if(m_target->GetTypeId()!=TYPEID_PLAYER)
2893        return;
2894
2895    if(apply)
2896        m_target->RemoveNoStackAurasDueToAura(this);
2897
2898    m_target->ApplyModFlag(PLAYER_FIELD_BYTES,PLAYER_FIELD_BYTE_TRACK_STEALTHED,apply);
2899}
2900
2901void Aura::HandleAuraModScale(bool apply, bool Real)
2902{
2903    m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X,m_modifier.m_amount,apply);
2904}
2905
2906void Aura::HandleModPossess(bool apply, bool Real)
2907{
2908    if(!Real)
2909        return;
2910
2911    if(m_target->getLevel() > m_modifier.m_amount)
2912        return;
2913
2914    // not possess yourself
2915    if(GetCasterGUID() == m_target->GetGUID())
2916        return;
2917
2918    Unit* caster = GetCaster();
2919    if(!caster)
2920        return;
2921
2922    if( apply )
2923    {
2924        if (caster->GetTypeId() == TYPEID_PLAYER)
2925            ((Player*)caster)->Possess(m_target);
2926    }
2927    else
2928        m_target->UnpossessSelf(true);
2929}
2930
2931void Aura::HandleModPossessPet(bool apply, bool Real)
2932{
2933    if(!Real)
2934        return;
2935
2936    Unit* caster = GetCaster();
2937    if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
2938        return;
2939    if(caster->GetPet() != m_target)
2940        return;
2941
2942    if(apply)
2943    {
2944        ((Player*)caster)->Possess(m_target);
2945    }
2946    else
2947    {
2948        ((Player*)caster)->RemovePossess(false);
2949    }
2950}
2951
2952void Aura::HandleModCharm(bool apply, bool Real)
2953{
2954    if(!Real)
2955        return;
2956
2957    // not charm yourself
2958    if(GetCasterGUID() == m_target->GetGUID())
2959        return;
2960
2961    Unit* caster = GetCaster();
2962    if(!caster)
2963        return;
2964
2965    if(int32(m_target->getLevel()) <= m_modifier.m_amount)
2966    {
2967        if( apply )
2968        {
2969            m_target->SetCharmerGUID(GetCasterGUID());
2970            m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,caster->getFaction());
2971            m_target->CastStop(m_target==caster ? GetId() : 0);
2972            caster->SetCharm(m_target);
2973
2974            m_target->CombatStop();
2975            m_target->DeleteThreatList();
2976
2977            if(m_target->GetTypeId() == TYPEID_UNIT)
2978            {
2979                ((Creature*)m_target)->AIM_Initialize();
2980                CharmInfo *charmInfo = ((Creature*)m_target)->InitCharmInfo(m_target);
2981                charmInfo->InitCharmCreateSpells();
2982                charmInfo->SetReactState( REACT_DEFENSIVE );
2983
2984                if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
2985                {
2986                    CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
2987                    if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
2988                    {
2989                        //to prevent client crash
2990                        m_target->SetFlag(UNIT_FIELD_BYTES_0, 2048);
2991                        //just to enable stat window
2992                        charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
2993                        //if charmed two demons the same session, the 2nd gets the 1st one's name
2994                        m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
2995                    }
2996                }
2997            }
2998
2999            if(caster->GetTypeId() == TYPEID_PLAYER)
3000            {
3001                ((Player*)caster)->CharmSpellInitialize();
3002            }
3003        }
3004        else
3005        {
3006            m_target->SetCharmerGUID(0);
3007
3008            if(m_target->GetTypeId() == TYPEID_PLAYER)
3009                ((Player*)m_target)->setFactionForRace(m_target->getRace());
3010            else
3011            {
3012                CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3013
3014                // restore faction
3015                if(((Creature*)m_target)->isPet())
3016                {
3017                    if(Unit* owner = m_target->GetOwner())
3018                        m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction());
3019                    else if(cinfo)
3020                        m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
3021                }
3022                else if(cinfo)                              // normal creature
3023                    m_target->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,cinfo->faction_A);
3024
3025                // restore UNIT_FIELD_BYTES_0
3026                if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3027                {
3028                    CreatureDataAddon const *cainfo = ((Creature*)m_target)->GetCreatureAddon();
3029                    if(cainfo && cainfo->bytes0 != 0)
3030                        m_target->SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0);
3031                    else
3032                        m_target->RemoveFlag(UNIT_FIELD_BYTES_0, 2048);
3033
3034                    if(m_target->GetCharmInfo())
3035                        m_target->GetCharmInfo()->SetPetNumber(0, true);
3036                    else
3037                        sLog.outError("Aura::HandleModCharm: target="I64FMTD" with typeid=%d has a charm aura but no charm info!", m_target->GetGUID(), m_target->GetTypeId());
3038                }
3039            }
3040
3041            caster->SetCharm(0);
3042
3043            if(caster->GetTypeId() == TYPEID_PLAYER)
3044            {
3045                WorldPacket data(SMSG_PET_SPELLS, 8);
3046                data << uint64(0);
3047                ((Player*)caster)->GetSession()->SendPacket(&data);
3048            }
3049            if(m_target->GetTypeId() == TYPEID_UNIT)
3050            {
3051                ((Creature*)m_target)->AIM_Initialize();
3052                if (((Creature*)m_target)->AI())
3053                    ((Creature*)m_target)->AI()->AttackStart(caster);
3054            }
3055        }
3056    }
3057}
3058
3059void Aura::HandleModConfuse(bool apply, bool Real)
3060{
3061    if(!Real)
3062        return;
3063
3064    m_target->SetConfused(apply, GetCasterGUID(), GetId());
3065}
3066
3067void Aura::HandleModFear(bool apply, bool Real)
3068{
3069    if (!Real)
3070        return;
3071
3072    m_target->SetFeared(apply, GetCasterGUID(), GetId());
3073}
3074
3075void Aura::HandleFeignDeath(bool apply, bool Real)
3076{
3077    if(!Real)
3078        return;
3079
3080    if(m_target->GetTypeId() != TYPEID_PLAYER)
3081        return;
3082
3083    if( apply )
3084    {
3085        /*
3086        WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3087        data<<m_target->GetGUID();
3088        data<<uint8(0);
3089        m_target->SendMessageToSet(&data,true);
3090        */
3091                                                            // blizz like 2.0.x
3092        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN6);
3093                                                            // blizz like 2.0.x
3094        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3095                                                            // blizz like 2.0.x
3096        m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3097
3098        m_target->addUnitState(UNIT_STAT_DIED);
3099        m_target->CombatStop();
3100        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3101
3102        // prevent interrupt message
3103        if(m_caster_guid==m_target->GetGUID() && m_target->m_currentSpells[CURRENT_GENERIC_SPELL])
3104            m_target->m_currentSpells[CURRENT_GENERIC_SPELL]->finish();
3105        m_target->InterruptNonMeleeSpells(true);
3106        m_target->getHostilRefManager().deleteReferences();
3107    }
3108    else
3109    {
3110        /*
3111        WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3112        data<<m_target->GetGUID();
3113        data<<uint8(1);
3114        m_target->SendMessageToSet(&data,true);
3115        */
3116                                                            // blizz like 2.0.x
3117        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN6);
3118                                                            // blizz like 2.0.x
3119        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3120                                                            // blizz like 2.0.x
3121        m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3122
3123        m_target->clearUnitState(UNIT_STAT_DIED);
3124    }
3125}
3126
3127void Aura::HandleAuraModDisarm(bool apply, bool Real)
3128{
3129    if(!Real)
3130        return;
3131
3132    if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3133        return;
3134
3135    // not sure for it's correctness
3136    if(apply)
3137        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3138    else
3139        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3140
3141    // only at real add/remove aura
3142    if (m_target->GetTypeId() != TYPEID_PLAYER)
3143        return;
3144
3145    // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3146    if (((Player *)m_target)->IsInFeralForm())
3147        return;
3148
3149    if (apply)
3150        m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3151    else
3152        ((Player *)m_target)->SetRegularAttackTime();
3153
3154    m_target->UpdateDamagePhysical(BASE_ATTACK);
3155}
3156
3157void Aura::HandleAuraModStun(bool apply, bool Real)
3158{
3159    if(!Real)
3160        return;
3161
3162    if (apply)
3163    {
3164        m_target->addUnitState(UNIT_STAT_STUNNED);
3165        m_target->SetUInt64Value(UNIT_FIELD_TARGET, 0);
3166
3167        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE);
3168        m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3169
3170        // Creature specific
3171        if(m_target->GetTypeId() != TYPEID_PLAYER)
3172            ((Creature*)m_target)->StopMoving();
3173        else
3174            m_target->SetUnitMovementFlags(0);    //Clear movement flags
3175
3176        WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3177
3178        data.append(m_target->GetPackGUID());
3179        data << uint32(0);
3180        m_target->SendMessageToSet(&data,true);
3181    }
3182    else
3183    {
3184        // Real remove called after current aura remove from lists, check if other similar auras active
3185        if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3186            return;
3187
3188        m_target->clearUnitState(UNIT_STAT_STUNNED);
3189        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE);
3190
3191        if(!m_target->hasUnitState(UNIT_STAT_ROOT))         // prevent allow move if have also root effect
3192        {
3193            if(m_target->getVictim() && m_target->isAlive())
3194                m_target->SetUInt64Value(UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3195
3196            WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3197            data.append(m_target->GetPackGUID());
3198            data << uint32(0);
3199            m_target->SendMessageToSet(&data,true);
3200        }
3201
3202        // Wyvern Sting
3203        if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1721)
3204        {
3205            Unit* caster = GetCaster();
3206            if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3207                return;
3208
3209            uint32 spell_id = 0;
3210
3211            switch(GetId())
3212            {
3213                case 19386: spell_id = 24131; break;
3214                case 24132: spell_id = 24134; break;
3215                case 24133: spell_id = 24135; break;
3216                case 27068: spell_id = 27069; break;
3217                default:
3218                    sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3219                    return;
3220            }
3221
3222            SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3223
3224            if(!spellInfo)
3225                return;
3226
3227            caster->CastSpell(m_target,spellInfo,true,NULL,this);
3228            return;
3229        }
3230    }
3231}
3232
3233void Aura::HandleModStealth(bool apply, bool Real)
3234{
3235    if(apply)
3236    {
3237        if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3238        {
3239            // drop flag at stealth in bg
3240            m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3241
3242            // remove player from the objective's active player count at stealth
3243            if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3244                pvp->HandlePlayerActivityChanged((Player*)m_target);
3245        }
3246
3247        // only at real aura add
3248        if(Real)
3249        {
3250            m_target->SetByteValue(UNIT_FIELD_BYTES_1, 2, 0x02);
3251            if(m_target->GetTypeId()==TYPEID_PLAYER)
3252                m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3253
3254            // apply only if not in GM invisibility (and overwrite invisibility state)
3255            if(m_target->GetVisibility()!=VISIBILITY_OFF)
3256            {
3257                //m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3258                m_target->SetVisibility(VISIBILITY_OFF);
3259                m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3260            }
3261
3262            // for RACE_NIGHTELF stealth
3263            if(m_target->GetTypeId()==TYPEID_PLAYER && GetId()==20580)
3264                m_target->CastSpell(m_target, 21009, true, NULL, this);
3265        }
3266    }
3267    else
3268    {
3269        // only at real aura remove
3270        if(Real)
3271        {
3272            // for RACE_NIGHTELF stealth
3273            if(m_target->GetTypeId()==TYPEID_PLAYER && GetId()==20580)
3274                m_target->RemoveAurasDueToSpell(21009);
3275
3276            // if last SPELL_AURA_MOD_STEALTH and no GM invisibility
3277            if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH) && m_target->GetVisibility()!=VISIBILITY_OFF)
3278            {
3279                m_target->SetByteValue(UNIT_FIELD_BYTES_1, 2, 0x00);
3280                if(m_target->GetTypeId()==TYPEID_PLAYER)
3281                    m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3282
3283                // restore invisibility if any
3284                if(m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3285                {
3286                    //m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3287                    //m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3288                    m_target->SetVisibility(VISIBILITY_ON);
3289                }
3290                else
3291                {
3292                    m_target->SetVisibility(VISIBILITY_ON);
3293                    if(m_target->GetTypeId() == TYPEID_PLAYER)
3294                        if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3295                            pvp->HandlePlayerActivityChanged((Player*)m_target);
3296                }
3297            }
3298        }
3299    }
3300
3301    // Master of Subtlety
3302    Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3303    for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3304    {
3305        if ((*i)->GetSpellProto()->SpellIconID == 2114)
3306        {
3307            if (apply)
3308            {
3309                int32 bp = (*i)->GetModifier()->m_amount;
3310                m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3311            }
3312            else
3313                m_target->CastSpell(m_target,31666,true);
3314            break;
3315        }
3316    }
3317}
3318
3319void Aura::HandleInvisibility(bool apply, bool Real)
3320{
3321    if(apply)
3322    {
3323        m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3324
3325        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3326
3327        if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3328        {
3329            // apply glow vision
3330            m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3331            // remove player from the objective's active player count at invisibility
3332            if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3333                pvp->HandlePlayerActivityChanged((Player*)m_target);
3334        }
3335
3336        // apply only if not in GM invisibility and not stealth
3337        if(m_target->GetVisibility()==VISIBILITY_ON)
3338        {
3339            // Aura not added yet but visibility code expect temporary add aura
3340            //m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3341            //m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3342            m_target->SetVisibility(VISIBILITY_ON);
3343        }
3344    }
3345    else
3346    {
3347        // recalculate value at modifier remove (current aura already removed)
3348        m_target->m_invisibilityMask = 0;
3349        Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
3350        for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3351            m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3352
3353        // only at real aura remove and if not have different invisibility auras.
3354        if(Real && m_target->m_invisibilityMask==0)
3355        {
3356            // remove glow vision
3357            if(m_target->GetTypeId() == TYPEID_PLAYER)
3358                m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3359
3360            // apply only if not in GM invisibility & not stealthed while invisible
3361            if(m_target->GetVisibility()!=VISIBILITY_OFF)
3362            {
3363                // if have stealth aura then already have stealth visibility
3364                if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3365                {
3366                    m_target->SetVisibility(VISIBILITY_ON);
3367                    if(m_target->GetTypeId() == TYPEID_PLAYER)
3368                        if(OutdoorPvP * pvp = ((Player*)m_target)->GetOutdoorPvP())
3369                            pvp->HandlePlayerActivityChanged((Player*)m_target);
3370                }
3371            }
3372        }
3373    }
3374}
3375
3376void Aura::HandleInvisibilityDetect(bool apply, bool Real)
3377{
3378    if(apply)
3379    {
3380        m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3381    }
3382    else
3383    {
3384        // recalculate value at modifier remove (current aura already removed)
3385        m_target->m_detectInvisibilityMask = 0;
3386        Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
3387        for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3388            m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3389    }
3390    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3391        ObjectAccessor::UpdateVisibilityForPlayer((Player*)m_target);
3392}
3393
3394void Aura::HandleAuraModRoot(bool apply, bool Real)
3395{
3396    // only at real add/remove aura
3397    if(!Real)
3398        return;
3399
3400    uint32 apply_stat = UNIT_STAT_ROOT;
3401    if (apply)
3402    {
3403        m_target->addUnitState(UNIT_STAT_ROOT);
3404        m_target->SetUInt64Value (UNIT_FIELD_TARGET, 0);
3405                                                            // probably wrong
3406        m_target->SetFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3407
3408        //Save last orientation
3409        if( m_target->getVictim() )
3410            m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
3411
3412        if(m_target->GetTypeId() == TYPEID_PLAYER)
3413        {
3414            WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
3415            data.append(m_target->GetPackGUID());
3416            data << (uint32)2;
3417            m_target->SendMessageToSet(&data,true);
3418
3419            //Clear unit movement flags
3420            m_target->SetUnitMovementFlags(0);
3421        }
3422        else
3423            ((Creature *)m_target)->StopMoving();
3424    }
3425    else
3426    {
3427        // Real remove called after current aura remove from lists, check if other similar auras active
3428        if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
3429            return;
3430
3431        m_target->clearUnitState(UNIT_STAT_ROOT);
3432                                                            // probably wrong
3433        m_target->RemoveFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3434
3435        if(!m_target->hasUnitState(UNIT_STAT_STUNNED))      // prevent allow move if have also stun effect
3436        {
3437            if(m_target->getVictim() && m_target->isAlive())
3438                m_target->SetUInt64Value (UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3439
3440            if(m_target->GetTypeId() == TYPEID_PLAYER)
3441            {
3442                WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
3443                data.append(m_target->GetPackGUID());
3444                data << (uint32)2;
3445                m_target->SendMessageToSet(&data,true);
3446            }
3447        }
3448    }
3449}
3450
3451void Aura::HandleAuraModSilence(bool apply, bool Real)
3452{
3453    // only at real add/remove aura
3454    if(!Real)
3455        return;
3456
3457    if(apply)
3458    {
3459        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3460        // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
3461        for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL;i++)
3462        {
3463            Spell* currentSpell = m_target->m_currentSpells[i];
3464            if (currentSpell && currentSpell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
3465            {
3466                uint32 state = currentSpell->getState();
3467                // Stop spells on prepare or casting state
3468                if ( state == SPELL_STATE_PREPARING || state == SPELL_STATE_CASTING )
3469                {
3470                    currentSpell->cancel();
3471                    currentSpell->SetReferencedFromCurrent(false);
3472                    m_target->m_currentSpells[i] = NULL;
3473                }
3474            }
3475        }
3476
3477        switch (GetId())
3478        {
3479            // Arcane Torrent (Energy)
3480            case 25046:
3481            {
3482                Unit * caster = GetCaster();
3483                if (!caster)
3484                    return;
3485
3486                // Search Mana Tap auras on caster
3487                int32 energy = 0;
3488                Unit::AuraList const& m_dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
3489                for(Unit::AuraList::const_iterator i = m_dummyAuras.begin(); i != m_dummyAuras.end(); ++i)
3490                    if ((*i)->GetId() == 28734)
3491                        ++energy;
3492                if (energy)
3493                {
3494                    energy *= 10;
3495                    caster->CastCustomSpell(caster, 25048, &energy, NULL, NULL, true);
3496                    caster->RemoveAurasDueToSpell(28734);
3497                }
3498            }
3499        }
3500    }
3501    else
3502    {
3503        // Real remove called after current aura remove from lists, check if other similar auras active
3504        if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
3505            return;
3506
3507        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3508    }
3509}
3510
3511void Aura::HandleModThreat(bool apply, bool Real)
3512{
3513    // only at real add/remove aura
3514    if(!Real)
3515        return;
3516
3517    if(!m_target->isAlive())
3518        return;
3519
3520    Unit* caster = GetCaster();
3521
3522    if(!caster || !caster->isAlive())
3523        return;
3524
3525    int level_diff = 0;
3526    int multiplier = 0;
3527    switch (GetId())
3528    {
3529        // Arcane Shroud
3530        case 26400:
3531            level_diff = m_target->getLevel() - 60;
3532            multiplier = 2;
3533            break;
3534        // The Eye of Diminution
3535        case 28862:
3536            level_diff = m_target->getLevel() - 60;
3537            multiplier = 1;
3538            break;
3539    }
3540    if (level_diff > 0)
3541        m_modifier.m_amount += multiplier * level_diff;
3542
3543    for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
3544    {
3545        if(m_modifier.m_miscvalue & int32(1<<x))
3546        {
3547            if(m_target->GetTypeId() == TYPEID_PLAYER)
3548                ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_positive ? m_modifier.m_amount : -m_modifier.m_amount, apply);
3549        }
3550    }
3551}
3552
3553void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
3554{
3555    // only at real add/remove aura
3556    if(!Real)
3557        return;
3558
3559    if(!m_target->isAlive() || m_target->GetTypeId()!= TYPEID_PLAYER)
3560        return;
3561
3562    Unit* caster = GetCaster();
3563
3564    if(!caster || !caster->isAlive())
3565        return;
3566
3567    float threatMod = 0.0f;
3568    if(apply)
3569        threatMod = float(m_modifier.m_amount);
3570    else
3571        threatMod =  float(-m_modifier.m_amount);
3572
3573    m_target->getHostilRefManager().threatAssist(caster, threatMod);
3574}
3575
3576void Aura::HandleModTaunt(bool apply, bool Real)
3577{
3578    // only at real add/remove aura
3579    if(!Real)
3580        return;
3581
3582    if(!m_target->isAlive() || !m_target->CanHaveThreatList())
3583        return;
3584
3585    Unit* caster = GetCaster();
3586
3587    if(!caster || !caster->isAlive() || caster->GetTypeId() != TYPEID_PLAYER)
3588        return;
3589
3590    if(apply)
3591        m_target->TauntApply(caster);
3592    else
3593    {
3594        // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
3595        m_target->TauntFadeOut(caster);
3596    }
3597}
3598
3599/*********************************************************/
3600/***                  MODIFY SPEED                     ***/
3601/*********************************************************/
3602void Aura::HandleAuraModIncreaseSpeed(bool apply, bool Real)
3603{
3604    // all applied/removed only at real aura add/remove
3605    if(!Real)
3606        return;
3607
3608    m_target->UpdateSpeed(MOVE_RUN, true);
3609}
3610
3611void Aura::HandleAuraModIncreaseMountedSpeed(bool apply, bool Real)
3612{
3613    // all applied/removed only at real aura add/remove
3614    if(!Real)
3615        return;
3616
3617    m_target->UpdateSpeed(MOVE_RUN, true);
3618}
3619
3620void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
3621{
3622    // all applied/removed only at real aura add/remove
3623    if(!Real)
3624        return;
3625
3626    // Enable Fly mode for flying mounts
3627    if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
3628    {
3629        WorldPacket data;
3630        if(apply)
3631            data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
3632        else
3633            data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
3634        data.append(m_target->GetPackGUID());
3635        data << uint32(0);                                      // unknown
3636        m_target->SendMessageToSet(&data, true);
3637
3638        //Players on flying mounts must be immune to polymorph
3639        if (m_target->GetTypeId()==TYPEID_PLAYER)
3640            m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
3641
3642        // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
3643        if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
3644            m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3645    }
3646
3647    m_target->UpdateSpeed(MOVE_FLY, true);
3648}
3649
3650void Aura::HandleAuraModIncreaseSwimSpeed(bool apply, bool Real)
3651{
3652    // all applied/removed only at real aura add/remove
3653    if(!Real)
3654        return;
3655
3656    m_target->UpdateSpeed(MOVE_SWIM, true);
3657}
3658
3659void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real)
3660{
3661    // all applied/removed only at real aura add/remove
3662    if(!Real)
3663        return;
3664
3665    m_target->UpdateSpeed(MOVE_RUN, true);
3666    m_target->UpdateSpeed(MOVE_SWIM, true);
3667    m_target->UpdateSpeed(MOVE_FLY, true);
3668}
3669
3670void Aura::HandleAuraModUseNormalSpeed(bool apply, bool Real)
3671{
3672    // all applied/removed only at real aura add/remove
3673    if(!Real)
3674        return;
3675
3676    m_target->UpdateSpeed(MOVE_RUN,  true);
3677    m_target->UpdateSpeed(MOVE_SWIM, true);
3678    m_target->UpdateSpeed(MOVE_FLY,  true);
3679}
3680
3681/*********************************************************/
3682/***                     IMMUNITY                      ***/
3683/*********************************************************/
3684
3685void Aura::HandleModMechanicImmunity(bool apply, bool Real)
3686{
3687    uint32 mechanic = 1 << m_modifier.m_miscvalue;
3688
3689    //immune movement impairment and loss of control
3690    if(GetId()==42292)
3691        mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
3692
3693    if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
3694    {
3695        Unit::AuraMap& Auras = m_target->GetAuras();
3696        for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
3697        {
3698            next = iter;
3699            ++next;
3700            SpellEntry const *spell = iter->second->GetSpellProto();
3701            if (!( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY)  // spells unaffected by invulnerability
3702                && !iter->second->IsPositive()                                    // only remove negative spells
3703                && spell->Id != GetId())
3704            {
3705                //check for mechanic mask
3706                if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & mechanic)
3707                {
3708                    m_target->RemoveAurasDueToSpell(spell->Id);
3709                    if(Auras.empty())
3710                        break;
3711                    else
3712                        next = Auras.begin();
3713                }
3714            }
3715        }
3716    }
3717
3718    m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,m_modifier.m_miscvalue,apply);
3719
3720    // special cases
3721    switch(m_modifier.m_miscvalue)
3722    {
3723        case MECHANIC_INVULNERABILITY:
3724            m_target->ModifyAuraState(AURA_STATE_FORBEARANCE,apply);
3725            break;
3726        case MECHANIC_SHIELD:
3727            m_target->ModifyAuraState(AURA_STATE_WEAKENED_SOUL,apply);
3728            break;
3729    }
3730
3731    // Bestial Wrath
3732    if ( GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->Id == 19574)
3733    {
3734        // The Beast Within cast on owner if talent present
3735        if ( Unit* owner = m_target->GetOwner() )
3736        {
3737            // Search talent
3738            Unit::AuraList const& m_dummyAuras = owner->GetAurasByType(SPELL_AURA_DUMMY);
3739            for(Unit::AuraList::const_iterator i = m_dummyAuras.begin(); i != m_dummyAuras.end(); ++i)
3740            {
3741                if ( (*i)->GetSpellProto()->SpellIconID == 2229 )
3742                {
3743                    if (apply)
3744                        owner->CastSpell(owner, 34471, true, 0, this);
3745                    else
3746                        owner->RemoveAurasDueToSpell(34471);
3747                    break;
3748                }
3749            }
3750        }
3751    }
3752
3753    // The Beast Within and Bestial Wrath - immunity
3754    if(GetId() == 19574 || GetId() == 34471)
3755    {
3756        if(apply)
3757        {
3758            m_target->CastSpell(m_target,24395,true);
3759            m_target->CastSpell(m_target,24396,true);
3760            m_target->CastSpell(m_target,24397,true);
3761            m_target->CastSpell(m_target,26592,true);
3762        }
3763        else
3764        {
3765            m_target->RemoveAurasDueToSpell(24395);
3766            m_target->RemoveAurasDueToSpell(24396);
3767            m_target->RemoveAurasDueToSpell(24397);
3768            m_target->RemoveAurasDueToSpell(26592);
3769        }
3770    }
3771}
3772
3773void Aura::HandleAuraModEffectImmunity(bool apply, bool Real)
3774{
3775    if(!apply)
3776    {
3777        if(m_target->GetTypeId() == TYPEID_PLAYER)
3778        {
3779            if(((Player*)m_target)->InBattleGround())
3780            {
3781                BattleGround *bg = ((Player*)m_target)->GetBattleGround();
3782                if(bg)
3783                {
3784                    switch(bg->GetTypeID())
3785                    {
3786                        case BATTLEGROUND_AV:
3787                        {
3788                            break;
3789                        }
3790                        case BATTLEGROUND_WS:
3791                        {
3792                            // Warsong Flag, horde               // Silverwing Flag, alliance
3793                            if(GetId() == 23333 || GetId() == 23335)
3794                                    bg->EventPlayerDroppedFlag(((Player*)m_target));
3795                            break;
3796                        }
3797                        case BATTLEGROUND_AB:
3798                        {
3799                            break;
3800                        }
3801                        case BATTLEGROUND_EY:
3802                        {
3803                           if(GetId() == 34976)
3804                                bg->EventPlayerDroppedFlag(((Player*)m_target));
3805                            break;
3806                        }
3807                    }
3808                }
3809            }
3810            else
3811                sOutdoorPvPMgr.HandleDropFlag((Player*)m_target,GetSpellProto()->Id);
3812        }
3813    }
3814
3815    m_target->ApplySpellImmune(GetId(),IMMUNITY_EFFECT,m_modifier.m_miscvalue,apply);
3816}
3817
3818void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
3819{
3820    if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
3821    {
3822        Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
3823        for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
3824        {
3825            if (auraList.front() != this)                   // skip itself aura (it already added)
3826            {
3827                m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
3828                itr = auraList.begin();
3829            }
3830            else
3831                ++itr;
3832        }
3833    }
3834
3835    m_target->ApplySpellImmune(GetId(),IMMUNITY_STATE,m_modifier.m_miscvalue,apply);
3836}
3837
3838void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
3839{
3840    if(apply && m_modifier.m_miscvalue == SPELL_SCHOOL_MASK_NORMAL)
3841        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
3842 
3843    m_target->ApplySpellImmune(GetId(),IMMUNITY_SCHOOL,m_modifier.m_miscvalue,apply);
3844
3845    if(Real && apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
3846    {
3847        if(IsPositiveSpell(GetId()))                        //Only positive immunity removes auras
3848        {
3849            uint32 school_mask = m_modifier.m_miscvalue;
3850            Unit::AuraMap& Auras = m_target->GetAuras();
3851            for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
3852            {
3853                next = iter;
3854                ++next;
3855                SpellEntry const *spell = iter->second->GetSpellProto();
3856                if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
3857                    && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY)   //Spells unaffected by invulnerability
3858                    && !iter->second->IsPositive()          //Don't remove positive spells
3859                    && spell->Id != GetId() )               //Don't remove self
3860                {
3861                    m_target->RemoveAurasDueToSpell(spell->Id);
3862                    if(Auras.empty())
3863                        break;
3864                    else
3865                        next = Auras.begin();
3866                }
3867            }
3868        }
3869    }
3870    if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
3871    {
3872        if( apply )
3873            m_target->addUnitState(UNIT_STAT_ISOLATED);
3874        else
3875            m_target->clearUnitState(UNIT_STAT_ISOLATED);
3876    }
3877}
3878
3879void Aura::HandleAuraModDmgImmunity(bool apply, bool Real)
3880{
3881    m_target->ApplySpellImmune(GetId(),IMMUNITY_DAMAGE,m_modifier.m_miscvalue,apply);
3882}
3883
3884void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
3885{
3886    // all applied/removed only at real aura add/remove
3887    if(!Real)
3888        return;
3889
3890    m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
3891}
3892
3893void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
3894{
3895    if(!Real)
3896        return;
3897
3898    if(apply)
3899    {
3900        // some spell have charges by functionality not have its in spell data
3901        switch (GetId())
3902        {
3903            case 28200:                                     // Ascendance (Talisman of Ascendance trinket)
3904                m_procCharges = 6;
3905                UpdateAuraCharges();
3906                break;
3907            default: break;
3908        }
3909    }
3910}
3911
3912void Aura::HandleAuraModStalked(bool apply, bool Real)
3913{
3914    // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
3915    if(apply)
3916        m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
3917    else
3918        m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
3919}
3920
3921/*********************************************************/
3922/***                   PERIODIC                        ***/
3923/*********************************************************/
3924
3925void Aura::HandlePeriodicTriggerSpell(bool apply, bool Real)
3926{
3927    if (m_periodicTimer <= 0)
3928        m_periodicTimer += m_modifier.periodictime;
3929
3930    m_isPeriodic = apply;
3931    m_isTrigger = apply;
3932
3933    // Curse of the Plaguebringer
3934    if (!apply && m_spellProto->Id == 29213 && m_removeMode!=AURA_REMOVE_BY_DISPEL)
3935    {
3936        // Cast Wrath of the Plaguebringer if not dispelled
3937        m_target->CastSpell(m_target, 29214, true, 0, this);
3938    }
3939}
3940
3941void Aura::HandlePeriodicEnergize(bool apply, bool Real)
3942{
3943    if (m_periodicTimer <= 0)
3944        m_periodicTimer += m_modifier.periodictime;
3945
3946    m_isPeriodic = apply;
3947}
3948
3949void Aura::HandlePeriodicHeal(bool apply, bool Real)
3950{
3951    if (m_periodicTimer <= 0)
3952        m_periodicTimer += m_modifier.periodictime;
3953
3954    m_isPeriodic = apply;
3955
3956    // only at real apply
3957    if (Real && apply && GetSpellProto()->Mechanic == MECHANIC_BANDAGE)
3958    {
3959        // provided m_target as original caster to prevent apply aura caster selection for this negative buff
3960        m_target->CastSpell(m_target,11196,true,NULL,this,m_target->GetGUID());
3961    }
3962
3963    // For prevent double apply bonuses
3964    bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
3965
3966    if(!loading && apply)
3967    {
3968        switch (m_spellProto->SpellFamilyName)
3969        {
3970            case SPELLFAMILY_DRUID:
3971            {
3972                // Rejuvenation
3973                if(m_spellProto->SpellFamilyFlags & 0x0000000000000010LL)
3974                {
3975                    if(Unit* caster = GetCaster())
3976                    {
3977                        Unit::AuraList const& classScripts = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
3978                        for(Unit::AuraList::const_iterator k = classScripts.begin(); k != classScripts.end(); ++k)
3979                        {
3980                            int32 tickcount = GetSpellDuration(m_spellProto) / m_spellProto->EffectAmplitude[m_effIndex];
3981                            switch((*k)->GetModifier()->m_miscvalue)
3982                            {
3983                                case 4953:                          // Increased Rejuvenation Healing - Harold's Rejuvenating Broach Aura
3984                                case 4415:                          // Increased Rejuvenation Healing - Idol of Rejuvenation Aura
3985                                {
3986                                    m_modifier.m_amount += (*k)->GetModifier()->m_amount / tickcount;
3987                                    break;
3988                                }
3989                            }
3990                        }
3991                    }
3992                }
3993            }
3994        }
3995    }
3996}
3997
3998void Aura::HandlePeriodicDamage(bool apply, bool Real)
3999{
4000    // spells required only Real aura add/remove
4001    if(!Real)
4002        return;
4003
4004    if (m_periodicTimer <= 0)
4005        m_periodicTimer += m_modifier.periodictime;
4006
4007    m_isPeriodic = apply;
4008
4009    // For prevent double apply bonuses
4010    bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4011
4012    Unit *caster = GetCaster();
4013
4014    switch (m_spellProto->SpellFamilyName)
4015    {
4016        case SPELLFAMILY_GENERIC:
4017        {
4018            // Pounce Bleed
4019            if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual == 0 )
4020            {
4021                // $AP*0.18/6 bonus per tick
4022                if (apply && !loading && caster)
4023                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4024                return;
4025            }
4026            break;
4027        }
4028        case SPELLFAMILY_WARRIOR:
4029        {
4030            // Rend
4031            if (m_spellProto->SpellFamilyFlags & 0x0000000000000020LL)
4032            {
4033                // 0.00743*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4034                if (apply && !loading && caster)
4035                {
4036                    float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4037                    int32 mws = caster->GetAttackTime(BASE_ATTACK);
4038                    float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4039                    float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4040                    // WARNING! in 3.0 multiplier 0.00743f change to 0.6
4041                    m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.00743f);
4042                }
4043                return;
4044            }
4045            break;
4046        }
4047        case SPELLFAMILY_DRUID:
4048        {
4049            // Rake
4050            if (m_spellProto->SpellFamilyFlags & 0x0000000000001000LL)
4051            {
4052                // $AP*0.06/3 bonus per tick
4053                if (apply && !loading && caster)
4054                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 2 / 100);
4055                return;
4056            }
4057            // Lacerate
4058            if (m_spellProto->SpellFamilyFlags & 0x000000010000000000LL)
4059            {
4060                // $AP*0.05/5 bonus per tick
4061                if (apply && !loading && caster)
4062                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4063                return;
4064            }
4065            // Rip
4066            if (m_spellProto->SpellFamilyFlags & 0x000000000000800000LL)
4067            {
4068                // $AP * min(0.06*$cp, 0.24)/6 [Yes, there is no difference, whether 4 or 5 CPs are being used]
4069                if (apply && !loading && caster && caster->GetTypeId() == TYPEID_PLAYER)
4070                {
4071                    uint8 cp = ((Player*)caster)->GetComboPoints();
4072
4073                    // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4074                    Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4075                    for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4076                    {
4077                        if((*itr)->GetId()==34241)
4078                        {
4079                            m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4080                            break;
4081                        }
4082                    }
4083
4084                    if (cp > 4) cp = 4;
4085                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4086                }
4087                return;
4088            }
4089            break;
4090        }
4091        case SPELLFAMILY_ROGUE:
4092        {
4093            // Deadly poison aura state
4094            if((m_spellProto->SpellFamilyFlags & 0x10000) && m_spellProto->SpellVisual==5100)
4095            {
4096                if(apply)
4097                    m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON,true);
4098                else
4099                {
4100                    // current aura already removed, search present of another
4101                    bool found = false;
4102                    Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
4103                    for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
4104                    {
4105                        SpellEntry const* itr_spell = (*itr)->GetSpellProto();
4106                        if(itr_spell && itr_spell->SpellFamilyName==SPELLFAMILY_ROGUE && (itr_spell->SpellFamilyFlags & 0x10000) && itr_spell->SpellVisual==5100)
4107                        {
4108                            found = true;
4109                            break;
4110                        }
4111                    }
4112                    // this has been last deadly poison aura
4113                    if(!found)
4114                        m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON,false);
4115                }
4116                return;
4117            }
4118            // Rupture
4119            if (m_spellProto->SpellFamilyFlags & 0x000000000000100000LL)
4120            {
4121                // Dmg/tick = $AP*min(0.01*$cp, 0.03) [Like Rip: only the first three CP increase the contribution from AP]
4122                if (apply && !loading && caster && caster->GetTypeId() == TYPEID_PLAYER)
4123                {
4124                    uint8 cp = ((Player*)caster)->GetComboPoints();
4125                    if (cp > 3) cp = 3;
4126                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4127                }
4128                return;
4129            }
4130            // Garrote
4131            if (m_spellProto->SpellFamilyFlags & 0x000000000000000100LL)
4132            {
4133                // $AP*0.18/6 bonus per tick
4134                if (apply && !loading && caster)
4135                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4136                return;
4137            }
4138            break;
4139        }
4140        case SPELLFAMILY_HUNTER:
4141        {
4142            // Serpent Sting
4143            if (m_spellProto->SpellFamilyFlags & 0x0000000000004000LL)
4144            {
4145                // $RAP*0.1/5 bonus per tick
4146                if (apply && !loading && caster)
4147                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4148                return;
4149            }
4150            // Immolation Trap
4151            if (m_spellProto->SpellFamilyFlags & 0x0000000000000004LL && m_spellProto->SpellIconID == 678)
4152            {
4153                // $RAP*0.1/5 bonus per tick
4154                if (apply && !loading && caster)
4155                    m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4156                return;
4157            }
4158            break;
4159        }
4160        case SPELLFAMILY_PALADIN:
4161        {
4162            // Consecration
4163            if (m_spellProto->SpellFamilyFlags & 0x0000000000000020LL)
4164            {
4165                if (apply && !loading)
4166                {
4167                    if(Unit* caster = GetCaster())
4168                    {
4169                        Unit::AuraList const& classScripts = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4170                        for(Unit::AuraList::const_iterator k = classScripts.begin(); k != classScripts.end(); ++k)
4171                        {
4172                            int32 tickcount = GetSpellDuration(m_spellProto) / m_spellProto->EffectAmplitude[m_effIndex];
4173                            switch((*k)->GetModifier()->m_miscvalue)
4174                            {
4175                                case 5147:                  // Improved Consecration - Libram of the Eternal Rest
4176                                {
4177                                    m_modifier.m_amount += (*k)->GetModifier()->m_amount / tickcount;
4178                                    break;
4179                                }
4180                            }
4181                        }
4182                    }
4183                }
4184                return;
4185            }
4186            break;
4187        }
4188        default:
4189            break;
4190    }
4191}
4192
4193void Aura::HandlePeriodicDamagePCT(bool apply, bool Real)
4194{
4195    if (m_periodicTimer <= 0)
4196        m_periodicTimer += m_modifier.periodictime;
4197
4198    m_isPeriodic = apply;
4199}
4200
4201void Aura::HandlePeriodicLeech(bool apply, bool Real)
4202{
4203    if (m_periodicTimer <= 0)
4204        m_periodicTimer += m_modifier.periodictime;
4205
4206    m_isPeriodic = apply;
4207}
4208
4209void Aura::HandlePeriodicManaLeech(bool apply, bool Real)
4210{
4211    if (m_periodicTimer <= 0)
4212        m_periodicTimer += m_modifier.periodictime;
4213
4214    m_isPeriodic = apply;
4215}
4216
4217/*********************************************************/
4218/***                  MODIFY STATS                     ***/
4219/*********************************************************/
4220
4221/********************************/
4222/***        RESISTANCE        ***/
4223/********************************/
4224
4225void Aura::HandleAuraModResistanceExclusive(bool apply, bool Real)
4226{
4227    for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4228    {
4229        if(m_modifier.m_miscvalue & int32(1<<x))
4230        {
4231            m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4232            if(m_target->GetTypeId() == TYPEID_PLAYER)
4233                m_target->ApplyResistanceBuffModsMod(SpellSchools(x),m_positive,m_modifier.m_amount, apply);
4234        }
4235    }
4236}
4237
4238void Aura::HandleAuraModResistance(bool apply, bool Real)
4239{
4240    for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4241    {
4242        if(m_modifier.m_miscvalue & int32(1<<x))
4243        {
4244            m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4245            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4246                m_target->ApplyResistanceBuffModsMod(SpellSchools(x),m_positive,m_modifier.m_amount, apply);
4247        }
4248    }
4249
4250    // Faerie Fire (druid versions)
4251    if( m_spellProto->SpellIconID == 109 &&
4252        m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID &&
4253        m_spellProto->SpellFamilyFlags & 0x0000000000000400LL )
4254    {
4255        m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE,apply);
4256    }
4257}
4258
4259void Aura::HandleAuraModBaseResistancePCT(bool apply, bool Real)
4260{
4261    // only players have base stats
4262    if(m_target->GetTypeId() != TYPEID_PLAYER)
4263    {
4264        //pets only have base armor
4265        if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4266            m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4267    }
4268    else
4269    {
4270        for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4271        {
4272            if(m_modifier.m_miscvalue & int32(1<<x))
4273                m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4274        }
4275    }
4276}
4277
4278void Aura::HandleModResistancePercent(bool apply, bool Real)
4279{
4280    for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4281    {
4282        if(m_modifier.m_miscvalue & int32(1<<i))
4283        {
4284            m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4285            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4286            {
4287                m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i),true,m_modifier.m_amount, apply);
4288                m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i),false,m_modifier.m_amount, apply);
4289            }
4290        }
4291    }
4292}
4293
4294void Aura::HandleModBaseResistance(bool apply, bool Real)
4295{
4296    // only players have base stats
4297    if(m_target->GetTypeId() != TYPEID_PLAYER)
4298    {
4299        //only pets have base stats
4300        if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4301            m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4302    }
4303    else
4304    {
4305        for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4306            if(m_modifier.m_miscvalue & (1<<i))
4307                m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4308    }
4309}
4310
4311/********************************/
4312/***           STAT           ***/
4313/********************************/
4314
4315void Aura::HandleAuraModStat(bool apply, bool Real)
4316{
4317    if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4318    {
4319        sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4320        return;
4321    }
4322
4323    for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4324    {
4325        // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4326        if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4327        {
4328            //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4329            m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4330            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4331                m_target->ApplyStatBuffMod(Stats(i),m_modifier.m_amount,apply);
4332        }
4333    }
4334}
4335
4336void Aura::HandleModPercentStat(bool apply, bool Real)
4337{
4338    if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4339    {
4340        sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4341        return;
4342    }
4343
4344    // only players have base stats
4345    if (m_target->GetTypeId() != TYPEID_PLAYER)
4346        return;
4347
4348    for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4349    {
4350        if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4351            m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4352    }
4353}
4354
4355void Aura::HandleModSpellDamagePercentFromStat(bool apply, bool Real)
4356{
4357    if(m_target->GetTypeId() != TYPEID_PLAYER)
4358        return;
4359
4360    // Magic damage modifiers implemented in Unit::SpellDamageBonus
4361    // This information for client side use only
4362    // Recalculate bonus
4363    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4364}
4365
4366void Aura::HandleModSpellHealingPercentFromStat(bool apply, bool Real)
4367{
4368    if(m_target->GetTypeId() != TYPEID_PLAYER)
4369        return;
4370
4371    // Recalculate bonus
4372    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4373}
4374
4375void Aura::HandleAuraModDispelResist(bool apply, bool Real)
4376{
4377    if(!Real || !apply)
4378        return;
4379
4380    if(GetId()==33206)
4381        m_target->CastSpell(m_target,44416,true,NULL,this,GetCasterGUID());
4382}
4383
4384void Aura::HandleModSpellDamagePercentFromAttackPower(bool apply, bool Real)
4385{
4386    if(m_target->GetTypeId() != TYPEID_PLAYER)
4387        return;
4388
4389    // Magic damage modifiers implemented in Unit::SpellDamageBonus
4390    // This information for client side use only
4391    // Recalculate bonus
4392    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4393}
4394
4395void Aura::HandleModSpellHealingPercentFromAttackPower(bool apply, bool Real)
4396{
4397    if(m_target->GetTypeId() != TYPEID_PLAYER)
4398        return;
4399
4400    // Recalculate bonus
4401    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4402}
4403
4404void Aura::HandleModHealingDone(bool apply, bool Real)
4405{
4406    if(m_target->GetTypeId() != TYPEID_PLAYER)
4407        return;
4408    // implemented in Unit::SpellHealingBonus
4409    // this information is for client side only
4410    ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4411}
4412
4413void Aura::HandleModTotalPercentStat(bool apply, bool Real)
4414{
4415    if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4416    {
4417        sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4418        return;
4419    }
4420
4421    //save current and max HP before applying aura
4422    uint32 curHPValue = m_target->GetHealth();
4423    uint32 maxHPValue = m_target->GetMaxHealth();
4424
4425    for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4426    {
4427        if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4428        {
4429            m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4430            if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4431                m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
4432        }
4433    }
4434
4435    //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
4436    if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
4437    {
4438        // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
4439        uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
4440        m_target->SetHealth(newHPValue);
4441    }
4442}
4443
4444void Aura::HandleAuraModResistenceOfStatPercent(bool apply, bool Real)
4445{
4446    if(m_target->GetTypeId() != TYPEID_PLAYER)
4447        return;
4448
4449    if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
4450    {
4451        // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
4452        // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
4453        sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
4454        return;
4455    }
4456
4457    // Recalculate Armor
4458    m_target->UpdateArmor();
4459}
4460
4461/********************************/
4462/***      HEAL & ENERGIZE     ***/
4463/********************************/
4464void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool Real)
4465{
4466    /*
4467    Need additional checking for auras who reduce or increase healing, magic effect like Dumpen Magic,
4468    so this aura not fully working.
4469    */
4470    if(apply)
4471    {
4472        if(!m_target->isAlive())
4473            return;
4474
4475        if((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) && !m_target->IsSitState())
4476            m_target->SetStandState(PLAYER_STATE_SIT);
4477
4478        if(m_periodicTimer <= 0)
4479        {
4480            m_periodicTimer += m_modifier.periodictime;
4481
4482            if(m_target->GetHealth() < m_target->GetMaxHealth())
4483            {
4484                // PeriodicTick can cast triggered spells with stats changes
4485                PeriodicTick();
4486            }
4487        }
4488    }
4489
4490    m_isPeriodic = apply;
4491}
4492
4493void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool Real)
4494{
4495    if((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) && apply  && !m_target->IsSitState())
4496        m_target->SetStandState(PLAYER_STATE_SIT);
4497    if(apply)
4498    {
4499        if(m_modifier.periodictime == 0)
4500            m_modifier.periodictime = 1000;
4501        if(m_periodicTimer <= 0 && m_target->getPowerType() == POWER_MANA)
4502        {
4503            m_periodicTimer += m_modifier.periodictime;
4504
4505            if(m_target->GetPower(POWER_MANA) < m_target->GetMaxPower(POWER_MANA))
4506            {
4507                // PeriodicTick can cast triggered spells with stats changes
4508                PeriodicTick();
4509            }
4510        }
4511    }
4512
4513    m_isPeriodic = apply;
4514}
4515
4516void Aura::HandleModRegen(bool apply, bool Real)            // eating
4517{
4518    if(apply)
4519    {
4520        if(!m_target->isAlive())
4521            return;
4522
4523        if ((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED)  && !m_target->IsSitState())
4524            m_target->SetStandState(PLAYER_STATE_SIT);
4525
4526        if(m_periodicTimer <= 0)
4527        {
4528            m_periodicTimer += 5000;
4529            int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
4530            Unit *caster = GetCaster();
4531            if (caster)
4532            {
4533                SpellEntry const *spellProto = GetSpellProto();
4534                if (spellProto)
4535                    m_target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, spellProto);
4536            }
4537        }
4538    }
4539
4540    m_isPeriodic = apply;
4541}
4542
4543void Aura::HandleModPowerRegen(bool apply, bool Real)       // drinking
4544{
4545    if ((GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) && apply && !m_target->IsSitState())
4546        m_target->SetStandState(PLAYER_STATE_SIT);
4547
4548    if(apply && m_periodicTimer <= 0)
4549    {
4550        m_periodicTimer += 2000;
4551
4552        Powers pt = m_target->getPowerType();
4553        if(int32(pt) != m_modifier.m_miscvalue)
4554            return;
4555
4556        if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
4557        {
4558            // eating anim
4559            m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
4560        }
4561        else if( GetId() == 20577 )
4562        {
4563            // cannibalize anim
4564            m_target->HandleEmoteCommand(398);
4565        }
4566
4567        // Warrior talent, gain 1 rage every 3 seconds while in combat
4568        if(pt == POWER_RAGE && m_target->isInCombat())
4569        {
4570            m_target->ModifyPower(pt, m_modifier.m_amount*10/17);
4571            m_periodicTimer += 1000;
4572        }
4573    }
4574    m_isPeriodic = apply;
4575    if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
4576        ((Player*)m_target)->UpdateManaRegen();
4577}
4578
4579void Aura::HandleModPowerRegenPCT(bool apply, bool Real)
4580{
4581    // spells required only Real aura add/remove
4582    if(!Real)
4583        return;
4584
4585    if (m_target->GetTypeId() != TYPEID_PLAYER)
4586        return;
4587
4588    // Update manaregen value
4589    if (m_modifier.m_miscvalue == POWER_MANA)
4590        ((Player*)m_target)->UpdateManaRegen();
4591}
4592
4593void Aura::HandleModManaRegen(bool apply, bool Real)
4594{
4595    // spells required only Real aura add/remove
4596    if(!Real)
4597        return;
4598
4599    if (m_target->GetTypeId() != TYPEID_PLAYER)
4600        return;
4601
4602    //Note: an increase in regen does NOT cause threat.
4603    ((Player*)m_target)->UpdateManaRegen();
4604}
4605
4606void Aura::HandleComprehendLanguage(bool apply, bool Real)
4607{
4608    if(apply)
4609        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4610    else
4611        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4612}
4613
4614void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
4615{
4616    if(Real)
4617    {
4618        if(apply)
4619        {
4620            m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4621            m_target->ModifyHealth(m_modifier.m_amount);
4622        }
4623        else
4624        {
4625            if (int32(m_target->GetHealth()) > m_modifier.m_amount)
4626                m_target->ModifyHealth(-m_modifier.m_amount);
4627            else
4628                m_target->SetHealth(1);
4629            m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4630        }
4631    }
4632}
4633
4634void  Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool Real)
4635{
4636    uint32 oldhealth = m_target->GetHealth();
4637    double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
4638
4639    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4640
4641    // refresh percentage
4642    if(oldhealth > 0)
4643    {
4644        uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
4645        if(newhealth==0)
4646            newhealth = 1;
4647
4648        m_target->SetHealth(newhealth);
4649    }
4650}
4651
4652void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
4653{
4654    Powers powerType = m_target->getPowerType();
4655    if(int32(powerType) != m_modifier.m_miscvalue)
4656        return;
4657
4658    m_target->HandleStatModifier(UnitMods(UNIT_MOD_POWER_START + powerType), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4659}
4660
4661void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool Real)
4662{
4663    Powers powerType = m_target->getPowerType();
4664    if(int32(powerType) != m_modifier.m_miscvalue)
4665        return;
4666
4667    m_target->HandleStatModifier(UnitMods(UNIT_MOD_POWER_START + powerType), TOTAL_PCT, float(m_modifier.m_amount), apply);
4668}
4669
4670void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool Real)
4671{
4672    //m_target->ApplyMaxHealthPercentMod(m_modifier.m_amount,apply);
4673    m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
4674}
4675
4676/********************************/
4677/***          FIGHT           ***/
4678/********************************/
4679
4680void Aura::HandleAuraModParryPercent(bool apply, bool Real)
4681{
4682    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4683        return;
4684
4685    ((Player*)m_target)->UpdateParryPercentage();
4686}
4687
4688void Aura::HandleAuraModDodgePercent(bool apply, bool Real)
4689{
4690    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4691        return;
4692
4693    ((Player*)m_target)->UpdateDodgePercentage();
4694    //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
4695}
4696
4697void Aura::HandleAuraModBlockPercent(bool apply, bool Real)
4698{
4699    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4700        return;
4701
4702    ((Player*)m_target)->UpdateBlockPercentage();
4703    //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
4704}
4705
4706void Aura::HandleAuraModRegenInterrupt(bool apply, bool Real)
4707{
4708    // spells required only Real aura add/remove
4709    if(!Real)
4710        return;
4711
4712    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4713        return;
4714
4715    ((Player*)m_target)->UpdateManaRegen();
4716}
4717
4718void Aura::HandleAuraModCritPercent(bool apply, bool Real)
4719{
4720    if(m_target->GetTypeId()!=TYPEID_PLAYER)
4721        return;
4722
4723    // apply item specific bonuses for already equipped weapon
4724    if(Real)
4725    {
4726        for(int i = 0; i < MAX_ATTACK; ++i)
4727            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4728                ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem,WeaponAttackType(i),this,apply);
4729    }
4730
4731    // mods must be applied base at equipped weapon class and subclass comparison
4732    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
4733    // m_modifier.m_miscvalue comparison with item generated damage types
4734
4735    if (GetSpellProto()->EquippedItemClass == -1)
4736    {
4737        ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE,         FLAT_MOD, float (m_modifier.m_amount), apply);
4738        ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
4739        ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE,  FLAT_MOD, float (m_modifier.m_amount), apply);
4740    }
4741    else
4742    {
4743        // done in Player::_ApplyWeaponDependentAuraMods
4744    }
4745}
4746
4747void Aura::HandleModHitChance(bool apply, bool Real)
4748{
4749    m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
4750    m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
4751}
4752
4753void Aura::HandleModSpellHitChance(bool apply, bool Real)
4754{
4755    m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
4756}
4757
4758void Aura::HandleModSpellCritChance(bool apply, bool Real)
4759{
4760    // spells required only Real aura add/remove
4761    if(!Real)
4762        return;
4763
4764    if(m_target->GetTypeId() == TYPEID_PLAYER)
4765    {
4766        ((Player*)m_target)->UpdateAllSpellCritChances();
4767    }
4768    else
4769    {
4770        m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
4771    }
4772}
4773
4774void Aura::HandleModSpellCritChanceShool(bool apply, bool Real)
4775{
4776    // spells required only Real aura add/remove
4777    if(!Real)
4778        return;
4779
4780    if(m_target->GetTypeId() != TYPEID_PLAYER)
4781        return;
4782
4783    for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
4784        if (m_modifier.m_miscvalue & (1<<school))
4785            ((Player*)m_target)->UpdateSpellCritChance(school);
4786}
4787
4788/********************************/
4789/***         ATTACK SPEED     ***/
4790/********************************/
4791
4792void Aura::HandleModCastingSpeed(bool apply, bool Real)
4793{
4794    m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
4795}
4796
4797void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool Real)
4798{
4799    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4800    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,m_modifier.m_amount,apply);
4801    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4802}
4803
4804void Aura::HandleModCombatSpeedPct(bool apply, bool Real)
4805{
4806    m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
4807    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4808    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,m_modifier.m_amount,apply);
4809    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4810}
4811
4812void Aura::HandleModAttackSpeed(bool apply, bool Real)
4813{
4814    if(!m_target->isAlive() )
4815        return;
4816
4817    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
4818}
4819
4820void Aura::HandleHaste(bool apply, bool Real)
4821{
4822    m_target->ApplyAttackTimePercentMod(BASE_ATTACK,  m_modifier.m_amount,apply);
4823    m_target->ApplyAttackTimePercentMod(OFF_ATTACK,   m_modifier.m_amount,apply);
4824    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount,apply);
4825}
4826
4827void Aura::HandleAuraModRangedHaste(bool apply, bool Real)
4828{
4829    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
4830}
4831
4832void Aura::HandleRangedAmmoHaste(bool apply, bool Real)
4833{
4834    if(m_target->GetTypeId() != TYPEID_PLAYER)
4835        return;
4836    m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
4837}
4838
4839/********************************/
4840/***        ATTACK POWER      ***/
4841/********************************/
4842
4843void Aura::HandleAuraModAttackPower(bool apply, bool Real)
4844{
4845    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4846}
4847
4848void Aura::HandleAuraModRangedAttackPower(bool apply, bool Real)
4849{
4850    if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4851        return;
4852
4853    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4854}
4855
4856void Aura::HandleAuraAttackPowerAttacker(bool apply, bool Real)
4857{
4858    // spells required only Real aura add/remove
4859    if(!Real)
4860        return;
4861    Unit *caster = GetCaster();
4862
4863    if (!caster)
4864        return;
4865
4866    // Hunter's Mark
4867    if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & 0x0000000000000400LL)
4868    {
4869        // Check Improved Hunter's Mark bonus on caster
4870        Unit::AuraList const& mOverrideClassScript = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4871        for(Unit::AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i)
4872        {
4873            Modifier* mod = (*i)->GetModifier();
4874            // mproved Hunter's Mark script from 5236 to 5240
4875            if (mod->m_miscvalue >= 5236 && mod->m_miscvalue <= 5240)
4876            {
4877                // Get amount of ranged bonus for this spell..
4878                int32 ranged_bonus = caster->CalculateSpellDamage(m_spellProto, 1, m_spellProto->EffectBasePoints[1], m_target);
4879                // Set melee attack power bonus % from ranged depends from Improved mask aura
4880                m_modifier.m_amount = mod->m_amount * ranged_bonus / 100;
4881                m_currentBasePoints = m_modifier.m_amount;
4882                break;
4883            }
4884        }
4885        return;
4886    }
4887}
4888
4889void Aura::HandleAuraModAttackPowerPercent(bool apply, bool Real)
4890{
4891    //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
4892    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
4893}
4894
4895void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool Real)
4896{
4897    if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4898        return;
4899
4900    //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
4901    m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
4902}
4903
4904void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool apply, bool Real)
4905{
4906    // spells required only Real aura add/remove
4907    if(!Real)
4908        return;
4909
4910    if(m_target->GetTypeId() == TYPEID_PLAYER && (m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
4911        return;
4912
4913    if(m_modifier.m_miscvalue != STAT_INTELLECT)
4914    {
4915        // support required adding UpdateAttackPowerAndDamage calls at stat update
4916        sLog.outError("Aura SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT (212) need support non-intellect stats!");
4917        return;
4918    }
4919
4920    // Recalculate bonus
4921    ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
4922}
4923
4924/********************************/
4925/***        DAMAGE BONUS      ***/
4926/********************************/
4927void Aura::HandleModDamageDone(bool apply, bool Real)
4928{
4929    // apply item specific bonuses for already equipped weapon
4930    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
4931    {
4932        for(int i = 0; i < MAX_ATTACK; ++i)
4933            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
4934                ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply);
4935    }
4936
4937    // m_modifier.m_miscvalue is bitmask of spell schools
4938    // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
4939    // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
4940    // 127 - full bitmask any damages
4941    //
4942    // mods must be applied base at equipped weapon class and subclass comparison
4943    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
4944    // m_modifier.m_miscvalue comparison with item generated damage types
4945
4946    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
4947    {
4948        // apply generic physical damage bonuses including wand case
4949        if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
4950        {
4951            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4952            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4953            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4954        }
4955        else
4956        {
4957            // done in Player::_ApplyWeaponDependentAuraMods
4958        }
4959
4960        if(m_target->GetTypeId() == TYPEID_PLAYER)
4961        {
4962            if(m_positive)
4963                m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS,m_modifier.m_amount,apply);
4964            else
4965                m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG,m_modifier.m_amount,apply);
4966        }
4967    }
4968
4969    // Skip non magic case for speedup
4970    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
4971        return;
4972
4973    if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
4974    {
4975        // wand magic case (skip generic to all item spell bonuses)
4976        // done in Player::_ApplyWeaponDependentAuraMods
4977
4978        // Skip item specific requirements for not wand magic damage
4979        return;
4980    }
4981
4982    // Magic damage modifiers implemented in Unit::SpellDamageBonus
4983    // This information for client side use only
4984    if(m_target->GetTypeId() == TYPEID_PLAYER)
4985    {
4986        if(m_positive)
4987        {
4988            for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; i++)
4989            {
4990                if((m_modifier.m_miscvalue & (1<<i)) != 0)
4991                    m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS+i,m_modifier.m_amount,apply);
4992            }
4993        }
4994        else
4995        {
4996            for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; i++)
4997            {
4998                if((m_modifier.m_miscvalue & (1<<i)) != 0)
4999                    m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG+i,m_modifier.m_amount,apply);
5000            }
5001        }
5002        Pet* pet = m_target->GetPet();
5003        if(pet)
5004            pet->UpdateAttackPowerAndDamage();
5005    }
5006}
5007
5008void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5009{
5010    sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5011
5012    // apply item specific bonuses for already equipped weapon
5013    if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
5014    {
5015        for(int i = 0; i < MAX_ATTACK; ++i)
5016            if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5017                ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply);
5018    }
5019
5020    // m_modifier.m_miscvalue is bitmask of spell schools
5021    // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5022    // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5023    // 127 - full bitmask any damages
5024    //
5025    // mods must be applied base at equipped weapon class and subclass comparison
5026    // with spell->EquippedItemClass and  EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5027    // m_modifier.m_miscvalue comparison with item generated damage types
5028
5029    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5030    {
5031        // apply generic physical damage bonuses including wand case
5032        if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5033        {
5034            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5035            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5036            m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5037        }
5038        else
5039        {
5040            // done in Player::_ApplyWeaponDependentAuraMods
5041        }
5042        // For show in client
5043        if(m_target->GetTypeId() == TYPEID_PLAYER)
5044            m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT,m_modifier.m_amount/100.0f,apply);
5045    }
5046
5047    // Skip non magic case for speedup
5048    if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5049        return;
5050
5051    if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5052    {
5053        // wand magic case (skip generic to all item spell bonuses)
5054        // done in Player::_ApplyWeaponDependentAuraMods
5055
5056        // Skip item specific requirements for not wand magic damage
5057        return;
5058    }
5059
5060    // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5061    // Send info to client
5062    if(m_target->GetTypeId() == TYPEID_PLAYER)
5063        for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5064            m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT+i,m_modifier.m_amount/100.0f,apply);
5065}
5066
5067void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5068{
5069    // spells required only Real aura add/remove
5070    if(!Real)
5071        return;
5072
5073    sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5074
5075    m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5076}
5077
5078/********************************/
5079/***        POWER COST        ***/
5080/********************************/
5081
5082void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5083{
5084    // spells required only Real aura add/remove
5085    if(!Real)
5086        return;
5087
5088    float amount = m_modifier.m_amount/100.0f;
5089    for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5090        if(m_modifier.m_miscvalue & (1<<i))
5091            m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+i,amount,apply);
5092}
5093
5094void Aura::HandleModPowerCost(bool apply, bool Real)
5095{
5096    // spells required only Real aura add/remove
5097    if(!Real)
5098        return;
5099
5100    for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5101        if(m_modifier.m_miscvalue & (1<<i))
5102            m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER+i,m_modifier.m_amount,apply);
5103}
5104
5105/*********************************************************/
5106/***                    OTHERS                         ***/
5107/*********************************************************/
5108
5109void Aura::HandleShapeshiftBoosts(bool apply)
5110{
5111    uint32 spellId = 0;
5112    uint32 spellId2 = 0;
5113    uint32 HotWSpellId = 0;
5114
5115    switch(GetModifier()->m_miscvalue)
5116    {
5117        case FORM_CAT:
5118            spellId = 3025;
5119            HotWSpellId = 24900;
5120            break;
5121        case FORM_TREE:
5122            spellId = 5420;
5123            break;
5124        case FORM_TRAVEL:
5125            spellId = 5419;
5126            break;
5127        case FORM_AQUA:
5128            spellId = 5421;
5129            break;
5130        case FORM_BEAR:
5131            spellId = 1178;
5132            spellId2 = 21178;
5133            HotWSpellId = 24899;
5134            break;
5135        case FORM_DIREBEAR:
5136            spellId = 9635;
5137            spellId2 = 21178;
5138            HotWSpellId = 24899;
5139            break;
5140        case FORM_BATTLESTANCE:
5141            spellId = 21156;
5142            break;
5143        case FORM_DEFENSIVESTANCE:
5144            spellId = 7376;
5145            break;
5146        case FORM_BERSERKERSTANCE:
5147            spellId = 7381;
5148            break;
5149        case FORM_MOONKIN:
5150            spellId = 24905;
5151            // aura from effect trigger spell
5152            spellId2 = 24907;
5153            break;
5154        case FORM_FLIGHT:
5155            spellId = 33948;
5156            break;
5157        case FORM_FLIGHT_EPIC:
5158            spellId  = 40122;
5159            spellId2 = 40121;
5160            break;
5161        case FORM_SPIRITOFREDEMPTION:
5162            spellId  = 27792;
5163            spellId2 = 27795;                               // must be second, this important at aura remove to prevent to early iterator invalidation.
5164            break;
5165        case FORM_GHOSTWOLF:
5166        case FORM_AMBIENT:
5167        case FORM_GHOUL:
5168        case FORM_SHADOW:
5169        case FORM_STEALTH:
5170        case FORM_CREATURECAT:
5171        case FORM_CREATUREBEAR:
5172            spellId = 0;
5173            break;
5174    }
5175
5176    uint32 form = GetModifier()->m_miscvalue-1;
5177
5178    if(apply)
5179    {
5180        if (spellId) m_target->CastSpell(m_target, spellId, true, NULL, this );
5181        if (spellId2) m_target->CastSpell(m_target, spellId2, true, NULL, this);
5182
5183        if(m_target->GetTypeId() == TYPEID_PLAYER)
5184        {
5185            const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5186            for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5187            {
5188                if(itr->second->state == PLAYERSPELL_REMOVED) continue;
5189                if(itr->first==spellId || itr->first==spellId2) continue;
5190                SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5191                if (!spellInfo || !(spellInfo->Attributes & ((1<<6) | (1<<7)))) continue;
5192                if (spellInfo->Stances & (1<<form))
5193                    m_target->CastSpell(m_target, itr->first, true, NULL, this);
5194            }
5195            //LotP
5196            if (((Player*)m_target)->HasSpell(17007))
5197            {
5198                SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5199                if (spellInfo && spellInfo->Stances & (1<<form))
5200                    m_target->CastSpell(m_target, 24932, true, NULL, this);
5201            }
5202            // HotW
5203            if (HotWSpellId)
5204            {
5205                Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5206                for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5207                {
5208                    if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5209                    {
5210                        int32 HotWMod = (*i)->GetModifier()->m_amount;
5211                        if(GetModifier()->m_miscvalue == FORM_CAT)
5212                            HotWMod /= 2;
5213
5214                        m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5215                        break;
5216                    }
5217                }
5218            }
5219        }
5220    }
5221    else
5222    {
5223        m_target->RemoveAurasDueToSpell(spellId);
5224        m_target->RemoveAurasDueToSpell(spellId2);
5225
5226        Unit::AuraMap& tAuras = m_target->GetAuras();
5227        for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5228        {
5229            if (itr->second->IsRemovedOnShapeLost())
5230            {
5231                m_target->RemoveAurasDueToSpell(itr->second->GetId());
5232                itr = tAuras.begin();
5233            }
5234            else
5235            {
5236                ++itr;
5237            }
5238        }
5239    }
5240
5241    /*double healthPercentage = (double)m_target->GetHealth() / (double)m_target->GetMaxHealth();
5242    m_target->SetHealth(uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage)));*/
5243}
5244
5245void Aura::HandleAuraEmpathy(bool apply, bool Real)
5246{
5247    if(m_target->GetTypeId() != TYPEID_UNIT)
5248        return;
5249
5250    CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5251    if(ci && ci->type == CREATURE_TYPE_BEAST)
5252        m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5253}
5254
5255void Aura::HandleAuraUntrackable(bool apply, bool Real)
5256{
5257    if(apply)
5258        m_target->SetFlag(UNIT_FIELD_BYTES_1, PLAYER_STATE_FLAG_UNTRACKABLE);
5259    else
5260        m_target->RemoveFlag(UNIT_FIELD_BYTES_1, PLAYER_STATE_FLAG_UNTRACKABLE);
5261}
5262
5263void Aura::HandleAuraModPacify(bool apply, bool Real)
5264{
5265    if(m_target->GetTypeId() != TYPEID_PLAYER)
5266        return;
5267
5268    if(apply)
5269        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5270    else
5271        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5272}
5273
5274void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5275{
5276    HandleAuraModPacify(apply,Real);
5277    HandleAuraModSilence(apply,Real);
5278}
5279
5280void Aura::HandleAuraGhost(bool apply, bool Real)
5281{
5282    if(m_target->GetTypeId() != TYPEID_PLAYER)
5283        return;
5284
5285    if(apply)
5286    {
5287        m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5288    }
5289    else
5290    {
5291        m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5292    }
5293}
5294
5295void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5296{
5297    // all applied/removed only at real aura add/remove
5298    if(!Real)
5299        return;
5300
5301    // allow fly
5302    WorldPacket data;
5303    if(apply)
5304        data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5305    else
5306        data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5307    data.append(m_target->GetPackGUID());
5308    data << uint32(0);                                      // unk
5309    m_target->SendMessageToSet(&data, true);
5310}
5311
5312void Aura::HandleModRating(bool apply, bool Real)
5313{
5314    // spells required only Real aura add/remove
5315    if(!Real)
5316        return;
5317
5318    if(m_target->GetTypeId() != TYPEID_PLAYER)
5319        return;
5320
5321    for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5322        if (m_modifier.m_miscvalue & (1 << rating))
5323            ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5324}
5325
5326void Aura::HandleForceMoveForward(bool apply, bool Real)
5327{
5328    if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5329        return;
5330    if(apply)
5331        m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5332    else
5333        m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5334}
5335
5336void Aura::HandleAuraModExpertise(bool apply, bool Real)
5337{
5338    if(m_target->GetTypeId() != TYPEID_PLAYER)
5339        return;
5340
5341    ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5342    ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5343}
5344
5345void Aura::HandleModTargetResistance(bool apply, bool Real)
5346{
5347    // spells required only Real aura add/remove
5348    if(!Real)
5349        return;
5350    // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
5351
5352    // show armor penetration
5353    if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
5354        m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE,m_modifier.m_amount, apply);
5355
5356    // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
5357    if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
5358        m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE,m_modifier.m_amount, apply);
5359}
5360
5361//HandleNoImmediateEffect auras implementation to support new stat system
5362void Aura::HandleAuraHealing(bool apply, bool Real)
5363{
5364    //m_target->HandleStatModifier(UNIT_MOD_HEALING, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5365}
5366
5367void Aura::HandleAuraHealingPct(bool apply, bool Real)
5368{
5369    //m_target->HandleStatModifier(UNIT_MOD_HEALING, TOTAL_PCT, float(m_modifier.m_amount), apply);
5370}
5371
5372void Aura::HandleShieldBlockValue(bool apply, bool Real)
5373{
5374    BaseModType modType = FLAT_MOD;
5375    if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
5376        modType = PCT_MOD;
5377
5378    if(m_target->GetTypeId() == TYPEID_PLAYER)
5379        ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
5380}
5381
5382void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
5383{
5384    // spells required only Real aura add/remove
5385    if(!Real)
5386        return;
5387
5388    if(m_target->GetTypeId() != TYPEID_PLAYER)
5389        return;
5390
5391    Player *target = (Player*)m_target;
5392
5393    // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
5394    // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
5395    if( !apply && m_duration==0 && target->GetComboTarget())
5396        if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
5397            target->AddComboPoints(unit, -m_modifier.m_amount);
5398}
5399
5400void Aura::HandleModUnattackable( bool Apply, bool Real )
5401{
5402    if(Real && Apply)
5403    {
5404        m_target->CombatStop();
5405        m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_UNATTACKABLE);
5406    }
5407
5408    m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
5409}
5410
5411void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
5412{
5413    // spells required only Real aura add/remove
5414    if(!Real)
5415        return;
5416
5417    // prepare spirit state
5418    if(apply)
5419    {
5420        if(m_target->GetTypeId()==TYPEID_PLAYER)
5421        {
5422            // disable breath/etc timers
5423            ((Player*)m_target)->StopMirrorTimers();
5424
5425            // set stand state (expected in this form)
5426            if(!m_target->IsStandState())
5427                m_target->SetStandState(PLAYER_STATE_NONE);
5428        }
5429
5430        m_target->SetHealth(1);
5431    }
5432    // die at aura end
5433    else
5434        m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
5435}
5436
5437void Aura::CleanupTriggeredSpells()
5438{
5439    uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
5440    if(!tSpellId)
5441        return;
5442
5443    SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
5444    if(!tProto)
5445        return;
5446
5447    if(GetSpellDuration(tProto) != -1)
5448        return;
5449
5450    // needed for spell 43680, maybe others
5451    // TODO: is there a spell flag, which can solve this in a more sophisticated way?
5452    if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
5453            GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
5454        return;
5455    m_target->RemoveAurasDueToSpell(tSpellId);
5456}
5457
5458void Aura::HandleAuraPowerBurn(bool apply, bool Real)
5459{
5460    if (m_periodicTimer <= 0)
5461        m_periodicTimer += m_modifier.periodictime;
5462
5463    m_isPeriodic = apply;
5464}
5465
5466void Aura::HandleSchoolAbsorb(bool apply, bool Real)
5467{
5468    if(!Real)
5469        return;
5470
5471    // prevent double apply bonuses
5472    if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
5473    {
5474        if(Unit* caster = GetCaster())
5475        {
5476            float DoneActualBenefit = 0.0f;
5477            switch(m_spellProto->SpellFamilyName)
5478            {
5479                case SPELLFAMILY_PRIEST:
5480                    if(m_spellProto->SpellFamilyFlags == 0x1) //PW:S
5481                    {
5482                        //+30% from +healing bonus
5483                        DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.3f;
5484                        break;
5485                    }
5486                    break;
5487                case SPELLFAMILY_MAGE:
5488                    if(m_spellProto->SpellFamilyFlags == 0x80100 || m_spellProto->SpellFamilyFlags == 0x8 || m_spellProto->SpellFamilyFlags == 0x100000000LL)
5489                    {
5490                        //frost ward, fire ward, ice barrier
5491                        //+10% from +spd bonus
5492                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
5493                        break;
5494                    }
5495                    break;
5496                case SPELLFAMILY_WARLOCK:
5497                    if(m_spellProto->SpellFamilyFlags == 0x00)
5498                    {
5499                        //shadow ward
5500                        //+10% from +spd bonus
5501                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
5502                        break;
5503                    }
5504                    break;
5505                default:
5506                    break;
5507            }
5508
5509            DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
5510
5511            m_modifier.m_amount += (int32)DoneActualBenefit;
5512        }
5513    }
5514}
5515
5516void Aura::PeriodicTick()
5517{
5518    if(!m_target->isAlive())
5519        return;
5520
5521    switch(m_modifier.m_auraname)
5522    {
5523        case SPELL_AURA_PERIODIC_DAMAGE:
5524        case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
5525        {
5526            Unit *pCaster = GetCaster();
5527            if(!pCaster)
5528                return;
5529
5530            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5531                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5532                return;
5533
5534            // Check for immune (not use charges)
5535            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5536                return;
5537
5538            // some auras remove at specific health level or more
5539            if(m_modifier.m_auraname==SPELL_AURA_PERIODIC_DAMAGE)
5540            {
5541                switch(GetId())
5542                {
5543                    case 43093: case 31956: case 38801:
5544                    case 35321: case 38363: case 39215:
5545                        if(m_target->GetHealth() == m_target->GetMaxHealth() )
5546                        {
5547                            m_target->RemoveAurasDueToSpell(GetId());
5548                            return;
5549                        }
5550                        break;
5551                    case 38772:
5552                    {
5553                        uint32 percent =
5554                            GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_DUMMY ?
5555                            pCaster->CalculateSpellDamage(GetSpellProto(),GetEffIndex()+1,GetSpellProto()->EffectBasePoints[GetEffIndex()+1],m_target) :
5556                            100;
5557                        if(m_target->GetHealth()*100 >= m_target->GetMaxHealth()*percent )
5558                        {
5559                            m_target->RemoveAurasDueToSpell(GetId());
5560                            return;
5561                        }
5562                        break;
5563                    }
5564                    case 41337:// aura of anger
5565                    {                       
5566                        Unit::AuraList const& mMod = m_target->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE);
5567                        for(Unit::AuraList::const_iterator i = mMod.begin(); i != mMod.end(); ++i)
5568                        {
5569                            if ((*i)->GetId() == 41337)
5570                            {
5571                                (*i)->ApplyModifier(false);
5572                                (*i)->GetModifier()->m_amount += 5;
5573                                (*i)->ApplyModifier(true);
5574                                break;
5575                            }
5576                        }                       
5577                        m_modifier.m_amount += 100;
5578                    }break;
5579                    default:
5580                        break;
5581                }
5582            }
5583
5584            uint32 absorb=0;
5585            uint32 resist=0;
5586            CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5587
5588            // ignore non positive values (can be result apply spellmods to aura damage
5589            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5590
5591            uint32 pdamage;
5592
5593            if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
5594            {
5595                pdamage = amount;
5596
5597                // Calculate armor mitigation if it is a physical spell
5598                // But not for bleed mechanic spells
5599                if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
5600                     GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
5601                {
5602                    uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
5603                    cleanDamage.damage += pdamage - pdamageReductedArmor;
5604                    pdamage = pdamageReductedArmor;
5605                }
5606
5607                pdamage = pCaster->SpellDamageBonus(m_target,GetSpellProto(),pdamage,DOT);
5608
5609                // Curse of Agony damage-per-tick calculation
5610                if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x0000000000000400LL) && GetSpellProto()->SpellIconID==544)
5611                {
5612                    // 1..4 ticks, 1/2 from normal tick damage
5613                    if (m_duration>=((m_maxduration-m_modifier.periodictime)*2/3))
5614                        pdamage = pdamage/2;
5615                    // 9..12 ticks, 3/2 from normal tick damage
5616                    else if(m_duration<((m_maxduration-m_modifier.periodictime)/3))
5617                        pdamage += (pdamage+1)/2;           // +1 prevent 0.5 damage possible lost at 1..4 ticks
5618                    // 5..8 ticks have normal tick damage
5619                }
5620            }
5621            else
5622                pdamage = uint32(m_target->GetMaxHealth()*amount/100);
5623
5624            //As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
5625            // Reduce dot damage from resilience for players
5626            if (m_target->GetTypeId()==TYPEID_PLAYER)
5627                pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
5628
5629            pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
5630
5631            sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
5632                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
5633
5634            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5635            data.append(m_target->GetPackGUID());
5636            data.appendPackGUID(GetCasterGUID());
5637            data << uint32(GetId());
5638            data << uint32(1);
5639            data << uint32(m_modifier.m_auraname);
5640            data << (uint32)pdamage;
5641            data << (uint32)GetSpellSchoolMask(GetSpellProto()); // will be mask in 2.4.x
5642            data << (uint32)absorb;
5643            data << (uint32)resist;
5644            m_target->SendMessageToSet(&data,true);
5645
5646            Unit* target = m_target;                        // aura can be deleted in DealDamage
5647            SpellEntry const* spellProto = GetSpellProto();
5648
5649            pCaster->DealDamage(m_target, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
5650
5651            // DO NOT ACCESS MEMBERS OF THE AURA FROM NOW ON (DealDamage can delete aura)
5652
5653            pCaster->ProcDamageAndSpell(target, PROC_FLAG_NONE, PROC_FLAG_TAKE_DAMAGE, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), GetSpellSchoolMask(spellProto), spellProto);
5654            break;
5655        }
5656        case SPELL_AURA_PERIODIC_LEECH:
5657        {
5658            Unit *pCaster = GetCaster();
5659            if(!pCaster)
5660                return;
5661
5662            if(!pCaster->isAlive())
5663                return;
5664
5665            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5666                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5667                return;
5668
5669            // Check for immune (not use charges)
5670            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5671                return;
5672
5673            uint32 absorb=0;
5674            uint32 resist=0;
5675            CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5676
5677            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5678
5679            //Calculate armor mitigation if it is a physical spell
5680            if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
5681            {
5682                uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
5683                cleanDamage.damage += pdamage - pdamageReductedArmor;
5684                pdamage = pdamageReductedArmor;
5685            }
5686
5687            pdamage = pCaster->SpellDamageBonus(m_target,GetSpellProto(),pdamage,DOT);
5688
5689            // talent Soul Siphon add bonus to Drain Life spells
5690            if( GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x8) )
5691            {
5692                // find talent max bonus percentage
5693                Unit::AuraList const& mClassScriptAuras = pCaster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
5694                for(Unit::AuraList::const_iterator i = mClassScriptAuras.begin(); i != mClassScriptAuras.end(); ++i)
5695                {
5696                    if ((*i)->GetModifier()->m_miscvalue == 4992 || (*i)->GetModifier()->m_miscvalue == 4993)
5697                    {
5698                        if((*i)->GetEffIndex()!=1)
5699                        {
5700                            sLog.outError("Expected spell %u structure change, need code update",(*i)->GetId());
5701                            break;
5702                        }
5703
5704                        // effect 1 m_amount
5705                        int32 maxPercent = (*i)->GetModifier()->m_amount;
5706                        // effect 0 m_amount
5707                        int32 stepPercent = pCaster->CalculateSpellDamage((*i)->GetSpellProto(),0,(*i)->GetSpellProto()->EffectBasePoints[0],pCaster);
5708
5709                        // count affliction effects and calc additional damage in percentage
5710                        int32 modPercent = 0;
5711                        Unit::AuraMap const& victimAuras = m_target->GetAuras();
5712                        for (Unit::AuraMap::const_iterator itr = victimAuras.begin(); itr != victimAuras.end(); ++itr)
5713                        {
5714                            Aura* aura = itr->second;
5715                            if (aura->IsPositive())continue;
5716                            SpellEntry const* m_spell = aura->GetSpellProto();
5717                            if (m_spell->SpellFamilyName != SPELLFAMILY_WARLOCK)
5718                                continue;
5719
5720                            SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(m_spell->Id);
5721                            SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(m_spell->Id);
5722
5723                            for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
5724                            {
5725                                if(_spell_idx->second->skillId == SKILL_AFFLICTION)
5726                                {
5727                                    modPercent += stepPercent;
5728                                    if (modPercent >= maxPercent)
5729                                    {
5730                                        modPercent = maxPercent;
5731                                        break;
5732                                    }
5733                                }
5734                            }
5735                        }
5736                        pdamage += (pdamage*modPercent/100);
5737                        break;
5738                    }
5739                }
5740            }
5741
5742            //As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
5743            // Reduce dot damage from resilience for players
5744            if (m_target->GetTypeId()==TYPEID_PLAYER)
5745                pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
5746
5747            pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
5748
5749            if(m_target->GetHealth() < pdamage)
5750                pdamage = uint32(m_target->GetHealth());
5751
5752            sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
5753                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
5754
5755            pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
5756
5757
5758            Unit* target = m_target;                        // aura can be deleted in DealDamage
5759            SpellEntry const* spellProto = GetSpellProto();
5760            float multiplier = spellProto->EffectMultipleValue[GetEffIndex()] > 0 ? spellProto->EffectMultipleValue[GetEffIndex()] : 1;
5761
5762            uint32 new_damage = pCaster->DealDamage(m_target, (pdamage <= absorb+resist) ? 0 : (pdamage-absorb-resist), &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
5763
5764            // DO NOT ACCESS MEMBERS OF THE AURA FROM NOW ON (DealDamage can delete aura)
5765
5766            pCaster->ProcDamageAndSpell(target, PROC_FLAG_HEALED, PROC_FLAG_TAKE_DAMAGE, new_damage, GetSpellSchoolMask(spellProto), spellProto);
5767            if (!target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
5768            {
5769                for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++)
5770                {
5771                    if (pCaster->m_currentSpells[i] && pCaster->m_currentSpells[i]->m_spellInfo->Id == spellProto->Id)
5772                        pCaster->m_currentSpells[i]->cancel();
5773                }
5774            }
5775
5776
5777            if(Player *modOwner = pCaster->GetSpellModOwner())
5778                modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
5779
5780            uint32 heal = pCaster->SpellHealingBonus(spellProto, uint32(new_damage * multiplier), DOT, pCaster);
5781
5782            int32 gain = pCaster->ModifyHealth(heal);
5783            pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, spellProto);
5784
5785            pCaster->SendHealSpellLog(pCaster, spellProto->Id, heal);
5786            break;
5787        }
5788        case SPELL_AURA_PERIODIC_HEAL:
5789        case SPELL_AURA_OBS_MOD_HEALTH:
5790        {
5791            Unit *pCaster = GetCaster();
5792            if(!pCaster)
5793                return;
5794
5795            // heal for caster damage (must be alive)
5796            if(m_target != pCaster && GetSpellProto()->SpellVisual==163 && !pCaster->isAlive())
5797                return;
5798
5799            // ignore non positive values (can be result apply spellmods to aura damage
5800            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5801
5802            uint32 pdamage;
5803
5804            if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
5805                pdamage = uint32(m_target->GetMaxHealth() * amount/100);
5806            else
5807                pdamage = amount;
5808
5809            pdamage = pCaster->SpellHealingBonus(GetSpellProto(), pdamage, DOT, m_target);
5810
5811            sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
5812                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5813
5814            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5815            data.append(m_target->GetPackGUID());
5816            data.appendPackGUID(GetCasterGUID());
5817            data << uint32(GetId());
5818            data << uint32(1);
5819            data << uint32(m_modifier.m_auraname);
5820            data << (uint32)pdamage;
5821            m_target->SendMessageToSet(&data,true);
5822
5823            int32 gain = m_target->ModifyHealth(pdamage);
5824
5825            // add HoTs to amount healed in bgs
5826            if( pCaster->GetTypeId() == TYPEID_PLAYER )
5827                if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
5828                    bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
5829
5830            //Do check before because m_modifier.auraName can be invalidate by DealDamage.
5831            bool procSpell = (m_modifier.m_auraname == SPELL_AURA_PERIODIC_HEAL && m_target != pCaster);
5832
5833            m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5834
5835            Unit* target = m_target;                        // aura can be deleted in DealDamage
5836            SpellEntry const* spellProto = GetSpellProto();
5837            bool haveCastItem = GetCastItemGUID()!=0;
5838
5839            // heal for caster damage
5840            if(m_target!=pCaster && spellProto->SpellVisual==163)
5841            {
5842                uint32 dmg = spellProto->manaPerSecond;
5843                if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
5844                {
5845                    pCaster->RemoveAurasDueToSpell(GetId());
5846
5847                    // finish current generic/channeling spells, don't affect autorepeat
5848                    if(pCaster->m_currentSpells[CURRENT_GENERIC_SPELL])
5849                    {
5850                        pCaster->m_currentSpells[CURRENT_GENERIC_SPELL]->finish();
5851                    }
5852                    if(pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL])
5853                    {
5854                        pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL]->SendChannelUpdate(0);
5855                        pCaster->m_currentSpells[CURRENT_CHANNELED_SPELL]->finish();
5856                    }
5857                }
5858                else
5859                {
5860                    pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), gain, GetSpellSchoolMask(GetSpellProto()), 0, 0, false, 0, false);
5861
5862                    CleanDamage cleanDamage =  CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
5863                    pCaster->DealDamage(pCaster, gain, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
5864                }
5865            }
5866
5867            // ignore item heals
5868            if(procSpell && !haveCastItem)
5869                pCaster->ProcDamageAndSpell(target,PROC_FLAG_NONE, PROC_FLAG_HEALED, pdamage, SPELL_SCHOOL_MASK_NONE, spellProto);
5870            break;
5871        }
5872        case SPELL_AURA_PERIODIC_MANA_LEECH:
5873        {
5874            Unit *pCaster = GetCaster();
5875            if(!pCaster)
5876                return;
5877
5878            if(!pCaster->isAlive())
5879                return;
5880
5881            if( GetSpellProto()->Effect[GetEffIndex()]==SPELL_EFFECT_PERSISTENT_AREA_AURA &&
5882                pCaster->SpellHitResult(m_target,GetSpellProto(),false)!=SPELL_MISS_NONE)
5883                return;
5884
5885            // Check for immune (not use charges)
5886            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
5887                return;
5888
5889            // ignore non positive values (can be result apply spellmods to aura damage
5890            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5891
5892            sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
5893                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5894
5895            if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue > 4)
5896                break;
5897
5898            Powers power = Powers(m_modifier.m_miscvalue);
5899
5900            // power type might have changed between aura applying and tick (druid's shapeshift)
5901            if(m_target->getPowerType() != power)
5902                break;
5903
5904            int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
5905
5906            // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
5907            if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
5908                drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
5909
5910            m_target->ModifyPower(power, -drain_amount);
5911
5912            float gain_multiplier = 0;
5913
5914            if(pCaster->GetMaxPower(power) > 0)
5915            {
5916                gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
5917
5918                if(Player *modOwner = pCaster->GetSpellModOwner())
5919                    modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
5920            }
5921
5922            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5923            data.append(m_target->GetPackGUID());
5924            data.appendPackGUID(GetCasterGUID());
5925            data << uint32(GetId());
5926            data << uint32(1);
5927            data << uint32(m_modifier.m_auraname);
5928            data << (uint32)power;                          // power type
5929            data << (uint32)drain_amount;
5930            data << (float)gain_multiplier;
5931            m_target->SendMessageToSet(&data,true);
5932
5933            int32 gain_amount = int32(drain_amount*gain_multiplier);
5934
5935            if(gain_amount)
5936            {
5937                int32 gain = pCaster->ModifyPower(power,gain_amount);
5938                m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
5939            }
5940            break;
5941        }
5942        case SPELL_AURA_PERIODIC_ENERGIZE:
5943        {
5944            // ignore non positive values (can be result apply spellmods to aura damage
5945            uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5946
5947            sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
5948                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5949
5950            if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue > 4)
5951                break;
5952
5953            Powers power = Powers(m_modifier.m_miscvalue);
5954
5955            if(m_target->GetMaxPower(power) == 0)
5956                break;
5957
5958            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5959            data.append(m_target->GetPackGUID());
5960            data.appendPackGUID(GetCasterGUID());
5961            data << uint32(GetId());
5962            data << uint32(1);
5963            data << uint32(m_modifier.m_auraname);
5964            data << (uint32)power;                          // power type
5965            data << (uint32)pdamage;
5966            m_target->SendMessageToSet(&data,true);
5967
5968            int32 gain = m_target->ModifyPower(power,pdamage);
5969
5970            if(Unit* pCaster = GetCaster())
5971                m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
5972            break;
5973        }
5974        case SPELL_AURA_OBS_MOD_MANA:
5975        {
5976            // ignore non positive values (can be result apply spellmods to aura damage
5977            uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
5978
5979            uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount/100);
5980
5981            sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
5982                GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
5983
5984            if(m_target->GetMaxPower(POWER_MANA) == 0)
5985                break;
5986
5987            WorldPacket data(SMSG_PERIODICAURALOG, (21+16));// we guess size
5988            data.append(m_target->GetPackGUID());
5989            data.appendPackGUID(GetCasterGUID());
5990            data << uint32(GetId());
5991            data << uint32(1);
5992            data << uint32(m_modifier.m_auraname);
5993            data << (uint32)0;                              // ?
5994            data << (uint32)pdamage;
5995            m_target->SendMessageToSet(&data,true);
5996
5997            int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
5998
5999            if(Unit* pCaster = GetCaster())
6000                m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6001            break;
6002        }
6003        case SPELL_AURA_POWER_BURN_MANA:
6004        {
6005            Unit *pCaster = GetCaster();
6006            if(!pCaster)
6007                return;
6008
6009            // Check for immune (not use charges)
6010            if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6011                return;
6012
6013            int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6014
6015            Powers powerType = Powers(m_modifier.m_miscvalue);
6016
6017            if(!m_target->isAlive() || m_target->getPowerType() != powerType)
6018                return;
6019
6020            // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6021            if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6022                pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
6023
6024            uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
6025
6026            gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
6027
6028            //maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
6029            pCaster->SpellNonMeleeDamageLog(m_target, GetId(), gain);
6030            break;
6031        }
6032        // Here tick dummy auras
6033        case SPELL_AURA_PERIODIC_DUMMY:
6034        {
6035            PeriodicDummyTick();
6036            break;
6037        }
6038        default:
6039            break;
6040    }
6041}
6042
6043void Aura::PeriodicDummyTick()
6044{
6045    SpellEntry const* spell = GetSpellProto();
6046    switch (spell->Id)
6047    {
6048        // Drink
6049        case 430:
6050        case 431:
6051        case 432:
6052        case 1133:
6053        case 1135:
6054        case 1137:
6055        case 10250:
6056        case 22734:
6057        case 27089:
6058        case 34291:
6059        case 43706:
6060        case 46755:
6061        {
6062            if (m_target->GetTypeId() != TYPEID_PLAYER)
6063                return;
6064            // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6065            Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6066            for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6067            {
6068                if ((*i)->GetId() == GetId())
6069                {
6070                    // Get tick number
6071                    int32 tick = (m_maxduration - m_duration) / m_modifier.periodictime;
6072                    // Default case (not on arenas)
6073                    if (tick == 0)
6074                    {
6075                        (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6076                        ((Player*)m_target)->UpdateManaRegen();
6077                        // Disable continue
6078                        m_isPeriodic = false;
6079                    }
6080                    return;
6081                    //**********************************************
6082                    // Code commended since arena patch not added
6083                    // This feature uses only in arenas
6084                    //**********************************************
6085                    // Here need increase mana regen per tick (6 second rule)
6086                    // on 0 tick -   0  (handled in 2 second)
6087                    // on 1 tick - 166% (handled in 4 second)
6088                    // on 2 tick - 133% (handled in 6 second)
6089                    // Not need update after 3 tick
6090                    /*
6091                    if (tick > 3)
6092                        return;
6093                    // Apply bonus for 0 - 3 tick
6094                    switch (tick)
6095                    {
6096                        case 0:   // 0%
6097                            (*i)->GetModifier()->m_amount = m_modifier.m_amount = 0;
6098                            break;
6099                        case 1:   // 166%
6100                            (*i)->GetModifier()->m_amount = m_modifier.m_amount * 5 / 3;
6101                            break;
6102                        case 2:   // 133%
6103                            (*i)->GetModifier()->m_amount = m_modifier.m_amount * 4 / 3;
6104                            break;
6105                        default:  // 100% - normal regen
6106                            (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6107                            break;
6108                    }
6109                    ((Player*)m_target)->UpdateManaRegen();
6110                    return;*/
6111                }
6112            }
6113            return;
6114        }
6115//        // Panda
6116//        case 19230: break;
6117//        // Master of Subtlety
6118//        case 31666: break;
6119//        // Gossip NPC Periodic - Talk
6120//        case 33208: break;
6121//        // Gossip NPC Periodic - Despawn
6122//        case 33209: break;
6123//        // Force of Nature
6124//        case 33831: break;
6125        // Aspect of the Viper
6126        case 34074:
6127        {
6128            if (m_target->GetTypeId() != TYPEID_PLAYER)
6129                return;
6130            // Should be manauser
6131            if (m_target->getPowerType()!=POWER_MANA)
6132                return;
6133            Unit *caster = GetCaster();
6134            if (!caster)
6135                return;
6136            // Regen amount is max (100% from spell) on 21% or less mana and min on 92.5% or greater mana (20% from spell)
6137            int mana = m_target->GetPower(POWER_MANA);
6138            int max_mana = m_target->GetMaxPower(POWER_MANA);
6139            int32 base_regen = caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, m_target);
6140            float regen_pct = 1.20f - 1.1f * mana / max_mana;
6141            if      (regen_pct > 1.0f) regen_pct = 1.0f;
6142            else if (regen_pct < 0.2f) regen_pct = 0.2f;
6143            m_modifier.m_amount = int32 (base_regen * regen_pct);
6144            ((Player*)m_target)->UpdateManaRegen();
6145            return;
6146        }
6147//        // Steal Weapon
6148//        case 36207: break;
6149//        // Simon Game START timer, (DND)
6150//        case 39993: break;
6151//        // Harpooner's Mark
6152//        case 40084: break;
6153//        // Knockdown Fel Cannon: break; The Aggro Burst
6154//        case 40119: break;
6155//        // Old Mount Spell
6156//        case 40154: break;
6157//        // Magnetic Pull
6158//        case 40581: break;
6159//        // Ethereal Ring: break; The Bolt Burst
6160//        case 40801: break;
6161//        // Crystal Prison
6162//        case 40846: break;
6163//        // Copy Weapon
6164//        case 41054: break;
6165//        // Ethereal Ring Visual, Lightning Aura
6166//        case 41477: break;
6167//        // Ethereal Ring Visual, Lightning Aura (Fork)
6168//        case 41525: break;
6169//        // Ethereal Ring Visual, Lightning Jumper Aura
6170//        case 41567: break;
6171//        // No Man's Land
6172//        case 41955: break;
6173//        // Headless Horseman - Fire
6174//        case 42074: break;
6175//        // Headless Horseman - Visual - Large Fire
6176//        case 42075: break;
6177//        // Headless Horseman - Start Fire, Periodic Aura
6178//        case 42140: break;
6179//        // Ram Speed Boost
6180//        case 42152: break;
6181//        // Headless Horseman - Fires Out Victory Aura
6182//        case 42235: break;
6183//        // Pumpkin Life Cycle
6184//        case 42280: break;
6185//        // Brewfest Request Chick Chuck Mug Aura
6186//        case 42537: break;
6187//        // Squashling
6188//        case 42596: break;
6189//        // Headless Horseman Climax, Head: Periodic
6190//        case 42603: break;
6191//        // Fire Bomb
6192//        case 42621: break;
6193//        // Headless Horseman - Conflagrate, Periodic Aura
6194//        case 42637: break;
6195//        // Headless Horseman - Create Pumpkin Treats Aura
6196//        case 42774: break;
6197//        // Headless Horseman Climax - Summoning Rhyme Aura
6198//        case 42879: break;
6199//        // Tricky Treat
6200//        case 42919: break;
6201//        // Giddyup!
6202//        case 42924: break;
6203//        // Ram - Trot
6204//        case 42992: break;
6205//        // Ram - Canter
6206//        case 42993: break;
6207//        // Ram - Gallop
6208//        case 42994: break;
6209//        // Ram Level - Neutral
6210//        case 43310: break;
6211//        // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6212//        case 43884: break;
6213//        // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6214//        case 44000: break;
6215//        // Energy Feedback
6216//        case 44328: break;
6217//        // Romantic Picnic
6218//        case 45102: break;
6219//        // Romantic Picnic
6220//        case 45123: break;
6221//        // Looking for Love
6222//        case 45124: break;
6223//        // Kite - Lightning Strike Kite Aura
6224//        case 45197: break;
6225//        // Rocket Chicken
6226//        case 45202: break;
6227//        // Copy Offhand Weapon
6228//        case 45205: break;
6229//        // Upper Deck - Kite - Lightning Periodic Aura
6230//        case 45207: break;
6231//        // Kite -Sky  Lightning Strike Kite Aura
6232//        case 45251: break;
6233//        // Ribbon Pole Dancer Check Aura
6234//        case 45390: break;
6235//        // Holiday - Midsummer, Ribbon Pole Periodic Visual
6236//        case 45406: break;
6237//        // Parachute
6238//        case 45472: break;
6239//        // Alliance Flag, Extra Damage Debuff
6240//        case 45898: break;
6241//        // Horde Flag, Extra Damage Debuff
6242//        case 45899: break;
6243//        // Ahune - Summoning Rhyme Aura
6244//        case 45926: break;
6245//        // Ahune - Slippery Floor
6246//        case 45945: break;
6247//        // Ahune's Shield
6248//        case 45954: break;
6249//        // Nether Vapor Lightning
6250//        case 45960: break;
6251//        // Darkness
6252//        case 45996: break;
6253//        // Summon Blood Elves Periodic
6254//        case 46041: break;
6255//        // Transform Visual Missile Periodic
6256//        case 46205: break;
6257//        // Find Opening Beam End
6258//        case 46333: break;
6259//        // Ice Spear Control Aura
6260//        case 46371: break;
6261//        // Hailstone Chill
6262//        case 46458: break;
6263//        // Hailstone Chill, Internal
6264//        case 46465: break;
6265//        // Chill, Internal Shifter
6266//        case 46549: break;
6267//        // Summon Ice Spear Knockback Delayer
6268//        case 46878: break;
6269//        // Burninate Effect
6270//        case 47214: break;
6271//        // Fizzcrank Practice Parachute
6272//        case 47228: break;
6273//        // Send Mug Control Aura
6274//        case 47369: break;
6275//        // Direbrew's Disarm (precast)
6276//        case 47407: break;
6277//        // Mole Machine Port Schedule
6278//        case 47489: break;
6279//        // Mole Machine Portal Schedule
6280//        case 49466: break;
6281//        // Drink Coffee
6282//        case 49472: break;
6283//        // Listening to Music
6284//        case 50493: break;
6285//        // Love Rocket Barrage
6286//        case 50530: break;
6287        default:
6288            break;
6289    }
6290}
6291
6292void Aura::HandlePreventFleeing(bool apply, bool Real)
6293{
6294    if(!Real)
6295        return;
6296
6297    Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
6298    if( !fearAuras.empty() )
6299    {
6300        if (apply)
6301            m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
6302        else
6303            m_target->SetFeared(true);
6304    }
6305}
6306
6307void Aura::HandleManaShield(bool apply, bool Real)
6308{
6309    if(!Real)
6310        return;
6311
6312    // prevent double apply bonuses
6313    if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
6314    {
6315        if(Unit* caster = GetCaster())
6316        {
6317            float DoneActualBenefit = 0.0f;
6318            switch(m_spellProto->SpellFamilyName)
6319            {
6320                case SPELLFAMILY_MAGE:
6321                    if(m_spellProto->SpellFamilyFlags & 0x8000)
6322                    {
6323                        // Mana Shield
6324                        // +50% from +spd bonus
6325                        DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
6326                        break;
6327                    }
6328                    break;
6329                default:
6330                    break;
6331            }
6332
6333            DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6334
6335            m_modifier.m_amount += (int32)DoneActualBenefit;
6336        }
6337    }
6338}
6339
6340void Aura::HandleArenaPreparation(bool apply, bool Real)
6341{
6342    if(!Real)
6343        return;
6344
6345    if(apply)
6346        m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
6347    else
6348        m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
6349}
Note: See TracBrowser for help on using the browser.