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

Revision 186, 25.7 kB (checked in by yumileroy, 17 years ago)

[svn] Remove isVisible function. Check stealth and invisible in canAttack();
Use new remove aura by interrupt flag function.

Original author: megamage
Date: 2008-11-07 09:36:46-06:00

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