From 46195bd8b762be3990297642c22e0c9285a2d14a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 13 Oct 2021 10:07:09 -0400 Subject: [PATCH] Core/Spells: Implemented SPELL_EFFECT_TELEPORT_WITH_SPELL_VISUAL_KIT_LOADING_SCREEN Port From (https://github.com/TrinityCore/TrinityCore/commit/49eb3cf8fea8e5eab0c102c2bfb27fad763ba07e) --- .../Game/Networking/Packets/SpellPackets.cs | 18 +++++ Source/Game/Spells/Spell.cs | 2 +- Source/Game/Spells/SpellEffects.cs | 67 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/Source/Game/Networking/Packets/SpellPackets.cs b/Source/Game/Networking/Packets/SpellPackets.cs index 52777fa3a..5c742ec01 100644 --- a/Source/Game/Networking/Packets/SpellPackets.cs +++ b/Source/Game/Networking/Packets/SpellPackets.cs @@ -778,6 +778,24 @@ namespace Game.Networking.Packets public bool MountedVisual; } + class SpellVisualLoadScreen : ServerPacket + { + public int SpellVisualKitID; + public int Delay; + + public SpellVisualLoadScreen(int spellVisualKitId, int delay) : base(ServerOpcodes.SpellVisualLoadScreen, ConnectionType.Instance) + { + SpellVisualKitID = spellVisualKitId; + Delay = delay; + } + + public override void Write() + { + _worldPacket.WriteInt32(SpellVisualKitID); + _worldPacket.WriteInt32(Delay); + } + } + public class CancelCast : ClientPacket { public CancelCast(WorldPacket packet) : base(packet) { } diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 2a48ba6ee..9992492dc 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -827,7 +827,7 @@ namespace Game.Spells if (st != null) { // @todo fix this check - if (m_spellInfo.HasEffect(SpellEffectName.TeleportUnits) || m_spellInfo.HasEffect(SpellEffectName.Bind)) + if (m_spellInfo.HasEffect(SpellEffectName.TeleportUnits) || m_spellInfo.HasEffect(SpellEffectName.TeleportWithSpellVisualKitLoadingScreen) || m_spellInfo.HasEffect(SpellEffectName.Bind)) dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation, st.target_mapId); else if (st.target_mapId == m_caster.GetMapId()) dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation); diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index b92aab8ae..02aa09d18 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -16,6 +16,7 @@ */ using Framework.Constants; +using Framework.Dynamic; using Framework.GameMath; using Game.BattleGrounds; using Game.BattlePets; @@ -712,6 +713,40 @@ namespace Game.Spells } } + [SpellEffectHandler(SpellEffectName.TeleportWithSpellVisualKitLoadingScreen)] + void EffectTeleportUnitsWithVisualLoadingScreen() + { + if (effectHandleMode != SpellEffectHandleMode.HitTarget) + return; + + if (!unitTarget) + return; + + // If not exist data for dest location - return + if (!m_targets.HasDst()) + { + Log.outError(LogFilter.Spells, $"Spell::EffectTeleportUnitsWithVisualLoadingScreen - does not have a destination for spellId {m_spellInfo.Id}."); + return; + } + + // Init dest coordinates + WorldLocation targetDest = new WorldLocation(destTarget); + if (targetDest.GetMapId() == 0xFFFFFFFF) + targetDest.SetMapId(unitTarget.GetMapId()); + + if (targetDest.GetOrientation() == 0 && m_targets.GetUnitTarget()) + targetDest.SetOrientation(m_targets.GetUnitTarget().GetOrientation()); + + if (effectInfo.MiscValueB != 0) + { + Player playerTarget = unitTarget.ToPlayer(); + if (playerTarget != null) + playerTarget.SendPacket(new SpellVisualLoadScreen(effectInfo.MiscValueB, effectInfo.MiscValue)); + } + + unitTarget.m_Events.AddEventAtOffset(new DelayedSpellTeleportEvent(unitTarget, targetDest, unitTarget == m_caster ? TeleportToOptions.Spell : 0, m_spellInfo.Id), TimeSpan.FromMilliseconds(effectInfo.MiscValue)); + } + [SpellEffectHandler(SpellEffectName.ApplyAura)] [SpellEffectHandler(SpellEffectName.ApplyAuraOnPet)] void EffectApplyAura() @@ -5814,4 +5849,36 @@ namespace Game.Spells int _chance; byte _charges; } + + class DelayedSpellTeleportEvent : BasicEvent + { + Unit _target; + WorldLocation _targetDest; + TeleportToOptions _options; + uint _spellId; + + public DelayedSpellTeleportEvent(Unit target, WorldLocation targetDest, TeleportToOptions options, uint spellId) + { + _target = target; + _targetDest = targetDest; + _options = options; + _spellId = spellId; + } + + public override bool Execute(ulong e_time, uint p_time) + { + if (_targetDest.GetMapId() == _target.GetMapId()) + _target.NearTeleportTo(_targetDest, (_options & TeleportToOptions.Spell) != 0); + else + { + Player player = _target.ToPlayer(); + if (player != null) + player.TeleportTo(_targetDest, _options); + else + Log.outError(LogFilter.Spells, $"Spell::EffectTeleportUnitsWithVisualLoadingScreen - spellId {_spellId} attempted to teleport creature to a different map."); + } + + return true; + } + } } \ No newline at end of file