TrinityCore
Loading...
Searching...
No Matches
Spell.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __SPELL_H
19#define __SPELL_H
20
21#include "ConditionMgr.h"
22#include "DBCEnums.h"
23#include "ObjectGuid.h"
24#include "Position.h"
25#include "SharedDefines.h"
26#include "SpellDefines.h"
27#include "UniqueTrackablePtr.h"
28#include <memory>
29
30namespace WorldPackets
31{
32 namespace Spells
33 {
34 struct SpellTargetData;
35 struct SpellAmmo;
36 struct SpellCastData;
37 }
38}
39
40class Aura;
41class AuraEffect;
42class Corpse;
43class DamageInfo;
44class DynamicObject;
45class DynObjAura;
46class GameObject;
47class Item;
48class Object;
49class PathGenerator;
50class Player;
51class SpellEffectInfo;
52class SpellEvent;
54class SpellInfo;
55class SpellScript;
56class Unit;
57class UnitAura;
58class WorldObject;
59class WorldPacket;
61enum AuraType : uint32;
63enum LootType : uint8;
67enum SpellValueMod : uint8;
70
71#define SPELL_CHANNEL_UPDATE_INTERVAL (1 * IN_MILLISECONDS)
72#define MAX_SPELL_RANGE_TOLERANCE 3.0f
73#define TRAJECTORY_MISSILE_SIZE 3.0f
74
76{
77 CAST_FLAG_NONE = 0x00000000,
78 CAST_FLAG_PENDING = 0x00000001, // aoe combat log?
80 CAST_FLAG_UNKNOWN_3 = 0x00000004,
81 CAST_FLAG_UNKNOWN_4 = 0x00000008, // ignore AOE visual
82 CAST_FLAG_UNKNOWN_5 = 0x00000010,
83 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
84 CAST_FLAG_UNKNOWN_7 = 0x00000040,
85 CAST_FLAG_UNKNOWN_8 = 0x00000080,
86 CAST_FLAG_UNKNOWN_9 = 0x00000100,
96 CAST_FLAG_NO_GCD = 0x00040000, // no GCD for spell casts from charm/summon (vehicle spells is an example)
99 CAST_FLAG_RUNE_LIST = 0x00200000,
104 CAST_FLAG_IMMUNITY = 0x04000000,
109 CAST_FLAG_UNKNOWN_32 = 0x80000000
111
113{
115 SPELL_RANGE_MELEE = 1, //melee
116 SPELL_RANGE_RANGED = 2 //hunter range and ranged weapon
118
128
138
146
147typedef std::vector<std::pair<uint32, ObjectGuid>> DispelList;
148
150
152{
153 friend class SpellScript;
154 public:
155
156 void EffectNULL();
157 void EffectUnused();
158 void EffectDistract();
159 void EffectPull();
160 void EffectSchoolDMG();
161 void EffectEnvironmentalDMG();
162 void EffectInstaKill();
163 void EffectDummy();
164 void EffectTeleportUnits();
165 void EffectApplyAura();
166 void EffectSendEvent();
167 void EffectPowerBurn();
168 void EffectPowerDrain();
169 void EffectHeal();
170 void EffectBind();
171 void EffectHealthLeech();
172 void EffectQuestComplete();
173 void EffectCreateItem();
174 void EffectCreateItem2();
175 void EffectCreateRandomItem();
176 void EffectPersistentAA();
177 void EffectEnergize();
178 void EffectOpenLock();
179 void EffectSummonChangeItem();
180 void EffectProficiency();
181 void EffectSummonType();
182 void EffectLearnSpell();
183 void EffectDispel();
184 void EffectDualWield();
185 void EffectPickPocket();
186 void EffectAddFarsight();
187 void EffectUntrainTalents();
188 void EffectHealMechanical();
189 void EffectJump();
190 void EffectJumpDest();
191 void EffectLeapBack();
192 void EffectQuestClear();
193 void EffectTeleUnitsFaceCaster();
194 void EffectLearnSkill();
195 void EffectAddHonor();
196 void EffectTradeSkill();
197 void EffectEnchantItemPerm();
198 void EffectEnchantItemTmp();
199 void EffectTameCreature();
200 void EffectSummonPet();
201 void EffectLearnPetSpell();
202 void EffectWeaponDmg();
203 void EffectForceCast();
204 void EffectTriggerSpell();
205 void EffectTriggerMissileSpell();
206 void EffectThreat();
207 void EffectHealMaxHealth();
208 void EffectInterruptCast();
209 void EffectSummonObjectWild();
210 void EffectScriptEffect();
211 void EffectSanctuary();
212 void EffectAddComboPoints();
213 void EffectDuel();
214 void EffectStuck();
215 void EffectSummonPlayer();
216 void EffectActivateObject();
217 void EffectApplyGlyph();
218 void EffectEnchantHeldItem();
219 void EffectSummonObject();
220 void EffectResurrect();
221 void EffectParry();
222 void EffectBlock();
223 void EffectLeap();
224 void EffectTransmitted();
225 void EffectDisEnchant();
226 void EffectInebriate();
227 void EffectFeedPet();
228 void EffectDismissPet();
229 void EffectReputation();
230 void EffectForceDeselect();
231 void EffectSelfResurrect();
232 void EffectSkinning();
233 void EffectCharge();
234 void EffectChargeDest();
235 void EffectProspecting();
236 void EffectMilling();
237 void EffectRenamePet();
238 void EffectSendTaxi();
239 void EffectKnockBack();
240 void EffectPullTowards();
241 void EffectPullTowardsDest();
242 void EffectDispelMechanic();
243 void EffectResurrectPet();
244 void EffectDestroyAllTotems();
245 void EffectDurabilityDamage();
246 void EffectSkill();
247 void EffectTaunt();
248 void EffectDurabilityDamagePCT();
249 void EffectModifyThreatPercent();
250 void EffectResurrectNew();
251 void EffectAddExtraAttacks();
252 void EffectSpiritHeal();
253 void EffectSkinPlayerCorpse();
254 void EffectStealBeneficialBuff();
255 void EffectUnlearnSpecialization();
256 void EffectHealPct();
257 void EffectEnergizePct();
258 void EffectTriggerRitualOfSummoning();
259 void EffectSummonRaFFriend();
260 void EffectKillCreditPersonal();
261 void EffectKillCredit();
262 void EffectQuestFail();
263 void EffectQuestStart();
264 void EffectRedirectThreat();
265 void EffectGameObjectDamage();
266 void EffectGameObjectRepair();
267 void EffectGameObjectSetDestructionState();
268 void EffectActivateRune();
269 void EffectCreateTamedPet();
270 void EffectDiscoverTaxi();
271 void EffectTitanGrip();
272 void EffectEnchantItemPrismatic();
273 void EffectPlayMusic();
274 void EffectSpecCount();
275 void EffectActivateSpec();
276 void EffectPlaySound();
277 void EffectRemoveAura();
278 void EffectCastButtons();
279 void EffectRechargeManaGem();
280
281 typedef std::unordered_set<Aura*> UsedSpellMods;
282
283 Spell(WorldObject* caster, SpellInfo const* info, TriggerCastFlags triggerFlags, ObjectGuid originalCasterGUID = ObjectGuid::Empty);
284 ~Spell();
285
286 void InitExplicitTargets(SpellCastTargets const& targets);
287 void SelectExplicitTargets();
288
289 void SelectSpellTargets();
290 void SelectEffectImplicitTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effectMask);
291 void SelectImplicitChannelTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effMask);
292 void SelectImplicitNearbyTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effMask);
293 void SelectImplicitConeTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effMask);
294 void SelectImplicitAreaTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effMask);
295 void SelectImplicitCasterDestTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType);
296 void SelectImplicitTargetDestTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType);
297 void SelectImplicitDestDestTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType);
298 void SelectImplicitCasterObjectTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effMask);
299 void SelectImplicitTargetObjectTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, uint32 effMask);
300 void SelectImplicitChainTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType, WorldObject* target, uint32 effMask);
301 void SelectImplicitTrajTargets(SpellEffectInfo const& spellEffectInfo, SpellImplicitTargetInfo const& targetType);
302
303 void SelectEffectTypeImplicitTargets(SpellEffectInfo const& spellEffectInfo);
304
305 uint32 GetSearcherTypeMask(SpellTargetObjectTypes objType, ConditionContainer* condList);
306 template<class SEARCHER> void SearchTargets(SEARCHER& searcher, uint32 containerMask, WorldObject* referer, Position const* pos, float radius);
307
308 WorldObject* SearchNearbyTarget(float range, SpellTargetObjectTypes objectType, SpellTargetCheckTypes selectionType, ConditionContainer* condList = nullptr);
309 void SearchAreaTargets(std::list<WorldObject*>& targets, float range, Position const* position, WorldObject* referer, SpellTargetObjectTypes objectType, SpellTargetCheckTypes selectionType, ConditionContainer* condList);
310 void SearchChainTargets(std::list<WorldObject*>& targets, uint32 chainTargets, WorldObject* target, SpellTargetObjectTypes objectType, SpellTargetCheckTypes selectType, ConditionContainer* condList, bool isChainHeal);
311
312 GameObject* SearchSpellFocus();
313
314 SpellCastResult prepare(SpellCastTargets const& targets, AuraEffect const* triggeredByAura = nullptr);
315 void cancel(SpellCastResult result = SPELL_FAILED_INTERRUPTED, Optional<SpellCastResult> resultOther = {});
316 void update(uint32 difftime);
317 void cast(bool skipCheck = false);
318 void finish(bool ok = true);
319 void TakePower();
320 void TakeAmmo();
321
322 void TakeRunePower(bool didHit);
323 void TakeReagents();
324 void TakeCastItem();
325
326 SpellCastResult CheckCast(bool strict, uint32* param1 = nullptr, uint32* param2 = nullptr);
327 SpellCastResult CheckPetCast(Unit* target);
328
329 // handlers
330 void handle_immediate();
331 uint64 handle_delayed(uint64 t_offset);
332 // handler helpers
333 void _handle_immediate_phase();
334 void _handle_finish_phase();
335
336 SpellCastResult CheckItems(uint32* param1, uint32* param2) const;
337 SpellCastResult CheckRange(bool strict) const;
338 SpellCastResult CheckPower() const;
339 SpellCastResult CheckRuneCost(uint32 runeCostID) const;
340 SpellCastResult CheckCasterAuras(uint32* param1) const;
341 SpellCastResult CheckArenaCastRules() const;
342 SpellCastResult CheckMovement() const;
343
344 bool CheckSpellCancelsAuraEffect(AuraType auraType, uint32* param1) const;
345 bool CheckSpellCancelsCharm(uint32* param1) const;
346 bool CheckSpellCancelsStun(uint32* param1) const;
347 bool CheckSpellCancelsSilence(uint32* param1) const;
348 bool CheckSpellCancelsPacify(uint32* param1) const;
349 bool CheckSpellCancelsFear(uint32* param1) const;
350 bool CheckSpellCancelsConfuse(uint32* param1) const;
351
352 int32 CalculateDamage(SpellEffectInfo const& spellEffectInfo) const;
353
354 void Delayed();
355 void DelayedChannel();
356 uint32 getState() const { return m_spellState; }
357 void setState(uint32 state) { m_spellState = state; }
358
359 void DoCreateItem(uint32 itemId);
360 void UpdateSpellCastDataTargets(WorldPackets::Spells::SpellCastData& data);
361 void UpdateSpellCastDataAmmo(WorldPackets::Spells::SpellAmmo& data);
362
363 bool CheckEffectTarget(Unit const* target, SpellEffectInfo const& spellEffectInfo, Position const* losPosition) const;
364 bool CheckEffectTarget(GameObject const* target, SpellEffectInfo const& spellEffectInfo) const;
365 bool CheckEffectTarget(Item const* target, SpellEffectInfo const& spellEffectInfo) const;
366 bool CanAutoCast(Unit* target);
367 void CheckSrc();
368 void CheckDst();
369
370 static void SendCastResult(Player* caster, SpellInfo const* spellInfo, uint8 castCount, SpellCastResult result, SpellCustomErrors customError = SPELL_CUSTOM_ERROR_NONE, uint32* param1 = nullptr, uint32* param2 = nullptr);
371 void SendCastResult(SpellCastResult result, uint32* param1 = nullptr, uint32* param2 = nullptr) const;
372 void SendPetCastResult(SpellCastResult result);
373 void SendMountResult(MountResult result);
374 void SendSpellStart();
375 void SendSpellGo();
376 void SendSpellCooldown();
377 void SendLogExecute();
378 void ExecuteLogEffectTakeTargetPower(uint8 effIndex, Unit* target, uint32 powerType, uint32 powerTaken, float gainMultiplier);
379 void ExecuteLogEffectExtraAttacks(uint8 effIndex, Unit* victim, uint32 attCount);
380 void ExecuteLogEffectInterruptCast(uint8 effIndex, Unit* victim, uint32 spellId);
381 void ExecuteLogEffectDurabilityDamage(uint8 effIndex, Unit* victim, int32 itemId, int32 slot);
382 void ExecuteLogEffectOpenLock(uint8 effIndex, Object* obj);
383 void ExecuteLogEffectCreateItem(uint8 effIndex, uint32 entry);
384 void ExecuteLogEffectDestroyItem(uint8 effIndex, uint32 entry);
385 void ExecuteLogEffectSummonObject(uint8 effIndex, WorldObject* obj);
386 void ExecuteLogEffectUnsummonObject(uint8 effIndex, WorldObject* obj);
387 void ExecuteLogEffectResurrect(uint8 effIndex, Unit* target);
388 void SendInterrupted(SpellCastResult result, Optional<SpellCastResult> resultOther = {});
389 void SendChannelUpdate(uint32 time);
390 void SendChannelStart(uint32 duration);
391 void SendResurrectRequest(Player* target);
392
393 void HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGoTarget, Corpse* pCorpseTarget, SpellEffectInfo const& spellEffectInfo, SpellEffectHandleMode mode);
394 void HandleThreatSpells();
395
396 SpellInfo const* const m_spellInfo;
402 union
403 {
404 // Alternate names for this value
406
408 } m_misc;
410
411 void AddComboPointGain(Unit* target, int8 amount)
412 {
413 if (target != m_comboTarget)
414 {
415 m_comboTarget = target;
416 m_comboPointGain = amount;
417 }
418 else
419 m_comboPointGain += amount;
420 }
424
426
427 int32 GetCastTime() const { return m_casttime; }
428 bool IsAutoRepeat() const { return m_autoRepeat; }
429 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
430 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
431 bool IsTriggered() const;
432 bool IsIgnoringCooldowns() const;
433 bool IsFocusDisabled() const;
434 bool IsProcDisabled() const;
435 bool IsChannelActive() const;
436 bool IsAutoActionResetSpell() const;
437 bool IsPositive() const;
438
439 bool IsTriggeredByAura(SpellInfo const* auraSpellInfo) const { return (auraSpellInfo == m_triggeredByAuraSpell); }
440
441 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
442 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
443 bool IsInterruptable() const { return !m_executedCurrently; }
444 void SetExecutedCurrently(bool yes) {m_executedCurrently = yes;}
445 uint64 GetDelayStart() const { return m_delayStart; }
446 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
447 uint64 GetDelayMoment() const { return m_delayMoment; }
448 uint64 CalculateDelayMomentForDst() const;
449 void RecalculateDelayMomentForDst();
450 uint8 GetRuneState() const { return m_runesState; }
451 void SetRuneState(uint8 value) { m_runesState = value; }
452
453 bool IsNeedSendToClient() const;
454
455 CurrentSpellTypes GetCurrentContainer() const;
456
457 WorldObject* GetCaster() const { return m_caster; }
458 Unit* GetOriginalCaster() const { return m_originalCaster; }
459 SpellInfo const* GetSpellInfo() const { return m_spellInfo; }
460 int32 GetPowerCost() const { return m_powerCost; }
461
462 bool UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
463 void UpdateOriginalCasterPointer();
464
465 void CleanupTargetList();
466
467 void SetSpellValue(SpellValueMod mod, int32 value);
468
469 Spell** m_selfContainer; // pointer to our spell container (if applicable)
470
471 std::string GetDebugInfo() const;
472
473 Trinity::unique_weak_ptr<Spell> GetWeakPtr() const;
474
475 void CallScriptOnResistAbsorbCalculateHandlers(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount);
476
477 int64 GetUnitTargetCountForEffect(SpellEffIndex effect) const;
478 int64 GetGameObjectTargetCountForEffect(SpellEffIndex effect) const;
479 int64 GetItemTargetCountForEffect(SpellEffIndex effect) const;
480
481 protected:
482 bool HasGlobalCooldown() const;
483 void TriggerGlobalCooldown();
484 void CancelGlobalCooldown();
485 void _cast(bool skipCheck = false);
486
487 void SendLoot(ObjectGuid guid, LootType loottype);
488 std::pair<float, float> GetMinMaxRange(bool strict) const;
489
491
493
494 ObjectGuid m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
495 // e.g. damage around area spell trigered by victim aura and damage enemies of aura caster
496 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
497
498 // Spell data
499 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
500 WeaponAttackType m_attackType; // For weapon based attack
501 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
502 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
503 int32 m_channeledDuration; // Calculated channeled spell duration in order to calculate correct pushback.
504 bool m_canReflect; // can reflect this spell?
507
510 {
511 if (m_delayAtDamageCount >= 2)
512 return true;
513
514 ++m_delayAtDamageCount;
515 return false;
516 }
517
518 // Delayed spells system
519 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
520 uint64 m_delayMoment; // moment of next delay call, used internally
521 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
522
523 // These vars are used in both delayed spell system and modified immediate spell system
524 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
525 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
528 float m_damageMultipliers[MAX_SPELL_EFFECTS];
529
530 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
540 // used in effects handlers
541 Unit* GetUnitCasterForEffectHandlers() const;
544
545 // -------------------------------------------
548
549 // Damage and healing in effects need just calculate
550 int32 m_damage; // Damage in effects count here
551 int32 m_healing; // Healing in effects count here
552
553 // ******************************************
554 // Spell trigger system
555 // ******************************************
556 uint32 m_procAttacker; // Attacker trigger flags
557 uint32 m_procVictim; // Victim trigger flags
559 void prepareDataForTriggerSystem();
560
561 // *****************************************
562 // Spell target subsystem
563 // *****************************************
564 // Targets store structures and data
566 {
567 virtual void PreprocessTarget(Spell* /*spell*/) { }
568 virtual void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) = 0;
569 virtual void DoDamageAndTriggers(Spell* /*spell*/) { }
570
571 uint8 EffectMask = 0;
572
573 protected:
575 virtual ~TargetInfoBase() { }
576 };
577
579 {
580 void PreprocessTarget(Spell* spell) override;
581 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
582 void DoDamageAndTriggers(Spell* spell) override;
583
585 uint64 TimeDelay = 0ULL;
586 int32 Damage = 0;
587 int32 Healing = 0;
588
591
592 bool IsAlive = false;
593 bool IsCrit = false;
594 bool ScaleAura = false;
595
596 // info set at PreprocessTarget, used by DoTargetSpellHit
598 int32 AuraDuration = 0;
599 SpellInfo const* AuraSpellInfo = nullptr;
600 int32 AuraBasePoints[MAX_SPELL_EFFECTS] = { };
601 bool Positive = true;
602 UnitAura* HitAura = nullptr;
603
604 private:
605 Unit* _spellHitTarget = nullptr; // changed for example by reflect
606 bool _enablePVP = false; // need to enable PVP at DoDamageAndTriggers?
607 };
608 std::vector<TargetInfo> m_UniqueTargetInfo;
609 uint8 m_channelTargetEffectMask; // Mask req. alive targets
610
612 {
613 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
614
616 uint64 TimeDelay = 0ULL;
617 };
618 std::vector<GOTargetInfo> m_UniqueGOTargetInfo;
619
621 {
622 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
623
624 Item* TargetItem = nullptr;
625 };
626 std::vector<ItemTargetInfo> m_UniqueItemInfo;
627
629 {
630 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
631
633 uint64 TimeDelay = 0ULL;
634 };
635 std::vector<CorpseTargetInfo> m_UniqueCorpseTargetInfo;
636
637 template <class Container>
638 void DoProcessTargetContainer(Container& targetContainer);
639
641
642 void AddUnitTarget(Unit* target, uint32 effectMask, bool checkIfValid = true, bool implicit = true, Position const* losPosition = nullptr);
643 void AddGOTarget(GameObject* target, uint32 effectMask);
644 void AddItemTarget(Item* item, uint32 effectMask);
645 void AddCorpseTarget(Corpse* target, uint32 effectMask);
646 void AddDestTarget(SpellDestination const& dest, uint32 effIndex);
647
648 void PreprocessSpellLaunch(TargetInfo& targetInfo);
649 SpellMissInfo PreprocessSpellHit(Unit* unit, bool scaleAura, TargetInfo& targetInfo);
650 void DoSpellEffectHit(Unit* unit, SpellEffectInfo const& spellEffectInfo, TargetInfo& targetInfo);
651
652 void DoTriggersOnSpellHit(Unit* unit, uint8 effMask);
653 bool UpdateChanneledTargetList();
654 bool IsValidDeadOrAliveTarget(Unit const* target) const;
655 void HandleLaunchPhase();
656 void DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, SpellEffectInfo const& spellEffectInfo);
657
658 void PrepareTargetProcessing();
659 void FinishTargetProcessing();
660
661 // spell execution log
662 void InitEffectExecuteData(uint8 effIndex);
663 void AssertEffectExecuteData() const;
664
665 // Scripting system
666 void LoadScripts();
667 void CallScriptBeforeCastHandlers();
668 void CallScriptOnCastHandlers();
669 void CallScriptAfterCastHandlers();
670 SpellCastResult CallScriptCheckCastHandlers();
671 bool CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode);
672 void CallScriptSuccessfulDispel(SpellEffIndex effIndex);
673 void CallScriptBeforeHitHandlers(SpellMissInfo missInfo);
674 void CallScriptOnHitHandlers();
675 void CallScriptAfterHitHandlers();
676 void CallScriptObjectAreaTargetSelectHandlers(std::list<WorldObject*>& targets, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
677 void CallScriptObjectTargetSelectHandlers(WorldObject*& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
678 void CallScriptDestinationTargetSelectHandlers(SpellDestination& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
679 bool CheckScriptEffectImplicitTargets(uint32 effIndex, uint32 effIndexToCheck);
680 std::vector<SpellScript*> m_loadedScripts;
681
683 {
684 HitTriggerSpell(SpellInfo const* spellInfo, SpellInfo const* auraSpellInfo, int32 procChance) :
685 triggeredSpell(spellInfo), triggeredByAura(auraSpellInfo), chance(procChance) { }
686
689 // uint8 triggeredByEffIdx This might be needed at a later stage - No need known for now
691 };
692
693 bool CanExecuteTriggersOnHit(uint8 effMask, SpellInfo const* triggeredByAura = nullptr) const;
694 void PrepareTriggersExecutedOnHit();
695 typedef std::vector<HitTriggerSpell> HitTriggerSpellList;
697
698 // effect helpers
699 void SummonGuardian(SpellEffectInfo const& spellEffectInfo, uint32 entry, SummonPropertiesEntry const* properties, uint32 numSummons);
700 void CalculateJumpSpeeds(SpellEffectInfo const& spellEffectInfo, float dist, float& speedXY, float& speedZ);
701
702 SpellCastResult CanOpenLock(SpellEffectInfo const& spellEffectInfo, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
703 // -------------------------------------------
704
707
710
711 // if need this can be replaced by Aura copy
712 // we can't store original aura link to prevent access to deleted auras
713 // and in same time need aura data and after aura deleting.
715
717 std::unique_ptr<PathGenerator> m_preGeneratedPath;
718
719 ByteBuffer* m_effectExecuteData[MAX_SPELL_EFFECTS];
720
721 Spell(Spell const& right) = delete;
722 Spell& operator=(Spell const& right) = delete;
723};
724
725namespace Trinity
726{
728 {
729 protected:
734 std::unique_ptr<ConditionSourceInfo> _condSrcInfo;
736
737 WorldObjectSpellTargetCheck(WorldObject* caster, WorldObject* referer, SpellInfo const* spellInfo,
738 SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
740
741 bool operator()(WorldObject* target) const;
742 };
743
745 {
746 float _range;
748 WorldObjectSpellNearbyTargetCheck(float range, WorldObject* caster, SpellInfo const* spellInfo,
749 SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
750
751 bool operator()(WorldObject* target);
752 };
753
755 {
756 float _range;
758 WorldObjectSpellAreaTargetCheck(float range, Position const* position, WorldObject* caster,
759 WorldObject* referer, SpellInfo const* spellInfo, SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
760
761 bool operator()(WorldObject* target) const;
762 };
763
765 {
767 WorldObjectSpellConeTargetCheck(float coneAngle, float range, WorldObject* caster,
768 SpellInfo const* spellInfo, SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
769
770 bool operator()(WorldObject* target) const;
771 };
772
774 {
775 float _range;
777 WorldObjectSpellTrajTargetCheck(float range, Position const* position, WorldObject* caster,
778 SpellInfo const* spellInfo, SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
779
780 bool operator()(WorldObject* target) const;
781 };
782}
783
784using SpellEffectHandlerFn = void(Spell::*)();
785
786#endif
std::vector< Condition * > ConditionContainer
#define MAX_SPELL_EFFECTS
Definition DBCEnums.h:386
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int64_t int64
Definition Define.h:128
int8_t int8
Definition Define.h:131
int32_t int32
Definition Define.h:129
uint64_t uint64
Definition Define.h:132
uint32_t uint32
Definition Define.h:133
std::string GetDebugInfo()
Definition Errors.cpp:155
LootType
Definition Loot.h:89
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
Spells
Definition PlayerAI.cpp:32
SpellEffIndex
MountResult
SpellSchoolMask
WeaponAttackType
SpellCustomErrors
@ SPELL_CUSTOM_ERROR_NONE
DiminishingGroup
@ DIMINISHING_NONE
SpellMissInfo
@ SPELL_MISS_NONE
SpellCastResult
@ SPELL_FAILED_INTERRUPTED
SkillType
SpellCastTargetFlags
TriggerCastFlags
SpellValueMod
SpellTargetCheckTypes
Definition SpellInfo.h:78
SpellTargetObjectTypes
Definition SpellInfo.h:62
SpellRangeFlag
Definition Spell.h:113
@ SPELL_RANGE_MELEE
Definition Spell.h:115
@ SPELL_RANGE_RANGED
Definition Spell.h:116
@ SPELL_RANGE_DEFAULT
Definition Spell.h:114
std::vector< std::pair< uint32, ObjectGuid > > DispelList
Definition Spell.h:147
void(Spell::*)() SpellEffectHandlerFn
Definition Spell.h:784
SpellEffectHandleMode
Definition Spell.h:140
@ SPELL_EFFECT_HANDLE_LAUNCH_TARGET
Definition Spell.h:142
@ SPELL_EFFECT_HANDLE_LAUNCH
Definition Spell.h:141
@ SPELL_EFFECT_HANDLE_HIT
Definition Spell.h:143
@ SPELL_EFFECT_HANDLE_HIT_TARGET
Definition Spell.h:144
SpellState
Definition Spell.h:130
@ SPELL_STATE_DELAYED
Definition Spell.h:136
@ SPELL_STATE_NULL
Definition Spell.h:131
@ SPELL_STATE_FINISHED
Definition Spell.h:134
@ SPELL_STATE_PREPARING
Definition Spell.h:132
@ SPELL_STATE_CASTING
Definition Spell.h:133
@ SPELL_STATE_IDLE
Definition Spell.h:135
static const uint32 SPELL_INTERRUPT_NONPLAYER
Definition Spell.h:149
SpellCastFlags
Definition Spell.h:76
@ CAST_FLAG_UNKNOWN_5
Definition Spell.h:82
@ CAST_FLAG_AMMO
Definition Spell.h:83
@ CAST_FLAG_UNKNOWN_10
Definition Spell.h:87
@ CAST_FLAG_UNKNOWN_32
Definition Spell.h:109
@ CAST_FLAG_UNKNOWN_25
Definition Spell.h:102
@ CAST_FLAG_VISUAL_CHAIN
Definition Spell.h:97
@ CAST_FLAG_ADJUST_MISSILE
Definition Spell.h:95
@ CAST_FLAG_UNKNOWN_8
Definition Spell.h:85
@ CAST_FLAG_UNKNOWN_9
Definition Spell.h:86
@ CAST_FLAG_UNKNOWN_3
Definition Spell.h:80
@ CAST_FLAG_UNKNOWN_26
Definition Spell.h:103
@ CAST_FLAG_UNKNOWN_11
Definition Spell.h:88
@ CAST_FLAG_UNKNOWN_31
Definition Spell.h:108
@ CAST_FLAG_UNKNOWN_30
Definition Spell.h:107
@ CAST_FLAG_UNKNOWN_4
Definition Spell.h:81
@ CAST_FLAG_NO_GCD
Definition Spell.h:96
@ CAST_FLAG_UNKNOWN_23
Definition Spell.h:100
@ CAST_FLAG_UNKNOWN_16
Definition Spell.h:93
@ CAST_FLAG_UNKNOWN_29
Definition Spell.h:106
@ CAST_FLAG_UNKNOWN_7
Definition Spell.h:84
@ CAST_FLAG_POWER_LEFT_SELF
Definition Spell.h:89
@ CAST_FLAG_UNKNOWN_13
Definition Spell.h:90
@ CAST_FLAG_UNKNOWN_28
Definition Spell.h:105
@ CAST_FLAG_UNKNOWN_24
Definition Spell.h:101
@ CAST_FLAG_HAS_TRAJECTORY
Definition Spell.h:79
@ CAST_FLAG_RUNE_LIST
Definition Spell.h:99
@ CAST_FLAG_UNKNOWN_14
Definition Spell.h:91
@ CAST_FLAG_UNKNOWN_15
Definition Spell.h:92
@ CAST_FLAG_PENDING
Definition Spell.h:78
@ CAST_FLAG_NONE
Definition Spell.h:77
@ CAST_FLAG_UNKNOWN_17
Definition Spell.h:94
@ CAST_FLAG_IMMUNITY
Definition Spell.h:104
@ CAST_FLAG_UNKNOWN_21
Definition Spell.h:98
CurrentSpellTypes
Definition Unit.h:619
Definition Item.h:62
static ObjectGuid const Empty
Definition ObjectGuid.h:140
Definition Spell.h:152
SpellInfo const * GetSpellInfo() const
Definition Spell.h:459
Unit * m_comboTarget
Definition Spell.h:421
std::vector< HitTriggerSpell > HitTriggerSpellList
Definition Spell.h:695
bool m_fromClient
Definition Spell.h:401
int8 m_comboPointGain
Definition Spell.h:422
std::vector< SpellScript * > m_loadedScripts
Definition Spell.h:680
GameObject * gameObjTarget
Definition Spell.h:533
SpellMissInfo targetMissInfo
Definition Spell.h:537
bool m_referencedFromCurrentSpell
Definition Spell.h:524
bool m_canReflect
Definition Spell.h:504
uint32 m_procVictim
Definition Spell.h:557
uint32 m_hitMask
Definition Spell.h:558
Unit * m_originalCaster
Definition Spell.h:496
DynObjAura * _dynObjAura
Definition Spell.h:543
bool m_needComboPoints
Definition Spell.h:526
uint64 m_delayStart
Definition Spell.h:519
SpellCastTargets m_targets
Definition Spell.h:409
void setState(uint32 state)
Definition Spell.h:357
std::unique_ptr< PathGenerator > m_preGeneratedPath
Definition Spell.h:717
TriggerCastFlags _triggeredCastFlags
Definition Spell.h:709
bool IsAutoRepeat() const
Definition Spell.h:428
int32 damage
Definition Spell.h:536
SpellEffectHandleMode effectHandleMode
Definition Spell.h:538
int32 m_channeledDuration
Definition Spell.h:503
std::vector< TargetInfo > m_UniqueTargetInfo
Definition Spell.h:608
bool IsInterruptable() const
Definition Spell.h:443
void SetExecutedCurrently(bool yes)
Definition Spell.h:444
uint8 m_delayAtDamageCount
Definition Spell.h:508
uint64 m_delayMoment
Definition Spell.h:520
void AddComboPointGain(Unit *target, int8 amount)
Definition Spell.h:411
WeaponAttackType m_attackType
Definition Spell.h:500
bool m_immediateHandled
Definition Spell.h:521
uint32 m_spellState
Definition Spell.h:705
ObjectGuid m_originalCasterGUID
Definition Spell.h:494
WorldObject *const m_caster
Definition Spell.h:490
int32 GetCastTime() const
Definition Spell.h:427
bool IsDeletable() const
Definition Spell.h:441
int32 m_timer
Definition Spell.h:706
int32 m_casttime
Definition Spell.h:502
Item * itemTarget
Definition Spell.h:532
uint8 m_cast_count
Definition Spell.h:400
int32 m_damage
Definition Spell.h:550
std::vector< CorpseTargetInfo > m_UniqueCorpseTargetInfo
Definition Spell.h:635
uint32 getState() const
Definition Spell.h:356
bool m_executedCurrently
Definition Spell.h:525
uint8 m_auraScaleMask
Definition Spell.h:716
std::unordered_set< Aura * > UsedSpellMods
Definition Spell.h:281
SpellCustomErrors m_customError
Definition Spell.h:423
Spell(Spell const &right)=delete
std::vector< GOTargetInfo > m_UniqueGOTargetInfo
Definition Spell.h:618
HitTriggerSpellList m_hitTriggerSpells
Definition Spell.h:696
int32 m_healing
Definition Spell.h:551
void SetDelayStart(uint64 m_time)
Definition Spell.h:446
SpellEffectInfo const * effectInfo
Definition Spell.h:539
SpellInfo const * m_triggeredByAuraSpell
Definition Spell.h:714
uint8 m_channelTargetEffectMask
Definition Spell.h:609
UnitAura * _spellAura
Definition Spell.h:542
Unit * unitTarget
Definition Spell.h:531
SpellSchoolMask m_spellSchoolMask
Definition Spell.h:499
uint32 GlyphSlot
Definition Spell.h:405
WorldObject * GetCaster() const
Definition Spell.h:457
SpellEvent * _spellEvent
Definition Spell.h:708
Unit * GetOriginalCaster() const
Definition Spell.h:458
Corpse * m_corpseTarget
Definition Spell.h:534
void ReSetTimer()
Definition Spell.h:430
void SetAutoRepeat(bool rep)
Definition Spell.h:429
WorldLocation * destTarget
Definition Spell.h:535
Spell ** m_selfContainer
Definition Spell.h:469
uint8 m_applyMultiplierMask
Definition Spell.h:527
bool IsTriggeredByAura(SpellInfo const *auraSpellInfo) const
Definition Spell.h:439
void SetReferencedFromCurrent(bool yes)
Definition Spell.h:442
bool IsDelayableNoMore()
Definition Spell.h:509
int32 GetPowerCost() const
Definition Spell.h:460
uint64 GetDelayStart() const
Definition Spell.h:445
void SetRuneState(uint8 value)
Definition Spell.h:451
Item * m_CastItem
Definition Spell.h:397
uint32 m_castItemEntry
Definition Spell.h:399
uint64 GetDelayMoment() const
Definition Spell.h:447
UsedSpellMods m_appliedMods
Definition Spell.h:425
ObjectGuid m_focusObjectGUID
Definition Spell.h:546
SpellValue *const m_spellValue
Definition Spell.h:492
int32 m_powerCost
Definition Spell.h:501
uint8 GetRuneState() const
Definition Spell.h:450
std::vector< ItemTargetInfo > m_UniqueItemInfo
Definition Spell.h:626
ObjectGuid m_castItemGUID
Definition Spell.h:398
uint32 m_procAttacker
Definition Spell.h:556
GameObject * focusObject
Definition Spell.h:547
Spell & operator=(Spell const &right)=delete
SpellInfo const *const m_spellInfo
Definition Spell.h:396
uint8 m_runesState
Definition Spell.h:506
bool m_autoRepeat
Definition Spell.h:505
uint32 Data
Definition Spell.h:407
Trinity::unique_trackable_ptr companion class, replicating what std::weak_ptr is to std::shared_ptr.
Definition Unit.h:783
float RadiusMod
Definition Spell.h:124
int32 EffectBasePoints[MAX_SPELL_EFFECTS]
Definition Spell.h:122
uint32 MaxAffectedTargets
Definition Spell.h:123
float CriticalChance
Definition Spell.h:126
uint8 AuraStackAmount
Definition Spell.h:125
ObjectGuid TargetGUID
Definition Spell.h:632
ObjectGuid TargetGUID
Definition Spell.h:615
SpellInfo const * triggeredSpell
Definition Spell.h:687
HitTriggerSpell(SpellInfo const *spellInfo, SpellInfo const *auraSpellInfo, int32 procChance)
Definition Spell.h:684
SpellInfo const * triggeredByAura
Definition Spell.h:688
virtual void DoTargetSpellHit(Spell *spell, SpellEffectInfo const &spellEffectInfo)=0
virtual void PreprocessTarget(Spell *)
Definition Spell.h:567
virtual ~TargetInfoBase()
Definition Spell.h:575
virtual void DoDamageAndTriggers(Spell *)
Definition Spell.h:569
ObjectGuid TargetGUID
Definition Spell.h:584
SpellTargetCheckTypes _targetSelectionType
Definition Spell.h:733
std::unique_ptr< ConditionSourceInfo > _condSrcInfo
Definition Spell.h:734
ConditionContainer const * _condList
Definition Spell.h:735
int finish(char const *message, int returnValue)