Support number of uses starting at zero (#19452)

This allows peelable bananas without replicating the entire YAML
structure to remove this one component.
This commit is contained in:
Kevin Zheng
2023-08-26 09:29:15 -07:00
committed by GitHub
parent 6def8c842f
commit ccd0e8b7c4
2 changed files with 8 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ namespace Content.Server.Storage.Components
/// <summary>
/// How many uses before the item should delete itself.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("uses")]
public int Uses = 1;
}

View File

@@ -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);