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

Revision 44, 26.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

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