From 4603b477787959cfe9dce2d90e26811f9d3ca861 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 11 Feb 2025 18:13:00 -0500 Subject: [PATCH] Limit maximum capacity of fillable cluster grenades (#34281) * Limit maximum capacity of fillable cluster grenades * Swap GrenadeCount method for component property --- .../Explosion/Components/ScatteringGrenadeComponent.cs | 8 +++++++- .../EntitySystems/SharedScatteringGrenadeSystem.cs | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Explosion/Components/ScatteringGrenadeComponent.cs b/Content.Shared/Explosion/Components/ScatteringGrenadeComponent.cs index be27c49ffa..059ad189d1 100644 --- a/Content.Shared/Explosion/Components/ScatteringGrenadeComponent.cs +++ b/Content.Shared/Explosion/Components/ScatteringGrenadeComponent.cs @@ -27,7 +27,7 @@ public sealed partial class ScatteringGrenadeComponent : Component /// /// If we have a pre-fill how many more can we spawn. /// - [AutoNetworkedField] + [ViewVariables(VVAccess.ReadOnly), AutoNetworkedField] public int UnspawnedCount; /// @@ -36,6 +36,12 @@ public sealed partial class ScatteringGrenadeComponent : Component [DataField] public int Capacity = 3; + /// + /// Number of grenades currently contained in the cluster (both spawned and unspawned) + /// + [ViewVariables(VVAccess.ReadOnly)] + public int Count => UnspawnedCount + Container.ContainedEntities.Count; + /// /// Decides if contained entities trigger after getting launched /// diff --git a/Content.Shared/Explosion/EntitySystems/SharedScatteringGrenadeSystem.cs b/Content.Shared/Explosion/EntitySystems/SharedScatteringGrenadeSystem.cs index b704fbf86f..7b54b0f7d5 100644 --- a/Content.Shared/Explosion/EntitySystems/SharedScatteringGrenadeSystem.cs +++ b/Content.Shared/Explosion/EntitySystems/SharedScatteringGrenadeSystem.cs @@ -49,6 +49,10 @@ public abstract class SharedScatteringGrenadeSystem : EntitySystem if (entity.Comp.Whitelist == null) return; + // Make sure there's room for another grenade to be added + if (entity.Comp.Count >= entity.Comp.Capacity) + return; + if (args.Handled || !_whitelistSystem.IsValid(entity.Comp.Whitelist, args.Used)) return; @@ -65,6 +69,6 @@ public abstract class SharedScatteringGrenadeSystem : EntitySystem if (!TryComp(entity, out var appearanceComponent)) return; - _appearance.SetData(entity, ClusterGrenadeVisuals.GrenadesCounter, entity.Comp.UnspawnedCount + entity.Comp.Container.ContainedEntities.Count, appearanceComponent); + _appearance.SetData(entity, ClusterGrenadeVisuals.GrenadesCounter, entity.Comp.Count, appearanceComponent); } } -- 2.51.2