[7445] Implement SPELL_EFFECT_JUMP2 used in some jump to target (unit/go/coordinates...
[AHbot.git] / src / game / Spell.h
blob6b33e636f4f18f34f311a394acbbac0834dba237
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 (1*IN_MILISECONDS)
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 EffectCreateItem2(uint32 i);
235 void EffectPersistentAA(uint32 i);
236 void EffectEnergize(uint32 i);
237 void EffectOpenLock(uint32 i);
238 void EffectSummonChangeItem(uint32 i);
239 void EffectOpenSecretSafe(uint32 i);
240 void EffectProficiency(uint32 i);
241 void EffectApplyAreaAura(uint32 i);
242 void EffectSummonType(uint32 i);
243 void EffectSummon(uint32 i);
244 void EffectLearnSpell(uint32 i);
245 void EffectDispel(uint32 i);
246 void EffectDualWield(uint32 i);
247 void EffectPickPocket(uint32 i);
248 void EffectAddFarsight(uint32 i);
249 void EffectSummonWild(uint32 i);
250 void EffectSummonGuardian(uint32 i);
251 void EffectHealMechanical(uint32 i);
252 void EffectJump(uint32 i);
253 void EffectTeleUnitsFaceCaster(uint32 i);
254 void EffectLearnSkill(uint32 i);
255 void EffectAddHonor(uint32 i);
256 void EffectTradeSkill(uint32 i);
257 void EffectEnchantItemPerm(uint32 i);
258 void EffectEnchantItemTmp(uint32 i);
259 void EffectTameCreature(uint32 i);
260 void EffectSummonPet(uint32 i);
261 void EffectLearnPetSpell(uint32 i);
262 void EffectWeaponDmg(uint32 i);
263 void EffectForceCast(uint32 i);
264 void EffectTriggerSpell(uint32 i);
265 void EffectTriggerMissileSpell(uint32 i);
266 void EffectThreat(uint32 i);
267 void EffectHealMaxHealth(uint32 i);
268 void EffectInterruptCast(uint32 i);
269 void EffectSummonObjectWild(uint32 i);
270 void EffectScriptEffect(uint32 i);
271 void EffectSanctuary(uint32 i);
272 void EffectAddComboPoints(uint32 i);
273 void EffectDuel(uint32 i);
274 void EffectStuck(uint32 i);
275 void EffectSummonPlayer(uint32 i);
276 void EffectActivateObject(uint32 i);
277 void EffectApplyGlyph(uint32 i);
278 void EffectSummonTotem(uint32 i);
279 void EffectEnchantHeldItem(uint32 i);
280 void EffectSummonObject(uint32 i);
281 void EffectResurrect(uint32 i);
282 void EffectParry(uint32 i);
283 void EffectBlock(uint32 i);
284 void EffectMomentMove(uint32 i);
285 void EffectTransmitted(uint32 i);
286 void EffectDisEnchant(uint32 i);
287 void EffectInebriate(uint32 i);
288 void EffectFeedPet(uint32 i);
289 void EffectDismissPet(uint32 i);
290 void EffectReputation(uint32 i);
291 void EffectSelfResurrect(uint32 i);
292 void EffectSkinning(uint32 i);
293 void EffectCharge(uint32 i);
294 void EffectProspecting(uint32 i);
295 void EffectMilling(uint32 i);
296 void EffectRenamePet(uint32 i);
297 void EffectSendTaxi(uint32 i);
298 void EffectSummonCritter(uint32 i);
299 void EffectKnockBack(uint32 i);
300 void EffectPlayerPull(uint32 i);
301 void EffectDispelMechanic(uint32 i);
302 void EffectSummonDeadPet(uint32 i);
303 void EffectDestroyAllTotems(uint32 i);
304 void EffectDurabilityDamage(uint32 i);
305 void EffectSkill(uint32 i);
306 void EffectTaunt(uint32 i);
307 void EffectDurabilityDamagePCT(uint32 i);
308 void EffectModifyThreatPercent(uint32 i);
309 void EffectResurrectNew(uint32 i);
310 void EffectAddExtraAttacks(uint32 i);
311 void EffectSpiritHeal(uint32 i);
312 void EffectSkinPlayerCorpse(uint32 i);
313 void EffectSummonDemon(uint32 i);
314 void EffectStealBeneficialBuff(uint32 i);
315 void EffectUnlearnSpecialization(uint32 i);
316 void EffectHealPct(uint32 i);
317 void EffectEnergisePct(uint32 i);
318 void EffectTriggerSpellWithValue(uint32 i);
319 void EffectTriggerRitualOfSummoning(uint32 i);
320 void EffectKillCredit(uint32 i);
321 void EffectQuestFail(uint32 i);
322 void EffectActivateRune(uint32 i);
323 void EffectTitanGrip(uint32 i);
324 void EffectEnchantItemPrismatic(uint32 i);
326 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
327 ~Spell();
329 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
330 void cancel();
331 void update(uint32 difftime);
332 void cast(bool skipCheck = false);
333 void finish(bool ok = true);
334 void TakePower();
335 uint8 CheckRuneCost(uint32 runeCostID);
336 void TakeRunePower();
337 void TakeReagents();
338 void TakeCastItem();
339 void TriggerSpell();
340 uint8 CanCast(bool strict);
341 int16 PetCanCast(Unit* target);
342 bool CanAutoCast(Unit* target);
344 // handlers
345 void handle_immediate();
346 uint64 handle_delayed(uint64 t_offset);
347 // handler helpers
348 void _handle_immediate_phase();
349 void _handle_finish_phase();
351 uint8 CheckItems();
352 uint8 CheckRange(bool strict);
353 uint8 CheckPower();
354 uint8 CheckCasterAuras() const;
356 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
357 int32 CalculatePowerCost();
359 bool HaveTargetsForEffect(uint8 effect) const;
360 void Delayed();
361 void DelayedChannel();
362 uint32 getState() const { return m_spellState; }
363 void setState(uint32 state) { m_spellState = state; }
365 void DoCreateItem(uint32 i, uint32 itemtype);
366 void WriteSpellGoTargets( WorldPacket * data );
367 void WriteAmmoToPacket( WorldPacket * data );
368 void FillTargetMap();
370 void SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap);
372 Unit* SelectMagnetTarget();
373 bool CheckTarget( Unit* target, uint32 eff );
375 void SendCastResult(uint8 result);
376 void SendSpellStart();
377 void SendSpellGo();
378 void SendSpellCooldown();
379 void SendLogExecute();
380 void SendInterrupted(uint8 result);
381 void SendChannelUpdate(uint32 time);
382 void SendChannelStart(uint32 duration);
383 void SendResurrectRequest(Player* target);
384 void SendPlaySpellVisual(uint32 SpellID);
386 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
387 void HandleThreatSpells(uint32 spellId);
388 //void HandleAddAura(Unit* Target);
390 SpellEntry const* m_spellInfo;
391 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
392 Item* m_CastItem;
393 uint8 m_cast_count;
394 uint32 m_glyphIndex;
395 uint32 m_preCastSpell;
396 SpellCastTargets m_targets;
398 int32 GetCastTime() const { return m_casttime; }
399 bool IsAutoRepeat() const { return m_autoRepeat; }
400 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
401 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
402 bool IsNextMeleeSwingSpell() const
404 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
406 bool IsRangedSpell() const
408 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
410 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
411 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
412 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
414 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
415 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
416 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
417 uint64 GetDelayStart() const { return m_delayStart; }
418 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
419 uint64 GetDelayMoment() const { return m_delayMoment; }
421 bool IsNeedSendToClient() const;
423 CurrentSpellTypes GetCurrentContainer();
425 Unit* GetCaster() const { return m_caster; }
426 Unit* GetOriginalCaster() const { return m_originalCaster; }
427 int32 GetPowerCost() const { return m_powerCost; }
429 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
431 bool IsAffectedByAura(Aura *aura);
433 bool CheckTargetCreatureType(Unit* target) const;
435 void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
437 void CleanupTargetList();
438 protected:
440 void SendLoot(uint64 guid, LootType loottype);
442 Unit* m_caster;
444 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
445 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
446 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
448 Spell** m_selfContainer; // pointer to our spell container (if applicable)
449 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
451 //Spell data
452 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
453 WeaponAttackType m_attackType; // For weapon based attack
454 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
455 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
456 bool m_canReflect; // can reflect this spell?
457 bool m_autoRepeat;
458 uint8 m_runesState;
460 uint8 m_delayAtDamageCount;
461 bool isDelayableNoMore()
463 if(m_delayAtDamageCount >= 2)
464 return true;
466 m_delayAtDamageCount++;
467 return false;
470 // Delayed spells system
471 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
472 uint64 m_delayMoment; // moment of next delay call, used internally
473 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
475 // These vars are used in both delayed spell system and modified immediate spell system
476 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
477 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
478 bool m_needSpellLog; // need to send spell log?
479 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
480 float m_damageMultipliers[3]; // by effect: damage multiplier
482 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
483 Unit* unitTarget;
484 Item* itemTarget;
485 GameObject* gameObjTarget;
486 int32 damage;
488 // this is set in Spell Hit, but used in Apply Aura handler
489 DiminishingLevels m_diminishLevel;
490 DiminishingGroup m_diminishGroup;
492 // -------------------------------------------
493 GameObject* focusObject;
495 // Damage and healing in effects need just calculate
496 int32 m_damage; // Damge in effects count here
497 int32 m_healing; // Healing in effects count here
498 int32 m_healthLeech; // Health leech in effects for all targets count here
500 //******************************************
501 // Spell trigger system
502 //******************************************
503 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
504 uint32 m_procAttacker; // Attacker trigger flags
505 uint32 m_procVictim; // Victim trigger flags
506 void prepareDataForTriggerSystem();
508 //*****************************************
509 // Spell target subsystem
510 //*****************************************
511 // Targets store structures and data
512 struct TargetInfo
514 uint64 targetGUID;
515 uint64 timeDelay;
516 SpellMissInfo missCondition:8;
517 SpellMissInfo reflectResult:8;
518 uint8 effectMask:8;
519 bool processed:1;
521 std::list<TargetInfo> m_UniqueTargetInfo;
522 uint8 m_needAliveTargetMask; // Mask req. alive targets
524 struct GOTargetInfo
526 uint64 targetGUID;
527 uint64 timeDelay;
528 uint8 effectMask:8;
529 bool processed:1;
531 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
533 struct ItemTargetInfo
535 Item *item;
536 uint8 effectMask;
538 std::list<ItemTargetInfo> m_UniqueItemInfo;
540 void AddUnitTarget(Unit* target, uint32 effIndex);
541 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
542 void AddGOTarget(GameObject* target, uint32 effIndex);
543 void AddGOTarget(uint64 goGUID, uint32 effIndex);
544 void AddItemTarget(Item* target, uint32 effIndex);
545 void DoAllEffectOnTarget(TargetInfo *target);
546 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
547 void DoAllEffectOnTarget(GOTargetInfo *target);
548 void DoAllEffectOnTarget(ItemTargetInfo *target);
549 bool IsAliveUnitPresentInTargetList();
550 // -------------------------------------------
552 //List For Triggered Spells
553 typedef std::list<SpellEntry const*> TriggerSpells;
554 TriggerSpells m_TriggerSpells;
556 uint32 m_spellState;
557 uint32 m_timer;
559 float m_castPositionX;
560 float m_castPositionY;
561 float m_castPositionZ;
562 float m_castOrientation;
563 bool m_IsTriggeredSpell;
565 // if need this can be replaced by Aura copy
566 // we can't store original aura link to prevent access to deleted auras
567 // and in same time need aura data and after aura deleting.
568 SpellEntry const* m_triggeredByAuraSpell;
571 enum ReplenishType
573 REPLENISH_UNDEFINED = 0,
574 REPLENISH_HEALTH = 20,
575 REPLENISH_MANA = 21,
576 REPLENISH_RAGE = 22
579 enum SpellTargets
581 SPELL_TARGETS_HOSTILE,
582 SPELL_TARGETS_NOT_FRIENDLY,
583 SPELL_TARGETS_NOT_HOSTILE,
584 SPELL_TARGETS_FRIENDLY,
585 SPELL_TARGETS_AOE_DAMAGE
588 namespace MaNGOS
590 struct MANGOS_DLL_DECL SpellNotifierPlayer
592 std::list<Unit*> &i_data;
593 Spell &i_spell;
594 const uint32& i_index;
595 float i_radius;
596 Unit* i_originalCaster;
598 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
599 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
601 i_originalCaster = i_spell.GetOriginalCaster();
604 void Visit(PlayerMapType &m)
606 if(!i_originalCaster)
607 return;
609 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
611 Player * pPlayer = itr->getSource();
612 if( !pPlayer->isAlive() || pPlayer->isInFlight())
613 continue;
615 if( i_originalCaster->IsFriendlyTo(pPlayer) )
616 continue;
618 if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
619 i_data.push_back(pPlayer);
622 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
625 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
627 std::list<Unit*> *i_data;
628 Spell &i_spell;
629 const uint32& i_push_type;
630 float i_radius;
631 SpellTargets i_TargetType;
632 Unit* i_originalCaster;
634 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, const uint32 &type,
635 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
636 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
638 i_originalCaster = spell.GetOriginalCaster();
641 template<class T> inline void Visit(GridRefManager<T> &m)
643 assert(i_data);
645 if(!i_originalCaster)
646 return;
648 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
650 if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
651 continue;
653 switch (i_TargetType)
655 case SPELL_TARGETS_HOSTILE:
656 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
657 continue;
658 break;
659 case SPELL_TARGETS_NOT_FRIENDLY:
660 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
661 continue;
662 break;
663 case SPELL_TARGETS_NOT_HOSTILE:
664 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
665 continue;
666 break;
667 case SPELL_TARGETS_FRIENDLY:
668 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
669 continue;
670 break;
671 case SPELL_TARGETS_AOE_DAMAGE:
673 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
674 continue;
675 if(!itr->getSource()->isTargetableForAttack())
676 continue;
678 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
680 if( check->GetTypeId()==TYPEID_PLAYER )
682 if (check->IsFriendlyTo( itr->getSource() ))
683 continue;
685 else
687 if (!check->IsHostileTo( itr->getSource() ))
688 continue;
691 break;
692 default: continue;
695 switch(i_push_type)
697 case PUSH_IN_FRONT:
698 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
699 i_data->push_back(itr->getSource());
700 break;
701 case PUSH_IN_BACK:
702 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
703 i_data->push_back(itr->getSource());
704 break;
705 case PUSH_SELF_CENTER:
706 if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
707 i_data->push_back(itr->getSource());
708 break;
709 case PUSH_DEST_CENTER:
710 if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
711 i_data->push_back(itr->getSource());
712 break;
713 case PUSH_TARGET_CENTER:
714 if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
715 i_data->push_back(itr->getSource());
716 break;
721 #ifdef WIN32
722 template<> inline void Visit(CorpseMapType & ) {}
723 template<> inline void Visit(GameObjectMapType & ) {}
724 template<> inline void Visit(DynamicObjectMapType & ) {}
725 #endif
728 #ifndef WIN32
729 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
730 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
731 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
732 #endif
735 typedef void(Spell::*pEffect)(uint32 i);
737 class SpellEvent : public BasicEvent
739 public:
740 SpellEvent(Spell* spell);
741 virtual ~SpellEvent();
743 virtual bool Execute(uint64 e_time, uint32 p_time);
744 virtual void Abort(uint64 e_time);
745 virtual bool IsDeletable() const;
746 protected:
747 Spell* m_Spell;
749 #endif