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

Revision 110, 25.2 kB (checked in by yumileroy, 17 years ago)

[svn] Add SpellExtraInfoMap?. Currently support:
Limited-number-of-players spell; shared damage spell; target-in-line cone spell (e.g. dark glare).
Change angle of cone spells from 120 degree to 60 degree.

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