From ea35c2ca6250377d574488622310b686752c12cd Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 15 Aug 2019 23:05:26 -0400 Subject: [PATCH] Core/Spells: Fixed spell effect 93 (SPELL_EFFECT_FORCE_DESELECT) Port From (https://github.com/TrinityCore/TrinityCore/commit/92e95ddf558db5fdcdf3c54ecd1d694da92c3a44) --- Source/Game/Maps/GridNotifiers.cs | 87 ++++++++++++++++++++++++++++++ Source/Game/Spells/SpellEffects.cs | 21 +++++++- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 007bb37b9..a1b839244 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -468,6 +468,93 @@ namespace Game.Maps Player skipped_receiver; } + public class MessageDistDelivererToHostile : Notifier + { + Unit i_source; + ServerPacket i_message; + float i_distSq; + + public MessageDistDelivererToHostile(Unit src, ServerPacket msg, float dist) + { + i_source = src; + i_message = msg; + i_distSq = dist * dist; + } + + public override void Visit(IList objs) + { + foreach (var target in objs) + { + if (!target.IsInPhase(i_source)) + continue; + + if (target.GetExactDist2dSq(i_source) > i_distSq) + continue; + + // Send packet to all who are sharing the player's vision + if (target.HasSharedVision()) + { + foreach (var player in target.GetSharedVisionList()) + if (player.seerView == target) + SendPacket(player); + } + + if (target.seerView == target || target.GetVehicle()) + SendPacket(target); + } + } + + public override void Visit(IList objs) + { + foreach (var target in objs) + { + if (!target.IsInPhase(i_source)) + continue; + + if (target.GetExactDist2dSq(i_source) > i_distSq) + continue; + + // Send packet to all who are sharing the creature's vision + if (target.HasSharedVision()) + { + foreach (var player in target.GetSharedVisionList()) + if (player.seerView == target) + SendPacket(player); + } + } + } + + public override void Visit(IList objs) + { + foreach (var target in objs) + { + if (!target.IsInPhase(i_source)) + continue; + + if (target.GetExactDist2dSq(i_source) > i_distSq) + continue; + + Unit caster = target.GetCaster(); + if (caster != null) + { + // Send packet back to the caster if the caster has vision of dynamic object + Player player = caster.ToPlayer(); + if (player && player.seerView == target) + SendPacket(player); + } + } + } + + void SendPacket(Player player) + { + // never send packet to self + if (player == i_source || !player.HaveAtClient(i_source) || player.IsFriendlyTo(i_source)) + return; + + player.SendPacket(i_message); + } + } + public class UpdaterNotifier : Notifier { public UpdaterNotifier(uint diff) diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 243a998c7..1340d9a70 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -4010,9 +4010,28 @@ namespace Game.Spells if (effectHandleMode != SpellEffectHandleMode.Hit) return; + float dist = m_caster.GetVisibilityRange(); + + // clear focus + BreakTarget breakTarget = new BreakTarget(); + breakTarget.UnitGUID = m_caster.GetGUID(); + MessageDistDelivererToHostile notifierBreak = new MessageDistDelivererToHostile(m_caster, breakTarget, dist); + Cell.VisitWorldObjects(m_caster, notifierBreak, dist); + + // and selection ClearTarget clearTarget = new ClearTarget(); clearTarget.Guid = m_caster.GetGUID(); - m_caster.SendMessageToSet(clearTarget, true); + MessageDistDelivererToHostile notifierClear = new MessageDistDelivererToHostile(m_caster, clearTarget, dist); + Cell.VisitWorldObjects(m_caster, notifierClear, dist); + + // we should also force pets to remove us from current target + List attackerSet = new List(); + foreach (var unit in m_caster.getAttackers()) + if (unit.GetTypeId() == TypeId.Unit && !unit.CanHaveThreatList()) + attackerSet.Add(unit); + + foreach (var unit in attackerSet) + unit.AttackStop(); } [SpellEffectHandler(SpellEffectName.SelfResurrect)]