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