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

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

[svn] Prevent Bestial Wrath from being applied 5 times when cast by a hunter with The Beast Within talent. Hopefully this will also fix the crashes caused by this spell.
Change 'tbc' to 'expansion' in realmd.sql.

Original author: w12x
Date: 2008-10-23 09:40:37-05:00

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