[10051] Fixed talent 58426 broken after 3.3.3 switch.
[getmangos.git] / src / game / SpellAuras.h
blob89918a8a8f7c4009aeb35973c087af1d24427b0b
1 /*
2 * Copyright (C) 2005-2010 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
18 #ifndef MANGOS_SPELLAURAS_H
19 #define MANGOS_SPELLAURAS_H
21 #include "SpellAuraDefines.h"
22 #include "DBCEnums.h"
24 struct Modifier
26 AuraType m_auraname;
27 int32 m_amount;
28 int32 m_miscvalue;
29 uint32 periodictime;
32 class Unit;
33 struct SpellEntry;
34 struct SpellModifier;
35 struct ProcTriggerSpell;
37 // forward decl
38 class Aura;
40 // internal helper
41 struct ReapplyAffectedPassiveAurasHelper;
43 typedef void(Aura::*pAuraHandler)(bool Apply, bool Real);
44 // Real == true at aura add/remove
45 // Real == false at aura mod unapply/reapply; when adding/removing dependent aura/item/stat mods
47 // Code in aura handler can be guarded by if(Real) check if it should execution only at real add/remove of aura
49 // MAIN RULE: Code MUST NOT be guarded by if(Real) check if it modifies any stats
50 // (percent auras, stats mods, etc)
51 // Second rule: Code must be guarded by if(Real) check if it modifies object state (start/stop attack, send packets to client, etc)
53 // Other case choice: each code line moved under if(Real) check is mangos speedup,
54 // each setting object update field code line moved under if(Real) check is significant mangos speedup, and less server->client data sends
55 // each packet sending code moved under if(Real) check is _large_ mangos speedup, and lot less server->client data sends
57 class MANGOS_DLL_SPEC Aura
59 friend struct ReapplyAffectedPassiveAurasHelper;
60 friend Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem);
62 public:
63 //aura handlers
64 void HandleNULL(bool, bool)
66 // NOT IMPLEMENTED
68 void HandleUnused(bool, bool)
70 // NOT USED BY ANY SPELL OR USELESS
72 void HandleNoImmediateEffect(bool, bool)
74 // aura not have immediate effect at add/remove and handled by ID in other code place
76 void HandleBindSight(bool Apply, bool Real);
77 void HandleModPossess(bool Apply, bool Real);
78 void HandlePeriodicDamage(bool Apply, bool Real);
79 void HandleAuraDummy(bool Apply, bool Real);
80 void HandleAuraPeriodicDummy(bool apply, bool Real);
81 void HandleModConfuse(bool Apply, bool Real);
82 void HandleModCharm(bool Apply, bool Real);
83 void HandleModFear(bool Apply, bool Real);
84 void HandlePeriodicHeal(bool Apply, bool Real);
85 void HandleModAttackSpeed(bool Apply, bool Real);
86 void HandleModMeleeRangedSpeedPct(bool apply, bool Real);
87 void HandleModCombatSpeedPct(bool apply, bool Real);
88 void HandleModThreat(bool Apply, bool Real);
89 void HandleModTaunt(bool Apply, bool Real);
90 void HandleFeignDeath(bool Apply, bool Real);
91 void HandleAuraModDisarm(bool Apply, bool Real);
92 void HandleAuraModStalked(bool Apply, bool Real);
93 void HandleAuraWaterWalk(bool Apply, bool Real);
94 void HandleAuraFeatherFall(bool Apply, bool Real);
95 void HandleAuraHover(bool Apply, bool Real);
96 void HandleAddModifier(bool Apply, bool Real);
98 void HandleAuraModStun(bool Apply, bool Real);
99 void HandleModDamageDone(bool Apply, bool Real);
100 void HandleAuraUntrackable(bool Apply, bool Real);
101 void HandleAuraEmpathy(bool Apply, bool Real);
102 void HandleModOffhandDamagePercent(bool apply, bool Real);
103 void HandleAuraModRangedAttackPower(bool Apply, bool Real);
104 void HandleAuraModIncreaseEnergyPercent(bool Apply, bool Real);
105 void HandleAuraModIncreaseHealthPercent(bool Apply, bool Real);
106 void HandleAuraModRegenInterrupt(bool Apply, bool Real);
107 void HandleHaste(bool Apply, bool Real);
108 void HandlePeriodicTriggerSpell(bool Apply, bool Real);
109 void HandlePeriodicTriggerSpellWithValue(bool apply, bool Real);
110 void HandlePeriodicEnergize(bool Apply, bool Real);
111 void HandleAuraModResistanceExclusive(bool Apply, bool Real);
112 void HandleAuraSafeFall(bool Apply, bool Real);
113 void HandleAuraModPetTalentsPoints(bool Apply, bool Real);
114 void HandleModStealth(bool Apply, bool Real);
115 void HandleInvisibility(bool Apply, bool Real);
116 void HandleInvisibilityDetect(bool Apply, bool Real);
117 void HandleAuraModTotalHealthPercentRegen(bool Apply, bool Real);
118 void HandleAuraModTotalManaPercentRegen(bool Apply, bool Real);
119 void HandleAuraModResistance(bool Apply, bool Real);
120 void HandleAuraModRoot(bool Apply, bool Real);
121 void HandleAuraModSilence(bool Apply, bool Real);
122 void HandleAuraModStat(bool Apply, bool Real);
123 void HandleAuraModIncreaseSpeed(bool Apply, bool Real);
124 void HandleAuraModIncreaseMountedSpeed(bool Apply, bool Real);
125 void HandleAuraModIncreaseFlightSpeed(bool Apply, bool Real);
126 void HandleAuraModDecreaseSpeed(bool Apply, bool Real);
127 void HandleAuraModUseNormalSpeed(bool Apply, bool Real);
128 void HandleAuraModIncreaseHealth(bool Apply, bool Real);
129 void HandleAuraModIncreaseEnergy(bool Apply, bool Real);
130 void HandleAuraModShapeshift(bool Apply, bool Real);
131 void HandleAuraModEffectImmunity(bool Apply, bool Real);
132 void HandleAuraModStateImmunity(bool Apply, bool Real);
133 void HandleAuraModSchoolImmunity(bool Apply, bool Real);
134 void HandleAuraModDmgImmunity(bool Apply, bool Real);
135 void HandleAuraModDispelImmunity(bool Apply, bool Real);
136 void HandleAuraProcTriggerSpell(bool Apply, bool Real);
137 void HandleAuraTrackCreatures(bool Apply, bool Real);
138 void HandleAuraTrackResources(bool Apply, bool Real);
139 void HandleAuraModParryPercent(bool Apply, bool Real);
140 void HandleAuraModDodgePercent(bool Apply, bool Real);
141 void HandleAuraModBlockPercent(bool Apply, bool Real);
142 void HandleAuraModCritPercent(bool Apply, bool Real);
143 void HandlePeriodicLeech(bool Apply, bool Real);
144 void HandleModHitChance(bool Apply, bool Real);
145 void HandleModSpellHitChance(bool Apply, bool Real);
146 void HandleAuraModScale(bool Apply, bool Real);
147 void HandlePeriodicManaLeech(bool Apply, bool Real);
148 void HandlePeriodicHealthFunnel(bool apply, bool Real);
149 void HandleModCastingSpeed(bool Apply, bool Real);
150 void HandleAuraMounted(bool Apply, bool Real);
151 void HandleWaterBreathing(bool Apply, bool Real);
152 void HandleModBaseResistance(bool Apply, bool Real);
153 void HandleModRegen(bool Apply, bool Real);
154 void HandleModPowerRegen(bool Apply, bool Real);
155 void HandleModPowerRegenPCT(bool Apply, bool Real);
156 void HandleChannelDeathItem(bool Apply, bool Real);
157 void HandlePeriodicDamagePCT(bool Apply, bool Real);
158 void HandleAuraModAttackPower(bool Apply, bool Real);
159 void HandleAuraTransform(bool Apply, bool Real);
160 void HandleModSpellCritChance(bool Apply, bool Real);
161 void HandleAuraModIncreaseSwimSpeed(bool Apply, bool Real);
162 void HandleModPowerCostPCT(bool Apply, bool Real);
163 void HandleModPowerCost(bool Apply, bool Real);
164 void HandleFarSight(bool Apply, bool Real);
165 void HandleModPossessPet(bool Apply, bool Real);
166 void HandleModMechanicImmunity(bool Apply, bool Real);
167 void HandleModMechanicImmunityMask(bool Apply, bool Real);
168 void HandleAuraModSkill(bool Apply, bool Real);
169 void HandleModDamagePercentDone(bool Apply, bool Real);
170 void HandleModPercentStat(bool Apply, bool Real);
171 void HandleModResistancePercent(bool Apply, bool Real);
172 void HandleAuraModBaseResistancePCT(bool Apply, bool Real);
173 void HandleModShieldBlockPCT(bool Apply, bool Real);
174 void HandleAuraTrackStealthed(bool Apply, bool Real);
175 void HandleModShieldBlock(bool Apply, bool Real);
176 void HandleForceReaction(bool Apply, bool Real);
177 void HandleAuraModRangedHaste(bool Apply, bool Real);
178 void HandleRangedAmmoHaste(bool Apply, bool Real);
179 void HandleModHealingDone(bool Apply, bool Real);
180 void HandleModTotalPercentStat(bool Apply, bool Real);
181 void HandleAuraModTotalThreat(bool Apply, bool Real);
182 void HandleModUnattackable(bool Apply, bool Real);
183 void HandleAuraModPacify(bool Apply, bool Real);
184 void HandleAuraGhost(bool Apply, bool Real);
185 void HandleAuraAllowFlight(bool Apply, bool Real);
186 void HandleModRating(bool apply, bool Real);
187 void HandleModRatingFromStat(bool apply, bool Real);
188 void HandleModTargetResistance(bool apply, bool Real);
189 void HandleAuraModAttackPowerPercent(bool apply, bool Real);
190 void HandleAuraModRangedAttackPowerPercent(bool apply, bool Real);
191 void HandleAuraModRangedAttackPowerOfStatPercent(bool apply, bool Real);
192 void HandleAuraModAttackPowerOfStatPercent(bool apply, bool Real);
193 void HandleAuraModAttackPowerOfArmor(bool apply, bool Real);
194 void HandleSpiritOfRedemption(bool apply, bool Real);
195 void HandleModManaRegen(bool apply, bool Real);
196 void HandleComprehendLanguage(bool apply, bool Real);
197 void HandleShieldBlockValue(bool apply, bool Real);
198 void HandleModSpellCritChanceShool(bool apply, bool Real);
199 void HandleAuraRetainComboPoints(bool apply, bool Real);
200 void HandleModSpellDamagePercentFromStat(bool apply, bool Real);
201 void HandleModSpellHealingPercentFromStat(bool apply, bool Real);
202 void HandleAuraModDispelResist(bool apply, bool Real);
203 void HandleAuraControlVehicle(bool apply, bool Real);
204 void HandleModSpellDamagePercentFromAttackPower(bool apply, bool Real);
205 void HandleModSpellHealingPercentFromAttackPower(bool apply, bool Real);
206 void HandleAuraModPacifyAndSilence(bool Apply, bool Real);
207 void HandleAuraModIncreaseMaxHealth(bool apply, bool Real);
208 void HandleAuraModExpertise(bool apply, bool Real);
209 void HandleForceMoveForward(bool apply, bool Real);
210 void HandleAuraModResistenceOfStatPercent(bool apply, bool Real);
211 void HandleAuraPowerBurn(bool apply, bool Real);
212 void HandleSchoolAbsorb(bool apply, bool Real);
213 void HandlePreventFleeing(bool apply, bool Real);
214 void HandleManaShield(bool apply, bool Real);
215 void HandleArenaPreparation(bool apply, bool Real);
216 void HandleAuraConvertRune(bool apply, bool Real);
217 void HandleAuraIncreaseBaseHealthPercent(bool Apply, bool Real);
218 void HandleNoReagentUseAura(bool Apply, bool Real);
219 void HandlePhase(bool Apply, bool Real);
220 void HandleModTargetArmorPct(bool Apply, bool Real);
221 void HandleAuraModAllCritChance(bool Apply, bool Real);
222 void HandleAllowOnlyAbility(bool Apply, bool Real);
224 virtual ~Aura();
226 void SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue);
227 Modifier* GetModifier() { return &m_modifier; }
228 Modifier const* GetModifier() const { return &m_modifier; }
229 int32 GetMiscValue() const { return m_spellProto->EffectMiscValue[m_effIndex]; }
230 int32 GetMiscBValue() const { return m_spellProto->EffectMiscValueB[m_effIndex]; }
232 SpellEntry const* GetSpellProto() const { return m_spellProto; }
233 uint32 GetId() const{ return m_spellProto->Id; }
234 uint64 GetCastItemGUID() const { return m_castItemGuid; }
235 SpellEffectIndex GetEffIndex() const{ return m_effIndex; }
236 int32 GetBasePoints() const { return m_currentBasePoints; }
238 int32 GetAuraMaxDuration() const { return m_maxduration; }
239 void SetAuraMaxDuration(int32 duration);
240 int32 GetAuraDuration() const { return m_duration; }
241 void SetAuraDuration(int32 duration) { m_duration = duration; }
242 time_t GetAuraApplyTime() const { return m_applyTime; }
243 uint32 GetAuraTicks() const { return m_periodicTick; }
244 uint32 GetAuraMaxTicks() const { return m_maxduration > 0 && m_modifier.periodictime > 0 ? m_maxduration / m_modifier.periodictime : 0; }
246 uint64 const& GetCasterGUID() const { return m_caster_guid; }
247 Unit* GetCaster() const;
248 Unit* GetTarget() const { return m_target; }
249 void SetTarget(Unit* target) { m_target = target; }
250 void SetLoadedState(uint64 caster_guid,int32 damage,int32 maxduration,int32 duration,int32 charges)
252 m_caster_guid = caster_guid;
253 m_modifier.m_amount = damage;
254 SetAuraMaxDuration(maxduration);
255 SetAuraDuration(duration);
256 m_procCharges = charges;
258 if(uint32 maxticks = GetAuraMaxTicks())
259 m_periodicTick = maxticks - m_duration / m_modifier.periodictime;
262 uint8 GetAuraSlot() const { return m_auraSlot; }
263 void SetAuraSlot(uint8 slot) { m_auraSlot = slot; }
264 uint8 GetAuraFlags() const { return m_auraFlags; }
265 void SetAuraFlags(uint8 flags) { m_auraFlags = flags; }
266 uint8 GetAuraLevel() const { return m_auraLevel; }
267 void SetAuraLevel(uint8 level) { m_auraLevel = level; }
268 uint8 GetAuraCharges() const { return m_procCharges; }
269 void SetAuraCharges(uint8 charges)
271 if (m_procCharges == charges)
272 return;
273 m_procCharges = charges;
274 SendAuraUpdate(false);
276 bool DropAuraCharge() // return true if last charge dropped
278 if (m_procCharges == 0)
279 return false;
281 // exist spells that have maxStack > 1 and m_procCharges > 0 (==1 in fact)
282 // all like stacks have 1 value in one from this fields
283 // so return true for allow remove one aura from stacks as expired
284 if (GetStackAmount() > 1)
285 return true;
287 m_procCharges--;
288 SendAuraUpdate(false);
289 return m_procCharges == 0;
292 void UnregisterSingleCastAura();
294 void SetAura(bool remove) { m_target->SetVisibleAura(m_auraSlot, remove ? 0 : GetId()); }
295 void SendAuraUpdate(bool remove);
297 uint8 GetStackAmount() {return m_stackAmount;}
298 void SetStackAmount(uint8 num);
299 bool modStackAmount(int32 num); // return true if last charge dropped
300 void RefreshAura();
302 bool IsPositive() { return m_positive; }
303 void SetNegative() { m_positive = false; }
304 void SetPositive() { m_positive = true; }
306 bool IsPermanent() const { return m_permanent; }
307 bool IsAreaAura() const { return m_isAreaAura; }
308 bool IsPeriodic() const { return m_isPeriodic; }
309 bool IsPassive() const { return m_isPassive; }
310 bool IsPersistent() const { return m_isPersistent; }
311 bool IsDeathPersistent() const { return m_isDeathPersist; }
312 bool IsRemovedOnShapeLost() const { return m_isRemovedOnShapeLost; }
313 bool IsInUse() const { return m_in_use;}
314 bool IsDeleted() const { return m_deleted;}
316 void SetInUse(bool state)
318 if(state)
319 ++m_in_use;
320 else
322 if(m_in_use)
323 --m_in_use;
326 void ApplyModifier(bool apply, bool Real = false);
328 void UpdateAura(uint32 diff) { SetInUse(true); Update(diff); SetInUse(false); }
329 void _AddAura();
330 bool _RemoveAura();
332 bool IsSingleTarget() {return m_isSingleTargetAura;}
333 void SetIsSingleTarget(bool val) { m_isSingleTargetAura = val;}
335 void SetRemoveMode(AuraRemoveMode mode) { m_removeMode = mode; }
337 virtual Unit* GetTriggerTarget() const { return m_target; }
339 // add/remove SPELL_AURA_MOD_SHAPESHIFT (36) linked auras
340 void HandleShapeshiftBoosts(bool apply);
341 void HandleSpellSpecificBoosts(bool apply);
343 // Allow Apply Aura Handler to modify and access m_AuraDRGroup
344 void setDiminishGroup(DiminishingGroup group) { m_AuraDRGroup = group; }
345 DiminishingGroup getDiminishGroup() const { return m_AuraDRGroup; }
347 void TriggerSpell();
348 void TriggerSpellWithValue();
350 uint32 const *getAuraSpellClassMask() const { return m_spellProto->GetEffectSpellClassMask(m_effIndex); }
351 bool isAffectedOnSpell(SpellEntry const *spell) const;
352 bool isWeaponBuffCoexistableWith(Aura* ref);
353 protected:
354 Aura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
356 // must be called only from Aura::UpdateAura
357 virtual void Update(uint32 diff);
359 // must be called only from Aura*::Update
360 void PeriodicTick();
361 void PeriodicDummyTick();
363 bool IsCritFromAbilityAura(Unit* caster, uint32& damage);
364 void ReapplyAffectedPassiveAuras();
366 Modifier m_modifier;
367 SpellModifier *m_spellmod;
369 SpellEntry const *m_spellProto;
370 Unit* m_target;
371 uint64 m_caster_guid;
372 uint64 m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted
373 time_t m_applyTime;
375 int32 m_currentBasePoints; // cache SpellEntry::CalculateSimpleValue and use for set custom base points
376 int32 m_maxduration; // Max aura duration
377 int32 m_duration; // Current time
378 int32 m_timeCla; // Timer for power per sec calcultion
379 int32 m_periodicTimer; // Timer for periodic auras
380 uint32 m_periodicTick; // Tick count pass (including current if use in tick code) from aura apply, used for some tick count dependent aura effects
382 AuraRemoveMode m_removeMode:8; // Store info for know remove aura reason
383 DiminishingGroup m_AuraDRGroup:8; // Diminishing
385 SpellEffectIndex m_effIndex :8; // Aura effect index in spell
386 uint8 m_auraSlot; // Aura slot on unit (for show in client)
387 uint8 m_auraFlags; // Aura info flag (for send data to client)
388 uint8 m_auraLevel; // Aura level (store caster level for correct show level dep amount)
389 uint8 m_procCharges; // Aura charges (0 for infinite)
390 uint8 m_stackAmount; // Aura stack amount
392 bool m_positive:1;
393 bool m_permanent:1;
394 bool m_isPeriodic:1;
395 bool m_isAreaAura:1;
396 bool m_isPassive:1;
397 bool m_isPersistent:1;
398 bool m_isDeathPersist:1;
399 bool m_isRemovedOnShapeLost:1;
400 bool m_deleted:1; // true if RemoveAura(iterator) called while in Aura::ApplyModifier call (added to Unit::m_deletedAuras)
401 bool m_isSingleTargetAura:1; // true if it's a single target spell and registered at caster - can change at spell steal for example
403 uint32 m_in_use; // > 0 while in Aura::ApplyModifier call/Aura::Update/etc
404 private:
405 void CleanupTriggeredSpells();
406 bool IsNeedVisibleSlot(Unit const* caster) const; // helper for check req. visibility slot
407 void ReapplyAffectedPassiveAuras(Unit* target, bool owner_mode);
410 class MANGOS_DLL_SPEC AreaAura : public Aura
412 public:
413 AreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
414 ~AreaAura();
415 protected:
416 void Update(uint32 diff);
417 private:
418 float m_radius;
419 AreaAuraType m_areaAuraType;
422 class MANGOS_DLL_SPEC PersistentAreaAura : public Aura
424 public:
425 PersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
426 ~PersistentAreaAura();
427 protected:
428 void Update(uint32 diff);
431 class MANGOS_DLL_SPEC SingleEnemyTargetAura : public Aura
433 friend Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem);
435 public:
436 ~SingleEnemyTargetAura();
437 Unit* GetTriggerTarget() const;
439 protected:
440 SingleEnemyTargetAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
441 uint64 m_casters_target_guid;
444 Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
445 #endif