Updated Copyright year to 2013
[getmangos.git] / src / game / Spell.h
blob1e84038e914fbf6526e5e2b79dc24c02fc8085c8
1 /*
2 * Copyright (C) 2005-2013 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 "Common.h"
23 #include "GridDefines.h"
24 #include "SharedDefines.h"
25 #include "DBCEnums.h"
26 #include "ObjectGuid.h"
27 #include "LootMgr.h"
28 #include "Unit.h"
29 #include "Player.h"
31 class WorldSession;
32 class WorldPacket;
33 class DynamicObj;
34 class Item;
35 class GameObject;
36 class Group;
37 class Aura;
39 enum SpellCastFlags
41 CAST_FLAG_NONE = 0x00000000,
42 CAST_FLAG_HIDDEN_COMBATLOG = 0x00000001, // hide in combat log?
43 CAST_FLAG_UNKNOWN2 = 0x00000002,
44 CAST_FLAG_UNKNOWN3 = 0x00000004,
45 CAST_FLAG_UNKNOWN4 = 0x00000008,
46 CAST_FLAG_UNKNOWN5 = 0x00000010,
47 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
48 CAST_FLAG_UNKNOWN7 = 0x00000040, // !0x41 mask used to call CGTradeSkillInfo::DoRecast
49 CAST_FLAG_UNKNOWN8 = 0x00000080,
50 CAST_FLAG_UNKNOWN9 = 0x00000100,
51 CAST_FLAG_UNKNOWN10 = 0x00000200,
52 CAST_FLAG_UNKNOWN11 = 0x00000400,
53 CAST_FLAG_PREDICTED_POWER = 0x00000800, // wotlk, trigger rune cooldown
54 CAST_FLAG_UNKNOWN13 = 0x00001000,
55 CAST_FLAG_UNKNOWN14 = 0x00002000,
56 CAST_FLAG_UNKNOWN15 = 0x00004000,
57 CAST_FLAG_UNKNOWN16 = 0x00008000,
58 CAST_FLAG_UNKNOWN17 = 0x00010000,
59 CAST_FLAG_ADJUST_MISSILE = 0x00020000, // wotlk
60 CAST_FLAG_UNKNOWN19 = 0x00040000, // spell cooldown related (may be category cooldown)
61 CAST_FLAG_VISUAL_CHAIN = 0x00080000, // wotlk
62 CAST_FLAG_UNKNOWN21 = 0x00100000,
63 CAST_FLAG_PREDICTED_RUNES = 0x00200000, // wotlk, rune cooldown list
64 CAST_FLAG_IMMUNITY = 0x04000000, // spell cast school imminity info
65 CAST_FLAG_UNKNOWN24 = 0x08000000,
66 CAST_FLAG_UNKNOWN25 = 0x10000000,
67 CAST_FLAG_UNKNOWN26 = 0x20000000,
68 CAST_FLAG_HEAL_PREDICTION = 0x40000000, // heal prediction
69 CAST_FLAG_UNKNOWN28 = 0x80000000,
72 enum SpellFlags
74 SPELL_FLAG_NORMAL = 0x00,
75 SPELL_FLAG_REFLECTED = 0x01, // reflected spell
76 SPELL_FLAG_REDIRECTED = 0x02 // redirected spell
79 enum SpellNotifyPushType
81 PUSH_IN_FRONT,
82 PUSH_IN_FRONT_90,
83 PUSH_IN_FRONT_30,
84 PUSH_IN_FRONT_15,
85 PUSH_IN_BACK,
86 PUSH_SELF_CENTER,
87 PUSH_DEST_CENTER,
88 PUSH_TARGET_CENTER
91 bool IsQuestTameSpell(uint32 spellId);
93 namespace MaNGOS
95 struct SpellNotifierPlayer;
96 struct SpellNotifierCreatureAndPlayer;
99 class SpellCastTargets;
101 struct SpellCastTargetsReader
103 explicit SpellCastTargetsReader(SpellCastTargets& _targets, Unit* _caster) : targets(_targets), caster(_caster) {}
105 SpellCastTargets& targets;
106 Unit* caster;
109 class SpellCastTargets
111 public:
112 SpellCastTargets();
113 ~SpellCastTargets();
115 void read(ByteBuffer& data, Unit* caster);
116 void write(ByteBuffer& data) const;
118 SpellCastTargetsReader ReadForCaster(Unit* caster) { return SpellCastTargetsReader(*this, caster); }
119 void ReadAdditionalData(WorldPacket& data, uint8& cast_flags);
121 SpellCastTargets& operator=(const SpellCastTargets& target)
123 m_unitTarget = target.m_unitTarget;
124 m_itemTarget = target.m_itemTarget;
125 m_GOTarget = target.m_GOTarget;
127 m_unitTargetGUID = target.m_unitTargetGUID;
128 m_GOTargetGUID = target.m_GOTargetGUID;
129 m_CorpseTargetGUID = target.m_CorpseTargetGUID;
130 m_itemTargetGUID = target.m_itemTargetGUID;
131 m_srcTransportGUID = target.m_srcTransportGUID;
132 m_destTransportGUID = target.m_destTransportGUID;
134 m_itemTargetEntry = target.m_itemTargetEntry;
136 m_srcX = target.m_srcX;
137 m_srcY = target.m_srcY;
138 m_srcZ = target.m_srcZ;
140 m_destX = target.m_destX;
141 m_destY = target.m_destY;
142 m_destZ = target.m_destZ;
144 m_strTarget = target.m_strTarget;
146 m_targetMask = target.m_targetMask;
148 m_elevation = target.m_elevation;
149 m_speed = target.m_speed;
151 return *this;
154 void setUnitTarget(Unit* target);
155 ObjectGuid getUnitTargetGuid() const { return m_unitTargetGUID; }
156 Unit* getUnitTarget() const { return m_unitTarget; }
158 void setDestination(float x, float y, float z);
159 void setSource(float x, float y, float z);
160 void getDestination(float& x, float& y, float& z) const { x = m_destX; y = m_destY; z = m_destZ; }
161 void getSource(float& x, float& y, float& z) const { x = m_srcX; y = m_srcY, z = m_srcZ; }
163 void setGOTarget(GameObject* target);
164 ObjectGuid getGOTargetGuid() const { return m_GOTargetGUID; }
165 GameObject* getGOTarget() const { return m_GOTarget; }
167 void setCorpseTarget(Corpse* corpse);
168 ObjectGuid getCorpseTargetGuid() const { return m_CorpseTargetGUID; }
170 void setItemTarget(Item* item);
171 ObjectGuid getItemTargetGuid() const { return m_itemTargetGUID; }
172 Item* getItemTarget() const { return m_itemTarget; }
173 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
175 void setTradeItemTarget(Player* caster);
177 void updateTradeSlotItem()
179 if (m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
181 m_itemTargetGUID = m_itemTarget->GetObjectGuid();
182 m_itemTargetEntry = m_itemTarget->GetEntry();
186 bool IsEmpty() const { return !m_GOTargetGUID && !m_unitTargetGUID && !m_itemTarget && !m_CorpseTargetGUID; }
188 void Update(Unit* caster);
190 float m_srcX, m_srcY, m_srcZ;
191 float m_destX, m_destY, m_destZ;
192 std::string m_strTarget;
194 float GetElevation() const { return m_elevation; }
195 float GetSpeed() const { return m_speed; }
197 uint32 m_targetMask;
199 private:
200 // objects (can be used at spell creating and after Update at casting
201 Unit* m_unitTarget;
202 GameObject* m_GOTarget;
203 Item* m_itemTarget;
205 // object GUID/etc, can be used always
206 ObjectGuid m_unitTargetGUID;
207 ObjectGuid m_GOTargetGUID;
208 ObjectGuid m_CorpseTargetGUID;
209 ObjectGuid m_itemTargetGUID;
210 ObjectGuid m_srcTransportGUID;
211 ObjectGuid m_destTransportGUID;
212 uint32 m_itemTargetEntry;
214 float m_elevation;
215 float m_speed;
218 inline ByteBuffer& operator<< (ByteBuffer& buf, SpellCastTargets const& targets)
220 targets.write(buf);
221 return buf;
224 inline ByteBuffer& operator>> (ByteBuffer& buf, SpellCastTargetsReader const& targets)
226 targets.targets.read(buf, targets.caster);
227 return buf;
230 enum SpellState
232 SPELL_STATE_PREPARING = 0, // cast time delay period, non channeled spell
233 SPELL_STATE_CASTING = 1, // channeled time period spell casting state
234 SPELL_STATE_FINISHED = 2, // cast finished to success or fail
235 SPELL_STATE_DELAYED = 3 // spell casted but need time to hit target(s)
238 enum SpellTargets
240 SPELL_TARGETS_HOSTILE,
241 SPELL_TARGETS_NOT_FRIENDLY,
242 SPELL_TARGETS_NOT_HOSTILE,
243 SPELL_TARGETS_FRIENDLY,
244 SPELL_TARGETS_AOE_DAMAGE,
245 SPELL_TARGETS_ALL
248 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
250 class Spell
252 friend struct MaNGOS::SpellNotifierPlayer;
253 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
254 friend void Unit::SetCurrentCastedSpell(Spell* pSpell);
256 public:
257 void EffectEmpty(SpellEffectEntry const* effect);
258 void EffectNULL(SpellEffectEntry const* effect);
259 void EffectUnused(SpellEffectEntry const* effect);
260 void EffectDistract(SpellEffectEntry const* effect);
261 void EffectPull(SpellEffectEntry const* effect);
262 void EffectSchoolDMG(SpellEffectEntry const* effect);
263 void EffectEnvironmentalDMG(SpellEffectEntry const* effect);
264 void EffectInstaKill(SpellEffectEntry const* effect);
265 void EffectDummy(SpellEffectEntry const* effect);
266 void EffectTeleportUnits(SpellEffectEntry const* effect);
267 void EffectApplyAura(SpellEffectEntry const* effect);
268 void EffectSendEvent(SpellEffectEntry const* effect);
269 void EffectPowerBurn(SpellEffectEntry const* effect);
270 void EffectPowerDrain(SpellEffectEntry const* effect);
271 void EffectHeal(SpellEffectEntry const* effect);
272 void EffectBind(SpellEffectEntry const* effect);
273 void EffectHealthLeech(SpellEffectEntry const* effect);
274 void EffectQuestComplete(SpellEffectEntry const* effect);
275 void EffectCreateItem(SpellEffectEntry const* effect);
276 void EffectCreateItem2(SpellEffectEntry const* effect);
277 void EffectCreateRandomItem(SpellEffectEntry const* effect);
278 void EffectPersistentAA(SpellEffectEntry const* effect);
279 void EffectEnergize(SpellEffectEntry const* effect);
280 void EffectOpenLock(SpellEffectEntry const* effect);
281 void EffectSummonChangeItem(SpellEffectEntry const* effect);
282 void EffectProficiency(SpellEffectEntry const* effect);
283 void EffectApplyAreaAura(SpellEffectEntry const* effect);
284 void EffectSummonType(SpellEffectEntry const* effect);
285 void EffectLearnSpell(SpellEffectEntry const* effect);
286 void EffectDispel(SpellEffectEntry const* effect);
287 void EffectDualWield(SpellEffectEntry const* effect);
288 void EffectPickPocket(SpellEffectEntry const* effect);
289 void EffectAddFarsight(SpellEffectEntry const* effect);
290 void EffectHealMechanical(SpellEffectEntry const* effect);
291 void EffectJump(SpellEffectEntry const* effect);
292 void EffectTeleUnitsFaceCaster(SpellEffectEntry const* effect);
293 void EffectLearnSkill(SpellEffectEntry const* effect);
294 void EffectAddHonor(SpellEffectEntry const* effect);
295 void EffectTradeSkill(SpellEffectEntry const* effect);
296 void EffectEnchantItemPerm(SpellEffectEntry const* effect);
297 void EffectEnchantItemTmp(SpellEffectEntry const* effect);
298 void EffectTameCreature(SpellEffectEntry const* effect);
299 void EffectSummonPet(SpellEffectEntry const* effect);
300 void EffectLearnPetSpell(SpellEffectEntry const* effect);
301 void EffectWeaponDmg(SpellEffectEntry const* effect);
302 void EffectClearQuest(SpellEffectEntry const* effect);
303 void EffectForceCast(SpellEffectEntry const* effect);
304 void EffectTriggerSpell(SpellEffectEntry const* effect);
305 void EffectTriggerMissileSpell(SpellEffectEntry const* effect);
306 void EffectThreat(SpellEffectEntry const* effect);
307 void EffectRestoreItemCharges(SpellEffectEntry const* effect);
308 void EffectHealMaxHealth(SpellEffectEntry const* effect);
309 void EffectInterruptCast(SpellEffectEntry const* effect);
310 void EffectSummonObjectWild(SpellEffectEntry const* effect);
311 void EffectScriptEffect(SpellEffectEntry const* effect);
312 void EffectSanctuary(SpellEffectEntry const* effect);
313 void EffectAddComboPoints(SpellEffectEntry const* effect);
314 void EffectDuel(SpellEffectEntry const* effect);
315 void EffectStuck(SpellEffectEntry const* effect);
316 void EffectSummonPlayer(SpellEffectEntry const* effect);
317 void EffectActivateObject(SpellEffectEntry const* effect);
318 void EffectApplyGlyph(SpellEffectEntry const* effect);
319 void EffectEnchantHeldItem(SpellEffectEntry const* effect);
320 void EffectSummonObject(SpellEffectEntry const* effect);
321 void EffectResurrect(SpellEffectEntry const* effect);
322 void EffectParry(SpellEffectEntry const* effect);
323 void EffectBlock(SpellEffectEntry const* effect);
324 void EffectLeapForward(SpellEffectEntry const* effect);
325 void EffectLeapBack(SpellEffectEntry const* effect);
326 void EffectTransmitted(SpellEffectEntry const* effect);
327 void EffectDisEnchant(SpellEffectEntry const* effect);
328 void EffectInebriate(SpellEffectEntry const* effect);
329 void EffectFeedPet(SpellEffectEntry const* effect);
330 void EffectDismissPet(SpellEffectEntry const* effect);
331 void EffectReputation(SpellEffectEntry const* effect);
332 void EffectSelfResurrect(SpellEffectEntry const* effect);
333 void EffectSkinning(SpellEffectEntry const* effect);
334 void EffectCharge(SpellEffectEntry const* effect);
335 void EffectCharge2(SpellEffectEntry const* effect);
336 void EffectProspecting(SpellEffectEntry const* effect);
337 void EffectRedirectThreat(SpellEffectEntry const* effect);
338 void EffectMilling(SpellEffectEntry const* effect);
339 void EffectRenamePet(SpellEffectEntry const* effect);
340 void EffectSendTaxi(SpellEffectEntry const* effect);
341 void EffectKnockBack(SpellEffectEntry const* effect);
342 void EffectPlayerPull(SpellEffectEntry const* effect);
343 void EffectDispelMechanic(SpellEffectEntry const* effect);
344 void EffectSummonDeadPet(SpellEffectEntry const* effect);
345 void EffectSummonAllTotems(SpellEffectEntry const* effect);
346 void EffectBreakPlayerTargeting (SpellEffectEntry const* effect);
347 void EffectDestroyAllTotems(SpellEffectEntry const* effect);
348 void EffectDurabilityDamage(SpellEffectEntry const* effect);
349 void EffectSkill(SpellEffectEntry const* effect);
350 void EffectTaunt(SpellEffectEntry const* effect);
351 void EffectDurabilityDamagePCT(SpellEffectEntry const* effect);
352 void EffectModifyThreatPercent(SpellEffectEntry const* effect);
353 void EffectResurrectNew(SpellEffectEntry const* effect);
354 void EffectAddExtraAttacks(SpellEffectEntry const* effect);
355 void EffectSpiritHeal(SpellEffectEntry const* effect);
356 void EffectSkinPlayerCorpse(SpellEffectEntry const* effect);
357 void EffectStealBeneficialBuff(SpellEffectEntry const* effect);
358 void EffectUnlearnSpecialization(SpellEffectEntry const* effect);
359 void EffectHealPct(SpellEffectEntry const* effect);
360 void EffectEnergisePct(SpellEffectEntry const* effect);
361 void EffectTriggerSpellWithValue(SpellEffectEntry const* effect);
362 void EffectTriggerRitualOfSummoning(SpellEffectEntry const* effect);
363 void EffectKillCreditPersonal(SpellEffectEntry const* effect);
364 void EffectKillCreditGroup(SpellEffectEntry const* effect);
365 void EffectQuestFail(SpellEffectEntry const* effect);
366 void EffectQuestOffer(SpellEffectEntry const* effect);
367 void EffectActivateRune(SpellEffectEntry const* effect);
368 void EffectTeachTaxiNode(SpellEffectEntry const* effect);
369 void EffectTitanGrip(SpellEffectEntry const* effect);
370 void EffectEnchantItemPrismatic(SpellEffectEntry const* effect);
371 void EffectPlaySound(SpellEffectEntry const* effect);
372 void EffectPlayMusic(SpellEffectEntry const* effect);
373 void EffectSpecCount(SpellEffectEntry const* effect);
374 void EffectActivateSpec(SpellEffectEntry const* effect);
375 void EffectCancelAura(SpellEffectEntry const* effect);
376 void EffectKnockBackFromPosition(SpellEffectEntry const* effect);
378 Spell(Unit* caster, SpellEntry const* info, bool triggered, ObjectGuid originalCasterGUID = ObjectGuid(), SpellEntry const* triggeredBy = NULL);
379 ~Spell();
381 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
383 void cancel();
385 void update(uint32 difftime);
386 void cast(bool skipCheck = false);
387 void finish(bool ok = true);
388 void TakePower();
389 void TakeReagents();
390 void TakeCastItem();
392 SpellCastResult CheckCast(bool strict);
393 SpellCastResult CheckPetCast(Unit* target);
395 // handlers
396 void handle_immediate();
397 uint64 handle_delayed(uint64 t_offset);
398 // handler helpers
399 void _handle_immediate_phase();
400 void _handle_finish_phase();
402 SpellCastResult CheckItems();
403 SpellCastResult CheckRange(bool strict);
404 SpellCastResult CheckPower();
405 SpellCastResult CheckOrTakeRunePower(bool take);
406 SpellCastResult CheckCasterAuras() const;
408 int32 CalculateDamage(SpellEffectIndex i, Unit* target) { return m_caster->CalculateSpellDamage(target, m_spellInfo, i, &m_currentBasePoints[i]); }
409 static uint32 CalculatePowerCost(SpellEntry const* spellInfo, Unit* caster, Spell const* spell = NULL, Item* castItem = NULL);
411 bool HaveTargetsForEffect(SpellEffectIndex effect) const;
412 void Delayed();
413 void DelayedChannel();
414 uint32 getState() const { return m_spellState; }
415 void setState(uint32 state) { m_spellState = state; }
417 void DoCreateItem(SpellEffectEntry const* effect, uint32 itemtype);
419 void WriteSpellGoTargets(WorldPacket* data);
420 void WriteAmmoToPacket(WorldPacket* data);
422 typedef std::list<Unit*> UnitList;
423 void FillTargetMap();
424 void SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& targetUnitMap);
426 void FillAreaTargets(UnitList& targetUnitMap, float radius, SpellNotifyPushType pushType, SpellTargets spellTargets, WorldObject* originalCaster = NULL);
427 void FillRaidOrPartyTargets(UnitList& targetUnitMap, Unit* member, Unit* center, float radius, bool raid, bool withPets, bool withcaster);
428 void FillRaidOrPartyManaPriorityTargets(UnitList& targetUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster);
429 void FillRaidOrPartyHealthPriorityTargets(UnitList& targetUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster);
431 // Returns a target that was filled by SPELL_SCRIPT_TARGET (or selected victim) Can return NULL
432 Unit* GetPrefilledUnitTargetOrUnitTarget(SpellEffectIndex effIndex) const;
434 template<typename T> WorldObject* FindCorpseUsing();
436 bool CheckTarget(Unit* target, SpellEffectIndex eff);
437 bool CanAutoCast(Unit* target);
439 static void MANGOS_DLL_SPEC SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 cast_count, SpellCastResult result);
440 void SendCastResult(SpellCastResult result);
441 void SendSpellStart();
442 void SendSpellGo();
443 void SendSpellCooldown();
444 void SendLogExecute();
445 void SendInterrupted(uint8 result);
446 void SendChannelUpdate(uint32 time);
447 void SendChannelStart(uint32 duration);
448 void SendResurrectRequest(Player* target);
449 void SendPlaySpellVisual(uint32 SpellID);
451 void HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOTarget, SpellEffectIndex i, float DamageMultiplier = 1.0);
452 void HandleThreatSpells();
453 // void HandleAddAura(Unit* Target);
455 SpellEntry const* m_spellInfo;
456 SpellEntry const* m_triggeredBySpellInfo;
457 SpellInterruptsEntry const* m_spellInterrupts;
458 int32 m_currentBasePoints[MAX_EFFECT_INDEX]; // cache SpellEntry::CalculateSimpleValue and use for set custom base points
459 Item* m_CastItem;
460 uint8 m_cast_count;
461 uint32 m_glyphIndex;
462 SpellCastTargets m_targets;
464 int32 GetCastTime() const { return m_casttime; }
465 uint32 GetCastedTime() { return m_timer; }
466 bool IsAutoRepeat() const { return m_autoRepeat; }
467 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
468 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
469 bool IsNextMeleeSwingSpell() const
471 return m_spellInfo->HasAttribute(SPELL_ATTR_ON_NEXT_SWING_1) || m_spellInfo->HasAttribute(SPELL_ATTR_ON_NEXT_SWING_2);
473 bool IsRangedSpell() const
475 return m_spellInfo->HasAttribute(SPELL_ATTR_RANGED);
477 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
478 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && m_spellInterrupts && (m_spellInterrupts->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
479 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && m_spellInterrupts && (m_spellInterrupts->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
481 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
482 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
483 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
484 uint64 GetDelayStart() const { return m_delayStart; }
485 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
486 uint64 GetDelayMoment() const { return m_delayMoment; }
488 bool IsNeedSendToClient() const; // use for hide spell cast for client in case when cast not have client side affect (animation or log entries)
489 bool IsTriggeredSpellWithRedundentData() const; // use for ignore some spell data for triggered spells like cast time, some triggered spells have redundant copy data from main spell for client use purpose
491 CurrentSpellTypes GetCurrentContainer();
493 // caster types:
494 // formal spell caster, in game source of spell affects cast
495 Unit* GetCaster() const { return m_caster; }
496 // real source of cast affects, explicit caster, or DoT/HoT applier, or GO owner, or wild GO itself. Can be NULL
497 WorldObject* GetAffectiveCasterObject() const;
498 // limited version returning NULL in cases wild gameobject caster object, need for Aura (auras currently not support non-Unit caster)
499 Unit* GetAffectiveCaster() const { return m_originalCasterGUID ? m_originalCaster : m_caster; }
500 // m_originalCasterGUID can store GO guid, and in this case this is visual caster
501 WorldObject* GetCastingObject() const;
503 uint32 GetPowerCost() const { return m_powerCost; }
505 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
507 bool CheckTargetCreatureType(Unit* target) const;
509 void AddTriggeredSpell(SpellEntry const* spellInfo) { m_TriggerSpells.push_back(spellInfo); }
510 void AddPrecastSpell(SpellEntry const* spellInfo) { m_preCastSpells.push_back(spellInfo); }
511 void AddTriggeredSpell(uint32 spellId);
512 void AddPrecastSpell(uint32 spellId);
513 void CastPreCastSpells(Unit* target);
514 void CastTriggerSpells();
516 void CleanupTargetList();
517 void ClearCastItem();
519 static void SelectMountByAreaAndSkill(Unit* target, SpellEntry const* parentSpell, uint32 spellId75, uint32 spellId150, uint32 spellId225, uint32 spellId300, uint32 spellIdSpecial);
521 protected:
522 bool HasGlobalCooldown();
523 void TriggerGlobalCooldown();
524 void CancelGlobalCooldown();
526 void SendLoot(ObjectGuid guid, LootType loottype, LockType lockType);
527 bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data
528 void UpdateOriginalCasterPointer();
530 Unit* m_caster;
532 ObjectGuid m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
533 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
534 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
536 Spell** m_selfContainer; // pointer to our spell container (if applicable)
538 // Spell data
539 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
540 WeaponAttackType m_attackType; // For weapon based attack
541 uint32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
542 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
543 int32 m_duration;
544 bool m_canReflect; // can reflect this spell?
545 uint8 m_spellFlags; // for spells whose target was changed in cast i.e. due to reflect
546 bool m_autoRepeat;
547 uint8 m_runesState;
549 uint8 m_delayAtDamageCount;
550 bool isDelayableNoMore()
552 if (m_delayAtDamageCount >= 2)
553 return true;
555 ++m_delayAtDamageCount;
556 return false;
559 // Delayed spells system
560 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
561 uint64 m_delayMoment; // moment of next delay call, used internally
562 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
564 // These vars are used in both delayed spell system and modified immediate spell system
565 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
566 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
567 bool m_needSpellLog; // need to send spell log?
568 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
569 float m_damageMultipliers[3]; // by effect: damage multiplier
571 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
572 Unit* unitTarget;
573 Item* itemTarget;
574 GameObject* gameObjTarget;
575 SpellAuraHolder* m_spellAuraHolder; // spell aura holder for current target, created only if spell has aura applying effect
576 int32 damage;
578 // this is set in Spell Hit, but used in Apply Aura handler
579 DiminishingLevels m_diminishLevel;
580 DiminishingGroup m_diminishGroup;
582 // -------------------------------------------
583 GameObject* focusObject;
585 // Damage and healing in effects need just calculate
586 int32 m_damage; // Damage in effects count here
587 int32 m_healing; // Healing in effects count here
588 int32 m_healthLeech; // Health leech in effects for all targets count here
590 //******************************************
591 // Spell trigger system
592 //******************************************
593 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
594 uint8 m_negativeEffectMask; // Use for avoid sent negative spell procs for additional positive effects only targets
595 uint32 m_procAttacker; // Attacker trigger flags
596 uint32 m_procVictim; // Victim trigger flags
597 void prepareDataForTriggerSystem();
599 //*****************************************
600 // Spell target subsystem
601 //*****************************************
602 // Targets store structures and data
603 struct TargetInfo
605 ObjectGuid targetGUID;
606 uint64 timeDelay;
607 uint32 HitInfo;
608 uint32 damage;
609 SpellMissInfo missCondition: 8;
610 SpellMissInfo reflectResult: 8;
611 uint8 effectMask: 8;
612 bool processed: 1;
614 uint8 m_needAliveTargetMask; // Mask req. alive targets
616 struct GOTargetInfo
618 ObjectGuid targetGUID;
619 uint64 timeDelay;
620 uint8 effectMask: 8;
621 bool processed: 1;
624 struct ItemTargetInfo
626 Item* item;
627 uint8 effectMask;
630 typedef std::list<TargetInfo> TargetList;
631 typedef std::list<GOTargetInfo> GOTargetList;
632 typedef std::list<ItemTargetInfo> ItemTargetList;
634 TargetList m_UniqueTargetInfo;
635 GOTargetList m_UniqueGOTargetInfo;
636 ItemTargetList m_UniqueItemInfo;
638 void AddUnitTarget(Unit* target, SpellEffectIndex effIndex);
639 void AddUnitTarget(ObjectGuid unitGuid, SpellEffectIndex effIndex);
640 void AddGOTarget(GameObject* target, SpellEffectIndex effIndex);
641 void AddGOTarget(ObjectGuid goGuid, SpellEffectIndex effIndex);
642 void AddItemTarget(Item* target, SpellEffectIndex effIndex);
643 void DoAllEffectOnTarget(TargetInfo* target);
644 void HandleDelayedSpellLaunch(TargetInfo* target);
645 void InitializeDamageMultipliers();
646 void ResetEffectDamageAndHeal();
647 void DoSpellHitOnUnit(Unit* unit, uint32 effectMask);
648 void DoAllEffectOnTarget(GOTargetInfo* target);
649 void DoAllEffectOnTarget(ItemTargetInfo* target);
650 bool IsAliveUnitPresentInTargetList();
651 SpellCastResult CanOpenLock(SpellEffectIndex effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
652 // -------------------------------------------
654 // List For Triggered Spells
655 typedef std::list<SpellEntry const*> SpellInfoList;
656 SpellInfoList m_TriggerSpells; // casted by caster to same targets settings in m_targets at success finish of current spell
657 SpellInfoList m_preCastSpells; // casted by caster to each target at spell hit before spell effects apply
659 uint32 m_spellState;
660 uint32 m_timer;
662 float m_castPositionX;
663 float m_castPositionY;
664 float m_castPositionZ;
665 float m_castOrientation;
666 bool m_IsTriggeredSpell;
668 // if need this can be replaced by Aura copy
669 // we can't store original aura link to prevent access to deleted auras
670 // and in same time need aura data and after aura deleting.
671 SpellEntry const* m_triggeredByAuraSpell;
673 private:
674 // NPC Summonings
675 struct CreaturePosition
677 CreaturePosition() :
678 x(0.0f), y(0.0f), z(0.0f),
679 creature(NULL)
682 float x, y, z;
683 Creature* creature;
685 typedef std::vector<CreaturePosition> CreatureSummonPositions;
687 // return true IFF further processing required
688 bool DoSummonPet(SpellEffectEntry const* effect);
689 bool DoSummonTotem(SpellEffectEntry const* effect, uint8 slot_dbc = 0);
690 bool DoSummonWild(CreatureSummonPositions& list, SummonPropertiesEntry const* prop, SpellEffectEntry const* effect, uint32 level);
691 bool DoSummonCritter(CreatureSummonPositions& list, SummonPropertiesEntry const* prop, SpellEffectEntry const* effect, uint32 level);
692 bool DoSummonGuardian(CreatureSummonPositions& list, SummonPropertiesEntry const* prop, SpellEffectEntry const* effect, uint32 level);
693 bool DoSummonPossessed(CreatureSummonPositions& list, SummonPropertiesEntry const* prop, SpellEffectEntry const* effect, uint32 level);
694 bool DoSummonVehicle(CreatureSummonPositions& list, SummonPropertiesEntry const* prop, SpellEffectEntry const* effect, uint32 level);
697 enum ReplenishType
699 REPLENISH_UNDEFINED = 0,
700 REPLENISH_HEALTH = 20,
701 REPLENISH_MANA = 21,
702 REPLENISH_RAGE = 22
705 namespace MaNGOS
707 struct MANGOS_DLL_DECL SpellNotifierPlayer // Currently unused. When put to use this one requires handling for source-location (smilar to below)
709 Spell::UnitList& i_data;
710 Spell& i_spell;
711 const uint32& i_index;
712 float i_radius;
713 WorldObject* i_originalCaster;
715 SpellNotifierPlayer(Spell& spell, Spell::UnitList& data, const uint32& i, float radius)
716 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
718 i_originalCaster = i_spell.GetAffectiveCasterObject();
721 void Visit(PlayerMapType& m)
723 if (!i_originalCaster)
724 return;
726 for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
728 Player* pPlayer = itr->getSource();
729 if (!pPlayer->isAlive() || pPlayer->IsTaxiFlying())
730 continue;
732 if (i_originalCaster->IsFriendlyTo(pPlayer))
733 continue;
735 if (pPlayer->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ, i_radius))
736 i_data.push_back(pPlayer);
739 template<class SKIP> void Visit(GridRefManager<SKIP>&) {}
742 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
744 Spell::UnitList* i_data;
745 Spell& i_spell;
746 SpellNotifyPushType i_push_type;
747 float i_radius;
748 SpellTargets i_TargetType;
749 WorldObject* i_originalCaster;
750 WorldObject* i_castingObject;
751 bool i_playerControlled;
752 float i_centerX;
753 float i_centerY;
754 float i_centerZ;
756 float GetCenterX() const { return i_centerX; }
757 float GetCenterY() const { return i_centerY; }
759 SpellNotifierCreatureAndPlayer(Spell& spell, Spell::UnitList& data, float radius, SpellNotifyPushType type,
760 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY, WorldObject* originalCaster = NULL)
761 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType),
762 i_originalCaster(originalCaster), i_castingObject(i_spell.GetCastingObject())
764 if (!i_originalCaster)
765 i_originalCaster = i_spell.GetAffectiveCasterObject();
766 i_playerControlled = i_originalCaster ? i_originalCaster->IsControlledByPlayer() : false;
768 switch (i_push_type)
770 case PUSH_IN_FRONT:
771 case PUSH_IN_FRONT_90:
772 case PUSH_IN_FRONT_30:
773 case PUSH_IN_FRONT_15:
774 case PUSH_IN_BACK:
775 case PUSH_SELF_CENTER:
776 if (i_castingObject)
778 i_centerX = i_castingObject->GetPositionX();
779 i_centerY = i_castingObject->GetPositionY();
781 break;
782 case PUSH_DEST_CENTER:
783 if (i_spell.m_targets.m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
784 i_spell.m_targets.getSource(i_centerX, i_centerY, i_centerZ);
785 else
786 i_spell.m_targets.getDestination(i_centerX, i_centerY, i_centerZ);
787 break;
788 case PUSH_TARGET_CENTER:
789 if (Unit* target = i_spell.m_targets.getUnitTarget())
791 i_centerX = target->GetPositionX();
792 i_centerY = target->GetPositionY();
794 break;
795 default:
796 sLog.outError("SpellNotifierCreatureAndPlayer: unsupported PUSH_* case %u.", i_push_type);
800 template<class T> inline void Visit(GridRefManager<T>& m)
802 MANGOS_ASSERT(i_data);
804 if (!i_originalCaster || !i_castingObject)
805 return;
807 for (typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
809 // there are still more spells which can be casted on dead, but
810 // they are no AOE and don't have such a nice SPELL_ATTR flag
811 if ((i_TargetType != SPELL_TARGETS_ALL && !itr->getSource()->isTargetableForAttack(i_spell.m_spellInfo->HasAttribute(SPELL_ATTR_EX3_CAST_ON_DEAD)))
812 // mostly phase check
813 || !itr->getSource()->IsInMap(i_originalCaster))
814 continue;
816 switch (i_TargetType)
818 case SPELL_TARGETS_HOSTILE:
819 if (!i_originalCaster->IsHostileTo(itr->getSource()))
820 continue;
821 break;
822 case SPELL_TARGETS_NOT_FRIENDLY:
823 if (i_originalCaster->IsFriendlyTo(itr->getSource()))
824 continue;
825 break;
826 case SPELL_TARGETS_NOT_HOSTILE:
827 if (i_originalCaster->IsHostileTo(itr->getSource()))
828 continue;
829 break;
830 case SPELL_TARGETS_FRIENDLY:
831 if (!i_originalCaster->IsFriendlyTo(itr->getSource()))
832 continue;
833 break;
834 case SPELL_TARGETS_AOE_DAMAGE:
836 if (itr->getSource()->GetTypeId() == TYPEID_UNIT && ((Creature*)itr->getSource())->IsTotem())
837 continue;
839 if (i_playerControlled)
841 if (i_originalCaster->IsFriendlyTo(itr->getSource()))
842 continue;
844 else
846 if (!i_originalCaster->IsHostileTo(itr->getSource()))
847 continue;
850 break;
851 case SPELL_TARGETS_ALL:
852 break;
853 default: continue;
856 // we don't need to check InMap here, it's already done some lines above
857 switch (i_push_type)
859 case PUSH_IN_FRONT:
860 if (i_castingObject->isInFront((Unit*)(itr->getSource()), i_radius, 2 * M_PI_F / 3))
861 i_data->push_back(itr->getSource());
862 break;
863 case PUSH_IN_FRONT_90:
864 if (i_castingObject->isInFront((Unit*)(itr->getSource()), i_radius, M_PI_F / 2))
865 i_data->push_back(itr->getSource());
866 break;
867 case PUSH_IN_FRONT_30:
868 if (i_castingObject->isInFront((Unit*)(itr->getSource()), i_radius, M_PI_F / 6))
869 i_data->push_back(itr->getSource());
870 break;
871 case PUSH_IN_FRONT_15:
872 if (i_castingObject->isInFront((Unit*)(itr->getSource()), i_radius, M_PI_F / 12))
873 i_data->push_back(itr->getSource());
874 break;
875 case PUSH_IN_BACK:
876 if (i_castingObject->isInBack((Unit*)(itr->getSource()), i_radius, 2 * M_PI_F / 3))
877 i_data->push_back(itr->getSource());
878 break;
879 case PUSH_SELF_CENTER:
880 if (i_castingObject->IsWithinDist((Unit*)(itr->getSource()), i_radius))
881 i_data->push_back(itr->getSource());
882 break;
883 case PUSH_DEST_CENTER:
884 if (itr->getSource()->IsWithinDist3d(i_centerX, i_centerY, i_centerZ, i_radius))
885 i_data->push_back(itr->getSource());
886 break;
887 case PUSH_TARGET_CENTER:
888 if (i_spell.m_targets.getUnitTarget() && i_spell.m_targets.getUnitTarget()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
889 i_data->push_back(itr->getSource());
890 break;
895 #ifdef WIN32
896 template<> inline void Visit(CorpseMapType&) {}
897 template<> inline void Visit(GameObjectMapType&) {}
898 template<> inline void Visit(DynamicObjectMapType&) {}
899 template<> inline void Visit(CameraMapType&) {}
900 #endif
903 #ifndef WIN32
904 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType&) {}
905 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType&) {}
906 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType&) {}
907 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CameraMapType&) {}
908 #endif
911 typedef void(Spell::*pEffect)(SpellEffectEntry const* spellEffect);
913 class SpellEvent : public BasicEvent
915 public:
916 SpellEvent(Spell* spell);
917 virtual ~SpellEvent();
919 virtual bool Execute(uint64 e_time, uint32 p_time) override;
920 virtual void Abort(uint64 e_time) override;
921 virtual bool IsDeletable() const override;
922 protected:
923 Spell* m_Spell;
925 #endif