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

Revision 229, 247.8 kB (checked in by yumileroy, 17 years ago)

[svn] *** Source: MaNGOS ***
* Fixed build extractor at Windows Vista. Author: Vladimir
* Fixed comment text and code indentifiers spelling. Author: Vladimir & Paradox.
* Access cached member lists in guild handlers instead of querying the DB. Author: Hunuza
* Small fixes in send/received packet and simple code cleanup also. Author: Vladimir
* Not output error at loading empty character_ticket table. Author: Vladimir
* Not reset display model at shapeshift aura remove if it not set at apply. Author: Arthorius
* Applied props to few files.

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