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

Revision 139, 25.4 kB (checked in by yumileroy, 17 years ago)

[svn] Spell target selection improvement. Remove most mangos hacks in spell target selection. (work almost done)
Merge mangos svn rev 6744.

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