Retractable items get removed by handcuffs (#38441)
* init * oops * happens * review * fix
This commit is contained in:
@@ -15,6 +15,7 @@ using Content.Shared.IdentityManagement;
|
|||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Components;
|
using Content.Shared.Interaction.Components;
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Inventory.Events;
|
using Content.Shared.Inventory.Events;
|
||||||
using Content.Shared.Inventory.VirtualItem;
|
using Content.Shared.Inventory.VirtualItem;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
@@ -472,6 +473,9 @@ namespace Content.Shared.Cuffs
|
|||||||
if (TryComp<HandsComponent>(target, out var hands) && hands.Count <= component.CuffedHandCount)
|
if (TryComp<HandsComponent>(target, out var hands) && hands.Count <= component.CuffedHandCount)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
var ev = new TargetHandcuffedEvent();
|
||||||
|
RaiseLocalEvent(target, ref ev);
|
||||||
|
|
||||||
// Success!
|
// Success!
|
||||||
_hands.TryDrop(user, handcuff);
|
_hands.TryDrop(user, handcuff);
|
||||||
|
|
||||||
@@ -807,15 +811,24 @@ namespace Content.Shared.Cuffs
|
|||||||
{
|
{
|
||||||
return component.Container.ContainedEntities;
|
return component.Container.ContainedEntities;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
private sealed partial class UnCuffDoAfterEvent : SimpleDoAfterEvent
|
public sealed partial class UnCuffDoAfterEvent : SimpleDoAfterEvent;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
private sealed partial class AddCuffDoAfterEvent : SimpleDoAfterEvent
|
public sealed partial class AddCuffDoAfterEvent : SimpleDoAfterEvent;
|
||||||
{
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Raised on the target when they get handcuffed.
|
||||||
|
/// Relayed to their held items.
|
||||||
|
/// </summary>
|
||||||
|
[ByRefEvent]
|
||||||
|
public record struct TargetHandcuffedEvent : IInventoryRelayEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// All slots to relay to
|
||||||
|
/// </summary>
|
||||||
|
public SlotFlags TargetSlots { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Camera;
|
using Content.Shared.Camera;
|
||||||
|
using Content.Shared.Cuffs;
|
||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.Projectiles;
|
using Content.Shared.Projectiles;
|
||||||
@@ -22,6 +23,7 @@ public abstract partial class SharedHandsSystem
|
|||||||
SubscribeLocalEvent<HandsComponent, HitScanReflectAttemptEvent>(RefRelayEvent);
|
SubscribeLocalEvent<HandsComponent, HitScanReflectAttemptEvent>(RefRelayEvent);
|
||||||
SubscribeLocalEvent<HandsComponent, WieldAttemptEvent>(RefRelayEvent);
|
SubscribeLocalEvent<HandsComponent, WieldAttemptEvent>(RefRelayEvent);
|
||||||
SubscribeLocalEvent<HandsComponent, UnwieldAttemptEvent>(RefRelayEvent);
|
SubscribeLocalEvent<HandsComponent, UnwieldAttemptEvent>(RefRelayEvent);
|
||||||
|
SubscribeLocalEvent<HandsComponent, TargetHandcuffedEvent>(RefRelayEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RelayEvent<T>(Entity<HandsComponent> entity, ref T args) where T : EntityEventArgs
|
private void RelayEvent<T>(Entity<HandsComponent> entity, ref T args) where T : EntityEventArgs
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
|
using Content.Shared.Cuffs;
|
||||||
|
using Content.Shared.Hands;
|
||||||
|
using Content.Shared.Hands.Components;
|
||||||
using Content.Shared.Hands.EntitySystems;
|
using Content.Shared.Hands.EntitySystems;
|
||||||
using Content.Shared.Interaction.Components;
|
using Content.Shared.Interaction.Components;
|
||||||
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
@@ -26,6 +30,7 @@ public sealed class RetractableItemActionSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<RetractableItemActionComponent, OnRetractableItemActionEvent>(OnRetractableItemAction);
|
SubscribeLocalEvent<RetractableItemActionComponent, OnRetractableItemActionEvent>(OnRetractableItemAction);
|
||||||
|
|
||||||
SubscribeLocalEvent<ActionRetractableItemComponent, ComponentShutdown>(OnActionSummonedShutdown);
|
SubscribeLocalEvent<ActionRetractableItemComponent, ComponentShutdown>(OnActionSummonedShutdown);
|
||||||
|
Subs.SubscribeWithRelay<ActionRetractableItemComponent, HeldRelayedEvent<TargetHandcuffedEvent>>(OnItemHandcuffed, inventory: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnActionInit(Entity<RetractableItemActionComponent> ent, ref MapInitEvent args)
|
private void OnActionInit(Entity<RetractableItemActionComponent> ent, ref MapInitEvent args)
|
||||||
@@ -58,16 +63,11 @@ public sealed class RetractableItemActionSystem : EntitySystem
|
|||||||
|
|
||||||
if (_hands.IsHolding(args.Performer, ent.Comp.ActionItemUid))
|
if (_hands.IsHolding(args.Performer, ent.Comp.ActionItemUid))
|
||||||
{
|
{
|
||||||
RemComp<UnremoveableComponent>(ent.Comp.ActionItemUid.Value);
|
RetractRetractableItem(args.Performer, ent.Comp.ActionItemUid.Value, ent.Owner);
|
||||||
var container = _containers.GetContainer(ent, RetractableItemActionComponent.ContainerId);
|
|
||||||
_containers.Insert(ent.Comp.ActionItemUid.Value, container);
|
|
||||||
_audio.PlayPredicted(ent.Comp.RetractSounds, action.Comp.AttachedEntity.Value, action.Comp.AttachedEntity.Value);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_hands.TryForcePickup(args.Performer, ent.Comp.ActionItemUid.Value, userHand, checkActionBlocker: false);
|
SummonRetractableItem(args.Performer, ent.Comp.ActionItemUid.Value, userHand, ent.Owner);
|
||||||
_audio.PlayPredicted(ent.Comp.SummonSounds, action.Comp.AttachedEntity.Value, action.Comp.AttachedEntity.Value);
|
|
||||||
EnsureComp<UnremoveableComponent>(ent.Comp.ActionItemUid.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
@@ -85,6 +85,20 @@ public sealed class RetractableItemActionSystem : EntitySystem
|
|||||||
PopulateActionItem(action.Owner);
|
PopulateActionItem(action.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnItemHandcuffed(Entity<ActionRetractableItemComponent> ent, ref HeldRelayedEvent<TargetHandcuffedEvent> args)
|
||||||
|
{
|
||||||
|
if (_actions.GetAction(ent.Comp.SummoningAction) is not { } action)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (action.Comp.AttachedEntity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_hands.GetActiveHand(action.Comp.AttachedEntity.Value) is not { } userHand)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RetractRetractableItem(action.Comp.AttachedEntity.Value, ent, action.Owner);
|
||||||
|
}
|
||||||
|
|
||||||
private void PopulateActionItem(Entity<RetractableItemActionComponent?> ent)
|
private void PopulateActionItem(Entity<RetractableItemActionComponent?> ent)
|
||||||
{
|
{
|
||||||
if (!Resolve(ent.Owner, ref ent.Comp, false) || TerminatingOrDeleted(ent))
|
if (!Resolve(ent.Owner, ref ent.Comp, false) || TerminatingOrDeleted(ent))
|
||||||
@@ -102,4 +116,25 @@ public sealed class RetractableItemActionSystem : EntitySystem
|
|||||||
|
|
||||||
Dirty(ent);
|
Dirty(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RetractRetractableItem(EntityUid holder, EntityUid item, Entity<RetractableItemActionComponent?> action)
|
||||||
|
{
|
||||||
|
if (!Resolve(action, ref action.Comp, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
RemComp<UnremoveableComponent>(item);
|
||||||
|
var container = _containers.GetContainer(action, RetractableItemActionComponent.ContainerId);
|
||||||
|
_containers.Insert(item, container);
|
||||||
|
_audio.PlayPredicted(action.Comp.RetractSounds, holder, holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SummonRetractableItem(EntityUid holder, EntityUid item, Hand hand, Entity<RetractableItemActionComponent?> action)
|
||||||
|
{
|
||||||
|
if (!Resolve(action, ref action.Comp, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_hands.TryForcePickup(holder, item, hand, checkActionBlocker: false);
|
||||||
|
_audio.PlayPredicted(action.Comp.SummonSounds, holder, holder);
|
||||||
|
EnsureComp<UnremoveableComponent>(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user