[8483] Implement glyph 43361.
[getmangos.git] / src / game / SpellAuras.cpp
blob1d0aa0593259eeb74a01fc8fe08cc7b6beb7fe9a
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "Opcodes.h"
24 #include "Log.h"
25 #include "UpdateMask.h"
26 #include "World.h"
27 #include "ObjectMgr.h"
28 #include "SpellMgr.h"
29 #include "Player.h"
30 #include "Unit.h"
31 #include "Spell.h"
32 #include "DynamicObject.h"
33 #include "Group.h"
34 #include "UpdateData.h"
35 #include "ObjectAccessor.h"
36 #include "Policies/SingletonImp.h"
37 #include "Totem.h"
38 #include "Creature.h"
39 #include "Formulas.h"
40 #include "BattleGround.h"
41 #include "CreatureAI.h"
42 #include "ScriptCalls.h"
43 #include "Util.h"
44 #include "GridNotifiers.h"
45 #include "GridNotifiersImpl.h"
46 #include "Vehicle.h"
47 #include "CellImpl.h"
49 #define NULL_AURA_SLOT 0xFF
51 pAuraHandler AuraHandler[TOTAL_AURAS]=
53 &Aura::HandleNULL, // 0 SPELL_AURA_NONE
54 &Aura::HandleBindSight, // 1 SPELL_AURA_BIND_SIGHT
55 &Aura::HandleModPossess, // 2 SPELL_AURA_MOD_POSSESS
56 &Aura::HandlePeriodicDamage, // 3 SPELL_AURA_PERIODIC_DAMAGE
57 &Aura::HandleAuraDummy, // 4 SPELL_AURA_DUMMY
58 &Aura::HandleModConfuse, // 5 SPELL_AURA_MOD_CONFUSE
59 &Aura::HandleModCharm, // 6 SPELL_AURA_MOD_CHARM
60 &Aura::HandleModFear, // 7 SPELL_AURA_MOD_FEAR
61 &Aura::HandlePeriodicHeal, // 8 SPELL_AURA_PERIODIC_HEAL
62 &Aura::HandleModAttackSpeed, // 9 SPELL_AURA_MOD_ATTACKSPEED
63 &Aura::HandleModThreat, // 10 SPELL_AURA_MOD_THREAT
64 &Aura::HandleModTaunt, // 11 SPELL_AURA_MOD_TAUNT
65 &Aura::HandleAuraModStun, // 12 SPELL_AURA_MOD_STUN
66 &Aura::HandleModDamageDone, // 13 SPELL_AURA_MOD_DAMAGE_DONE
67 &Aura::HandleNoImmediateEffect, // 14 SPELL_AURA_MOD_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
68 &Aura::HandleNoImmediateEffect, // 15 SPELL_AURA_DAMAGE_SHIELD implemented in Unit::DoAttackDamage
69 &Aura::HandleModStealth, // 16 SPELL_AURA_MOD_STEALTH
70 &Aura::HandleNoImmediateEffect, // 17 SPELL_AURA_MOD_STEALTH_DETECT
71 &Aura::HandleInvisibility, // 18 SPELL_AURA_MOD_INVISIBILITY
72 &Aura::HandleInvisibilityDetect, // 19 SPELL_AURA_MOD_INVISIBILITY_DETECTION
73 &Aura::HandleAuraModTotalHealthPercentRegen, // 20 SPELL_AURA_OBS_MOD_HEALTH
74 &Aura::HandleAuraModTotalManaPercentRegen, // 21 SPELL_AURA_OBS_MOD_MANA
75 &Aura::HandleAuraModResistance, // 22 SPELL_AURA_MOD_RESISTANCE
76 &Aura::HandlePeriodicTriggerSpell, // 23 SPELL_AURA_PERIODIC_TRIGGER_SPELL
77 &Aura::HandlePeriodicEnergize, // 24 SPELL_AURA_PERIODIC_ENERGIZE
78 &Aura::HandleAuraModPacify, // 25 SPELL_AURA_MOD_PACIFY
79 &Aura::HandleAuraModRoot, // 26 SPELL_AURA_MOD_ROOT
80 &Aura::HandleAuraModSilence, // 27 SPELL_AURA_MOD_SILENCE
81 &Aura::HandleNoImmediateEffect, // 28 SPELL_AURA_REFLECT_SPELLS implement in Unit::SpellHitResult
82 &Aura::HandleAuraModStat, // 29 SPELL_AURA_MOD_STAT
83 &Aura::HandleAuraModSkill, // 30 SPELL_AURA_MOD_SKILL
84 &Aura::HandleAuraModIncreaseSpeed, // 31 SPELL_AURA_MOD_INCREASE_SPEED
85 &Aura::HandleAuraModIncreaseMountedSpeed, // 32 SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
86 &Aura::HandleAuraModDecreaseSpeed, // 33 SPELL_AURA_MOD_DECREASE_SPEED
87 &Aura::HandleAuraModIncreaseHealth, // 34 SPELL_AURA_MOD_INCREASE_HEALTH
88 &Aura::HandleAuraModIncreaseEnergy, // 35 SPELL_AURA_MOD_INCREASE_ENERGY
89 &Aura::HandleAuraModShapeshift, // 36 SPELL_AURA_MOD_SHAPESHIFT
90 &Aura::HandleAuraModEffectImmunity, // 37 SPELL_AURA_EFFECT_IMMUNITY
91 &Aura::HandleAuraModStateImmunity, // 38 SPELL_AURA_STATE_IMMUNITY
92 &Aura::HandleAuraModSchoolImmunity, // 39 SPELL_AURA_SCHOOL_IMMUNITY
93 &Aura::HandleAuraModDmgImmunity, // 40 SPELL_AURA_DAMAGE_IMMUNITY
94 &Aura::HandleAuraModDispelImmunity, // 41 SPELL_AURA_DISPEL_IMMUNITY
95 &Aura::HandleAuraProcTriggerSpell, // 42 SPELL_AURA_PROC_TRIGGER_SPELL implemented in Unit::ProcDamageAndSpellFor and Unit::HandleProcTriggerSpell
96 &Aura::HandleNoImmediateEffect, // 43 SPELL_AURA_PROC_TRIGGER_DAMAGE implemented in Unit::ProcDamageAndSpellFor
97 &Aura::HandleAuraTrackCreatures, // 44 SPELL_AURA_TRACK_CREATURES
98 &Aura::HandleAuraTrackResources, // 45 SPELL_AURA_TRACK_RESOURCES
99 &Aura::HandleUnused, // 46 SPELL_AURA_46 (used in test spells 54054 and 54058, and spell 48050) (3.0.8a)
100 &Aura::HandleAuraModParryPercent, // 47 SPELL_AURA_MOD_PARRY_PERCENT
101 &Aura::HandleNULL, // 48 SPELL_AURA_48 spell Napalm (area damage spell with additional delayed damage effect)
102 &Aura::HandleAuraModDodgePercent, // 49 SPELL_AURA_MOD_DODGE_PERCENT
103 &Aura::HandleNoImmediateEffect, // 50 SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT implemented in Unit::SpellCriticalHealingBonus
104 &Aura::HandleAuraModBlockPercent, // 51 SPELL_AURA_MOD_BLOCK_PERCENT
105 &Aura::HandleAuraModCritPercent, // 52 SPELL_AURA_MOD_CRIT_PERCENT
106 &Aura::HandlePeriodicLeech, // 53 SPELL_AURA_PERIODIC_LEECH
107 &Aura::HandleModHitChance, // 54 SPELL_AURA_MOD_HIT_CHANCE
108 &Aura::HandleModSpellHitChance, // 55 SPELL_AURA_MOD_SPELL_HIT_CHANCE
109 &Aura::HandleAuraTransform, // 56 SPELL_AURA_TRANSFORM
110 &Aura::HandleModSpellCritChance, // 57 SPELL_AURA_MOD_SPELL_CRIT_CHANCE
111 &Aura::HandleAuraModIncreaseSwimSpeed, // 58 SPELL_AURA_MOD_INCREASE_SWIM_SPEED
112 &Aura::HandleNoImmediateEffect, // 59 SPELL_AURA_MOD_DAMAGE_DONE_CREATURE implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
113 &Aura::HandleAuraModPacifyAndSilence, // 60 SPELL_AURA_MOD_PACIFY_SILENCE
114 &Aura::HandleAuraModScale, // 61 SPELL_AURA_MOD_SCALE
115 &Aura::HandlePeriodicHealthFunnel, // 62 SPELL_AURA_PERIODIC_HEALTH_FUNNEL
116 &Aura::HandleUnused, // 63 unused (3.0.8a) old SPELL_AURA_PERIODIC_MANA_FUNNEL
117 &Aura::HandlePeriodicManaLeech, // 64 SPELL_AURA_PERIODIC_MANA_LEECH
118 &Aura::HandleModCastingSpeed, // 65 SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
119 &Aura::HandleFeignDeath, // 66 SPELL_AURA_FEIGN_DEATH
120 &Aura::HandleAuraModDisarm, // 67 SPELL_AURA_MOD_DISARM
121 &Aura::HandleAuraModStalked, // 68 SPELL_AURA_MOD_STALKED
122 &Aura::HandleSchoolAbsorb, // 69 SPELL_AURA_SCHOOL_ABSORB implemented in Unit::CalcAbsorbResist
123 &Aura::HandleUnused, // 70 SPELL_AURA_EXTRA_ATTACKS Useless, used by only one spell that has only visual effect
124 &Aura::HandleModSpellCritChanceShool, // 71 SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
125 &Aura::HandleModPowerCostPCT, // 72 SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
126 &Aura::HandleModPowerCost, // 73 SPELL_AURA_MOD_POWER_COST_SCHOOL
127 &Aura::HandleNoImmediateEffect, // 74 SPELL_AURA_REFLECT_SPELLS_SCHOOL implemented in Unit::SpellHitResult
128 &Aura::HandleNoImmediateEffect, // 75 SPELL_AURA_MOD_LANGUAGE
129 &Aura::HandleFarSight, // 76 SPELL_AURA_FAR_SIGHT
130 &Aura::HandleModMechanicImmunity, // 77 SPELL_AURA_MECHANIC_IMMUNITY
131 &Aura::HandleAuraMounted, // 78 SPELL_AURA_MOUNTED
132 &Aura::HandleModDamagePercentDone, // 79 SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
133 &Aura::HandleModPercentStat, // 80 SPELL_AURA_MOD_PERCENT_STAT
134 &Aura::HandleNoImmediateEffect, // 81 SPELL_AURA_SPLIT_DAMAGE_PCT
135 &Aura::HandleWaterBreathing, // 82 SPELL_AURA_WATER_BREATHING
136 &Aura::HandleModBaseResistance, // 83 SPELL_AURA_MOD_BASE_RESISTANCE
137 &Aura::HandleModRegen, // 84 SPELL_AURA_MOD_REGEN
138 &Aura::HandleModPowerRegen, // 85 SPELL_AURA_MOD_POWER_REGEN
139 &Aura::HandleChannelDeathItem, // 86 SPELL_AURA_CHANNEL_DEATH_ITEM
140 &Aura::HandleNoImmediateEffect, // 87 SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN implemented in Unit::MeleeDamageBonus and Unit::SpellDamageBonus
141 &Aura::HandleNoImmediateEffect, // 88 SPELL_AURA_MOD_HEALTH_REGEN_PERCENT
142 &Aura::HandlePeriodicDamagePCT, // 89 SPELL_AURA_PERIODIC_DAMAGE_PERCENT
143 &Aura::HandleUnused, // 90 unused (3.0.8a) old SPELL_AURA_MOD_RESIST_CHANCE
144 &Aura::HandleNoImmediateEffect, // 91 SPELL_AURA_MOD_DETECT_RANGE implemented in Creature::GetAttackDistance
145 &Aura::HandlePreventFleeing, // 92 SPELL_AURA_PREVENTS_FLEEING
146 &Aura::HandleModUnattackable, // 93 SPELL_AURA_MOD_UNATTACKABLE
147 &Aura::HandleNoImmediateEffect, // 94 SPELL_AURA_INTERRUPT_REGEN implemented in Player::RegenerateAll
148 &Aura::HandleAuraGhost, // 95 SPELL_AURA_GHOST
149 &Aura::HandleNoImmediateEffect, // 96 SPELL_AURA_SPELL_MAGNET implemented in Unit::SelectMagnetTarget
150 &Aura::HandleManaShield, // 97 SPELL_AURA_MANA_SHIELD implemented in Unit::CalcAbsorbResist
151 &Aura::HandleAuraModSkill, // 98 SPELL_AURA_MOD_SKILL_TALENT
152 &Aura::HandleAuraModAttackPower, // 99 SPELL_AURA_MOD_ATTACK_POWER
153 &Aura::HandleUnused, //100 SPELL_AURA_AURAS_VISIBLE obsolete? all player can see all auras now, but still have spells including GM-spell
154 &Aura::HandleModResistancePercent, //101 SPELL_AURA_MOD_RESISTANCE_PCT
155 &Aura::HandleNoImmediateEffect, //102 SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
156 &Aura::HandleAuraModTotalThreat, //103 SPELL_AURA_MOD_TOTAL_THREAT
157 &Aura::HandleAuraWaterWalk, //104 SPELL_AURA_WATER_WALK
158 &Aura::HandleAuraFeatherFall, //105 SPELL_AURA_FEATHER_FALL
159 &Aura::HandleAuraHover, //106 SPELL_AURA_HOVER
160 &Aura::HandleAddModifier, //107 SPELL_AURA_ADD_FLAT_MODIFIER
161 &Aura::HandleAddModifier, //108 SPELL_AURA_ADD_PCT_MODIFIER
162 &Aura::HandleAddTargetTrigger, //109 SPELL_AURA_ADD_TARGET_TRIGGER
163 &Aura::HandleModPowerRegenPCT, //110 SPELL_AURA_MOD_POWER_REGEN_PERCENT
164 &Aura::HandleNoImmediateEffect, //111 SPELL_AURA_ADD_CASTER_HIT_TRIGGER implemented in Unit::SelectMagnetTarget
165 &Aura::HandleNoImmediateEffect, //112 SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
166 &Aura::HandleNoImmediateEffect, //113 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
167 &Aura::HandleNoImmediateEffect, //114 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
168 &Aura::HandleNoImmediateEffect, //115 SPELL_AURA_MOD_HEALING implemented in Unit::SpellBaseHealingBonusForVictim
169 &Aura::HandleNoImmediateEffect, //116 SPELL_AURA_MOD_REGEN_DURING_COMBAT
170 &Aura::HandleNoImmediateEffect, //117 SPELL_AURA_MOD_MECHANIC_RESISTANCE implemented in Unit::MagicSpellHitResult
171 &Aura::HandleNoImmediateEffect, //118 SPELL_AURA_MOD_HEALING_PCT implemented in Unit::SpellHealingBonus
172 &Aura::HandleUnused, //119 unused (3.0.8a) old SPELL_AURA_SHARE_PET_TRACKING
173 &Aura::HandleAuraUntrackable, //120 SPELL_AURA_UNTRACKABLE
174 &Aura::HandleAuraEmpathy, //121 SPELL_AURA_EMPATHY
175 &Aura::HandleModOffhandDamagePercent, //122 SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT
176 &Aura::HandleModTargetResistance, //123 SPELL_AURA_MOD_TARGET_RESISTANCE
177 &Aura::HandleAuraModRangedAttackPower, //124 SPELL_AURA_MOD_RANGED_ATTACK_POWER
178 &Aura::HandleNoImmediateEffect, //125 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus
179 &Aura::HandleNoImmediateEffect, //126 SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus
180 &Aura::HandleNoImmediateEffect, //127 SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
181 &Aura::HandleModPossessPet, //128 SPELL_AURA_MOD_POSSESS_PET
182 &Aura::HandleAuraModIncreaseSpeed, //129 SPELL_AURA_MOD_SPEED_ALWAYS
183 &Aura::HandleAuraModIncreaseMountedSpeed, //130 SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
184 &Aura::HandleNoImmediateEffect, //131 SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS implemented in Unit::MeleeDamageBonus
185 &Aura::HandleAuraModIncreaseEnergyPercent, //132 SPELL_AURA_MOD_INCREASE_ENERGY_PERCENT
186 &Aura::HandleAuraModIncreaseHealthPercent, //133 SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT
187 &Aura::HandleAuraModRegenInterrupt, //134 SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
188 &Aura::HandleModHealingDone, //135 SPELL_AURA_MOD_HEALING_DONE
189 &Aura::HandleNoImmediateEffect, //136 SPELL_AURA_MOD_HEALING_DONE_PERCENT implemented in Unit::SpellHealingBonus
190 &Aura::HandleModTotalPercentStat, //137 SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE
191 &Aura::HandleHaste, //138 SPELL_AURA_MOD_HASTE
192 &Aura::HandleForceReaction, //139 SPELL_AURA_FORCE_REACTION
193 &Aura::HandleAuraModRangedHaste, //140 SPELL_AURA_MOD_RANGED_HASTE
194 &Aura::HandleRangedAmmoHaste, //141 SPELL_AURA_MOD_RANGED_AMMO_HASTE
195 &Aura::HandleAuraModBaseResistancePCT, //142 SPELL_AURA_MOD_BASE_RESISTANCE_PCT
196 &Aura::HandleAuraModResistanceExclusive, //143 SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE
197 &Aura::HandleAuraSafeFall, //144 SPELL_AURA_SAFE_FALL implemented in WorldSession::HandleMovementOpcodes
198 &Aura::HandleAuraModPetTalentsPoints, //145 SPELL_AURA_MOD_PET_TALENT_POINTS
199 &Aura::HandleNoImmediateEffect, //146 SPELL_AURA_ALLOW_TAME_PET_TYPE
200 &Aura::HandleNULL, //147 SPELL_AURA_ADD_CREATURE_IMMUNITY
201 &Aura::HandleAuraRetainComboPoints, //148 SPELL_AURA_RETAIN_COMBO_POINTS
202 &Aura::HandleNoImmediateEffect, //149 SPELL_AURA_REDUCE_PUSHBACK
203 &Aura::HandleShieldBlockValue, //150 SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT
204 &Aura::HandleAuraTrackStealthed, //151 SPELL_AURA_TRACK_STEALTHED
205 &Aura::HandleNoImmediateEffect, //152 SPELL_AURA_MOD_DETECTED_RANGE implemented in Creature::GetAttackDistance
206 &Aura::HandleNoImmediateEffect, //153 SPELL_AURA_SPLIT_DAMAGE_FLAT
207 &Aura::HandleNoImmediateEffect, //154 SPELL_AURA_MOD_STEALTH_LEVEL
208 &Aura::HandleNoImmediateEffect, //155 SPELL_AURA_MOD_WATER_BREATHING
209 &Aura::HandleNoImmediateEffect, //156 SPELL_AURA_MOD_REPUTATION_GAIN
210 &Aura::HandleNULL, //157 SPELL_AURA_PET_DAMAGE_MULTI
211 &Aura::HandleShieldBlockValue, //158 SPELL_AURA_MOD_SHIELD_BLOCKVALUE
212 &Aura::HandleNoImmediateEffect, //159 SPELL_AURA_NO_PVP_CREDIT only for Honorless Target spell
213 &Aura::HandleNoImmediateEffect, //160 SPELL_AURA_MOD_AOE_AVOIDANCE implemented in Unit::MagicSpellHitResult
214 &Aura::HandleNoImmediateEffect, //161 SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
215 &Aura::HandleAuraPowerBurn, //162 SPELL_AURA_POWER_BURN_MANA
216 &Aura::HandleNoImmediateEffect, //163 SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
217 &Aura::HandleUnused, //164 unused (3.0.8a), only one test spell
218 &Aura::HandleNoImmediateEffect, //165 SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus
219 &Aura::HandleAuraModAttackPowerPercent, //166 SPELL_AURA_MOD_ATTACK_POWER_PCT
220 &Aura::HandleAuraModRangedAttackPowerPercent, //167 SPELL_AURA_MOD_RANGED_ATTACK_POWER_PCT
221 &Aura::HandleNoImmediateEffect, //168 SPELL_AURA_MOD_DAMAGE_DONE_VERSUS implemented in Unit::SpellDamageBonus, Unit::MeleeDamageBonus
222 &Aura::HandleNoImmediateEffect, //169 SPELL_AURA_MOD_CRIT_PERCENT_VERSUS implemented in Unit::DealDamageBySchool, Unit::DoAttackDamage, Unit::SpellCriticalBonus
223 &Aura::HandleNULL, //170 SPELL_AURA_DETECT_AMORE different spells that ignore transformation effects
224 &Aura::HandleAuraModIncreaseSpeed, //171 SPELL_AURA_MOD_SPEED_NOT_STACK
225 &Aura::HandleAuraModIncreaseMountedSpeed, //172 SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
226 &Aura::HandleUnused, //173 unused (3.0.8a) no spells, old SPELL_AURA_ALLOW_CHAMPION_SPELLS only for Proclaim Champion spell
227 &Aura::HandleModSpellDamagePercentFromStat, //174 SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT implemented in Unit::SpellBaseDamageBonus
228 &Aura::HandleModSpellHealingPercentFromStat, //175 SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT implemented in Unit::SpellBaseHealingBonus
229 &Aura::HandleSpiritOfRedemption, //176 SPELL_AURA_SPIRIT_OF_REDEMPTION only for Spirit of Redemption spell, die at aura end
230 &Aura::HandleNULL, //177 SPELL_AURA_AOE_CHARM
231 &Aura::HandleNoImmediateEffect, //178 SPELL_AURA_MOD_DEBUFF_RESISTANCE implemented in Unit::MagicSpellHitResult
232 &Aura::HandleNoImmediateEffect, //179 SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE implemented in Unit::SpellCriticalBonus
233 &Aura::HandleNoImmediateEffect, //180 SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS implemented in Unit::SpellDamageBonus
234 &Aura::HandleUnused, //181 unused (3.0.8a) old SPELL_AURA_MOD_FLAT_SPELL_CRIT_DAMAGE_VERSUS
235 &Aura::HandleAuraModResistenceOfStatPercent, //182 SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT
236 &Aura::HandleNULL, //183 SPELL_AURA_MOD_CRITICAL_THREAT only used in 28746
237 &Aura::HandleNoImmediateEffect, //184 SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
238 &Aura::HandleNoImmediateEffect, //185 SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
239 &Aura::HandleNoImmediateEffect, //186 SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE implemented in Unit::MagicSpellHitResult
240 &Aura::HandleNoImmediateEffect, //187 SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE implemented in Unit::GetUnitCriticalChance
241 &Aura::HandleNoImmediateEffect, //188 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE implemented in Unit::GetUnitCriticalChance
242 &Aura::HandleModRating, //189 SPELL_AURA_MOD_RATING
243 &Aura::HandleNoImmediateEffect, //190 SPELL_AURA_MOD_FACTION_REPUTATION_GAIN implemented in Player::CalculateReputationGain
244 &Aura::HandleAuraModUseNormalSpeed, //191 SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
245 &Aura::HandleModMeleeRangedSpeedPct, //192 SPELL_AURA_HASTE_MELEE
246 &Aura::HandleModCombatSpeedPct, //193 SPELL_AURA_MELEE_SLOW (in fact combat (any type attack) speed pct)
247 &Aura::HandleNULL, //194 SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
248 &Aura::HandleNoImmediateEffect, //195 SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL implement in Unit::CalculateSpellDamage
249 &Aura::HandleNULL, //196 SPELL_AURA_MOD_COOLDOWN
250 &Aura::HandleNoImmediateEffect, //197 SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE implemented in Unit::SpellCriticalBonus Unit::GetUnitCriticalChance
251 &Aura::HandleUnused, //198 unused (3.0.8a) old SPELL_AURA_MOD_ALL_WEAPON_SKILLS
252 &Aura::HandleNoImmediateEffect, //199 SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT implemented in Unit::MagicSpellHitResult
253 &Aura::HandleNoImmediateEffect, //200 SPELL_AURA_MOD_XP_PCT implemented in Player::GiveXP
254 &Aura::HandleAuraAllowFlight, //201 SPELL_AURA_FLY this aura enable flight mode...
255 &Aura::HandleNoImmediateEffect, //202 SPELL_AURA_CANNOT_BE_DODGED implemented in Unit::RollPhysicalOutcomeAgainst
256 &Aura::HandleNoImmediateEffect, //203 SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE implemented in Unit::CalculateMeleeDamage and Unit::CalculateSpellDamage
257 &Aura::HandleNoImmediateEffect, //204 SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE implemented in Unit::CalculateMeleeDamage and Unit::CalculateSpellDamage
258 &Aura::HandleNULL, //205 vulnerable to school dmg?
259 &Aura::HandleNULL, //206 SPELL_AURA_MOD_SPEED_MOUNTED
260 &Aura::HandleAuraModIncreaseFlightSpeed, //207 SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
261 &Aura::HandleAuraModIncreaseFlightSpeed, //208 SPELL_AURA_MOD_SPEED_FLIGHT, used only in spell: Flight Form (Passive)
262 &Aura::HandleAuraModIncreaseFlightSpeed, //209 SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
263 &Aura::HandleNULL, //210 Commentator's Command
264 &Aura::HandleAuraModIncreaseFlightSpeed, //211 SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
265 &Aura::HandleAuraModRangedAttackPowerOfStatPercent, //212 SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT
266 &Aura::HandleNoImmediateEffect, //213 SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT implemented in Player::RewardRage
267 &Aura::HandleNULL, //214 Tamed Pet Passive
268 &Aura::HandleArenaPreparation, //215 SPELL_AURA_ARENA_PREPARATION
269 &Aura::HandleModCastingSpeed, //216 SPELL_AURA_HASTE_SPELLS
270 &Aura::HandleUnused, //217 unused (3.0.8a)
271 &Aura::HandleAuraModRangedHaste, //218 SPELL_AURA_HASTE_RANGED
272 &Aura::HandleModManaRegen, //219 SPELL_AURA_MOD_MANA_REGEN_FROM_STAT
273 &Aura::HandleModRatingFromStat, //220 SPELL_AURA_MOD_RATING_FROM_STAT
274 &Aura::HandleNULL, //221 ignored
275 &Aura::HandleUnused, //222 unused (3.0.8a) only for spell 44586 that not used in real spell cast
276 &Aura::HandleNULL, //223 Cold Stare
277 &Aura::HandleUnused, //224 unused (3.0.8a)
278 &Aura::HandleNoImmediateEffect, //225 SPELL_AURA_PRAYER_OF_MENDING
279 &Aura::HandleAuraPeriodicDummy, //226 SPELL_AURA_PERIODIC_DUMMY
280 &Aura::HandlePeriodicTriggerSpellWithValue, //227 SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE
281 &Aura::HandleNoImmediateEffect, //228 stealth detection
282 &Aura::HandleNoImmediateEffect, //229 SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE implemented in Unit::SpellDamageBonus
283 &Aura::HandleAuraModIncreaseMaxHealth, //230 Commanding Shout
284 &Aura::HandleNoImmediateEffect, //231 SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
285 &Aura::HandleNoImmediateEffect, //232 SPELL_AURA_MECHANIC_DURATION_MOD implement in Unit::CalculateSpellDuration
286 &Aura::HandleNULL, //233 set model id to the one of the creature with id m_modifier.m_miscvalue
287 &Aura::HandleNoImmediateEffect, //234 SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK implement in Unit::CalculateSpellDuration
288 &Aura::HandleAuraModDispelResist, //235 SPELL_AURA_MOD_DISPEL_RESIST implement in Unit::MagicSpellHitResult
289 &Aura::HandleAuraControlVehicle, //236 SPELL_AURA_CONTROL_VEHICLE
290 &Aura::HandleModSpellDamagePercentFromAttackPower, //237 SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER implemented in Unit::SpellBaseDamageBonus
291 &Aura::HandleModSpellHealingPercentFromAttackPower, //238 SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER implemented in Unit::SpellBaseHealingBonus
292 &Aura::HandleAuraModScale, //239 SPELL_AURA_MOD_SCALE_2 only in Noggenfogger Elixir (16595) before 2.3.0 aura 61
293 &Aura::HandleAuraModExpertise, //240 SPELL_AURA_MOD_EXPERTISE
294 &Aura::HandleForceMoveForward, //241 Forces the player to move forward
295 &Aura::HandleUnused, //242 SPELL_AURA_MOD_SPELL_DAMAGE_FROM_HEALING
296 &Aura::HandleNULL, //243 faction reaction override spells
297 &Aura::HandleComprehendLanguage, //244 Comprehend language
298 &Aura::HandleNULL, //245 SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
299 &Aura::HandleNoImmediateEffect, //246 SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
300 &Aura::HandleNULL, //247 target to become a clone of the caster
301 &Aura::HandleNoImmediateEffect, //248 SPELL_AURA_MOD_COMBAT_RESULT_CHANCE implemented in Unit::RollMeleeOutcomeAgainst
302 &Aura::HandleAuraConvertRune, //249 SPELL_AURA_CONVERT_RUNE
303 &Aura::HandleAuraModIncreaseHealth, //250 SPELL_AURA_MOD_INCREASE_HEALTH_2
304 &Aura::HandleNULL, //251 SPELL_AURA_MOD_ENEMY_DODGE
305 &Aura::HandleNULL, //252 haste all?
306 &Aura::HandleNULL, //253 SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
307 &Aura::HandleNULL, //254 SPELL_AURA_MOD_DISARM_SHIELD disarm Shield
308 &Aura::HandleNoImmediateEffect, //255 SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT implemented in Unit::SpellDamageBonus
309 &Aura::HandleNoReagentUseAura, //256 SPELL_AURA_NO_REAGENT_USE Use SpellClassMask for spell select
310 &Aura::HandleNULL, //257 SPELL_AURA_MOD_TARGET_RESIST_BY_SPELL_CLASS Use SpellClassMask for spell select
311 &Aura::HandleNULL, //258 SPELL_AURA_MOD_SPELL_VISUAL
312 &Aura::HandleNULL, //259 corrupt healing over time spell
313 &Aura::HandleNoImmediateEffect, //260 SPELL_AURA_SCREEN_EFFECT (miscvalue = id in ScreenEffect.dbc) not required any code
314 &Aura::HandlePhase, //261 SPELL_AURA_PHASE undetactable invisibility? implemented in Unit::isVisibleForOrDetect
315 &Aura::HandleNULL, //262
316 &Aura::HandleNULL, //263 SPELL_AURA_ALLOW_ONLY_ABILITY player can use only abilities set in SpellClassMask
317 &Aura::HandleUnused, //264 unused (3.0.8a)
318 &Aura::HandleUnused, //265 unused (3.0.8a)
319 &Aura::HandleUnused, //266 unused (3.0.8a)
320 &Aura::HandleNoImmediateEffect, //267 SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL implemented in Unit::IsImmunedToSpellEffect
321 &Aura::HandleAuraModAttackPowerOfStatPercent, //268 SPELL_AURA_MOD_ATTACK_POWER_OF_STAT_PERCENT
322 &Aura::HandleNULL, //269 ignore DR effects?
323 &Aura::HandleNULL, //270 SPELL_AURA_MOD_IGNORE_TARGET_RESIST
324 &Aura::HandleNoImmediateEffect, //271 SPELL_AURA_MOD_DAMAGE_FROM_CASTER implemented in Unit::SpellDamageBonus
325 &Aura::HandleNULL, //272 reduce spell cast time?
326 &Aura::HandleNULL, //273
327 &Aura::HandleNULL, //274 proc free shot?
328 &Aura::HandleNoImmediateEffect, //275 SPELL_AURA_MOD_IGNORE_SHAPESHIFT Use SpellClassMask for spell select
329 &Aura::HandleNULL, //276 mod damage % mechanic?
330 &Aura::HandleNoImmediateEffect, //277 SPELL_AURA_MOD_MAX_AFFECTED_TARGETS Use SpellClassMask for spell select
331 &Aura::HandleNULL, //278 SPELL_AURA_MOD_DISARM_RANGED disarm ranged weapon
332 &Aura::HandleNULL, //279 visual effects? 58836 and 57507
333 &Aura::HandleModTargetArmorPct, //280 SPELL_AURA_MOD_TARGET_ARMOR_PCT
334 &Aura::HandleNULL, //281 SPELL_AURA_MOD_HONOR_GAIN
335 &Aura::HandleAuraIncreaseBaseHealthPercent, //282 SPELL_AURA_INCREASE_BASE_HEALTH_PERCENT
336 &Aura::HandleNoImmediateEffect, //283 SPELL_AURA_MOD_HEALING_RECEIVED implemented in Unit::SpellHealingBonus
337 &Aura::HandleUnused, //284 not used by any spells (3.08a)
338 &Aura::HandleAuraModAttackPowerOfArmor, //285 SPELL_AURA_MOD_ATTACK_POWER_OF_ARMOR implemented in Player::UpdateAttackPowerAndDamage
339 &Aura::HandleNoImmediateEffect, //286 SPELL_AURA_ABILITY_PERIODIC_CRIT implemented in Aura::IsCritFromAbilityAura called from Aura::PeriodicTick
340 &Aura::HandleNoImmediateEffect, //287 SPELL_AURA_DEFLECT_SPELLS implemented in Unit::MagicSpellHitResult and Unit::MeleeSpellHitResult
341 &Aura::HandleUnused, //288 not used by any spells (3.09) except 1 test spell.
342 &Aura::HandleUnused, //289 unused
343 &Aura::HandleUnused, //290 unused
344 &Aura::HandleUnused, //291 unused
345 &Aura::HandleNULL, //292 call stabled pet
346 &Aura::HandleNULL, //293 2 test spells
347 &Aura::HandleNULL //294 2 spells, possible prevent mana regen
350 static AuraType const frozenAuraTypes[] = { SPELL_AURA_MOD_ROOT, SPELL_AURA_MOD_STUN, SPELL_AURA_NONE };
352 Aura::Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem) :
353 m_spellmod(NULL), m_caster_guid(0), m_target(target), m_castItemGuid(castItem?castItem->GetGUID():0),
354 m_timeCla(1000), m_periodicTimer(0), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_AuraDRGroup(DIMINISHING_NONE),
355 m_effIndex(eff), m_auraSlot(MAX_AURAS), m_auraFlags(AFLAG_NONE), m_auraLevel(1), m_procCharges(0), m_stackAmount(1),
356 m_positive(false), m_permanent(false), m_isPeriodic(false), m_isAreaAura(false), m_isPersistent(false),
357 m_isRemovedOnShapeLost(true), m_in_use(0), m_deleted(false)
359 assert(target);
361 assert(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
363 m_spellProto = spellproto;
365 m_currentBasePoints = currentBasePoints ? *currentBasePoints : m_spellProto->EffectBasePoints[eff];
367 m_isPassive = IsPassiveSpell(GetId());
368 m_positive = IsPositiveEffect(GetId(), m_effIndex);
370 m_isSingleTargetAura = IsSingleTargetSpell(m_spellProto);
372 m_applyTime = time(NULL);
374 int32 damage;
375 if(!caster)
377 m_caster_guid = target->GetGUID();
378 damage = m_currentBasePoints+1; // stored value-1
379 m_maxduration = target->CalculateSpellDuration(m_spellProto, m_effIndex, target);
381 else
383 m_caster_guid = caster->GetGUID();
385 damage = caster->CalculateSpellDamage(m_spellProto,m_effIndex,m_currentBasePoints,target);
386 m_maxduration = caster->CalculateSpellDuration(m_spellProto, m_effIndex, target);
388 if (!damage && castItem && castItem->GetItemSuffixFactor())
390 ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
391 if(item_rand_suffix)
393 for (int k = 0; k < 3; ++k)
395 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand_suffix->enchant_id[k]);
396 if(pEnchant)
398 for (int t = 0; t < 3; ++t)
399 if(pEnchant->spellid[t] == m_spellProto->Id)
401 damage = uint32((item_rand_suffix->prefix[k]*castItem->GetItemSuffixFactor()) / 10000 );
402 break;
406 if(damage)
407 break;
413 if(m_maxduration == -1 || m_isPassive && m_spellProto->DurationIndex == 0)
414 m_permanent = true;
416 Player* modOwner = caster ? caster->GetSpellModOwner() : NULL;
418 if(!m_permanent && modOwner)
420 modOwner->ApplySpellMod(GetId(), SPELLMOD_DURATION, m_maxduration);
421 // Get zero duration aura after - need set m_maxduration > 0 for apply/remove aura work
422 if (m_maxduration<=0)
423 m_maxduration = 1;
426 m_duration = m_maxduration;
428 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);
430 m_effIndex = eff;
431 SetModifier(AuraType(m_spellProto->EffectApplyAuraName[eff]), damage, m_spellProto->EffectAmplitude[eff], m_spellProto->EffectMiscValue[eff]);
433 // Apply periodic time mod
434 if(modOwner && m_modifier.periodictime)
435 modOwner->ApplySpellMod(GetId(), SPELLMOD_ACTIVATION_TIME, m_modifier.periodictime);
437 // Start periodic on next tick or at aura apply
438 if (!(m_spellProto->AttributesEx5 & SPELL_ATTR_EX5_START_PERIODIC_AT_APPLY))
439 m_periodicTimer += m_modifier.periodictime;
441 m_isDeathPersist = IsDeathPersistentSpell(m_spellProto);
443 m_procCharges = m_spellProto->procCharges;
444 if(modOwner)
445 modOwner->ApplySpellMod(GetId(), SPELLMOD_CHARGES, m_procCharges);
447 m_isRemovedOnShapeLost = (m_caster_guid==m_target->GetGUID() &&
448 m_spellProto->Stances &&
449 !(m_spellProto->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) &&
450 !(m_spellProto->Attributes & SPELL_ATTR_NOT_SHAPESHIFT));
453 Aura::~Aura()
457 AreaAura::AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
458 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
460 m_isAreaAura = true;
462 // caster==NULL in constructor args if target==caster in fact
463 Unit* caster_ptr = caster ? caster : target;
465 m_radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(GetSpellProto()->EffectRadiusIndex[m_effIndex]));
466 if(Player* modOwner = caster_ptr->GetSpellModOwner())
467 modOwner->ApplySpellMod(GetId(), SPELLMOD_RADIUS, m_radius);
469 switch(spellproto->Effect[eff])
471 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
472 m_areaAuraType = AREA_AURA_PARTY;
473 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
474 m_modifier.m_auraname = SPELL_AURA_NONE;
475 break;
476 case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
477 m_areaAuraType = AREA_AURA_RAID;
478 if (target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isTotem())
479 m_modifier.m_auraname = SPELL_AURA_NONE;
480 break;
481 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
482 m_areaAuraType = AREA_AURA_FRIEND;
483 break;
484 case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
485 m_areaAuraType = AREA_AURA_ENEMY;
486 if (target == caster_ptr)
487 m_modifier.m_auraname = SPELL_AURA_NONE; // Do not do any effect on self
488 break;
489 case SPELL_EFFECT_APPLY_AREA_AURA_PET:
490 m_areaAuraType = AREA_AURA_PET;
491 break;
492 case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
493 m_areaAuraType = AREA_AURA_OWNER;
494 if (target == caster_ptr)
495 m_modifier.m_auraname = SPELL_AURA_NONE;
496 break;
497 default:
498 sLog.outError("Wrong spell effect in AreaAura constructor");
499 ASSERT(false);
500 break;
504 AreaAura::~AreaAura()
508 PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
509 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
511 m_isPersistent = true;
514 PersistentAreaAura::~PersistentAreaAura()
518 SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target,
519 Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, target, caster, castItem)
521 if (caster)
522 m_casters_target_guid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelection() : caster->GetUInt64Value(UNIT_FIELD_TARGET);
523 else
524 m_casters_target_guid = 0;
527 SingleEnemyTargetAura::~SingleEnemyTargetAura()
531 Unit* SingleEnemyTargetAura::GetTriggerTarget() const
533 return ObjectAccessor::GetUnit(*m_target, m_casters_target_guid);
536 Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem)
538 if (IsAreaAuraEffect(spellproto->Effect[eff]))
539 return new AreaAura(spellproto, eff, currentBasePoints, target, caster, castItem);
541 uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff];
543 if(SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
544 for (int i = 0; i < 3; ++i)
545 if (triggeredSpellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_ENEMY)
546 return new SingleEnemyTargetAura(spellproto, eff, currentBasePoints, target, caster, castItem);
548 return new Aura(spellproto, eff, currentBasePoints, target, caster, castItem);
551 Unit* Aura::GetCaster() const
553 if(m_caster_guid==m_target->GetGUID())
554 return m_target;
556 //return ObjectAccessor::GetUnit(*m_target,m_caster_guid);
557 //must return caster even if it's in another grid/map
558 Unit *unit = ObjectAccessor::GetObjectInWorld(m_caster_guid, (Unit*)NULL);
559 return unit && unit->IsInWorld() ? unit : NULL;
562 void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
564 m_modifier.m_auraname = t;
565 m_modifier.m_amount = a;
566 m_modifier.m_miscvalue = miscValue;
567 m_modifier.periodictime = pt;
570 void Aura::Update(uint32 diff)
572 if (m_duration > 0)
574 m_duration -= diff;
575 if (m_duration < 0)
576 m_duration = 0;
577 m_timeCla -= diff;
579 // GetEffIndex()==0 prevent double/triple apply manaPerSecond/manaPerSecondPerLevel to same spell with many auras
580 // all spells with manaPerSecond/manaPerSecondPerLevel have aura in effect 0
581 if(GetEffIndex()==0 && m_timeCla <= 0)
583 if(Unit* caster = GetCaster())
585 Powers powertype = Powers(m_spellProto->powerType);
586 int32 manaPerSecond = m_spellProto->manaPerSecond + m_spellProto->manaPerSecondPerLevel * caster->getLevel();
587 m_timeCla = 1*IN_MILISECONDS;
588 if (manaPerSecond)
590 if(powertype==POWER_HEALTH)
591 caster->ModifyHealth(-manaPerSecond);
592 else
593 caster->ModifyPower(powertype,-manaPerSecond);
599 // Channeled aura required check distance from caster
600 if(IsChanneledSpell(m_spellProto) && m_caster_guid != m_target->GetGUID())
602 Unit* caster = GetCaster();
603 if(!caster)
605 m_target->RemoveAura(GetId(), GetEffIndex());
606 return;
609 // Get spell range
610 float radius;
611 SpellModOp mod;
612 if (m_spellProto->EffectRadiusIndex[GetEffIndex()])
614 radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellProto->EffectRadiusIndex[GetEffIndex()]));
615 mod = SPELLMOD_RADIUS;
617 else
619 radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellProto->rangeIndex));
620 mod = SPELLMOD_RANGE;
623 if(Player* modOwner = caster->GetSpellModOwner())
624 modOwner->ApplySpellMod(GetId(), mod, radius, NULL);
626 if(!caster->IsWithinDistInMap(m_target, radius))
628 m_target->RemoveAura(GetId(), GetEffIndex());
629 return;
633 if(m_isPeriodic && (m_duration >= 0 || m_isPassive || m_permanent))
635 m_periodicTimer -= diff;
636 if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N
638 // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls)
639 m_periodicTimer += m_modifier.periodictime;
640 PeriodicTick();
645 void AreaAura::Update(uint32 diff)
647 // update for the caster of the aura
648 if(m_caster_guid == m_target->GetGUID())
650 Unit* caster = m_target;
652 if( !caster->hasUnitState(UNIT_STAT_ISOLATED) )
654 Unit* owner = caster->GetCharmerOrOwner();
655 if (!owner)
656 owner = caster;
657 std::list<Unit *> targets;
659 switch(m_areaAuraType)
661 case AREA_AURA_PARTY:
663 Group *pGroup = NULL;
665 if (owner->GetTypeId() == TYPEID_PLAYER)
666 pGroup = ((Player*)owner)->GetGroup();
668 if( pGroup)
670 uint8 subgroup = ((Player*)owner)->GetSubGroup();
671 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
673 Player* Target = itr->getSource();
674 if(Target && Target->isAlive() && Target->GetSubGroup()==subgroup && caster->IsFriendlyTo(Target))
676 if(caster->IsWithinDistInMap(Target, m_radius))
677 targets.push_back(Target);
678 Pet *pet = Target->GetPet();
679 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
680 targets.push_back(pet);
684 else
686 // add owner
687 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
688 targets.push_back(owner);
689 // add caster's pet
690 Unit* pet = caster->GetPet();
691 if( pet && caster->IsWithinDistInMap(pet, m_radius))
692 targets.push_back(pet);
694 break;
696 case AREA_AURA_RAID:
698 Group *pGroup = NULL;
700 if (owner->GetTypeId() == TYPEID_PLAYER)
701 pGroup = ((Player*)owner)->GetGroup();
703 if( pGroup)
705 for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
707 Player* Target = itr->getSource();
708 if(Target && Target->isAlive() && caster->IsFriendlyTo(Target))
710 if(caster->IsWithinDistInMap(Target, m_radius))
711 targets.push_back(Target);
712 Pet *pet = Target->GetPet();
713 if(pet && pet->isAlive() && caster->IsWithinDistInMap(pet, m_radius))
714 targets.push_back(pet);
718 else
720 // add owner
721 if( owner != caster && caster->IsWithinDistInMap(owner, m_radius) )
722 targets.push_back(owner);
723 // add caster's pet
724 Unit* pet = caster->GetPet();
725 if( pet && caster->IsWithinDistInMap(pet, m_radius))
726 targets.push_back(pet);
728 break;
730 case AREA_AURA_FRIEND:
732 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
733 Cell cell(p);
734 cell.data.Part.reserved = ALL_DISTRICT;
735 cell.SetNoCreate();
737 MaNGOS::AnyFriendlyUnitInObjectRangeCheck u_check(caster, owner, m_radius);
738 MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck> searcher(caster,targets, u_check);
739 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
740 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
741 CellLock<GridReadGuard> cell_lock(cell, p);
742 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap());
743 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap());
744 break;
746 case AREA_AURA_ENEMY:
748 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY()));
749 Cell cell(p);
750 cell.data.Part.reserved = ALL_DISTRICT;
751 cell.SetNoCreate();
753 MaNGOS::AnyAoETargetUnitInObjectRangeCheck u_check(caster, owner, m_radius); // No GetCharmer in searcher
754 MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck> searcher(caster, targets, u_check);
755 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
756 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
757 CellLock<GridReadGuard> cell_lock(cell, p);
758 cell_lock->Visit(cell_lock, world_unit_searcher, *caster->GetMap());
759 cell_lock->Visit(cell_lock, grid_unit_searcher, *caster->GetMap());
760 break;
762 case AREA_AURA_OWNER:
763 case AREA_AURA_PET:
765 if(owner != caster)
766 targets.push_back(owner);
767 break;
771 for(std::list<Unit *>::iterator tIter = targets.begin(); tIter != targets.end(); tIter++)
773 if((*tIter)->HasAura(GetId(), m_effIndex))
774 continue;
776 if(SpellEntry const *actualSpellInfo = spellmgr.SelectAuraRankForPlayerLevel(GetSpellProto(), (*tIter)->getLevel()))
778 int32 actualBasePoints = m_currentBasePoints;
779 // recalculate basepoints for lower rank (all AreaAura spell not use custom basepoints?)
780 if(actualSpellInfo != GetSpellProto())
781 actualBasePoints = actualSpellInfo->EffectBasePoints[m_effIndex];
782 AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
783 aur->SetAuraDuration(GetAuraDuration());
784 (*tIter)->AddAura(aur);
788 Aura::Update(diff);
790 else // aura at non-caster
792 Unit* caster = GetCaster();
794 Aura::Update(diff);
796 // remove aura if out-of-range from caster (after teleport for example)
797 // or caster is isolated or caster no longer has the aura
798 // or caster is (no longer) friendly
799 bool needFriendly = (m_areaAuraType == AREA_AURA_ENEMY ? false : true);
800 if( !caster || caster->hasUnitState(UNIT_STAT_ISOLATED) ||
801 !caster->IsWithinDistInMap(m_target, m_radius) ||
802 !caster->HasAura(GetId(), GetEffIndex()) ||
803 caster->IsFriendlyTo(m_target) != needFriendly
806 m_target->RemoveAura(GetId(), GetEffIndex());
808 else if( m_areaAuraType == AREA_AURA_PARTY) // check if in same sub group
810 // not check group if target == owner or target == pet
811 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
813 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
815 Group *pGroup = check ? check->GetGroup() : NULL;
816 if( pGroup )
818 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
819 if(!checkTarget || !pGroup->SameSubGroup(check, checkTarget))
820 m_target->RemoveAura(GetId(), GetEffIndex());
822 else
823 m_target->RemoveAura(GetId(), GetEffIndex());
826 else if( m_areaAuraType == AREA_AURA_RAID) // TODO: fix me!
828 // not check group if target == owner or target == pet
829 if (caster->GetCharmerOrOwnerGUID() != m_target->GetGUID() && caster->GetGUID() != m_target->GetCharmerOrOwnerGUID())
831 Player* check = caster->GetCharmerOrOwnerPlayerOrPlayerItself();
833 Group *pGroup = check ? check->GetGroup() : NULL;
834 if( pGroup )
836 Player* checkTarget = m_target->GetCharmerOrOwnerPlayerOrPlayerItself();
837 if(!checkTarget)
838 m_target->RemoveAura(GetId(), GetEffIndex());
840 else
841 m_target->RemoveAura(GetId(), GetEffIndex());
844 else if( m_areaAuraType == AREA_AURA_PET || m_areaAuraType == AREA_AURA_OWNER )
846 if( m_target->GetGUID() != caster->GetCharmerOrOwnerGUID() )
847 m_target->RemoveAura(GetId(), GetEffIndex());
852 void PersistentAreaAura::Update(uint32 diff)
854 bool remove = false;
856 // remove the aura if its caster or the dynamic object causing it was removed
857 // or if the target moves too far from the dynamic object
858 if(Unit *caster = GetCaster())
860 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
861 if (dynObj)
863 if (!m_target->IsWithinDistInMap(dynObj, dynObj->GetRadius()))
864 remove = true;
866 else
867 remove = true;
869 else
870 remove = true;
872 Aura::Update(diff);
874 if(remove)
875 m_target->RemoveAura(GetId(), GetEffIndex());
878 void Aura::ApplyModifier(bool apply, bool Real)
880 AuraType aura = m_modifier.m_auraname;
882 SetInUse(true);
883 if(aura < TOTAL_AURAS)
884 (*this.*AuraHandler [aura])(apply, Real);
885 SetInUse(false);
888 void Aura::_AddAura()
890 if (!GetId())
891 return;
892 if(!m_target)
893 return;
895 // Second aura if some spell
896 bool secondaura = false;
897 // Try find slot for aura
898 uint8 slot = NULL_AURA_SLOT;
899 // Lookup for some spell auras (and get slot from it)
900 for(uint8 i = 0; i < m_effIndex; ++i)
902 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
903 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
905 // allow use single slot only by auras from same caster
906 if(itr->second->GetCasterGUID()==GetCasterGUID())
908 slot = itr->second->GetAuraSlot();
909 secondaura = true;
910 break;
913 if (secondaura)
914 break;
916 // Lookup free slot
917 if (!secondaura && m_target->GetVisibleAurasCount() < MAX_AURAS)
919 Unit::VisibleAuraMap const *visibleAuras = m_target->GetVisibleAuras();
920 for(uint8 i = 0; i < MAX_AURAS; ++i)
922 Unit::VisibleAuraMap::const_iterator itr = visibleAuras->find(i);
923 if(itr == visibleAuras->end())
925 slot = i;
926 // update for out of range group members (on 1 slot use)
927 m_target->UpdateAuraForGroup(slot);
928 break;
933 Unit* caster = GetCaster();
935 // set infinity cooldown state for spells
936 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
938 if (m_spellProto->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)
940 Item* castItem = m_castItemGuid ? ((Player*)caster)->GetItemByGuid(m_castItemGuid) : NULL;
941 ((Player*)caster)->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true);
945 // passive auras (except totem auras) do not get placed in the slots
946 // area auras with SPELL_AURA_NONE are not shown on target
947 if((!m_isPassive || (caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem())) &&
948 (m_spellProto->Effect[GetEffIndex()] != SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || m_target != caster))
950 SetAuraSlot( slot );
951 if(slot < MAX_AURAS) // slot found send data to client
953 SetAura(false);
954 SetAuraFlags((1 << GetEffIndex()) | AFLAG_NOT_CASTER | ((GetAuraMaxDuration() > 0) ? AFLAG_DURATION : AFLAG_NONE) | (IsPositive() ? AFLAG_POSITIVE : AFLAG_NEGATIVE));
955 SetAuraLevel(caster ? caster->getLevel() : sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
956 SendAuraUpdate(false);
959 //*****************************************************
960 // Update target aura state flag (at 1 aura apply)
961 // TODO: Make it easer
962 //*****************************************************
963 if (!secondaura)
965 // Sitdown on apply aura req seated
966 if (m_spellProto->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED && !m_target->IsSitState())
967 m_target->SetStandState(UNIT_STAND_STATE_SIT);
969 // register aura diminishing on apply
970 if (getDiminishGroup() != DIMINISHING_NONE )
971 m_target->ApplyDiminishingAura(getDiminishGroup(), true);
973 // Update Seals information
974 if (IsSealSpell(m_spellProto))
975 m_target->ModifyAuraState(AURA_STATE_JUDGEMENT, true);
977 // Conflagrate aura state on Immolate and Shadowflame
978 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARLOCK &&
979 // Immolate
980 ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
981 // Shadowflame
982 (m_spellProto->SpellFamilyFlags2 & 0x00000002)))
983 m_target->ModifyAuraState(AURA_STATE_CONFLAGRATE, true);
985 // Faerie Fire (druid versions)
986 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
987 m_target->ModifyAuraState(AURA_STATE_FAERIE_FIRE, true);
989 // Victorious
990 if (m_spellProto->SpellFamilyName == SPELLFAMILY_WARRIOR && (m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
991 m_target->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, true);
993 // Swiftmend state on Regrowth & Rejuvenation
994 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && (m_spellProto->SpellFamilyFlags & UI64LIT(0x50)))
995 m_target->ModifyAuraState(AURA_STATE_SWIFTMEND, true);
997 // Deadly poison aura state
998 if(m_spellProto->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellProto->SpellFamilyFlags & UI64LIT(0x10000)))
999 m_target->ModifyAuraState(AURA_STATE_DEADLY_POISON, true);
1001 // Enrage aura state
1002 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1003 m_target->ModifyAuraState(AURA_STATE_ENRAGE, true);
1008 bool Aura::_RemoveAura()
1010 // Remove all triggered by aura spells vs unlimited duration
1011 // except same aura replace case
1012 if(m_removeMode!=AURA_REMOVE_BY_STACK)
1013 CleanupTriggeredSpells();
1015 Unit* caster = GetCaster();
1017 if(caster && IsPersistent())
1019 DynamicObject *dynObj = caster->GetDynObject(GetId(), GetEffIndex());
1020 if (dynObj)
1021 dynObj->RemoveAffected(m_target);
1024 //passive auras do not get put in slots
1025 // Note: but totem can be not accessible for aura target in time remove (to far for find in grid)
1026 //if(m_isPassive && !(caster && caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->isTotem()))
1027 // return;
1029 uint8 slot = GetAuraSlot();
1031 if(slot >= MAX_AURAS) // slot not set
1032 return false;
1034 if(m_target->GetVisibleAura(slot) == 0)
1035 return false;
1037 bool lastaura = true;
1039 // find other aura in same slot (current already removed from list)
1040 for(uint8 i = 0; i < 3; ++i)
1042 Unit::spellEffectPair spair = Unit::spellEffectPair(GetId(), i);
1043 for(Unit::AuraMap::const_iterator itr = m_target->GetAuras().lower_bound(spair); itr != m_target->GetAuras().upper_bound(spair); ++itr)
1045 if(itr->second->GetAuraSlot() == slot)
1047 lastaura = false;
1048 break;
1051 if(!lastaura)
1052 break;
1055 // only remove icon when the last aura of the spell is removed (current aura already removed from list)
1056 if (!lastaura)
1057 return false;
1059 // unregister aura diminishing (and store last time)
1060 if (getDiminishGroup() != DIMINISHING_NONE )
1061 m_target->ApplyDiminishingAura(getDiminishGroup(), false);
1063 SetAura(true);
1064 SetAuraFlags(AFLAG_NONE);
1065 SetAuraLevel(0);
1066 SendAuraUpdate(true);
1068 // update for out of range group members
1069 m_target->UpdateAuraForGroup(slot);
1071 //*****************************************************
1072 // Update target aura state flag (at last aura remove)
1073 //*****************************************************
1074 // Enrage aura state
1075 if(m_spellProto->Dispel == DISPEL_ENRAGE)
1076 m_target->ModifyAuraState(AURA_STATE_ENRAGE, false);
1078 uint32 removeState = 0;
1079 uint64 removeFamilyFlag = m_spellProto->SpellFamilyFlags;
1080 uint32 removeFamilyFlag2 = m_spellProto->SpellFamilyFlags2;
1081 switch(m_spellProto->SpellFamilyName)
1083 case SPELLFAMILY_PALADIN:
1084 if (IsSealSpell(m_spellProto))
1085 removeState = AURA_STATE_JUDGEMENT; // Update Seals information
1086 break;
1087 case SPELLFAMILY_WARLOCK:
1088 // Conflagrate aura state on Immolate and Shadowflame,
1089 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) ||
1090 (m_spellProto->SpellFamilyFlags2 & 0x00000002))
1092 removeFamilyFlag = UI64LIT(0x0000000000000004);
1093 removeFamilyFlag2 = 0x00000002;
1094 removeState = AURA_STATE_CONFLAGRATE;
1096 break;
1097 case SPELLFAMILY_DRUID:
1098 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000400))
1099 removeState = AURA_STATE_FAERIE_FIRE; // Faerie Fire (druid versions)
1100 else if(m_spellProto->SpellFamilyFlags & UI64LIT(0x50))
1102 removeFamilyFlag = 0x50;
1103 removeState = AURA_STATE_SWIFTMEND; // Swiftmend aura state
1105 break;
1106 case SPELLFAMILY_WARRIOR:
1107 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x0004000000000000))
1108 removeState = AURA_STATE_WARRIOR_VICTORY_RUSH; // Victorious
1109 break;
1110 case SPELLFAMILY_ROGUE:
1111 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x10000))
1112 removeState = AURA_STATE_DEADLY_POISON; // Deadly poison aura state
1113 break;
1114 case SPELLFAMILY_HUNTER:
1115 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
1116 removeState = AURA_STATE_FAERIE_FIRE; // Sting (hunter versions)
1119 // Remove state (but need check other auras for it)
1120 if (removeState)
1122 bool found = false;
1123 Unit::AuraMap& Auras = m_target->GetAuras();
1124 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
1126 SpellEntry const *auraSpellInfo = (*i).second->GetSpellProto();
1127 if(auraSpellInfo->SpellFamilyName == m_spellProto->SpellFamilyName &&
1128 (auraSpellInfo->SpellFamilyFlags & removeFamilyFlag || auraSpellInfo->SpellFamilyFlags2 & removeFamilyFlag2))
1130 found = true;
1131 break;
1134 // this has been last aura
1135 if(!found)
1136 m_target->ModifyAuraState(AuraState(removeState), false);
1139 // reset cooldown state for spells
1140 if(caster && caster->GetTypeId() == TYPEID_PLAYER)
1142 if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE )
1143 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
1144 ((Player*)caster)->SendCooldownEvent(GetSpellProto());
1147 return true;
1150 void Aura::SendAuraUpdate(bool remove)
1152 WorldPacket data(SMSG_AURA_UPDATE);
1153 data.append(m_target->GetPackGUID());
1154 data << uint8(GetAuraSlot());
1155 data << uint32(remove ? 0 : GetId());
1157 if(remove)
1159 m_target->SendMessageToSet(&data, true);
1160 return;
1163 uint8 auraFlags = GetAuraFlags();
1164 data << uint8(auraFlags);
1165 data << uint8(GetAuraLevel());
1166 data << uint8(m_procCharges ? m_procCharges*m_stackAmount : m_stackAmount);
1168 if(!(auraFlags & AFLAG_NOT_CASTER))
1170 data << uint8(0); // pguid
1173 if(auraFlags & AFLAG_DURATION)
1175 data << uint32(GetAuraMaxDuration());
1176 data << uint32(GetAuraDuration());
1179 m_target->SendMessageToSet(&data, true);
1182 void Aura::SetStackAmount(uint8 stackAmount)
1184 Unit *target = GetTarget();
1185 Unit *caster = GetCaster();
1186 if (!target || !caster)
1187 return;
1189 bool refresh = stackAmount >= m_stackAmount;
1190 if (stackAmount != m_stackAmount)
1192 m_stackAmount = stackAmount;
1193 int32 amount = m_stackAmount * caster->CalculateSpellDamage(m_spellProto, m_effIndex, m_currentBasePoints, target);
1194 // Reapply if amount change
1195 if (amount!=m_modifier.m_amount)
1197 ApplyModifier(false, true);
1198 m_modifier.m_amount = amount;
1199 ApplyModifier(true, true);
1203 if (refresh)
1204 // Stack increased refresh duration
1205 RefreshAura();
1206 else
1207 // Stack decreased only send update
1208 SendAuraUpdate(false);
1211 bool Aura::modStackAmount(int32 num)
1213 // Can`t mod
1214 if (!m_spellProto->StackAmount)
1215 return true;
1217 // Modify stack but limit it
1218 int32 stackAmount = m_stackAmount + num;
1219 if (stackAmount > m_spellProto->StackAmount)
1220 stackAmount = m_spellProto->StackAmount;
1221 else if (stackAmount <=0) // Last aura from stack removed
1223 m_stackAmount = 0;
1224 return true; // need remove aura
1227 // Update stack amount
1228 SetStackAmount(stackAmount);
1229 return false;
1232 void Aura::RefreshAura()
1234 m_duration = m_maxduration;
1235 SendAuraUpdate(false);
1238 bool Aura::isAffectedOnSpell(SpellEntry const *spell) const
1240 // Check family name
1241 if (spell->SpellFamilyName != m_spellProto->SpellFamilyName)
1242 return false;
1243 // Check EffectClassMask
1244 uint32 const *ptr = getAuraSpellClassMask();
1245 if (((uint64*)ptr)[0] & spell->SpellFamilyFlags)
1246 return true;
1247 if (ptr[2] & spell->SpellFamilyFlags2)
1248 return true;
1249 return false;
1252 void Aura::ReapplyAffectedPassiveAuras( Unit* target )
1254 std::set<uint32> affectedPassives;
1256 for(Unit::AuraMap::const_iterator itr = target->GetAuras().begin(); itr != target->GetAuras().end(); ++itr)
1258 // permanent passive
1259 if (itr->second->IsPassive() && itr->second->IsPermanent() &&
1260 // non deleted and not same aura (any with same spell id)
1261 !itr->second->IsDeleted() && itr->second->GetId() != GetId() &&
1262 // only applied by self and affected by aura
1263 itr->second->GetCasterGUID() == target->GetGUID() && isAffectedOnSpell(itr->second->GetSpellProto()))
1265 affectedPassives.insert(itr->second->GetId());
1269 for(std::set<uint32>::const_iterator set_itr = affectedPassives.begin(); set_itr != affectedPassives.end(); ++set_itr)
1271 target->RemoveAurasDueToSpell(*set_itr);
1272 target->CastSpell(m_target, *set_itr, true);
1276 /*********************************************************/
1277 /*** BASIC AURA FUNCTION ***/
1278 /*********************************************************/
1279 void Aura::HandleAddModifier(bool apply, bool Real)
1281 if(m_target->GetTypeId() != TYPEID_PLAYER || !Real)
1282 return;
1284 if(m_modifier.m_miscvalue >= MAX_SPELLMOD)
1285 return;
1287 if (apply)
1289 // Add custom charges for some mod aura
1290 switch (m_spellProto->Id)
1292 case 17941: // Shadow Trance
1293 case 22008: // Netherwind Focus
1294 case 31834: // Light's Grace
1295 case 34754: // Clearcasting
1296 case 34936: // Backlash
1297 case 48108: // Hot Streak
1298 case 51124: // Killing Machine
1299 case 54741: // Firestarter
1300 case 57761: // Fireball!
1301 SetAuraCharges(1);
1302 break;
1305 SpellModifier *mod = new SpellModifier;
1306 mod->op = SpellModOp(m_modifier.m_miscvalue);
1307 mod->value = m_modifier.m_amount;
1308 mod->type = SpellModType(m_modifier.m_auraname); // SpellModType value == spell aura types
1309 mod->spellId = GetId();
1311 uint32 const *ptr;
1312 switch (m_effIndex)
1314 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1315 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1316 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1317 default:
1318 return;
1321 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1322 mod->mask2= (uint64)ptr[2];
1323 mod->charges = m_procCharges;
1325 m_spellmod = mod;
1328 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
1330 // reapply talents to own passive persistent auras
1331 ReapplyAffectedPassiveAuras(m_target);
1333 // re-aplly talents and passives applied to pet (it affected by player spellmods)
1334 if(Pet* pet = m_target->GetPet())
1335 ReapplyAffectedPassiveAuras(pet);
1337 for(int i = 0; i < MAX_TOTEM; ++i)
1338 if(m_target->m_TotemSlot[i])
1339 if(Creature* totem = m_target->GetMap()->GetCreature(m_target->m_TotemSlot[i]))
1340 ReapplyAffectedPassiveAuras(totem);
1342 void Aura::HandleAddTargetTrigger(bool apply, bool /*Real*/)
1344 // Use SpellModifier structure for check
1345 // used only fields:
1346 // spellId, mask, mask2
1347 if (apply)
1349 SpellModifier *mod = new SpellModifier;
1350 mod->spellId = GetId();
1352 uint32 const *ptr;
1353 switch (m_effIndex)
1355 case 0: ptr = &m_spellProto->EffectSpellClassMaskA[0]; break;
1356 case 1: ptr = &m_spellProto->EffectSpellClassMaskB[0]; break;
1357 case 2: ptr = &m_spellProto->EffectSpellClassMaskC[0]; break;
1358 default:
1359 return;
1362 mod->mask = (uint64)ptr[0] | (uint64)ptr[1]<<32;
1363 mod->mask2= (uint64)ptr[2];
1364 m_spellmod = mod;
1366 else
1368 delete m_spellmod;
1369 m_spellmod = NULL;
1373 void Aura::TriggerSpell()
1375 Unit* caster = GetCaster();
1376 Unit* target = GetTriggerTarget();
1378 if(!caster || !target)
1379 return;
1381 // generic casting code with custom spells and target/caster customs
1382 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
1384 SpellEntry const *triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
1385 SpellEntry const *auraSpellInfo = GetSpellProto();
1386 uint32 auraId = auraSpellInfo->Id;
1388 // specific code for cases with no trigger spell provided in field
1389 if (triggeredSpellInfo == NULL)
1391 switch(auraSpellInfo->SpellFamilyName)
1393 case SPELLFAMILY_GENERIC:
1395 switch(auraId)
1397 // Firestone Passive (1-5 ranks)
1398 case 758:
1399 case 17945:
1400 case 17947:
1401 case 17949:
1402 case 27252:
1404 if (caster->GetTypeId()!=TYPEID_PLAYER)
1405 return;
1406 Item* item = ((Player*)caster)->GetWeaponForAttack(BASE_ATTACK);
1407 if (!item)
1408 return;
1409 uint32 enchant_id = 0;
1410 switch (GetId())
1412 case 758: enchant_id = 1803; break; // Rank 1
1413 case 17945: enchant_id = 1823; break; // Rank 2
1414 case 17947: enchant_id = 1824; break; // Rank 3
1415 case 17949: enchant_id = 1825; break; // Rank 4
1416 case 27252: enchant_id = 2645; break; // Rank 5
1417 default:
1418 return;
1420 // remove old enchanting before applying new
1421 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1422 item->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, m_modifier.periodictime+1000, 0);
1423 // add new enchanting
1424 ((Player*)caster)->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,true);
1425 return;
1427 // // Periodic Mana Burn
1428 // case 812: break;
1429 // // Polymorphic Ray
1430 // case 6965: break;
1431 // // Fire Nova (1-7 ranks)
1432 // case 8350:
1433 // case 8508:
1434 // case 8509:
1435 // case 11312:
1436 // case 11313:
1437 // case 25540:
1438 // case 25544:
1439 // break;
1440 // Thaumaturgy Channel
1441 case 9712: trigger_spell_id = 21029; break;
1442 // // Egan's Blaster
1443 // case 17368: break;
1444 // // Haunted
1445 // case 18347: break;
1446 // // Ranshalla Waiting
1447 // case 18953: break;
1448 // // Inferno
1449 // case 19695: break;
1450 // // Frostwolf Muzzle DND
1451 // case 21794: break;
1452 // // Alterac Ram Collar DND
1453 // case 21866: break;
1454 // // Celebras Waiting
1455 // case 21916: break;
1456 // Brood Affliction: Bronze
1457 case 23170:
1459 m_target->CastSpell(m_target, 23171, true, 0, this);
1460 return;
1462 // // Mark of Frost
1463 // case 23184: break;
1464 // Restoration
1465 case 23493:
1467 int32 heal = caster->GetMaxHealth() / 10;
1468 caster->DealHeal(caster, heal, auraSpellInfo);
1470 int32 mana = caster->GetMaxPower(POWER_MANA);
1471 if (mana)
1473 mana /= 10;
1474 caster->EnergizeBySpell(caster, 23493, mana, POWER_MANA);
1476 return;
1478 // // Stoneclaw Totem Passive TEST
1479 // case 23792: break;
1480 // // Axe Flurry
1481 // case 24018: break;
1482 // // Mark of Arlokk
1483 // case 24210: break;
1484 // // Restoration
1485 // case 24379: break;
1486 // // Happy Pet
1487 // case 24716: break;
1488 // // Dream Fog
1489 // case 24780: break;
1490 // // Cannon Prep
1491 // case 24832: break;
1492 // // Shadow Bolt Whirl
1493 // case 24834: break;
1494 // // Stink Trap
1495 // case 24918: break;
1496 // // Mark of Nature
1497 // case 25041: break;
1498 // // Agro Drones
1499 // case 25152: break;
1500 // // Consume
1501 // case 25371: break;
1502 // // Pain Spike
1503 // case 25572: break;
1504 // // Rotate 360
1505 // case 26009: break;
1506 // // Rotate -360
1507 // case 26136: break;
1508 // // Consume
1509 // case 26196: break;
1510 // // Berserk
1511 // case 26615: break;
1512 // // Defile
1513 // case 27177: break;
1514 // // Teleport: IF/UC
1515 // case 27601: break;
1516 // // Five Fat Finger Exploding Heart Technique
1517 // case 27673: break;
1518 // // Nitrous Boost
1519 // case 27746: break;
1520 // // Steam Tank Passive
1521 // case 27747: break;
1522 // Frost Blast
1523 case 27808:
1525 int32 bpDamage = target->GetMaxHealth()*26/100;
1526 caster->CastCustomSpell(target, 29879, &bpDamage, NULL, NULL, true, NULL, this);
1527 return;
1529 // // Detonate Mana
1530 // case 27819: break;
1531 // // Controller Timer
1532 // case 28095: break;
1533 // // Stalagg Chain
1534 // case 28096: break;
1535 // // Stalagg Tesla Passive
1536 // case 28097: break;
1537 // // Feugen Tesla Passive
1538 // case 28109: break;
1539 // // Feugen Chain
1540 // case 28111: break;
1541 // // Mark of Didier
1542 // case 28114: break;
1543 // // Communique Timer, camp
1544 // case 28346: break;
1545 // // Icebolt
1546 // case 28522: break;
1547 // // Silithyst
1548 // case 29519: break;
1549 // Inoculate Nestlewood Owlkin
1550 case 29528:
1551 if(target->GetTypeId() != TYPEID_UNIT)// prevent error reports in case ignored player target
1552 return;
1553 break;
1554 // // Overload
1555 // case 29768: break;
1556 // // Return Fire
1557 // case 29788: break;
1558 // // Return Fire
1559 // case 29793: break;
1560 // // Return Fire
1561 // case 29794: break;
1562 // // Guardian of Icecrown Passive
1563 // case 29897: break;
1564 // Feed Captured Animal
1565 case 29917: trigger_spell_id = 29916; break;
1566 // // Flame Wreath
1567 // case 29946: break;
1568 // // Flame Wreath
1569 // case 29947: break;
1570 // // Mind Exhaustion Passive
1571 // case 30025: break;
1572 // // Nether Beam - Serenity
1573 // case 30401: break;
1574 // Extract Gas
1575 case 30427:
1577 // move loot to player inventory and despawn target
1578 if(caster->GetTypeId() ==TYPEID_PLAYER &&
1579 target->GetTypeId() == TYPEID_UNIT &&
1580 ((Creature*)target)->GetCreatureInfo()->type == CREATURE_TYPE_GAS_CLOUD)
1582 Player* player = (Player*)caster;
1583 Creature* creature = (Creature*)target;
1584 // missing lootid has been reported on startup - just return
1585 if (!creature->GetCreatureInfo()->SkinLootId)
1586 return;
1588 player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true);
1590 creature->ForcedDespawn();
1592 return;
1594 // Quake
1595 case 30576: trigger_spell_id = 30571; break;
1596 // // Burning Maul
1597 // case 30598: break;
1598 // // Regeneration
1599 // case 30799:
1600 // case 30800:
1601 // case 30801:
1602 // break;
1603 // // Despawn Self - Smoke cloud
1604 // case 31269: break;
1605 // // Time Rift Periodic
1606 // case 31320: break;
1607 // // Corrupt Medivh
1608 // case 31326: break;
1609 // Doom
1610 case 31347:
1612 m_target->CastSpell(m_target,31350,true);
1613 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
1614 return;
1616 // Spellcloth
1617 case 31373:
1619 // Summon Elemental after create item
1620 caster->SummonCreature(17870, 0, 0, 0, caster->GetOrientation(), TEMPSUMMON_DEAD_DESPAWN, 0);
1621 return;
1623 // // Bloodmyst Tesla
1624 // case 31611: break;
1625 // // Doomfire
1626 // case 31944: break;
1627 // // Teleport Test
1628 // case 32236: break;
1629 // // Earthquake
1630 // case 32686: break;
1631 // // Possess
1632 // case 33401: break;
1633 // // Draw Shadows
1634 // case 33563: break;
1635 // // Murmur's Touch
1636 // case 33711: break;
1637 // Flame Quills
1638 case 34229:
1640 // cast 24 spells 34269-34289, 34314-34316
1641 for(uint32 spell_id = 34269; spell_id != 34290; ++spell_id)
1642 caster->CastSpell(m_target, spell_id, true);
1643 for(uint32 spell_id = 34314; spell_id != 34317; ++spell_id)
1644 caster->CastSpell(m_target, spell_id, true);
1645 return;
1647 // // Gravity Lapse
1648 // case 34480: break;
1649 // // Tornado
1650 // case 34683: break;
1651 // // Frostbite Rotate
1652 // case 34748: break;
1653 // // Arcane Flurry
1654 // case 34821: break;
1655 // // Interrupt Shutdown
1656 // case 35016: break;
1657 // // Interrupt Shutdown
1658 // case 35176: break;
1659 // // Inferno
1660 // case 35268: break;
1661 // // Salaadin's Tesla
1662 // case 35515: break;
1663 // // Ethereal Channel (Red)
1664 // case 35518: break;
1665 // // Nether Vapor
1666 // case 35879: break;
1667 // // Dark Portal Storm
1668 // case 36018: break;
1669 // // Burning Maul
1670 // case 36056: break;
1671 // // Living Grove Defender Lifespan
1672 // case 36061: break;
1673 // // Professor Dabiri Talks
1674 // case 36064: break;
1675 // // Kael Gaining Power
1676 // case 36091: break;
1677 // // They Must Burn Bomb Aura
1678 // case 36344: break;
1679 // // They Must Burn Bomb Aura (self)
1680 // case 36350: break;
1681 // // Stolen Ravenous Ravager Egg
1682 // case 36401: break;
1683 // // Activated Cannon
1684 // case 36410: break;
1685 // // Stolen Ravenous Ravager Egg
1686 // case 36418: break;
1687 // // Enchanted Weapons
1688 // case 36510: break;
1689 // // Cursed Scarab Periodic
1690 // case 36556: break;
1691 // // Cursed Scarab Despawn Periodic
1692 // case 36561: break;
1693 // // Vision Guide
1694 // case 36573: break;
1695 // // Cannon Charging (platform)
1696 // case 36785: break;
1697 // // Cannon Charging (self)
1698 // case 36860: break;
1699 // Remote Toy
1700 case 37027: trigger_spell_id = 37029; break;
1701 // // Mark of Death
1702 // case 37125: break;
1703 // // Arcane Flurry
1704 // case 37268: break;
1705 // // Spout
1706 // case 37429: break;
1707 // // Spout
1708 // case 37430: break;
1709 // // Karazhan - Chess NPC AI, Snapshot timer
1710 // case 37440: break;
1711 // // Karazhan - Chess NPC AI, action timer
1712 // case 37504: break;
1713 // // Karazhan - Chess: Is Square OCCUPIED aura (DND)
1714 // case 39400: break;
1715 // // Banish
1716 // case 37546: break;
1717 // // Shriveling Gaze
1718 // case 37589: break;
1719 // // Fake Aggro Radius (2 yd)
1720 // case 37815: break;
1721 // // Corrupt Medivh
1722 // case 37853: break;
1723 // Eye of Grillok
1724 case 38495:
1726 m_target->CastSpell(m_target, 38530, true);
1727 return;
1729 // Absorb Eye of Grillok (Zezzak's Shard)
1730 case 38554:
1732 if(m_target->GetTypeId() != TYPEID_UNIT)
1733 return;
1735 caster->CastSpell(caster, 38495, true);
1737 Creature* creatureTarget = (Creature*)m_target;
1739 creatureTarget->ForcedDespawn();
1740 return;
1742 // // Magic Sucker Device timer
1743 // case 38672: break;
1744 // // Tomb Guarding Charging
1745 // case 38751: break;
1746 // // Murmur's Touch
1747 // case 38794: break;
1748 // // Activate Nether-wraith Beacon (31742 Nether-wraith Beacon item)
1749 // case 39105: break;
1750 // // Drain World Tree Visual
1751 // case 39140: break;
1752 // // Quest - Dustin's Undead Dragon Visual aura
1753 // case 39259: break;
1754 // // Hellfire - The Exorcism, Jules releases darkness, aura
1755 // case 39306: break;
1756 // // Inferno
1757 // case 39346: break;
1758 // // Enchanted Weapons
1759 // case 39489: break;
1760 // // Shadow Bolt Whirl
1761 // case 39630: break;
1762 // // Shadow Bolt Whirl
1763 // case 39634: break;
1764 // // Shadow Inferno
1765 // case 39645: break;
1766 // Tear of Azzinoth Summon Channel - it's not really supposed to do anything,and this only prevents the console spam
1767 case 39857: trigger_spell_id = 39856; break;
1768 // // Soulgrinder Ritual Visual (Smashed)
1769 // case 39974: break;
1770 // // Simon Game Pre-game timer
1771 // case 40041: break;
1772 // // Knockdown Fel Cannon: The Aggro Check Aura
1773 // case 40113: break;
1774 // // Spirit Lance
1775 // case 40157: break;
1776 // // Demon Transform 2
1777 // case 40398: break;
1778 // // Demon Transform 1
1779 // case 40511: break;
1780 // // Ancient Flames
1781 // case 40657: break;
1782 // // Ethereal Ring Cannon: Cannon Aura
1783 // case 40734: break;
1784 // // Cage Trap
1785 // case 40760: break;
1786 // // Random Periodic
1787 // case 40867: break;
1788 // // Prismatic Shield
1789 // case 40879: break;
1790 // // Aura of Desire
1791 // case 41350: break;
1792 // // Dementia
1793 // case 41404: break;
1794 // // Chaos Form
1795 // case 41629: break;
1796 // // Alert Drums
1797 // case 42177: break;
1798 // // Spout
1799 // case 42581: break;
1800 // // Spout
1801 // case 42582: break;
1802 // // Return to the Spirit Realm
1803 // case 44035: break;
1804 // // Curse of Boundless Agony
1805 // case 45050: break;
1806 // // Earthquake
1807 // case 46240: break;
1808 // Personalized Weather
1809 case 46736: trigger_spell_id = 46737; break;
1810 // // Stay Submerged
1811 // case 46981: break;
1812 // // Dragonblight Ram
1813 // case 47015: break;
1814 // // Party G.R.E.N.A.D.E.
1815 // case 51510: break;
1816 default:
1817 break;
1819 break;
1821 case SPELLFAMILY_MAGE:
1823 switch(auraId)
1825 // Invisibility
1826 case 66:
1827 // Here need periodic triger reducing threat spell (or do it manually)
1828 return;
1829 default:
1830 break;
1832 break;
1834 // case SPELLFAMILY_WARRIOR:
1835 // {
1836 // switch(auraId)
1837 // {
1838 // // Wild Magic
1839 // case 23410: break;
1840 // // Corrupted Totems
1841 // case 23425: break;
1842 // default:
1843 // break;
1844 // }
1845 // break;
1846 // }
1847 // case SPELLFAMILY_PRIEST:
1848 // {
1849 // switch(auraId)
1850 // {
1851 // // Blue Beam
1852 // case 32930: break;
1853 // // Fury of the Dreghood Elders
1854 // case 35460: break;
1855 // default:
1856 // break;
1857 // }
1858 // break;
1859 // }
1860 case SPELLFAMILY_HUNTER:
1862 switch (auraId)
1864 // Sniper training
1865 case 53302:
1866 case 53303:
1867 case 53304:
1868 if (target->GetTypeId() != TYPEID_PLAYER)
1869 return;
1871 // Reset reapply counter at move
1872 if (((Player*)target)->isMoving())
1874 m_modifier.m_amount = 6;
1875 return;
1878 // We are standing at the moment
1879 if (m_modifier.m_amount > 0)
1881 --m_modifier.m_amount;
1882 return;
1885 // select rank of buff
1886 switch(auraId)
1888 case 53302: trigger_spell_id = 64418; break;
1889 case 53303: trigger_spell_id = 64419; break;
1890 case 53304: trigger_spell_id = 64420; break;
1893 // If aura is active - no need to continue
1894 if (target->HasAura(trigger_spell_id))
1895 return;
1897 break;
1898 default:
1899 break;
1901 break;
1903 case SPELLFAMILY_DRUID:
1905 switch(auraId)
1907 // Cat Form
1908 // trigger_spell_id not set and unknown effect triggered in this case, ignoring for while
1909 case 768:
1910 return;
1911 // Frenzied Regeneration
1912 case 22842:
1913 case 22895:
1914 case 22896:
1915 case 26999:
1917 int32 LifePerRage = GetModifier()->m_amount;
1919 int32 lRage = m_target->GetPower(POWER_RAGE);
1920 if(lRage > 100) // rage stored as rage*10
1921 lRage = 100;
1922 m_target->ModifyPower(POWER_RAGE, -lRage);
1923 int32 FRTriggerBasePoints = int32(lRage*LifePerRage/10);
1924 m_target->CastCustomSpell(m_target, 22845, &FRTriggerBasePoints, NULL, NULL, true, NULL, this);
1925 return;
1927 default:
1928 break;
1930 break;
1933 // case SPELLFAMILY_HUNTER:
1934 // {
1935 // switch(auraId)
1936 // {
1937 // //Frost Trap Aura
1938 // case 13810:
1939 // return;
1940 // //Rizzle's Frost Trap
1941 // case 39900:
1942 // return;
1943 // // Tame spells
1944 // case 19597: // Tame Ice Claw Bear
1945 // case 19676: // Tame Snow Leopard
1946 // case 19677: // Tame Large Crag Boar
1947 // case 19678: // Tame Adult Plainstrider
1948 // case 19679: // Tame Prairie Stalker
1949 // case 19680: // Tame Swoop
1950 // case 19681: // Tame Dire Mottled Boar
1951 // case 19682: // Tame Surf Crawler
1952 // case 19683: // Tame Armored Scorpid
1953 // case 19684: // Tame Webwood Lurker
1954 // case 19685: // Tame Nightsaber Stalker
1955 // case 19686: // Tame Strigid Screecher
1956 // case 30100: // Tame Crazed Dragonhawk
1957 // case 30103: // Tame Elder Springpaw
1958 // case 30104: // Tame Mistbat
1959 // case 30647: // Tame Barbed Crawler
1960 // case 30648: // Tame Greater Timberstrider
1961 // case 30652: // Tame Nightstalker
1962 // return;
1963 // default:
1964 // break;
1965 // }
1966 // break;
1967 // }
1968 case SPELLFAMILY_SHAMAN:
1970 switch(auraId)
1972 // Lightning Shield (The Earthshatterer set trigger after cast Lighting Shield)
1973 case 28820:
1975 // Need remove self if Lightning Shield not active
1976 Unit::AuraMap const& auras = target->GetAuras();
1977 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1979 SpellEntry const* spell = itr->second->GetSpellProto();
1980 if( spell->SpellFamilyName == SPELLFAMILY_SHAMAN &&
1981 (spell->SpellFamilyFlags & UI64LIT(0x0000000000000400)))
1982 return;
1984 target->RemoveAurasDueToSpell(28820);
1985 return;
1987 // Totemic Mastery (Skyshatter Regalia (Shaman Tier 6) - bonus)
1988 case 38443:
1990 bool all = true;
1991 for(int i = 0; i < MAX_TOTEM; ++i)
1993 if(!caster->m_TotemSlot[i])
1995 all = false;
1996 break;
2000 if(all)
2001 caster->CastSpell(caster, 38437, true);
2002 else
2003 caster->RemoveAurasDueToSpell(38437);
2004 return;
2006 default:
2007 break;
2009 break;
2011 default:
2012 break;
2015 // Reget trigger spell proto
2016 triggeredSpellInfo = sSpellStore.LookupEntry(trigger_spell_id);
2018 else
2020 // Spell exist but require custom code
2021 switch(auraId)
2023 // Curse of Idiocy
2024 case 1010:
2026 // TODO: spell casted by result in correct way mostly
2027 // BUT:
2028 // 1) target show casting at each triggered cast: target don't must show casting animation for any triggered spell
2029 // but must show affect apply like item casting
2030 // 2) maybe aura must be replace by new with accumulative stat mods instead stacking
2032 // prevent cast by triggered auras
2033 if(m_caster_guid == m_target->GetGUID())
2034 return;
2036 // stop triggering after each affected stats lost > 90
2037 int32 intelectLoss = 0;
2038 int32 spiritLoss = 0;
2040 Unit::AuraList const& mModStat = m_target->GetAurasByType(SPELL_AURA_MOD_STAT);
2041 for(Unit::AuraList::const_iterator i = mModStat.begin(); i != mModStat.end(); ++i)
2043 if ((*i)->GetId() == 1010)
2045 switch((*i)->GetModifier()->m_miscvalue)
2047 case STAT_INTELLECT: intelectLoss += (*i)->GetModifier()->m_amount; break;
2048 case STAT_SPIRIT: spiritLoss += (*i)->GetModifier()->m_amount; break;
2049 default: break;
2054 if(intelectLoss <= -90 && spiritLoss <= -90)
2055 return;
2057 caster = target;
2058 break;
2060 // Mana Tide
2061 case 16191:
2063 caster->CastCustomSpell(target, trigger_spell_id, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
2064 return;
2066 // Ground Slam
2067 case 33525:
2068 target->CastSpell(target, trigger_spell_id, true);
2069 return;
2073 // All ok cast by default case
2074 if(triggeredSpellInfo)
2075 caster->CastSpell(target, triggeredSpellInfo, true, 0, this);
2076 else if(target->GetTypeId()!=TYPEID_UNIT || !Script->EffectDummyCreature(caster, GetId(), GetEffIndex(), (Creature*)target))
2077 sLog.outError("Aura::TriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",GetId(),GetEffIndex());
2080 void Aura::TriggerSpellWithValue()
2082 Unit* caster = GetCaster();
2083 Unit* target = GetTriggerTarget();
2085 if(!caster || !target)
2086 return;
2088 // generic casting code with custom spells and target/caster customs
2089 uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex];
2090 int32 basepoints0 = this->GetModifier()->m_amount;
2092 caster->CastCustomSpell(target, trigger_spell_id, &basepoints0, NULL, NULL, true, NULL, this);
2095 /*********************************************************/
2096 /*** AURA EFFECTS ***/
2097 /*********************************************************/
2099 void Aura::HandleAuraDummy(bool apply, bool Real)
2101 // spells required only Real aura add/remove
2102 if(!Real)
2103 return;
2105 Unit* caster = GetCaster();
2107 // AT APPLY
2108 if(apply)
2110 switch(GetId())
2112 case 1515: // Tame beast
2113 // FIX_ME: this is 2.0.12 threat effect replaced in 2.1.x by dummy aura, must be checked for correctness
2114 if( caster && m_target->CanHaveThreatList())
2115 m_target->AddThreat(caster, 10.0f);
2116 return;
2117 case 13139: // net-o-matic
2118 // root to self part of (root_target->charge->root_self sequence
2119 if(caster)
2120 caster->CastSpell(caster, 13138, true, NULL, this);
2121 return;
2122 case 39850: // Rocket Blast
2123 if(roll_chance_i(20)) // backfire stun
2124 m_target->CastSpell(m_target, 51581, true, NULL, this);
2125 return;
2126 case 43873: // Headless Horseman Laugh
2127 m_target->PlayDistanceSound(11965);
2128 return;
2129 case 46354: // Blood Elf Illusion
2130 if(caster)
2132 switch(caster->getGender())
2134 case GENDER_FEMALE:
2135 caster->CastSpell(m_target, 46356, true, NULL, this);
2136 break;
2137 case GENDER_MALE:
2138 caster->CastSpell(m_target, 46355, true, NULL, this);
2139 break;
2140 default:
2141 break;
2144 return;
2145 case 46699: // Requires No Ammo
2146 if(m_target->GetTypeId() == TYPEID_PLAYER)
2147 ((Player*)m_target)->RemoveAmmo(); // not use ammo and not allow use
2148 return;
2151 // Earth Shield
2152 if ( caster && GetSpellProto()->SpellFamilyName == SPELLFAMILY_SHAMAN && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x40000000000)))
2154 // prevent double apply bonuses
2155 if(m_target->GetTypeId() != TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2156 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2157 return;
2160 // AT REMOVE
2161 else
2163 if( m_target->GetTypeId() == TYPEID_PLAYER &&
2164 ( GetSpellProto()->Effect[0]==72 || GetSpellProto()->Effect[0]==6 &&
2165 ( GetSpellProto()->EffectApplyAuraName[0]==1 || GetSpellProto()->EffectApplyAuraName[0]==128 ) ) )
2167 // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425
2168 ((Player*)m_target)->SetFarSightGUID(0);
2169 WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0);
2170 ((Player*)m_target)->GetSession()->SendPacket(&data);
2171 return;
2174 if( (IsQuestTameSpell(GetId())) && caster && caster->isAlive() && m_target->isAlive())
2176 uint32 finalSpelId = 0;
2177 switch(GetId())
2179 case 19548: finalSpelId = 19597; break;
2180 case 19674: finalSpelId = 19677; break;
2181 case 19687: finalSpelId = 19676; break;
2182 case 19688: finalSpelId = 19678; break;
2183 case 19689: finalSpelId = 19679; break;
2184 case 19692: finalSpelId = 19680; break;
2185 case 19693: finalSpelId = 19684; break;
2186 case 19694: finalSpelId = 19681; break;
2187 case 19696: finalSpelId = 19682; break;
2188 case 19697: finalSpelId = 19683; break;
2189 case 19699: finalSpelId = 19685; break;
2190 case 19700: finalSpelId = 19686; break;
2191 case 30646: finalSpelId = 30647; break;
2192 case 30653: finalSpelId = 30648; break;
2193 case 30654: finalSpelId = 30652; break;
2194 case 30099: finalSpelId = 30100; break;
2195 case 30102: finalSpelId = 30103; break;
2196 case 30105: finalSpelId = 30104; break;
2199 if(finalSpelId)
2200 caster->CastSpell(m_target, finalSpelId, true, NULL, this);
2201 return;
2204 switch(GetId())
2206 case 2584: // Waiting to Resurrect
2208 // Waiting to resurrect spell cancel, we must remove player from resurrect queue
2209 if(m_target->GetTypeId() == TYPEID_PLAYER)
2210 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
2211 bg->RemovePlayerFromResurrectQueue(m_target->GetGUID());
2212 return;
2214 case 36730: // Flame Strike
2216 m_target->CastSpell(m_target, 36731, true, NULL, this);
2217 return;
2219 case 44191: // Flame Strike
2221 if (m_target->GetMap()->IsDungeon())
2223 uint32 spellId = m_target->GetMap()->IsHeroic() ? 46163 : 44190;
2225 m_target->CastSpell(m_target, spellId, true, NULL, this);
2227 return;
2229 case 45934: // Dark Fiend
2231 // Kill target if dispelled
2232 if (m_removeMode==AURA_REMOVE_BY_DISPEL)
2233 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
2234 return;
2236 case 46308: // Burning Winds
2238 // casted only at creatures at spawn
2239 m_target->CastSpell(m_target, 47287, true, NULL, this);
2240 return;
2244 if (caster && m_removeMode == AURA_REMOVE_BY_DEATH)
2246 // Stop caster Arcane Missle chanelling on death
2247 if (m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE &&
2248 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000800)))
2250 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2251 return;
2253 // Stop caster Penance chanelling on death
2254 if (m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST &&
2255 (m_spellProto->SpellFamilyFlags2 & UI64LIT(0x00000080)))
2257 caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
2258 return;
2264 // AT APPLY & REMOVE
2266 switch(m_spellProto->SpellFamilyName)
2268 case SPELLFAMILY_GENERIC:
2270 switch(GetId())
2272 // Recently Bandaged
2273 case 11196:
2274 m_target->ApplySpellImmune(GetId(), IMMUNITY_MECHANIC, GetMiscValue(), apply);
2275 return;
2276 // Unstable Power
2277 case 24658:
2279 uint32 spellId = 24659;
2280 if (apply && caster)
2282 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2283 if (!spell)
2284 return;
2286 for (int i=0; i < spell->StackAmount; ++i)
2287 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2288 return;
2290 m_target->RemoveAurasDueToSpell(spellId);
2291 return;
2293 // Restless Strength
2294 case 24661:
2296 uint32 spellId = 24662;
2297 if (apply && caster)
2299 const SpellEntry *spell = sSpellStore.LookupEntry(spellId);
2300 if (!spell)
2301 return;
2302 for (int i=0; i < spell->StackAmount; ++i)
2303 caster->CastSpell(m_target, spell->Id, true, NULL, NULL, GetCasterGUID());
2304 return;
2306 m_target->RemoveAurasDueToSpell(spellId);
2307 return;
2309 //Summon Fire Elemental
2310 case 40133:
2312 if (!caster)
2313 return;
2315 Unit *owner = caster->GetOwner();
2316 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2318 if(apply)
2319 owner->CastSpell(owner, 8985, true);
2320 else
2321 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2323 return;
2325 //Summon Earth Elemental
2326 case 40132 :
2328 if (!caster)
2329 return;
2331 Unit *owner = caster->GetOwner();
2332 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
2334 if(apply)
2335 owner->CastSpell(owner, 19704, true);
2336 else
2337 ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
2339 return;
2341 //Dragonmaw Illusion
2342 case 40214 :
2344 if(apply)
2346 m_target->CastSpell(m_target, 40216, true);
2347 m_target->CastSpell(m_target, 42016, true);
2349 else
2351 m_target->RemoveAurasDueToSpell(40216);
2352 m_target->RemoveAurasDueToSpell(42016);
2354 return;
2356 // LK Intro VO (1)
2357 case 58204:
2358 if(m_target->GetTypeId() == TYPEID_PLAYER)
2360 // Play part 1
2361 if(apply)
2362 m_target->PlayDirectSound(14970, (Player *)m_target);
2363 // continue in 58205
2364 else
2365 m_target->CastSpell(m_target, 58205, true);
2367 return;
2368 // LK Intro VO (2)
2369 case 58205:
2370 if(m_target->GetTypeId() == TYPEID_PLAYER)
2372 // Play part 2
2373 if(apply)
2374 m_target->PlayDirectSound(14971, (Player *)m_target);
2375 // Play part 3
2376 else
2377 m_target->PlayDirectSound(14972, (Player *)m_target);
2379 return;
2381 break;
2383 case SPELLFAMILY_MAGE:
2385 break;
2387 case SPELLFAMILY_PRIEST:
2389 // Pain and Suffering
2390 if( m_spellProto->SpellIconID == 2874 && m_target->GetTypeId()==TYPEID_PLAYER )
2392 if(apply)
2394 // Reduce backfire damage (dot damage) from Shadow Word: Death
2395 SpellModifier *mod = new SpellModifier;
2396 mod->op = SPELLMOD_DOT;
2397 mod->value = m_modifier.m_amount;
2398 mod->type = SPELLMOD_PCT;
2399 mod->spellId = GetId();
2400 mod->mask = UI64LIT(0x0000200000000000);
2401 mod->mask2= UI64LIT(0x0);
2402 m_spellmod = mod;
2404 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2405 return;
2407 break;
2409 case SPELLFAMILY_DRUID:
2411 switch(GetId())
2413 case 34246: // Idol of the Emerald Queen
2414 case 60779: // Idol of Lush Moss
2416 if (m_target->GetTypeId() != TYPEID_PLAYER)
2417 return;
2419 if(apply)
2421 SpellModifier *mod = new SpellModifier;
2422 mod->op = SPELLMOD_DOT;
2423 mod->value = m_modifier.m_amount/7;
2424 mod->type = SPELLMOD_FLAT;
2425 mod->spellId = GetId();
2426 mod->mask = UI64LIT(0x001000000000);
2427 mod->mask2= UI64LIT(0x0);
2429 m_spellmod = mod;
2432 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2433 return;
2435 case 52610: // Savage Roar
2437 if(apply)
2439 if(m_target->m_form != FORM_CAT)
2440 return;
2442 m_target->CastSpell(m_target, 62071, true);
2444 else
2445 m_target-> RemoveAurasDueToSpell(62071);
2446 return;
2448 case 61336: // Survival Instincts
2450 if(apply)
2452 if (!m_target->IsInFeralForm())
2453 return;
2455 int32 bp0 = int32(m_target->GetMaxHealth() * m_modifier.m_amount / 100);
2456 m_target->CastCustomSpell(m_target, 50322, &bp0, NULL, NULL, true);
2458 else
2459 m_target-> RemoveAurasDueToSpell(50322);
2460 return;
2464 // Lifebloom
2465 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000))
2467 if ( apply )
2469 if ( caster )
2470 // prevent double apply bonuses
2471 if(m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
2472 m_modifier.m_amount = caster->SpellHealingBonus(m_target, GetSpellProto(), m_modifier.m_amount, SPELL_DIRECT_DAMAGE);
2474 else
2476 // Final heal only on dispelled or duration end
2477 if ( !(GetAuraDuration() <= 0 || m_removeMode == AURA_REMOVE_BY_DISPEL) )
2478 return;
2480 // have a look if there is still some other Lifebloom dummy aura
2481 Unit::AuraList auras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2482 for(Unit::AuraList::iterator itr = auras.begin(); itr!=auras.end(); ++itr)
2483 if((*itr)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2484 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x1000000000)))
2485 return;
2487 // final heal
2488 if(m_target->IsInWorld() && m_stackAmount > 0)
2490 int32 amount = m_modifier.m_amount / m_stackAmount;
2491 m_target->CastCustomSpell(m_target, 33778, &amount, NULL, NULL, true, NULL, this, GetCasterGUID());
2493 if (caster)
2495 int32 returnmana = (GetSpellProto()->ManaCostPercentage * caster->GetCreateMana() / 100) * m_stackAmount / 2;
2496 caster->CastCustomSpell(caster, 64372, &returnmana, NULL, NULL, true, NULL, this, GetCasterGUID());
2500 return;
2503 // Predatory Strikes
2504 if(m_target->GetTypeId()==TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563)
2506 ((Player*)m_target)->UpdateAttackPowerAndDamage();
2507 return;
2510 // Improved Moonkin Form
2511 if(GetSpellProto()->SpellIconID == 2855)
2513 uint32 spell_id;
2514 switch(GetId())
2516 case 48384: spell_id = 50170; break; //Rank 1
2517 case 48395: spell_id = 50171; break; //Rank 2
2518 case 48396: spell_id = 50172; break; //Rank 3
2519 default:
2520 sLog.outError("HandleAuraDummy: Not handled rank of IMF (Spell: %u)",GetId());
2521 return;
2524 if(apply)
2526 if(m_target->m_form != FORM_MOONKIN)
2527 return;
2529 m_target->CastSpell(m_target, spell_id, true);
2531 else
2532 m_target-> RemoveAurasDueToSpell(spell_id);
2533 return;
2535 break;
2537 case SPELLFAMILY_HUNTER:
2538 break;
2539 case SPELLFAMILY_SHAMAN:
2541 // Improved Weapon Totems
2542 if( GetSpellProto()->SpellIconID == 57 && m_target->GetTypeId()==TYPEID_PLAYER )
2544 if(apply)
2546 SpellModifier *mod = new SpellModifier;
2547 mod->op = SPELLMOD_EFFECT1;
2548 mod->value = m_modifier.m_amount;
2549 mod->type = SPELLMOD_PCT;
2550 mod->spellId = GetId();
2551 switch (m_effIndex)
2553 case 0:
2554 // Windfury Totem
2555 mod->mask = UI64LIT(0x00200000000);
2556 mod->mask2= UI64LIT(0x0);
2557 break;
2558 case 1:
2559 // Flametongue Totem
2560 mod->mask = UI64LIT(0x00400000000);
2561 mod->mask2= UI64LIT(0x0);
2562 break;
2565 m_spellmod = mod;
2568 ((Player*)m_target)->AddSpellMod(m_spellmod, apply);
2569 return;
2571 break;
2575 // pet auras
2576 if(PetAura const* petSpell = spellmgr.GetPetAura(GetId(), m_effIndex))
2578 if(apply)
2579 m_target->AddPetAura(petSpell);
2580 else
2581 m_target->RemovePetAura(petSpell);
2582 return;
2585 if(GetEffIndex()==0 && m_target->GetTypeId()==TYPEID_PLAYER)
2587 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
2588 if(saBounds.first != saBounds.second)
2590 uint32 zone, area;
2591 m_target->GetZoneAndAreaId(zone, area);
2593 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2595 // some auras remove at aura remove
2596 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
2597 m_target->RemoveAurasDueToSpell(itr->second->spellId);
2598 // some auras applied at aura apply
2599 else if(itr->second->autocast)
2601 if( !m_target->HasAura(itr->second->spellId, 0) )
2602 m_target->CastSpell(m_target, itr->second->spellId, true);
2609 void Aura::HandleAuraMounted(bool apply, bool Real)
2611 // only at real add/remove aura
2612 if(!Real)
2613 return;
2615 if(apply)
2617 CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
2618 if(!ci)
2620 sLog.outErrorDb("AuraMounted: `creature_template`='%u' not found in database (only need it modelid)", m_modifier.m_miscvalue);
2621 return;
2624 uint32 team = 0;
2625 if (m_target->GetTypeId()==TYPEID_PLAYER)
2626 team = ((Player*)m_target)->GetTeam();
2628 uint32 display_id = objmgr.ChooseDisplayId(team,ci);
2629 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
2630 if (minfo)
2631 display_id = minfo->modelid;
2633 m_target->Mount(display_id);
2635 else
2637 m_target->Unmount();
2641 void Aura::HandleAuraWaterWalk(bool apply, bool Real)
2643 // only at real add/remove aura
2644 if(!Real)
2645 return;
2647 WorldPacket data;
2648 if(apply)
2649 data.Initialize(SMSG_MOVE_WATER_WALK, 8+4);
2650 else
2651 data.Initialize(SMSG_MOVE_LAND_WALK, 8+4);
2652 data.append(m_target->GetPackGUID());
2653 data << uint32(0);
2654 m_target->SendMessageToSet(&data, true);
2657 void Aura::HandleAuraFeatherFall(bool apply, bool Real)
2659 // only at real add/remove aura
2660 if(!Real)
2661 return;
2663 WorldPacket data;
2664 if(apply)
2665 data.Initialize(SMSG_MOVE_FEATHER_FALL, 8+4);
2666 else
2667 data.Initialize(SMSG_MOVE_NORMAL_FALL, 8+4);
2668 data.append(m_target->GetPackGUID());
2669 data << uint32(0);
2670 m_target->SendMessageToSet(&data, true);
2672 // start fall from current height
2673 if(!apply && m_target->GetTypeId() == TYPEID_PLAYER)
2674 ((Player*)m_target)->SetFallInformation(0, m_target->GetPositionZ());
2677 void Aura::HandleAuraHover(bool apply, bool Real)
2679 // only at real add/remove aura
2680 if(!Real)
2681 return;
2683 WorldPacket data;
2684 if(apply)
2685 data.Initialize(SMSG_MOVE_SET_HOVER, 8+4);
2686 else
2687 data.Initialize(SMSG_MOVE_UNSET_HOVER, 8+4);
2688 data.append(m_target->GetPackGUID());
2689 data << uint32(0);
2690 m_target->SendMessageToSet(&data, true);
2693 void Aura::HandleWaterBreathing(bool /*apply*/, bool /*Real*/)
2695 // update timers in client
2696 if(m_target->GetTypeId()==TYPEID_PLAYER)
2697 ((Player*)m_target)->UpdateMirrorTimers();
2700 void Aura::HandleAuraModShapeshift(bool apply, bool Real)
2702 if(!Real)
2703 return;
2705 uint32 modelid = 0;
2706 Powers PowerType = POWER_MANA;
2707 ShapeshiftForm form = ShapeshiftForm(m_modifier.m_miscvalue);
2708 switch(form)
2710 case FORM_CAT:
2711 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2712 modelid = 892;
2713 else
2714 modelid = 8571;
2715 PowerType = POWER_ENERGY;
2716 break;
2717 case FORM_TRAVEL:
2718 modelid = 632;
2719 break;
2720 case FORM_AQUA:
2721 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2722 modelid = 2428;
2723 else
2724 modelid = 2428;
2725 break;
2726 case FORM_BEAR:
2727 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2728 modelid = 2281;
2729 else
2730 modelid = 2289;
2731 PowerType = POWER_RAGE;
2732 break;
2733 case FORM_GHOUL:
2734 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2735 modelid = 10045;
2736 break;
2737 case FORM_DIREBEAR:
2738 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2739 modelid = 2281;
2740 else
2741 modelid = 2289;
2742 PowerType = POWER_RAGE;
2743 break;
2744 case FORM_CREATUREBEAR:
2745 modelid = 902;
2746 break;
2747 case FORM_GHOSTWOLF:
2748 modelid = 4613;
2749 break;
2750 case FORM_FLIGHT:
2751 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2752 modelid = 20857;
2753 else
2754 modelid = 20872;
2755 break;
2756 case FORM_MOONKIN:
2757 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2758 modelid = 15374;
2759 else
2760 modelid = 15375;
2761 break;
2762 case FORM_FLIGHT_EPIC:
2763 if(Player::TeamForRace(m_target->getRace()) == ALLIANCE)
2764 modelid = 21243;
2765 else
2766 modelid = 21244;
2767 break;
2768 case FORM_METAMORPHOSIS:
2769 modelid = 25277;
2770 break;
2771 case FORM_AMBIENT:
2772 case FORM_SHADOW:
2773 case FORM_STEALTH:
2774 break;
2775 case FORM_TREE:
2776 modelid = 864;
2777 break;
2778 case FORM_BATTLESTANCE:
2779 case FORM_BERSERKERSTANCE:
2780 case FORM_DEFENSIVESTANCE:
2781 PowerType = POWER_RAGE;
2782 break;
2783 case FORM_SPIRITOFREDEMPTION:
2784 modelid = 16031;
2785 break;
2786 default:
2787 sLog.outError("Auras: Unknown Shapeshift Type: %u", m_modifier.m_miscvalue);
2790 // remove polymorph before changing display id to keep new display id
2791 switch ( form )
2793 case FORM_CAT:
2794 case FORM_TREE:
2795 case FORM_TRAVEL:
2796 case FORM_AQUA:
2797 case FORM_BEAR:
2798 case FORM_DIREBEAR:
2799 case FORM_FLIGHT_EPIC:
2800 case FORM_FLIGHT:
2801 case FORM_MOONKIN:
2803 // remove movement affects
2804 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2805 Unit::AuraList const& slowingAuras = m_target->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
2806 for (Unit::AuraList::const_iterator iter = slowingAuras.begin(); iter != slowingAuras.end();)
2808 SpellEntry const* aurSpellInfo = (*iter)->GetSpellProto();
2810 uint32 aurMechMask = GetAllSpellMechanicMask(aurSpellInfo);
2812 // If spell that caused this aura has Croud Control or Daze effect
2813 if((aurMechMask & MECHANIC_NOT_REMOVED_BY_SHAPESHIFT) ||
2814 // some Daze spells have these parameters instead of MECHANIC_DAZE (skip snare spells)
2815 aurSpellInfo->SpellIconID == 15 && aurSpellInfo->Dispel == 0 && (aurMechMask & (1 << MECHANIC_SNARE))==0)
2817 ++iter;
2818 continue;
2821 // All OK, remove aura now
2822 m_target->RemoveAurasDueToSpellByCancel(aurSpellInfo->Id);
2823 iter = slowingAuras.begin();
2826 // and polymorphic affects
2827 if(m_target->IsPolymorphed())
2828 m_target->RemoveAurasDueToSpell(m_target->getTransForm());
2830 break;
2832 default:
2833 break;
2836 if(apply)
2838 // remove other shapeshift before applying a new one
2839 if(m_target->m_ShapeShiftFormSpellId)
2840 m_target->RemoveAurasDueToSpell(m_target->m_ShapeShiftFormSpellId, this);
2842 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, form);
2844 if(modelid > 0)
2845 m_target->SetDisplayId(modelid);
2847 if(PowerType != POWER_MANA)
2849 // reset power to default values only at power change
2850 if(m_target->getPowerType() != PowerType)
2851 m_target->setPowerType(PowerType);
2853 switch(form)
2855 case FORM_CAT:
2856 case FORM_BEAR:
2857 case FORM_DIREBEAR:
2859 // get furor proc chance
2860 uint32 FurorChance = 0;
2861 Unit::AuraList const& mDummy = m_target->GetAurasByType(SPELL_AURA_DUMMY);
2862 for(Unit::AuraList::const_iterator i = mDummy.begin(); i != mDummy.end(); ++i)
2864 if ((*i)->GetSpellProto()->SpellIconID == 238)
2866 FurorChance = (*i)->GetModifier()->m_amount;
2867 break;
2871 if (m_modifier.m_miscvalue == FORM_CAT)
2873 m_target->SetPower(POWER_ENERGY, 0);
2874 if(urand(1,100) <= FurorChance)
2875 m_target->CastSpell(m_target, 17099, true, NULL, this);
2877 else
2879 m_target->SetPower(POWER_RAGE, 0);
2880 if(urand(1,100) <= FurorChance)
2881 m_target->CastSpell(m_target, 17057, true, NULL, this);
2883 break;
2885 case FORM_BATTLESTANCE:
2886 case FORM_DEFENSIVESTANCE:
2887 case FORM_BERSERKERSTANCE:
2889 uint32 Rage_val = 0;
2890 // Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
2891 if(m_target->GetTypeId() == TYPEID_PLAYER)
2893 PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap();
2894 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2896 if(itr->second->state == PLAYERSPELL_REMOVED) continue;
2897 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2898 if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139)
2899 Rage_val += m_target->CalculateSpellDamage(spellInfo, 0, spellInfo->EffectBasePoints[0], m_target) * 10;
2903 if (m_target->GetPower(POWER_RAGE) > Rage_val)
2904 m_target->SetPower(POWER_RAGE, Rage_val);
2905 break;
2907 default:
2908 break;
2912 m_target->m_ShapeShiftFormSpellId = GetId();
2913 m_target->m_form = form;
2915 else
2917 if(modelid > 0)
2918 m_target->SetDisplayId(m_target->GetNativeDisplayId());
2919 m_target->SetByteValue(UNIT_FIELD_BYTES_2, 3, FORM_NONE);
2920 if(m_target->getClass() == CLASS_DRUID)
2921 m_target->setPowerType(POWER_MANA);
2922 m_target->m_ShapeShiftFormSpellId = 0;
2923 m_target->m_form = FORM_NONE;
2925 switch(form)
2927 // Nordrassil Harness - bonus
2928 case FORM_BEAR:
2929 case FORM_DIREBEAR:
2930 case FORM_CAT:
2931 if(Aura* dummy = m_target->GetDummyAura(37315) )
2932 m_target->CastSpell(m_target, 37316, true, NULL, dummy);
2933 break;
2934 // Nordrassil Regalia - bonus
2935 case FORM_MOONKIN:
2936 if(Aura* dummy = m_target->GetDummyAura(37324) )
2937 m_target->CastSpell(m_target, 37325, true, NULL, dummy);
2938 break;
2939 default:
2940 break;
2944 // adding/removing linked auras
2945 // add/remove the shapeshift aura's boosts
2946 HandleShapeshiftBoosts(apply);
2948 if(m_target->GetTypeId() == TYPEID_PLAYER)
2949 ((Player*)m_target)->InitDataForForm();
2952 void Aura::HandleAuraTransform(bool apply, bool Real)
2954 if (apply)
2956 // special case (spell specific functionality)
2957 if (m_modifier.m_miscvalue == 0)
2959 // player applied only
2960 if (m_target->GetTypeId() != TYPEID_PLAYER)
2961 return;
2963 switch (GetId())
2965 // Orb of Deception
2966 case 16739:
2968 uint32 orb_model = m_target->GetNativeDisplayId();
2969 switch(orb_model)
2971 // Troll Female
2972 case 1479: m_target->SetDisplayId(10134); break;
2973 // Troll Male
2974 case 1478: m_target->SetDisplayId(10135); break;
2975 // Tauren Male
2976 case 59: m_target->SetDisplayId(10136); break;
2977 // Human Male
2978 case 49: m_target->SetDisplayId(10137); break;
2979 // Human Female
2980 case 50: m_target->SetDisplayId(10138); break;
2981 // Orc Male
2982 case 51: m_target->SetDisplayId(10139); break;
2983 // Orc Female
2984 case 52: m_target->SetDisplayId(10140); break;
2985 // Dwarf Male
2986 case 53: m_target->SetDisplayId(10141); break;
2987 // Dwarf Female
2988 case 54: m_target->SetDisplayId(10142); break;
2989 // NightElf Male
2990 case 55: m_target->SetDisplayId(10143); break;
2991 // NightElf Female
2992 case 56: m_target->SetDisplayId(10144); break;
2993 // Undead Female
2994 case 58: m_target->SetDisplayId(10145); break;
2995 // Undead Male
2996 case 57: m_target->SetDisplayId(10146); break;
2997 // Tauren Female
2998 case 60: m_target->SetDisplayId(10147); break;
2999 // Gnome Male
3000 case 1563: m_target->SetDisplayId(10148); break;
3001 // Gnome Female
3002 case 1564: m_target->SetDisplayId(10149); break;
3003 // BloodElf Female
3004 case 15475: m_target->SetDisplayId(17830); break;
3005 // BloodElf Male
3006 case 15476: m_target->SetDisplayId(17829); break;
3007 // Dranei Female
3008 case 16126: m_target->SetDisplayId(17828); break;
3009 // Dranei Male
3010 case 16125: m_target->SetDisplayId(17827); break;
3011 default: break;
3013 break;
3015 // Murloc costume
3016 case 42365: m_target->SetDisplayId(21723); break;
3017 default: break;
3020 else
3022 uint32 model_id;
3024 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue);
3025 if (!ci)
3027 model_id = 16358; // pig pink ^_^
3028 sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
3030 else
3031 model_id = ci->DisplayID_A[0]; // Will use the default model here
3033 // Polymorph (sheep/penguin case)
3034 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
3035 if (Unit* caster = GetCaster())
3036 if (caster->HasAura(52648)) // Glyph of the Penguin
3037 model_id = 26452;
3039 m_target->SetDisplayId(model_id);
3041 // Dragonmaw Illusion (set mount model also)
3042 if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty())
3043 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
3046 // update active transform spell only not set or not overwriting negative by positive case
3047 if (!m_target->getTransForm() || !IsPositiveSpell(GetId()) || IsPositiveSpell(m_target->getTransForm()))
3048 m_target->setTransForm(GetId());
3050 // polymorph case
3051 if (Real && m_target->GetTypeId() == TYPEID_PLAYER && m_target->IsPolymorphed())
3053 // for players, start regeneration after 1s (in polymorph fast regeneration case)
3054 // only if caster is Player (after patch 2.4.2)
3055 if (IS_PLAYER_GUID(GetCasterGUID()) )
3056 ((Player*)m_target)->setRegenTimer(1*IN_MILISECONDS);
3058 //dismount polymorphed target (after patch 2.4.2)
3059 if (m_target->IsMounted())
3060 m_target->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
3063 else
3065 // ApplyModifier(true) will reapply it if need
3066 m_target->setTransForm(0);
3067 m_target->SetDisplayId(m_target->GetNativeDisplayId());
3069 // re-aplly some from still active with preference negative cases
3070 Unit::AuraList const& otherTransforms = m_target->GetAurasByType(SPELL_AURA_TRANSFORM);
3071 if (!otherTransforms.empty())
3073 // look for other transform auras
3074 Aura* handledAura = *otherTransforms.begin();
3075 for(Unit::AuraList::const_iterator i = otherTransforms.begin();i != otherTransforms.end(); ++i)
3077 // negative auras are preferred
3078 if (!IsPositiveSpell((*i)->GetSpellProto()->Id))
3080 handledAura = *i;
3081 break;
3084 handledAura->ApplyModifier(true);
3087 // Dragonmaw Illusion (restore mount model)
3088 if (GetId() == 42016 && m_target->GetMountID() == 16314)
3090 if (!m_target->GetAurasByType(SPELL_AURA_MOUNTED).empty())
3092 uint32 cr_id = m_target->GetAurasByType(SPELL_AURA_MOUNTED).front()->GetModifier()->m_miscvalue;
3093 if (CreatureInfo const* ci = objmgr.GetCreatureTemplate(cr_id))
3095 uint32 team = 0;
3096 if (m_target->GetTypeId() == TYPEID_PLAYER)
3097 team = ((Player*)m_target)->GetTeam();
3099 uint32 display_id = objmgr.ChooseDisplayId(team, ci);
3100 CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id);
3101 if (minfo)
3102 display_id = minfo->modelid;
3104 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, display_id);
3111 void Aura::HandleForceReaction(bool apply, bool Real)
3113 if(m_target->GetTypeId() != TYPEID_PLAYER)
3114 return;
3116 if(!Real)
3117 return;
3119 Player* player = (Player*)m_target;
3121 uint32 faction_id = m_modifier.m_miscvalue;
3122 uint32 faction_rank = m_modifier.m_amount;
3124 player->GetReputationMgr().ApplyForceReaction(faction_id, ReputationRank(faction_rank), apply);
3125 player->GetReputationMgr().SendForceReactions();
3128 void Aura::HandleAuraModSkill(bool apply, bool /*Real*/)
3130 if(m_target->GetTypeId() != TYPEID_PLAYER)
3131 return;
3133 uint32 prot=GetSpellProto()->EffectMiscValue[m_effIndex];
3134 int32 points = GetModifier()->m_amount;
3136 ((Player*)m_target)->ModifySkillBonus(prot, (apply ? points: -points), m_modifier.m_auraname == SPELL_AURA_MOD_SKILL_TALENT);
3137 if(prot == SKILL_DEFENSE)
3138 ((Player*)m_target)->UpdateDefenseBonusesMod();
3141 void Aura::HandleChannelDeathItem(bool apply, bool Real)
3143 if(Real && !apply)
3145 Unit* caster = GetCaster();
3146 Unit* victim = GetTarget();
3147 if(!caster || caster->GetTypeId() != TYPEID_PLAYER || !victim || m_removeMode != AURA_REMOVE_BY_DEATH)
3148 return;
3149 // Item amount
3150 if (m_modifier.m_amount <= 0)
3151 return;
3153 SpellEntry const *spellInfo = GetSpellProto();
3154 if(spellInfo->EffectItemType[m_effIndex] == 0)
3155 return;
3157 // Soul Shard only from non-grey units
3158 if( spellInfo->EffectItemType[m_effIndex] == 6265 &&
3159 (victim->getLevel() <= MaNGOS::XP::GetGrayLevel(caster->getLevel()) ||
3160 victim->GetTypeId()==TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)victim)) )
3161 return;
3162 //Adding items
3163 uint32 noSpaceForCount = 0;
3164 uint32 count = m_modifier.m_amount;
3166 ItemPosCountVec dest;
3167 uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, spellInfo->EffectItemType[m_effIndex], count, &noSpaceForCount);
3168 if( msg != EQUIP_ERR_OK )
3170 count-=noSpaceForCount;
3171 ((Player*)caster)->SendEquipError( msg, NULL, NULL );
3172 if (count==0)
3173 return;
3176 Item* newitem = ((Player*)caster)->StoreNewItem(dest, spellInfo->EffectItemType[m_effIndex], true);
3177 ((Player*)caster)->SendNewItem(newitem, count, true, false);
3181 void Aura::HandleBindSight(bool apply, bool /*Real*/)
3183 Unit* caster = GetCaster();
3184 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3185 return;
3187 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3190 void Aura::HandleFarSight(bool apply, bool /*Real*/)
3192 Unit* caster = GetCaster();
3193 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3194 return;
3196 ((Player*)caster)->SetFarSightGUID(apply ? m_target->GetGUID() : 0);
3199 void Aura::HandleAuraTrackCreatures(bool apply, bool /*Real*/)
3201 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3202 return;
3204 if(apply)
3205 m_target->RemoveNoStackAurasDueToAura(this);
3206 m_target->SetUInt32Value(PLAYER_TRACK_CREATURES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1) : 0 );
3209 void Aura::HandleAuraTrackResources(bool apply, bool /*Real*/)
3211 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3212 return;
3214 if(apply)
3215 m_target->RemoveNoStackAurasDueToAura(this);
3216 m_target->SetUInt32Value(PLAYER_TRACK_RESOURCES, apply ? ((uint32)1)<<(m_modifier.m_miscvalue-1): 0 );
3219 void Aura::HandleAuraTrackStealthed(bool apply, bool /*Real*/)
3221 if(m_target->GetTypeId()!=TYPEID_PLAYER)
3222 return;
3224 if(apply)
3225 m_target->RemoveNoStackAurasDueToAura(this);
3227 m_target->ApplyModFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTE_TRACK_STEALTHED, apply);
3230 void Aura::HandleAuraModScale(bool apply, bool /*Real*/)
3232 m_target->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X, m_modifier.m_amount, apply);
3235 void Aura::HandleModPossess(bool apply, bool Real)
3237 if(!Real)
3238 return;
3240 // not possess yourself
3241 if(GetCasterGUID() == m_target->GetGUID())
3242 return;
3244 Unit* caster = GetCaster();
3245 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3246 return;
3248 Player* p_caster = (Player*)caster;
3251 if( apply )
3253 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3255 m_target->SetCharmerGUID(p_caster->GetGUID());
3256 m_target->setFaction(p_caster->getFaction());
3258 p_caster->SetCharm(m_target);
3260 p_caster->SetFarSightGUID(m_target->GetGUID());
3261 p_caster->SetClientControl(m_target, 1);
3262 p_caster->SetMover(m_target);
3264 m_target->CombatStop();
3265 m_target->DeleteThreatList();
3267 if(m_target->GetTypeId() == TYPEID_UNIT)
3269 m_target->StopMoving();
3270 m_target->GetMotionMaster()->Clear();
3271 m_target->GetMotionMaster()->MoveIdle();
3273 else if(m_target->GetTypeId() == TYPEID_PLAYER)
3275 ((Player*)m_target)->SetClientControl(m_target, 0);
3278 if(CharmInfo *charmInfo = m_target->InitCharmInfo(m_target))
3279 charmInfo->InitPossessCreateSpells();
3281 p_caster->PossessSpellInitialize();
3283 else
3285 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3287 m_target->SetCharmerGUID(0);
3288 p_caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now
3290 if(m_target->GetTypeId() == TYPEID_PLAYER)
3292 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3293 ((Player*)m_target)->SetClientControl(m_target, 1);
3295 else if(m_target->GetTypeId() == TYPEID_UNIT)
3297 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3298 m_target->setFaction(cinfo->faction_A);
3301 p_caster->SetCharm(NULL);
3303 p_caster->SetFarSightGUID(0);
3304 p_caster->SetClientControl(m_target, 0);
3305 p_caster->SetMover(NULL);
3307 p_caster->RemovePetActionBar();
3309 if(m_target->GetTypeId() == TYPEID_UNIT)
3311 ((Creature*)m_target)->AIM_Initialize();
3313 if (((Creature*)m_target)->AI())
3314 ((Creature*)m_target)->AI()->AttackedBy(caster);
3319 void Aura::HandleModPossessPet(bool apply, bool Real)
3321 if(!Real)
3322 return;
3324 Unit* caster = GetCaster();
3325 if(!caster || caster->GetTypeId() != TYPEID_PLAYER)
3326 return;
3328 Pet *pet = caster->GetPet();
3329 if(!pet || pet != m_target)
3330 return;
3332 Player* p_caster = (Player*)caster;
3334 if(apply)
3335 pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3336 else
3337 pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
3339 p_caster->SetFarSightGUID(apply ? pet->GetGUID() : 0);
3340 p_caster->SetCharm(apply ? pet : NULL);
3341 p_caster->SetClientControl(pet, apply ? 1 : 0);
3342 ((Player*)caster)->SetMover(apply ? pet : NULL);
3344 if(apply)
3346 pet->StopMoving();
3347 pet->GetMotionMaster()->Clear();
3348 pet->GetMotionMaster()->MoveIdle();
3350 else
3352 pet->AttackStop();
3353 pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
3354 pet->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
3358 void Aura::HandleAuraModPetTalentsPoints(bool /*Apply*/, bool Real)
3360 if(!Real)
3361 return;
3363 // Recalculate pet talent points
3364 if (Pet *pet=m_target->GetPet())
3365 pet->InitTalentForLevel();
3368 void Aura::HandleModCharm(bool apply, bool Real)
3370 if(!Real)
3371 return;
3373 // not charm yourself
3374 if(GetCasterGUID() == m_target->GetGUID())
3375 return;
3377 Unit* caster = GetCaster();
3378 if(!caster)
3379 return;
3381 if( apply )
3383 m_target->SetCharmerGUID(GetCasterGUID());
3384 m_target->setFaction(caster->getFaction());
3385 m_target->CastStop(m_target == caster ? GetId() : 0);
3386 caster->SetCharm(m_target);
3388 m_target->CombatStop();
3389 m_target->DeleteThreatList();
3391 if(m_target->GetTypeId() == TYPEID_UNIT)
3393 ((Creature*)m_target)->AIM_Initialize();
3394 CharmInfo *charmInfo = m_target->InitCharmInfo(m_target);
3395 charmInfo->InitCharmCreateSpells();
3396 charmInfo->SetReactState( REACT_DEFENSIVE );
3398 if(caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK)
3400 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3401 if(cinfo && cinfo->type == CREATURE_TYPE_DEMON)
3403 // creature with pet number expected have class set
3404 if(m_target->GetByteValue(UNIT_FIELD_BYTES_0, 1)==0)
3406 if(cinfo->unit_class==0)
3407 sLog.outErrorDb("Creature (Entry: %u) have unit_class = 0 but used in charmed spell, that will be result client crash.",cinfo->Entry);
3408 else
3409 sLog.outError("Creature (Entry: %u) have unit_class = %u but at charming have class 0!!! that will be result client crash.",cinfo->Entry,cinfo->unit_class);
3411 m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, CLASS_MAGE);
3414 //just to enable stat window
3415 charmInfo->SetPetNumber(objmgr.GeneratePetNumber(), true);
3416 //if charmed two demons the same session, the 2nd gets the 1st one's name
3417 m_target->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
3422 if(caster->GetTypeId() == TYPEID_PLAYER)
3423 ((Player*)caster)->CharmSpellInitialize();
3425 else
3427 m_target->SetCharmerGUID(0);
3429 if(m_target->GetTypeId() == TYPEID_PLAYER)
3430 ((Player*)m_target)->setFactionForRace(m_target->getRace());
3431 else
3433 CreatureInfo const *cinfo = ((Creature*)m_target)->GetCreatureInfo();
3435 // restore faction
3436 if(((Creature*)m_target)->isPet())
3438 if(Unit* owner = m_target->GetOwner())
3439 m_target->setFaction(owner->getFaction());
3440 else if(cinfo)
3441 m_target->setFaction(cinfo->faction_A);
3443 else if(cinfo) // normal creature
3444 m_target->setFaction(cinfo->faction_A);
3446 // restore UNIT_FIELD_BYTES_0
3447 if(cinfo && caster->GetTypeId() == TYPEID_PLAYER && caster->getClass() == CLASS_WARLOCK && cinfo->type == CREATURE_TYPE_DEMON)
3449 // DB must have proper class set in field at loading, not req. restore, including workaround case at apply
3450 // m_target->SetByteValue(UNIT_FIELD_BYTES_0, 1, cinfo->unit_class);
3452 if(m_target->GetCharmInfo())
3453 m_target->GetCharmInfo()->SetPetNumber(0, true);
3454 else
3455 sLog.outError("Aura::HandleModCharm: target (GUID: %u TypeId: %u) has a charm aura but no charm info!", m_target->GetGUIDLow(), m_target->GetTypeId());
3459 caster->SetCharm(NULL);
3461 if(caster->GetTypeId() == TYPEID_PLAYER)
3462 ((Player*)caster)->RemovePetActionBar();
3464 if(m_target->GetTypeId() == TYPEID_UNIT)
3466 ((Creature*)m_target)->AIM_Initialize();
3467 if (((Creature*)m_target)->AI())
3468 ((Creature*)m_target)->AI()->AttackedBy(caster);
3473 void Aura::HandleModConfuse(bool apply, bool Real)
3475 if(!Real)
3476 return;
3478 m_target->SetConfused(apply, GetCasterGUID(), GetId());
3481 void Aura::HandleModFear(bool apply, bool Real)
3483 if (!Real)
3484 return;
3486 m_target->SetFeared(apply, GetCasterGUID(), GetId());
3489 void Aura::HandleFeignDeath(bool apply, bool Real)
3491 if(!Real)
3492 return;
3494 if(m_target->GetTypeId() != TYPEID_PLAYER)
3495 return;
3497 if( apply )
3500 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3501 data<<m_target->GetGUID();
3502 data<<uint8(0);
3503 m_target->SendMessageToSet(&data,true);
3505 // blizz like 2.0.x
3506 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3507 // blizz like 2.0.x
3508 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3509 // blizz like 2.0.x
3510 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3512 m_target->addUnitState(UNIT_STAT_DIED);
3513 m_target->CombatStop();
3514 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3516 // prevent interrupt message
3517 if (m_caster_guid==m_target->GetGUID())
3518 m_target->FinishSpell(CURRENT_GENERIC_SPELL,false);
3519 m_target->InterruptNonMeleeSpells(true);
3520 m_target->getHostilRefManager().deleteReferences();
3522 else
3525 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
3526 data<<m_target->GetGUID();
3527 data<<uint8(1);
3528 m_target->SendMessageToSet(&data,true);
3530 // blizz like 2.0.x
3531 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_29);
3532 // blizz like 2.0.x
3533 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
3534 // blizz like 2.0.x
3535 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
3537 m_target->clearUnitState(UNIT_STAT_DIED);
3541 void Aura::HandleAuraModDisarm(bool apply, bool Real)
3543 if(!Real)
3544 return;
3546 if(!apply && m_target->HasAuraType(SPELL_AURA_MOD_DISARM))
3547 return;
3549 // not sure for it's correctness
3550 if(apply)
3551 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3552 else
3553 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED);
3555 // only at real add/remove aura
3556 if (m_target->GetTypeId() != TYPEID_PLAYER)
3557 return;
3559 // main-hand attack speed already set to special value for feral form already and don't must change and reset at remove.
3560 if (m_target->IsInFeralForm())
3561 return;
3563 if (apply)
3564 m_target->SetAttackTime(BASE_ATTACK,BASE_ATTACK_TIME);
3565 else
3566 ((Player *)m_target)->SetRegularAttackTime();
3568 m_target->UpdateDamagePhysical(BASE_ATTACK);
3571 void Aura::HandleAuraModStun(bool apply, bool Real)
3573 if(!Real)
3574 return;
3576 if (apply)
3578 // Frost stun aura -> freeze/unfreeze target
3579 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3580 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3582 m_target->addUnitState(UNIT_STAT_STUNNED);
3583 m_target->SetUInt64Value(UNIT_FIELD_TARGET, 0);
3585 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3586 m_target->CastStop(m_target->GetGUID() == GetCasterGUID() ? GetId() : 0);
3588 // Creature specific
3589 if(m_target->GetTypeId() != TYPEID_PLAYER)
3590 m_target->StopMoving();
3591 else
3593 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3594 m_target->SetStandState(UNIT_STAND_STATE_STAND);// in 1.5 client
3597 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 8);
3598 data.append(m_target->GetPackGUID());
3599 data << uint32(0);
3600 m_target->SendMessageToSet(&data, true);
3602 // Summon the Naj'entus Spine GameObject on target if spell is Impaling Spine
3603 if(GetId() == 39837)
3605 GameObject* pObj = new GameObject;
3606 if(pObj->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 185584, m_target->GetMap(), m_target->GetPhaseMask(),
3607 m_target->GetPositionX(), m_target->GetPositionY(), m_target->GetPositionZ(), m_target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
3609 pObj->SetRespawnTime(GetAuraDuration()/IN_MILISECONDS);
3610 pObj->SetSpellId(GetId());
3611 m_target->AddGameObject(pObj);
3612 m_target->GetMap()->Add(pObj);
3614 else
3615 delete pObj;
3618 else
3620 // Frost stun aura -> freeze/unfreeze target
3621 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3623 bool found_another = false;
3624 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3626 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3627 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3629 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3631 found_another = true;
3632 break;
3635 if(found_another)
3636 break;
3639 if(!found_another)
3640 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3643 // Real remove called after current aura remove from lists, check if other similar auras active
3644 if(m_target->HasAuraType(SPELL_AURA_MOD_STUN))
3645 return;
3647 m_target->clearUnitState(UNIT_STAT_STUNNED);
3648 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
3650 if(!m_target->hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
3652 if(m_target->getVictim() && m_target->isAlive())
3653 m_target->SetUInt64Value(UNIT_FIELD_TARGET,m_target->getVictim()->GetGUID() );
3655 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
3656 data.append(m_target->GetPackGUID());
3657 data << uint32(0);
3658 m_target->SendMessageToSet(&data, true);
3661 // Wyvern Sting
3662 if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & UI64LIT(0x0000100000000000))
3664 Unit* caster = GetCaster();
3665 if( !caster || caster->GetTypeId()!=TYPEID_PLAYER )
3666 return;
3668 uint32 spell_id = 0;
3670 switch(GetId())
3672 case 19386: spell_id = 24131; break;
3673 case 24132: spell_id = 24134; break;
3674 case 24133: spell_id = 24135; break;
3675 case 27068: spell_id = 27069; break;
3676 case 49011: spell_id = 49009; break;
3677 case 49012: spell_id = 49010; break;
3678 default:
3679 sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?",GetId());
3680 return;
3683 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
3685 if(!spellInfo)
3686 return;
3688 caster->CastSpell(m_target,spellInfo,true,NULL,this);
3689 return;
3694 void Aura::HandleModStealth(bool apply, bool Real)
3696 if (apply)
3698 // drop flag at stealth in bg
3699 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3701 // only at real aura add
3702 if (Real)
3704 m_target->SetStandFlags(UNIT_STAND_FLAGS_CREEP);
3706 if (m_target->GetTypeId()==TYPEID_PLAYER)
3707 m_target->SetFlag(PLAYER_FIELD_BYTES2, 0x2000);
3709 // apply only if not in GM invisibility (and overwrite invisibility state)
3710 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3712 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3713 m_target->SetVisibility(VISIBILITY_GROUP_STEALTH);
3716 // apply full stealth period bonuses only at first stealth aura in stack
3717 if(m_target->GetAurasByType(SPELL_AURA_MOD_STEALTH).size()<=1)
3719 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3720 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3722 // Master of Subtlety
3723 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3725 m_target->RemoveAurasDueToSpell(31666);
3726 int32 bp = (*i)->GetModifier()->m_amount;
3727 m_target->CastCustomSpell(m_target,31665,&bp,NULL,NULL,true);
3729 // Overkill
3730 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3732 m_target->RemoveAurasDueToSpell(58428);
3733 m_target->CastSpell(m_target, 58427, true);
3739 else
3741 // only at real aura remove of _last_ SPELL_AURA_MOD_STEALTH
3742 if (Real && !m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3744 // if no GM invisibility
3745 if (m_target->GetVisibility()!=VISIBILITY_OFF)
3747 m_target->RemoveStandFlags(UNIT_STAND_FLAGS_CREEP);
3749 if (m_target->GetTypeId()==TYPEID_PLAYER)
3750 m_target->RemoveFlag(PLAYER_FIELD_BYTES2, 0x2000);
3752 // restore invisibility if any
3753 if (m_target->HasAuraType(SPELL_AURA_MOD_INVISIBILITY))
3755 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3756 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3758 else
3759 m_target->SetVisibility(VISIBILITY_ON);
3762 // apply delayed talent bonus remover at last stealth aura remove
3763 Unit::AuraList const& mDummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
3764 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
3766 // Master of Subtlety
3767 if ((*i)->GetSpellProto()->SpellIconID == 2114)
3768 m_target->CastSpell(m_target, 31666, true);
3769 // Overkill
3770 else if ((*i)->GetId() == 58426 && GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000400000))
3771 m_target->CastSpell(m_target, 58428, true);
3777 void Aura::HandleInvisibility(bool apply, bool Real)
3779 if(apply)
3781 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3783 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
3785 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3787 // apply glow vision
3788 m_target->SetFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3792 // apply only if not in GM invisibility and not stealth
3793 if(m_target->GetVisibility() == VISIBILITY_ON)
3795 // Aura not added yet but visibility code expect temporary add aura
3796 m_target->SetVisibility(VISIBILITY_GROUP_NO_DETECT);
3797 m_target->SetVisibility(VISIBILITY_GROUP_INVISIBILITY);
3800 else
3802 // recalculate value at modifier remove (current aura already removed)
3803 m_target->m_invisibilityMask = 0;
3804 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY);
3805 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3806 m_target->m_invisibilityMask |= (1 << m_modifier.m_miscvalue);
3808 // only at real aura remove and if not have different invisibility auras.
3809 if(Real && m_target->m_invisibilityMask == 0)
3811 // remove glow vision
3812 if(m_target->GetTypeId() == TYPEID_PLAYER)
3813 m_target->RemoveFlag(PLAYER_FIELD_BYTES2,PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW);
3815 // apply only if not in GM invisibility & not stealthed while invisible
3816 if(m_target->GetVisibility() != VISIBILITY_OFF)
3818 // if have stealth aura then already have stealth visibility
3819 if(!m_target->HasAuraType(SPELL_AURA_MOD_STEALTH))
3820 m_target->SetVisibility(VISIBILITY_ON);
3826 void Aura::HandleInvisibilityDetect(bool apply, bool Real)
3828 if(apply)
3830 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3832 else
3834 // recalculate value at modifier remove (current aura already removed)
3835 m_target->m_detectInvisibilityMask = 0;
3836 Unit::AuraList const& auras = m_target->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION);
3837 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3838 m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue);
3840 if(Real && m_target->GetTypeId()==TYPEID_PLAYER)
3841 ObjectAccessor::UpdateVisibilityForPlayer((Player*)m_target);
3844 void Aura::HandleAuraModRoot(bool apply, bool Real)
3846 // only at real add/remove aura
3847 if(!Real)
3848 return;
3850 if (apply)
3852 // Frost root aura -> freeze/unfreeze target
3853 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3854 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3856 m_target->addUnitState(UNIT_STAT_ROOT);
3857 m_target->SetUInt64Value (UNIT_FIELD_TARGET, 0);
3858 // probably wrong (this add skinable flag)
3859 // TODO: find correct flag
3860 //m_target->SetFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3862 //Save last orientation
3863 if( m_target->getVictim() )
3864 m_target->SetOrientation(m_target->GetAngle(m_target->getVictim()));
3866 if(m_target->GetTypeId() == TYPEID_PLAYER)
3868 WorldPacket data(SMSG_FORCE_MOVE_ROOT, 10);
3869 data.append(m_target->GetPackGUID());
3870 data << (uint32)2;
3871 m_target->SendMessageToSet(&data, true);
3873 //Clear unit movement flags
3874 ((Player*)m_target)->m_movementInfo.SetMovementFlags(MOVEMENTFLAG_NONE);
3876 else
3877 m_target->StopMoving();
3879 else
3881 // Frost root aura -> freeze/unfreeze target
3882 if (GetSpellSchoolMask(m_spellProto) & SPELL_SCHOOL_MASK_FROST)
3884 bool found_another = false;
3885 for(AuraType const* itr = &frozenAuraTypes[0]; *itr != SPELL_AURA_NONE; ++itr)
3887 Unit::AuraList const& auras = m_target->GetAurasByType(*itr);
3888 for(Unit::AuraList::const_iterator i = auras.begin(); i != auras.end(); ++i)
3890 if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST)
3892 found_another = true;
3893 break;
3896 if(found_another)
3897 break;
3900 if(!found_another)
3901 m_target->ModifyAuraState(AURA_STATE_FROZEN, apply);
3904 // Real remove called after current aura remove from lists, check if other similar auras active
3905 if(m_target->HasAuraType(SPELL_AURA_MOD_ROOT))
3906 return;
3908 m_target->clearUnitState(UNIT_STAT_ROOT);
3909 // probably wrong (this add skinable flag)
3910 // TODO: find correct flag
3911 //m_target->RemoveFlag(UNIT_FIELD_FLAGS,(apply_stat<<16));
3913 if(!m_target->hasUnitState(UNIT_STAT_STUNNED)) // prevent allow move if have also stun effect
3915 if(m_target->getVictim() && m_target->isAlive())
3916 m_target->SetUInt64Value (UNIT_FIELD_TARGET, m_target->getVictim()->GetGUID() );
3918 if(m_target->GetTypeId() == TYPEID_PLAYER)
3920 WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 10);
3921 data.append(m_target->GetPackGUID());
3922 data << (uint32)2;
3923 m_target->SendMessageToSet(&data, true);
3929 void Aura::HandleAuraModSilence(bool apply, bool Real)
3931 // only at real add/remove aura
3932 if(!Real)
3933 return;
3935 if(apply)
3937 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3938 // Stop cast only spells vs PreventionType == SPELL_PREVENTION_TYPE_SILENCE
3939 for (uint32 i = CURRENT_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
3940 if (Spell* spell = m_target->GetCurrentSpell(CurrentSpellTypes(i)))
3941 if(spell->m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE)
3942 // Stop spells on prepare or casting state
3943 m_target->InterruptSpell(CurrentSpellTypes(i), false);
3945 else
3947 // Real remove called after current aura remove from lists, check if other similar auras active
3948 if(m_target->HasAuraType(SPELL_AURA_MOD_SILENCE))
3949 return;
3951 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED);
3955 void Aura::HandleModThreat(bool apply, bool Real)
3957 // only at real add/remove aura
3958 if (!Real)
3959 return;
3961 if (!m_target->isAlive())
3962 return;
3964 Unit* caster = GetCaster();
3966 if (!caster || !caster->isAlive())
3967 return;
3969 int level_diff = 0;
3970 int multiplier = 0;
3971 switch (GetId())
3973 // Arcane Shroud
3974 case 26400:
3975 level_diff = m_target->getLevel() - 60;
3976 multiplier = 2;
3977 break;
3978 // The Eye of Diminution
3979 case 28862:
3980 level_diff = m_target->getLevel() - 60;
3981 multiplier = 1;
3982 break;
3985 if (level_diff > 0)
3986 m_modifier.m_amount += multiplier * level_diff;
3988 if (m_target->GetTypeId() == TYPEID_PLAYER)
3989 for(int8 x=0;x < MAX_SPELL_SCHOOL;x++)
3990 if (m_modifier.m_miscvalue & int32(1<<x))
3991 ApplyPercentModFloatVar(m_target->m_threatModifier[x], m_modifier.m_amount, apply);
3994 void Aura::HandleAuraModTotalThreat(bool apply, bool Real)
3996 // only at real add/remove aura
3997 if (!Real)
3998 return;
4000 if (!m_target->isAlive() || m_target->GetTypeId() != TYPEID_PLAYER)
4001 return;
4003 Unit* caster = GetCaster();
4005 if (!caster || !caster->isAlive())
4006 return;
4008 float threatMod = apply ? float(m_modifier.m_amount) : float(-m_modifier.m_amount);
4010 m_target->getHostilRefManager().threatAssist(caster, threatMod);
4013 void Aura::HandleModTaunt(bool apply, bool Real)
4015 // only at real add/remove aura
4016 if (!Real)
4017 return;
4019 if (!m_target->isAlive() || !m_target->CanHaveThreatList())
4020 return;
4022 Unit* caster = GetCaster();
4024 if (!caster || !caster->isAlive())
4025 return;
4027 if (apply)
4028 m_target->TauntApply(caster);
4029 else
4031 // When taunt aura fades out, mob will switch to previous target if current has less than 1.1 * secondthreat
4032 m_target->TauntFadeOut(caster);
4036 /*********************************************************/
4037 /*** MODIFY SPEED ***/
4038 /*********************************************************/
4039 void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real)
4041 // all applied/removed only at real aura add/remove
4042 if(!Real)
4043 return;
4045 m_target->UpdateSpeed(MOVE_RUN, true);
4048 void Aura::HandleAuraModIncreaseMountedSpeed(bool /*apply*/, bool Real)
4050 // all applied/removed only at real aura add/remove
4051 if(!Real)
4052 return;
4054 m_target->UpdateSpeed(MOVE_RUN, true);
4057 void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real)
4059 // all applied/removed only at real aura add/remove
4060 if(!Real)
4061 return;
4063 // Enable Fly mode for flying mounts
4064 if (m_modifier.m_auraname == SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED)
4066 WorldPacket data;
4067 if(apply)
4068 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
4069 else
4070 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
4071 data.append(m_target->GetPackGUID());
4072 data << uint32(0); // unknown
4073 m_target->SendMessageToSet(&data, true);
4075 //Players on flying mounts must be immune to polymorph
4076 if (m_target->GetTypeId()==TYPEID_PLAYER)
4077 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,MECHANIC_POLYMORPH,apply);
4079 // Dragonmaw Illusion (overwrite mount model, mounted aura already applied)
4080 if( apply && m_target->HasAura(42016,0) && m_target->GetMountID())
4081 m_target->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID,16314);
4084 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4087 void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real)
4089 // all applied/removed only at real aura add/remove
4090 if(!Real)
4091 return;
4093 m_target->UpdateSpeed(MOVE_SWIM, true);
4096 void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real)
4098 // all applied/removed only at real aura add/remove
4099 if(!Real)
4100 return;
4102 if (apply)
4104 // Gronn Lord's Grasp, becomes stoned
4105 if (GetId() == 33572)
4107 if (GetStackAmount() >= 5 && !m_target->HasAura(33652))
4108 m_target->CastSpell(m_target, 33652, true);
4112 m_target->UpdateSpeed(MOVE_RUN, true);
4113 m_target->UpdateSpeed(MOVE_SWIM, true);
4114 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4117 void Aura::HandleAuraModUseNormalSpeed(bool /*apply*/, bool Real)
4119 // all applied/removed only at real aura add/remove
4120 if(!Real)
4121 return;
4123 m_target->UpdateSpeed(MOVE_RUN, true);
4124 m_target->UpdateSpeed(MOVE_SWIM, true);
4125 m_target->UpdateSpeed(MOVE_FLIGHT, true);
4128 /*********************************************************/
4129 /*** IMMUNITY ***/
4130 /*********************************************************/
4132 void Aura::HandleModMechanicImmunity(bool apply, bool /*Real*/)
4134 uint32 misc = m_modifier.m_miscvalue;
4135 // Forbearance
4136 // in DBC wrong mechanic immune since 3.0.x
4137 if (GetId() == 25771)
4138 misc = MECHANIC_IMMUNE_SHIELD;
4141 if(apply && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4143 uint32 mechanic = 1 << misc;
4145 //immune movement impairment and loss of control
4146 if(GetId()==42292 || GetId()==59752)
4147 mechanic=IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
4149 Unit::AuraMap& Auras = m_target->GetAuras();
4150 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4152 next = iter;
4153 ++next;
4154 SpellEntry const *spell = iter->second->GetSpellProto();
4155 if (!( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) && // spells unaffected by invulnerability
4156 spell->Id != GetId())
4158 //check for mechanic mask
4159 if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & mechanic)
4161 m_target->RemoveAurasDueToSpell(spell->Id);
4162 if(Auras.empty())
4163 break;
4164 else
4165 next = Auras.begin();
4171 m_target->ApplySpellImmune(GetId(),IMMUNITY_MECHANIC,misc,apply);
4173 // Bestial Wrath
4174 if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_HUNTER && GetSpellProto()->SpellIconID == 1680)
4176 // The Beast Within cast on owner if talent present
4177 if (Unit* owner = m_target->GetOwner())
4179 // Search talent
4180 Unit::AuraList const& dummyAuras = owner->GetAurasByType(SPELL_AURA_DUMMY);
4181 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); ++i)
4183 if ((*i)->GetSpellProto()->SpellIconID == 2229)
4185 if (apply)
4186 owner->CastSpell(owner, 34471, true, 0, this);
4187 else
4188 owner->RemoveAurasDueToSpell(34471);
4189 break;
4196 //this method is called whenever we add / remove aura which gives m_target some imunity to some spell effect
4197 void Aura::HandleAuraModEffectImmunity(bool apply, bool /*Real*/)
4199 // when removing flag aura, handle flag drop
4200 if( !apply && m_target->GetTypeId() == TYPEID_PLAYER
4201 && (GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION) )
4203 if( BattleGround *bg = ((Player*)m_target)->GetBattleGround() )
4204 bg->EventPlayerDroppedFlag(((Player*)m_target));
4207 m_target->ApplySpellImmune(GetId(), IMMUNITY_EFFECT, m_modifier.m_miscvalue, apply);
4210 void Aura::HandleAuraModStateImmunity(bool apply, bool Real)
4212 if(apply && Real && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)
4214 Unit::AuraList const& auraList = m_target->GetAurasByType(AuraType(m_modifier.m_miscvalue));
4215 for(Unit::AuraList::const_iterator itr = auraList.begin(); itr != auraList.end();)
4217 if (auraList.front() != this) // skip itself aura (it already added)
4219 m_target->RemoveAurasDueToSpell(auraList.front()->GetId());
4220 itr = auraList.begin();
4222 else
4223 ++itr;
4227 m_target->ApplySpellImmune(GetId(), IMMUNITY_STATE, m_modifier.m_miscvalue, apply);
4230 void Aura::HandleAuraModSchoolImmunity(bool apply, bool Real)
4232 m_target->ApplySpellImmune(GetId(), IMMUNITY_SCHOOL, m_modifier.m_miscvalue, apply);
4234 // remove all flag auras (they are positive, but they must be removed when you are immune)
4235 if( this->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4236 && this->GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_DAMAGE_REDUCED_SHIELD )
4237 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
4239 // TODO: optimalize this cycle - use RemoveAurasWithInterruptFlags call or something else
4240 if( Real && apply
4241 && GetSpellProto()->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
4242 && IsPositiveSpell(GetId()) ) //Only positive immunity removes auras
4244 uint32 school_mask = m_modifier.m_miscvalue;
4245 Unit::AuraMap& Auras = m_target->GetAuras();
4246 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
4248 next = iter;
4249 ++next;
4250 SpellEntry const *spell = iter->second->GetSpellProto();
4251 if((GetSpellSchoolMask(spell) & school_mask)//Check for school mask
4252 && !( spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) //Spells unaffected by invulnerability
4253 && !iter->second->IsPositive() //Don't remove positive spells
4254 && spell->Id != GetId() ) //Don't remove self
4256 m_target->RemoveAurasDueToSpell(spell->Id);
4257 if(Auras.empty())
4258 break;
4259 else
4260 next = Auras.begin();
4264 if( Real && GetSpellProto()->Mechanic == MECHANIC_BANISH )
4266 if( apply )
4267 m_target->addUnitState(UNIT_STAT_ISOLATED);
4268 else
4269 m_target->clearUnitState(UNIT_STAT_ISOLATED);
4273 void Aura::HandleAuraModDmgImmunity(bool apply, bool /*Real*/)
4275 m_target->ApplySpellImmune(GetId(), IMMUNITY_DAMAGE, m_modifier.m_miscvalue, apply);
4278 void Aura::HandleAuraModDispelImmunity(bool apply, bool Real)
4280 // all applied/removed only at real aura add/remove
4281 if(!Real)
4282 return;
4284 m_target->ApplySpellDispelImmunity(m_spellProto, DispelType(m_modifier.m_miscvalue), apply);
4287 void Aura::HandleAuraProcTriggerSpell(bool apply, bool Real)
4289 if(!Real)
4290 return;
4292 if(apply)
4294 // some spell have charges by functionality not have its in spell data
4295 switch (GetId())
4297 case 28200: // Ascendance (Talisman of Ascendance trinket)
4298 SetAuraCharges(6);
4299 break;
4300 default: break;
4305 void Aura::HandleAuraModStalked(bool apply, bool /*Real*/)
4307 // used by spells: Hunter's Mark, Mind Vision, Syndicate Tracker (MURP) DND
4308 if(apply)
4309 m_target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4310 else
4311 m_target->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TRACK_UNIT);
4314 /*********************************************************/
4315 /*** PERIODIC ***/
4316 /*********************************************************/
4318 void Aura::HandlePeriodicTriggerSpell(bool apply, bool /*Real*/)
4320 m_isPeriodic = apply;
4322 if (!apply)
4324 switch(m_spellProto->Id)
4326 case 66: // Invisibility
4327 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && m_duration<=0)
4328 m_target->CastSpell(m_target, 32612, true, NULL, this);
4330 return;
4331 case 42783: //Wrath of the Astrom...
4332 if (m_removeMode == AURA_REMOVE_BY_DEFAULT && GetEffIndex() + 1 < 3)
4333 m_target->CastSpell(m_target, m_spellProto->CalculateSimpleValue(GetEffIndex()+1), true);
4334 return;
4335 default:
4336 break;
4341 void Aura::HandlePeriodicTriggerSpellWithValue(bool apply, bool /*Real*/)
4343 m_isPeriodic = apply;
4346 void Aura::HandlePeriodicEnergize(bool apply, bool Real)
4348 if (!Real)
4349 return;
4351 m_isPeriodic = apply;
4353 // Replenishment (0.25% from max)
4354 // Infinite Replenishment
4355 if (GetId() == 57669 ||
4356 GetId() == 61782)
4357 m_modifier.m_amount = m_target->GetMaxPower(POWER_MANA) * 25 / 10000;
4360 void Aura::HandleAuraPowerBurn(bool apply, bool /*Real*/)
4362 m_isPeriodic = apply;
4365 void Aura::HandleAuraPeriodicDummy(bool apply, bool Real)
4367 // spells required only Real aura add/remove
4368 if(!Real)
4369 return;
4371 // For prevent double apply bonuses
4372 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4374 Unit* caster = GetCaster();
4376 SpellEntry const*spell = GetSpellProto();
4377 switch( spell->SpellFamilyName)
4379 case SPELLFAMILY_ROGUE:
4381 if(!apply)
4383 switch(spell->Id)
4385 // Master of Subtlety
4386 case 31666: m_target->RemoveAurasDueToSpell(31665); break;
4387 // Overkill
4388 case 58428: m_target->RemoveAurasDueToSpell(58427); break;
4391 break;
4393 case SPELLFAMILY_HUNTER:
4395 // Explosive Shot
4396 if (apply && !loading && caster)
4397 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 14 / 100);
4398 break;
4402 m_isPeriodic = apply;
4405 void Aura::HandlePeriodicHeal(bool apply, bool /*Real*/)
4407 m_isPeriodic = apply;
4410 void Aura::HandlePeriodicDamage(bool apply, bool Real)
4412 // spells required only Real aura add/remove
4413 if(!Real)
4414 return;
4416 m_isPeriodic = apply;
4418 // For prevent double apply bonuses
4419 bool loading = (m_target->GetTypeId() == TYPEID_PLAYER && ((Player*)m_target)->GetSession()->PlayerLoading());
4421 // Custom damage calculation after
4422 if (apply)
4424 if(loading)
4425 return;
4427 Unit *caster = GetCaster();
4428 if (!caster)
4429 return;
4431 switch (m_spellProto->SpellFamilyName)
4433 case SPELLFAMILY_GENERIC:
4435 // Pounce Bleed
4436 if ( m_spellProto->SpellIconID == 147 && m_spellProto->SpellVisual[0] == 0 )
4438 // $AP*0.18/6 bonus per tick
4439 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 3 / 100);
4440 return;
4442 break;
4444 case SPELLFAMILY_WARRIOR:
4446 // Rend
4447 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000020))
4449 // $0.2*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick
4450 float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK);
4451 int32 mws = caster->GetAttackTime(BASE_ATTACK);
4452 float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE);
4453 float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE);
4454 m_modifier.m_amount+=int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.2f);
4455 return;
4457 break;
4459 case SPELLFAMILY_DRUID:
4461 // Rake
4462 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellProto->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
4464 // $AP*0.18/3 bonus per tick
4465 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 6 / 100);
4466 return;
4468 // Lacerate
4469 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000010000000000))
4471 // $AP*0.05/5 bonus per tick
4472 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
4473 return;
4475 // Rip
4476 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000800000))
4478 // 0.01*$AP*cp
4479 if (caster->GetTypeId() != TYPEID_PLAYER)
4480 return;
4482 uint8 cp = ((Player*)caster)->GetComboPoints();
4484 // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs
4485 Unit::AuraList const& dummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
4486 for(Unit::AuraList::const_iterator itr = dummyAuras.begin(); itr != dummyAuras.end(); ++itr)
4488 if((*itr)->GetId()==34241)
4490 m_modifier.m_amount += cp * (*itr)->GetModifier()->m_amount;
4491 break;
4494 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100);
4495 return;
4497 // Lock Jaw
4498 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x1000000000000000))
4500 // 0.15*$AP
4501 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 15 / 100);
4502 return;
4504 break;
4506 case SPELLFAMILY_ROGUE:
4508 // Rupture
4509 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000100000))
4511 if (caster->GetTypeId() != TYPEID_PLAYER)
4512 return;
4513 //1 point : ${($m1+$b1*1+0.015*$AP)*4} damage over 8 secs
4514 //2 points: ${($m1+$b1*2+0.024*$AP)*5} damage over 10 secs
4515 //3 points: ${($m1+$b1*3+0.03*$AP)*6} damage over 12 secs
4516 //4 points: ${($m1+$b1*4+0.03428571*$AP)*7} damage over 14 secs
4517 //5 points: ${($m1+$b1*5+0.0375*$AP)*8} damage over 16 secs
4518 float AP_per_combo[6] = {0.0f, 0.015f, 0.024f, 0.03f, 0.03428571f, 0.0375f};
4519 uint8 cp = ((Player*)caster)->GetComboPoints();
4520 if (cp > 5) cp = 5;
4521 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * AP_per_combo[cp]);
4522 return;
4524 // Garrote
4525 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x000000000000000100))
4527 // $AP*0.07 bonus per tick
4528 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 7 / 100);
4529 return;
4531 // Deadly Poison
4532 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000010000))
4534 // 0.08*$AP / 4 * amount of stack
4535 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * 2 * GetStackAmount() / 100);
4536 return;
4538 break;
4540 case SPELLFAMILY_HUNTER:
4542 // Serpent Sting
4543 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000004000))
4545 // $RAP*0.1/5 bonus per tick
4546 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4547 return;
4549 // Immolation Trap
4550 if ((m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000004)) && m_spellProto->SpellIconID == 678)
4552 // $RAP*0.1/5 bonus per tick
4553 m_modifier.m_amount += int32(caster->GetTotalAttackPowerValue(RANGED_ATTACK) * 10 / 500);
4554 return;
4556 break;
4558 default:
4559 break;
4562 // remove time effects
4563 else
4565 // Parasitic Shadowfiend - handle summoning of two Shadowfiends on DoT expire
4566 if(m_spellProto->Id == 41917)
4567 m_target->CastSpell(m_target, 41915, true);
4571 void Aura::HandlePeriodicDamagePCT(bool apply, bool /*Real*/)
4573 m_isPeriodic = apply;
4576 void Aura::HandlePeriodicLeech(bool apply, bool /*Real*/)
4578 m_isPeriodic = apply;
4581 void Aura::HandlePeriodicManaLeech(bool apply, bool /*Real*/)
4583 m_isPeriodic = apply;
4586 void Aura::HandlePeriodicHealthFunnel(bool apply, bool /*Real*/)
4588 m_isPeriodic = apply;
4591 /*********************************************************/
4592 /*** MODIFY STATS ***/
4593 /*********************************************************/
4595 /********************************/
4596 /*** RESISTANCE ***/
4597 /********************************/
4599 void Aura::HandleAuraModResistanceExclusive(bool apply, bool /*Real*/)
4601 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4603 if(m_modifier.m_miscvalue & int32(1<<x))
4605 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(m_modifier.m_amount), apply);
4606 if(m_target->GetTypeId() == TYPEID_PLAYER)
4607 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4612 void Aura::HandleAuraModResistance(bool apply, bool /*Real*/)
4614 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4616 if(m_modifier.m_miscvalue & int32(1<<x))
4618 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4619 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4620 m_target->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, m_modifier.m_amount, apply);
4625 void Aura::HandleAuraModBaseResistancePCT(bool apply, bool /*Real*/)
4627 // only players have base stats
4628 if(m_target->GetTypeId() != TYPEID_PLAYER)
4630 //pets only have base armor
4631 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4632 m_target->HandleStatModifier(UNIT_MOD_ARMOR, BASE_PCT, float(m_modifier.m_amount), apply);
4634 else
4636 for(int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL;x++)
4638 if(m_modifier.m_miscvalue & int32(1<<x))
4639 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply);
4644 void Aura::HandleModResistancePercent(bool apply, bool /*Real*/)
4646 for(int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4648 if(m_modifier.m_miscvalue & int32(1<<i))
4650 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4651 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4653 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, m_modifier.m_amount, apply);
4654 m_target->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, m_modifier.m_amount, apply);
4660 void Aura::HandleModBaseResistance(bool apply, bool /*Real*/)
4662 // only players have base stats
4663 if(m_target->GetTypeId() != TYPEID_PLAYER)
4665 //only pets have base stats
4666 if(((Creature*)m_target)->isPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
4667 m_target->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4669 else
4671 for(int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++)
4672 if(m_modifier.m_miscvalue & (1<<i))
4673 m_target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4677 /********************************/
4678 /*** STAT ***/
4679 /********************************/
4681 void Aura::HandleAuraModStat(bool apply, bool /*Real*/)
4683 if (m_modifier.m_miscvalue < -2 || m_modifier.m_miscvalue > 4)
4685 sLog.outError("WARNING: Spell %u effect %u have unsupported misc value (%i) for SPELL_AURA_MOD_STAT ",GetId(),GetEffIndex(),m_modifier.m_miscvalue);
4686 return;
4689 for(int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4691 // -1 or -2 is all stats ( misc < -2 checked in function beginning )
4692 if (m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue == i)
4694 //m_target->ApplyStatMod(Stats(i), m_modifier.m_amount,apply);
4695 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply);
4696 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4697 m_target->ApplyStatBuffMod(Stats(i), m_modifier.m_amount, apply);
4702 void Aura::HandleModPercentStat(bool apply, bool /*Real*/)
4704 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4706 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4707 return;
4710 // only players have base stats
4711 if (m_target->GetTypeId() != TYPEID_PLAYER)
4712 return;
4714 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
4716 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4717 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), BASE_PCT, float(m_modifier.m_amount), apply);
4721 void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool /*Real*/)
4723 if(m_target->GetTypeId() != TYPEID_PLAYER)
4724 return;
4726 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4727 // This information for client side use only
4728 // Recalculate bonus
4729 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4732 void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool /*Real*/)
4734 if(m_target->GetTypeId() != TYPEID_PLAYER)
4735 return;
4737 // Recalculate bonus
4738 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4741 void Aura::HandleAuraModDispelResist(bool apply, bool Real)
4743 if(!Real || !apply)
4744 return;
4746 if(GetId() == 33206)
4747 m_target->CastSpell(m_target, 44416, true, NULL, this, GetCasterGUID());
4750 void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4752 if(m_target->GetTypeId() != TYPEID_PLAYER)
4753 return;
4755 // Magic damage modifiers implemented in Unit::SpellDamageBonus
4756 // This information for client side use only
4757 // Recalculate bonus
4758 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4761 void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool /*Real*/)
4763 if(m_target->GetTypeId() != TYPEID_PLAYER)
4764 return;
4766 // Recalculate bonus
4767 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4770 void Aura::HandleModHealingDone(bool /*apply*/, bool /*Real*/)
4772 if(m_target->GetTypeId() != TYPEID_PLAYER)
4773 return;
4774 // implemented in Unit::SpellHealingBonus
4775 // this information is for client side only
4776 ((Player*)m_target)->UpdateSpellDamageAndHealingBonus();
4779 void Aura::HandleModTotalPercentStat(bool apply, bool /*Real*/)
4781 if (m_modifier.m_miscvalue < -1 || m_modifier.m_miscvalue > 4)
4783 sLog.outError("WARNING: Misc Value for SPELL_AURA_MOD_PERCENT_STAT not valid");
4784 return;
4787 //save current and max HP before applying aura
4788 uint32 curHPValue = m_target->GetHealth();
4789 uint32 maxHPValue = m_target->GetMaxHealth();
4791 for (int32 i = STAT_STRENGTH; i < MAX_STATS; i++)
4793 if(m_modifier.m_miscvalue == i || m_modifier.m_miscvalue == -1)
4795 m_target->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply);
4796 if(m_target->GetTypeId() == TYPEID_PLAYER || ((Creature*)m_target)->isPet())
4797 m_target->ApplyStatPercentBuffMod(Stats(i), m_modifier.m_amount, apply );
4801 //recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
4802 if ((m_modifier.m_miscvalue == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
4804 // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
4805 uint32 newHPValue = (m_target->GetMaxHealth() * curHPValue) / maxHPValue;
4806 m_target->SetHealth(newHPValue);
4810 void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool /*Real*/)
4812 if(m_target->GetTypeId() != TYPEID_PLAYER)
4813 return;
4815 if(m_modifier.m_miscvalue != SPELL_SCHOOL_MASK_NORMAL)
4817 // support required adding replace UpdateArmor by loop by UpdateResistence at intellect update
4818 // and include in UpdateResistence same code as in UpdateArmor for aura mod apply.
4819 sLog.outError("Aura SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT(182) need adding support for non-armor resistances!");
4820 return;
4823 // Recalculate Armor
4824 m_target->UpdateArmor();
4827 /********************************/
4828 /*** HEAL & ENERGIZE ***/
4829 /********************************/
4830 void Aura::HandleAuraModTotalHealthPercentRegen(bool apply, bool /*Real*/)
4832 m_isPeriodic = apply;
4835 void Aura::HandleAuraModTotalManaPercentRegen(bool apply, bool /*Real*/)
4837 if(m_modifier.periodictime == 0)
4838 m_modifier.periodictime = 1000;
4840 m_periodicTimer = m_modifier.periodictime;
4841 m_isPeriodic = apply;
4844 void Aura::HandleModRegen(bool apply, bool /*Real*/) // eating
4846 if(m_modifier.periodictime == 0)
4847 m_modifier.periodictime = 5000;
4849 m_periodicTimer = 5000;
4850 m_isPeriodic = apply;
4853 void Aura::HandleModPowerRegen(bool apply, bool Real) // drinking
4855 if (!Real)
4856 return;
4858 Powers pt = m_target->getPowerType();
4859 if(m_modifier.periodictime == 0)
4861 // Anger Management (only spell use this aura for rage)
4862 if (pt == POWER_RAGE)
4863 m_modifier.periodictime = 3000;
4864 else
4865 m_modifier.periodictime = 2000;
4868 m_periodicTimer = 5000;
4870 if (m_target->GetTypeId() == TYPEID_PLAYER && m_modifier.m_miscvalue == POWER_MANA)
4871 ((Player*)m_target)->UpdateManaRegen();
4873 m_isPeriodic = apply;
4876 void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real)
4878 // spells required only Real aura add/remove
4879 if(!Real)
4880 return;
4882 if (m_target->GetTypeId() != TYPEID_PLAYER)
4883 return;
4885 // Update manaregen value
4886 if (m_modifier.m_miscvalue == POWER_MANA)
4887 ((Player*)m_target)->UpdateManaRegen();
4890 void Aura::HandleModManaRegen(bool /*apply*/, bool Real)
4892 // spells required only Real aura add/remove
4893 if(!Real)
4894 return;
4896 if (m_target->GetTypeId() != TYPEID_PLAYER)
4897 return;
4899 //Note: an increase in regen does NOT cause threat.
4900 ((Player*)m_target)->UpdateManaRegen();
4903 void Aura::HandleComprehendLanguage(bool apply, bool /*Real*/)
4905 if(apply)
4906 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4907 else
4908 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_COMPREHEND_LANG);
4911 void Aura::HandleAuraModIncreaseHealth(bool apply, bool Real)
4913 // Special case with temporary increase max/current health
4914 switch(GetId())
4916 case 12976: // Warrior Last Stand triggered spell
4917 case 28726: // Nightmare Seed ( Nightmare Seed )
4918 case 34511: // Valor (Bulwark of Kings, Bulwark of the Ancient Kings)
4919 case 44055: // Tremendous Fortitude (Battlemaster's Alacrity)
4920 case 50322: // Survival Instincts
4921 case 54443: // Demonic Empowerment (Voidwalker)
4923 if(Real)
4925 if(apply)
4927 // Demonic Empowerment (Voidwalker) - special case, store percent in data
4928 // recalculate to full amount at apply for proper remove
4929 if (GetId() == 54443)
4930 m_modifier.m_amount = m_target->GetMaxHealth() * m_modifier.m_amount / 100;
4932 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4933 m_target->ModifyHealth(m_modifier.m_amount);
4935 else
4937 if (int32(m_target->GetHealth()) > m_modifier.m_amount)
4938 m_target->ModifyHealth(-m_modifier.m_amount);
4939 else
4940 m_target->SetHealth(1);
4941 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4944 return;
4948 // generic case
4949 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4952 void Aura::HandleAuraModIncreaseMaxHealth(bool apply, bool /*Real*/)
4954 uint32 oldhealth = m_target->GetHealth();
4955 double healthPercentage = (double)oldhealth / (double)m_target->GetMaxHealth();
4957 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4959 // refresh percentage
4960 if(oldhealth > 0)
4962 uint32 newhealth = uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage));
4963 if(newhealth==0)
4964 newhealth = 1;
4966 m_target->SetHealth(newhealth);
4970 void Aura::HandleAuraModIncreaseEnergy(bool apply, bool Real)
4972 Powers powerType = m_target->getPowerType();
4973 if(int32(powerType) != m_modifier.m_miscvalue)
4974 return;
4976 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
4978 // Special case with temporary increase max/current power (percent)
4979 if (GetId()==64904) // Hymn of Hope
4981 if(Real)
4983 uint32 val = m_target->GetPower(powerType);
4984 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
4985 m_target->SetPower(powerType, apply ? val*(100+m_modifier.m_amount)/100 : val*100/(100+m_modifier.m_amount));
4987 return;
4990 // generic flat case
4991 m_target->HandleStatModifier(unitMod, TOTAL_VALUE, float(m_modifier.m_amount), apply);
4994 void Aura::HandleAuraModIncreaseEnergyPercent(bool apply, bool /*Real*/)
4996 Powers powerType = m_target->getPowerType();
4997 if(int32(powerType) != m_modifier.m_miscvalue)
4998 return;
5000 UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + powerType);
5002 m_target->HandleStatModifier(unitMod, TOTAL_PCT, float(m_modifier.m_amount), apply);
5005 void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool /*Real*/)
5007 m_target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(m_modifier.m_amount), apply);
5010 void Aura::HandleAuraIncreaseBaseHealthPercent(bool apply, bool /*Real*/)
5012 m_target->HandleStatModifier(UNIT_MOD_HEALTH, BASE_PCT, float(m_modifier.m_amount), apply);
5015 /********************************/
5016 /*** FIGHT ***/
5017 /********************************/
5019 void Aura::HandleAuraModParryPercent(bool /*apply*/, bool /*Real*/)
5021 if(m_target->GetTypeId() != TYPEID_PLAYER)
5022 return;
5024 ((Player*)m_target)->UpdateParryPercentage();
5027 void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool /*Real*/)
5029 if(m_target->GetTypeId() != TYPEID_PLAYER)
5030 return;
5032 ((Player*)m_target)->UpdateDodgePercentage();
5033 //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount));
5036 void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool /*Real*/)
5038 if(m_target->GetTypeId() != TYPEID_PLAYER)
5039 return;
5041 ((Player*)m_target)->UpdateBlockPercentage();
5042 //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount));
5045 void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real)
5047 // spells required only Real aura add/remove
5048 if(!Real)
5049 return;
5051 if(m_target->GetTypeId() != TYPEID_PLAYER)
5052 return;
5054 ((Player*)m_target)->UpdateManaRegen();
5057 void Aura::HandleAuraModCritPercent(bool apply, bool Real)
5059 if(m_target->GetTypeId() != TYPEID_PLAYER)
5060 return;
5062 // apply item specific bonuses for already equipped weapon
5063 if(Real)
5065 for(int i = 0; i < MAX_ATTACK; ++i)
5066 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5067 ((Player*)m_target)->_ApplyWeaponDependentAuraCritMod(pItem, WeaponAttackType(i), this, apply);
5070 // mods must be applied base at equipped weapon class and subclass comparison
5071 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5072 // m_modifier.m_miscvalue comparison with item generated damage types
5074 if (GetSpellProto()->EquippedItemClass == -1)
5076 ((Player*)m_target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5077 ((Player*)m_target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5078 ((Player*)m_target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (m_modifier.m_amount), apply);
5080 else
5082 // done in Player::_ApplyWeaponDependentAuraMods
5086 void Aura::HandleModHitChance(bool apply, bool /*Real*/)
5088 if(m_target->GetTypeId() == TYPEID_PLAYER)
5090 ((Player*)m_target)->UpdateMeleeHitChances();
5091 ((Player*)m_target)->UpdateRangedHitChances();
5093 else
5095 m_target->m_modMeleeHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5096 m_target->m_modRangedHitChance += apply ? m_modifier.m_amount : (-m_modifier.m_amount);
5100 void Aura::HandleModSpellHitChance(bool apply, bool /*Real*/)
5102 if(m_target->GetTypeId() == TYPEID_PLAYER)
5104 ((Player*)m_target)->UpdateSpellHitChances();
5106 else
5108 m_target->m_modSpellHitChance += apply ? m_modifier.m_amount: (-m_modifier.m_amount);
5112 void Aura::HandleModSpellCritChance(bool apply, bool Real)
5114 // spells required only Real aura add/remove
5115 if(!Real)
5116 return;
5118 if(m_target->GetTypeId() == TYPEID_PLAYER)
5120 ((Player*)m_target)->UpdateAllSpellCritChances();
5122 else
5124 m_target->m_baseSpellCritChance += apply ? m_modifier.m_amount:(-m_modifier.m_amount);
5128 void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real)
5130 // spells required only Real aura add/remove
5131 if(!Real)
5132 return;
5134 if(m_target->GetTypeId() != TYPEID_PLAYER)
5135 return;
5137 for(int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school)
5138 if (m_modifier.m_miscvalue & (1<<school))
5139 ((Player*)m_target)->UpdateSpellCritChance(school);
5142 /********************************/
5143 /*** ATTACK SPEED ***/
5144 /********************************/
5146 void Aura::HandleModCastingSpeed(bool apply, bool /*Real*/)
5148 m_target->ApplyCastTimePercentMod(m_modifier.m_amount,apply);
5151 void Aura::HandleModMeleeRangedSpeedPct(bool apply, bool /*Real*/)
5153 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5154 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5155 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5158 void Aura::HandleModCombatSpeedPct(bool apply, bool /*Real*/)
5160 m_target->ApplyCastTimePercentMod(m_modifier.m_amount, apply);
5161 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5162 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5163 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5166 void Aura::HandleModAttackSpeed(bool apply, bool /*Real*/)
5168 if(!m_target->isAlive() )
5169 return;
5171 m_target->ApplyAttackTimePercentMod(BASE_ATTACK,m_modifier.m_amount,apply);
5174 void Aura::HandleHaste(bool apply, bool /*Real*/)
5176 m_target->ApplyAttackTimePercentMod(BASE_ATTACK, m_modifier.m_amount, apply);
5177 m_target->ApplyAttackTimePercentMod(OFF_ATTACK, m_modifier.m_amount, apply);
5178 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5181 void Aura::HandleAuraModRangedHaste(bool apply, bool /*Real*/)
5183 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK, m_modifier.m_amount, apply);
5186 void Aura::HandleRangedAmmoHaste(bool apply, bool /*Real*/)
5188 if(m_target->GetTypeId() != TYPEID_PLAYER)
5189 return;
5190 m_target->ApplyAttackTimePercentMod(RANGED_ATTACK,m_modifier.m_amount, apply);
5193 /********************************/
5194 /*** ATTACK POWER ***/
5195 /********************************/
5197 void Aura::HandleAuraModAttackPower(bool apply, bool /*Real*/)
5199 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5202 void Aura::HandleAuraModRangedAttackPower(bool apply, bool /*Real*/)
5204 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5205 return;
5207 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5210 void Aura::HandleAuraModAttackPowerPercent(bool apply, bool /*Real*/)
5212 //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1
5213 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER, TOTAL_PCT, float(m_modifier.m_amount), apply);
5216 void Aura::HandleAuraModRangedAttackPowerPercent(bool apply, bool /*Real*/)
5218 if((m_target->getClassMask() & CLASSMASK_WAND_USERS)!=0)
5219 return;
5221 //UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER = multiplier - 1
5222 m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5225 void Aura::HandleAuraModRangedAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5227 // spells required only Real aura add/remove
5228 if(!Real)
5229 return;
5231 // Recalculate bonus
5232 if(m_target->GetTypeId() == TYPEID_PLAYER && !(m_target->getClassMask() & CLASSMASK_WAND_USERS))
5233 ((Player*)m_target)->UpdateAttackPowerAndDamage(true);
5236 void Aura::HandleAuraModAttackPowerOfStatPercent(bool /*apply*/, bool Real)
5238 // spells required only Real aura add/remove
5239 if(!Real)
5240 return;
5242 // Recalculate bonus
5243 if(m_target->GetTypeId() == TYPEID_PLAYER)
5244 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5247 void Aura::HandleAuraModAttackPowerOfArmor(bool /*apply*/, bool Real)
5249 // spells required only Real aura add/remove
5250 if(!Real)
5251 return;
5253 // Recalculate bonus
5254 if(m_target->GetTypeId() == TYPEID_PLAYER)
5255 ((Player*)m_target)->UpdateAttackPowerAndDamage(false);
5257 /********************************/
5258 /*** DAMAGE BONUS ***/
5259 /********************************/
5260 void Aura::HandleModDamageDone(bool apply, bool Real)
5262 // apply item specific bonuses for already equipped weapon
5263 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5265 for(int i = 0; i < MAX_ATTACK; ++i)
5266 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5267 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5270 // m_modifier.m_miscvalue is bitmask of spell schools
5271 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5272 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wands
5273 // 127 - full bitmask any damages
5275 // mods must be applied base at equipped weapon class and subclass comparison
5276 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5277 // m_modifier.m_miscvalue comparison with item generated damage types
5279 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5281 // apply generic physical damage bonuses including wand case
5282 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5284 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5285 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5286 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply);
5288 else
5290 // done in Player::_ApplyWeaponDependentAuraMods
5293 if(m_target->GetTypeId() == TYPEID_PLAYER)
5295 if(m_positive)
5296 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS, m_modifier.m_amount, apply);
5297 else
5298 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG, m_modifier.m_amount, apply);
5302 // Skip non magic case for speedup
5303 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5304 return;
5306 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5308 // wand magic case (skip generic to all item spell bonuses)
5309 // done in Player::_ApplyWeaponDependentAuraMods
5311 // Skip item specific requirements for not wand magic damage
5312 return;
5315 // Magic damage modifiers implemented in Unit::SpellDamageBonus
5316 // This information for client side use only
5317 if(m_target->GetTypeId() == TYPEID_PLAYER)
5319 if(m_positive)
5321 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5323 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5324 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, m_modifier.m_amount, apply);
5327 else
5329 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5331 if((m_modifier.m_miscvalue & (1<<i)) != 0)
5332 m_target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, m_modifier.m_amount, apply);
5335 Pet* pet = m_target->GetPet();
5336 if(pet)
5337 pet->UpdateAttackPowerAndDamage();
5341 void Aura::HandleModDamagePercentDone(bool apply, bool Real)
5343 sLog.outDebug("AURA MOD DAMAGE type:%u negative:%u", m_modifier.m_miscvalue, m_positive ? 0 : 1);
5345 // apply item specific bonuses for already equipped weapon
5346 if(Real && m_target->GetTypeId() == TYPEID_PLAYER)
5348 for(int i = 0; i < MAX_ATTACK; ++i)
5349 if(Item* pItem = ((Player*)m_target)->GetWeaponForAttack(WeaponAttackType(i)))
5350 ((Player*)m_target)->_ApplyWeaponDependentAuraDamageMod(pItem, WeaponAttackType(i), this, apply);
5353 // m_modifier.m_miscvalue is bitmask of spell schools
5354 // 1 ( 0-bit ) - normal school damage (SPELL_SCHOOL_MASK_NORMAL)
5355 // 126 - full bitmask all magic damages (SPELL_SCHOOL_MASK_MAGIC) including wand
5356 // 127 - full bitmask any damages
5358 // mods must be applied base at equipped weapon class and subclass comparison
5359 // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask
5360 // m_modifier.m_miscvalue comparison with item generated damage types
5362 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) != 0)
5364 // apply generic physical damage bonuses including wand case
5365 if (GetSpellProto()->EquippedItemClass == -1 || m_target->GetTypeId() != TYPEID_PLAYER)
5367 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5368 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5369 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_RANGED, TOTAL_PCT, float(m_modifier.m_amount), apply);
5371 else
5373 // done in Player::_ApplyWeaponDependentAuraMods
5375 // For show in client
5376 if(m_target->GetTypeId() == TYPEID_PLAYER)
5377 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT, m_modifier.m_amount/100.0f, apply);
5380 // Skip non magic case for speedup
5381 if((m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_MAGIC) == 0)
5382 return;
5384 if( GetSpellProto()->EquippedItemClass != -1 || GetSpellProto()->EquippedItemInventoryTypeMask != 0 )
5386 // wand magic case (skip generic to all item spell bonuses)
5387 // done in Player::_ApplyWeaponDependentAuraMods
5389 // Skip item specific requirements for not wand magic damage
5390 return;
5393 // Magic damage percent modifiers implemented in Unit::SpellDamageBonus
5394 // Send info to client
5395 if(m_target->GetTypeId() == TYPEID_PLAYER)
5396 for(int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
5397 m_target->ApplyModSignedFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT + i, m_modifier.m_amount/100.0f, apply);
5400 void Aura::HandleModOffhandDamagePercent(bool apply, bool Real)
5402 // spells required only Real aura add/remove
5403 if(!Real)
5404 return;
5406 sLog.outDebug("AURA MOD OFFHAND DAMAGE");
5408 m_target->HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND, TOTAL_PCT, float(m_modifier.m_amount), apply);
5411 /********************************/
5412 /*** POWER COST ***/
5413 /********************************/
5415 void Aura::HandleModPowerCostPCT(bool apply, bool Real)
5417 // spells required only Real aura add/remove
5418 if(!Real)
5419 return;
5421 float amount = m_modifier.m_amount/100.0f;
5422 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5423 if(m_modifier.m_miscvalue & (1<<i))
5424 m_target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + i, amount, apply);
5427 void Aura::HandleModPowerCost(bool apply, bool Real)
5429 // spells required only Real aura add/remove
5430 if(!Real)
5431 return;
5433 for(int i = 0; i < MAX_SPELL_SCHOOL; ++i)
5434 if(m_modifier.m_miscvalue & (1<<i))
5435 m_target->ApplyModInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + i, m_modifier.m_amount, apply);
5438 void Aura::HandleNoReagentUseAura(bool /*Apply*/, bool Real)
5440 // spells required only Real aura add/remove
5441 if(!Real)
5442 return;
5443 if(m_target->GetTypeId() != TYPEID_PLAYER)
5444 return;
5445 uint32 mask[3] = {0, 0, 0};
5446 Unit::AuraList const& noReagent = m_target->GetAurasByType(SPELL_AURA_NO_REAGENT_USE);
5447 for(Unit::AuraList::const_iterator i = noReagent.begin(); i != noReagent.end(); ++i)
5449 uint32 const *ptr = (*i)->getAuraSpellClassMask();
5450 mask[0] |= ptr[0];
5451 mask[1] |= ptr[1];
5452 mask[2] |= ptr[2];
5455 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+0, mask[0]);
5456 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+1, mask[1]);
5457 m_target->SetUInt32Value(PLAYER_NO_REAGENT_COST_1+2, mask[2]);
5460 /*********************************************************/
5461 /*** OTHERS ***/
5462 /*********************************************************/
5464 void Aura::HandleShapeshiftBoosts(bool apply)
5466 uint32 spellId1 = 0;
5467 uint32 spellId2 = 0;
5468 uint32 HotWSpellId = 0;
5469 uint32 MasterShaperSpellId = 0;
5471 uint32 form = GetModifier()->m_miscvalue;
5473 switch(form)
5475 case FORM_CAT:
5476 spellId1 = 3025;
5477 HotWSpellId = 24900;
5478 MasterShaperSpellId = 48420;
5479 break;
5480 case FORM_TREE:
5481 spellId1 = 5420;
5482 spellId2 = 34123;
5483 MasterShaperSpellId = 48422;
5484 break;
5485 case FORM_TRAVEL:
5486 spellId1 = 5419;
5487 break;
5488 case FORM_AQUA:
5489 spellId1 = 5421;
5490 break;
5491 case FORM_BEAR:
5492 spellId1 = 1178;
5493 spellId2 = 21178;
5494 HotWSpellId = 24899;
5495 MasterShaperSpellId = 48418;
5496 break;
5497 case FORM_DIREBEAR:
5498 spellId1 = 9635;
5499 spellId2 = 21178;
5500 HotWSpellId = 24899;
5501 MasterShaperSpellId = 48418;
5502 break;
5503 case FORM_BATTLESTANCE:
5504 spellId1 = 21156;
5505 break;
5506 case FORM_DEFENSIVESTANCE:
5507 spellId1 = 7376;
5508 break;
5509 case FORM_BERSERKERSTANCE:
5510 spellId1 = 7381;
5511 break;
5512 case FORM_MOONKIN:
5513 spellId1 = 24905;
5514 MasterShaperSpellId = 48421;
5515 break;
5516 case FORM_FLIGHT:
5517 spellId1 = 33948;
5518 spellId2 = 34764;
5519 break;
5520 case FORM_FLIGHT_EPIC:
5521 spellId1 = 40122;
5522 spellId2 = 40121;
5523 break;
5524 case FORM_METAMORPHOSIS:
5525 spellId1 = 54817;
5526 spellId2 = 54879;
5527 break;
5528 case FORM_SPIRITOFREDEMPTION:
5529 spellId1 = 27792;
5530 spellId2 = 27795; // must be second, this important at aura remove to prevent to early iterator invalidation.
5531 break;
5532 case FORM_SHADOW:
5533 spellId1 = 49868;
5535 if(m_target->GetTypeId() == TYPEID_PLAYER) // Spell 49868 have same category as main form spell and share cooldown
5536 ((Player*)m_target)->RemoveSpellCooldown(49868);
5537 break;
5538 case FORM_GHOSTWOLF:
5539 case FORM_AMBIENT:
5540 case FORM_GHOUL:
5541 case FORM_STEALTH:
5542 case FORM_CREATURECAT:
5543 case FORM_CREATUREBEAR:
5544 break;
5547 if(apply)
5549 if (spellId1)
5550 m_target->CastSpell(m_target, spellId1, true, NULL, this );
5551 if (spellId2)
5552 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5554 if (m_target->GetTypeId() == TYPEID_PLAYER)
5556 const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap();
5557 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
5559 if (itr->second->state == PLAYERSPELL_REMOVED) continue;
5560 if (itr->first==spellId1 || itr->first==spellId2) continue;
5561 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
5562 if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7))))
5563 continue;
5564 if (spellInfo->Stances & (1<<(form-1)))
5565 m_target->CastSpell(m_target, itr->first, true, NULL, this);
5568 // Master Shapeshifter
5569 if (MasterShaperSpellId)
5571 Unit::AuraList const& ShapeShifterAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5572 for(Unit::AuraList::const_iterator i = ShapeShifterAuras.begin(); i != ShapeShifterAuras.end(); i++)
5574 if ((*i)->GetSpellProto()->SpellIconID == 2851)
5576 int32 ShiftMod = (*i)->GetModifier()->m_amount;
5577 m_target->CastCustomSpell(m_target, MasterShaperSpellId, &ShiftMod, NULL, NULL, true);
5578 break;
5583 // Leader of the Pack
5584 if (((Player*)m_target)->HasSpell(17007))
5586 SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932);
5587 if (spellInfo && spellInfo->Stances & (1<<(form-1)))
5588 m_target->CastSpell(m_target, 24932, true, NULL, this);
5591 // Savage Roar
5592 if (form == FORM_CAT && ((Player*)m_target)->HasAura(52610))
5593 m_target->CastSpell(m_target, 62071, true);
5595 // Improved Moonkin Form
5596 if (form == FORM_MOONKIN)
5598 Unit::AuraList const& dummyAuras = m_target->GetAurasByType(SPELL_AURA_DUMMY);
5599 for(Unit::AuraList::const_iterator i = dummyAuras.begin(); i != dummyAuras.end(); i++)
5601 if ((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_DRUID &&
5602 (*i)->GetSpellProto()->SpellIconID == 2855)
5604 uint32 spell_id = 0;
5605 switch((*i)->GetId())
5607 case 48384:spell_id=50170;break;//Rank 1
5608 case 48395:spell_id=50171;break;//Rank 2
5609 case 48396:spell_id=50172;break;//Rank 3
5610 default:
5611 sLog.outError("Aura::HandleShapeshiftBoosts: Not handled rank of IMF (Spell: %u)",(*i)->GetId());
5612 break;
5615 if(spell_id)
5616 m_target->CastSpell(m_target, spell_id, true, NULL, this);
5617 break;
5622 // Heart of the Wild
5623 if (HotWSpellId)
5625 Unit::AuraList const& mModTotalStatPct = m_target->GetAurasByType(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE);
5626 for(Unit::AuraList::const_iterator i = mModTotalStatPct.begin(); i != mModTotalStatPct.end(); ++i)
5628 if ((*i)->GetSpellProto()->SpellIconID == 240 && (*i)->GetModifier()->m_miscvalue == 3)
5630 int32 HotWMod = (*i)->GetModifier()->m_amount;
5631 if(GetModifier()->m_miscvalue == FORM_CAT)
5632 HotWMod /= 2;
5634 m_target->CastCustomSpell(m_target, HotWSpellId, &HotWMod, NULL, NULL, true, NULL, this);
5635 break;
5641 else
5643 if(spellId1)
5644 m_target->RemoveAurasDueToSpell(spellId1);
5645 if(spellId2)
5646 m_target->RemoveAurasDueToSpell(spellId2);
5647 if(MasterShaperSpellId)
5648 m_target->RemoveAurasDueToSpell(MasterShaperSpellId);
5650 Unit::AuraMap& tAuras = m_target->GetAuras();
5651 for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();)
5653 if (itr->second->IsRemovedOnShapeLost())
5655 m_target->RemoveAurasDueToSpell(itr->second->GetId());
5656 itr = tAuras.begin();
5658 else
5659 ++itr;
5664 void Aura::HandleSpellSpecificBoosts(bool apply)
5666 uint32 spellId1 = 0;
5667 uint32 spellId2 = 0;
5668 uint32 spellId3 = 0;
5669 uint32 spellId4 = 0;
5671 switch(GetSpellProto()->SpellFamilyName)
5673 case SPELLFAMILY_WARRIOR:
5675 if(!apply)
5677 // Remove Blood Frenzy only if target no longer has any Deep Wound or Rend (applying is handled by procs)
5678 if (GetSpellProto()->Mechanic != MECHANIC_BLEED)
5679 return;
5681 // If target still has one of Warrior's bleeds, do nothing
5682 Unit::AuraList const& PeriodicDamage = m_target->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
5683 for(Unit::AuraList::const_iterator i = PeriodicDamage.begin(); i != PeriodicDamage.end(); ++i)
5684 if( (*i)->GetCasterGUID() == GetCasterGUID() &&
5685 (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARRIOR &&
5686 (*i)->GetSpellProto()->Mechanic == MECHANIC_BLEED)
5687 return;
5689 spellId1 = 30069;
5690 spellId2 = 30070;
5692 break;
5694 case SPELLFAMILY_ROGUE:
5695 // Sprint (skip non player casted spells by category)
5696 if (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000040) && GetSpellProto()->Category == 44)
5698 if(!apply || m_target->HasAura(58039)) // Glyph of Blurred Speed
5699 spellId1 = 61922; // Sprint (waterwalk)
5700 else
5701 return;
5703 else
5704 return;
5705 break;
5706 case SPELLFAMILY_HUNTER:
5708 // The Beast Within and Bestial Wrath - immunity
5709 if (GetId() == 19574 || GetId() == 34471)
5711 spellId1 = 24395;
5712 spellId2 = 24396;
5713 spellId3 = 24397;
5714 spellId4 = 26592;
5716 // Aspect of the Dragonhawk dodge
5717 else if (GetSpellProto()->SpellFamilyFlags2 & 0x00001000)
5719 spellId1 = 61848;
5721 // triggered spell have same category as main spell and cooldown
5722 if (apply && m_target->GetTypeId()==TYPEID_PLAYER)
5723 ((Player*)m_target)->RemoveSpellCooldown(61848);
5725 else
5726 return;
5727 break;
5729 case SPELLFAMILY_PALADIN:
5731 // Only process on player casting paladin aura
5732 // all aura bonuses applied also in aura area effect way to caster
5733 if (GetCasterGUID() != m_target->GetGUID() || !IS_PLAYER_GUID(GetCasterGUID()))
5734 return;
5736 if (GetSpellSpecific(m_spellProto->Id) != SPELL_AURA)
5737 return;
5739 // Sanctified Retribution and Swift Retribution (they share one aura), but not Retribution Aura (already gets modded)
5740 if ((GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000008))==0)
5741 spellId1 = 63531; // placeholder for talent spell mods
5742 // Improved Concentration Aura (auras bonus)
5743 spellId2 = 63510; // placeholder for talent spell mods
5744 // Improved Devotion Aura (auras bonus)
5745 spellId3 = 63514; // placeholder for talent spell mods
5746 break;
5748 case SPELLFAMILY_DEATHKNIGHT:
5750 if (GetSpellSpecific(m_spellProto->Id) != SPELL_PRESENCE)
5751 return;
5753 // Frost Presence health
5754 if (GetId() == 48263)
5755 spellId1 = 61261;
5756 // Unholy Presence move speed
5757 else if (GetId() == 48265)
5758 spellId1 = 49772;
5759 else
5760 return;
5762 break;
5764 default:
5765 return;
5768 // prevent aura deletion, specially in multi-boost case
5769 SetInUse(true);
5771 if (apply)
5773 if (spellId1)
5774 m_target->CastSpell(m_target, spellId1, true, NULL, this);
5775 if (spellId2 && !IsDeleted())
5776 m_target->CastSpell(m_target, spellId2, true, NULL, this);
5777 if (spellId3 && !IsDeleted())
5778 m_target->CastSpell(m_target, spellId3, true, NULL, this);
5779 if (spellId4 && !IsDeleted())
5780 m_target->CastSpell(m_target, spellId4, true, NULL, this);
5782 else
5784 if (spellId1)
5785 m_target->RemoveAurasByCasterSpell(spellId1, GetCasterGUID());
5786 if (spellId2)
5787 m_target->RemoveAurasByCasterSpell(spellId2, GetCasterGUID());
5788 if (spellId3)
5789 m_target->RemoveAurasByCasterSpell(spellId3, GetCasterGUID());
5790 if (spellId4)
5791 m_target->RemoveAurasByCasterSpell(spellId4, GetCasterGUID());
5794 SetInUse(false);
5797 void Aura::HandleAuraEmpathy(bool apply, bool /*Real*/)
5799 if(m_target->GetTypeId() != TYPEID_UNIT)
5800 return;
5802 CreatureInfo const * ci = objmgr.GetCreatureTemplate(m_target->GetEntry());
5803 if(ci && ci->type == CREATURE_TYPE_BEAST)
5804 m_target->ApplyModUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_SPECIALINFO, apply);
5807 void Aura::HandleAuraUntrackable(bool apply, bool /*Real*/)
5809 if(apply)
5810 m_target->SetByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5811 else
5812 m_target->RemoveByteFlag(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_UNTRACKABLE);
5815 void Aura::HandleAuraModPacify(bool apply, bool /*Real*/)
5817 if(m_target->GetTypeId() != TYPEID_PLAYER)
5818 return;
5820 if(apply)
5821 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5822 else
5823 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED);
5826 void Aura::HandleAuraModPacifyAndSilence(bool apply, bool Real)
5828 HandleAuraModPacify(apply, Real);
5829 HandleAuraModSilence(apply, Real);
5832 void Aura::HandleAuraGhost(bool apply, bool /*Real*/)
5834 if(m_target->GetTypeId() != TYPEID_PLAYER)
5835 return;
5837 if(apply)
5839 m_target->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5841 else
5843 m_target->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST);
5847 void Aura::HandleAuraAllowFlight(bool apply, bool Real)
5849 // all applied/removed only at real aura add/remove
5850 if(!Real)
5851 return;
5853 // allow fly
5854 WorldPacket data;
5855 if(apply)
5856 data.Initialize(SMSG_MOVE_SET_CAN_FLY, 12);
5857 else
5858 data.Initialize(SMSG_MOVE_UNSET_CAN_FLY, 12);
5859 data.append(m_target->GetPackGUID());
5860 data << uint32(0); // unk
5861 m_target->SendMessageToSet(&data, true);
5864 void Aura::HandleModRating(bool apply, bool Real)
5866 // spells required only Real aura add/remove
5867 if(!Real)
5868 return;
5870 if(m_target->GetTypeId() != TYPEID_PLAYER)
5871 return;
5873 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5874 if (m_modifier.m_miscvalue & (1 << rating))
5875 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), m_modifier.m_amount, apply);
5878 void Aura::HandleModRatingFromStat(bool apply, bool Real)
5880 // spells required only Real aura add/remove
5881 if(!Real)
5882 return;
5884 if(m_target->GetTypeId() != TYPEID_PLAYER)
5885 return;
5886 // Just recalculate ratings
5887 for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating)
5888 if (m_modifier.m_miscvalue & (1 << rating))
5889 ((Player*)m_target)->ApplyRatingMod(CombatRating(rating), 0, apply);
5892 void Aura::HandleForceMoveForward(bool apply, bool Real)
5894 if(!Real || m_target->GetTypeId() != TYPEID_PLAYER)
5895 return;
5896 if(apply)
5897 m_target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5898 else
5899 m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE);
5902 void Aura::HandleAuraModExpertise(bool /*apply*/, bool /*Real*/)
5904 if(m_target->GetTypeId() != TYPEID_PLAYER)
5905 return;
5907 ((Player*)m_target)->UpdateExpertise(BASE_ATTACK);
5908 ((Player*)m_target)->UpdateExpertise(OFF_ATTACK);
5911 void Aura::HandleModTargetResistance(bool apply, bool Real)
5913 // spells required only Real aura add/remove
5914 if(!Real)
5915 return;
5916 // applied to damage as HandleNoImmediateEffect in Unit::CalcAbsorbResist and Unit::CalcArmorReducedDamage
5918 // show armor penetration
5919 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL))
5920 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE, m_modifier.m_amount, apply);
5922 // show as spell penetration only full spell penetration bonuses (all resistances except armor and holy
5923 if (m_target->GetTypeId() == TYPEID_PLAYER && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_SPELL)==SPELL_SCHOOL_MASK_SPELL)
5924 m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE, m_modifier.m_amount, apply);
5927 void Aura::HandleShieldBlockValue(bool apply, bool /*Real*/)
5929 BaseModType modType = FLAT_MOD;
5930 if(m_modifier.m_auraname == SPELL_AURA_MOD_SHIELD_BLOCKVALUE_PCT)
5931 modType = PCT_MOD;
5933 if(m_target->GetTypeId() == TYPEID_PLAYER)
5934 ((Player*)m_target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(m_modifier.m_amount), apply);
5937 void Aura::HandleAuraRetainComboPoints(bool apply, bool Real)
5939 // spells required only Real aura add/remove
5940 if(!Real)
5941 return;
5943 if(m_target->GetTypeId() != TYPEID_PLAYER)
5944 return;
5946 Player *target = (Player*)m_target;
5948 // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler
5949 // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost)
5950 if( !apply && m_duration==0 && target->GetComboTarget())
5951 if(Unit* unit = ObjectAccessor::GetUnit(*m_target,target->GetComboTarget()))
5952 target->AddComboPoints(unit, -m_modifier.m_amount);
5955 void Aura::HandleModUnattackable( bool Apply, bool Real )
5957 if(Real && Apply)
5959 m_target->CombatStop();
5960 m_target->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION);
5962 m_target->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE,Apply);
5965 void Aura::HandleSpiritOfRedemption( bool apply, bool Real )
5967 // spells required only Real aura add/remove
5968 if(!Real)
5969 return;
5971 // prepare spirit state
5972 if(apply)
5974 if(m_target->GetTypeId()==TYPEID_PLAYER)
5976 // disable breath/etc timers
5977 ((Player*)m_target)->StopMirrorTimers();
5979 // set stand state (expected in this form)
5980 if(!m_target->IsStandState())
5981 m_target->SetStandState(UNIT_STAND_STATE_STAND);
5984 m_target->SetHealth(1);
5986 // die at aura end
5987 else
5988 m_target->DealDamage(m_target, m_target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, GetSpellProto(), false);
5991 void Aura::CleanupTriggeredSpells()
5993 uint32 tSpellId = m_spellProto->EffectTriggerSpell[GetEffIndex()];
5994 if(!tSpellId)
5995 return;
5997 SpellEntry const* tProto = sSpellStore.LookupEntry(tSpellId);
5998 if(!tProto)
5999 return;
6001 if(GetSpellDuration(tProto) != -1)
6002 return;
6004 // needed for spell 43680, maybe others
6005 // TODO: is there a spell flag, which can solve this in a more sophisticated way?
6006 if(m_spellProto->EffectApplyAuraName[GetEffIndex()] == SPELL_AURA_PERIODIC_TRIGGER_SPELL &&
6007 GetSpellDuration(m_spellProto) == m_spellProto->EffectAmplitude[GetEffIndex()])
6008 return;
6009 m_target->RemoveAurasDueToSpell(tSpellId);
6012 void Aura::HandleSchoolAbsorb(bool apply, bool Real)
6014 if(!Real)
6015 return;
6017 Unit* caster = GetCaster();
6018 if(!caster)
6019 return;
6021 if (apply)
6023 // prevent double apply bonuses
6024 if (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading())
6026 float DoneActualBenefit = 0.0f;
6027 switch(m_spellProto->SpellFamilyName)
6029 case SPELLFAMILY_PRIEST:
6030 // Power Word: Shield
6031 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001))
6032 //+80.68% from +spell bonus
6033 DoneActualBenefit = caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * 0.8068f;
6034 break;
6035 case SPELLFAMILY_MAGE:
6036 // Frost Ward, Fire Ward
6037 if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000108))
6038 //+10% from +spell bonus
6039 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.1f;
6040 // Ice Barrier
6041 else if (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000100000000))
6042 //+80.67% from +spell bonus
6043 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.8067f;
6044 break;
6045 case SPELLFAMILY_WARLOCK:
6046 // Shadow Ward
6047 if (m_spellProto->SpellFamilyFlags2 & 0x00000040)
6048 //+30% from +spell bonus
6049 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.30f;
6050 break;
6051 case SPELLFAMILY_DRUID:
6052 // Savage Defense (amount store original percent of attack power applied)
6053 if (m_spellProto->SpellIconID == 50) // only spell with this aura fit
6054 m_modifier.m_amount = int32(m_modifier.m_amount * m_target->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
6055 break;
6056 default:
6057 break;
6060 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
6062 m_modifier.m_amount += (int32)DoneActualBenefit;
6065 else
6067 // Ice Barrier (remove effect from Shattered Barrier)
6068 if (m_spellProto->SpellIconID == 32 && m_spellProto->SpellFamilyName == SPELLFAMILY_MAGE)
6070 if (!((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6071 return;
6073 if (m_target->HasAura(44745,0)) // Shattered Barrier, rank 1
6075 if(roll_chance_i(50))
6076 m_target->CastSpell(m_target, 55080, true, NULL, this);
6078 else if (m_target->HasAura(54787,0)) // Shattered Barrier, rank 2
6080 m_target->CastSpell(m_target, 55080, true, NULL, this);
6084 if (caster &&
6085 // Power Word: Shield
6086 m_spellProto->SpellFamilyName == SPELLFAMILY_PRIEST && m_spellProto->Mechanic == MECHANIC_SHIELD &&
6087 (m_spellProto->SpellFamilyFlags & UI64LIT(0x0000000000000001)) &&
6088 // completely absorbed or dispelled
6089 ((m_removeMode == AURA_REMOVE_BY_DEFAULT && !m_modifier.m_amount) || m_removeMode == AURA_REMOVE_BY_DISPEL))
6091 Unit::AuraList const& vDummyAuras = caster->GetAurasByType(SPELL_AURA_DUMMY);
6092 for(Unit::AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); itr++)
6094 SpellEntry const* vSpell = (*itr)->GetSpellProto();
6096 // Rapture (main spell)
6097 if(vSpell->SpellFamilyName == SPELLFAMILY_PRIEST && vSpell->SpellIconID == 2894 && vSpell->Effect[1])
6099 switch((*itr)->GetEffIndex())
6101 case 0:
6103 // energize caster
6104 int32 manapct1000 = 5 * ((*itr)->GetModifier()->m_amount + spellmgr.GetSpellRank(vSpell->Id));
6105 int32 basepoints0 = caster->GetMaxPower(POWER_MANA) * manapct1000 / 1000;
6106 caster->CastCustomSpell(caster, 47755, &basepoints0, NULL, NULL, true);
6107 break;
6109 case 1:
6111 // energize target
6112 if (!roll_chance_i((*itr)->GetModifier()->m_amount) || caster->HasAura(63853))
6113 break;
6115 switch(m_target->getPowerType())
6117 case POWER_RUNIC_POWER:
6118 m_target->CastSpell(m_target, 63652, true, NULL, NULL, m_caster_guid);
6119 break;
6120 case POWER_RAGE:
6121 m_target->CastSpell(m_target, 63653, true, NULL, NULL, m_caster_guid);
6122 break;
6123 case POWER_MANA:
6125 int32 basepoints0 = m_target->GetMaxPower(POWER_MANA) * 2 / 100;
6126 m_target->CastCustomSpell(m_target, 63654, &basepoints0, NULL, NULL, true);
6127 break;
6129 case POWER_ENERGY:
6130 m_target->CastSpell(m_target, 63655, true, NULL, NULL, m_caster_guid);
6131 break;
6132 default:
6133 break;
6136 //cooldwon aura
6137 caster->CastSpell(caster, 63853, true);
6138 break;
6140 default:
6141 sLog.outError("Changes in R-dummy spell???: effect 3");
6142 break;
6150 void Aura::PeriodicTick()
6152 if(!m_target->isAlive())
6153 return;
6155 switch(m_modifier.m_auraname)
6157 case SPELL_AURA_PERIODIC_DAMAGE:
6158 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
6160 Unit *pCaster = GetCaster();
6161 if(!pCaster)
6162 return;
6164 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6165 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6166 return;
6168 // Check for immune (not use charges)
6169 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6170 return;
6172 // some auras remove at specific health level or more
6173 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6175 switch(GetId())
6177 case 43093: case 31956: case 38801:
6178 case 35321: case 38363: case 39215:
6179 if(m_target->GetHealth() == m_target->GetMaxHealth() )
6181 m_target->RemoveAurasDueToSpell(GetId());
6182 return;
6184 break;
6185 case 38772:
6187 uint32 percent =
6188 GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_DUMMY ?
6189 pCaster->CalculateSpellDamage(GetSpellProto(), GetEffIndex() + 1, GetSpellProto()->EffectBasePoints[GetEffIndex() + 1], m_target) :
6190 100;
6191 if(m_target->GetHealth() * 100 >= m_target->GetMaxHealth() * percent )
6193 m_target->RemoveAurasDueToSpell(GetId());
6194 return;
6196 break;
6198 default:
6199 break;
6203 uint32 absorb = 0;
6204 uint32 resist = 0;
6205 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6207 // ignore non positive values (can be result apply spellmods to aura damage
6208 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6210 uint32 pdamage;
6212 if(m_modifier.m_auraname == SPELL_AURA_PERIODIC_DAMAGE)
6214 pdamage = amount;
6216 // Calculate armor mitigation if it is a physical spell
6217 // But not for bleed mechanic spells
6218 if ( GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL &&
6219 GetEffectMechanic(GetSpellProto(), m_effIndex) != MECHANIC_BLEED)
6221 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6222 cleanDamage.damage += pdamage - pdamageReductedArmor;
6223 pdamage = pdamageReductedArmor;
6226 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6228 // Curse of Agony damage-per-tick calculation
6229 if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000400)) && GetSpellProto()->SpellIconID==544)
6231 // 1..4 ticks, 1/2 from normal tick damage
6232 if (m_duration >= ((m_maxduration-m_modifier.periodictime) * 2 / 3))
6233 pdamage = pdamage/2;
6234 // 9..12 ticks, 3/2 from normal tick damage
6235 else if(m_duration < ((m_maxduration-m_modifier.periodictime) / 3))
6236 pdamage += (pdamage + 1) / 2; // +1 prevent 0.5 damage possible lost at 1..4 ticks
6237 // 5..8 ticks have normal tick damage
6240 else
6241 pdamage = uint32(m_target->GetMaxHealth()*amount/100);
6243 // This method can modify pdamage
6244 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6246 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6247 // Reduce dot damage from resilience for players
6248 if (m_target->GetTypeId() == TYPEID_PLAYER)
6249 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6251 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6253 sLog.outDetail("PeriodicTick: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6254 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6256 pCaster->DealDamageMods(m_target, pdamage, &absorb);
6258 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, absorb, resist, 0.0f, isCrit);
6259 m_target->SendPeriodicAuraLog(&pInfo);
6261 // Set trigger flag
6262 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6263 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6264 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage - absorb - resist);
6265 if (pdamage)
6266 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6267 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6269 pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6270 break;
6272 case SPELL_AURA_PERIODIC_LEECH:
6273 case SPELL_AURA_PERIODIC_HEALTH_FUNNEL:
6275 Unit *pCaster = GetCaster();
6276 if(!pCaster)
6277 return;
6279 if(!pCaster->isAlive())
6280 return;
6282 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6283 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6284 return;
6286 // Check for immune
6287 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6288 return;
6290 uint32 absorb=0;
6291 uint32 resist=0;
6292 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6294 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6296 //Calculate armor mitigation if it is a physical spell
6297 if (GetSpellSchoolMask(GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)
6299 uint32 pdamageReductedArmor = pCaster->CalcArmorReducedDamage(m_target, pdamage);
6300 cleanDamage.damage += pdamage - pdamageReductedArmor;
6301 pdamage = pdamageReductedArmor;
6304 pdamage = pCaster->SpellDamageBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6306 // As of 2.2 resilience reduces damage from DoT ticks as much as the chance to not be critically hit
6307 // Reduce dot damage from resilience for players
6308 if (m_target->GetTypeId()==TYPEID_PLAYER)
6309 pdamage-=((Player*)m_target)->GetDotDamageReduction(pdamage);
6311 pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist);
6313 if(m_target->GetHealth() < pdamage)
6314 pdamage = uint32(m_target->GetHealth());
6316 sLog.outDetail("PeriodicTick: %u (TypeId: %u) health leech of %u (TypeId: %u) for %u dmg inflicted by %u abs is %u",
6317 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId(),absorb);
6319 pCaster->SendSpellNonMeleeDamageLog(m_target, GetId(), pdamage, GetSpellSchoolMask(GetSpellProto()), absorb, resist, false, 0);
6321 float multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()] > 0 ? GetSpellProto()->EffectMultipleValue[GetEffIndex()] : 1;
6323 // Set trigger flag
6324 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6325 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6326 pdamage = (pdamage <= absorb + resist) ? 0 : (pdamage-absorb-resist);
6327 if (pdamage)
6328 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6329 pCaster->ProcDamageAndSpell(m_target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, GetSpellProto());
6330 int32 new_damage = pCaster->DealDamage(m_target, pdamage, &cleanDamage, DOT, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), false);
6332 if (!m_target->isAlive() && pCaster->IsNonMeleeSpellCasted(false))
6333 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
6334 if (Spell* spell = pCaster->GetCurrentSpell(CurrentSpellTypes(i)))
6335 if (spell->m_spellInfo->Id == GetId())
6336 spell->cancel();
6339 if(Player *modOwner = pCaster->GetSpellModOwner())
6340 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, multiplier);
6342 uint32 heal = pCaster->SpellHealingBonus(pCaster, GetSpellProto(), uint32(new_damage * multiplier), DOT, GetStackAmount());
6344 int32 gain = pCaster->DealHeal(pCaster, heal, GetSpellProto());
6345 pCaster->getHostilRefManager().threatAssist(pCaster, gain * 0.5f, GetSpellProto());
6346 break;
6348 case SPELL_AURA_PERIODIC_HEAL:
6349 case SPELL_AURA_OBS_MOD_HEALTH:
6351 Unit *pCaster = GetCaster();
6352 if(!pCaster)
6353 return;
6355 // heal for caster damage (must be alive)
6356 if(m_target != pCaster && GetSpellProto()->SpellVisual[0] == 163 && !pCaster->isAlive())
6357 return;
6359 // ignore non positive values (can be result apply spellmods to aura damage
6360 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6362 uint32 pdamage;
6364 if(m_modifier.m_auraname==SPELL_AURA_OBS_MOD_HEALTH)
6365 pdamage = uint32(m_target->GetMaxHealth() * amount / 100);
6366 else
6368 pdamage = amount;
6370 // Wild Growth (1/7 - 6 + 2*ramainTicks) %
6371 if (m_spellProto->SpellFamilyName == SPELLFAMILY_DRUID && m_spellProto->SpellIconID == 2864)
6373 int32 ticks = m_maxduration/m_modifier.periodictime;
6374 int32 remainingTicks = int32(float(m_duration) / m_modifier.periodictime + 0.5);
6375 pdamage = int32(pdamage) + int32(amount)*ticks*(-6+2*remainingTicks)/100;
6379 pdamage = pCaster->SpellHealingBonus(m_target, GetSpellProto(), pdamage, DOT, GetStackAmount());
6381 // This method can modify pdamage
6382 bool isCrit = IsCritFromAbilityAura(pCaster, pdamage);
6384 sLog.outDetail("PeriodicTick: %u (TypeId: %u) heal of %u (TypeId: %u) for %u health inflicted by %u",
6385 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6387 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f, isCrit);
6388 m_target->SendPeriodicAuraLog(&pInfo);
6390 int32 gain = m_target->ModifyHealth(pdamage);
6392 // add HoTs to amount healed in bgs
6393 if( pCaster->GetTypeId() == TYPEID_PLAYER )
6394 if( BattleGround *bg = ((Player*)pCaster)->GetBattleGround() )
6395 bg->UpdatePlayerScore(((Player*)pCaster), SCORE_HEALING_DONE, gain);
6397 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6399 SpellEntry const* spellProto = GetSpellProto();
6401 // heal for caster damage
6402 if(m_target != pCaster && spellProto->SpellVisual[0] == 163)
6404 uint32 dmg = spellProto->manaPerSecond;
6405 if(pCaster->GetHealth() <= dmg && pCaster->GetTypeId()==TYPEID_PLAYER)
6407 pCaster->RemoveAurasDueToSpell(GetId());
6409 // finish current generic/channeling spells, don't affect autorepeat
6410 pCaster->FinishSpell(CURRENT_GENERIC_SPELL);
6411 pCaster->FinishSpell(CURRENT_CHANNELED_SPELL);
6413 else
6415 uint32 damage = gain;
6416 uint32 absorb = 0;
6417 pCaster->DealDamageMods(pCaster, damage, &absorb);
6418 pCaster->SendSpellNonMeleeDamageLog(pCaster, GetId(), damage, GetSpellSchoolMask(GetSpellProto()), absorb, 0, false, 0, false);
6420 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL );
6421 pCaster->DealDamage(pCaster, damage, &cleanDamage, NODAMAGE, GetSpellSchoolMask(GetSpellProto()), GetSpellProto(), true);
6425 // uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC;// | PROC_FLAG_SUCCESSFUL_HEAL;
6426 // uint32 procVictim = 0;//ROC_FLAG_ON_TAKE_PERIODIC | PROC_FLAG_TAKEN_HEAL;
6427 // ignore item heals
6428 // if(procSpell && !haveCastItem)
6429 // pCaster->ProcDamageAndSpell(target, procAttacker, procVictim, PROC_EX_NORMAL_HIT, pdamage, BASE_ATTACK, spellProto);
6430 break;
6432 case SPELL_AURA_PERIODIC_MANA_LEECH:
6434 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6435 return;
6437 Powers power = Powers(m_modifier.m_miscvalue);
6439 // power type might have changed between aura applying and tick (druid's shapeshift)
6440 if(m_target->getPowerType() != power)
6441 return;
6443 Unit *pCaster = GetCaster();
6444 if(!pCaster)
6445 return;
6447 if(!pCaster->isAlive())
6448 return;
6450 if( GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_PERSISTENT_AREA_AURA &&
6451 pCaster->SpellHitResult(m_target, GetSpellProto(), false) != SPELL_MISS_NONE)
6452 return;
6454 // Check for immune (not use charges)
6455 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6456 return;
6458 // ignore non positive values (can be result apply spellmods to aura damage
6459 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6461 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
6462 // It's mana percent cost spells, m_modifier.m_amount is percent drain from target
6463 if (m_spellProto->ManaCostPercentage)
6465 // max value
6466 uint32 maxmana = pCaster->GetMaxPower(power) * pdamage * 2 / 100;
6467 pdamage = m_target->GetMaxPower(power) * pdamage / 100;
6468 if(pdamage > maxmana)
6469 pdamage = maxmana;
6472 sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u",
6473 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6475 int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
6477 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6478 if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6479 drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
6481 m_target->ModifyPower(power, -drain_amount);
6483 float gain_multiplier = 0;
6485 if(pCaster->GetMaxPower(power) > 0)
6487 gain_multiplier = GetSpellProto()->EffectMultipleValue[GetEffIndex()];
6489 if(Player *modOwner = pCaster->GetSpellModOwner())
6490 modOwner->ApplySpellMod(GetId(), SPELLMOD_MULTIPLE_VALUE, gain_multiplier);
6493 SpellPeriodicAuraLogInfo pInfo(this, drain_amount, 0, 0, 0, gain_multiplier);
6494 m_target->SendPeriodicAuraLog(&pInfo);
6496 int32 gain_amount = int32(drain_amount * gain_multiplier);
6498 if(gain_amount)
6500 int32 gain = pCaster->ModifyPower(power, gain_amount);
6501 m_target->AddThreat(pCaster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto());
6503 break;
6505 case SPELL_AURA_PERIODIC_ENERGIZE:
6507 // ignore non positive values (can be result apply spellmods to aura damage
6508 uint32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6510 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u dmg inflicted by %u",
6511 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6513 if(m_modifier.m_miscvalue < 0 || m_modifier.m_miscvalue >= MAX_POWERS)
6514 break;
6516 Powers power = Powers(m_modifier.m_miscvalue);
6518 if(m_target->GetMaxPower(power) == 0)
6519 break;
6521 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6522 m_target->SendPeriodicAuraLog(&pInfo);
6524 int32 gain = m_target->ModifyPower(power,pdamage);
6526 if(Unit* pCaster = GetCaster())
6527 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6528 break;
6530 case SPELL_AURA_OBS_MOD_MANA:
6532 // ignore non positive values (can be result apply spellmods to aura damage
6533 uint32 amount = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6535 uint32 pdamage = uint32(m_target->GetMaxPower(POWER_MANA) * amount / 100);
6537 sLog.outDetail("PeriodicTick: %u (TypeId: %u) energize %u (TypeId: %u) for %u mana inflicted by %u",
6538 GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), m_target->GetGUIDLow(), m_target->GetTypeId(), pdamage, GetId());
6540 if(m_target->GetMaxPower(POWER_MANA) == 0)
6541 break;
6543 SpellPeriodicAuraLogInfo pInfo(this, pdamage, 0, 0, 0, 0.0f);
6544 m_target->SendPeriodicAuraLog(&pInfo);
6546 int32 gain = m_target->ModifyPower(POWER_MANA, pdamage);
6548 if(Unit* pCaster = GetCaster())
6549 m_target->getHostilRefManager().threatAssist(pCaster, float(gain) * 0.5f, GetSpellProto());
6550 break;
6552 case SPELL_AURA_POWER_BURN_MANA:
6554 Unit *pCaster = GetCaster();
6555 if(!pCaster)
6556 return;
6558 // Check for immune (not use charges)
6559 if(m_target->IsImmunedToDamage(GetSpellSchoolMask(GetSpellProto())))
6560 return;
6562 int32 pdamage = m_modifier.m_amount > 0 ? m_modifier.m_amount : 0;
6564 Powers powerType = Powers(m_modifier.m_miscvalue);
6566 if(!m_target->isAlive() || m_target->getPowerType() != powerType)
6567 return;
6569 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
6570 if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
6571 pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
6573 uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
6575 gain = uint32(gain * GetSpellProto()->EffectMultipleValue[GetEffIndex()]);
6577 SpellEntry const* spellProto = GetSpellProto();
6578 // maybe has to be sent different to client, but not by SMSG_PERIODICAURALOG
6579 SpellNonMeleeDamage damageInfo(pCaster, m_target, spellProto->Id, spellProto->SchoolMask);
6580 pCaster->CalculateSpellDamage(&damageInfo, gain, spellProto);
6582 pCaster->DealDamageMods(damageInfo.target, damageInfo.damage, &damageInfo.absorb);
6584 pCaster->SendSpellNonMeleeDamageLog(&damageInfo);
6586 // Set trigger flag
6587 uint32 procAttacker = PROC_FLAG_ON_DO_PERIODIC; // | PROC_FLAG_SUCCESSFUL_HARMFUL_SPELL_HIT;
6588 uint32 procVictim = PROC_FLAG_ON_TAKE_PERIODIC;// | PROC_FLAG_TAKEN_HARMFUL_SPELL_HIT;
6589 uint32 procEx = createProcExtendMask(&damageInfo, SPELL_MISS_NONE);
6590 if (damageInfo.damage)
6591 procVictim|=PROC_FLAG_TAKEN_ANY_DAMAGE;
6593 pCaster->ProcDamageAndSpell(damageInfo.target, procAttacker, procVictim, procEx, damageInfo.damage, BASE_ATTACK, spellProto);
6595 pCaster->DealSpellDamage(&damageInfo, true);
6596 break;
6598 case SPELL_AURA_MOD_REGEN:
6600 int32 gain = m_target->ModifyHealth(m_modifier.m_amount);
6601 if (Unit *caster = GetCaster())
6602 m_target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, GetSpellProto());
6603 break;
6605 case SPELL_AURA_MOD_POWER_REGEN:
6607 Powers pt = m_target->getPowerType();
6608 if(int32(pt) != m_modifier.m_miscvalue)
6609 return;
6611 if ( GetSpellProto()->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
6613 // eating anim
6614 m_target->HandleEmoteCommand(EMOTE_ONESHOT_EAT);
6616 else if( GetId() == 20577 )
6618 // cannibalize anim
6619 m_target->HandleEmoteCommand(EMOTE_STATE_CANNIBALIZE);
6622 // Anger Management
6623 // amount = 1+ 16 = 17 = 3,4*5 = 10,2*5/3
6624 // so 17 is rounded amount for 5 sec tick grow ~ 1 range grow in 3 sec
6625 if(pt == POWER_RAGE)
6626 m_target->ModifyPower(pt, m_modifier.m_amount * 3 / 5);
6627 break;
6629 // Here tick dummy auras
6630 case SPELL_AURA_PERIODIC_DUMMY:
6632 PeriodicDummyTick();
6633 break;
6635 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
6637 TriggerSpell();
6638 break;
6640 case SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE:
6642 TriggerSpellWithValue();
6643 break;
6645 default:
6646 break;
6650 void Aura::PeriodicDummyTick()
6652 Unit *caster = GetCaster();
6653 SpellEntry const* spell = GetSpellProto();
6654 switch (spell->SpellFamilyName)
6656 case SPELLFAMILY_GENERIC:
6657 switch (spell->Id)
6659 // Drink
6660 case 430:
6661 case 431:
6662 case 432:
6663 case 1133:
6664 case 1135:
6665 case 1137:
6666 case 10250:
6667 case 22734:
6668 case 27089:
6669 case 34291:
6670 case 43182:
6671 case 43183:
6672 case 43706:
6673 case 46755:
6674 case 49472: // Drink Coffee
6675 case 57073:
6676 case 61830:
6678 if (m_target->GetTypeId() != TYPEID_PLAYER)
6679 return;
6680 // Search SPELL_AURA_MOD_POWER_REGEN aura for this spell and add bonus
6681 Unit::AuraList const& aura = m_target->GetAurasByType(SPELL_AURA_MOD_POWER_REGEN);
6682 for(Unit::AuraList::const_iterator i = aura.begin(); i != aura.end(); ++i)
6684 if ((*i)->GetId() == GetId())
6686 (*i)->GetModifier()->m_amount = m_modifier.m_amount;
6687 ((Player*)m_target)->UpdateManaRegen();
6688 // Disable continue
6689 m_isPeriodic = false;
6690 return;
6693 return;
6695 // Forsaken Skills
6696 case 7054:
6698 // Possibly need cast one of them (but
6699 // 7038 Forsaken Skill: Swords
6700 // 7039 Forsaken Skill: Axes
6701 // 7040 Forsaken Skill: Daggers
6702 // 7041 Forsaken Skill: Maces
6703 // 7042 Forsaken Skill: Staves
6704 // 7043 Forsaken Skill: Bows
6705 // 7044 Forsaken Skill: Guns
6706 // 7045 Forsaken Skill: 2H Axes
6707 // 7046 Forsaken Skill: 2H Maces
6708 // 7047 Forsaken Skill: 2H Swords
6709 // 7048 Forsaken Skill: Defense
6710 // 7049 Forsaken Skill: Fire
6711 // 7050 Forsaken Skill: Frost
6712 // 7051 Forsaken Skill: Holy
6713 // 7053 Forsaken Skill: Shadow
6714 return;
6716 // // Panda
6717 // case 19230: break;
6718 // // Gossip NPC Periodic - Talk
6719 // case 33208: break;
6720 // // Gossip NPC Periodic - Despawn
6721 // case 33209: break;
6722 // // Steal Weapon
6723 // case 36207: break;
6724 // // Simon Game START timer, (DND)
6725 // case 39993: break;
6726 // // Knockdown Fel Cannon: break; The Aggro Burst
6727 // case 40119: break;
6728 // // Old Mount Spell
6729 // case 40154: break;
6730 // // Magnetic Pull
6731 // case 40581: break;
6732 // // Ethereal Ring: break; The Bolt Burst
6733 // case 40801: break;
6734 // // Crystal Prison
6735 // case 40846: break;
6736 // // Copy Weapon
6737 // case 41054: break;
6738 // // Dementia
6739 // case 41404: break;
6740 // // Ethereal Ring Visual, Lightning Aura
6741 // case 41477: break;
6742 // // Ethereal Ring Visual, Lightning Aura (Fork)
6743 // case 41525: break;
6744 // // Ethereal Ring Visual, Lightning Jumper Aura
6745 // case 41567: break;
6746 // // No Man's Land
6747 // case 41955: break;
6748 // // Headless Horseman - Fire
6749 // case 42074: break;
6750 // // Headless Horseman - Visual - Large Fire
6751 // case 42075: break;
6752 // // Headless Horseman - Start Fire, Periodic Aura
6753 // case 42140: break;
6754 // // Ram Speed Boost
6755 // case 42152: break;
6756 // // Headless Horseman - Fires Out Victory Aura
6757 // case 42235: break;
6758 // // Pumpkin Life Cycle
6759 // case 42280: break;
6760 // // Brewfest Request Chick Chuck Mug Aura
6761 // case 42537: break;
6762 // // Squashling
6763 // case 42596: break;
6764 // // Headless Horseman Climax, Head: Periodic
6765 // case 42603: break;
6766 // // Fire Bomb
6767 // case 42621: break;
6768 // // Headless Horseman - Conflagrate, Periodic Aura
6769 // case 42637: break;
6770 // // Headless Horseman - Create Pumpkin Treats Aura
6771 // case 42774: break;
6772 // // Headless Horseman Climax - Summoning Rhyme Aura
6773 // case 42879: break;
6774 // // Tricky Treat
6775 // case 42919: break;
6776 // // Giddyup!
6777 // case 42924: break;
6778 // // Ram - Trot
6779 // case 42992: break;
6780 // // Ram - Canter
6781 // case 42993: break;
6782 // // Ram - Gallop
6783 // case 42994: break;
6784 // // Ram Level - Neutral
6785 // case 43310: break;
6786 // // Headless Horseman - Maniacal Laugh, Maniacal, Delayed 17
6787 // case 43884: break;
6788 // // Wretched!
6789 // case 43963: break;
6790 // // Headless Horseman - Maniacal Laugh, Maniacal, other, Delayed 17
6791 // case 44000: break;
6792 // // Energy Feedback
6793 // case 44328: break;
6794 // // Romantic Picnic
6795 // case 45102: break;
6796 // // Romantic Picnic
6797 // case 45123: break;
6798 // // Looking for Love
6799 // case 45124: break;
6800 // // Kite - Lightning Strike Kite Aura
6801 // case 45197: break;
6802 // // Rocket Chicken
6803 // case 45202: break;
6804 // // Copy Offhand Weapon
6805 // case 45205: break;
6806 // // Upper Deck - Kite - Lightning Periodic Aura
6807 // case 45207: break;
6808 // // Kite -Sky Lightning Strike Kite Aura
6809 // case 45251: break;
6810 // // Ribbon Pole Dancer Check Aura
6811 // case 45390: break;
6812 // // Holiday - Midsummer, Ribbon Pole Periodic Visual
6813 // case 45406: break;
6814 // // Parachute
6815 // case 45472: break;
6816 // // Alliance Flag, Extra Damage Debuff
6817 // case 45898: break;
6818 // // Horde Flag, Extra Damage Debuff
6819 // case 45899: break;
6820 // // Ahune - Summoning Rhyme Aura
6821 // case 45926: break;
6822 // // Ahune - Slippery Floor
6823 // case 45945: break;
6824 // // Ahune's Shield
6825 // case 45954: break;
6826 // // Nether Vapor Lightning
6827 // case 45960: break;
6828 // // Darkness
6829 // case 45996: break;
6830 // // Summon Blood Elves Periodic
6831 // case 46041: break;
6832 // // Transform Visual Missile Periodic
6833 // case 46205: break;
6834 // // Find Opening Beam End
6835 // case 46333: break;
6836 // // Ice Spear Control Aura
6837 // case 46371: break;
6838 // // Hailstone Chill
6839 // case 46458: break;
6840 // // Hailstone Chill, Internal
6841 // case 46465: break;
6842 // // Chill, Internal Shifter
6843 // case 46549: break;
6844 // // Summon Ice Spear Knockback Delayer
6845 // case 46878: break;
6846 // // Burninate Effect
6847 // case 47214: break;
6848 // // Fizzcrank Practice Parachute
6849 // case 47228: break;
6850 // // Send Mug Control Aura
6851 // case 47369: break;
6852 // // Direbrew's Disarm (precast)
6853 // case 47407: break;
6854 // // Mole Machine Port Schedule
6855 // case 47489: break;
6856 // case 47941: break; // Crystal Spike
6857 // case 48200: break; // Healer Aura
6858 // case 48630: break; // Summon Gauntlet Mobs Periodic
6859 // case 49313: break; // Proximity Mine Area Aura
6860 // // Mole Machine Portal Schedule
6861 // case 49466: break;
6862 // case 49555: break; // Corpse Explode
6863 // case 49592: break; // Temporal Rift
6864 // case 49957: break; // Cutting Laser
6865 // case 50085: break; // Slow Fall
6866 // // Listening to Music
6867 // case 50493: break;
6868 // // Love Rocket Barrage
6869 // case 50530: break;
6870 // Exist more after, need add later
6871 default:
6872 break;
6874 break;
6875 case SPELLFAMILY_MAGE:
6877 // Mirror Image
6878 // if (spell->Id == 55342)
6879 // return;
6880 break;
6882 case SPELLFAMILY_DRUID:
6884 switch (spell->Id)
6886 // Frenzied Regeneration
6887 case 22842:
6889 // Converts up to 10 rage per second into health for $d. Each point of rage is converted into ${$m2/10}.1% of max health.
6890 // Should be manauser
6891 if (m_target->getPowerType() != POWER_RAGE)
6892 return;
6893 uint32 rage = m_target->GetPower(POWER_RAGE);
6894 // Nothing todo
6895 if (rage == 0)
6896 return;
6897 int32 mod = (rage < 100) ? rage : 100;
6898 int32 points = m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
6899 int32 regen = m_target->GetMaxHealth() * (mod * points / 10) / 1000;
6900 m_target->CastCustomSpell(m_target, 22845, &regen, NULL, NULL, true, NULL, this);
6901 m_target->SetPower(POWER_RAGE, rage-mod);
6902 return;
6904 // Force of Nature
6905 case 33831:
6906 return;
6907 default:
6908 break;
6910 break;
6912 case SPELLFAMILY_ROGUE:
6914 switch (spell->Id)
6916 case 51690:
6918 std::list<Unit*> targets;
6920 // eff_radius ==0
6921 float radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spell->rangeIndex));
6923 CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(),caster->GetPositionY()));
6924 Cell cell(p);
6925 cell.data.Part.reserved = ALL_DISTRICT;
6927 MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck u_check(caster, caster, radius);
6928 MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck> checker(caster,targets, u_check);
6930 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker);
6931 TypeContainerVisitor<MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyVisibleUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
6933 CellLock<GridReadGuard> cell_lock(cell, p);
6935 cell_lock->Visit(cell_lock, grid_object_checker, *caster->GetMap());
6936 cell_lock->Visit(cell_lock, world_object_checker, *caster->GetMap());
6939 if(targets.empty())
6940 return;
6942 std::list<Unit*>::const_iterator itr = targets.begin();
6943 std::advance(itr, rand()%targets.size());
6944 Unit* target = *itr;
6946 caster->CastSpell(target, 57840, true);
6947 caster->CastSpell(target, 57841, true);
6948 return;
6950 // Master of Subtlety
6951 // case 31666: break;
6952 // Killing Spree
6953 // case 51690: break;
6954 // Overkill
6955 // case 58428: break;
6956 // default:
6957 // break;
6959 break;
6961 case SPELLFAMILY_HUNTER:
6963 // Explosive Shot
6964 if (spell->SpellFamilyFlags & UI64LIT(0x8000000000000000))
6966 m_target->CastCustomSpell(m_target, 53352, &m_modifier.m_amount, 0, 0, true, 0, this, GetCasterGUID());
6967 return;
6969 switch (spell->Id)
6971 // Harpooner's Mark
6972 // case 40084:
6973 // return;
6974 // Feeding Frenzy Rank 1
6975 case 53511:
6976 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
6977 m_target->CastSpell(m_target, 60096, true, 0, this);
6978 return;
6979 // Feeding Frenzy Rank 2
6980 case 53512:
6981 if ( m_target->GetHealth() * 100 < m_target->GetMaxHealth() * 35 )
6982 m_target->CastSpell(m_target, 60097, true, 0, this);
6983 return;
6984 default:
6985 break;
6987 break;
6989 case SPELLFAMILY_SHAMAN:
6991 // Astral Shift
6992 if (spell->Id == 52179)
6994 // Periodic need for remove visual on stun/fear/silence lost
6995 if (!(m_target->GetUInt32Value(UNIT_FIELD_FLAGS)&(UNIT_FLAG_STUNNED|UNIT_FLAG_FLEEING|UNIT_FLAG_SILENCED)))
6996 m_target->RemoveAurasDueToSpell(52179);
6997 return;
6999 break;
7001 case SPELLFAMILY_DEATHKNIGHT:
7003 // Death and Decay
7004 if (spell->SpellFamilyFlags & UI64LIT(0x0000000000000020))
7006 if (caster)
7007 caster->CastCustomSpell(m_target, 52212, &m_modifier.m_amount, NULL, NULL, true, NULL, this);
7008 return;
7010 // Raise Dead
7011 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000001000))
7012 // return;
7013 // Chains of Ice
7014 if (spell->SpellFamilyFlags & UI64LIT(0x0000400000000000))
7016 // Get 0 effect aura
7017 Aura *slow = m_target->GetAura(GetId(), 0);
7018 if (slow)
7020 slow->ApplyModifier(false, true);
7021 Modifier *mod = slow->GetModifier();
7022 mod->m_amount+= m_modifier.m_amount;
7023 if (mod->m_amount > 0) mod->m_amount = 0;
7024 slow->ApplyModifier(true, true);
7026 return;
7028 // Summon Gargoyle
7029 // if (spell->SpellFamilyFlags & UI64LIT(0x0000008000000000))
7030 // return;
7031 // Death Rune Mastery
7032 // if (spell->SpellFamilyFlags & UI64LIT(0x0000000000004000))
7033 // return;
7034 // Bladed Armor
7035 if (spell->SpellIconID == 2653)
7037 // Increases your attack power by $s1 for every $s2 armor value you have.
7038 // Calculate AP bonus (from 1 efect of this spell)
7039 int32 apBonus = m_modifier.m_amount * m_target->GetArmor() / m_target->CalculateSpellDamage(spell, 1, spell->EffectBasePoints[1], m_target);
7040 m_target->CastCustomSpell(m_target, 61217, &apBonus, &apBonus, NULL, true, NULL, this);
7041 return;
7043 // Reaping
7044 // if (spell->SpellIconID == 22)
7045 // return;
7046 // Blood of the North
7047 // if (spell->SpellIconID == 30412)
7048 // return;
7049 break;
7051 default:
7052 break;
7056 void Aura::HandlePreventFleeing(bool apply, bool Real)
7058 if(!Real)
7059 return;
7061 Unit::AuraList const& fearAuras = m_target->GetAurasByType(SPELL_AURA_MOD_FEAR);
7062 if( !fearAuras.empty() )
7064 if (apply)
7065 m_target->SetFeared(false, fearAuras.front()->GetCasterGUID());
7066 else
7067 m_target->SetFeared(true);
7071 void Aura::HandleManaShield(bool apply, bool Real)
7073 if(!Real)
7074 return;
7076 // prevent double apply bonuses
7077 if(apply && (m_target->GetTypeId()!=TYPEID_PLAYER || !((Player*)m_target)->GetSession()->PlayerLoading()))
7079 if(Unit* caster = GetCaster())
7081 float DoneActualBenefit = 0.0f;
7082 switch(m_spellProto->SpellFamilyName)
7084 case SPELLFAMILY_MAGE:
7085 if(m_spellProto->SpellFamilyFlags & UI64LIT(0x8000))
7087 // Mana Shield
7088 // +50% from +spd bonus
7089 DoneActualBenefit = caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.5f;
7090 break;
7092 break;
7093 default:
7094 break;
7097 DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto());
7099 m_modifier.m_amount += (int32)DoneActualBenefit;
7104 void Aura::HandleArenaPreparation(bool apply, bool Real)
7106 if(!Real)
7107 return;
7109 if(apply)
7110 m_target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7111 else
7112 m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION);
7116 * Such auras are applied from a caster(=player) to a vehicle.
7117 * This has been verified using spell #49256
7119 void Aura::HandleAuraControlVehicle(bool apply, bool Real)
7121 if(!Real)
7122 return;
7124 Unit *player = GetCaster();
7125 Vehicle *vehicle = dynamic_cast<Vehicle*>(m_target);
7126 if(!player || player->GetTypeId() != TYPEID_PLAYER || !vehicle)
7127 return;
7129 if (apply)
7131 if(Pet *pet = player->GetPet())
7132 pet->Remove(PET_SAVE_AS_CURRENT);
7133 ((Player*)player)->EnterVehicle(vehicle);
7135 else
7137 SpellEntry const *spell = GetSpellProto();
7139 // some SPELL_AURA_CONTROL_VEHICLE auras have a dummy effect on the player - remove them
7140 player->RemoveAurasDueToSpell(spell->Id);
7142 ((Player*)player)->ExitVehicle(vehicle);
7146 void Aura::HandleAuraConvertRune(bool apply, bool Real)
7148 if(!Real)
7149 return;
7151 if(m_target->GetTypeId() != TYPEID_PLAYER)
7152 return;
7154 Player *plr = (Player*)m_target;
7156 if(plr->getClass() != CLASS_DEATH_KNIGHT)
7157 return;
7159 // how to determine what rune need to be converted?
7160 for(uint32 i = 0; i < MAX_RUNES; ++i)
7162 if(apply)
7164 if(!plr->GetRuneCooldown(i))
7166 plr->ConvertRune(i, GetSpellProto()->EffectMiscValueB[m_effIndex]);
7167 break;
7170 else
7172 if(plr->GetCurrentRune(i) == GetSpellProto()->EffectMiscValueB[m_effIndex])
7174 plr->ConvertRune(i, plr->GetBaseRune(i));
7175 break;
7181 void Aura::HandlePhase(bool apply, bool Real)
7183 if(!Real)
7184 return;
7186 // always non stackable
7187 if(apply)
7189 Unit::AuraList const& phases = m_target->GetAurasByType(SPELL_AURA_PHASE);
7190 if(!phases.empty())
7191 m_target->RemoveAurasDueToSpell(phases.front()->GetId(), this);
7194 // no-phase is also phase state so same code for apply and remove
7196 // phase auras normally not expected at BG but anyway better check
7197 if(m_target->GetTypeId() == TYPEID_PLAYER)
7199 // drop flag at invisible in bg
7200 if(((Player*)m_target)->InBattleGround())
7201 if(BattleGround *bg = ((Player*)m_target)->GetBattleGround())
7202 bg->EventPlayerDroppedFlag((Player*)m_target);
7204 // GM-mode have mask 0xFFFFFFFF
7205 if(!((Player*)m_target)->isGameMaster())
7206 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7208 ((Player*)m_target)->GetSession()->SendSetPhaseShift(apply ? GetMiscValue() : PHASEMASK_NORMAL);
7210 if(GetEffIndex()==0)
7212 SpellAreaForAreaMapBounds saBounds = spellmgr.GetSpellAreaForAuraMapBounds(GetId());
7213 if(saBounds.first != saBounds.second)
7215 uint32 zone, area;
7216 m_target->GetZoneAndAreaId(zone, area);
7218 for(SpellAreaForAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
7220 // some auras remove at aura remove
7221 if(!itr->second->IsFitToRequirements((Player*)m_target, zone, area))
7222 m_target->RemoveAurasDueToSpell(itr->second->spellId);
7223 // some auras applied at aura apply
7224 else if(itr->second->autocast)
7226 if( !m_target->HasAura(itr->second->spellId, 0) )
7227 m_target->CastSpell(m_target, itr->second->spellId, true);
7233 else
7234 m_target->SetPhaseMask(apply ? GetMiscValue() : PHASEMASK_NORMAL, false);
7236 // need triggering visibility update base at phase update of not GM invisible (other GMs anyway see in any phases)
7237 if(m_target->GetVisibility() != VISIBILITY_OFF)
7238 m_target->SetVisibility(m_target->GetVisibility());
7241 void Aura::UnregisterSingleCastAura()
7243 if (IsSingleTarget())
7245 if(Unit* caster = GetCaster())
7247 caster->GetSingleCastAuras().remove(this);
7249 else
7251 sLog.outError("Couldn't find the caster of the single target aura (SpellId %u), may crash later!", GetId());
7252 assert(false);
7254 m_isSingleTargetAura = false;
7258 void Aura::HandleAuraSafeFall( bool Apply, bool Real )
7260 // implemented in WorldSession::HandleMovementOpcodes
7262 // only special case
7263 if(Apply && Real && GetId() == 32474 && m_target->GetTypeId() == TYPEID_PLAYER)
7264 ((Player*)m_target)->ActivateTaxiPathTo(506, GetId());
7267 bool Aura::IsCritFromAbilityAura(Unit* caster, uint32& damage)
7269 Unit::AuraList const& auras = caster->GetAurasByType(SPELL_AURA_ABILITY_PERIODIC_CRIT);
7270 for(Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
7272 if (!(*itr)->isAffectedOnSpell(m_spellProto))
7273 continue;
7274 if (!caster->isSpellCrit(m_target, m_spellProto, GetSpellSchoolMask(m_spellProto)))
7275 break;
7277 damage = caster->SpellCriticalDamageBonus(m_spellProto, damage, m_target);
7278 return true;
7280 return false;
7283 void Aura::HandleModTargetArmorPct(bool apply, bool Real)
7285 if(m_target->GetTypeId() != TYPEID_PLAYER)
7286 return;
7288 ((Player*)m_target)->UpdateArmorPenetration();