Migrate cuffing to an uncuff attempt event and allow self-uncuff again (#4725)
* Migrate cuffing to an uncuff attempt event and allow self-uncuff again * Uncuff attempt event: Use more SubscribeLocalEvent and Dependency attributes
This commit is contained in:
@@ -206,10 +206,11 @@ namespace Content.Server.Cuffs.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make into an event and instead have a system check for owner.
|
var attempt = new UncuffAttemptEvent(user.Uid, Owner.Uid);
|
||||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
Owner.EntityManager.EventBus.RaiseLocalEvent(user.Uid, attempt);
|
||||||
|
|
||||||
|
if (attempt.Cancelled)
|
||||||
{
|
{
|
||||||
user.PopupMessage(Loc.GetString("cuffable-component-cannot-interact-message"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,72 @@
|
|||||||
using Content.Server.Cuffs.Components;
|
using Content.Server.Cuffs.Components;
|
||||||
using Content.Server.Hands.Components;
|
using Content.Server.Hands.Components;
|
||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
|
using Content.Shared.ActionBlocker;
|
||||||
|
using Content.Shared.MobState;
|
||||||
using Content.Shared.Cuffs;
|
using Content.Shared.Cuffs;
|
||||||
|
using Content.Shared.Popups;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Localization;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
namespace Content.Server.Cuffs
|
namespace Content.Server.Cuffs
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal sealed class CuffableSystem : SharedCuffableSystem
|
internal sealed class CuffableSystem : SharedCuffableSystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||||
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
EntityManager.EventBus.SubscribeEvent<HandCountChangedEvent>(EventSource.Local, this, OnHandCountChanged);
|
SubscribeLocalEvent<HandCountChangedEvent>(OnHandCountChanged);
|
||||||
|
SubscribeLocalEvent<UncuffAttemptEvent>(OnUncuffAttempt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUncuffAttempt(UncuffAttemptEvent args)
|
||||||
|
{
|
||||||
|
if (args.Cancelled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!EntityManager.TryGetEntity(args.User, out var userEntity))
|
||||||
|
{
|
||||||
|
// Should this even be possible?
|
||||||
|
args.Cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If the user is the target, special logic applies.
|
||||||
|
// This is because the CanInteract blocking of the cuffs prevents self-uncuff.
|
||||||
|
if (args.User == args.Target)
|
||||||
|
{
|
||||||
|
if (userEntity.TryGetComponent<IMobStateComponent>(out var state))
|
||||||
|
{
|
||||||
|
// Manually check this.
|
||||||
|
if (state.IsIncapacitated())
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Uh... let it go through???
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check if the user can interact.
|
||||||
|
if (!_actionBlockerSystem.CanInteract(userEntity))
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args.Cancelled)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, _popupSystem.GetFilterFromEntity(userEntity));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -49,4 +101,20 @@ namespace Content.Server.Cuffs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event fired on the User when the User attempts to cuff the Target.
|
||||||
|
/// Should generate popups on the User.
|
||||||
|
/// </summary>
|
||||||
|
public class UncuffAttemptEvent : CancellableEntityEventArgs
|
||||||
|
{
|
||||||
|
public readonly EntityUid User;
|
||||||
|
public readonly EntityUid Target;
|
||||||
|
|
||||||
|
public UncuffAttemptEvent(EntityUid user, EntityUid target)
|
||||||
|
{
|
||||||
|
User = user;
|
||||||
|
Target = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user