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

Revision 233, 248.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Reimplemented packet/update forwarding in more generic way
* Implemented far sight spells (Far Sight, Eagle Eye, etc) at unlimited range and properly forward packets
* Implemented bind vision spells (Mind Vision, etc) to forward packets at unlimited distance
* Implemented Sentry Totem (both vision switching/forwarding and alerting)
* Other misc possession fixes
* Added .bindsight and .unbindsight commands

Please test out the above spells (including Mind Control) and report any issues on the forums.

Original author: gvcoman
Date: 2008-11-14 20:40:35-06:00

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