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

Revision 6, 27.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Added ACE for Linux and Windows (Thanks Derex for Linux part and partial Windows part)
* Updated to 6721 and 676
* Fixed TrinityScript? logo
* Version updated to 0.2.6721.676

Original author: Neo2003
Date: 2008-10-04 06:17:19-05:00

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