[9323] Fixes in code work with original caster guid.
[getmangos.git] / src / game / Spell.h
blobc754d2a744021142af48d190cf1bb52a6e35e41e
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #ifndef __SPELL_H
20 #define __SPELL_H
22 #include "GridDefines.h"
23 #include "SharedDefines.h"
25 class WorldSession;
26 class Unit;
27 class DynamicObj;
28 class Player;
29 class GameObject;
30 class Group;
31 class Aura;
33 enum SpellCastTargetFlags
35 TARGET_FLAG_SELF = 0x00000000,
36 TARGET_FLAG_UNUSED1 = 0x00000001, // not used in any spells as of 3.0.3 (can be set dynamically)
37 TARGET_FLAG_UNIT = 0x00000002, // pguid
38 TARGET_FLAG_UNUSED2 = 0x00000004, // not used in any spells as of 3.0.3 (can be set dynamically)
39 TARGET_FLAG_UNUSED3 = 0x00000008, // not used in any spells as of 3.0.3 (can be set dynamically)
40 TARGET_FLAG_ITEM = 0x00000010, // pguid
41 TARGET_FLAG_SOURCE_LOCATION = 0x00000020, // 3 float
42 TARGET_FLAG_DEST_LOCATION = 0x00000040, // 3 float
43 TARGET_FLAG_OBJECT_UNK = 0x00000080, // used in 7 spells only
44 TARGET_FLAG_UNIT_UNK = 0x00000100, // looks like self target (480 spells)
45 TARGET_FLAG_PVP_CORPSE = 0x00000200, // pguid
46 TARGET_FLAG_UNIT_CORPSE = 0x00000400, // 10 spells (gathering professions)
47 TARGET_FLAG_OBJECT = 0x00000800, // pguid, 2 spells
48 TARGET_FLAG_TRADE_ITEM = 0x00001000, // pguid, 0 spells
49 TARGET_FLAG_STRING = 0x00002000, // string, 0 spells
50 TARGET_FLAG_UNK1 = 0x00004000, // 199 spells, opening object/lock
51 TARGET_FLAG_CORPSE = 0x00008000, // pguid, resurrection spells
52 TARGET_FLAG_UNK2 = 0x00010000, // pguid, not used in any spells as of 3.0.3 (can be set dynamically)
53 TARGET_FLAG_GLYPH = 0x00020000 // used in glyph spells
56 enum SpellCastFlags
58 CAST_FLAG_NONE = 0x00000000,
59 CAST_FLAG_UNKNOWN0 = 0x00000001, // may be pending spell cast
60 CAST_FLAG_UNKNOWN1 = 0x00000002,
61 CAST_FLAG_UNKNOWN11 = 0x00000004,
62 CAST_FLAG_UNKNOWN12 = 0x00000008,
63 CAST_FLAG_UNKNOWN2 = 0x00000010,
64 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
65 CAST_FLAG_UNKNOWN8 = 0x00000040,
66 CAST_FLAG_UNKNOWN9 = 0x00000080,
67 CAST_FLAG_UNKNOWN3 = 0x00000100,
68 CAST_FLAG_UNKNOWN13 = 0x00000200,
69 CAST_FLAG_UNKNOWN14 = 0x00000400,
70 CAST_FLAG_UNKNOWN6 = 0x00000800, // wotlk, trigger rune cooldown
71 CAST_FLAG_UNKNOWN15 = 0x00001000,
72 CAST_FLAG_UNKNOWN16 = 0x00002000,
73 CAST_FLAG_UNKNOWN17 = 0x00004000,
74 CAST_FLAG_UNKNOWN18 = 0x00008000,
75 CAST_FLAG_UNKNOWN19 = 0x00010000,
76 CAST_FLAG_UNKNOWN4 = 0x00020000, // wotlk
77 CAST_FLAG_UNKNOWN10 = 0x00040000,
78 CAST_FLAG_UNKNOWN5 = 0x00080000, // wotlk
79 CAST_FLAG_UNKNOWN20 = 0x00100000,
80 CAST_FLAG_UNKNOWN7 = 0x00200000, // wotlk, rune cooldown list
81 CAST_FLAG_UNKNOWN21 = 0x04000000
84 enum SpellNotifyPushType
86 PUSH_IN_FRONT,
87 PUSH_IN_FRONT_90,
88 PUSH_IN_FRONT_30,
89 PUSH_IN_FRONT_15,
90 PUSH_IN_BACK,
91 PUSH_SELF_CENTER,
92 PUSH_DEST_CENTER,
93 PUSH_TARGET_CENTER
96 bool IsQuestTameSpell(uint32 spellId);
98 namespace MaNGOS
100 struct SpellNotifierPlayer;
101 struct SpellNotifierCreatureAndPlayer;
104 class SpellCastTargets
106 public:
107 SpellCastTargets();
108 ~SpellCastTargets();
110 bool read ( WorldPacket * data, Unit *caster );
111 void write ( WorldPacket * data );
113 SpellCastTargets& operator=(const SpellCastTargets &target)
115 m_unitTarget = target.m_unitTarget;
116 m_itemTarget = target.m_itemTarget;
117 m_GOTarget = target.m_GOTarget;
119 m_unitTargetGUID = target.m_unitTargetGUID;
120 m_GOTargetGUID = target.m_GOTargetGUID;
121 m_CorpseTargetGUID = target.m_CorpseTargetGUID;
122 m_itemTargetGUID = target.m_itemTargetGUID;
124 m_itemTargetEntry = target.m_itemTargetEntry;
126 m_srcX = target.m_srcX;
127 m_srcY = target.m_srcY;
128 m_srcZ = target.m_srcZ;
130 m_destX = target.m_destX;
131 m_destY = target.m_destY;
132 m_destZ = target.m_destZ;
134 m_strTarget = target.m_strTarget;
136 m_targetMask = target.m_targetMask;
138 return *this;
141 uint64 getUnitTargetGUID() const { return m_unitTargetGUID; }
142 Unit *getUnitTarget() const { return m_unitTarget; }
143 void setUnitTarget(Unit *target);
144 void setDestination(float x, float y, float z);
145 void setSource(float x, float y, float z);
147 uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
148 GameObject *getGOTarget() const { return m_GOTarget; }
149 void setGOTarget(GameObject *target);
151 uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
152 void setCorpseTarget(Corpse* corpse);
153 uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
154 Item* getItemTarget() const { return m_itemTarget; }
155 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
156 void setItemTarget(Item* item);
157 void updateTradeSlotItem()
159 if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
161 m_itemTargetGUID = m_itemTarget->GetGUID();
162 m_itemTargetEntry = m_itemTarget->GetEntry();
166 bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
168 void Update(Unit* caster);
170 float m_srcX, m_srcY, m_srcZ;
171 float m_destX, m_destY, m_destZ;
172 std::string m_strTarget;
174 uint32 m_targetMask;
175 private:
176 // objects (can be used at spell creating and after Update at casting
177 Unit *m_unitTarget;
178 GameObject *m_GOTarget;
179 Item *m_itemTarget;
181 // object GUID/etc, can be used always
182 uint64 m_unitTargetGUID;
183 uint64 m_GOTargetGUID;
184 uint64 m_CorpseTargetGUID;
185 uint64 m_itemTargetGUID;
186 uint32 m_itemTargetEntry;
189 enum SpellState
191 SPELL_STATE_NULL = 0,
192 SPELL_STATE_PREPARING = 1,
193 SPELL_STATE_CASTING = 2,
194 SPELL_STATE_FINISHED = 3,
195 SPELL_STATE_IDLE = 4,
196 SPELL_STATE_DELAYED = 5
199 enum SpellTargets
201 SPELL_TARGETS_HOSTILE,
202 SPELL_TARGETS_NOT_FRIENDLY,
203 SPELL_TARGETS_NOT_HOSTILE,
204 SPELL_TARGETS_FRIENDLY,
205 SPELL_TARGETS_AOE_DAMAGE
208 #define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL (1*IN_MILISECONDS)
210 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
212 class Spell
214 friend struct MaNGOS::SpellNotifierPlayer;
215 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
216 friend void Unit::SetCurrentCastedSpell( Spell * pSpell );
217 public:
219 void EffectNULL(uint32 );
220 void EffectUnused(uint32 );
221 void EffectDistract(uint32 i);
222 void EffectPull(uint32 i);
223 void EffectSchoolDMG(uint32 i);
224 void EffectEnvironmentalDMG(uint32 i);
225 void EffectInstaKill(uint32 i);
226 void EffectDummy(uint32 i);
227 void EffectTeleportUnits(uint32 i);
228 void EffectApplyAura(uint32 i);
229 void EffectSendEvent(uint32 i);
230 void EffectPowerBurn(uint32 i);
231 void EffectPowerDrain(uint32 i);
232 void EffectHeal(uint32 i);
233 void EffectHealthLeech(uint32 i);
234 void EffectQuestComplete(uint32 i);
235 void EffectCreateItem(uint32 i);
236 void EffectCreateItem2(uint32 i);
237 void EffectCreateRandomItem(uint32 i);
238 void EffectPersistentAA(uint32 i);
239 void EffectEnergize(uint32 i);
240 void EffectOpenLock(uint32 i);
241 void EffectSummonChangeItem(uint32 i);
242 void EffectProficiency(uint32 i);
243 void EffectApplyAreaAura(uint32 i);
244 void EffectSummonType(uint32 i);
245 void EffectSummon(uint32 i);
246 void EffectLearnSpell(uint32 i);
247 void EffectDispel(uint32 i);
248 void EffectDualWield(uint32 i);
249 void EffectPickPocket(uint32 i);
250 void EffectAddFarsight(uint32 i);
251 void EffectSummonWild(uint32 i, uint32 forceFaction = 0);
252 void EffectSummonGuardian(uint32 i, uint32 forceFaction = 0);
253 void EffectHealMechanical(uint32 i);
254 void EffectJump(uint32 i);
255 void EffectTeleUnitsFaceCaster(uint32 i);
256 void EffectLearnSkill(uint32 i);
257 void EffectAddHonor(uint32 i);
258 void EffectTradeSkill(uint32 i);
259 void EffectEnchantItemPerm(uint32 i);
260 void EffectEnchantItemTmp(uint32 i);
261 void EffectTameCreature(uint32 i);
262 void EffectSummonPet(uint32 i);
263 void EffectLearnPetSpell(uint32 i);
264 void EffectWeaponDmg(uint32 i);
265 void EffectForceCast(uint32 i);
266 void EffectTriggerSpell(uint32 i);
267 void EffectTriggerMissileSpell(uint32 i);
268 void EffectThreat(uint32 i);
269 void EffectHealMaxHealth(uint32 i);
270 void EffectInterruptCast(uint32 i);
271 void EffectSummonObjectWild(uint32 i);
272 void EffectScriptEffect(uint32 i);
273 void EffectSanctuary(uint32 i);
274 void EffectAddComboPoints(uint32 i);
275 void EffectDuel(uint32 i);
276 void EffectStuck(uint32 i);
277 void EffectSummonPlayer(uint32 i);
278 void EffectActivateObject(uint32 i);
279 void EffectApplyGlyph(uint32 i);
280 void EffectSummonTotem(uint32 i, uint8 slot = 0);
281 void EffectEnchantHeldItem(uint32 i);
282 void EffectSummonObject(uint32 i);
283 void EffectResurrect(uint32 i);
284 void EffectParry(uint32 i);
285 void EffectBlock(uint32 i);
286 void EffectLeapForward(uint32 i);
287 void EffectLeapBack(uint32 i);
288 void EffectTransmitted(uint32 i);
289 void EffectDisEnchant(uint32 i);
290 void EffectInebriate(uint32 i);
291 void EffectFeedPet(uint32 i);
292 void EffectDismissPet(uint32 i);
293 void EffectReputation(uint32 i);
294 void EffectSelfResurrect(uint32 i);
295 void EffectSkinning(uint32 i);
296 void EffectCharge(uint32 i);
297 void EffectCharge2(uint32 i);
298 void EffectProspecting(uint32 i);
299 void EffectMilling(uint32 i);
300 void EffectRenamePet(uint32 i);
301 void EffectSendTaxi(uint32 i);
302 void EffectSummonCritter(uint32 i, uint32 forceFaction = 0);
303 void EffectKnockBack(uint32 i);
304 void EffectPlayerPull(uint32 i);
305 void EffectDispelMechanic(uint32 i);
306 void EffectSummonDeadPet(uint32 i);
307 void EffectSummonAllTotems(uint32 i);
308 void EffectDestroyAllTotems(uint32 i);
309 void EffectDurabilityDamage(uint32 i);
310 void EffectSkill(uint32 i);
311 void EffectTaunt(uint32 i);
312 void EffectDurabilityDamagePCT(uint32 i);
313 void EffectModifyThreatPercent(uint32 i);
314 void EffectResurrectNew(uint32 i);
315 void EffectAddExtraAttacks(uint32 i);
316 void EffectSpiritHeal(uint32 i);
317 void EffectSkinPlayerCorpse(uint32 i);
318 void EffectStealBeneficialBuff(uint32 i);
319 void EffectUnlearnSpecialization(uint32 i);
320 void EffectHealPct(uint32 i);
321 void EffectEnergisePct(uint32 i);
322 void EffectTriggerSpellWithValue(uint32 i);
323 void EffectTriggerRitualOfSummoning(uint32 i);
324 void EffectKillCreditPersonal(uint32 i);
325 void EffectKillCredit(uint32 i);
326 void EffectQuestFail(uint32 i);
327 void EffectActivateRune(uint32 i);
328 void EffectTitanGrip(uint32 i);
329 void EffectEnchantItemPrismatic(uint32 i);
330 void EffectPlayMusic(uint32 i);
332 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
333 ~Spell();
335 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
336 void cancel();
337 void update(uint32 difftime);
338 void cast(bool skipCheck = false);
339 void finish(bool ok = true);
340 void TakePower();
341 void TakeReagents();
342 void TakeCastItem();
344 SpellCastResult CheckCast(bool strict);
345 SpellCastResult CheckPetCast(Unit* target);
347 // handlers
348 void handle_immediate();
349 uint64 handle_delayed(uint64 t_offset);
350 // handler helpers
351 void _handle_immediate_phase();
352 void _handle_finish_phase();
354 SpellCastResult CheckItems();
355 SpellCastResult CheckRange(bool strict);
356 SpellCastResult CheckPower();
357 SpellCastResult CheckOrTakeRunePower(bool take);
358 SpellCastResult CheckCasterAuras() const;
360 int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
361 int32 CalculatePowerCost();
363 bool HaveTargetsForEffect(uint8 effect) const;
364 void Delayed();
365 void DelayedChannel();
366 uint32 getState() const { return m_spellState; }
367 void setState(uint32 state) { m_spellState = state; }
369 void DoCreateItem(uint32 i, uint32 itemtype);
370 void WriteSpellGoTargets( WorldPacket * data );
371 void WriteAmmoToPacket( WorldPacket * data );
373 typedef std::list<Unit*> UnitList;
374 void FillTargetMap();
375 void SetTargetMap(uint32 effIndex, uint32 targetMode, UnitList &targetUnitMap);
377 void FillAreaTargets(UnitList &targetUnitMap, float x, float y, float radius, SpellNotifyPushType pushType, SpellTargets spellTargets);
378 void FillRaidOrPartyTargets(UnitList &targetUnitMap, Unit* member, Unit* center, float radius, bool raid, bool withPets, bool withcaster);
379 void FillRaidOrPartyManaPriorityTargets(UnitList &targetUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster);
380 void FillRaidOrPartyHealthPriorityTargets(UnitList &targetUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster);
382 template<typename T> WorldObject* FindCorpseUsing();
384 bool CheckTarget( Unit* target, uint32 eff );
385 bool CanAutoCast(Unit* target);
387 static void MANGOS_DLL_SPEC SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 cast_count, SpellCastResult result);
388 void SendCastResult(SpellCastResult result);
389 void SendSpellStart();
390 void SendSpellGo();
391 void SendSpellCooldown();
392 void SendLogExecute();
393 void SendInterrupted(uint8 result);
394 void SendChannelUpdate(uint32 time);
395 void SendChannelStart(uint32 duration);
396 void SendResurrectRequest(Player* target);
397 void SendPlaySpellVisual(uint32 SpellID);
399 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier = 1.0);
400 void HandleThreatSpells(uint32 spellId);
401 //void HandleAddAura(Unit* Target);
403 SpellEntry const* m_spellInfo;
404 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
405 Item* m_CastItem;
406 uint8 m_cast_count;
407 uint32 m_glyphIndex;
408 SpellCastTargets m_targets;
410 int32 GetCastTime() const { return m_casttime; }
411 uint32 GetCastedTime() { return m_timer; }
412 bool IsAutoRepeat() const { return m_autoRepeat; }
413 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
414 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
415 bool IsNextMeleeSwingSpell() const
417 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
419 bool IsRangedSpell() const
421 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
423 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
424 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
425 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
427 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
428 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
429 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
430 uint64 GetDelayStart() const { return m_delayStart; }
431 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
432 uint64 GetDelayMoment() const { return m_delayMoment; }
434 bool IsNeedSendToClient() const; // use for hide spell cast for client in case when cast not have client side affect (animation or log entries)
435 bool IsTriggeredSpellWithRedundentData() const; // use for ignore some spell data for triggered spells like cast time, some triggered spells have redundent copy data from main spell for client use purpose
437 CurrentSpellTypes GetCurrentContainer();
439 // caster types:
440 // formal spell caster, in game source of spell affects cast
441 Unit* GetCaster() const { return m_caster; }
442 // real source of cast affects, explcit caster, or DoT/HoT applier, or GO owner, etc. Can be NULL
443 Unit* GetAffectiveCaster() const { return m_originalCasterGUID ? m_originalCaster : m_caster; }
444 // m_originalCasterGUID can store GO guid, and in this case this is visual caster
445 WorldObject* GetCastingObject() const;
447 int32 GetPowerCost() const { return m_powerCost; }
449 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
451 bool IsAffectedByAura(Aura *aura) const;
453 bool CheckTargetCreatureType(Unit* target) const;
455 void AddTriggeredSpell(SpellEntry const* spellInfo) { m_TriggerSpells.push_back(spellInfo); }
456 void AddPrecastSpell(SpellEntry const* spellInfo) { m_preCastSpells.push_back(spellInfo); }
457 void AddTriggeredSpell(uint32 spellId);
458 void AddPrecastSpell(uint32 spellId);
459 void CastPreCastSpells(Unit* target);
460 void CastTriggerSpells();
462 void CleanupTargetList();
463 protected:
465 void SendLoot(uint64 guid, LootType loottype);
466 bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data
467 void UpdateOriginalCasterPointer();
469 Unit* m_caster;
471 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
472 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
473 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
475 Spell** m_selfContainer; // pointer to our spell container (if applicable)
476 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
478 //Spell data
479 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
480 WeaponAttackType m_attackType; // For weapon based attack
481 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
482 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
483 bool m_canReflect; // can reflect this spell?
484 bool m_autoRepeat;
485 uint8 m_runesState;
487 uint8 m_delayAtDamageCount;
488 bool isDelayableNoMore()
490 if(m_delayAtDamageCount >= 2)
491 return true;
493 m_delayAtDamageCount++;
494 return false;
497 // Delayed spells system
498 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
499 uint64 m_delayMoment; // moment of next delay call, used internally
500 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
502 // These vars are used in both delayed spell system and modified immediate spell system
503 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
504 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
505 bool m_needSpellLog; // need to send spell log?
506 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
507 float m_damageMultipliers[3]; // by effect: damage multiplier
509 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
510 Unit* unitTarget;
511 Item* itemTarget;
512 GameObject* gameObjTarget;
513 int32 damage;
515 // this is set in Spell Hit, but used in Apply Aura handler
516 DiminishingLevels m_diminishLevel;
517 DiminishingGroup m_diminishGroup;
519 // -------------------------------------------
520 GameObject* focusObject;
522 // Damage and healing in effects need just calculate
523 int32 m_damage; // Damge in effects count here
524 int32 m_healing; // Healing in effects count here
525 int32 m_healthLeech; // Health leech in effects for all targets count here
527 //******************************************
528 // Spell trigger system
529 //******************************************
530 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
531 uint32 m_procAttacker; // Attacker trigger flags
532 uint32 m_procVictim; // Victim trigger flags
533 void prepareDataForTriggerSystem();
535 //*****************************************
536 // Spell target subsystem
537 //*****************************************
538 // Targets store structures and data
539 struct TargetInfo
541 uint64 targetGUID;
542 uint64 timeDelay;
543 SpellMissInfo missCondition:8;
544 SpellMissInfo reflectResult:8;
545 uint8 effectMask:8;
546 bool processed:1;
548 std::list<TargetInfo> m_UniqueTargetInfo;
549 uint8 m_needAliveTargetMask; // Mask req. alive targets
551 struct GOTargetInfo
553 uint64 targetGUID;
554 uint64 timeDelay;
555 uint8 effectMask:8;
556 bool processed:1;
558 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
560 struct ItemTargetInfo
562 Item *item;
563 uint8 effectMask;
565 std::list<ItemTargetInfo> m_UniqueItemInfo;
567 void AddUnitTarget(Unit* target, uint32 effIndex);
568 void AddUnitTarget(uint64 unitGUID, uint32 effIndex);
569 void AddGOTarget(GameObject* target, uint32 effIndex);
570 void AddGOTarget(uint64 goGUID, uint32 effIndex);
571 void AddItemTarget(Item* target, uint32 effIndex);
572 void DoAllEffectOnTarget(TargetInfo *target);
573 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
574 void DoAllEffectOnTarget(GOTargetInfo *target);
575 void DoAllEffectOnTarget(ItemTargetInfo *target);
576 bool IsAliveUnitPresentInTargetList();
577 SpellCastResult CanOpenLock(uint32 effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
578 // -------------------------------------------
580 //List For Triggered Spells
581 typedef std::list<SpellEntry const*> SpellInfoList;
582 SpellInfoList m_TriggerSpells; // casted by caster to same targets settings in m_targets at success finish of current spell
583 SpellInfoList m_preCastSpells; // casted by caster to each target at spell hit before spell effects apply
585 uint32 m_spellState;
586 uint32 m_timer;
588 float m_castPositionX;
589 float m_castPositionY;
590 float m_castPositionZ;
591 float m_castOrientation;
592 bool m_IsTriggeredSpell;
594 // if need this can be replaced by Aura copy
595 // we can't store original aura link to prevent access to deleted auras
596 // and in same time need aura data and after aura deleting.
597 SpellEntry const* m_triggeredByAuraSpell;
600 enum ReplenishType
602 REPLENISH_UNDEFINED = 0,
603 REPLENISH_HEALTH = 20,
604 REPLENISH_MANA = 21,
605 REPLENISH_RAGE = 22
608 namespace MaNGOS
610 struct MANGOS_DLL_DECL SpellNotifierPlayer
612 std::list<Unit*> &i_data;
613 Spell &i_spell;
614 const uint32& i_index;
615 float i_radius;
616 Unit* i_originalCaster;
618 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
619 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
621 i_originalCaster = i_spell.GetAffectiveCaster();
624 void Visit(PlayerMapType &m)
626 if(!i_originalCaster)
627 return;
629 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
631 Player * pPlayer = itr->getSource();
632 if( !pPlayer->isAlive() || pPlayer->isInFlight())
633 continue;
635 if( i_originalCaster->IsFriendlyTo(pPlayer) )
636 continue;
638 if( pPlayer->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius))
639 i_data.push_back(pPlayer);
642 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
645 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
647 std::list<Unit*> *i_data;
648 Spell &i_spell;
649 SpellNotifyPushType i_push_type;
650 float i_radius;
651 SpellTargets i_TargetType;
652 Unit* i_originalCaster;
654 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, SpellNotifyPushType type,
655 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
656 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
658 i_originalCaster = spell.GetAffectiveCaster();
661 template<class T> inline void Visit(GridRefManager<T> &m)
663 assert(i_data);
665 if(!i_originalCaster)
666 return;
668 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
670 // there are still more spells which can be casted on dead, but
671 // they are no AOE and don't have such a nice SPELL_ATTR flag
672 if ( !itr->getSource()->isTargetableForAttack(i_spell.m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_CAST_ON_DEAD)
673 // mostly phase check
674 || !itr->getSource()->IsInMap(i_originalCaster))
675 continue;
677 switch (i_TargetType)
679 case SPELL_TARGETS_HOSTILE:
680 if (!i_originalCaster->IsHostileTo( itr->getSource() ))
681 continue;
682 break;
683 case SPELL_TARGETS_NOT_FRIENDLY:
684 if (i_originalCaster->IsFriendlyTo( itr->getSource() ))
685 continue;
686 break;
687 case SPELL_TARGETS_NOT_HOSTILE:
688 if (i_originalCaster->IsHostileTo( itr->getSource() ))
689 continue;
690 break;
691 case SPELL_TARGETS_FRIENDLY:
692 if (!i_originalCaster->IsFriendlyTo( itr->getSource() ))
693 continue;
694 break;
695 case SPELL_TARGETS_AOE_DAMAGE:
697 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
698 continue;
700 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
702 if( check->GetTypeId()==TYPEID_PLAYER )
704 if (check->IsFriendlyTo( itr->getSource() ))
705 continue;
707 else
709 if (!check->IsHostileTo( itr->getSource() ))
710 continue;
713 break;
714 default: continue;
717 // we don't need to check InMap here, it's already done some lines above
718 switch(i_push_type)
720 case PUSH_IN_FRONT:
721 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
722 i_data->push_back(itr->getSource());
723 break;
724 case PUSH_IN_FRONT_90:
725 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, M_PI/2 ))
726 i_data->push_back(itr->getSource());
727 break;
728 case PUSH_IN_FRONT_30:
729 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, M_PI/6 ))
730 i_data->push_back(itr->getSource());
731 break;
732 case PUSH_IN_FRONT_15:
733 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, M_PI/12 ))
734 i_data->push_back(itr->getSource());
735 break;
736 case PUSH_IN_BACK:
737 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 ))
738 i_data->push_back(itr->getSource());
739 break;
740 case PUSH_SELF_CENTER:
741 if(i_spell.GetCaster()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
742 i_data->push_back(itr->getSource());
743 break;
744 case PUSH_DEST_CENTER:
745 if(itr->getSource()->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius))
746 i_data->push_back(itr->getSource());
747 break;
748 case PUSH_TARGET_CENTER:
749 if(i_spell.m_targets.getUnitTarget()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
750 i_data->push_back(itr->getSource());
751 break;
756 #ifdef WIN32
757 template<> inline void Visit(CorpseMapType & ) {}
758 template<> inline void Visit(GameObjectMapType & ) {}
759 template<> inline void Visit(DynamicObjectMapType & ) {}
760 #endif
763 #ifndef WIN32
764 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
765 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
766 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
767 #endif
770 typedef void(Spell::*pEffect)(uint32 i);
772 class SpellEvent : public BasicEvent
774 public:
775 SpellEvent(Spell* spell);
776 virtual ~SpellEvent();
778 virtual bool Execute(uint64 e_time, uint32 p_time);
779 virtual void Abort(uint64 e_time);
780 virtual bool IsDeletable() const;
781 protected:
782 Spell* m_Spell;
784 #endif