root/trunk/src/game/Spell.h @ 37

Revision 37, 26.6 kB (checked in by yumileroy, 17 years ago)

[svn] * svn:eol-style native set on all files that need it

Original author: Neo2003
Date: 2008-10-11 14:16:25-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef __SPELL_H
20#define __SPELL_H
21
22#include "GridDefines.h"
23
24class WorldSession;
25class Unit;
26class DynamicObj;
27class Player;
28class GameObject;
29class Group;
30class Aura;
31
32enum SpellCastTargetFlags
33{
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*/
46
47    TARGET_FLAG_SELF            = 0x00000000,
48    TARGET_FLAG_UNIT            = 0x00000002,               // pguid
49    TARGET_FLAG_ITEM            = 0x00000010,               // pguid
50    TARGET_FLAG_SOURCE_LOCATION = 0x00000020,               // 3 float
51    TARGET_FLAG_DEST_LOCATION   = 0x00000040,               // 3 float
52    TARGET_FLAG_OBJECT_UNK      = 0x00000080,               // ?
53    TARGET_FLAG_PVP_CORPSE      = 0x00000200,               // pguid
54    TARGET_FLAG_OBJECT          = 0x00000800,               // pguid
55    TARGET_FLAG_TRADE_ITEM      = 0x00001000,               // pguid
56    TARGET_FLAG_STRING          = 0x00002000,               // string
57    TARGET_FLAG_UNK1            = 0x00004000,               // ?
58    TARGET_FLAG_CORPSE          = 0x00008000,               // pguid
59    TARGET_FLAG_UNK2            = 0x00010000                // pguid
60};
61
62enum SpellCastFlags
63{
64    CAST_FLAG_UNKNOWN1           = 0x00000002,
65    CAST_FLAG_UNKNOWN2           = 0x00000010,
66    CAST_FLAG_AMMO               = 0x00000020,
67    CAST_FLAG_UNKNOWN3           = 0x00000100
68};
69
70enum SpellNotifyPushType
71{
72    PUSH_IN_FRONT,
73    PUSH_IN_BACK,
74    PUSH_SELF_CENTER,
75    PUSH_DEST_CENTER,
76    PUSH_TARGET_CENTER
77};
78
79bool IsQuestTameSpell(uint32 spellId);
80
81namespace MaNGOS
82{
83    struct SpellNotifierPlayer;
84    struct SpellNotifierCreatureAndPlayer;
85}
86
87class SpellCastTargets
88{
89    public:
90        SpellCastTargets();
91        ~SpellCastTargets();
92
93        bool read ( WorldPacket * data, Unit *caster );
94        void write ( WorldPacket * data );
95
96        SpellCastTargets& operator=(const SpellCastTargets &target)
97        {
98            m_unitTarget = target.m_unitTarget;
99            m_itemTarget = target.m_itemTarget;
100            m_GOTarget   = target.m_GOTarget;
101
102            m_unitTargetGUID   = target.m_unitTargetGUID;
103            m_GOTargetGUID     = target.m_GOTargetGUID;
104            m_CorpseTargetGUID = target.m_CorpseTargetGUID;
105            m_itemTargetGUID   = target.m_itemTargetGUID;
106
107            m_itemTargetEntry  = target.m_itemTargetEntry;
108
109            m_srcX = target.m_srcX;
110            m_srcY = target.m_srcY;
111            m_srcZ = target.m_srcZ;
112
113            m_destX = target.m_destX;
114            m_destY = target.m_destY;
115            m_destZ = target.m_destZ;
116
117            m_strTarget = target.m_strTarget;
118
119            m_targetMask = target.m_targetMask;
120
121            return *this;
122        }
123
124        uint64 getUnitTargetGUID() const { return m_unitTargetGUID; }
125        Unit *getUnitTarget() const { return m_unitTarget; }
126        void setUnitTarget(Unit *target);
127        void setDestination(float x, float y, float z);
128
129        uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
130        GameObject *getGOTarget() const { return m_GOTarget; }
131        void setGOTarget(GameObject *target);
132
133        uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
134        void setCorpseTarget(Corpse* corpse);
135        uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
136        Item* getItemTarget() const { return m_itemTarget; }
137        uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
138        void setItemTarget(Item* item);
139        void updateTradeSlotItem()
140        {
141            if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
142            {
143                m_itemTargetGUID = m_itemTarget->GetGUID();
144                m_itemTargetEntry = m_itemTarget->GetEntry();
145            }
146        }
147
148        bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
149
150        void Update(Unit* caster);
151
152        float m_srcX, m_srcY, m_srcZ;
153        float m_destX, m_destY, m_destZ;
154        std::string m_strTarget;
155
156        uint32 m_targetMask;
157    private:
158        // objects (can be used at spell creating and after Update at casting
159        Unit *m_unitTarget;
160        GameObject *m_GOTarget;
161        Item *m_itemTarget;
162
163        // object GUID/etc, can be used always
164        uint64 m_unitTargetGUID;
165        uint64 m_GOTargetGUID;
166        uint64 m_CorpseTargetGUID;
167        uint64 m_itemTargetGUID;
168        uint32 m_itemTargetEntry;
169};
170
171enum SpellState
172{
173    SPELL_STATE_NULL      = 0,
174    SPELL_STATE_PREPARING = 1,
175    SPELL_STATE_CASTING   = 2,
176    SPELL_STATE_FINISHED  = 3,
177    SPELL_STATE_IDLE      = 4,
178    SPELL_STATE_DELAYED   = 5
179};
180
181#define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL 1000
182
183typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
184
185class Spell
186{
187    friend struct MaNGOS::SpellNotifierPlayer;
188    friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
189    public:
190
191        void EffectNULL(uint32 );
192        void EffectUnused(uint32 );
193        void EffectDistract(uint32 i);
194        void EffectPull(uint32 i);
195        void EffectSchoolDMG(uint32 i);
196        void EffectEnvirinmentalDMG(uint32 i);
197        void EffectInstaKill(uint32 i);
198        void EffectDummy(uint32 i);
199        void EffectTeleportUnits(uint32 i);
200        void EffectApplyAura(uint32 i);
201        void EffectSendEvent(uint32 i);
202        void EffectPowerBurn(uint32 i);
203        void EffectPowerDrain(uint32 i);
204        void EffectHeal(uint32 i);
205        void EffectHealthLeech(uint32 i);
206        void EffectQuestComplete(uint32 i);
207        void EffectCreateItem(uint32 i);
208        void EffectPersistentAA(uint32 i);
209        void EffectEnergize(uint32 i);
210        void EffectOpenLock(uint32 i);
211        void EffectSummonChangeItem(uint32 i);
212        void EffectOpenSecretSafe(uint32 i);
213        void EffectProficiency(uint32 i);
214        void EffectApplyAreaAura(uint32 i);
215        void EffectSummonType(uint32 i);
216        void EffectSummon(uint32 i);
217        void EffectLearnSpell(uint32 i);
218        void EffectDispel(uint32 i);
219        void EffectDualWield(uint32 i);
220        void EffectPickPocket(uint32 i);
221        void EffectAddFarsight(uint32 i);
222        void EffectSummonWild(uint32 i);
223        void EffectSummonGuardian(uint32 i);
224        void EffectHealMechanical(uint32 i);
225        void EffectTeleUnitsFaceCaster(uint32 i);
226        void EffectLearnSkill(uint32 i);
227        void EffectAddHonor(uint32 i);
228        void EffectTradeSkill(uint32 i);
229        void EffectEnchantItemPerm(uint32 i);
230        void EffectEnchantItemTmp(uint32 i);
231        void EffectTameCreature(uint32 i);
232        void EffectSummonPet(uint32 i);
233        void EffectLearnPetSpell(uint32 i);
234        void EffectWeaponDmg(uint32 i);
235        void EffectForceCast(uint32 i);
236        void EffectTriggerSpell(uint32 i);
237        void EffectTriggerMissileSpell(uint32 i);
238        void EffectThreat(uint32 i);
239        void EffectHealMaxHealth(uint32 i);
240        void EffectInterruptCast(uint32 i);
241        void EffectSummonObjectWild(uint32 i);
242        void EffectScriptEffect(uint32 i);
243        void EffectSanctuary(uint32 i);
244        void EffectAddComboPoints(uint32 i);
245        void EffectDuel(uint32 i);
246        void EffectStuck(uint32 i);
247        void EffectSummonPlayer(uint32 i);
248        void EffectActivateObject(uint32 i);
249        void EffectSummonTotem(uint32 i);
250        void EffectEnchantHeldItem(uint32 i);
251        void EffectSummonObject(uint32 i);
252        void EffectResurrect(uint32 i);
253        void EffectParry(uint32 i);
254        void EffectBlock(uint32 i);
255        void EffectMomentMove(uint32 i);
256        void EffectTransmitted(uint32 i);
257        void EffectDisEnchant(uint32 i);
258        void EffectInebriate(uint32 i);
259        void EffectFeedPet(uint32 i);
260        void EffectDismissPet(uint32 i);
261        void EffectReputation(uint32 i);
262        void EffectSelfResurrect(uint32 i);
263        void EffectSkinning(uint32 i);
264        void EffectCharge(uint32 i);
265        void EffectProspecting(uint32 i);
266        void EffectSendTaxi(uint32 i);
267        void EffectSummonCritter(uint32 i);
268        void EffectKnockBack(uint32 i);
269        void EffectPlayerPull(uint32 i);
270        void EffectDispelMechanic(uint32 i);
271        void EffectSummonDeadPet(uint32 i);
272        void EffectDestroyAllTotems(uint32 i);
273        void EffectDurabilityDamage(uint32 i);
274        void EffectSkill(uint32 i);
275        void EffectTaunt(uint32 i);
276        void EffectDurabilityDamagePCT(uint32 i);
277        void EffectModifyThreatPercent(uint32 i);
278        void EffectResurrectNew(uint32 i);
279        void EffectAddExtraAttacks(uint32 i);
280        void EffectSpiritHeal(uint32 i);
281        void EffectSkinPlayerCorpse(uint32 i);
282        void EffectSummonDemon(uint32 i);
283        void EffectStealBeneficialBuff(uint32 i);
284        void EffectUnlearnSpecialization(uint32 i);
285        void EffectHealPct(uint32 i);
286        void EffectEnergisePct(uint32 i);
287        void EffectTriggerSpellWithValue(uint32 i);
288        void EffectTriggerRitualOfSummoning(uint32 i);
289        void EffectKillCredit(uint32 i);
290        void EffectQuestFail(uint32 i);
291
292        Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
293        ~Spell();
294
295        void prepare(SpellCastTargets * targets, Aura* triggeredByAura = NULL);
296        void cancel();
297        void update(uint32 difftime);
298        void cast(bool skipCheck = false);
299        void finish(bool ok = true);
300        void TakePower();
301        void TakeReagents();
302        void TakeCastItem();
303        void TriggerSpell();
304        uint8 CanCast(bool strict);
305        int16 PetCanCast(Unit* target);
306        bool CanAutoCast(Unit* target);
307
308        // handlers
309        void handle_immediate();
310        uint64 handle_delayed(uint64 t_offset);
311        // handler helpers
312        void _handle_immediate_phase();
313        void _handle_finish_phase();
314
315        uint8 CheckItems();
316        uint8 CheckRange(bool strict);
317        uint8 CheckPower();
318        uint8 CheckCasterAuras() const;
319
320        int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
321        int32 CalculatePowerCost();
322
323        bool HaveTargetsForEffect(uint8 effect) const;
324        void Delayed();
325        void DelayedChannel();
326        inline uint32 getState() const { return m_spellState; }
327        void setState(uint32 state) { m_spellState = state; }
328
329        void DoCreateItem(uint32 i, uint32 itemtype);
330
331        void WriteSpellGoTargets( WorldPacket * data );
332        void WriteAmmoToPacket( WorldPacket * data );
333        void FillTargetMap();
334
335        void SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap);
336
337        Unit* SelectMagnetTarget();
338        std::pair <bool,Unit *> m_magnetPair;
339        bool CheckTarget( Unit* target, uint32 eff, bool hitPhase );
340
341        void SendCastResult(uint8 result);
342        void SendSpellStart();
343        void SendSpellGo();
344        void SendSpellCooldown();
345        void SendLogExecute();
346        void SendInterrupted(uint8 result);
347        void SendChannelUpdate(uint32 time);
348        void SendChannelStart(uint32 duration);
349        void SendResurrectRequest(Player* target);
350        void SendPlaySpellVisual(uint32 SpellID);
351
352        void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
353        void HandleThreatSpells(uint32 spellId);
354        //void HandleAddAura(Unit* Target);
355
356        SpellEntry const* m_spellInfo;
357        int32 m_currentBasePoints[3];                       // cache SpellEntry::EffectBasePoints and use for set custom base points
358        Item* m_CastItem;
359        uint8 m_cast_count;
360        SpellCastTargets m_targets;
361
362        int32 GetCastTime() const { return m_casttime; }
363        bool IsAutoRepeat() const { return m_autoRepeat; }
364        void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
365        void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
366        bool IsNextMeleeSwingSpell() const
367        {
368            return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
369        }
370        bool IsRangedSpell() const
371        {
372            return  m_spellInfo->Attributes & SPELL_ATTR_RANGED;
373        }
374        bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
375        bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK);  }
376        bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
377
378        bool IsDeletable() const { return m_deletable; }
379        void SetDeletable(bool deletable) { m_deletable = deletable; }
380        uint64 GetDelayStart() const { return m_delayStart; }
381        void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
382        uint64 GetDelayMoment() const { return m_delayMoment; }
383
384        bool IsNeedSendToClient() const;
385
386        CurrentSpellTypes GetCurrentContainer();
387
388        Unit* GetCaster() const { return m_caster; }
389        Unit* GetOriginalCaster() const { return m_originalCaster; }
390        int32 GetPowerCost() const { return m_powerCost; }
391
392        void UpdatePointers();                              // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
393
394        bool IsAffectedBy(SpellEntry const *spellInfo, uint32 effectId);
395
396        bool CheckTargetCreatureType(Unit* target) const;
397
398        void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
399
400        void CleanupTargetList();
401    protected:
402
403        void SendLoot(uint64 guid, LootType loottype);
404
405        Unit* m_caster;
406
407        uint64 m_originalCasterGUID;                        // real source of cast (aura caster/etc), used for spell targets selection
408                                                            // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
409        Unit* m_originalCaster;                             // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
410
411        Spell** m_selfContainer;                            // pointer to our spell container (if applicable)
412        Spell** m_triggeringContainer;                      // pointer to container with spell that has triggered us
413
414        //Spell data
415        SpellSchoolMask m_spellSchoolMask;                  // Spell school (can be overwrite for some spells (wand shoot for example)
416        WeaponAttackType m_attackType;                      // For weapon based attack
417        int32 m_powerCost;                                  // Calculated spell cost     initialized only in Spell::prepare
418        int32 m_casttime;                                   // Calculated spell cast time initialized only in Spell::prepare
419        bool m_canReflect;                                  // can reflect this spell?
420        bool m_autoRepeat;
421
422        uint8 m_delayAtDamageCount;
423        int32 GetNextDelayAtDamageMsTime() { return m_delayAtDamageCount < 5 ? 1000 - (m_delayAtDamageCount++)* 200 : 200; }
424
425        // Delayed spells system
426        uint64 m_delayStart;                                // time of spell delay start, filled by event handler, zero = just started
427        uint64 m_delayMoment;                               // moment of next delay call, used internally
428        bool m_immediateHandled;                            // were immediate actions handled? (used by delayed spells only)
429
430        // These vars are used in both delayed spell system and modified immediate spell system
431        bool m_deletable;                                   // is the spell pending deletion or must be updated till permitted to delete?
432        bool m_needSpellLog;                                // need to send spell log?
433        uint8 m_applyMultiplierMask;                        // by effect: damage multiplier needed?
434        float m_damageMultipliers[3];                       // by effect: damage multiplier
435
436        // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
437        Unit* unitTarget;
438        Item* itemTarget;
439        GameObject* gameObjTarget;
440        int32 damage;
441
442        // this is set in Spell Hit, but used in Apply Aura handler
443        DiminishingLevels m_diminishLevel;
444        DiminishingGroup m_diminishGroup;
445
446        // -------------------------------------------
447        GameObject* focusObject;
448
449        //******************************************
450        // Spell trigger system
451        //******************************************
452        void doTriggers(SpellMissInfo missInfo, uint32 damage=0, SpellSchoolMask damageSchoolMask = SPELL_SCHOOL_MASK_NONE, uint32 block=0, uint32 absorb=0, bool crit=false);
453
454        //*****************************************
455        // Spell target subsystem
456        //*****************************************
457        // Targets store structures and data
458        uint32 m_countOfHit;
459        uint32 m_countOfMiss;
460        struct TargetInfo
461        {
462            uint64 targetGUID;
463            uint64 timeDelay;
464            SpellMissInfo missCondition:8;
465            SpellMissInfo reflectResult:8;
466            uint8  effectMask:8;
467            bool   processed:1;
468        };
469        std::list<TargetInfo> m_UniqueTargetInfo;
470        uint8 m_needAliveTargetMask;                        // Mask req. alive targets
471
472        struct GOTargetInfo
473        {
474            uint64 targetGUID;
475            uint64 timeDelay;
476            uint8  effectMask:8;
477            bool   processed:1;
478        };
479        std::list<GOTargetInfo> m_UniqueGOTargetInfo;
480
481        struct ItemTargetInfo
482        {
483            Item  *item;
484            uint8 effectMask;
485        };
486        std::list<ItemTargetInfo> m_UniqueItemInfo;
487
488        void AddUnitTarget(Unit* target, uint32 effIndex);
489        void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
490        void AddGOTarget(GameObject* target, uint32 effIndex);
491        void AddGOTarget(uint64 goGUID, uint32 effIndex);
492        void AddItemTarget(Item* target, uint32 effIndex);
493        void DoAllEffectOnTarget(TargetInfo *target);
494        void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
495        void DoAllEffectOnTarget(GOTargetInfo *target);
496        void DoAllEffectOnTarget(ItemTargetInfo *target);
497        bool IsAliveUnitPresentInTargetList();
498        // -------------------------------------------
499
500        //List For Triggered Spells
501        typedef std::list<SpellEntry const*> TriggerSpells;
502        TriggerSpells m_TriggerSpells;
503
504        uint32 m_spellState;
505        uint32 m_timer;
506
507        float m_castPositionX;
508        float m_castPositionY;
509        float m_castPositionZ;
510        float m_castOrientation;
511        bool m_IsTriggeredSpell;
512
513        // if need this can be replaced by Aura copy
514        // we can't store original aura link to prevent access to deleted auras
515        // and in same time need aura data and after aura deleting.
516        SpellEntry const* m_triggeredByAuraSpell;
517};
518
519enum ReplenishType
520{
521    REPLENISH_UNDEFINED = 0,
522    REPLENISH_HEALTH    = 20,
523    REPLENISH_MANA      = 21,
524    REPLENISH_RAGE      = 22
525};
526
527enum SpellTargets
528{
529    SPELL_TARGETS_HOSTILE,
530    SPELL_TARGETS_NOT_FRIENDLY,
531    SPELL_TARGETS_NOT_HOSTILE,
532    SPELL_TARGETS_FRIENDLY,
533    SPELL_TARGETS_AOE_DAMAGE
534};
535
536namespace MaNGOS
537{
538    struct MANGOS_DLL_DECL SpellNotifierPlayer
539    {
540        std::list<Unit*> &i_data;
541        Spell &i_spell;
542        const uint32& i_index;
543        float i_radius;
544        Unit* i_originalCaster;
545
546        SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
547            : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
548        {
549            i_originalCaster = i_spell.GetOriginalCaster();
550        }
551
552        void Visit(PlayerMapType &m)
553        {
554            if(!i_originalCaster)
555                return;
556
557            for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
558            {
559                Player * pPlayer = itr->getSource();
560                if( !pPlayer->isAlive() || pPlayer->isInFlight())
561                    continue;
562
563                if( i_originalCaster->IsFriendlyTo(pPlayer) )
564                    continue;
565
566                if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
567                    i_data.push_back(pPlayer);
568            }
569        }
570        template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
571    };
572
573    struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
574    {
575        std::list<Unit*> *i_data;
576        Spell &i_spell;
577        const uint32& i_push_type;
578        float i_radius;
579        SpellTargets i_TargetType;
580        Unit* i_originalCaster;
581
582        SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, const uint32 &type,
583            SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
584            : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
585        {
586            i_originalCaster = spell.GetOriginalCaster();
587        }
588
589        template<class T> inline void Visit(GridRefManager<T>  &m)
590        {
591            assert(i_data);
592
593            if(!i_originalCaster)
594                return;
595
596            for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
597            {
598                if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
599                    continue;
600
601                switch (i_TargetType)
602                {
603                    case SPELL_TARGETS_HOSTILE:
604                        if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
605                            continue;
606                        break;
607                    case SPELL_TARGETS_NOT_FRIENDLY:
608                        if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
609                            continue;
610                        break;
611                    case SPELL_TARGETS_NOT_HOSTILE:
612                        if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
613                            continue;
614                        break;
615                    case SPELL_TARGETS_FRIENDLY:
616                        if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
617                            continue;
618                        break;
619                    case SPELL_TARGETS_AOE_DAMAGE:
620                    {
621                        if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
622                            continue;
623                        if(!itr->getSource()->isTargetableForAttack())
624                            continue;
625
626                        Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
627
628                        if( check->GetTypeId()==TYPEID_PLAYER )
629                        {
630                            if (check->IsFriendlyTo( itr->getSource() ))
631                                continue;
632                        }
633                        else
634                        {
635                            if (!check->IsHostileTo( itr->getSource() ))
636                                continue;
637                        }
638                    }
639                    break;
640                    default: continue;
641                }
642
643                switch(i_push_type)
644                {
645                    case PUSH_IN_FRONT:
646                        if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
647                            i_data->push_back(itr->getSource());
648                        break;
649                    case PUSH_IN_BACK:
650                        if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
651                            i_data->push_back(itr->getSource());
652                        break;
653                    case PUSH_SELF_CENTER:
654                        if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
655                            i_data->push_back(itr->getSource());
656                        break;
657                    case PUSH_DEST_CENTER:
658                        if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
659                            i_data->push_back(itr->getSource());
660                        break;
661                    case PUSH_TARGET_CENTER:
662                        if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
663                            i_data->push_back(itr->getSource());
664                        break;
665                }
666            }
667        }
668
669        #ifdef WIN32
670        template<> inline void Visit(CorpseMapType & ) {}
671        template<> inline void Visit(GameObjectMapType & ) {}
672        template<> inline void Visit(DynamicObjectMapType & ) {}
673        #endif
674    };
675
676    #ifndef WIN32
677    template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
678    template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
679    template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
680    #endif
681}
682
683typedef void(Spell::*pEffect)(uint32 i);
684
685class SpellEvent : public BasicEvent
686{
687    public:
688        SpellEvent(Spell* spell);
689        virtual ~SpellEvent();
690
691        virtual bool Execute(uint64 e_time, uint32 p_time);
692        virtual void Abort(uint64 e_time);
693    protected:
694        Spell* m_Spell;
695};
696#endif
Note: See TracBrowser for help on using the browser.