No unbuckling while cuffed (#17719)

This commit is contained in:
Nemanja
2023-06-28 23:19:56 -04:00
committed by GitHub
parent e2823d8006
commit 5212fc5478
4 changed files with 35 additions and 14 deletions

View File

@@ -94,7 +94,7 @@ public sealed class BuckleComponentState : ComponentState
} }
[ByRefEvent] [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] [ByRefEvent]
public readonly record struct BuckleChangeEvent(EntityUid StrapEntity, EntityUid BuckledEntity, bool Buckling); public readonly record struct BuckleChangeEvent(EntityUid StrapEntity, EntityUid BuckledEntity, bool Buckling);

View File

@@ -11,6 +11,7 @@ using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Events; using Content.Shared.Movement.Events;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Pulling.Components; using Content.Shared.Pulling.Components;
using Content.Shared.Pulling.Events;
using Content.Shared.Standing; using Content.Shared.Standing;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
@@ -312,6 +313,12 @@ public abstract partial class SharedBuckleSystem
return false; 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; return true;
} }
@@ -333,12 +340,6 @@ public abstract partial class SharedBuckleSystem
if (!CanBuckle(buckleUid, userUid, strapUid, out var strapComp, buckleComp)) if (!CanBuckle(buckleUid, userUid, strapUid, out var strapComp, buckleComp))
return false; 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)) if (!StrapTryAdd(strapUid, buckleUid, buckleComp, false, strapComp))
{ {
var message = Loc.GetString(buckleUid == userUid var message = Loc.GetString(buckleUid == userUid
@@ -407,14 +408,14 @@ public abstract partial class SharedBuckleSystem
buckleComp.BuckledTo is not { } strapUid) buckleComp.BuckledTo is not { } strapUid)
return false; 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) 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) if (_gameTiming.CurTime < buckleComp.BuckleTime + buckleComp.UnbuckleDelay)
return false; return false;

View File

@@ -3,6 +3,7 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Components; using Content.Shared.Administration.Components;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.Buckle.Components;
using Content.Shared.Cuffs.Components; using Content.Shared.Cuffs.Components;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.DoAfter; using Content.Shared.DoAfter;
@@ -66,6 +67,7 @@ namespace Content.Shared.Cuffs
SubscribeLocalEvent<CuffableComponent, IsEquippingAttemptEvent>(OnEquipAttempt); SubscribeLocalEvent<CuffableComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<CuffableComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt); SubscribeLocalEvent<CuffableComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
SubscribeLocalEvent<CuffableComponent, BeingPulledAttemptEvent>(OnBeingPulledAttempt); SubscribeLocalEvent<CuffableComponent, BeingPulledAttemptEvent>(OnBeingPulledAttempt);
SubscribeLocalEvent<CuffableComponent, BuckleAttemptEvent>(OnBuckleAttemptEvent);
SubscribeLocalEvent<CuffableComponent, GetVerbsEvent<Verb>>(AddUncuffVerb); SubscribeLocalEvent<CuffableComponent, GetVerbsEvent<Verb>>(AddUncuffVerb);
SubscribeLocalEvent<CuffableComponent, UnCuffDoAfterEvent>(OnCuffableDoAfter); SubscribeLocalEvent<CuffableComponent, UnCuffDoAfterEvent>(OnCuffableDoAfter);
SubscribeLocalEvent<CuffableComponent, PullStartedMessage>(OnPull); SubscribeLocalEvent<CuffableComponent, PullStartedMessage>(OnPull);
@@ -79,7 +81,6 @@ namespace Content.Shared.Cuffs
SubscribeLocalEvent<HandcuffComponent, AfterInteractEvent>(OnCuffAfterInteract); SubscribeLocalEvent<HandcuffComponent, AfterInteractEvent>(OnCuffAfterInteract);
SubscribeLocalEvent<HandcuffComponent, MeleeHitEvent>(OnCuffMeleeHit); SubscribeLocalEvent<HandcuffComponent, MeleeHitEvent>(OnCuffMeleeHit);
SubscribeLocalEvent<HandcuffComponent, AddCuffDoAfterEvent>(OnAddCuffDoAfter); SubscribeLocalEvent<HandcuffComponent, AddCuffDoAfterEvent>(OnAddCuffDoAfter);
} }
private void OnUncuffAttempt(ref UncuffAttemptEvent args) private void OnUncuffAttempt(ref UncuffAttemptEvent args)
@@ -178,6 +179,23 @@ namespace Content.Shared.Cuffs
args.Cancel(); 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<HandsComponent>(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) private void OnPull(EntityUid uid, CuffableComponent component, PullMessage args)
{ {
if (!component.CanStillInteract) if (!component.CanStillInteract)

View File

@@ -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-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-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-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!