[7768] Add check to prevent set homebind to instance map.
[AHbot.git] / src / game / SpellAuras.h
blobda920425cb75f0ea870447a0e8cc98b5e1762811
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
18 #ifndef MANGOS_SPELLAURAS_H
19 #define MANGOS_SPELLAURAS_H
21 #include "SpellAuraDefines.h"
23 struct Modifier
25 AuraType m_auraname;
26 int32 m_amount;
27 int32 m_miscvalue;
28 uint32 periodictime;
31 class Unit;
32 struct SpellEntry;
33 struct SpellModifier;
34 struct ProcTriggerSpell;
36 // forward decl
37 class Aura;
39 typedef void(Aura::*pAuraHandler)(bool Apply, bool Real);
40 // Real == true at aura add/remove
41 // Real == false at aura mod unapply/reapply; when adding/removing dependent aura/item/stat mods
43 // Code in aura handler can be guarded by if(Real) check if it should execution only at real add/remove of aura
45 // MAIN RULE: Code MUST NOT be guarded by if(Real) check if it modifies any stats
46 // (percent auras, stats mods, etc)
47 // Second rule: Code must be guarded by if(Real) check if it modifies object state (start/stop attack, send packets to client, etc)
49 // Other case choice: each code line moved under if(Real) check is mangos speedup,
50 // each setting object update field code line moved under if(Real) check is significant mangos speedup, and less server->client data sends
51 // each packet sending code moved under if(Real) check is _large_ mangos speedup, and lot less server->client data sends
53 class MANGOS_DLL_SPEC Aura
55 friend Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem);
57 public:
58 //aura handlers
59 void HandleNULL(bool, bool)
61 // NOT IMPLEMENTED
63 void HandleUnused(bool, bool)
65 // NOT USED BY ANY SPELL OR USELESS
67 void HandleNoImmediateEffect(bool, bool)
69 // aura not have immediate effect at add/remove and handled by ID in other code place
71 void HandleBindSight(bool Apply, bool Real);
72 void HandleModPossess(bool Apply, bool Real);
73 void HandlePeriodicDamage(bool Apply, bool Real);
74 void HandleAuraDummy(bool Apply, bool Real);
75 void HandleAuraPeriodicDummy(bool apply, bool Real);
76 void HandleModConfuse(bool Apply, bool Real);
77 void HandleModCharm(bool Apply, bool Real);
78 void HandleModFear(bool Apply, bool Real);
79 void HandlePeriodicHeal(bool Apply, bool Real);
80 void HandleModAttackSpeed(bool Apply, bool Real);
81 void HandleModMeleeRangedSpeedPct(bool apply, bool Real);
82 void HandleModCombatSpeedPct(bool apply, bool Real);
83 void HandleModThreat(bool Apply, bool Real);
84 void HandleModTaunt(bool Apply, bool Real);
85 void HandleFeignDeath(bool Apply, bool Real);
86 void HandleAuraModDisarm(bool Apply, bool Real);
87 void HandleAuraModStalked(bool Apply, bool Real);
88 void HandleAuraWaterWalk(bool Apply, bool Real);
89 void HandleAuraFeatherFall(bool Apply, bool Real);
90 void HandleAuraHover(bool Apply, bool Real);
91 void HandleAddModifier(bool Apply, bool Real);
92 void HandleAddTargetTrigger(bool Apply, bool Real);
93 void HandleAuraModStun(bool Apply, bool Real);
94 void HandleModDamageDone(bool Apply, bool Real);
95 void HandleAuraUntrackable(bool Apply, bool Real);
96 void HandleAuraEmpathy(bool Apply, bool Real);
97 void HandleModOffhandDamagePercent(bool apply, bool Real);
98 void HandleAuraModRangedAttackPower(bool Apply, bool Real);
99 void HandleAuraModIncreaseEnergyPercent(bool Apply, bool Real);
100 void HandleAuraModIncreaseHealthPercent(bool Apply, bool Real);
101 void HandleAuraModRegenInterrupt(bool Apply, bool Real);
102 void HandleHaste(bool Apply, bool Real);
103 void HandlePeriodicTriggerSpell(bool Apply, bool Real);
104 void HandlePeriodicTriggerSpellWithValue(bool apply, bool Real);
105 void HandlePeriodicEnergize(bool Apply, bool Real);
106 void HandleAuraModResistanceExclusive(bool Apply, bool Real);
107 void HandleAuraModPetTalentsPoints(bool Apply, bool Real);
108 void HandleModStealth(bool Apply, bool Real);
109 void HandleInvisibility(bool Apply, bool Real);
110 void HandleInvisibilityDetect(bool Apply, bool Real);
111 void HandleAuraModTotalHealthPercentRegen(bool Apply, bool Real);
112 void HandleAuraModTotalManaPercentRegen(bool Apply, bool Real);
113 void HandleAuraModResistance(bool Apply, bool Real);
114 void HandleAuraModRoot(bool Apply, bool Real);
115 void HandleAuraModSilence(bool Apply, bool Real);
116 void HandleAuraModStat(bool Apply, bool Real);
117 void HandleAuraModIncreaseSpeed(bool Apply, bool Real);
118 void HandleAuraModIncreaseMountedSpeed(bool Apply, bool Real);
119 void HandleAuraModIncreaseFlightSpeed(bool Apply, bool Real);
120 void HandleAuraModDecreaseSpeed(bool Apply, bool Real);
121 void HandleAuraModUseNormalSpeed(bool Apply, bool Real);
122 void HandleAuraModIncreaseHealth(bool Apply, bool Real);
123 void HandleAuraModIncreaseEnergy(bool Apply, bool Real);
124 void HandleAuraModShapeshift(bool Apply, bool Real);
125 void HandleAuraModEffectImmunity(bool Apply, bool Real);
126 void HandleAuraModStateImmunity(bool Apply, bool Real);
127 void HandleAuraModSchoolImmunity(bool Apply, bool Real);
128 void HandleAuraModDmgImmunity(bool Apply, bool Real);
129 void HandleAuraModDispelImmunity(bool Apply, bool Real);
130 void HandleAuraProcTriggerSpell(bool Apply, bool Real);
131 void HandleAuraTrackCreatures(bool Apply, bool Real);
132 void HandleAuraTrackResources(bool Apply, bool Real);
133 void HandleAuraModParryPercent(bool Apply, bool Real);
134 void HandleAuraModDodgePercent(bool Apply, bool Real);
135 void HandleAuraModBlockPercent(bool Apply, bool Real);
136 void HandleAuraModCritPercent(bool Apply, bool Real);
137 void HandlePeriodicLeech(bool Apply, bool Real);
138 void HandleModHitChance(bool Apply, bool Real);
139 void HandleModSpellHitChance(bool Apply, bool Real);
140 void HandleAuraModScale(bool Apply, bool Real);
141 void HandlePeriodicManaLeech(bool Apply, bool Real);
142 void HandlePeriodicHealthFunnel(bool apply, bool Real);
143 void HandleModCastingSpeed(bool Apply, bool Real);
144 void HandleAuraMounted(bool Apply, bool Real);
145 void HandleWaterBreathing(bool Apply, bool Real);
146 void HandleModBaseResistance(bool Apply, bool Real);
147 void HandleModRegen(bool Apply, bool Real);
148 void HandleModPowerRegen(bool Apply, bool Real);
149 void HandleModPowerRegenPCT(bool Apply, bool Real);
150 void HandleChannelDeathItem(bool Apply, bool Real);
151 void HandlePeriodicDamagePCT(bool Apply, bool Real);
152 void HandleAuraModAttackPower(bool Apply, bool Real);
153 void HandleAuraTransform(bool Apply, bool Real);
154 void HandleModSpellCritChance(bool Apply, bool Real);
155 void HandleAuraModIncreaseSwimSpeed(bool Apply, bool Real);
156 void HandleModPowerCostPCT(bool Apply, bool Real);
157 void HandleModPowerCost(bool Apply, bool Real);
158 void HandleFarSight(bool Apply, bool Real);
159 void HandleModPossessPet(bool Apply, bool Real);
160 void HandleModMechanicImmunity(bool Apply, bool Real);
161 void HandleAuraModSkill(bool Apply, bool Real);
162 void HandleModDamagePercentDone(bool Apply, bool Real);
163 void HandleModPercentStat(bool Apply, bool Real);
164 void HandleModResistancePercent(bool Apply, bool Real);
165 void HandleAuraModBaseResistancePCT(bool Apply, bool Real);
166 void HandleModShieldBlockPCT(bool Apply, bool Real);
167 void HandleAuraTrackStealthed(bool Apply, bool Real);
168 void HandleModShieldBlock(bool Apply, bool Real);
169 void HandleForceReaction(bool Apply, bool Real);
170 void HandleAuraModRangedHaste(bool Apply, bool Real);
171 void HandleRangedAmmoHaste(bool Apply, bool Real);
172 void HandleModHealingDone(bool Apply, bool Real);
173 void HandleModTotalPercentStat(bool Apply, bool Real);
174 void HandleAuraModTotalThreat(bool Apply, bool Real);
175 void HandleModUnattackable(bool Apply, bool Real);
176 void HandleAuraModPacify(bool Apply, bool Real);
177 void HandleAuraGhost(bool Apply, bool Real);
178 void HandleAuraAllowFlight(bool Apply, bool Real);
179 void HandleModRating(bool apply, bool Real);
180 void HandleModRatingFromStat(bool apply, bool Real);
181 void HandleModTargetResistance(bool apply, bool Real);
182 void HandleAuraModAttackPowerPercent(bool apply, bool Real);
183 void HandleAuraModRangedAttackPowerPercent(bool apply, bool Real);
184 void HandleAuraModRangedAttackPowerOfStatPercent(bool apply, bool Real);
185 void HandleAuraModAttackPowerOfStatPercent(bool apply, bool Real);
186 void HandleSpiritOfRedemption(bool apply, bool Real);
187 void HandleModManaRegen(bool apply, bool Real);
188 void HandleComprehendLanguage(bool apply, bool Real);
189 void HandleShieldBlockValue(bool apply, bool Real);
190 void HandleModSpellCritChanceShool(bool apply, bool Real);
191 void HandleAuraRetainComboPoints(bool apply, bool Real);
192 void HandleModSpellDamagePercentFromStat(bool apply, bool Real);
193 void HandleModSpellHealingPercentFromStat(bool apply, bool Real);
194 void HandleAuraModDispelResist(bool apply, bool Real);
195 void HandleAuraControlVehicle(bool apply, bool Real);
196 void HandleModSpellDamagePercentFromAttackPower(bool apply, bool Real);
197 void HandleModSpellHealingPercentFromAttackPower(bool apply, bool Real);
198 void HandleAuraModPacifyAndSilence(bool Apply, bool Real);
199 void HandleAuraModIncreaseMaxHealth(bool apply, bool Real);
200 void HandleAuraModExpertise(bool apply, bool Real);
201 void HandleForceMoveForward(bool apply, bool Real);
202 void HandleAuraModResistenceOfStatPercent(bool apply, bool Real);
203 void HandleAuraPowerBurn(bool apply, bool Real);
204 void HandleSchoolAbsorb(bool apply, bool Real);
205 void HandlePreventFleeing(bool apply, bool Real);
206 void HandleManaShield(bool apply, bool Real);
207 void HandleArenaPreparation(bool apply, bool Real);
208 void HandleAuraConvertRune(bool apply, bool Real);
209 void HandleAuraIncreaseBaseHealthPercent(bool Apply, bool Real);
210 void HandleNoReagentUseAura(bool Apply, bool Real);
211 void HandlePhase(bool Apply, bool Real);
213 virtual ~Aura();
215 void SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue);
216 Modifier* GetModifier() {return &m_modifier;}
217 int32 GetMiscValue() {return m_spellProto->EffectMiscValue[m_effIndex];}
218 int32 GetMiscBValue() {return m_spellProto->EffectMiscValueB[m_effIndex];}
220 SpellEntry const* GetSpellProto() const { return m_spellProto; }
221 uint32 GetId() const{ return m_spellProto->Id; }
222 uint64 GetCastItemGUID() const { return m_castItemGuid; }
223 uint32 GetEffIndex() const{ return m_effIndex; }
224 int32 GetBasePoints() const { return m_currentBasePoints; }
226 int32 GetAuraMaxDuration() const { return m_maxduration; }
227 void SetAuraMaxDuration(int32 duration) { m_maxduration = duration; }
228 int32 GetAuraDuration() const { return m_duration; }
229 void SetAuraDuration(int32 duration) { m_duration = duration; }
230 time_t GetAuraApplyTime() { return m_applyTime; }
232 SpellModifier *getAuraSpellMod() {return m_spellmod; }
234 uint64 const& GetCasterGUID() const { return m_caster_guid; }
235 Unit* GetCaster() const;
236 Unit* GetTarget() const { return m_target; }
237 void SetTarget(Unit* target) { m_target = target; }
238 void SetLoadedState(uint64 caster_guid,int32 damage,int32 maxduration,int32 duration,int32 charges)
240 m_caster_guid = caster_guid;
241 m_modifier.m_amount = damage;
242 m_maxduration = maxduration;
243 m_duration = duration;
244 m_procCharges = charges;
247 uint8 GetAuraSlot() const { return m_auraSlot; }
248 void SetAuraSlot(uint8 slot) { m_auraSlot = slot; }
249 uint8 GetAuraFlags() const { return m_auraFlags; }
250 void SetAuraFlags(uint8 flags) { m_auraFlags = flags; }
251 uint8 GetAuraLevel() const { return m_auraLevel; }
252 void SetAuraLevel(uint8 level) { m_auraLevel = level; }
253 uint8 GetAuraCharges() const { return m_procCharges; }
254 void SetAuraCharges(uint8 charges)
256 if (m_procCharges == charges)
257 return;
258 m_procCharges = charges;
259 SendAuraUpdate(false);
261 bool DropAuraCharge() // return true if last charge dropped
263 if (m_procCharges == 0)
264 return false;
265 m_procCharges--;
266 SendAuraUpdate(false);
267 return m_procCharges == 0;
270 void UnregisterSingleCastAura();
272 void SetAura(bool remove) { m_target->SetVisibleAura(m_auraSlot, remove ? 0 : GetId()); }
273 void SendAuraUpdate(bool remove);
275 int8 GetStackAmount() {return m_stackAmount;}
276 void SetStackAmount(uint8 num);
277 bool modStackAmount(int32 num); // return true if last charge dropped
278 void RefreshAura();
280 bool IsPositive() { return m_positive; }
281 void SetNegative() { m_positive = false; }
282 void SetPositive() { m_positive = true; }
284 bool IsPermanent() const { return m_permanent; }
285 bool IsAreaAura() const { return m_isAreaAura; }
286 bool IsPeriodic() const { return m_isPeriodic; }
287 bool IsPassive() const { return m_isPassive; }
288 bool IsPersistent() const { return m_isPersistent; }
289 bool IsDeathPersistent() const { return m_isDeathPersist; }
290 bool IsRemovedOnShapeLost() const { return m_isRemovedOnShapeLost; }
291 bool IsInUse() const { return m_in_use;}
293 virtual void Update(uint32 diff);
294 void ApplyModifier(bool apply, bool Real = false);
296 void _AddAura();
297 void _RemoveAura();
299 bool IsUpdated() { return m_updated; }
300 void SetUpdated(bool val) { m_updated = val; }
302 bool IsSingleTarget() {return m_isSingleTargetAura;}
303 void SetIsSingleTarget(bool val) { m_isSingleTargetAura = val;}
305 void SetRemoveMode(AuraRemoveMode mode) { m_removeMode = mode; }
307 virtual Unit* GetTriggerTarget() const { return m_target; }
309 // add/remove SPELL_AURA_MOD_SHAPESHIFT (36) linked auras
310 void HandleShapeshiftBoosts(bool apply);
312 // Allow Apply Aura Handler to modify and access m_AuraDRGroup
313 void setDiminishGroup(DiminishingGroup group) { m_AuraDRGroup = group; }
314 DiminishingGroup getDiminishGroup() const { return m_AuraDRGroup; }
316 void TriggerSpell();
317 void TriggerSpellWithValue();
318 void PeriodicTick();
319 void PeriodicDummyTick();
321 uint32 const *getAuraSpellClassMask() const { return m_spellProto->EffectSpellClassMaskA + m_effIndex * 3; }
322 bool isAffectedOnSpell(SpellEntry const *spell) const;
323 protected:
324 Aura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
326 Modifier m_modifier;
327 SpellModifier *m_spellmod;
329 SpellEntry const *m_spellProto;
330 Unit* m_target;
331 uint64 m_caster_guid;
332 uint64 m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted
333 time_t m_applyTime;
335 int32 m_currentBasePoints; // cache SpellEntry::EffectBasePoints and use for set custom base points
336 int32 m_maxduration; // Max aura duration
337 int32 m_duration; // Current time
338 int32 m_timeCla; // Timer for power per sec calcultion
339 int32 m_periodicTimer; // Timer for periodic auras
341 AuraRemoveMode m_removeMode:8; // Store info for know remove aura reason
342 DiminishingGroup m_AuraDRGroup:8; // Diminishing
344 uint8 m_effIndex; // Aura effect index in spell
345 uint8 m_auraSlot; // Aura slot on unit (for show in client)
346 uint8 m_auraFlags; // Aura info flag (for send data to client)
347 uint8 m_auraLevel; // Aura level (store caster level for correct show level dep amount)
348 uint8 m_procCharges; // Aura charges (0 for infinite)
349 uint8 m_stackAmount; // Aura stack amount
351 bool m_positive:1;
352 bool m_permanent:1;
353 bool m_isPeriodic:1;
354 bool m_isAreaAura:1;
355 bool m_isPassive:1;
356 bool m_isPersistent:1;
357 bool m_isDeathPersist:1;
358 bool m_isRemovedOnShapeLost:1;
359 bool m_updated:1; // Prevent remove aura by stack if set
360 bool m_in_use:1; // true while in Aura::ApplyModifier call
361 bool m_isSingleTargetAura:1; // true if it's a single target spell and registered at caster - can change at spell steal for example
363 private:
364 void CleanupTriggeredSpells();
367 class MANGOS_DLL_SPEC AreaAura : public Aura
369 public:
370 AreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
371 ~AreaAura();
372 void Update(uint32 diff);
373 private:
374 float m_radius;
375 AreaAuraType m_areaAuraType;
378 class MANGOS_DLL_SPEC PersistentAreaAura : public Aura
380 public:
381 PersistentAreaAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
382 ~PersistentAreaAura();
383 void Update(uint32 diff);
386 class MANGOS_DLL_SPEC SingleEnemyTargetAura : public Aura
388 friend Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster, Item* castItem);
390 public:
391 ~SingleEnemyTargetAura();
392 Unit* GetTriggerTarget() const;
394 protected:
395 SingleEnemyTargetAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
396 uint64 m_casters_target_guid;
399 Aura* CreateAura(SpellEntry const* spellproto, uint32 eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
400 #endif