[7160] Implement (un-)learning skill level dependent spells at skill level change.
[getmangos.git] / src / game / Spell.h
bloba443c212d5b7aac61e685845646d8a49d2c90039
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 #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);
153 void setSource(float x, float y, float z);
155 uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
156 GameObject *getGOTarget() const { return m_GOTarget; }
157 void setGOTarget(GameObject *target);
159 uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
160 void setCorpseTarget(Corpse* corpse);
161 uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
162 Item* getItemTarget() const { return m_itemTarget; }
163 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
164 void setItemTarget(Item* item);
165 void updateTradeSlotItem()
167 if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
169 m_itemTargetGUID = m_itemTarget->GetGUID();
170 m_itemTargetEntry = m_itemTarget->GetEntry();
174 bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
176 void Update(Unit* caster);
178 float m_srcX, m_srcY, m_srcZ;
179 float m_destX, m_destY, m_destZ;
180 std::string m_strTarget;
182 uint32 m_targetMask;
183 private:
184 // objects (can be used at spell creating and after Update at casting
185 Unit *m_unitTarget;
186 GameObject *m_GOTarget;
187 Item *m_itemTarget;
189 // object GUID/etc, can be used always
190 uint64 m_unitTargetGUID;
191 uint64 m_GOTargetGUID;
192 uint64 m_CorpseTargetGUID;
193 uint64 m_itemTargetGUID;
194 uint32 m_itemTargetEntry;
197 enum SpellState
199 SPELL_STATE_NULL = 0,
200 SPELL_STATE_PREPARING = 1,
201 SPELL_STATE_CASTING = 2,
202 SPELL_STATE_FINISHED = 3,
203 SPELL_STATE_IDLE = 4,
204 SPELL_STATE_DELAYED = 5
207 #define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL 1000
209 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
211 class Spell
213 friend struct MaNGOS::SpellNotifierPlayer;
214 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
215 public:
217 void EffectNULL(uint32 );
218 void EffectUnused(uint32 );
219 void EffectDistract(uint32 i);
220 void EffectPull(uint32 i);
221 void EffectSchoolDMG(uint32 i);
222 void EffectEnvirinmentalDMG(uint32 i);
223 void EffectInstaKill(uint32 i);
224 void EffectDummy(uint32 i);
225 void EffectTeleportUnits(uint32 i);
226 void EffectApplyAura(uint32 i);
227 void EffectSendEvent(uint32 i);
228 void EffectPowerBurn(uint32 i);
229 void EffectPowerDrain(uint32 i);
230 void EffectHeal(uint32 i);
231 void EffectHealthLeech(uint32 i);
232 void EffectQuestComplete(uint32 i);
233 void EffectCreateItem(uint32 i);
234 void EffectPersistentAA(uint32 i);
235 void EffectEnergize(uint32 i);
236 void EffectOpenLock(uint32 i);
237 void EffectSummonChangeItem(uint32 i);
238 void EffectOpenSecretSafe(uint32 i);
239 void EffectProficiency(uint32 i);
240 void EffectApplyAreaAura(uint32 i);
241 void EffectSummonType(uint32 i);
242 void EffectSummon(uint32 i);
243 void EffectLearnSpell(uint32 i);
244 void EffectDispel(uint32 i);
245 void EffectDualWield(uint32 i);
246 void EffectPickPocket(uint32 i);
247 void EffectAddFarsight(uint32 i);
248 void EffectSummonWild(uint32 i);
249 void EffectSummonGuardian(uint32 i);
250 void EffectHealMechanical(uint32 i);
251 void EffectTeleUnitsFaceCaster(uint32 i);
252 void EffectLearnSkill(uint32 i);
253 void EffectAddHonor(uint32 i);
254 void EffectTradeSkill(uint32 i);
255 void EffectEnchantItemPerm(uint32 i);
256 void EffectEnchantItemTmp(uint32 i);
257 void EffectTameCreature(uint32 i);
258 void EffectSummonPet(uint32 i);
259 void EffectLearnPetSpell(uint32 i);
260 void EffectWeaponDmg(uint32 i);
261 void EffectForceCast(uint32 i);
262 void EffectTriggerSpell(uint32 i);
263 void EffectTriggerMissileSpell(uint32 i);
264 void EffectThreat(uint32 i);
265 void EffectHealMaxHealth(uint32 i);
266 void EffectInterruptCast(uint32 i);
267 void EffectSummonObjectWild(uint32 i);
268 void EffectScriptEffect(uint32 i);
269 void EffectSanctuary(uint32 i);
270 void EffectAddComboPoints(uint32 i);
271 void EffectDuel(uint32 i);
272 void EffectStuck(uint32 i);
273 void EffectSummonPlayer(uint32 i);
274 void EffectActivateObject(uint32 i);
275 void EffectApplyGlyph(uint32 i);
276 void EffectSummonTotem(uint32 i);
277 void EffectEnchantHeldItem(uint32 i);
278 void EffectSummonObject(uint32 i);
279 void EffectResurrect(uint32 i);
280 void EffectParry(uint32 i);
281 void EffectBlock(uint32 i);
282 void EffectMomentMove(uint32 i);
283 void EffectTransmitted(uint32 i);
284 void EffectDisEnchant(uint32 i);
285 void EffectInebriate(uint32 i);
286 void EffectFeedPet(uint32 i);
287 void EffectDismissPet(uint32 i);
288 void EffectReputation(uint32 i);
289 void EffectSelfResurrect(uint32 i);
290 void EffectSkinning(uint32 i);
291 void EffectCharge(uint32 i);
292 void EffectProspecting(uint32 i);
293 void EffectMilling(uint32 i);
294 void EffectRenamePet(uint32 i);
295 void EffectSendTaxi(uint32 i);
296 void EffectSummonCritter(uint32 i);
297 void EffectKnockBack(uint32 i);
298 void EffectPlayerPull(uint32 i);
299 void EffectDispelMechanic(uint32 i);
300 void EffectSummonDeadPet(uint32 i);
301 void EffectDestroyAllTotems(uint32 i);
302 void EffectDurabilityDamage(uint32 i);
303 void EffectSkill(uint32 i);
304 void EffectTaunt(uint32 i);
305 void EffectDurabilityDamagePCT(uint32 i);
306 void EffectModifyThreatPercent(uint32 i);
307 void EffectResurrectNew(uint32 i);
308 void EffectAddExtraAttacks(uint32 i);
309 void EffectSpiritHeal(uint32 i);
310 void EffectSkinPlayerCorpse(uint32 i);
311 void EffectSummonDemon(uint32 i);
312 void EffectStealBeneficialBuff(uint32 i);
313 void EffectUnlearnSpecialization(uint32 i);
314 void EffectHealPct(uint32 i);
315 void EffectEnergisePct(uint32 i);
316 void EffectTriggerSpellWithValue(uint32 i);
317 void EffectTriggerRitualOfSummoning(uint32 i);
318 void EffectKillCredit(uint32 i);
319 void EffectQuestFail(uint32 i);
320 void EffectActivateRune(uint32 i);
321 void EffectTitanGrip(uint32 i);
323 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
324 ~Spell();
326 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
327 void cancel();
328 void update(uint32 difftime);
329 void cast(bool skipCheck = false);
330 void finish(bool ok = true);
331 void TakePower();
332 uint8 CheckRuneCost(uint32 runeCostID);
333 void TakeRunePower();
334 void TakeReagents();
335 void TakeCastItem();
336 void TriggerSpell();
337 uint8 CanCast(bool strict);
338 int16 PetCanCast(Unit* target);
339 bool CanAutoCast(Unit* target);
341 // handlers
342 void handle_immediate();
343 uint64 handle_delayed(uint64 t_offset);
344 // handler helpers
345 void _handle_immediate_phase();
346 void _handle_finish_phase();
348 uint8 CheckItems();
349 uint8 CheckRange(bool strict);
350 uint8 CheckPower();
351 uint8 CheckCasterAuras() const;
353 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
354 int32 CalculatePowerCost();
356 bool HaveTargetsForEffect(uint8 effect) const;
357 void Delayed();
358 void DelayedChannel();
359 uint32 getState() const { return m_spellState; }
360 void setState(uint32 state) { m_spellState = state; }
362 void DoCreateItem(uint32 i, uint32 itemtype);
363 void WriteSpellGoTargets( WorldPacket * data );
364 void WriteAmmoToPacket( WorldPacket * data );
365 void FillTargetMap();
367 void SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap);
369 Unit* SelectMagnetTarget();
370 bool CheckTarget( Unit* target, uint32 eff );
372 void SendCastResult(uint8 result);
373 void SendSpellStart();
374 void SendSpellGo();
375 void SendSpellCooldown();
376 void SendLogExecute();
377 void SendInterrupted(uint8 result);
378 void SendChannelUpdate(uint32 time);
379 void SendChannelStart(uint32 duration);
380 void SendResurrectRequest(Player* target);
381 void SendPlaySpellVisual(uint32 SpellID);
383 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
384 void HandleThreatSpells(uint32 spellId);
385 //void HandleAddAura(Unit* Target);
387 SpellEntry const* m_spellInfo;
388 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
389 Item* m_CastItem;
390 uint8 m_cast_count;
391 uint32 m_glyphIndex;
392 SpellCastTargets m_targets;
394 int32 GetCastTime() const { return m_casttime; }
395 bool IsAutoRepeat() const { return m_autoRepeat; }
396 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
397 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
398 bool IsNextMeleeSwingSpell() const
400 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
402 bool IsRangedSpell() const
404 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
406 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
407 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
408 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
410 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
411 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
412 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
413 uint64 GetDelayStart() const { return m_delayStart; }
414 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
415 uint64 GetDelayMoment() const { return m_delayMoment; }
417 bool IsNeedSendToClient() const;
419 CurrentSpellTypes GetCurrentContainer();
421 Unit* GetCaster() const { return m_caster; }
422 Unit* GetOriginalCaster() const { return m_originalCaster; }
423 int32 GetPowerCost() const { return m_powerCost; }
425 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
427 bool IsAffectedByAura(Aura *aura);
429 bool CheckTargetCreatureType(Unit* target) const;
431 void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
433 void CleanupTargetList();
434 protected:
436 void SendLoot(uint64 guid, LootType loottype);
438 Unit* m_caster;
440 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
441 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
442 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
444 Spell** m_selfContainer; // pointer to our spell container (if applicable)
445 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
447 //Spell data
448 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
449 WeaponAttackType m_attackType; // For weapon based attack
450 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
451 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
452 bool m_canReflect; // can reflect this spell?
453 bool m_autoRepeat;
454 uint8 m_runesState;
456 uint8 m_delayAtDamageCount;
457 int32 GetNextDelayAtDamageMsTime() { return m_delayAtDamageCount < 5 ? 1000 - (m_delayAtDamageCount++)* 200 : 200; }
459 // Delayed spells system
460 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
461 uint64 m_delayMoment; // moment of next delay call, used internally
462 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
464 // These vars are used in both delayed spell system and modified immediate spell system
465 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
466 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
467 bool m_needSpellLog; // need to send spell log?
468 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
469 float m_damageMultipliers[3]; // by effect: damage multiplier
471 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
472 Unit* unitTarget;
473 Item* itemTarget;
474 GameObject* gameObjTarget;
475 int32 damage;
477 // this is set in Spell Hit, but used in Apply Aura handler
478 DiminishingLevels m_diminishLevel;
479 DiminishingGroup m_diminishGroup;
481 // -------------------------------------------
482 GameObject* focusObject;
484 // Damage and healing in effects need just calculate
485 int32 m_damage; // Damge in effects count here
486 int32 m_healing; // Healing in effects count here
487 int32 m_healthLeech; // Health leech in effects for all targets count here
489 //******************************************
490 // Spell trigger system
491 //******************************************
492 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
493 uint32 m_procAttacker; // Attacker trigger flags
494 uint32 m_procVictim; // Victim trigger flags
495 void prepareDataForTriggerSystem();
497 //*****************************************
498 // Spell target subsystem
499 //*****************************************
500 // Targets store structures and data
501 struct TargetInfo
503 uint64 targetGUID;
504 uint64 timeDelay;
505 SpellMissInfo missCondition:8;
506 SpellMissInfo reflectResult:8;
507 uint8 effectMask:8;
508 bool processed:1;
510 std::list<TargetInfo> m_UniqueTargetInfo;
511 uint8 m_needAliveTargetMask; // Mask req. alive targets
513 struct GOTargetInfo
515 uint64 targetGUID;
516 uint64 timeDelay;
517 uint8 effectMask:8;
518 bool processed:1;
520 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
522 struct ItemTargetInfo
524 Item *item;
525 uint8 effectMask;
527 std::list<ItemTargetInfo> m_UniqueItemInfo;
529 void AddUnitTarget(Unit* target, uint32 effIndex);
530 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
531 void AddGOTarget(GameObject* target, uint32 effIndex);
532 void AddGOTarget(uint64 goGUID, uint32 effIndex);
533 void AddItemTarget(Item* target, uint32 effIndex);
534 void DoAllEffectOnTarget(TargetInfo *target);
535 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
536 void DoAllEffectOnTarget(GOTargetInfo *target);
537 void DoAllEffectOnTarget(ItemTargetInfo *target);
538 bool IsAliveUnitPresentInTargetList();
539 // -------------------------------------------
541 //List For Triggered Spells
542 typedef std::list<SpellEntry const*> TriggerSpells;
543 TriggerSpells m_TriggerSpells;
545 uint32 m_spellState;
546 uint32 m_timer;
548 float m_castPositionX;
549 float m_castPositionY;
550 float m_castPositionZ;
551 float m_castOrientation;
552 bool m_IsTriggeredSpell;
554 // if need this can be replaced by Aura copy
555 // we can't store original aura link to prevent access to deleted auras
556 // and in same time need aura data and after aura deleting.
557 SpellEntry const* m_triggeredByAuraSpell;
560 enum ReplenishType
562 REPLENISH_UNDEFINED = 0,
563 REPLENISH_HEALTH = 20,
564 REPLENISH_MANA = 21,
565 REPLENISH_RAGE = 22
568 enum SpellTargets
570 SPELL_TARGETS_HOSTILE,
571 SPELL_TARGETS_NOT_FRIENDLY,
572 SPELL_TARGETS_NOT_HOSTILE,
573 SPELL_TARGETS_FRIENDLY,
574 SPELL_TARGETS_AOE_DAMAGE
577 namespace MaNGOS
579 struct MANGOS_DLL_DECL SpellNotifierPlayer
581 std::list<Unit*> &i_data;
582 Spell &i_spell;
583 const uint32& i_index;
584 float i_radius;
585 Unit* i_originalCaster;
587 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
588 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
590 i_originalCaster = i_spell.GetOriginalCaster();
593 void Visit(PlayerMapType &m)
595 if(!i_originalCaster)
596 return;
598 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
600 Player * pPlayer = itr->getSource();
601 if( !pPlayer->isAlive() || pPlayer->isInFlight())
602 continue;
604 if( i_originalCaster->IsFriendlyTo(pPlayer) )
605 continue;
607 if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
608 i_data.push_back(pPlayer);
611 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
614 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
616 std::list<Unit*> *i_data;
617 Spell &i_spell;
618 const uint32& i_push_type;
619 float i_radius;
620 SpellTargets i_TargetType;
621 Unit* i_originalCaster;
623 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, const uint32 &type,
624 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
625 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
627 i_originalCaster = spell.GetOriginalCaster();
630 template<class T> inline void Visit(GridRefManager<T> &m)
632 assert(i_data);
634 if(!i_originalCaster)
635 return;
637 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
639 if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
640 continue;
642 switch (i_TargetType)
644 case SPELL_TARGETS_HOSTILE:
645 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
646 continue;
647 break;
648 case SPELL_TARGETS_NOT_FRIENDLY:
649 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
650 continue;
651 break;
652 case SPELL_TARGETS_NOT_HOSTILE:
653 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
654 continue;
655 break;
656 case SPELL_TARGETS_FRIENDLY:
657 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
658 continue;
659 break;
660 case SPELL_TARGETS_AOE_DAMAGE:
662 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
663 continue;
664 if(!itr->getSource()->isTargetableForAttack())
665 continue;
667 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
669 if( check->GetTypeId()==TYPEID_PLAYER )
671 if (check->IsFriendlyTo( itr->getSource() ))
672 continue;
674 else
676 if (!check->IsHostileTo( itr->getSource() ))
677 continue;
680 break;
681 default: continue;
684 switch(i_push_type)
686 case PUSH_IN_FRONT:
687 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
688 i_data->push_back(itr->getSource());
689 break;
690 case PUSH_IN_BACK:
691 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
692 i_data->push_back(itr->getSource());
693 break;
694 case PUSH_SELF_CENTER:
695 if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
696 i_data->push_back(itr->getSource());
697 break;
698 case PUSH_DEST_CENTER:
699 if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
700 i_data->push_back(itr->getSource());
701 break;
702 case PUSH_TARGET_CENTER:
703 if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
704 i_data->push_back(itr->getSource());
705 break;
710 #ifdef WIN32
711 template<> inline void Visit(CorpseMapType & ) {}
712 template<> inline void Visit(GameObjectMapType & ) {}
713 template<> inline void Visit(DynamicObjectMapType & ) {}
714 #endif
717 #ifndef WIN32
718 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
719 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
720 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
721 #endif
724 typedef void(Spell::*pEffect)(uint32 i);
726 class SpellEvent : public BasicEvent
728 public:
729 SpellEvent(Spell* spell);
730 virtual ~SpellEvent();
732 virtual bool Execute(uint64 e_time, uint32 p_time);
733 virtual void Abort(uint64 e_time);
734 virtual bool IsDeletable() const;
735 protected:
736 Spell* m_Spell;
738 #endif