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:
@@ -24,6 +24,7 @@ namespace Content.Server.Storage.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// How many uses before the item should delete itself.
|
/// How many uses before the item should delete itself.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("uses")]
|
[DataField("uses")]
|
||||||
public int Uses = 1;
|
public int Uses = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
return;
|
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 coords = Transform(args.User).Coordinates;
|
||||||
var spawnEntities = GetSpawns(component.Items, _random);
|
var spawnEntities = GetSpawns(component.Items, _random);
|
||||||
EntityUid? entityToPlaceInHands = null;
|
EntityUid? entityToPlaceInHands = null;
|
||||||
@@ -79,7 +83,9 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid), uid);
|
SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid), uid);
|
||||||
|
|
||||||
component.Uses--;
|
component.Uses--;
|
||||||
if (component.Uses == 0)
|
|
||||||
|
// Delete entity only if component was successfully used
|
||||||
|
if (component.Uses <= 0)
|
||||||
{
|
{
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
EntityManager.DeleteEntity(uid);
|
EntityManager.DeleteEntity(uid);
|
||||||
|
|||||||
Reference in New Issue
Block a user