Implement aura use in new version of racial trait 20550. Add unit stat mods for rune...
[getmangos.git] / src / game / Spell.h
blobac71da5b479806999f8b2472a7040cbb33112ac4
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);
320 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
321 ~Spell();
323 void prepare(SpellCastTargets * targets, Aura* triggeredByAura = NULL);
324 void cancel();
325 void update(uint32 difftime);
326 void cast(bool skipCheck = false);
327 void finish(bool ok = true);
328 void TakePower();
329 uint8 CheckRuneCost(uint32 runeCostID);
330 void TakeRunePower();
331 void TakeReagents();
332 void TakeCastItem();
333 void TriggerSpell();
334 uint8 CanCast(bool strict);
335 int16 PetCanCast(Unit* target);
336 bool CanAutoCast(Unit* target);
338 // handlers
339 void handle_immediate();
340 uint64 handle_delayed(uint64 t_offset);
341 // handler helpers
342 void _handle_immediate_phase();
343 void _handle_finish_phase();
345 uint8 CheckItems();
346 uint8 CheckRange(bool strict);
347 uint8 CheckPower();
348 uint8 CheckCasterAuras() const;
350 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
351 int32 CalculatePowerCost();
353 bool HaveTargetsForEffect(uint8 effect) const;
354 void Delayed();
355 void DelayedChannel();
356 inline uint32 getState() const { return m_spellState; }
357 void setState(uint32 state) { m_spellState = state; }
359 void DoCreateItem(uint32 i, uint32 itemtype);
361 void WriteSpellGoTargets( WorldPacket * data );
362 void WriteAmmoToPacket( WorldPacket * data );
363 void FillTargetMap();
365 void SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap);
367 Unit* SelectMagnetTarget();
368 bool CheckTarget( Unit* target, uint32 eff );
370 void SendCastResult(uint8 result);
371 void SendSpellStart();
372 void SendSpellGo();
373 void SendSpellCooldown();
374 void SendLogExecute();
375 void SendInterrupted(uint8 result);
376 void SendChannelUpdate(uint32 time);
377 void SendChannelStart(uint32 duration);
378 void SendResurrectRequest(Player* target);
379 void SendPlaySpellVisual(uint32 SpellID);
381 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
382 void HandleThreatSpells(uint32 spellId);
383 //void HandleAddAura(Unit* Target);
385 SpellEntry const* m_spellInfo;
386 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
387 Item* m_CastItem;
388 uint8 m_cast_count;
389 uint32 m_glyphIndex;
390 SpellCastTargets m_targets;
392 int32 GetCastTime() const { return m_casttime; }
393 bool IsAutoRepeat() const { return m_autoRepeat; }
394 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
395 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
396 bool IsNextMeleeSwingSpell() const
398 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
400 bool IsRangedSpell() const
402 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
404 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
405 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
406 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
408 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
409 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
410 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
411 uint64 GetDelayStart() const { return m_delayStart; }
412 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
413 uint64 GetDelayMoment() const { return m_delayMoment; }
415 bool IsNeedSendToClient() const;
417 CurrentSpellTypes GetCurrentContainer();
419 Unit* GetCaster() const { return m_caster; }
420 Unit* GetOriginalCaster() const { return m_originalCaster; }
421 int32 GetPowerCost() const { return m_powerCost; }
423 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
425 bool IsAffectedBy(SpellEntry const *spellInfo, uint32 effectId);
427 bool CheckTargetCreatureType(Unit* target) const;
429 void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
431 void CleanupTargetList();
432 protected:
434 void SendLoot(uint64 guid, LootType loottype);
436 Unit* m_caster;
438 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
439 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
440 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
442 Spell** m_selfContainer; // pointer to our spell container (if applicable)
443 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
445 //Spell data
446 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
447 WeaponAttackType m_attackType; // For weapon based attack
448 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
449 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
450 bool m_canReflect; // can reflect this spell?
451 bool m_autoRepeat;
452 uint8 m_runesState;
454 uint8 m_delayAtDamageCount;
455 int32 GetNextDelayAtDamageMsTime() { return m_delayAtDamageCount < 5 ? 1000 - (m_delayAtDamageCount++)* 200 : 200; }
457 // Delayed spells system
458 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
459 uint64 m_delayMoment; // moment of next delay call, used internally
460 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
462 // These vars are used in both delayed spell system and modified immediate spell system
463 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
464 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
465 bool m_needSpellLog; // need to send spell log?
466 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
467 float m_damageMultipliers[3]; // by effect: damage multiplier
469 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
470 Unit* unitTarget;
471 Item* itemTarget;
472 GameObject* gameObjTarget;
473 int32 damage;
475 // this is set in Spell Hit, but used in Apply Aura handler
476 DiminishingLevels m_diminishLevel;
477 DiminishingGroup m_diminishGroup;
479 // -------------------------------------------
480 GameObject* focusObject;
482 //******************************************
483 // Spell trigger system
484 //******************************************
485 void doTriggers(SpellMissInfo missInfo, uint32 damage=0, SpellSchoolMask damageSchoolMask = SPELL_SCHOOL_MASK_NONE, uint32 block=0, uint32 absorb=0, bool crit=false);
487 //*****************************************
488 // Spell target subsystem
489 //*****************************************
490 // Targets store structures and data
491 uint32 m_countOfHit;
492 uint32 m_countOfMiss;
493 struct TargetInfo
495 uint64 targetGUID;
496 uint64 timeDelay;
497 SpellMissInfo missCondition:8;
498 SpellMissInfo reflectResult:8;
499 uint8 effectMask:8;
500 bool processed:1;
502 std::list<TargetInfo> m_UniqueTargetInfo;
503 uint8 m_needAliveTargetMask; // Mask req. alive targets
505 struct GOTargetInfo
507 uint64 targetGUID;
508 uint64 timeDelay;
509 uint8 effectMask:8;
510 bool processed:1;
512 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
514 struct ItemTargetInfo
516 Item *item;
517 uint8 effectMask;
519 std::list<ItemTargetInfo> m_UniqueItemInfo;
521 void AddUnitTarget(Unit* target, uint32 effIndex);
522 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
523 void AddGOTarget(GameObject* target, uint32 effIndex);
524 void AddGOTarget(uint64 goGUID, uint32 effIndex);
525 void AddItemTarget(Item* target, uint32 effIndex);
526 void DoAllEffectOnTarget(TargetInfo *target);
527 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
528 void DoAllEffectOnTarget(GOTargetInfo *target);
529 void DoAllEffectOnTarget(ItemTargetInfo *target);
530 bool IsAliveUnitPresentInTargetList();
531 // -------------------------------------------
533 //List For Triggered Spells
534 typedef std::list<SpellEntry const*> TriggerSpells;
535 TriggerSpells m_TriggerSpells;
537 uint32 m_spellState;
538 uint32 m_timer;
540 float m_castPositionX;
541 float m_castPositionY;
542 float m_castPositionZ;
543 float m_castOrientation;
544 bool m_IsTriggeredSpell;
546 // if need this can be replaced by Aura copy
547 // we can't store original aura link to prevent access to deleted auras
548 // and in same time need aura data and after aura deleting.
549 SpellEntry const* m_triggeredByAuraSpell;
552 enum ReplenishType
554 REPLENISH_UNDEFINED = 0,
555 REPLENISH_HEALTH = 20,
556 REPLENISH_MANA = 21,
557 REPLENISH_RAGE = 22
560 enum SpellTargets
562 SPELL_TARGETS_HOSTILE,
563 SPELL_TARGETS_NOT_FRIENDLY,
564 SPELL_TARGETS_NOT_HOSTILE,
565 SPELL_TARGETS_FRIENDLY,
566 SPELL_TARGETS_AOE_DAMAGE
569 namespace MaNGOS
571 struct MANGOS_DLL_DECL SpellNotifierPlayer
573 std::list<Unit*> &i_data;
574 Spell &i_spell;
575 const uint32& i_index;
576 float i_radius;
577 Unit* i_originalCaster;
579 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
580 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
582 i_originalCaster = i_spell.GetOriginalCaster();
585 void Visit(PlayerMapType &m)
587 if(!i_originalCaster)
588 return;
590 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
592 Player * pPlayer = itr->getSource();
593 if( !pPlayer->isAlive() || pPlayer->isInFlight())
594 continue;
596 if( i_originalCaster->IsFriendlyTo(pPlayer) )
597 continue;
599 if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
600 i_data.push_back(pPlayer);
603 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
606 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
608 std::list<Unit*> *i_data;
609 Spell &i_spell;
610 const uint32& i_push_type;
611 float i_radius;
612 SpellTargets i_TargetType;
613 Unit* i_originalCaster;
615 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, const uint32 &type,
616 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
617 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
619 i_originalCaster = spell.GetOriginalCaster();
622 template<class T> inline void Visit(GridRefManager<T> &m)
624 assert(i_data);
626 if(!i_originalCaster)
627 return;
629 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
631 if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
632 continue;
634 switch (i_TargetType)
636 case SPELL_TARGETS_HOSTILE:
637 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
638 continue;
639 break;
640 case SPELL_TARGETS_NOT_FRIENDLY:
641 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
642 continue;
643 break;
644 case SPELL_TARGETS_NOT_HOSTILE:
645 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
646 continue;
647 break;
648 case SPELL_TARGETS_FRIENDLY:
649 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
650 continue;
651 break;
652 case SPELL_TARGETS_AOE_DAMAGE:
654 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
655 continue;
656 if(!itr->getSource()->isTargetableForAttack())
657 continue;
659 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
661 if( check->GetTypeId()==TYPEID_PLAYER )
663 if (check->IsFriendlyTo( itr->getSource() ))
664 continue;
666 else
668 if (!check->IsHostileTo( itr->getSource() ))
669 continue;
672 break;
673 default: continue;
676 switch(i_push_type)
678 case PUSH_IN_FRONT:
679 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
680 i_data->push_back(itr->getSource());
681 break;
682 case PUSH_IN_BACK:
683 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
684 i_data->push_back(itr->getSource());
685 break;
686 case PUSH_SELF_CENTER:
687 if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
688 i_data->push_back(itr->getSource());
689 break;
690 case PUSH_DEST_CENTER:
691 if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
692 i_data->push_back(itr->getSource());
693 break;
694 case PUSH_TARGET_CENTER:
695 if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
696 i_data->push_back(itr->getSource());
697 break;
702 #ifdef WIN32
703 template<> inline void Visit(CorpseMapType & ) {}
704 template<> inline void Visit(GameObjectMapType & ) {}
705 template<> inline void Visit(DynamicObjectMapType & ) {}
706 #endif
709 #ifndef WIN32
710 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
711 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
712 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
713 #endif
716 typedef void(Spell::*pEffect)(uint32 i);
718 class SpellEvent : public BasicEvent
720 public:
721 SpellEvent(Spell* spell);
722 virtual ~SpellEvent();
724 virtual bool Execute(uint64 e_time, uint32 p_time);
725 virtual void Abort(uint64 e_time);
726 virtual bool IsDeletable() const;
727 protected:
728 Spell* m_Spell;
730 #endif