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 namespace Content.Client.Cuffs.Components
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedCuffableComponent))]
public class CuffableComponent : SharedCuffableComponent public class CuffableComponent : SharedCuffableComponent
{ {
[ViewVariables] [ViewVariables]

View File

@@ -14,7 +14,7 @@ namespace Content.Server.Alert.Click
{ {
public void AlertClicked(ClickAlertEventArgs args) 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 namespace Content.Server.Cuffs.Components
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedCuffableComponent))]
public class CuffableComponent : SharedCuffableComponent public class CuffableComponent : SharedCuffableComponent
{ {
/// <summary> /// <summary>
@@ -207,7 +208,8 @@ namespace Content.Server.Cuffs.Components
return; 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!")); user.PopupMessage(Loc.GetString("You can't do that!"));
return; return;
@@ -219,6 +221,7 @@ namespace Content.Server.Cuffs.Components
return; return;
} }
// TODO: Why are we even doing this check?
if (!cuffsToRemove.InRangeUnobstructed(Owner)) if (!cuffsToRemove.InRangeUnobstructed(Owner))
{ {
Logger.Warning("Handcuffs being removed from player are obstructed or too far away! This should not happen!"); 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.")); user.PopupMessage(Loc.GetString("You start removing the cuffs."));
var audio = EntitySystem.Get<AudioSystem>();
if (isOwner) if (isOwner)
{ {
if (cuff.StartBreakoutSound != null) if (cuff.StartBreakoutSound != null)

View File

@@ -1,13 +1,14 @@
#nullable enable #nullable enable
using Content.Server.Cuffs.Components; using Content.Server.Cuffs.Components;
using Content.Server.Hands.Components; using Content.Server.Hands.Components;
using Content.Shared.Cuffs;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Server.Cuffs namespace Content.Server.Cuffs
{ {
[UsedImplicitly] [UsedImplicitly]
public class CuffableSystem : EntitySystem internal sealed class CuffableSystem : SharedCuffableSystem
{ {
public override void Initialize() 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; return true;
} }
public bool TryStopPull() public bool TryStopPull(IEntity? user = null)
{ {
if (!BeingPulled) if (!BeingPulled)
{ {
return false; 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) if (_physics != null && _pullJoint != null)
{ {
_physics.RemoveJoint(_pullJoint); _physics.RemoveJoint(_pullJoint);
@@ -375,4 +380,17 @@ namespace Content.Shared.Pulling.Components
Puller = puller; 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;
}
}
} }