diff --git a/Content.Shared/Storage/EntitySpawnEntry.cs b/Content.Shared/Storage/EntitySpawnEntry.cs index 19c414da0c..9748f8dc30 100644 --- a/Content.Shared/Storage/EntitySpawnEntry.cs +++ b/Content.Shared/Storage/EntitySpawnEntry.cs @@ -45,9 +45,17 @@ public struct EntitySpawnEntry : IPopulateDefaultValues [DataField("amount")] public int Amount; + /// + /// How many of this can be spawned, in total. + /// If this is lesser or equal to , it will spawn exactly. + /// Otherwise, it chooses a random value between and on spawn. + /// + [DataField("maxAmount")] public int MaxAmount; + public void PopulateDefaultValues() { Amount = 1; + MaxAmount = 1; SpawnProbability = 1; } } @@ -100,7 +108,12 @@ public static class EntitySpawnCollection // ReSharper disable once CompareOfFloatsByEqualityOperator if (entry.SpawnProbability != 1f && !random.Prob(entry.SpawnProbability)) continue; - for (var i = 0; i < entry.Amount; i++) + var amount = entry.Amount; + + if (entry.MaxAmount > amount) + amount = random.Next(amount, entry.MaxAmount); + + for (var i = 0; i < amount; i++) { spawned.Add(entry.PrototypeId); } @@ -118,7 +131,13 @@ public static class EntitySpawnCollection cumulative += entry.SpawnProbability; if (diceRoll > cumulative) continue; // Dice roll succeeded, add item and break loop - for (var index = 0; index < entry.Amount; index++) + + var amount = entry.Amount; + + if (entry.MaxAmount > amount) + amount = random.Next(amount, entry.MaxAmount); + + for (var index = 0; index < amount; index++) { spawned.Add(entry.PrototypeId); }