port over some changes from Trinity version including one possible memory leak fix
[AHbot.git] / src / game / Spell.h
blobfc2eb23148f39c623f49875edb84892ca2e7c143
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_NONE = 0x0000,
36 TARGET_FLAG_SWIMMER = 0x0002,
37 TARGET_FLAG_ITEM = 0x0010,
38 TARGET_FLAG_SOURCE_AREA = 0x0020,
39 TARGET_FLAG_DEST_AREA = 0x0040,
40 TARGET_FLAG_UNKNOWN = 0x0080,
41 TARGET_FLAG_SELF = 0x0100,
42 TARGET_FLAG_PVP_CORPSE = 0x0200,
43 TARGET_FLAG_MASS_SPIRIT_HEAL = 0x0400,
44 TARGET_FLAG_BEAST_CORPSE = 0x0402,
45 TARGET_FLAG_OBJECT = 0x4000,
46 TARGET_FLAG_RESURRECTABLE = 0x8000*/
48 TARGET_FLAG_SELF = 0x00000000,
49 TARGET_FLAG_UNUSED1 = 0x00000001, // not used in any spells as of 3.0.3 (can be set dynamically)
50 TARGET_FLAG_UNIT = 0x00000002, // pguid
51 TARGET_FLAG_UNUSED2 = 0x00000004, // not used in any spells as of 3.0.3 (can be set dynamically)
52 TARGET_FLAG_UNUSED3 = 0x00000008, // not used in any spells as of 3.0.3 (can be set dynamically)
53 TARGET_FLAG_ITEM = 0x00000010, // pguid
54 TARGET_FLAG_SOURCE_LOCATION = 0x00000020, // 3 float
55 TARGET_FLAG_DEST_LOCATION = 0x00000040, // 3 float
56 TARGET_FLAG_OBJECT_UNK = 0x00000080, // used in 7 spells only
57 TARGET_FLAG_UNIT_UNK = 0x00000100, // looks like self target (480 spells)
58 TARGET_FLAG_PVP_CORPSE = 0x00000200, // pguid
59 TARGET_FLAG_UNIT_CORPSE = 0x00000400, // 10 spells (gathering professions)
60 TARGET_FLAG_OBJECT = 0x00000800, // pguid, 2 spells
61 TARGET_FLAG_TRADE_ITEM = 0x00001000, // pguid, 0 spells
62 TARGET_FLAG_STRING = 0x00002000, // string, 0 spells
63 TARGET_FLAG_UNK1 = 0x00004000, // 199 spells, opening object/lock
64 TARGET_FLAG_CORPSE = 0x00008000, // pguid, resurrection spells
65 TARGET_FLAG_UNK2 = 0x00010000, // pguid, not used in any spells as of 3.0.3 (can be set dynamically)
66 TARGET_FLAG_GLYPH = 0x00020000 // used in glyph spells
69 enum SpellCastFlags
71 CAST_FLAG_NONE = 0x00000000,
72 CAST_FLAG_UNKNOWN0 = 0x00000001, // may be pending spell cast
73 CAST_FLAG_UNKNOWN1 = 0x00000002,
74 CAST_FLAG_UNKNOWN11 = 0x00000004,
75 CAST_FLAG_UNKNOWN12 = 0x00000008,
76 CAST_FLAG_UNKNOWN2 = 0x00000010,
77 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
78 CAST_FLAG_UNKNOWN8 = 0x00000040,
79 CAST_FLAG_UNKNOWN9 = 0x00000080,
80 CAST_FLAG_UNKNOWN3 = 0x00000100,
81 CAST_FLAG_UNKNOWN13 = 0x00000200,
82 CAST_FLAG_UNKNOWN14 = 0x00000400,
83 CAST_FLAG_UNKNOWN6 = 0x00000800, // wotlk, trigger rune cooldown
84 CAST_FLAG_UNKNOWN15 = 0x00001000,
85 CAST_FLAG_UNKNOWN16 = 0x00002000,
86 CAST_FLAG_UNKNOWN17 = 0x00004000,
87 CAST_FLAG_UNKNOWN18 = 0x00008000,
88 CAST_FLAG_UNKNOWN19 = 0x00010000,
89 CAST_FLAG_UNKNOWN4 = 0x00020000, // wotlk
90 CAST_FLAG_UNKNOWN10 = 0x00040000,
91 CAST_FLAG_UNKNOWN5 = 0x00080000, // wotlk
92 CAST_FLAG_UNKNOWN20 = 0x00100000,
93 CAST_FLAG_UNKNOWN7 = 0x00200000 // wotlk, rune cooldown list
96 enum SpellNotifyPushType
98 PUSH_IN_FRONT,
99 PUSH_IN_BACK,
100 PUSH_SELF_CENTER,
101 PUSH_DEST_CENTER,
102 PUSH_TARGET_CENTER
105 bool IsQuestTameSpell(uint32 spellId);
107 namespace MaNGOS
109 struct SpellNotifierPlayer;
110 struct SpellNotifierCreatureAndPlayer;
113 class SpellCastTargets
115 public:
116 SpellCastTargets();
117 ~SpellCastTargets();
119 bool read ( WorldPacket * data, Unit *caster );
120 void write ( WorldPacket * data );
122 SpellCastTargets& operator=(const SpellCastTargets &target)
124 m_unitTarget = target.m_unitTarget;
125 m_itemTarget = target.m_itemTarget;
126 m_GOTarget = target.m_GOTarget;
128 m_unitTargetGUID = target.m_unitTargetGUID;
129 m_GOTargetGUID = target.m_GOTargetGUID;
130 m_CorpseTargetGUID = target.m_CorpseTargetGUID;
131 m_itemTargetGUID = target.m_itemTargetGUID;
133 m_itemTargetEntry = target.m_itemTargetEntry;
135 m_srcX = target.m_srcX;
136 m_srcY = target.m_srcY;
137 m_srcZ = target.m_srcZ;
139 m_destX = target.m_destX;
140 m_destY = target.m_destY;
141 m_destZ = target.m_destZ;
143 m_strTarget = target.m_strTarget;
145 m_targetMask = target.m_targetMask;
147 return *this;
150 uint64 getUnitTargetGUID() const { return m_unitTargetGUID; }
151 Unit *getUnitTarget() const { return m_unitTarget; }
152 void setUnitTarget(Unit *target);
153 void setDestination(float x, float y, float z);
154 void setSource(float x, float y, float z);
156 uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
157 GameObject *getGOTarget() const { return m_GOTarget; }
158 void setGOTarget(GameObject *target);
160 uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
161 void setCorpseTarget(Corpse* corpse);
162 uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
163 Item* getItemTarget() const { return m_itemTarget; }
164 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
165 void setItemTarget(Item* item);
166 void updateTradeSlotItem()
168 if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
170 m_itemTargetGUID = m_itemTarget->GetGUID();
171 m_itemTargetEntry = m_itemTarget->GetEntry();
175 bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
177 void Update(Unit* caster);
179 float m_srcX, m_srcY, m_srcZ;
180 float m_destX, m_destY, m_destZ;
181 std::string m_strTarget;
183 uint32 m_targetMask;
184 private:
185 // objects (can be used at spell creating and after Update at casting
186 Unit *m_unitTarget;
187 GameObject *m_GOTarget;
188 Item *m_itemTarget;
190 // object GUID/etc, can be used always
191 uint64 m_unitTargetGUID;
192 uint64 m_GOTargetGUID;
193 uint64 m_CorpseTargetGUID;
194 uint64 m_itemTargetGUID;
195 uint32 m_itemTargetEntry;
198 enum SpellState
200 SPELL_STATE_NULL = 0,
201 SPELL_STATE_PREPARING = 1,
202 SPELL_STATE_CASTING = 2,
203 SPELL_STATE_FINISHED = 3,
204 SPELL_STATE_IDLE = 4,
205 SPELL_STATE_DELAYED = 5
208 enum SpellTargets
210 SPELL_TARGETS_HOSTILE,
211 SPELL_TARGETS_NOT_FRIENDLY,
212 SPELL_TARGETS_NOT_HOSTILE,
213 SPELL_TARGETS_FRIENDLY,
214 SPELL_TARGETS_AOE_DAMAGE
217 #define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL (1*IN_MILISECONDS)
219 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
221 class Spell
223 friend struct MaNGOS::SpellNotifierPlayer;
224 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
225 public:
227 void EffectNULL(uint32 );
228 void EffectUnused(uint32 );
229 void EffectDistract(uint32 i);
230 void EffectPull(uint32 i);
231 void EffectSchoolDMG(uint32 i);
232 void EffectEnvirinmentalDMG(uint32 i);
233 void EffectInstaKill(uint32 i);
234 void EffectDummy(uint32 i);
235 void EffectTeleportUnits(uint32 i);
236 void EffectApplyAura(uint32 i);
237 void EffectSendEvent(uint32 i);
238 void EffectPowerBurn(uint32 i);
239 void EffectPowerDrain(uint32 i);
240 void EffectHeal(uint32 i);
241 void EffectHealthLeech(uint32 i);
242 void EffectQuestComplete(uint32 i);
243 void EffectCreateItem(uint32 i);
244 void EffectCreateItem2(uint32 i);
245 void EffectPersistentAA(uint32 i);
246 void EffectEnergize(uint32 i);
247 void EffectOpenLock(uint32 i);
248 void EffectSummonChangeItem(uint32 i);
249 void EffectOpenSecretSafe(uint32 i);
250 void EffectProficiency(uint32 i);
251 void EffectApplyAreaAura(uint32 i);
252 void EffectSummonType(uint32 i);
253 void EffectSummon(uint32 i);
254 void EffectLearnSpell(uint32 i);
255 void EffectDispel(uint32 i);
256 void EffectDualWield(uint32 i);
257 void EffectPickPocket(uint32 i);
258 void EffectAddFarsight(uint32 i);
259 void EffectSummonWild(uint32 i);
260 void EffectSummonGuardian(uint32 i);
261 void EffectHealMechanical(uint32 i);
262 void EffectJump(uint32 i);
263 void EffectTeleUnitsFaceCaster(uint32 i);
264 void EffectLearnSkill(uint32 i);
265 void EffectAddHonor(uint32 i);
266 void EffectTradeSkill(uint32 i);
267 void EffectEnchantItemPerm(uint32 i);
268 void EffectEnchantItemTmp(uint32 i);
269 void EffectTameCreature(uint32 i);
270 void EffectSummonPet(uint32 i);
271 void EffectLearnPetSpell(uint32 i);
272 void EffectWeaponDmg(uint32 i);
273 void EffectForceCast(uint32 i);
274 void EffectTriggerSpell(uint32 i);
275 void EffectTriggerMissileSpell(uint32 i);
276 void EffectThreat(uint32 i);
277 void EffectHealMaxHealth(uint32 i);
278 void EffectInterruptCast(uint32 i);
279 void EffectSummonObjectWild(uint32 i);
280 void EffectScriptEffect(uint32 i);
281 void EffectSanctuary(uint32 i);
282 void EffectAddComboPoints(uint32 i);
283 void EffectDuel(uint32 i);
284 void EffectStuck(uint32 i);
285 void EffectSummonPlayer(uint32 i);
286 void EffectActivateObject(uint32 i);
287 void EffectApplyGlyph(uint32 i);
288 void EffectSummonTotem(uint32 i);
289 void EffectEnchantHeldItem(uint32 i);
290 void EffectSummonObject(uint32 i);
291 void EffectResurrect(uint32 i);
292 void EffectParry(uint32 i);
293 void EffectBlock(uint32 i);
294 void EffectMomentMove(uint32 i);
295 void EffectTransmitted(uint32 i);
296 void EffectDisEnchant(uint32 i);
297 void EffectInebriate(uint32 i);
298 void EffectFeedPet(uint32 i);
299 void EffectDismissPet(uint32 i);
300 void EffectReputation(uint32 i);
301 void EffectSelfResurrect(uint32 i);
302 void EffectSkinning(uint32 i);
303 void EffectCharge(uint32 i);
304 void EffectProspecting(uint32 i);
305 void EffectMilling(uint32 i);
306 void EffectRenamePet(uint32 i);
307 void EffectSendTaxi(uint32 i);
308 void EffectSummonCritter(uint32 i);
309 void EffectKnockBack(uint32 i);
310 void EffectPlayerPull(uint32 i);
311 void EffectDispelMechanic(uint32 i);
312 void EffectSummonDeadPet(uint32 i);
313 void EffectDestroyAllTotems(uint32 i);
314 void EffectDurabilityDamage(uint32 i);
315 void EffectSkill(uint32 i);
316 void EffectTaunt(uint32 i);
317 void EffectDurabilityDamagePCT(uint32 i);
318 void EffectModifyThreatPercent(uint32 i);
319 void EffectResurrectNew(uint32 i);
320 void EffectAddExtraAttacks(uint32 i);
321 void EffectSpiritHeal(uint32 i);
322 void EffectSkinPlayerCorpse(uint32 i);
323 void EffectSummonDemon(uint32 i);
324 void EffectStealBeneficialBuff(uint32 i);
325 void EffectUnlearnSpecialization(uint32 i);
326 void EffectHealPct(uint32 i);
327 void EffectEnergisePct(uint32 i);
328 void EffectTriggerSpellWithValue(uint32 i);
329 void EffectTriggerRitualOfSummoning(uint32 i);
330 void EffectKillCredit(uint32 i);
331 void EffectQuestFail(uint32 i);
332 void EffectActivateRune(uint32 i);
333 void EffectTitanGrip(uint32 i);
334 void EffectEnchantItemPrismatic(uint32 i);
336 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
337 ~Spell();
339 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
340 void cancel();
341 void update(uint32 difftime);
342 void cast(bool skipCheck = false);
343 void finish(bool ok = true);
344 void TakePower();
345 void TakeRunePower();
346 void TakeReagents();
347 void TakeCastItem();
348 void TriggerSpell();
350 SpellCastResult CheckCast(bool strict);
351 SpellCastResult CheckPetCast(Unit* target);
353 // handlers
354 void handle_immediate();
355 uint64 handle_delayed(uint64 t_offset);
356 // handler helpers
357 void _handle_immediate_phase();
358 void _handle_finish_phase();
360 SpellCastResult CheckItems();
361 SpellCastResult CheckRange(bool strict);
362 SpellCastResult CheckPower();
363 SpellCastResult CheckRuneCost(uint32 runeCostID);
364 SpellCastResult CheckCasterAuras() const;
366 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
367 int32 CalculatePowerCost();
369 bool HaveTargetsForEffect(uint8 effect) const;
370 void Delayed();
371 void DelayedChannel();
372 uint32 getState() const { return m_spellState; }
373 void setState(uint32 state) { m_spellState = state; }
375 void DoCreateItem(uint32 i, uint32 itemtype);
376 void WriteSpellGoTargets( WorldPacket * data );
377 void WriteAmmoToPacket( WorldPacket * data );
379 typedef std::list<Unit*> UnitList;
380 void FillTargetMap();
381 void SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap);
382 void FillAreaTargets( UnitList& TagUnitMap, float x, float y, float radius, SpellNotifyPushType pushType, SpellTargets spellTargets );
384 bool CheckTarget( Unit* target, uint32 eff );
385 bool CanAutoCast(Unit* target);
387 void SendCastResult(SpellCastResult result);
388 void SendSpellStart();
389 void SendSpellGo();
390 void SendSpellCooldown();
391 void SendLogExecute();
392 void SendInterrupted(uint8 result);
393 void SendChannelUpdate(uint32 time);
394 void SendChannelStart(uint32 duration);
395 void SendResurrectRequest(Player* target);
396 void SendPlaySpellVisual(uint32 SpellID);
398 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
399 void HandleThreatSpells(uint32 spellId);
400 //void HandleAddAura(Unit* Target);
402 SpellEntry const* m_spellInfo;
403 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
404 Item* m_CastItem;
405 uint8 m_cast_count;
406 uint32 m_glyphIndex;
407 uint32 m_preCastSpell;
408 SpellCastTargets m_targets;
410 int32 GetCastTime() const { return m_casttime; }
411 bool IsAutoRepeat() const { return m_autoRepeat; }
412 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
413 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
414 bool IsNextMeleeSwingSpell() const
416 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
418 bool IsRangedSpell() const
420 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
422 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
423 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
424 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
426 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
427 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
428 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
429 uint64 GetDelayStart() const { return m_delayStart; }
430 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
431 uint64 GetDelayMoment() const { return m_delayMoment; }
433 bool IsNeedSendToClient() const;
435 CurrentSpellTypes GetCurrentContainer();
437 Unit* GetCaster() const { return m_caster; }
438 Unit* GetOriginalCaster() const { return m_originalCaster; }
439 int32 GetPowerCost() const { return m_powerCost; }
441 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
443 bool IsAffectedByAura(Aura *aura);
445 bool CheckTargetCreatureType(Unit* target) const;
447 void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
449 void CleanupTargetList();
450 protected:
452 void SendLoot(uint64 guid, LootType loottype);
454 Unit* m_caster;
456 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
457 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
458 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
460 Spell** m_selfContainer; // pointer to our spell container (if applicable)
461 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
463 //Spell data
464 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
465 WeaponAttackType m_attackType; // For weapon based attack
466 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
467 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
468 bool m_canReflect; // can reflect this spell?
469 bool m_autoRepeat;
470 uint8 m_runesState;
472 uint8 m_delayAtDamageCount;
473 bool isDelayableNoMore()
475 if(m_delayAtDamageCount >= 2)
476 return true;
478 m_delayAtDamageCount++;
479 return false;
482 // Delayed spells system
483 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
484 uint64 m_delayMoment; // moment of next delay call, used internally
485 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
487 // These vars are used in both delayed spell system and modified immediate spell system
488 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
489 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
490 bool m_needSpellLog; // need to send spell log?
491 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
492 float m_damageMultipliers[3]; // by effect: damage multiplier
494 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
495 Unit* unitTarget;
496 Item* itemTarget;
497 GameObject* gameObjTarget;
498 int32 damage;
500 // this is set in Spell Hit, but used in Apply Aura handler
501 DiminishingLevels m_diminishLevel;
502 DiminishingGroup m_diminishGroup;
504 // -------------------------------------------
505 GameObject* focusObject;
507 // Damage and healing in effects need just calculate
508 int32 m_damage; // Damge in effects count here
509 int32 m_healing; // Healing in effects count here
510 int32 m_healthLeech; // Health leech in effects for all targets count here
512 //******************************************
513 // Spell trigger system
514 //******************************************
515 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
516 uint32 m_procAttacker; // Attacker trigger flags
517 uint32 m_procVictim; // Victim trigger flags
518 void prepareDataForTriggerSystem();
520 //*****************************************
521 // Spell target subsystem
522 //*****************************************
523 // Targets store structures and data
524 struct TargetInfo
526 uint64 targetGUID;
527 uint64 timeDelay;
528 SpellMissInfo missCondition:8;
529 SpellMissInfo reflectResult:8;
530 uint8 effectMask:8;
531 bool processed:1;
533 std::list<TargetInfo> m_UniqueTargetInfo;
534 uint8 m_needAliveTargetMask; // Mask req. alive targets
536 struct GOTargetInfo
538 uint64 targetGUID;
539 uint64 timeDelay;
540 uint8 effectMask:8;
541 bool processed:1;
543 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
545 struct ItemTargetInfo
547 Item *item;
548 uint8 effectMask;
550 std::list<ItemTargetInfo> m_UniqueItemInfo;
552 void AddUnitTarget(Unit* target, uint32 effIndex);
553 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
554 void AddGOTarget(GameObject* target, uint32 effIndex);
555 void AddGOTarget(uint64 goGUID, uint32 effIndex);
556 void AddItemTarget(Item* target, uint32 effIndex);
557 void DoAllEffectOnTarget(TargetInfo *target);
558 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
559 void DoAllEffectOnTarget(GOTargetInfo *target);
560 void DoAllEffectOnTarget(ItemTargetInfo *target);
561 bool IsAliveUnitPresentInTargetList();
562 SpellCastResult CanOpenLock(uint32 effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
563 // -------------------------------------------
565 //List For Triggered Spells
566 typedef std::list<SpellEntry const*> TriggerSpells;
567 TriggerSpells m_TriggerSpells;
569 uint32 m_spellState;
570 uint32 m_timer;
572 float m_castPositionX;
573 float m_castPositionY;
574 float m_castPositionZ;
575 float m_castOrientation;
576 bool m_IsTriggeredSpell;
578 // if need this can be replaced by Aura copy
579 // we can't store original aura link to prevent access to deleted auras
580 // and in same time need aura data and after aura deleting.
581 SpellEntry const* m_triggeredByAuraSpell;
584 enum ReplenishType
586 REPLENISH_UNDEFINED = 0,
587 REPLENISH_HEALTH = 20,
588 REPLENISH_MANA = 21,
589 REPLENISH_RAGE = 22
592 namespace MaNGOS
594 struct MANGOS_DLL_DECL SpellNotifierPlayer
596 std::list<Unit*> &i_data;
597 Spell &i_spell;
598 const uint32& i_index;
599 float i_radius;
600 Unit* i_originalCaster;
602 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
603 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
605 i_originalCaster = i_spell.GetOriginalCaster();
608 void Visit(PlayerMapType &m)
610 if(!i_originalCaster)
611 return;
613 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
615 Player * pPlayer = itr->getSource();
616 if( !pPlayer->isAlive() || pPlayer->isInFlight())
617 continue;
619 if( i_originalCaster->IsFriendlyTo(pPlayer) )
620 continue;
622 if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
623 i_data.push_back(pPlayer);
626 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
629 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
631 std::list<Unit*> *i_data;
632 Spell &i_spell;
633 SpellNotifyPushType i_push_type;
634 float i_radius;
635 SpellTargets i_TargetType;
636 Unit* i_originalCaster;
638 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, SpellNotifyPushType type,
639 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
640 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
642 i_originalCaster = spell.GetOriginalCaster();
645 template<class T> inline void Visit(GridRefManager<T> &m)
647 assert(i_data);
649 if(!i_originalCaster)
650 return;
652 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
654 if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
655 continue;
657 switch (i_TargetType)
659 case SPELL_TARGETS_HOSTILE:
660 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
661 continue;
662 break;
663 case SPELL_TARGETS_NOT_FRIENDLY:
664 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
665 continue;
666 break;
667 case SPELL_TARGETS_NOT_HOSTILE:
668 if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
669 continue;
670 break;
671 case SPELL_TARGETS_FRIENDLY:
672 if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
673 continue;
674 break;
675 case SPELL_TARGETS_AOE_DAMAGE:
677 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
678 continue;
679 if(!itr->getSource()->isTargetableForAttack())
680 continue;
682 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
684 if( check->GetTypeId()==TYPEID_PLAYER )
686 if (check->IsFriendlyTo( itr->getSource() ))
687 continue;
689 else
691 if (!check->IsHostileTo( itr->getSource() ))
692 continue;
695 break;
696 default: continue;
699 switch(i_push_type)
701 case PUSH_IN_FRONT:
702 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
703 i_data->push_back(itr->getSource());
704 break;
705 case PUSH_IN_BACK:
706 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
707 i_data->push_back(itr->getSource());
708 break;
709 case PUSH_SELF_CENTER:
710 if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
711 i_data->push_back(itr->getSource());
712 break;
713 case PUSH_DEST_CENTER:
714 if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
715 i_data->push_back(itr->getSource());
716 break;
717 case PUSH_TARGET_CENTER:
718 if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
719 i_data->push_back(itr->getSource());
720 break;
725 #ifdef WIN32
726 template<> inline void Visit(CorpseMapType & ) {}
727 template<> inline void Visit(GameObjectMapType & ) {}
728 template<> inline void Visit(DynamicObjectMapType & ) {}
729 #endif
732 #ifndef WIN32
733 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
734 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
735 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
736 #endif
739 typedef void(Spell::*pEffect)(uint32 i);
741 class SpellEvent : public BasicEvent
743 public:
744 SpellEvent(Spell* spell);
745 virtual ~SpellEvent();
747 virtual bool Execute(uint64 e_time, uint32 p_time);
748 virtual void Abort(uint64 e_time);
749 virtual bool IsDeletable() const;
750 protected:
751 Spell* m_Spell;
753 #endif