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

Revision 44, 249.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

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