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

Revision 123, 250.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Changed modelid_a/h(2) values to modelid1..4, display ids are no longer incorrectly chosen based on player faction. Patch provided by WarHead?.

Original author: w12x
Date: 2008-10-27 11:48:45-05:00

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