[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / Spell.h
blob2d2367028f856909787f98be24b769f80120e7cd
1 /*
2 * Copyright (C) 2005-2008 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 #ifndef __SPELL_H
20 #define __SPELL_H
22 #include "GridDefines.h"
24 class WorldSession;
25 class Unit;
26 class DynamicObj;
27 class Player;
28 class GameObject;
29 class Group;
30 class Aura;
32 enum SpellCastTargetFlags
34 /*TARGET_FLAG_NONE = 0x0000,
35 TARGET_FLAG_SWIMMER = 0x0002,
36 TARGET_FLAG_ITEM = 0x0010,
37 TARGET_FLAG_SOURCE_AREA = 0x0020,
38 TARGET_FLAG_DEST_AREA = 0x0040,
39 TARGET_FLAG_UNKNOWN = 0x0080,
40 TARGET_FLAG_SELF = 0x0100,
41 TARGET_FLAG_PVP_CORPSE = 0x0200,
42 TARGET_FLAG_MASS_SPIRIT_HEAL = 0x0400,
43 TARGET_FLAG_BEAST_CORPSE = 0x0402,
44 TARGET_FLAG_OBJECT = 0x4000,
45 TARGET_FLAG_RESURRECTABLE = 0x8000*/
47 TARGET_FLAG_SELF = 0x00000000,
48 TARGET_FLAG_UNUSED1 = 0x00000001, // not used in any spells as of 3.0.3 (can be set dynamically)
49 TARGET_FLAG_UNIT = 0x00000002, // pguid
50 TARGET_FLAG_UNUSED2 = 0x00000004, // not used in any spells as of 3.0.3 (can be set dynamically)
51 TARGET_FLAG_UNUSED3 = 0x00000008, // not used in any spells as of 3.0.3 (can be set dynamically)
52 TARGET_FLAG_ITEM = 0x00000010, // pguid
53 TARGET_FLAG_SOURCE_LOCATION = 0x00000020, // 3 float
54 TARGET_FLAG_DEST_LOCATION = 0x00000040, // 3 float
55 TARGET_FLAG_OBJECT_UNK = 0x00000080, // used in 7 spells only
56 TARGET_FLAG_UNIT_UNK = 0x00000100, // looks like self target (480 spells)
57 TARGET_FLAG_PVP_CORPSE = 0x00000200, // pguid
58 TARGET_FLAG_UNIT_CORPSE = 0x00000400, // 10 spells (gathering professions)
59 TARGET_FLAG_OBJECT = 0x00000800, // pguid, 2 spells
60 TARGET_FLAG_TRADE_ITEM = 0x00001000, // pguid, 0 spells
61 TARGET_FLAG_STRING = 0x00002000, // string, 0 spells
62 TARGET_FLAG_UNK1 = 0x00004000, // 199 spells, opening object/lock
63 TARGET_FLAG_CORPSE = 0x00008000, // pguid, resurrection spells
64 TARGET_FLAG_UNK2 = 0x00010000, // pguid, not used in any spells as of 3.0.3 (can be set dynamically)
65 TARGET_FLAG_GLYPH = 0x00020000 // used in glyph spells
68 enum SpellCastFlags
70 CAST_FLAG_NONE = 0x00000000,
71 CAST_FLAG_UNKNOWN0 = 0x00000001, // may be pending spell cast
72 CAST_FLAG_UNKNOWN1 = 0x00000002,
73 CAST_FLAG_UNKNOWN11 = 0x00000004,
74 CAST_FLAG_UNKNOWN12 = 0x00000008,
75 CAST_FLAG_UNKNOWN2 = 0x00000010,
76 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
77 CAST_FLAG_UNKNOWN8 = 0x00000040,
78 CAST_FLAG_UNKNOWN9 = 0x00000080,
79 CAST_FLAG_UNKNOWN3 = 0x00000100,
80 CAST_FLAG_UNKNOWN13 = 0x00000200,
81 CAST_FLAG_UNKNOWN14 = 0x00000400,
82 CAST_FLAG_UNKNOWN6 = 0x00000800, // wotlk, trigger rune cooldown
83 CAST_FLAG_UNKNOWN15 = 0x00001000,
84 CAST_FLAG_UNKNOWN16 = 0x00002000,
85 CAST_FLAG_UNKNOWN17 = 0x00004000,
86 CAST_FLAG_UNKNOWN18 = 0x00008000,
87 CAST_FLAG_UNKNOWN19 = 0x00010000,
88 CAST_FLAG_UNKNOWN4 = 0x00020000, // wotlk
89 CAST_FLAG_UNKNOWN10 = 0x00040000,
90 CAST_FLAG_UNKNOWN5 = 0x00080000, // wotlk
91 CAST_FLAG_UNKNOWN20 = 0x00100000,
92 CAST_FLAG_UNKNOWN7 = 0x00200000 // wotlk, rune cooldown list
95 enum SpellNotifyPushType
97 PUSH_IN_FRONT,
98 PUSH_IN_BACK,
99 PUSH_SELF_CENTER,
100 PUSH_DEST_CENTER,
101 PUSH_TARGET_CENTER
104 bool IsQuestTameSpell(uint32 spellId);
106 namespace MaNGOS
108 struct SpellNotifierPlayer;
109 struct SpellNotifierCreatureAndPlayer;
112 class SpellCastTargets
114 public:
115 SpellCastTargets();
116 ~SpellCastTargets();
118 bool read ( WorldPacket * data, Unit *caster );
119 void write ( WorldPacket * data );
121 SpellCastTargets& operator=(const SpellCastTargets &target)
123 m_unitTarget = target.m_unitTarget;
124 m_itemTarget = target.m_itemTarget;
125 m_GOTarget = target.m_GOTarget;
127 m_unitTargetGUID = target.m_unitTargetGUID;
128 m_GOTargetGUID = target.m_GOTargetGUID;
129 m_CorpseTargetGUID = target.m_CorpseTargetGUID;
130 m_itemTargetGUID = target.m_itemTargetGUID;
132 m_itemTargetEntry = target.m_itemTargetEntry;
134 m_srcX = target.m_srcX;
135 m_srcY = target.m_srcY;
136 m_srcZ = target.m_srcZ;
138 m_destX = target.m_destX;
139 m_destY = target.m_destY;
140 m_destZ = target.m_destZ;
142 m_strTarget = target.m_strTarget;
144 m_targetMask = target.m_targetMask;
146 return *this;
149 uint64 getUnitTargetGUID() const { return m_unitTargetGUID; }
150 Unit *getUnitTarget() const { return m_unitTarget; }
151 void setUnitTarget(Unit *target);
152 void setDestination(float x, float y, float z);
154 uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
155 GameObject *getGOTarget() const { return m_GOTarget; }
156 void setGOTarget(GameObject *target);
158 uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
159 void setCorpseTarget(Corpse* corpse);
160 uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
161 Item* getItemTarget() const { return m_itemTarget; }
162 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
163 void setItemTarget(Item* item);
164 void updateTradeSlotItem()
166 if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
168 m_itemTargetGUID = m_itemTarget->GetGUID();
169 m_itemTargetEntry = m_itemTarget->GetEntry();
173 bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
175 void Update(Unit* caster);
177 float m_srcX, m_srcY, m_srcZ;
178 float m_destX, m_destY, m_destZ;
179 std::string m_strTarget;
181 uint32 m_targetMask;
182 private:
183 // objects (can be used at spell creating and after Update at casting
184 Unit *m_unitTarget;
185 GameObject *m_GOTarget;
186 Item *m_itemTarget;
188 // object GUID/etc, can be used always
189 uint64 m_unitTargetGUID;
190 uint64 m_GOTargetGUID;
191 uint64 m_CorpseTargetGUID;
192 uint64 m_itemTargetGUID;
193 uint32 m_itemTargetEntry;
196 enum SpellState
198 SPELL_STATE_NULL = 0,
199 SPELL_STATE_PREPARING = 1,
200 SPELL_STATE_CASTING = 2,
201 SPELL_STATE_FINISHED = 3,
202 SPELL_STATE_IDLE = 4,
203 SPELL_STATE_DELAYED = 5
206 #define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL 1000
208 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
210 class Spell
212 friend struct MaNGOS::SpellNotifierPlayer;
213 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
214 public:
216 void EffectNULL(uint32 );
217 void EffectUnused(uint32 );
218 void EffectDistract(uint32 i);
219 void EffectPull(uint32 i);
220 void EffectSchoolDMG(uint32 i);
221 void EffectEnvirinmentalDMG(uint32 i);
222 void EffectInstaKill(uint32 i);
223 void EffectDummy(uint32 i);
224 void EffectTeleportUnits(uint32 i);
225 void EffectApplyAura(uint32 i);
226 void EffectSendEvent(uint32 i);
227 void EffectPowerBurn(uint32 i);
228 void EffectPowerDrain(uint32 i);
229 void EffectHeal(uint32 i);
230 void EffectHealthLeech(uint32 i);
231 void EffectQuestComplete(uint32 i);
232 void EffectCreateItem(uint32 i);
233 void EffectPersistentAA(uint32 i);
234 void EffectEnergize(uint32 i);
235 void EffectOpenLock(uint32 i);
236 void EffectSummonChangeItem(uint32 i);
237 void EffectOpenSecretSafe(uint32 i);
238 void EffectProficiency(uint32 i);
239 void EffectApplyAreaAura(uint32 i);
240 void EffectSummonType(uint32 i);
241 void EffectSummon(uint32 i);
242 void EffectLearnSpell(uint32 i);
243 void EffectDispel(uint32 i);
244 void EffectDualWield(uint32 i);
245 void EffectPickPocket(uint32 i);
246 void EffectAddFarsight(uint32 i);
247 void EffectSummonWild(uint32 i);
248 void EffectSummonGuardian(uint32 i);
249 void EffectHealMechanical(uint32 i);
250 void EffectTeleUnitsFaceCaster(uint32 i);
251 void EffectLearnSkill(uint32 i);
252 void EffectAddHonor(uint32 i);
253 void EffectTradeSkill(uint32 i);
254 void EffectEnchantItemPerm(uint32 i);
255 void EffectEnchantItemTmp(uint32 i);
256 void EffectTameCreature(uint32 i);
257 void EffectSummonPet(uint32 i);
258 void EffectLearnPetSpell(uint32 i);
259 void EffectWeaponDmg(uint32 i);
260 void EffectForceCast(uint32 i);
261 void EffectTriggerSpell(uint32 i);
262 void EffectTriggerMissileSpell(uint32 i);
263 void EffectThreat(uint32 i);
264 void EffectHealMaxHealth(uint32 i);
265 void EffectInterruptCast(uint32 i);
266 void EffectSummonObjectWild(uint32 i);
267 void EffectScriptEffect(uint32 i);
268 void EffectSanctuary(uint32 i);
269 void EffectAddComboPoints(uint32 i);
270 void EffectDuel(uint32 i);
271 void EffectStuck(uint32 i);
272 void EffectSummonPlayer(uint32 i);
273 void EffectActivateObject(uint32 i);
274 void EffectApplyGlyph(uint32 i);
275 void EffectSummonTotem(uint32 i);
276 void EffectEnchantHeldItem(uint32 i);
277 void EffectSummonObject(uint32 i);
278 void EffectResurrect(uint32 i);
279 void EffectParry(uint32 i);
280 void EffectBlock(uint32 i);
281 void EffectMomentMove(uint32 i);
282 void EffectTransmitted(uint32 i);
283 void EffectDisEnchant(uint32 i);
284 void EffectInebriate(uint32 i);
285 void EffectFeedPet(uint32 i);
286 void EffectDismissPet(uint32 i);
287 void EffectReputation(uint32 i);
288 void EffectSelfResurrect(uint32 i);
289 void EffectSkinning(uint32 i);
290 void EffectCharge(uint32 i);
291 void EffectProspecting(uint32 i);
292 void EffectMilling(uint32 i);
293 void EffectSendTaxi(uint32 i);
294 void EffectSummonCritter(uint32 i);
295 void EffectKnockBack(uint32 i);
296 void EffectPlayerPull(uint32 i);
297 void EffectDispelMechanic(uint32 i);
298 void EffectSummonDeadPet(uint32 i);
299 void EffectDestroyAllTotems(uint32 i);
300 void EffectDurabilityDamage(uint32 i);
301 void EffectSkill(uint32 i);
302 void EffectTaunt(uint32 i);
303 void EffectDurabilityDamagePCT(uint32 i);
304 void EffectModifyThreatPercent(uint32 i);
305 void EffectResurrectNew(uint32 i);
306 void EffectAddExtraAttacks(uint32 i);
307 void EffectSpiritHeal(uint32 i);
308 void EffectSkinPlayerCorpse(uint32 i);
309 void EffectSummonDemon(uint32 i);
310 void EffectStealBeneficialBuff(uint32 i);
311 void EffectUnlearnSpecialization(uint32 i);
312 void EffectHealPct(uint32 i);
313 void EffectEnergisePct(uint32 i);
314 void EffectTriggerSpellWithValue(uint32 i);
315 void EffectTriggerRitualOfSummoning(uint32 i);
316 void EffectKillCredit(uint32 i);
317 void EffectQuestFail(uint32 i);
318 void EffectActivateRune(uint32 i);
319 void EffectTitanGrip(uint32 i);
321 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
322 ~Spell();
324 void prepare(SpellCastTargets * targets, Aura* triggeredByAura = NULL);
325 void cancel();
326 void update(uint32 difftime);
327 void cast(bool skipCheck = false);
328 void finish(bool ok = true);
329 void TakePower();
330 uint8 CheckRuneCost(uint32 runeCostID);
331 void TakeRunePower();
332 void TakeReagents();
333 void TakeCastItem();
334 void TriggerSpell();
335 uint8 CanCast(bool strict);
336 int16 PetCanCast(Unit* target);
337 bool CanAutoCast(Unit* target);
339 // handlers
340 void handle_immediate();
341 uint64 handle_delayed(uint64 t_offset);
342 // handler helpers
343 void _handle_immediate_phase();
344 void _handle_finish_phase();
346 uint8 CheckItems();
347 uint8 CheckRange(bool strict);
348 uint8 CheckPower();
349 uint8 CheckCasterAuras() const;
351 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
352 int32 CalculatePowerCost();
354 bool HaveTargetsForEffect(uint8 effect) const;
355 void Delayed();
356 void DelayedChannel();
357 inline uint32 getState() const { return m_spellState; }
358 void setState(uint32 state) { m_spellState = state; }
360 void DoCreateItem(uint32 i, uint32 itemtype);
362 void WriteSpellGoTargets( WorldPacket * data );
363 void WriteAmmoToPacket( WorldPacket * data );
364 void FillTargetMap();
366 void SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap);
368 Unit* SelectMagnetTarget();
369 bool CheckTarget( Unit* target, uint32 eff );
371 void SendCastResult(uint8 result);
372 void SendSpellStart();
373 void SendSpellGo();
374 void SendSpellCooldown();
375 void SendLogExecute();
376 void SendInterrupted(uint8 result);
377 void SendChannelUpdate(uint32 time);
378 void SendChannelStart(uint32 duration);
379 void SendResurrectRequest(Player* target);
380 void SendPlaySpellVisual(uint32 SpellID);
382 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
383 void HandleThreatSpells(uint32 spellId);
384 //void HandleAddAura(Unit* Target);
386 SpellEntry const* m_spellInfo;
387 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
388 Item* m_CastItem;
389 uint8 m_cast_count;
390 uint32 m_glyphIndex;
391 SpellCastTargets m_targets;
393 int32 GetCastTime() const { return m_casttime; }
394 bool IsAutoRepeat() const { return m_autoRepeat; }
395 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
396 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
397 bool IsNextMeleeSwingSpell() const
399 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
401 bool IsRangedSpell() const
403 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
405 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
406 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
407 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
409 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
410 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
411 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
412 uint64 GetDelayStart() const { return m_delayStart; }
413 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
414 uint64 GetDelayMoment() const { return m_delayMoment; }
416 bool IsNeedSendToClient() const;
418 CurrentSpellTypes GetCurrentContainer();
420 Unit* GetCaster() const { return m_caster; }
421 Unit* GetOriginalCaster() const { return m_originalCaster; }
422 int32 GetPowerCost() const { return m_powerCost; }
424 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
426 bool IsAffectedByAura(Aura *aura);
428 bool CheckTargetCreatureType(Unit* target) const;
430 void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
432 void CleanupTargetList();
433 protected:
435 void SendLoot(uint64 guid, LootType loottype);
437 Unit* m_caster;
439 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
440 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
441 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
443 Spell** m_selfContainer; // pointer to our spell container (if applicable)
444 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
446 //Spell data
447 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
448 WeaponAttackType m_attackType; // For weapon based attack
449 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
450 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
451 bool m_canReflect; // can reflect this spell?
452 bool m_autoRepeat;
453 uint8 m_runesState;
455 uint8 m_delayAtDamageCount;
456 int32 GetNextDelayAtDamageMsTime() { return m_delayAtDamageCount < 5 ? 1000 - (m_delayAtDamageCount++)* 200 : 200; }
458 // Delayed spells system
459 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
460 uint64 m_delayMoment; // moment of next delay call, used internally
461 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
463 // These vars are used in both delayed spell system and modified immediate spell system
464 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
465 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
466 bool m_needSpellLog; // need to send spell log?
467 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
468 float m_damageMultipliers[3]; // by effect: damage multiplier
470 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
471 Unit* unitTarget;
472 Item* itemTarget;
473 GameObject* gameObjTarget;
474 int32 damage;
476 // this is set in Spell Hit, but used in Apply Aura handler
477 DiminishingLevels m_diminishLevel;
478 DiminishingGroup m_diminishGroup;
480 // -------------------------------------------
481 GameObject* focusObject;
483 // Damage and healing in effects need just calculate
484 int32 m_damage; // Damge in effects count here
485 int32 m_healing; // Healing in effects count here
486 int32 m_healthLeech; // Health leech in effects for all targets count here
488 //******************************************
489 // Spell trigger system
490 //******************************************
491 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
492 uint32 m_procAttacker; // Attacker trigger flags
493 uint32 m_procVictim; // Victim trigger flags
494 void prepareDataForTriggerSystem();
496 //*****************************************
497 // Spell target subsystem
498 //*****************************************
499 // Targets store structures and data
500 uint32 m_countOfHit;
501 uint32 m_countOfMiss;
502 struct TargetInfo
504 uint64 targetGUID;
505 uint64 timeDelay;
506 SpellMissInfo missCondition:8;
507 SpellMissInfo reflectResult:8;
508 uint8 effectMask:8;
509 bool processed:1;
511 std::list<TargetInfo> m_UniqueTargetInfo;
512 uint8 m_needAliveTargetMask; // Mask req. alive targets
514 struct GOTargetInfo
516 uint64 targetGUID;
517 uint64 timeDelay;
518 uint8 effectMask:8;
519 bool processed:1;
521 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
523 struct ItemTargetInfo
525 Item *item;
526 uint8 effectMask;
528 std::list<ItemTargetInfo> m_UniqueItemInfo;
530 void AddUnitTarget(Unit* target, uint32 effIndex);
531 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
532 void AddGOTarget(GameObject* target, uint32 effIndex);
533 void AddGOTarget(uint64 goGUID, uint32 effIndex);
534 void AddItemTarget(Item* target, uint32 effIndex);
535 void DoAllEffectOnTarget(TargetInfo *target);
536 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
537 void DoAllEffectOnTarget(GOTargetInfo *target);
538 void DoAllEffectOnTarget(ItemTargetInfo *target);
539 bool IsAliveUnitPresentInTargetList();
540 // -------------------------------------------
542 //List For Triggered Spells
543 typedef std::list<SpellEntry const*> TriggerSpells;
544 TriggerSpells m_TriggerSpells;
546 uint32 m_spellState;
547 uint32 m_timer;
549 float m_castPositionX;
550 float m_castPositionY;
551 float m_castPositionZ;
552 float m_castOrientation;
553 bool m_IsTriggeredSpell;
555 // if need this can be replaced by Aura copy
556 // we can't store original aura link to prevent access to deleted auras
557 // and in same time need aura data and after aura deleting.
558 SpellEntry const* m_triggeredByAuraSpell;
561 enum ReplenishType
563 REPLENISH_UNDEFINED = 0,
564 REPLENISH_HEALTH = 20,
565 REPLENISH_MANA = 21,
566 REPLENISH_RAGE = 22
569 enum SpellTargets
571 SPELL_TARGETS_HOSTILE,
572 SPELL_TARGETS_NOT_FRIENDLY,
573 SPELL_TARGETS_NOT_HOSTILE,
574 SPELL_TARGETS_FRIENDLY,
575 SPELL_TARGETS_AOE_DAMAGE
578 namespace MaNGOS
580 struct MANGOS_DLL_DECL SpellNotifierPlayer
582 std::list<Unit*> &i_data;
583 Spell &i_spell;
584 const uint32& i_index;
585 float i_radius;
586 Unit* i_originalCaster;
588 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
589 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
591 i_originalCaster = i_spell.GetOriginalCaster();
594 void Visit(PlayerMapType &m)
596 if(!i_originalCaster)
597 return;
599 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
601 Player * pPlayer = itr->getSource();
602 if( !pPlayer->isAlive() || pPlayer->isInFlight())
603 continue;
605 if( i_originalCaster->IsFriendlyTo(pPlayer) )
606 continue;
608 if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
609 i_data.push_back(pPlayer);
612 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
615 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
617 std::list<Unit*> *i_data;
618 Spell &i_spell;
619 const uint32& i_push_type;
620 float i_radius;
621 SpellTargets i_TargetType;
622 Unit* i_originalCaster;
624 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, const uint32 &type,
625 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
626 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
628 i_originalCaster = spell.GetOriginalCaster();
631 template<class T> inline void Visit(GridRefManager<T> &m)
633 assert(i_data);
635 if(!i_originalCaster)
636 return;
638 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
640 if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
641 continue;
643 switch (i_TargetType)
645 case SPELL_TARGETS_HOSTILE:
646 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
647 continue;
648 break;
649 case SPELL_TARGETS_NOT_FRIENDLY:
650 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
651 continue;
652 break;
653 case SPELL_TARGETS_NOT_HOSTILE:
654 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
655 continue;
656 break;
657 case SPELL_TARGETS_FRIENDLY:
658 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
659 continue;
660 break;
661 case SPELL_TARGETS_AOE_DAMAGE:
663 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
664 continue;
665 if(!itr->getSource()->isTargetableForAttack())
666 continue;
668 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
670 if( check->GetTypeId()==TYPEID_PLAYER )
672 if (check->IsFriendlyTo( itr->getSource() ))
673 continue;
675 else
677 if (!check->IsHostileTo( itr->getSource() ))
678 continue;
681 break;
682 default: continue;
685 switch(i_push_type)
687 case PUSH_IN_FRONT:
688 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
689 i_data->push_back(itr->getSource());
690 break;
691 case PUSH_IN_BACK:
692 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
693 i_data->push_back(itr->getSource());
694 break;
695 case PUSH_SELF_CENTER:
696 if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
697 i_data->push_back(itr->getSource());
698 break;
699 case PUSH_DEST_CENTER:
700 if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
701 i_data->push_back(itr->getSource());
702 break;
703 case PUSH_TARGET_CENTER:
704 if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
705 i_data->push_back(itr->getSource());
706 break;
711 #ifdef WIN32
712 template<> inline void Visit(CorpseMapType & ) {}
713 template<> inline void Visit(GameObjectMapType & ) {}
714 template<> inline void Visit(DynamicObjectMapType & ) {}
715 #endif
718 #ifndef WIN32
719 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
720 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
721 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
722 #endif
725 typedef void(Spell::*pEffect)(uint32 i);
727 class SpellEvent : public BasicEvent
729 public:
730 SpellEvent(Spell* spell);
731 virtual ~SpellEvent();
733 virtual bool Execute(uint64 e_time, uint32 p_time);
734 virtual void Abort(uint64 e_time);
735 virtual bool IsDeletable() const;
736 protected:
737 Spell* m_Spell;
739 #endif