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

Revision 2, 26.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-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 EffectMomentMove(uint32 i);
255        void EffectTransmitted(uint32 i);
256        void EffectDisEnchant(uint32 i);
257        void EffectInebriate(uint32 i);
258        void EffectFeedPet(uint32 i);
259        void EffectDismissPet(uint32 i);
260        void EffectReputation(uint32 i);
261        void EffectSelfResurrect(uint32 i);
262        void EffectSkinning(uint32 i);
263        void EffectCharge(uint32 i);
264        void EffectProspecting(uint32 i);
265        void EffectSendTaxi(uint32 i);
266        void EffectSummonCritter(uint32 i);
267        void EffectKnockBack(uint32 i);
268        void EffectPlayerPull(uint32 i);
269        void EffectDispelMechanic(uint32 i);
270        void EffectSummonDeadPet(uint32 i);
271        void EffectDestroyAllTotems(uint32 i);
272        void EffectDurabilityDamage(uint32 i);
273        void EffectSkill(uint32 i);
274        void EffectTaunt(uint32 i);
275        void EffectDurabilityDamagePCT(uint32 i);
276        void EffectModifyThreatPercent(uint32 i);
277        void EffectResurrectNew(uint32 i);
278        void EffectAddExtraAttacks(uint32 i);
279        void EffectSpiritHeal(uint32 i);
280        void EffectSkinPlayerCorpse(uint32 i);
281        void EffectSummonDemon(uint32 i);
282        void EffectStealBeneficialBuff(uint32 i);
283        void EffectUnlearnSpecialization(uint32 i);
284        void EffectHealPct(uint32 i);
285        void EffectEnergisePct(uint32 i);
286        void EffectTriggerSpellWithValue(uint32 i);
287        void EffectTriggerRitualOfSummoning(uint32 i);
288        void EffectKillCredit(uint32 i);
289        void EffectQuestFail(uint32 i);
290
291        Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
292        ~Spell();
293
294        void prepare(SpellCastTargets * targets, Aura* triggeredByAura = NULL);
295        void cancel();
296        void update(uint32 difftime);
297        void cast(bool skipCheck = false);
298        void finish(bool ok = true);
299        void TakePower();
300        void TakeReagents();
301        void TakeCastItem();
302        void TriggerSpell();
303        uint8 CanCast(bool strict);
304        int16 PetCanCast(Unit* target);
305        bool CanAutoCast(Unit* target);
306
307        // handlers
308        void handle_immediate();
309        uint64 handle_delayed(uint64 t_offset);
310        // handler helpers
311        void _handle_immediate_phase();
312        void _handle_finish_phase();
313
314        uint8 CheckItems();
315        uint8 CheckRange(bool strict);
316        uint8 CheckPower();
317        uint8 CheckCasterAuras() const;
318
319        int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
320        int32 CalculatePowerCost();
321
322        bool HaveTargetsForEffect(uint8 effect) const;
323        void Delayed();
324        void DelayedChannel();
325        inline uint32 getState() const { return m_spellState; }
326        void setState(uint32 state) { m_spellState = state; }
327
328        void DoCreateItem(uint32 i, uint32 itemtype);
329
330        void WriteSpellGoTargets( WorldPacket * data );
331        void WriteAmmoToPacket( WorldPacket * data );
332        void FillTargetMap();
333
334        void SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap);
335
336        Unit* SelectMagnetTarget();
337        bool CheckTarget( Unit* target, uint32 eff, bool hitPhase );
338
339        void SendCastResult(uint8 result);
340        void SendSpellStart();
341        void SendSpellGo();
342        void SendSpellCooldown();
343        void SendLogExecute();
344        void SendInterrupted(uint8 result);
345        void SendChannelUpdate(uint32 time);
346        void SendChannelStart(uint32 duration);
347        void SendResurrectRequest(Player* target);
348        void SendPlaySpellVisual(uint32 SpellID);
349
350        void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
351        void HandleThreatSpells(uint32 spellId);
352        //void HandleAddAura(Unit* Target);
353
354        SpellEntry const* m_spellInfo;
355        int32 m_currentBasePoints[3];                       // cache SpellEntry::EffectBasePoints and use for set custom base points
356        Item* m_CastItem;
357        uint8 m_cast_count;
358        SpellCastTargets m_targets;
359
360        int32 GetCastTime() const { return m_casttime; }
361        bool IsAutoRepeat() const { return m_autoRepeat; }
362        void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
363        void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
364        bool IsNextMeleeSwingSpell() const
365        {
366            return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
367        }
368        bool IsRangedSpell() const
369        {
370            return  m_spellInfo->Attributes & SPELL_ATTR_RANGED;
371        }
372        bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
373        bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK);  }
374        bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
375
376        bool IsDeletable() const { return m_deletable; }
377        void SetDeletable(bool deletable) { m_deletable = deletable; }
378        uint64 GetDelayStart() const { return m_delayStart; }
379        void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
380        uint64 GetDelayMoment() const { return m_delayMoment; }
381
382        bool IsNeedSendToClient() const;
383
384        CurrentSpellTypes GetCurrentContainer();
385
386        Unit* GetCaster() const { return m_caster; }
387        Unit* GetOriginalCaster() const { return m_originalCaster; }
388        int32 GetPowerCost() const { return m_powerCost; }
389
390        void UpdatePointers();                              // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
391
392        bool IsAffectedBy(SpellEntry const *spellInfo, uint32 effectId);
393
394        bool CheckTargetCreatureType(Unit* target) const;
395
396        void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
397
398        void CleanupTargetList();
399    protected:
400
401        void SendLoot(uint64 guid, LootType loottype);
402
403        Unit* m_caster;
404
405        uint64 m_originalCasterGUID;                        // real source of cast (aura caster/etc), used for spell targets selection
406                                                            // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
407        Unit* m_originalCaster;                             // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
408
409        Spell** m_selfContainer;                            // pointer to our spell container (if applicable)
410        Spell** m_triggeringContainer;                      // pointer to container with spell that has triggered us
411
412        //Spell data
413        SpellSchoolMask m_spellSchoolMask;                  // Spell school (can be overwrite for some spells (wand shoot for example)
414        WeaponAttackType m_attackType;                      // For weapon based attack
415        int32 m_powerCost;                                  // Calculated spell cost     initialized only in Spell::prepare
416        int32 m_casttime;                                   // Calculated spell cast time initialized only in Spell::prepare
417        bool m_canReflect;                                  // can reflect this spell?
418        bool m_autoRepeat;
419
420        uint8 m_delayAtDamageCount;
421        int32 GetNextDelayAtDamageMsTime() { return m_delayAtDamageCount < 5 ? 1000 - (m_delayAtDamageCount++)* 200 : 200; }
422
423        // Delayed spells system
424        uint64 m_delayStart;                                // time of spell delay start, filled by event handler, zero = just started
425        uint64 m_delayMoment;                               // moment of next delay call, used internally
426        bool m_immediateHandled;                            // were immediate actions handled? (used by delayed spells only)
427
428        // These vars are used in both delayed spell system and modified immediate spell system
429        bool m_deletable;                                   // is the spell pending deletion or must be updated till permitted to delete?
430        bool m_needSpellLog;                                // need to send spell log?
431        uint8 m_applyMultiplierMask;                        // by effect: damage multiplier needed?
432        float m_damageMultipliers[3];                       // by effect: damage multiplier
433
434        // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
435        Unit* unitTarget;
436        Item* itemTarget;
437        GameObject* gameObjTarget;
438        int32 damage;
439
440        // this is set in Spell Hit, but used in Apply Aura handler
441        DiminishingLevels m_diminishLevel;
442        DiminishingGroup m_diminishGroup;
443
444        // -------------------------------------------
445        GameObject* focusObject;
446
447        //******************************************
448        // Spell trigger system
449        //******************************************
450        void doTriggers(SpellMissInfo missInfo, uint32 damage=0, SpellSchoolMask damageSchoolMask = SPELL_SCHOOL_MASK_NONE, uint32 block=0, uint32 absorb=0, bool crit=false);
451
452        //*****************************************
453        // Spell target subsystem
454        //*****************************************
455        // Targets store structures and data
456        uint32 m_countOfHit;
457        uint32 m_countOfMiss;
458        struct TargetInfo
459        {
460            uint64 targetGUID;
461            uint64 timeDelay;
462            SpellMissInfo missCondition:8;
463            SpellMissInfo reflectResult:8;
464            uint8  effectMask:8;
465            bool   processed:1;
466        };
467        std::list<TargetInfo> m_UniqueTargetInfo;
468        uint8 m_needAliveTargetMask;                        // Mask req. alive targets
469
470        struct GOTargetInfo
471        {
472            uint64 targetGUID;
473            uint64 timeDelay;
474            uint8  effectMask:8;
475            bool   processed:1;
476        };
477        std::list<GOTargetInfo> m_UniqueGOTargetInfo;
478
479        struct ItemTargetInfo
480        {
481            Item  *item;
482            uint8 effectMask;
483        };
484        std::list<ItemTargetInfo> m_UniqueItemInfo;
485
486        void AddUnitTarget(Unit* target, uint32 effIndex);
487        void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
488        void AddGOTarget(GameObject* target, uint32 effIndex);
489        void AddGOTarget(uint64 goGUID, uint32 effIndex);
490        void AddItemTarget(Item* target, uint32 effIndex);
491        void DoAllEffectOnTarget(TargetInfo *target);
492        void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
493        void DoAllEffectOnTarget(GOTargetInfo *target);
494        void DoAllEffectOnTarget(ItemTargetInfo *target);
495        bool IsAliveUnitPresentInTargetList();
496        // -------------------------------------------
497
498        //List For Triggered Spells
499        typedef std::list<SpellEntry const*> TriggerSpells;
500        TriggerSpells m_TriggerSpells;
501
502        uint32 m_spellState;
503        uint32 m_timer;
504
505        float m_castPositionX;
506        float m_castPositionY;
507        float m_castPositionZ;
508        float m_castOrientation;
509        bool m_IsTriggeredSpell;
510
511        // if need this can be replaced by Aura copy
512        // we can't store original aura link to prevent access to deleted auras
513        // and in same time need aura data and after aura deleting.
514        SpellEntry const* m_triggeredByAuraSpell;
515};
516
517enum ReplenishType
518{
519    REPLENISH_UNDEFINED = 0,
520    REPLENISH_HEALTH    = 20,
521    REPLENISH_MANA      = 21,
522    REPLENISH_RAGE      = 22
523};
524
525enum SpellTargets
526{
527    SPELL_TARGETS_HOSTILE,
528    SPELL_TARGETS_NOT_FRIENDLY,
529    SPELL_TARGETS_NOT_HOSTILE,
530    SPELL_TARGETS_FRIENDLY,
531    SPELL_TARGETS_AOE_DAMAGE
532};
533
534namespace MaNGOS
535{
536    struct MANGOS_DLL_DECL SpellNotifierPlayer
537    {
538        std::list<Unit*> &i_data;
539        Spell &i_spell;
540        const uint32& i_index;
541        float i_radius;
542        Unit* i_originalCaster;
543
544        SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
545            : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
546        {
547            i_originalCaster = i_spell.GetOriginalCaster();
548        }
549
550        void Visit(PlayerMapType &m)
551        {
552            if(!i_originalCaster)
553                return;
554
555            for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
556            {
557                Player * pPlayer = itr->getSource();
558                if( !pPlayer->isAlive() || pPlayer->isInFlight())
559                    continue;
560
561                if( i_originalCaster->IsFriendlyTo(pPlayer) )
562                    continue;
563
564                if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )
565                    i_data.push_back(pPlayer);
566            }
567        }
568        template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
569    };
570
571    struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
572    {
573        std::list<Unit*> *i_data;
574        Spell &i_spell;
575        const uint32& i_push_type;
576        float i_radius;
577        SpellTargets i_TargetType;
578        Unit* i_originalCaster;
579
580        SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, const uint32 &type,
581            SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
582            : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
583        {
584            i_originalCaster = spell.GetOriginalCaster();
585        }
586
587        template<class T> inline void Visit(GridRefManager<T>  &m)
588        {
589            assert(i_data);
590
591            if(!i_originalCaster)
592                return;
593
594            for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
595            {
596                if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight()))
597                    continue;
598
599                switch (i_TargetType)
600                {
601                    case SPELL_TARGETS_HOSTILE:
602                        if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() ))
603                            continue;
604                        break;
605                    case SPELL_TARGETS_NOT_FRIENDLY:
606                        if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() ))
607                            continue;
608                        break;
609                    case SPELL_TARGETS_NOT_HOSTILE:
610                        if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() ))
611                            continue;
612                        break;
613                    case SPELL_TARGETS_FRIENDLY:
614                        if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() ))
615                            continue;
616                        break;
617                    case SPELL_TARGETS_AOE_DAMAGE:
618                    {
619                        if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
620                            continue;
621                        if(!itr->getSource()->isTargetableForAttack())
622                            continue;
623
624                        Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
625
626                        if( check->GetTypeId()==TYPEID_PLAYER )
627                        {
628                            if (check->IsFriendlyTo( itr->getSource() ))
629                                continue;
630                        }
631                        else
632                        {
633                            if (!check->IsHostileTo( itr->getSource() ))
634                                continue;
635                        }
636                    }
637                    break;
638                    default: continue;
639                }
640
641                switch(i_push_type)
642                {
643                    case PUSH_IN_FRONT:
644                        if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
645                            i_data->push_back(itr->getSource());
646                        break;
647                    case PUSH_IN_BACK:
648                        if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
649                            i_data->push_back(itr->getSource());
650                        break;
651                    case PUSH_SELF_CENTER:
652                        if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
653                            i_data->push_back(itr->getSource());
654                        break;
655                    case PUSH_DEST_CENTER:
656                        if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ))
657                            i_data->push_back(itr->getSource());
658                        break;
659                    case PUSH_TARGET_CENTER:
660                        if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius))
661                            i_data->push_back(itr->getSource());
662                        break;
663                }
664            }
665        }
666
667        #ifdef WIN32
668        template<> inline void Visit(CorpseMapType & ) {}
669        template<> inline void Visit(GameObjectMapType & ) {}
670        template<> inline void Visit(DynamicObjectMapType & ) {}
671        #endif
672    };
673
674    #ifndef WIN32
675    template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
676    template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
677    template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
678    #endif
679}
680
681typedef void(Spell::*pEffect)(uint32 i);
682
683class SpellEvent : public BasicEvent
684{
685    public:
686        SpellEvent(Spell* spell);
687        virtual ~SpellEvent();
688
689        virtual bool Execute(uint64 e_time, uint32 p_time);
690        virtual void Abort(uint64 e_time);
691    protected:
692        Spell* m_Spell;
693};
694#endif
Note: See TracBrowser for help on using the browser.