diff --git a/Content.Client/Cuffs/Components/CuffableComponent.cs b/Content.Client/Cuffs/Components/CuffableComponent.cs index df292084f6..2583946354 100644 --- a/Content.Client/Cuffs/Components/CuffableComponent.cs +++ b/Content.Client/Cuffs/Components/CuffableComponent.cs @@ -9,6 +9,7 @@ using Robust.Shared.ViewVariables; namespace Content.Client.Cuffs.Components { [RegisterComponent] + [ComponentReference(typeof(SharedCuffableComponent))] public class CuffableComponent : SharedCuffableComponent { [ViewVariables] diff --git a/Content.Server/Alert/Click/StopBeingPulled.cs b/Content.Server/Alert/Click/StopBeingPulled.cs index f1c16a95a6..11ae93117d 100644 --- a/Content.Server/Alert/Click/StopBeingPulled.cs +++ b/Content.Server/Alert/Click/StopBeingPulled.cs @@ -14,7 +14,7 @@ namespace Content.Server.Alert.Click { public void AlertClicked(ClickAlertEventArgs args) { - args.Player.GetComponentOrNull()?.TryStopPull(); + args.Player.GetComponentOrNull()?.TryStopPull(args.Player); } } } diff --git a/Content.Server/Cuffs/Components/CuffableComponent.cs b/Content.Server/Cuffs/Components/CuffableComponent.cs index 3112dcb9b9..15d187f1d8 100644 --- a/Content.Server/Cuffs/Components/CuffableComponent.cs +++ b/Content.Server/Cuffs/Components/CuffableComponent.cs @@ -26,6 +26,7 @@ using Robust.Shared.ViewVariables; namespace Content.Server.Cuffs.Components { [RegisterComponent] + [ComponentReference(typeof(SharedCuffableComponent))] public class CuffableComponent : SharedCuffableComponent { /// @@ -207,7 +208,8 @@ namespace Content.Server.Cuffs.Components return; } - if (!ActionBlockerSystem.CanInteract(user)) + // TODO: Make into an event and instead have a system check for owner. + if (!isOwner && !ActionBlockerSystem.CanInteract(user)) { user.PopupMessage(Loc.GetString("You can't do that!")); return; @@ -219,6 +221,7 @@ namespace Content.Server.Cuffs.Components return; } + // TODO: Why are we even doing this check? if (!cuffsToRemove.InRangeUnobstructed(Owner)) { Logger.Warning("Handcuffs being removed from player are obstructed or too far away! This should not happen!"); @@ -227,7 +230,6 @@ namespace Content.Server.Cuffs.Components user.PopupMessage(Loc.GetString("You start removing the cuffs.")); - var audio = EntitySystem.Get(); if (isOwner) { if (cuff.StartBreakoutSound != null) diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index ceaab04074..c05f7e21f2 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -1,13 +1,14 @@ #nullable enable using Content.Server.Cuffs.Components; using Content.Server.Hands.Components; +using Content.Shared.Cuffs; using JetBrains.Annotations; using Robust.Shared.GameObjects; namespace Content.Server.Cuffs { [UsedImplicitly] - public class CuffableSystem : EntitySystem + internal sealed class CuffableSystem : SharedCuffableSystem { public override void Initialize() { diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs new file mode 100644 index 0000000000..9877c4659c --- /dev/null +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -0,0 +1,25 @@ +using Content.Shared.Cuffs.Components; +using Content.Shared.Pulling.Components; +using Robust.Shared.GameObjects; + +namespace Content.Shared.Cuffs +{ + public abstract class SharedCuffableSystem : EntitySystem + { + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(HandleStopPull); + } + + private void HandleStopPull(EntityUid uid, SharedCuffableComponent component, StopPullingEvent args) + { + if (args.User == null || !EntityManager.TryGetEntity(args.User.Value, out var user)) return; + + if (user == component.Owner && !component.CanStillInteract) + { + args.Cancel(); + } + } + } +} diff --git a/Content.Shared/Pulling/Components/SharedPullableComponent.cs b/Content.Shared/Pulling/Components/SharedPullableComponent.cs index f966c16942..988b67b8f8 100644 --- a/Content.Shared/Pulling/Components/SharedPullableComponent.cs +++ b/Content.Shared/Pulling/Components/SharedPullableComponent.cs @@ -245,13 +245,18 @@ namespace Content.Shared.Pulling.Components return true; } - public bool TryStopPull() + public bool TryStopPull(IEntity? user = null) { if (!BeingPulled) { return false; } + var msg = new StopPullingEvent(user?.Uid); + Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, msg); + + if (msg.Cancelled) return false; + if (_physics != null && _pullJoint != null) { _physics.RemoveJoint(_pullJoint); @@ -375,4 +380,17 @@ namespace Content.Shared.Pulling.Components Puller = puller; } } + + /// + /// Raised when a request is made to stop pulling an entity. + /// + public sealed class StopPullingEvent : CancellableEntityEventArgs + { + public EntityUid? User { get; } + + public StopPullingEvent(EntityUid? uid = null) + { + User = uid; + } + } }