From 5212fc54780ab798f937b54eddcf75720135bf67 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:19:56 -0400 Subject: [PATCH] No unbuckling while cuffed (#17719) --- .../Buckle/Components/BuckleComponent.cs | 2 +- .../Buckle/SharedBuckleSystem.Buckle.cs | 25 ++++++++++--------- Content.Shared/Cuffs/SharedCuffableSystem.cs | 20 ++++++++++++++- .../cuffs/components/handcuff-component.ftl | 2 ++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Content.Shared/Buckle/Components/BuckleComponent.cs b/Content.Shared/Buckle/Components/BuckleComponent.cs index 8b5d092e29..59fab36285 100644 --- a/Content.Shared/Buckle/Components/BuckleComponent.cs +++ b/Content.Shared/Buckle/Components/BuckleComponent.cs @@ -94,7 +94,7 @@ public sealed class BuckleComponentState : ComponentState } [ByRefEvent] -public record struct BuckleAttemptEvent(EntityUid StrapEntity, EntityUid BuckledEntity, bool Buckling, bool Cancelled = false); +public record struct BuckleAttemptEvent(EntityUid StrapEntity, EntityUid BuckledEntity, EntityUid UserEntity, bool Buckling, bool Cancelled = false); [ByRefEvent] public readonly record struct BuckleChangeEvent(EntityUid StrapEntity, EntityUid BuckledEntity, bool Buckling); diff --git a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs index 8a06ce55c1..d9c1e76b9c 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs @@ -11,6 +11,7 @@ using Content.Shared.Mobs.Components; using Content.Shared.Movement.Events; using Content.Shared.Popups; using Content.Shared.Pulling.Components; +using Content.Shared.Pulling.Events; using Content.Shared.Standing; using Content.Shared.Storage.Components; using Content.Shared.Stunnable; @@ -312,6 +313,12 @@ public abstract partial class SharedBuckleSystem return false; } + var attemptEvent = new BuckleAttemptEvent(strapUid, buckleUid, userUid, true); + RaiseLocalEvent(attemptEvent.BuckledEntity, ref attemptEvent); + RaiseLocalEvent(attemptEvent.StrapEntity, ref attemptEvent); + if (attemptEvent.Cancelled) + return false; + return true; } @@ -333,12 +340,6 @@ public abstract partial class SharedBuckleSystem if (!CanBuckle(buckleUid, userUid, strapUid, out var strapComp, buckleComp)) return false; - var attemptEvent = new BuckleAttemptEvent(strapUid, buckleUid, true); - RaiseLocalEvent(attemptEvent.BuckledEntity, ref attemptEvent); - RaiseLocalEvent(attemptEvent.StrapEntity, ref attemptEvent); - if (attemptEvent.Cancelled) - return false; - if (!StrapTryAdd(strapUid, buckleUid, buckleComp, false, strapComp)) { var message = Loc.GetString(buckleUid == userUid @@ -407,14 +408,14 @@ public abstract partial class SharedBuckleSystem buckleComp.BuckledTo is not { } strapUid) return false; - var attemptEvent = new BuckleAttemptEvent(strapUid, buckleUid, false); - RaiseLocalEvent(attemptEvent.BuckledEntity, ref attemptEvent); - RaiseLocalEvent(attemptEvent.StrapEntity, ref attemptEvent); - if (attemptEvent.Cancelled) - return false; - if (!force) { + var attemptEvent = new BuckleAttemptEvent(strapUid, buckleUid, userUid, false); + RaiseLocalEvent(attemptEvent.BuckledEntity, ref attemptEvent); + RaiseLocalEvent(attemptEvent.StrapEntity, ref attemptEvent); + if (attemptEvent.Cancelled) + return false; + if (_gameTiming.CurTime < buckleComp.BuckleTime + buckleComp.UnbuckleDelay) return false; diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index d037f063fe..64f9b7c6e3 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -3,6 +3,7 @@ using Content.Shared.ActionBlocker; using Content.Shared.Administration.Components; using Content.Shared.Administration.Logs; using Content.Shared.Alert; +using Content.Shared.Buckle.Components; using Content.Shared.Cuffs.Components; using Content.Shared.Database; using Content.Shared.DoAfter; @@ -66,6 +67,7 @@ namespace Content.Shared.Cuffs SubscribeLocalEvent(OnEquipAttempt); SubscribeLocalEvent(OnUnequipAttempt); SubscribeLocalEvent(OnBeingPulledAttempt); + SubscribeLocalEvent(OnBuckleAttemptEvent); SubscribeLocalEvent>(AddUncuffVerb); SubscribeLocalEvent(OnCuffableDoAfter); SubscribeLocalEvent(OnPull); @@ -79,7 +81,6 @@ namespace Content.Shared.Cuffs SubscribeLocalEvent(OnCuffAfterInteract); SubscribeLocalEvent(OnCuffMeleeHit); SubscribeLocalEvent(OnAddCuffDoAfter); - } private void OnUncuffAttempt(ref UncuffAttemptEvent args) @@ -178,6 +179,23 @@ namespace Content.Shared.Cuffs args.Cancel(); } + private void OnBuckleAttemptEvent(EntityUid uid, CuffableComponent component, ref BuckleAttemptEvent args) + { + // if someone else is doing it, let it pass. + if (args.UserEntity != uid) + return; + + if (!TryComp(uid, out var hands) || component.CuffedHandCount != hands.Count) + return; + + args.Cancelled = true; + var message = args.Buckling + ? Loc.GetString("handcuff-component-cuff-interrupt-buckled-message") + : Loc.GetString("handcuff-component-cuff-interrupt-unbuckled-message"); + if (_net.IsServer) + _popup.PopupEntity(message, uid, args.UserEntity); + } + private void OnPull(EntityUid uid, CuffableComponent component, PullMessage args) { if (!component.CanStillInteract) diff --git a/Resources/Locale/en-US/cuffs/components/handcuff-component.ftl b/Resources/Locale/en-US/cuffs/components/handcuff-component.ftl index 8c024f7943..4d74143d50 100644 --- a/Resources/Locale/en-US/cuffs/components/handcuff-component.ftl +++ b/Resources/Locale/en-US/cuffs/components/handcuff-component.ftl @@ -13,3 +13,5 @@ handcuff-component-cuff-self-success-message = You cuff yourself. handcuff-component-cuff-interrupt-message = You were interrupted while cuffing {$targetName}! handcuff-component-cuff-interrupt-other-message = You interrupt {$otherName} while they are cuffing you! handcuff-component-cuff-interrupt-self-message = You were interrupted while cuffing yourself. +handcuff-component-cuff-interrupt-buckled-message = You can't buckle while cuffed! +handcuff-component-cuff-interrupt-unbuckled-message = You can't unbuckle while cuffed!