diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs index 5b9b7596ef..ed5777c42a 100644 --- a/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs +++ b/Content.Server/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs @@ -31,29 +31,38 @@ namespace Content.Server.Destructible.Thresholds.Behaviors var getRandomVector = () => new Vector2(system.Random.NextFloat(-Offset, Offset), system.Random.NextFloat(-Offset, Offset)); + var executions = 1; + if (system.EntityManager.TryGetComponent(owner, out var stack)) + { + executions = stack.Count; + } + foreach (var (entityId, minMax) in Spawn) { - var count = minMax.Min >= minMax.Max - ? minMax.Min - : system.Random.Next(minMax.Min, minMax.Max + 1); - - if (count == 0) continue; - - if (EntityPrototypeHelpers.HasComponent(entityId, system.PrototypeManager, system.ComponentFactory)) + for (var execution = 0; execution < executions; execution++) { - var spawned = system.EntityManager.SpawnEntity(entityId, position.Offset(getRandomVector())); - system.StackSystem.SetCount(spawned, count); + var count = minMax.Min >= minMax.Max + ? minMax.Min + : system.Random.Next(minMax.Min, minMax.Max + 1); - TransferForensics(spawned, system, owner); - } - else - { - for (var i = 0; i < count; i++) + if (count == 0) continue; + + if (EntityPrototypeHelpers.HasComponent(entityId, system.PrototypeManager, system.ComponentFactory)) { var spawned = system.EntityManager.SpawnEntity(entityId, position.Offset(getRandomVector())); + system.StackSystem.SetCount(spawned, count); TransferForensics(spawned, system, owner); } + else + { + for (var i = 0; i < count; i++) + { + var spawned = system.EntityManager.SpawnEntity(entityId, position.Offset(getRandomVector())); + + TransferForensics(spawned, system, owner); + } + } } } }