From ccd0e8b7c440a31b9f17dd517d85943bfdf79426 Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Sat, 26 Aug 2023 09:29:15 -0700 Subject: [PATCH] Support number of uses starting at zero (#19452) This allows peelable bananas without replicating the entire YAML structure to remove this one component. --- .../Storage/Components/SpawnItemsOnUseComponent.cs | 1 + .../Storage/EntitySystems/SpawnItemsOnUseSystem.cs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Content.Server/Storage/Components/SpawnItemsOnUseComponent.cs b/Content.Server/Storage/Components/SpawnItemsOnUseComponent.cs index ef4b8197fc..6db9f091d3 100644 --- a/Content.Server/Storage/Components/SpawnItemsOnUseComponent.cs +++ b/Content.Server/Storage/Components/SpawnItemsOnUseComponent.cs @@ -24,6 +24,7 @@ namespace Content.Server.Storage.Components /// /// How many uses before the item should delete itself. /// + [ViewVariables(VVAccess.ReadWrite)] [DataField("uses")] public int Uses = 1; } diff --git a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs index b24348507d..061ddee824 100644 --- a/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs +++ b/Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs @@ -65,6 +65,10 @@ namespace Content.Server.Storage.EntitySystems if (args.Handled) return; + // If starting with zero or less uses, this component is a no-op + if (component.Uses <= 0) + return; + var coords = Transform(args.User).Coordinates; var spawnEntities = GetSpawns(component.Items, _random); EntityUid? entityToPlaceInHands = null; @@ -79,7 +83,9 @@ namespace Content.Server.Storage.EntitySystems SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid), uid); component.Uses--; - if (component.Uses == 0) + + // Delete entity only if component was successfully used + if (component.Uses <= 0) { args.Handled = true; EntityManager.DeleteEntity(uid);