Delete unremoveable items when removed from hands or inventory (#15662)

This commit is contained in:
brainfood1183
2023-04-24 01:20:39 +01:00
committed by GitHub
parent 0fdbe1152e
commit 298913f980
3 changed files with 50 additions and 1 deletions

View File

@@ -1,8 +1,17 @@
using Content.Shared.Whitelist;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
namespace Content.Shared.Interaction.Components namespace Content.Shared.Interaction.Components
{ {
[RegisterComponent] [RegisterComponent]
[NetworkedComponent] [NetworkedComponent]
public sealed class UnremoveableComponent : Component {} public sealed class UnremoveableComponent : Component
{
/// <summary>
/// If this is true then unremovable items that are removed from inventory are deleted (typically from corpse gibbing).
/// Items within unremovable containers are not deleted when removed.
/// </summary>
[DataField("deleteOnDrop")]
public bool DeleteOnDrop = true;
}
} }

View File

@@ -1,3 +1,4 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
@@ -7,11 +8,13 @@ using Content.Shared.Administration.Managers;
using Content.Shared.CombatMode; using Content.Shared.CombatMode;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Ghost; using Content.Shared.Ghost;
using Content.Shared.Hands;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Input; using Content.Shared.Input;
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;
using Content.Shared.Inventory.Events;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Movement.Components; using Content.Shared.Movement.Components;
using Content.Shared.Physics; using Content.Shared.Physics;
@@ -24,9 +27,11 @@ using Content.Shared.Verbs;
using Content.Shared.Wall; using Content.Shared.Wall;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input; using Robust.Shared.Input;
using Robust.Shared.Input.Binding; using Robust.Shared.Input.Binding;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems; using Robust.Shared.Physics.Systems;
@@ -46,6 +51,7 @@ namespace Content.Shared.Interaction
public abstract partial class SharedInteractionSystem : EntitySystem public abstract partial class SharedInteractionSystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly ISharedAdminManager _adminManager = default!; [Dependency] private readonly ISharedAdminManager _adminManager = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
@@ -76,6 +82,9 @@ namespace Content.Shared.Interaction
SubscribeLocalEvent<BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt); SubscribeLocalEvent<BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
SubscribeAllEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent); SubscribeAllEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent);
SubscribeLocalEvent<UnremoveableComponent, ContainerGettingRemovedAttemptEvent>(OnRemoveAttempt); SubscribeLocalEvent<UnremoveableComponent, ContainerGettingRemovedAttemptEvent>(OnRemoveAttempt);
SubscribeLocalEvent<UnremoveableComponent, GotUnequippedEvent>(OnUnequip);
SubscribeLocalEvent<UnremoveableComponent, GotUnequippedHandEvent>(OnUnequipHand);
SubscribeLocalEvent<UnremoveableComponent, DroppedEvent>(OnDropped);
CommandBinds.Builder CommandBinds.Builder
.Bind(ContentKeyFunctions.AltActivateItemInWorld, .Bind(ContentKeyFunctions.AltActivateItemInWorld,
@@ -133,6 +142,35 @@ namespace Content.Shared.Interaction
args.Cancel(); args.Cancel();
} }
/// <summary>
/// If item has DeleteOnDrop true then item will be deleted if removed from inventory, if it is false then item
/// loses Unremoveable when removed from inventory (gibbing).
/// </summary>
private void OnUnequip(EntityUid uid, UnremoveableComponent item, GotUnequippedEvent args)
{
if (!item.DeleteOnDrop)
RemCompDeferred<UnremoveableComponent>(uid);
else if (_net.IsServer)
QueueDel(uid);
}
private void OnUnequipHand(EntityUid uid, UnremoveableComponent item, GotUnequippedHandEvent args)
{
if (!item.DeleteOnDrop)
RemCompDeferred<UnremoveableComponent>(uid);
else if (_net.IsServer)
QueueDel(uid);
}
private void OnDropped(EntityUid uid, UnremoveableComponent item, DroppedEvent args)
{
if (!item.DeleteOnDrop)
RemCompDeferred<UnremoveableComponent>(uid);
else if (_net.IsServer)
QueueDel(uid);
}
private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid) private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{ {
if (!ValidateClientInput(session, coords, uid, out var userEntity)) if (!ValidateClientInput(session, coords, uid, out var userEntity))

View File

@@ -236,3 +236,5 @@
- type: Sprite - type: Sprite
sprite: Clothing/Back/Backpacks/cluwne.rsi sprite: Clothing/Back/Backpacks/cluwne.rsi
- type: Unremoveable - type: Unremoveable
deleteOnDrop: false