From 298913f98053f9360b6207a057a77a4abafba749 Mon Sep 17 00:00:00 2001 From: brainfood1183 <113240905+brainfood1183@users.noreply.github.com> Date: Mon, 24 Apr 2023 01:20:39 +0100 Subject: [PATCH] Delete unremoveable items when removed from hands or inventory (#15662) --- .../Components/UnremoveableComponent.cs | 11 +++++- .../Interaction/SharedInteractionSystem.cs | 38 +++++++++++++++++++ .../Entities/Clothing/Back/backpacks.yml | 2 + 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Interaction/Components/UnremoveableComponent.cs b/Content.Shared/Interaction/Components/UnremoveableComponent.cs index b2fe954b3f..bcf294a657 100644 --- a/Content.Shared/Interaction/Components/UnremoveableComponent.cs +++ b/Content.Shared/Interaction/Components/UnremoveableComponent.cs @@ -1,8 +1,17 @@ +using Content.Shared.Whitelist; using Robust.Shared.GameStates; namespace Content.Shared.Interaction.Components { [RegisterComponent] [NetworkedComponent] - public sealed class UnremoveableComponent : Component {} + public sealed class UnremoveableComponent : Component + { + /// + /// 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. + /// + [DataField("deleteOnDrop")] + public bool DeleteOnDrop = true; + } } diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 7d8de660a2..ac6582f571 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -1,3 +1,4 @@ +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.ActionBlocker; @@ -7,11 +8,13 @@ using Content.Shared.Administration.Managers; using Content.Shared.CombatMode; using Content.Shared.Database; using Content.Shared.Ghost; +using Content.Shared.Hands; using Content.Shared.Hands.Components; using Content.Shared.Input; using Content.Shared.Interaction.Components; using Content.Shared.Interaction.Events; using Content.Shared.Inventory; +using Content.Shared.Inventory.Events; using Content.Shared.Item; using Content.Shared.Movement.Components; using Content.Shared.Physics; @@ -24,9 +27,11 @@ using Content.Shared.Verbs; using Content.Shared.Wall; using JetBrains.Annotations; using Robust.Shared.Containers; +using Robust.Shared.GameObjects; using Robust.Shared.Input; using Robust.Shared.Input.Binding; using Robust.Shared.Map; +using Robust.Shared.Network; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Systems; @@ -46,6 +51,7 @@ namespace Content.Shared.Interaction public abstract partial class SharedInteractionSystem : EntitySystem { [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly INetManager _net = default!; [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly ISharedAdminManager _adminManager = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; @@ -76,6 +82,9 @@ namespace Content.Shared.Interaction SubscribeLocalEvent(OnBoundInterfaceInteractAttempt); SubscribeAllEvent(HandleInteractInventorySlotEvent); SubscribeLocalEvent(OnRemoveAttempt); + SubscribeLocalEvent(OnUnequip); + SubscribeLocalEvent(OnUnequipHand); + SubscribeLocalEvent(OnDropped); CommandBinds.Builder .Bind(ContentKeyFunctions.AltActivateItemInWorld, @@ -133,6 +142,35 @@ namespace Content.Shared.Interaction args.Cancel(); } + /// + /// 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). + /// + private void OnUnequip(EntityUid uid, UnremoveableComponent item, GotUnequippedEvent args) + { + if (!item.DeleteOnDrop) + RemCompDeferred(uid); + else if (_net.IsServer) + QueueDel(uid); + } + + private void OnUnequipHand(EntityUid uid, UnremoveableComponent item, GotUnequippedHandEvent args) + { + if (!item.DeleteOnDrop) + RemCompDeferred(uid); + else if (_net.IsServer) + QueueDel(uid); + } + + private void OnDropped(EntityUid uid, UnremoveableComponent item, DroppedEvent args) + { + if (!item.DeleteOnDrop) + RemCompDeferred(uid); + else if (_net.IsServer) + QueueDel(uid); + } + + private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid) { if (!ValidateClientInput(session, coords, uid, out var userEntity)) diff --git a/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml b/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml index e898f59212..9e1a1dc94c 100644 --- a/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml +++ b/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml @@ -236,3 +236,5 @@ - type: Sprite sprite: Clothing/Back/Backpacks/cluwne.rsi - type: Unremoveable + deleteOnDrop: false + -- 2.51.2