Minor cuff changes (#4164)

This commit is contained in:
metalgearsloth
2021-06-17 00:37:05 +10:00
committed by GitHub
parent 40b86903b3
commit 7cbfbad578
6 changed files with 52 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Client.Cuffs.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedCuffableComponent))]
public class CuffableComponent : SharedCuffableComponent
{
[ViewVariables]

View File

@@ -14,7 +14,7 @@ namespace Content.Server.Alert.Click
{
public void AlertClicked(ClickAlertEventArgs args)
{
args.Player.GetComponentOrNull<SharedPullableComponent>()?.TryStopPull();
args.Player.GetComponentOrNull<SharedPullableComponent>()?.TryStopPull(args.Player);
}
}
}

View File

@@ -26,6 +26,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Cuffs.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedCuffableComponent))]
public class CuffableComponent : SharedCuffableComponent
{
/// <summary>
@@ -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<AudioSystem>();
if (isOwner)
{
if (cuff.StartBreakoutSound != null)

View File

@@ -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()
{

View File

@@ -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<SharedCuffableComponent, StopPullingEvent>(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();
}
}
}
}

View File

@@ -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;
}
}
/// <summary>
/// Raised when a request is made to stop pulling an entity.
/// </summary>
public sealed class StopPullingEvent : CancellableEntityEventArgs
{
public EntityUid? User { get; }
public StopPullingEvent(EntityUid? uid = null)
{
User = uid;
}
}
}