diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs index b3f9c0d1c0..a6798aabb2 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Shared.ActionBlocker; using Content.Shared.Administration.Logs; using Content.Shared.Buckle.Components; @@ -26,6 +27,7 @@ namespace Content.Shared.Pulling [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly SharedJointSystem _jointSystem = default!; // WD public bool CanPull(EntityUid puller, EntityUid pulled) { @@ -98,6 +100,7 @@ namespace Content.Shared.Pulling if (!pullable.BeingPulled) { + ClearPullJoints(pullable); // WD return false; } @@ -117,6 +120,31 @@ namespace Content.Shared.Pulling return true; } + + // WD START + private void ClearPullJoints(SharedPullableComponent pullable) + { + var uid = pullable.Owner; + + if (_timing.ApplyingState || !TryComp(uid, out JointComponent? jointComp)) + return; + + TryComp(uid, out SharedPullerComponent? puller); + + foreach (var joint in jointComp.GetJoints.Where(j => j.Key.StartsWith("pull-joint"))) + { + if (pullable.PullJointId == joint.Key) + continue; + + if (puller is {Pulling: not null} && + EntityManager.GetComponent(puller.Pulling.Value).PullJointId == joint.Key) + continue; + + _jointSystem.RemoveJoint(joint.Value); + } + } + // WD END + public bool TryStartPull(EntityUid puller, EntityUid pullable) { if (!EntityManager.TryGetComponent(puller, out SharedPullerComponent? pullerComp))