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 CanAutoCast(Unit* target);
365 void CheckSrc();
366 void CheckDst();
367
368 static void WriteCastResultInfo(WorldPacket& data, Player* caster, SpellInfo const* spellInfo, uint8 castCount, SpellCastResult result, SpellCustomErrors customError, uint32* param1 = nullptr, uint32* param2 = nullptr);
369 static void SendCastResult(Player* caster, SpellInfo const* spellInfo, uint8 castCount, SpellCastResult result, SpellCustomErrors customError = SPELL_CUSTOM_ERROR_NONE, uint32* param1 = nullptr, uint32* param2 = nullptr);
370 void SendCastResult(SpellCastResult result, uint32* param1 = nullptr, uint32* param2 = nullptr) const;
371 void SendPetCastResult(SpellCastResult result);
372 void SendMountResult(MountResult result);
373 void SendSpellStart();
374 void SendSpellGo();
375 void SendSpellCooldown();
376 void SendLogExecute();
377 void ExecuteLogEffectTakeTargetPower(uint8 effIndex, Unit* target, uint32 powerType, uint32 powerTaken, float gainMultiplier);
378 void ExecuteLogEffectExtraAttacks(uint8 effIndex, Unit* victim, uint32 attCount);
379 void ExecuteLogEffectInterruptCast(uint8 effIndex, Unit* victim, uint32 spellId);
380 void ExecuteLogEffectDurabilityDamage(uint8 effIndex, Unit* victim, int32 itemId, int32 slot);
381 void ExecuteLogEffectOpenLock(uint8 effIndex, Object* obj);
382 void ExecuteLogEffectCreateItem(uint8 effIndex, uint32 entry);
383 void ExecuteLogEffectDestroyItem(uint8 effIndex, uint32 entry);
384 void ExecuteLogEffectSummonObject(uint8 effIndex, WorldObject* obj);
385 void ExecuteLogEffectUnsummonObject(uint8 effIndex, WorldObject* obj);
386 void ExecuteLogEffectResurrect(uint8 effIndex, Unit* target);
387 void SendInterrupted(SpellCastResult result, Optional<SpellCastResult> resultOther = {});
388 void SendChannelUpdate(uint32 time);
389 void SendChannelStart(uint32 duration);
390 void SendResurrectRequest(Player* target);
391
392 void HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGoTarget, Corpse* pCorpseTarget, SpellEffectInfo const& spellEffectInfo, SpellEffectHandleMode mode);
393 void HandleThreatSpells();
394
395 SpellInfo const* const m_spellInfo;
403
404 void AddComboPointGain(Unit* target, int8 amount)
405 {
406 if (target != m_comboTarget)
407 {
408 m_comboTarget = target;
409 m_comboPointGain = amount;
410 }
411 else
412 m_comboPointGain += amount;
413 }
417
419
420 int32 GetCastTime() const { return m_casttime; }
421 bool IsAutoRepeat() const { return m_autoRepeat; }
422 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
423 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
424 bool IsTriggered() const;
425 bool IsIgnoringCooldowns() const;
426 bool IsFocusDisabled() const;
427 bool IsProcDisabled() const;
428 bool IsChannelActive() const;
429 bool IsAutoActionResetSpell() const;
430 bool IsPositive() const;
431
432 bool IsTriggeredByAura(SpellInfo const* auraSpellInfo) const { return (auraSpellInfo == m_triggeredByAuraSpell); }
433
434 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
435 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
436 bool IsInterruptable() const { return !m_executedCurrently; }
437 void SetExecutedCurrently(bool yes) {m_executedCurrently = yes;}
438 uint64 GetDelayStart() const { return m_delayStart; }
439 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
440 uint64 GetDelayMoment() const { return m_delayMoment; }
441 uint64 CalculateDelayMomentForDst() const;
442 void RecalculateDelayMomentForDst();
443 uint8 GetRuneState() const { return m_runesState; }
444 void SetRuneState(uint8 value) { m_runesState = value; }
445
446 bool IsNeedSendToClient() const;
447
448 CurrentSpellTypes GetCurrentContainer() const;
449
450 WorldObject* GetCaster() const { return m_caster; }
451 Unit* GetOriginalCaster() const { return m_originalCaster; }
452 SpellInfo const* GetSpellInfo() const { return m_spellInfo; }
453 int32 GetPowerCost() const { return m_powerCost; }
454
455 bool UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
456
457 void CleanupTargetList();
458
459 void SetSpellValue(SpellValueMod mod, int32 value);
460
461 Spell** m_selfContainer; // pointer to our spell container (if applicable)
462
463 std::string GetDebugInfo() const;
464
465 Trinity::unique_weak_ptr<Spell> GetWeakPtr() const;
466
467 void CallScriptOnResistAbsorbCalculateHandlers(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount);
468
469 int64 GetUnitTargetCountForEffect(SpellEffIndex effect) const;
470 int64 GetGameObjectTargetCountForEffect(SpellEffIndex effect) const;
471 int64 GetItemTargetCountForEffect(SpellEffIndex effect) const;
472
473 protected:
474 bool HasGlobalCooldown() const;
475 void TriggerGlobalCooldown();
476 void CancelGlobalCooldown();
477 void _cast(bool skipCheck = false);
478
479 void SendLoot(ObjectGuid guid, LootType loottype);
480 std::pair<float, float> GetMinMaxRange(bool strict) const;
481
483
485
486 ObjectGuid m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
487 // e.g. damage around area spell trigered by victim aura and damage enemies of aura caster
488 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
489
490 // Spell data
491 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
492 WeaponAttackType m_attackType; // For weapon based attack
493 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
494 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
495 int32 m_channeledDuration; // Calculated channeled spell duration in order to calculate correct pushback.
496 bool m_canReflect; // can reflect this spell?
499
502 {
503 if (m_delayAtDamageCount >= 2)
504 return true;
505
506 ++m_delayAtDamageCount;
507 return false;
508 }
509
510 // Delayed spells system
511 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
512 uint64 m_delayMoment; // moment of next delay call, used internally
513 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
514
515 // These vars are used in both delayed spell system and modified immediate spell system
516 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
517 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
520 float m_damageMultipliers[MAX_SPELL_EFFECTS];
521
522 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
532 // used in effects handlers
533 Unit* GetUnitCasterForEffectHandlers() const;
536
537 // -------------------------------------------
540
541 // Damage and healing in effects need just calculate
542 int32 m_damage; // Damage in effects count here
543 int32 m_healing; // Healing in effects count here
544
545 // ******************************************
546 // Spell trigger system
547 // ******************************************
548 uint32 m_procAttacker; // Attacker trigger flags
549 uint32 m_procVictim; // Victim trigger flags
551 void prepareDataForTriggerSystem();
552
553 // *****************************************
554 // Spell target subsystem
555 // *****************************************
556 // Targets store structures and data
558 {
559 virtual void PreprocessTarget(Spell* /*spell*/) { }
560 virtual void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) = 0;
561 virtual void DoDamageAndTriggers(Spell* /*spell*/) { }
562
563 uint8 EffectMask = 0;
564
565 protected:
567 virtual ~TargetInfoBase() { }
568 };
569
571 {
572 void PreprocessTarget(Spell* spell) override;
573 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
574 void DoDamageAndTriggers(Spell* spell) override;
575
577 uint64 TimeDelay = 0ULL;
578 int32 Damage = 0;
579 int32 Healing = 0;
580
583
584 bool IsAlive = false;
585 bool IsCrit = false;
586 bool ScaleAura = false;
587
588 // info set at PreprocessTarget, used by DoTargetSpellHit
590 int32 AuraDuration = 0;
591 SpellInfo const* AuraSpellInfo = nullptr;
592 int32 AuraBasePoints[MAX_SPELL_EFFECTS] = { };
593 bool Positive = true;
594 UnitAura* HitAura = nullptr;
595
596 private:
597 Unit* _spellHitTarget = nullptr; // changed for example by reflect
598 bool _enablePVP = false; // need to enable PVP at DoDamageAndTriggers?
599 };
600 std::vector<TargetInfo> m_UniqueTargetInfo;
601 uint8 m_channelTargetEffectMask; // Mask req. alive targets
602
604 {
605 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
606
608 uint64 TimeDelay = 0ULL;
609 };
610 std::vector<GOTargetInfo> m_UniqueGOTargetInfo;
611
613 {
614 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
615
616 Item* TargetItem = nullptr;
617 };
618 std::vector<ItemTargetInfo> m_UniqueItemInfo;
619
621 {
622 void DoTargetSpellHit(Spell* spell, SpellEffectInfo const& spellEffectInfo) override;
623
625 uint64 TimeDelay = 0ULL;
626 };
627 std::vector<CorpseTargetInfo> m_UniqueCorpseTargetInfo;
628
629 template <class Container>
630 void DoProcessTargetContainer(Container& targetContainer);
631
633
634 void AddUnitTarget(Unit* target, uint32 effectMask, bool checkIfValid = true, bool implicit = true, Position const* losPosition = nullptr);
635 void AddGOTarget(GameObject* target, uint32 effectMask);
636 void AddItemTarget(Item* item, uint32 effectMask);
637 void AddCorpseTarget(Corpse* target, uint32 effectMask);
638 void AddDestTarget(SpellDestination const& dest, uint32 effIndex);
639
640 void PreprocessSpellLaunch(TargetInfo& targetInfo);
641 SpellMissInfo PreprocessSpellHit(Unit* unit, bool scaleAura, TargetInfo& targetInfo);
642 void DoSpellEffectHit(Unit* unit, SpellEffectInfo const& spellEffectInfo, TargetInfo& targetInfo);
643
644 void DoTriggersOnSpellHit(Unit* unit, uint8 effMask);
645 bool UpdateChanneledTargetList();
646 bool IsValidDeadOrAliveTarget(Unit const* target) const;
647 void HandleLaunchPhase();
648 void DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, SpellEffectInfo const& spellEffectInfo);
649
650 void PrepareTargetProcessing();
651 void FinishTargetProcessing();
652
653 // spell execution log
654 void InitEffectExecuteData(uint8 effIndex);
655 void AssertEffectExecuteData() const;
656
657 // Scripting system
658 void LoadScripts();
659 void CallScriptBeforeCastHandlers();
660 void CallScriptOnCastHandlers();
661 void CallScriptAfterCastHandlers();
662 SpellCastResult CallScriptCheckCastHandlers();
663 bool CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode);
664 void CallScriptSuccessfulDispel(SpellEffIndex effIndex);
665 void CallScriptBeforeHitHandlers(SpellMissInfo missInfo);
666 void CallScriptOnHitHandlers();
667 void CallScriptAfterHitHandlers();
668 void CallScriptObjectAreaTargetSelectHandlers(std::list<WorldObject*>& targets, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
669 void CallScriptObjectTargetSelectHandlers(WorldObject*& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
670 void CallScriptDestinationTargetSelectHandlers(SpellDestination& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
671 bool CheckScriptEffectImplicitTargets(uint32 effIndex, uint32 effIndexToCheck);
672 std::vector<SpellScript*> m_loadedScripts;
673
675 {
676 HitTriggerSpell(SpellInfo const* spellInfo, SpellInfo const* auraSpellInfo, int32 procChance) :
677 triggeredSpell(spellInfo), triggeredByAura(auraSpellInfo), chance(procChance) { }
678
681 // uint8 triggeredByEffIdx This might be needed at a later stage - No need known for now
683 };
684
685 bool CanExecuteTriggersOnHit(uint8 effMask, SpellInfo const* triggeredByAura = nullptr) const;
686 void PrepareTriggersExecutedOnHit();
687 typedef std::vector<HitTriggerSpell> HitTriggerSpellList;
689
690 // effect helpers
691 void SummonGuardian(SpellEffectInfo const& spellEffectInfo, uint32 entry, SummonPropertiesEntry const* properties, uint32 numSummons);
692 void CalculateJumpSpeeds(SpellEffectInfo const& spellEffectInfo, float dist, float& speedXY, float& speedZ);
693
694 SpellCastResult CanOpenLock(SpellEffectInfo const& spellEffectInfo, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
695 // -------------------------------------------
696
699
702
703 // if need this can be replaced by Aura copy
704 // we can't store original aura link to prevent access to deleted auras
705 // and in same time need aura data and after aura deleting.
707
709 std::unique_ptr<PathGenerator> m_preGeneratedPath;
710
711 ByteBuffer* m_effectExecuteData[MAX_SPELL_EFFECTS];
712
713 Spell(Spell const& right) = delete;
714 Spell& operator=(Spell const& right) = delete;
715};
716
717namespace Trinity
718{
720 {
721 protected:
726 std::unique_ptr<ConditionSourceInfo> _condSrcInfo;
728
729 WorldObjectSpellTargetCheck(WorldObject* caster, WorldObject* referer, SpellInfo const* spellInfo,
730 SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
732
733 bool operator()(WorldObject* target) const;
734 };
735
737 {
738 float _range;
740 WorldObjectSpellNearbyTargetCheck(float range, WorldObject* caster, SpellInfo const* spellInfo,
741 SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
742
743 bool operator()(WorldObject* target);
744 };
745
747 {
748 float _range;
750 WorldObjectSpellAreaTargetCheck(float range, Position const* position, WorldObject* caster,
751 WorldObject* referer, SpellInfo const* spellInfo, SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
752
753 bool operator()(WorldObject* target) const;
754 };
755
757 {
759 WorldObjectSpellConeTargetCheck(float coneAngle, float range, WorldObject* caster,
760 SpellInfo const* spellInfo, SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
761
762 bool operator()(WorldObject* target) const;
763 };
764
766 {
767 float _range;
769 WorldObjectSpellTrajTargetCheck(float range, Position const* position, WorldObject* caster,
770 SpellInfo const* spellInfo, SpellTargetCheckTypes selectionType, ConditionContainer const* condList);
771
772 bool operator()(WorldObject* target) const;
773 };
774}
775
776using SpellEffectHandlerFn = void(Spell::*)();
777
778#endif
std::vector< Condition * > ConditionContainer
#define MAX_SPELL_EFFECTS
Definition DBCEnums.h:388
#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:81
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:776
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:605
Definition Item.h:62
static ObjectGuid const Empty
Definition ObjectGuid.h:140
Definition Spell.h:152
SpellInfo const * GetSpellInfo() const
Definition Spell.h:452
Unit * m_comboTarget
Definition Spell.h:414
std::vector< HitTriggerSpell > HitTriggerSpellList
Definition Spell.h:687
bool m_fromClient
Definition Spell.h:400
int8 m_comboPointGain
Definition Spell.h:415
std::vector< SpellScript * > m_loadedScripts
Definition Spell.h:672
GameObject * gameObjTarget
Definition Spell.h:525
SpellMissInfo targetMissInfo
Definition Spell.h:529
bool m_referencedFromCurrentSpell
Definition Spell.h:516
bool m_canReflect
Definition Spell.h:496
uint32 m_procVictim
Definition Spell.h:549
uint32 m_hitMask
Definition Spell.h:550
Unit * m_originalCaster
Definition Spell.h:488
DynObjAura * _dynObjAura
Definition Spell.h:535
bool m_needComboPoints
Definition Spell.h:518
uint64 m_delayStart
Definition Spell.h:511
SpellCastTargets m_targets
Definition Spell.h:402
void setState(uint32 state)
Definition Spell.h:357
std::unique_ptr< PathGenerator > m_preGeneratedPath
Definition Spell.h:709
TriggerCastFlags _triggeredCastFlags
Definition Spell.h:701
bool IsAutoRepeat() const
Definition Spell.h:421
int32 damage
Definition Spell.h:528
SpellEffectHandleMode effectHandleMode
Definition Spell.h:530
int32 m_channeledDuration
Definition Spell.h:495
std::vector< TargetInfo > m_UniqueTargetInfo
Definition Spell.h:600
bool IsInterruptable() const
Definition Spell.h:436
void SetExecutedCurrently(bool yes)
Definition Spell.h:437
uint8 m_delayAtDamageCount
Definition Spell.h:500
uint64 m_delayMoment
Definition Spell.h:512
void AddComboPointGain(Unit *target, int8 amount)
Definition Spell.h:404
WeaponAttackType m_attackType
Definition Spell.h:492
bool m_immediateHandled
Definition Spell.h:513
uint32 m_spellState
Definition Spell.h:697
ObjectGuid m_originalCasterGUID
Definition Spell.h:486
WorldObject *const m_caster
Definition Spell.h:482
int32 GetCastTime() const
Definition Spell.h:420
bool IsDeletable() const
Definition Spell.h:434
int32 m_timer
Definition Spell.h:698
int32 m_casttime
Definition Spell.h:494
Item * itemTarget
Definition Spell.h:524
uint8 m_cast_count
Definition Spell.h:399
int32 m_damage
Definition Spell.h:542
std::vector< CorpseTargetInfo > m_UniqueCorpseTargetInfo
Definition Spell.h:627
uint32 getState() const
Definition Spell.h:356
bool m_executedCurrently
Definition Spell.h:517
uint8 m_auraScaleMask
Definition Spell.h:708
std::unordered_set< Aura * > UsedSpellMods
Definition Spell.h:281
SpellCustomErrors m_customError
Definition Spell.h:416
Spell(Spell const &right)=delete
std::vector< GOTargetInfo > m_UniqueGOTargetInfo
Definition Spell.h:610
HitTriggerSpellList m_hitTriggerSpells
Definition Spell.h:688
int32 m_healing
Definition Spell.h:543
void SetDelayStart(uint64 m_time)
Definition Spell.h:439
SpellEffectInfo const * effectInfo
Definition Spell.h:531
uint32 m_glyphIndex
Definition Spell.h:401
SpellInfo const * m_triggeredByAuraSpell
Definition Spell.h:706
uint8 m_channelTargetEffectMask
Definition Spell.h:601
UnitAura * _spellAura
Definition Spell.h:534
Unit * unitTarget
Definition Spell.h:523
SpellSchoolMask m_spellSchoolMask
Definition Spell.h:491
WorldObject * GetCaster() const
Definition Spell.h:450
SpellEvent * _spellEvent
Definition Spell.h:700
Unit * GetOriginalCaster() const
Definition Spell.h:451
Corpse * m_corpseTarget
Definition Spell.h:526
void ReSetTimer()
Definition Spell.h:423
void SetAutoRepeat(bool rep)
Definition Spell.h:422
WorldLocation * destTarget
Definition Spell.h:527
Spell ** m_selfContainer
Definition Spell.h:461
uint8 m_applyMultiplierMask
Definition Spell.h:519
bool IsTriggeredByAura(SpellInfo const *auraSpellInfo) const
Definition Spell.h:432
void SetReferencedFromCurrent(bool yes)
Definition Spell.h:435
bool IsDelayableNoMore()
Definition Spell.h:501
int32 GetPowerCost() const
Definition Spell.h:453
uint64 GetDelayStart() const
Definition Spell.h:438
void SetRuneState(uint8 value)
Definition Spell.h:444
Item * m_CastItem
Definition Spell.h:396
uint32 m_castItemEntry
Definition Spell.h:398
uint64 GetDelayMoment() const
Definition Spell.h:440
UsedSpellMods m_appliedMods
Definition Spell.h:418
ObjectGuid m_focusObjectGUID
Definition Spell.h:538
SpellValue *const m_spellValue
Definition Spell.h:484
int32 m_powerCost
Definition Spell.h:493
uint8 GetRuneState() const
Definition Spell.h:443
std::vector< ItemTargetInfo > m_UniqueItemInfo
Definition Spell.h:618
ObjectGuid m_castItemGUID
Definition Spell.h:397
uint32 m_procAttacker
Definition Spell.h:548
GameObject * focusObject
Definition Spell.h:539
Spell & operator=(Spell const &right)=delete
SpellInfo const *const m_spellInfo
Definition Spell.h:395
uint8 m_runesState
Definition Spell.h:498
bool m_autoRepeat
Definition Spell.h:497
Trinity::unique_trackable_ptr companion class, replicating what std::weak_ptr is to std::shared_ptr.
Definition Unit.h:769
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:624
ObjectGuid TargetGUID
Definition Spell.h:607
SpellInfo const * triggeredSpell
Definition Spell.h:679
HitTriggerSpell(SpellInfo const *spellInfo, SpellInfo const *auraSpellInfo, int32 procChance)
Definition Spell.h:676
SpellInfo const * triggeredByAura
Definition Spell.h:680
virtual void DoTargetSpellHit(Spell *spell, SpellEffectInfo const &spellEffectInfo)=0
virtual void PreprocessTarget(Spell *)
Definition Spell.h:559
virtual ~TargetInfoBase()
Definition Spell.h:567
virtual void DoDamageAndTriggers(Spell *)
Definition Spell.h:561
ObjectGuid TargetGUID
Definition Spell.h:576
SpellTargetCheckTypes _targetSelectionType
Definition Spell.h:725
std::unique_ptr< ConditionSourceInfo > _condSrcInfo
Definition Spell.h:726
ConditionContainer const * _condList
Definition Spell.h:727
int finish(char const *message, int returnValue)