[8483] Implement glyph 43361.
[getmangos.git] / src / game / Spell.h
blobc197c3e610991f8ae8908895d0722cb3a2e4dbb7
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"
23 #include "SharedDefines.h"
25 class WorldSession;
26 class Unit;
27 class DynamicObj;
28 class Player;
29 class GameObject;
30 class Group;
31 class Aura;
33 enum SpellCastTargetFlags
35 TARGET_FLAG_SELF = 0x00000000,
36 TARGET_FLAG_UNUSED1 = 0x00000001, // not used in any spells as of 3.0.3 (can be set dynamically)
37 TARGET_FLAG_UNIT = 0x00000002, // pguid
38 TARGET_FLAG_UNUSED2 = 0x00000004, // not used in any spells as of 3.0.3 (can be set dynamically)
39 TARGET_FLAG_UNUSED3 = 0x00000008, // not used in any spells as of 3.0.3 (can be set dynamically)
40 TARGET_FLAG_ITEM = 0x00000010, // pguid
41 TARGET_FLAG_SOURCE_LOCATION = 0x00000020, // 3 float
42 TARGET_FLAG_DEST_LOCATION = 0x00000040, // 3 float
43 TARGET_FLAG_OBJECT_UNK = 0x00000080, // used in 7 spells only
44 TARGET_FLAG_UNIT_UNK = 0x00000100, // looks like self target (480 spells)
45 TARGET_FLAG_PVP_CORPSE = 0x00000200, // pguid
46 TARGET_FLAG_UNIT_CORPSE = 0x00000400, // 10 spells (gathering professions)
47 TARGET_FLAG_OBJECT = 0x00000800, // pguid, 2 spells
48 TARGET_FLAG_TRADE_ITEM = 0x00001000, // pguid, 0 spells
49 TARGET_FLAG_STRING = 0x00002000, // string, 0 spells
50 TARGET_FLAG_UNK1 = 0x00004000, // 199 spells, opening object/lock
51 TARGET_FLAG_CORPSE = 0x00008000, // pguid, resurrection spells
52 TARGET_FLAG_UNK2 = 0x00010000, // pguid, not used in any spells as of 3.0.3 (can be set dynamically)
53 TARGET_FLAG_GLYPH = 0x00020000 // used in glyph spells
56 enum SpellCastFlags
58 CAST_FLAG_NONE = 0x00000000,
59 CAST_FLAG_UNKNOWN0 = 0x00000001, // may be pending spell cast
60 CAST_FLAG_UNKNOWN1 = 0x00000002,
61 CAST_FLAG_UNKNOWN11 = 0x00000004,
62 CAST_FLAG_UNKNOWN12 = 0x00000008,
63 CAST_FLAG_UNKNOWN2 = 0x00000010,
64 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
65 CAST_FLAG_UNKNOWN8 = 0x00000040,
66 CAST_FLAG_UNKNOWN9 = 0x00000080,
67 CAST_FLAG_UNKNOWN3 = 0x00000100,
68 CAST_FLAG_UNKNOWN13 = 0x00000200,
69 CAST_FLAG_UNKNOWN14 = 0x00000400,
70 CAST_FLAG_UNKNOWN6 = 0x00000800, // wotlk, trigger rune cooldown
71 CAST_FLAG_UNKNOWN15 = 0x00001000,
72 CAST_FLAG_UNKNOWN16 = 0x00002000,
73 CAST_FLAG_UNKNOWN17 = 0x00004000,
74 CAST_FLAG_UNKNOWN18 = 0x00008000,
75 CAST_FLAG_UNKNOWN19 = 0x00010000,
76 CAST_FLAG_UNKNOWN4 = 0x00020000, // wotlk
77 CAST_FLAG_UNKNOWN10 = 0x00040000,
78 CAST_FLAG_UNKNOWN5 = 0x00080000, // wotlk
79 CAST_FLAG_UNKNOWN20 = 0x00100000,
80 CAST_FLAG_UNKNOWN7 = 0x00200000 // wotlk, rune cooldown list
83 enum SpellNotifyPushType
85 PUSH_IN_FRONT,
86 PUSH_IN_FRONT_30,
87 PUSH_IN_BACK,
88 PUSH_SELF_CENTER,
89 PUSH_DEST_CENTER,
90 PUSH_TARGET_CENTER
93 bool IsQuestTameSpell(uint32 spellId);
95 namespace MaNGOS
97 struct SpellNotifierPlayer;
98 struct SpellNotifierCreatureAndPlayer;
101 class SpellCastTargets
103 public:
104 SpellCastTargets();
105 ~SpellCastTargets();
107 bool read ( WorldPacket * data, Unit *caster );
108 void write ( WorldPacket * data );
110 SpellCastTargets& operator=(const SpellCastTargets &target)
112 m_unitTarget = target.m_unitTarget;
113 m_itemTarget = target.m_itemTarget;
114 m_GOTarget = target.m_GOTarget;
116 m_unitTargetGUID = target.m_unitTargetGUID;
117 m_GOTargetGUID = target.m_GOTargetGUID;
118 m_CorpseTargetGUID = target.m_CorpseTargetGUID;
119 m_itemTargetGUID = target.m_itemTargetGUID;
121 m_itemTargetEntry = target.m_itemTargetEntry;
123 m_srcX = target.m_srcX;
124 m_srcY = target.m_srcY;
125 m_srcZ = target.m_srcZ;
127 m_destX = target.m_destX;
128 m_destY = target.m_destY;
129 m_destZ = target.m_destZ;
131 m_strTarget = target.m_strTarget;
133 m_targetMask = target.m_targetMask;
135 return *this;
138 uint64 getUnitTargetGUID() const { return m_unitTargetGUID; }
139 Unit *getUnitTarget() const { return m_unitTarget; }
140 void setUnitTarget(Unit *target);
141 void setDestination(float x, float y, float z);
142 void setSource(float x, float y, float z);
144 uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
145 GameObject *getGOTarget() const { return m_GOTarget; }
146 void setGOTarget(GameObject *target);
148 uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
149 void setCorpseTarget(Corpse* corpse);
150 uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
151 Item* getItemTarget() const { return m_itemTarget; }
152 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
153 void setItemTarget(Item* item);
154 void updateTradeSlotItem()
156 if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
158 m_itemTargetGUID = m_itemTarget->GetGUID();
159 m_itemTargetEntry = m_itemTarget->GetEntry();
163 bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
165 void Update(Unit* caster);
167 float m_srcX, m_srcY, m_srcZ;
168 float m_destX, m_destY, m_destZ;
169 std::string m_strTarget;
171 uint32 m_targetMask;
172 private:
173 // objects (can be used at spell creating and after Update at casting
174 Unit *m_unitTarget;
175 GameObject *m_GOTarget;
176 Item *m_itemTarget;
178 // object GUID/etc, can be used always
179 uint64 m_unitTargetGUID;
180 uint64 m_GOTargetGUID;
181 uint64 m_CorpseTargetGUID;
182 uint64 m_itemTargetGUID;
183 uint32 m_itemTargetEntry;
186 enum SpellState
188 SPELL_STATE_NULL = 0,
189 SPELL_STATE_PREPARING = 1,
190 SPELL_STATE_CASTING = 2,
191 SPELL_STATE_FINISHED = 3,
192 SPELL_STATE_IDLE = 4,
193 SPELL_STATE_DELAYED = 5
196 enum SpellTargets
198 SPELL_TARGETS_HOSTILE,
199 SPELL_TARGETS_NOT_FRIENDLY,
200 SPELL_TARGETS_NOT_HOSTILE,
201 SPELL_TARGETS_FRIENDLY,
202 SPELL_TARGETS_AOE_DAMAGE
205 #define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL (1*IN_MILISECONDS)
207 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
209 class Spell
211 friend struct MaNGOS::SpellNotifierPlayer;
212 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
213 friend void Unit::SetCurrentCastedSpell( Spell * pSpell );
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 EffectCreateItem2(uint32 i);
234 void EffectCreateRandomItem(uint32 i);
235 void EffectPersistentAA(uint32 i);
236 void EffectEnergize(uint32 i);
237 void EffectOpenLock(uint32 i);
238 void EffectSummonChangeItem(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 EffectJump(uint32 i);
252 void EffectTeleUnitsFaceCaster(uint32 i);
253 void EffectLearnSkill(uint32 i);
254 void EffectAddHonor(uint32 i);
255 void EffectTradeSkill(uint32 i);
256 void EffectEnchantItemPerm(uint32 i);
257 void EffectEnchantItemTmp(uint32 i);
258 void EffectTameCreature(uint32 i);
259 void EffectSummonPet(uint32 i);
260 void EffectLearnPetSpell(uint32 i);
261 void EffectWeaponDmg(uint32 i);
262 void EffectForceCast(uint32 i);
263 void EffectTriggerSpell(uint32 i);
264 void EffectTriggerMissileSpell(uint32 i);
265 void EffectThreat(uint32 i);
266 void EffectHealMaxHealth(uint32 i);
267 void EffectInterruptCast(uint32 i);
268 void EffectSummonObjectWild(uint32 i);
269 void EffectScriptEffect(uint32 i);
270 void EffectSanctuary(uint32 i);
271 void EffectAddComboPoints(uint32 i);
272 void EffectDuel(uint32 i);
273 void EffectStuck(uint32 i);
274 void EffectSummonPlayer(uint32 i);
275 void EffectActivateObject(uint32 i);
276 void EffectApplyGlyph(uint32 i);
277 void EffectSummonTotem(uint32 i);
278 void EffectEnchantHeldItem(uint32 i);
279 void EffectSummonObject(uint32 i);
280 void EffectResurrect(uint32 i);
281 void EffectParry(uint32 i);
282 void EffectBlock(uint32 i);
283 void EffectLeapForward(uint32 i);
284 void EffectLeapBack(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 EffectCharge2(uint32 i);
295 void EffectProspecting(uint32 i);
296 void EffectMilling(uint32 i);
297 void EffectRenamePet(uint32 i);
298 void EffectSendTaxi(uint32 i);
299 void EffectSummonCritter(uint32 i);
300 void EffectKnockBack(uint32 i);
301 void EffectPlayerPull(uint32 i);
302 void EffectDispelMechanic(uint32 i);
303 void EffectSummonDeadPet(uint32 i);
304 void EffectDestroyAllTotems(uint32 i);
305 void EffectDurabilityDamage(uint32 i);
306 void EffectSkill(uint32 i);
307 void EffectTaunt(uint32 i);
308 void EffectDurabilityDamagePCT(uint32 i);
309 void EffectModifyThreatPercent(uint32 i);
310 void EffectResurrectNew(uint32 i);
311 void EffectAddExtraAttacks(uint32 i);
312 void EffectSpiritHeal(uint32 i);
313 void EffectSkinPlayerCorpse(uint32 i);
314 void EffectSummonDemon(uint32 i);
315 void EffectStealBeneficialBuff(uint32 i);
316 void EffectUnlearnSpecialization(uint32 i);
317 void EffectHealPct(uint32 i);
318 void EffectEnergisePct(uint32 i);
319 void EffectTriggerSpellWithValue(uint32 i);
320 void EffectTriggerRitualOfSummoning(uint32 i);
321 void EffectKillCreditPersonal(uint32 i);
322 void EffectKillCredit(uint32 i);
323 void EffectQuestFail(uint32 i);
324 void EffectActivateRune(uint32 i);
325 void EffectTitanGrip(uint32 i);
326 void EffectEnchantItemPrismatic(uint32 i);
327 void EffectPlayMusic(uint32 i);
329 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
330 ~Spell();
332 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
333 void cancel();
334 void update(uint32 difftime);
335 void cast(bool skipCheck = false);
336 void finish(bool ok = true);
337 void TakePower();
338 void TakeRunePower();
339 void TakeReagents();
340 void TakeCastItem();
342 SpellCastResult CheckCast(bool strict);
343 SpellCastResult CheckPetCast(Unit* target);
345 // handlers
346 void handle_immediate();
347 uint64 handle_delayed(uint64 t_offset);
348 // handler helpers
349 void _handle_immediate_phase();
350 void _handle_finish_phase();
352 SpellCastResult CheckItems();
353 SpellCastResult CheckRange(bool strict);
354 SpellCastResult CheckPower();
355 SpellCastResult CheckRuneCost(uint32 runeCostID);
356 SpellCastResult CheckCasterAuras() const;
358 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
359 int32 CalculatePowerCost();
361 bool HaveTargetsForEffect(uint8 effect) const;
362 void Delayed();
363 void DelayedChannel();
364 uint32 getState() const { return m_spellState; }
365 void setState(uint32 state) { m_spellState = state; }
367 void DoCreateItem(uint32 i, uint32 itemtype);
368 void WriteSpellGoTargets( WorldPacket * data );
369 void WriteAmmoToPacket( WorldPacket * data );
371 typedef std::list<Unit*> UnitList;
372 void FillTargetMap();
373 void SetTargetMap(uint32 effIndex,uint32 targetMode,UnitList& TagUnitMap);
375 void FillAreaTargets( UnitList& TagUnitMap, float x, float y, float radius, SpellNotifyPushType pushType, SpellTargets spellTargets );
376 void FillRaidOrPartyTargets( UnitList &TagUnitMap, Unit* member, Unit* center, float radius, bool raid, bool withPets, bool withcaster );
377 void FillRaidOrPartyManaPriorityTargets( UnitList &TagUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster );
378 void FillRaidOrPartyHealthPriorityTargets( UnitList &TagUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster );
380 template<typename T> WorldObject* FindCorpseUsing();
382 bool CheckTarget( Unit* target, uint32 eff );
383 bool CanAutoCast(Unit* target);
385 static void MANGOS_DLL_SPEC SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 cast_count, SpellCastResult result);
386 void SendCastResult(SpellCastResult result);
387 void SendSpellStart();
388 void SendSpellGo();
389 void SendSpellCooldown();
390 void SendLogExecute();
391 void SendInterrupted(uint8 result);
392 void SendChannelUpdate(uint32 time);
393 void SendChannelStart(uint32 duration);
394 void SendResurrectRequest(Player* target);
395 void SendPlaySpellVisual(uint32 SpellID);
397 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
398 void HandleThreatSpells(uint32 spellId);
399 //void HandleAddAura(Unit* Target);
401 SpellEntry const* m_spellInfo;
402 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
403 Item* m_CastItem;
404 uint8 m_cast_count;
405 uint32 m_glyphIndex;
406 SpellCastTargets m_targets;
408 int32 GetCastTime() const { return m_casttime; }
409 bool IsAutoRepeat() const { return m_autoRepeat; }
410 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
411 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
412 bool IsNextMeleeSwingSpell() const
414 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
416 bool IsRangedSpell() const
418 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
420 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
421 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
422 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
424 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
425 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
426 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
427 uint64 GetDelayStart() const { return m_delayStart; }
428 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
429 uint64 GetDelayMoment() const { return m_delayMoment; }
431 bool IsNeedSendToClient() const;
433 CurrentSpellTypes GetCurrentContainer();
435 Unit* GetCaster() const { return m_caster; }
436 Unit* GetOriginalCaster() const { return m_originalCaster; }
437 int32 GetPowerCost() const { return m_powerCost; }
439 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
441 bool IsAffectedByAura(Aura *aura);
443 bool CheckTargetCreatureType(Unit* target) const;
445 void AddTriggeredSpell(SpellEntry const* spellInfo) { m_TriggerSpells.push_back(spellInfo); }
446 void AddPrecastSpell(SpellEntry const* spellInfo) { m_preCastSpells.push_back(spellInfo); }
447 void AddTriggeredSpell(uint32 spellId);
448 void AddPrecastSpell(uint32 spellId);
449 void CastPreCastSpells(Unit* target);
450 void CastTriggerSpells();
452 void CleanupTargetList();
453 protected:
455 void SendLoot(uint64 guid, LootType loottype);
457 Unit* m_caster;
459 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
460 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
461 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
463 Spell** m_selfContainer; // pointer to our spell container (if applicable)
464 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
466 //Spell data
467 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
468 WeaponAttackType m_attackType; // For weapon based attack
469 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
470 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
471 bool m_canReflect; // can reflect this spell?
472 bool m_autoRepeat;
473 uint8 m_runesState;
475 uint8 m_delayAtDamageCount;
476 bool isDelayableNoMore()
478 if(m_delayAtDamageCount >= 2)
479 return true;
481 m_delayAtDamageCount++;
482 return false;
485 // Delayed spells system
486 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
487 uint64 m_delayMoment; // moment of next delay call, used internally
488 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
490 // These vars are used in both delayed spell system and modified immediate spell system
491 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
492 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
493 bool m_needSpellLog; // need to send spell log?
494 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
495 float m_damageMultipliers[3]; // by effect: damage multiplier
497 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
498 Unit* unitTarget;
499 Item* itemTarget;
500 GameObject* gameObjTarget;
501 int32 damage;
503 // this is set in Spell Hit, but used in Apply Aura handler
504 DiminishingLevels m_diminishLevel;
505 DiminishingGroup m_diminishGroup;
507 // -------------------------------------------
508 GameObject* focusObject;
510 // Damage and healing in effects need just calculate
511 int32 m_damage; // Damge in effects count here
512 int32 m_healing; // Healing in effects count here
513 int32 m_healthLeech; // Health leech in effects for all targets count here
515 //******************************************
516 // Spell trigger system
517 //******************************************
518 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
519 uint32 m_procAttacker; // Attacker trigger flags
520 uint32 m_procVictim; // Victim trigger flags
521 void prepareDataForTriggerSystem();
523 //*****************************************
524 // Spell target subsystem
525 //*****************************************
526 // Targets store structures and data
527 struct TargetInfo
529 uint64 targetGUID;
530 uint64 timeDelay;
531 SpellMissInfo missCondition:8;
532 SpellMissInfo reflectResult:8;
533 uint8 effectMask:8;
534 bool processed:1;
536 std::list<TargetInfo> m_UniqueTargetInfo;
537 uint8 m_needAliveTargetMask; // Mask req. alive targets
539 struct GOTargetInfo
541 uint64 targetGUID;
542 uint64 timeDelay;
543 uint8 effectMask:8;
544 bool processed:1;
546 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
548 struct ItemTargetInfo
550 Item *item;
551 uint8 effectMask;
553 std::list<ItemTargetInfo> m_UniqueItemInfo;
555 void AddUnitTarget(Unit* target, uint32 effIndex);
556 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
557 void AddGOTarget(GameObject* target, uint32 effIndex);
558 void AddGOTarget(uint64 goGUID, uint32 effIndex);
559 void AddItemTarget(Item* target, uint32 effIndex);
560 void DoAllEffectOnTarget(TargetInfo *target);
561 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
562 void DoAllEffectOnTarget(GOTargetInfo *target);
563 void DoAllEffectOnTarget(ItemTargetInfo *target);
564 bool IsAliveUnitPresentInTargetList();
565 SpellCastResult CanOpenLock(uint32 effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
566 // -------------------------------------------
568 //List For Triggered Spells
569 typedef std::list<SpellEntry const*> SpellInfoList;
570 SpellInfoList m_TriggerSpells; // casted by caster to same targets settings in m_targets at success finish of current spell
571 SpellInfoList m_preCastSpells; // casted by caster to each target at spell hit before spell effects apply
573 uint32 m_spellState;
574 uint32 m_timer;
576 float m_castPositionX;
577 float m_castPositionY;
578 float m_castPositionZ;
579 float m_castOrientation;
580 bool m_IsTriggeredSpell;
582 // if need this can be replaced by Aura copy
583 // we can't store original aura link to prevent access to deleted auras
584 // and in same time need aura data and after aura deleting.
585 SpellEntry const* m_triggeredByAuraSpell;
588 enum ReplenishType
590 REPLENISH_UNDEFINED = 0,
591 REPLENISH_HEALTH = 20,
592 REPLENISH_MANA = 21,
593 REPLENISH_RAGE = 22
596 namespace MaNGOS
598 struct MANGOS_DLL_DECL SpellNotifierPlayer
600 std::list<Unit*> &i_data;
601 Spell &i_spell;
602 const uint32& i_index;
603 float i_radius;
604 Unit* i_originalCaster;
606 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
607 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
609 i_originalCaster = i_spell.GetOriginalCaster();
612 void Visit(PlayerMapType &m)
614 if(!i_originalCaster)
615 return;
617 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
619 Player * pPlayer = itr->getSource();
620 if( !pPlayer->isAlive() || pPlayer->isInFlight())
621 continue;
623 if( i_originalCaster->IsFriendlyTo(pPlayer) )
624 continue;
626 if( pPlayer->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius))
627 i_data.push_back(pPlayer);
630 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
633 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
635 std::list<Unit*> *i_data;
636 Spell &i_spell;
637 SpellNotifyPushType i_push_type;
638 float i_radius;
639 SpellTargets i_TargetType;
640 Unit* i_originalCaster;
642 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, SpellNotifyPushType type,
643 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
644 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
646 i_originalCaster = spell.GetOriginalCaster();
649 template<class T> inline void Visit(GridRefManager<T> &m)
651 assert(i_data);
653 if(!i_originalCaster)
654 return;
656 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
658 if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
659 continue;
661 // mostly phase check
662 if(!itr->getSource()->IsInMap(i_originalCaster))
663 continue;
665 switch (i_TargetType)
667 case SPELL_TARGETS_HOSTILE:
668 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
669 continue;
670 break;
671 case SPELL_TARGETS_NOT_FRIENDLY:
672 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
673 continue;
674 break;
675 case SPELL_TARGETS_NOT_HOSTILE:
676 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
677 continue;
678 break;
679 case SPELL_TARGETS_FRIENDLY:
680 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
681 continue;
682 break;
683 case SPELL_TARGETS_AOE_DAMAGE:
685 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
686 continue;
687 if(!itr->getSource()->isTargetableForAttack())
688 continue;
690 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
692 if( check->GetTypeId()==TYPEID_PLAYER )
694 if (check->IsFriendlyTo( itr->getSource() ))
695 continue;
697 else
699 if (!check->IsHostileTo( itr->getSource() ))
700 continue;
703 break;
704 default: continue;
707 switch(i_push_type)
709 case PUSH_IN_FRONT:
710 if(i_spell.GetCaster()->isInFrontInMap((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
711 i_data->push_back(itr->getSource());
712 break;
713 case PUSH_IN_FRONT_30:
714 if(i_spell.GetCaster()->isInFrontInMap((Unit*)(itr->getSource()), i_radius, M_PI/6 ))
715 i_data->push_back(itr->getSource());
716 break;
717 case PUSH_IN_BACK:
718 if(i_spell.GetCaster()->isInBackInMap((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
719 i_data->push_back(itr->getSource());
720 break;
721 case PUSH_SELF_CENTER:
722 if(i_spell.GetCaster()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
723 i_data->push_back(itr->getSource());
724 break;
725 case PUSH_DEST_CENTER:
726 if(itr->getSource()->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius))
727 i_data->push_back(itr->getSource());
728 break;
729 case PUSH_TARGET_CENTER:
730 if(i_spell.m_targets.getUnitTarget()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
731 i_data->push_back(itr->getSource());
732 break;
737 #ifdef WIN32
738 template<> inline void Visit(CorpseMapType & ) {}
739 template<> inline void Visit(GameObjectMapType & ) {}
740 template<> inline void Visit(DynamicObjectMapType & ) {}
741 #endif
744 #ifndef WIN32
745 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
746 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
747 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
748 #endif
751 typedef void(Spell::*pEffect)(uint32 i);
753 class SpellEvent : public BasicEvent
755 public:
756 SpellEvent(Spell* spell);
757 virtual ~SpellEvent();
759 virtual bool Execute(uint64 e_time, uint32 p_time);
760 virtual void Abort(uint64 e_time);
761 virtual bool IsDeletable() const;
762 protected:
763 Spell* m_Spell;
765 #endif