From 0344077d231fa46d0e706e534db0e7f63d41b050 Mon Sep 17 00:00:00 2001 From: killerwife Date: Sun, 17 Dec 2023 14:01:02 +0100 Subject: [PATCH] Spell: Add dyngo fake caster support Caster is dyngo, caster unit is dyngo owner in spell packet --- src/game/Spells/Scripts/SpellScript.h | 5 +++-- src/game/Spells/Spell.cpp | 2 +- src/game/Spells/Spell.h | 2 +- src/game/Spells/SpellAuras.cpp | 8 +++++--- src/game/Spells/SpellMgr.cpp | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/game/Spells/Scripts/SpellScript.h b/src/game/Spells/Scripts/SpellScript.h index fa79f55bfa..64678552f2 100644 --- a/src/game/Spells/Scripts/SpellScript.h +++ b/src/game/Spells/Scripts/SpellScript.h @@ -28,11 +28,12 @@ class DynamicObject; struct PeriodicTriggerData { + WorldObject* trueCaster; Unit* caster; Unit* target; WorldObject* targetObject; SpellEntry const* spellInfo; int32* basePoints; - PeriodicTriggerData(Unit* caster, Unit* target, WorldObject* targetObject, SpellEntry const* spellInfo, int32* basePoints) : - caster(caster), target(target), targetObject(targetObject), spellInfo(spellInfo), basePoints(basePoints) {} + PeriodicTriggerData(WorldObject* trueCaster, Unit* caster, Unit* target, WorldObject* targetObject, SpellEntry const* spellInfo, int32* basePoints) : + trueCaster(nullptr), caster(caster), target(target), targetObject(targetObject), spellInfo(spellInfo), basePoints(basePoints) {} }; struct SpellScript diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index d2bd69839e..adb23f67e2 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -3101,7 +3101,7 @@ SpellCastResult Spell::SpellStart(SpellCastTargets const* targets, Aura* trigger SpellEvent* Event = new SpellEvent(this); m_trueCaster->m_events.AddEvent(Event, m_trueCaster->m_events.CalculateTime(1)); - if (!m_trueCaster->IsGameObject()) // gameobjects dont have a sense of already casting a spell + if (m_trueCaster->IsUnit()) // gameobjects dont have a sense of already casting a spell { // Prevent casting at cast another spell (ServerSide check) if (m_caster->IsNonMeleeSpellCasted(false, true, true) && m_cast_count && !m_ignoreConcurrentCasts) diff --git a/src/game/Spells/Spell.h b/src/game/Spells/Spell.h index 21869691f3..7eaf704658 100644 --- a/src/game/Spells/Spell.h +++ b/src/game/Spells/Spell.h @@ -798,7 +798,7 @@ class Spell void SetEventTarget(WorldObject* object) { m_eventTarget = object; } // GO casting preparations - void SetFakeCaster(Unit* caster) { m_caster = caster; } + void SetFakeCaster(Unit* caster) { m_caster = caster; } // also used by dyngo caster emulation WorldObject* GetTrueCaster() const { return m_trueCaster; } Unit* GetAffectiveCasterOrOwner() const; diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index 87bc0b673e..bdb5e687ad 100755 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -1025,9 +1025,11 @@ void Aura::PickTargetsForSpellTrigger(Unit*& triggerCaster, Unit*& triggerTarget void Aura::CastTriggeredSpell(PeriodicTriggerData& data) { - Spell* spell = new Spell(data.caster, data.spellInfo, TRIGGERED_OLD_TRIGGERED, data.caster->GetObjectGuid(), GetSpellProto()); + Spell* spell = new Spell(data.trueCaster ? data.trueCaster : data.caster, data.spellInfo, TRIGGERED_OLD_TRIGGERED, data.trueCaster ? data.trueCaster->GetObjectGuid() : data.caster->GetObjectGuid(), GetSpellProto()); if (data.spellInfo->HasAttribute(SPELL_ATTR_EX2_RETAIN_ITEM_CAST)) // forward guid to at least spell go spell->SetForwardedCastItem(GetCastItemGuid()); + if (data.trueCaster && data.caster) + spell->SetFakeCaster(data.caster); SpellCastTargets targets; if (data.spellInfo->Targets & TARGET_FLAG_DEST_LOCATION) { @@ -2023,7 +2025,7 @@ void Aura::TriggerSpell() } } int32 basePoints[] = { 0,0,0 }; - PeriodicTriggerData data(triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints); + PeriodicTriggerData data(nullptr, triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints); OnPeriodicTrigger(data); // All ok cast by default case @@ -2070,7 +2072,7 @@ void Aura::TriggerSpellWithValue() WorldObject* triggerTargetObject = nullptr; PickTargetsForSpellTrigger(triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo); - PeriodicTriggerData data(triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints); + PeriodicTriggerData data(nullptr, triggerCaster, triggerTarget, triggerTargetObject, triggeredSpellInfo, basePoints); OnPeriodicTrigger(data); if (data.spellInfo) diff --git a/src/game/Spells/SpellMgr.cpp b/src/game/Spells/SpellMgr.cpp index 6df45d56b2..00090a5cde 100644 --- a/src/game/Spells/SpellMgr.cpp +++ b/src/game/Spells/SpellMgr.cpp @@ -147,7 +147,7 @@ uint32 GetSpellCastTime(SpellEntry const* spellInfo, WorldObject* caster, Spell* if (!spellCastTimeEntry) return 0; - int32 spellRank = caster && caster->GetTypeId() != TYPEID_GAMEOBJECT ? static_cast(caster)->GetSpellRank(spellInfo) : 0; + int32 spellRank = caster && caster->IsUnit() ? static_cast(caster)->GetSpellRank(spellInfo) : 0; int32 castTime = spellCastTimeEntry->CastTime + spellCastTimeEntry->CastTimePerLevel * (spellRank / 5 - spellInfo->baseLevel); castTime = std::max(castTime, spellCastTimeEntry->MinCastTime);