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
22 #include "GridDefines.h"
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
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
104 bool IsQuestTameSpell(uint32 spellId
);
108 struct SpellNotifierPlayer
;
109 struct SpellNotifierCreatureAndPlayer
;
112 class 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
;
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
;
184 // objects (can be used at spell creating and after Update at casting
186 GameObject
*m_GOTarget
;
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
;
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
;
213 friend struct MaNGOS::SpellNotifierPlayer
;
214 friend struct MaNGOS::SpellNotifierCreatureAndPlayer
;
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 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 EffectMomentMove(uint32 i
);
284 void EffectTransmitted(uint32 i
);
285 void EffectDisEnchant(uint32 i
);
286 void EffectInebriate(uint32 i
);
287 void EffectFeedPet(uint32 i
);
288 void EffectDismissPet(uint32 i
);
289 void EffectReputation(uint32 i
);
290 void EffectSelfResurrect(uint32 i
);
291 void EffectSkinning(uint32 i
);
292 void EffectCharge(uint32 i
);
293 void EffectProspecting(uint32 i
);
294 void EffectMilling(uint32 i
);
295 void EffectRenamePet(uint32 i
);
296 void EffectSendTaxi(uint32 i
);
297 void EffectSummonCritter(uint32 i
);
298 void EffectKnockBack(uint32 i
);
299 void EffectPlayerPull(uint32 i
);
300 void EffectDispelMechanic(uint32 i
);
301 void EffectSummonDeadPet(uint32 i
);
302 void EffectDestroyAllTotems(uint32 i
);
303 void EffectDurabilityDamage(uint32 i
);
304 void EffectSkill(uint32 i
);
305 void EffectTaunt(uint32 i
);
306 void EffectDurabilityDamagePCT(uint32 i
);
307 void EffectModifyThreatPercent(uint32 i
);
308 void EffectResurrectNew(uint32 i
);
309 void EffectAddExtraAttacks(uint32 i
);
310 void EffectSpiritHeal(uint32 i
);
311 void EffectSkinPlayerCorpse(uint32 i
);
312 void EffectSummonDemon(uint32 i
);
313 void EffectStealBeneficialBuff(uint32 i
);
314 void EffectUnlearnSpecialization(uint32 i
);
315 void EffectHealPct(uint32 i
);
316 void EffectEnergisePct(uint32 i
);
317 void EffectTriggerSpellWithValue(uint32 i
);
318 void EffectTriggerRitualOfSummoning(uint32 i
);
319 void EffectKillCredit(uint32 i
);
320 void EffectQuestFail(uint32 i
);
321 void EffectActivateRune(uint32 i
);
322 void EffectTitanGrip(uint32 i
);
323 void EffectEnchantItemPrismatic(uint32 i
);
325 Spell( Unit
* Caster
, SpellEntry
const *info
, bool triggered
, uint64 originalCasterGUID
= 0, Spell
** triggeringContainer
= NULL
);
328 void prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
= NULL
);
330 void update(uint32 difftime
);
331 void cast(bool skipCheck
= false);
332 void finish(bool ok
= true);
334 uint8
CheckRuneCost(uint32 runeCostID
);
335 void TakeRunePower();
339 uint8
CanCast(bool strict
);
340 int16
PetCanCast(Unit
* target
);
341 bool CanAutoCast(Unit
* target
);
344 void handle_immediate();
345 uint64
handle_delayed(uint64 t_offset
);
347 void _handle_immediate_phase();
348 void _handle_finish_phase();
351 uint8
CheckRange(bool strict
);
353 uint8
CheckCasterAuras() const;
355 int32
CalculateDamage(uint8 i
, Unit
* target
) { return m_caster
->CalculateSpellDamage(m_spellInfo
,i
,m_currentBasePoints
[i
],target
); }
356 int32
CalculatePowerCost();
358 bool HaveTargetsForEffect(uint8 effect
) const;
360 void DelayedChannel();
361 uint32
getState() const { return m_spellState
; }
362 void setState(uint32 state
) { m_spellState
= state
; }
364 void DoCreateItem(uint32 i
, uint32 itemtype
);
365 void WriteSpellGoTargets( WorldPacket
* data
);
366 void WriteAmmoToPacket( WorldPacket
* data
);
367 void FillTargetMap();
369 void SetTargetMap(uint32 i
,uint32 cur
,std::list
<Unit
*> &TagUnitMap
);
371 Unit
* SelectMagnetTarget();
372 bool CheckTarget( Unit
* target
, uint32 eff
);
374 void SendCastResult(uint8 result
);
375 void SendSpellStart();
377 void SendSpellCooldown();
378 void SendLogExecute();
379 void SendInterrupted(uint8 result
);
380 void SendChannelUpdate(uint32 time
);
381 void SendChannelStart(uint32 duration
);
382 void SendResurrectRequest(Player
* target
);
383 void SendPlaySpellVisual(uint32 SpellID
);
385 void HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
= 1.0);
386 void HandleThreatSpells(uint32 spellId
);
387 //void HandleAddAura(Unit* Target);
389 SpellEntry
const* m_spellInfo
;
390 int32 m_currentBasePoints
[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
394 uint32 m_preCastSpell
;
395 SpellCastTargets m_targets
;
397 int32
GetCastTime() const { return m_casttime
; }
398 bool IsAutoRepeat() const { return m_autoRepeat
; }
399 void SetAutoRepeat(bool rep
) { m_autoRepeat
= rep
; }
400 void ReSetTimer() { m_timer
= m_casttime
> 0 ? m_casttime
: 0; }
401 bool IsNextMeleeSwingSpell() const
403 return m_spellInfo
->Attributes
& (SPELL_ATTR_ON_NEXT_SWING_1
|SPELL_ATTR_ON_NEXT_SWING_2
);
405 bool IsRangedSpell() const
407 return m_spellInfo
->Attributes
& SPELL_ATTR_RANGED
;
409 bool IsChannelActive() const { return m_caster
->GetUInt32Value(UNIT_CHANNEL_SPELL
) != 0; }
410 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_AUTOATTACK
); }
411 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell
&& IsRangedSpell() && (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_AUTOATTACK
); }
413 bool IsDeletable() const { return !m_referencedFromCurrentSpell
&& !m_executedCurrently
; }
414 void SetReferencedFromCurrent(bool yes
) { m_referencedFromCurrentSpell
= yes
; }
415 void SetExecutedCurrently(bool yes
) { m_executedCurrently
= yes
; }
416 uint64
GetDelayStart() const { return m_delayStart
; }
417 void SetDelayStart(uint64 m_time
) { m_delayStart
= m_time
; }
418 uint64
GetDelayMoment() const { return m_delayMoment
; }
420 bool IsNeedSendToClient() const;
422 CurrentSpellTypes
GetCurrentContainer();
424 Unit
* GetCaster() const { return m_caster
; }
425 Unit
* GetOriginalCaster() const { return m_originalCaster
; }
426 int32
GetPowerCost() const { return m_powerCost
; }
428 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
430 bool IsAffectedByAura(Aura
*aura
);
432 bool CheckTargetCreatureType(Unit
* target
) const;
434 void AddTriggeredSpell(SpellEntry
const* spell
) { m_TriggerSpells
.push_back(spell
); }
436 void CleanupTargetList();
439 void SendLoot(uint64 guid
, LootType loottype
);
443 uint64 m_originalCasterGUID
; // real source of cast (aura caster/etc), used for spell targets selection
444 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
445 Unit
* m_originalCaster
; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
447 Spell
** m_selfContainer
; // pointer to our spell container (if applicable)
448 Spell
** m_triggeringContainer
; // pointer to container with spell that has triggered us
451 SpellSchoolMask m_spellSchoolMask
; // Spell school (can be overwrite for some spells (wand shoot for example)
452 WeaponAttackType m_attackType
; // For weapon based attack
453 int32 m_powerCost
; // Calculated spell cost initialized only in Spell::prepare
454 int32 m_casttime
; // Calculated spell cast time initialized only in Spell::prepare
455 bool m_canReflect
; // can reflect this spell?
459 uint8 m_delayAtDamageCount
;
460 bool isDelayableNoMore()
462 if(m_delayAtDamageCount
>= 2)
465 m_delayAtDamageCount
++;
469 // Delayed spells system
470 uint64 m_delayStart
; // time of spell delay start, filled by event handler, zero = just started
471 uint64 m_delayMoment
; // moment of next delay call, used internally
472 bool m_immediateHandled
; // were immediate actions handled? (used by delayed spells only)
474 // These vars are used in both delayed spell system and modified immediate spell system
475 bool m_referencedFromCurrentSpell
; // mark as references to prevent deleted and access by dead pointers
476 bool m_executedCurrently
; // mark as executed to prevent deleted and access by dead pointers
477 bool m_needSpellLog
; // need to send spell log?
478 uint8 m_applyMultiplierMask
; // by effect: damage multiplier needed?
479 float m_damageMultipliers
[3]; // by effect: damage multiplier
481 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
484 GameObject
* gameObjTarget
;
487 // this is set in Spell Hit, but used in Apply Aura handler
488 DiminishingLevels m_diminishLevel
;
489 DiminishingGroup m_diminishGroup
;
491 // -------------------------------------------
492 GameObject
* focusObject
;
494 // Damage and healing in effects need just calculate
495 int32 m_damage
; // Damge in effects count here
496 int32 m_healing
; // Healing in effects count here
497 int32 m_healthLeech
; // Health leech in effects for all targets count here
499 //******************************************
500 // Spell trigger system
501 //******************************************
502 bool m_canTrigger
; // Can start trigger (m_IsTriggeredSpell can`t use for this)
503 uint32 m_procAttacker
; // Attacker trigger flags
504 uint32 m_procVictim
; // Victim trigger flags
505 void prepareDataForTriggerSystem();
507 //*****************************************
508 // Spell target subsystem
509 //*****************************************
510 // Targets store structures and data
515 SpellMissInfo missCondition
:8;
516 SpellMissInfo reflectResult
:8;
520 std::list
<TargetInfo
> m_UniqueTargetInfo
;
521 uint8 m_needAliveTargetMask
; // Mask req. alive targets
530 std::list
<GOTargetInfo
> m_UniqueGOTargetInfo
;
532 struct ItemTargetInfo
537 std::list
<ItemTargetInfo
> m_UniqueItemInfo
;
539 void AddUnitTarget(Unit
* target
, uint32 effIndex
);
540 void AddUnitTarget(uint64 unitGUID
, uint32 effIndex
);
541 void AddGOTarget(GameObject
* target
, uint32 effIndex
);
542 void AddGOTarget(uint64 goGUID
, uint32 effIndex
);
543 void AddItemTarget(Item
* target
, uint32 effIndex
);
544 void DoAllEffectOnTarget(TargetInfo
*target
);
545 void DoSpellHitOnUnit(Unit
*unit
, uint32 effectMask
);
546 void DoAllEffectOnTarget(GOTargetInfo
*target
);
547 void DoAllEffectOnTarget(ItemTargetInfo
*target
);
548 bool IsAliveUnitPresentInTargetList();
549 // -------------------------------------------
551 //List For Triggered Spells
552 typedef std::list
<SpellEntry
const*> TriggerSpells
;
553 TriggerSpells m_TriggerSpells
;
558 float m_castPositionX
;
559 float m_castPositionY
;
560 float m_castPositionZ
;
561 float m_castOrientation
;
562 bool m_IsTriggeredSpell
;
564 // if need this can be replaced by Aura copy
565 // we can't store original aura link to prevent access to deleted auras
566 // and in same time need aura data and after aura deleting.
567 SpellEntry
const* m_triggeredByAuraSpell
;
572 REPLENISH_UNDEFINED
= 0,
573 REPLENISH_HEALTH
= 20,
580 SPELL_TARGETS_HOSTILE
,
581 SPELL_TARGETS_NOT_FRIENDLY
,
582 SPELL_TARGETS_NOT_HOSTILE
,
583 SPELL_TARGETS_FRIENDLY
,
584 SPELL_TARGETS_AOE_DAMAGE
589 struct MANGOS_DLL_DECL SpellNotifierPlayer
591 std::list
<Unit
*> &i_data
;
593 const uint32
& i_index
;
595 Unit
* i_originalCaster
;
597 SpellNotifierPlayer(Spell
&spell
, std::list
<Unit
*> &data
, const uint32
&i
, float radius
)
598 : i_data(data
), i_spell(spell
), i_index(i
), i_radius(radius
)
600 i_originalCaster
= i_spell
.GetOriginalCaster();
603 void Visit(PlayerMapType
&m
)
605 if(!i_originalCaster
)
608 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
610 Player
* pPlayer
= itr
->getSource();
611 if( !pPlayer
->isAlive() || pPlayer
->isInFlight())
614 if( i_originalCaster
->IsFriendlyTo(pPlayer
) )
617 if( pPlayer
->GetDistance(i_spell
.m_targets
.m_destX
, i_spell
.m_targets
.m_destY
, i_spell
.m_targets
.m_destZ
) < i_radius
)
618 i_data
.push_back(pPlayer
);
621 template<class SKIP
> void Visit(GridRefManager
<SKIP
> &) {}
624 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
626 std::list
<Unit
*> *i_data
;
628 const uint32
& i_push_type
;
630 SpellTargets i_TargetType
;
631 Unit
* i_originalCaster
;
633 SpellNotifierCreatureAndPlayer(Spell
&spell
, std::list
<Unit
*> &data
, float radius
, const uint32
&type
,
634 SpellTargets TargetType
= SPELL_TARGETS_NOT_FRIENDLY
)
635 : i_data(&data
), i_spell(spell
), i_push_type(type
), i_radius(radius
), i_TargetType(TargetType
)
637 i_originalCaster
= spell
.GetOriginalCaster();
640 template<class T
> inline void Visit(GridRefManager
<T
> &m
)
644 if(!i_originalCaster
)
647 for(typename GridRefManager
<T
>::iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
)
649 if( !itr
->getSource()->isAlive() || (itr
->getSource()->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)itr
->getSource())->isInFlight()))
652 switch (i_TargetType
)
654 case SPELL_TARGETS_HOSTILE
:
655 if (!itr
->getSource()->isTargetableForAttack() || !i_originalCaster
->IsHostileTo( itr
->getSource() ))
658 case SPELL_TARGETS_NOT_FRIENDLY
:
659 if (!itr
->getSource()->isTargetableForAttack() || i_originalCaster
->IsFriendlyTo( itr
->getSource() ))
662 case SPELL_TARGETS_NOT_HOSTILE
:
663 if (!itr
->getSource()->isTargetableForAttack() || i_originalCaster
->IsHostileTo( itr
->getSource() ))
666 case SPELL_TARGETS_FRIENDLY
:
667 if (!itr
->getSource()->isTargetableForAttack() || !i_originalCaster
->IsFriendlyTo( itr
->getSource() ))
670 case SPELL_TARGETS_AOE_DAMAGE
:
672 if(itr
->getSource()->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)itr
->getSource())->isTotem())
674 if(!itr
->getSource()->isTargetableForAttack())
677 Unit
* check
= i_originalCaster
->GetCharmerOrOwnerOrSelf();
679 if( check
->GetTypeId()==TYPEID_PLAYER
)
681 if (check
->IsFriendlyTo( itr
->getSource() ))
686 if (!check
->IsHostileTo( itr
->getSource() ))
697 if(i_spell
.GetCaster()->isInFront((Unit
*)(itr
->getSource()), i_radius
, 2*M_PI
/3 ))
698 i_data
->push_back(itr
->getSource());
701 if(i_spell
.GetCaster()->isInBack((Unit
*)(itr
->getSource()), i_radius
, 2*M_PI
/3 ))
702 i_data
->push_back(itr
->getSource());
704 case PUSH_SELF_CENTER
:
705 if(i_spell
.GetCaster()->IsWithinDistInMap((Unit
*)(itr
->getSource()), i_radius
))
706 i_data
->push_back(itr
->getSource());
708 case PUSH_DEST_CENTER
:
709 if((itr
->getSource()->GetDistance(i_spell
.m_targets
.m_destX
, i_spell
.m_targets
.m_destY
, i_spell
.m_targets
.m_destZ
) < i_radius
))
710 i_data
->push_back(itr
->getSource());
712 case PUSH_TARGET_CENTER
:
713 if(i_spell
.m_targets
.getUnitTarget()->IsWithinDistInMap((Unit
*)(itr
->getSource()), i_radius
))
714 i_data
->push_back(itr
->getSource());
721 template<> inline void Visit(CorpseMapType
& ) {}
722 template<> inline void Visit(GameObjectMapType
& ) {}
723 template<> inline void Visit(DynamicObjectMapType
& ) {}
728 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType
& ) {}
729 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType
& ) {}
730 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType
& ) {}
734 typedef void(Spell::*pEffect
)(uint32 i
);
736 class SpellEvent
: public BasicEvent
739 SpellEvent(Spell
* spell
);
740 virtual ~SpellEvent();
742 virtual bool Execute(uint64 e_time
, uint32 p_time
);
743 virtual void Abort(uint64 e_time
);
744 virtual bool IsDeletable() const;