]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Limit maximum capacity of fillable cluster grenades (#34281)
authorTayrtahn <tayrtahn@gmail.com>
Tue, 11 Feb 2025 23:13:00 +0000 (18:13 -0500)
committerGitHub <noreply@github.com>
Tue, 11 Feb 2025 23:13:00 +0000 (00:13 +0100)
* Limit maximum capacity of fillable cluster grenades

* Swap GrenadeCount method for component property

Content.Shared/Explosion/Components/ScatteringGrenadeComponent.cs
Content.Shared/Explosion/EntitySystems/SharedScatteringGrenadeSystem.cs

index be27c49ffa462a193ae6c23a424cf0b564cdfcde..059ad189d1113c0186d114b458c09b8b9eb09745 100644 (file)
@@ -27,7 +27,7 @@ public sealed partial class ScatteringGrenadeComponent : Component
     /// <summary>
     /// If we have a pre-fill how many more can we spawn.
     /// </summary>
-    [AutoNetworkedField]
+    [ViewVariables(VVAccess.ReadOnly), AutoNetworkedField]
     public int UnspawnedCount;
 
     /// <summary>
@@ -36,6 +36,12 @@ public sealed partial class ScatteringGrenadeComponent : Component
     [DataField]
     public int Capacity = 3;
 
+    /// <summary>
+    /// Number of grenades currently contained in the cluster (both spawned and unspawned)
+    /// </summary>
+    [ViewVariables(VVAccess.ReadOnly)]
+    public int Count => UnspawnedCount + Container.ContainedEntities.Count;
+
     /// <summary>
     /// Decides if contained entities trigger after getting launched
     /// </summary>
index b704fbf86f3fa435112509df9a7530c10822ec02..7b54b0f7d5f7d75e3bb67fb0ddecdd9df219530c 100644 (file)
@@ -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<AppearanceComponent>(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);
     }
 }