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

Revision 57, 250.7 kB (checked in by yumileroy, 17 years ago)

[svn] Update some Black Temple boss scripts.
Implement some Black Temple boss spells.
Update maiden of virtue and void reaver scripts. Patch provided by Blaymoira.

Original author: megamage
Date: 2008-10-18 16:25:58-05:00

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