using System.Diagnostics; namespace TanksServer.GameLogic; internal sealed class SpawnPowerUp( IOptions options, MapEntityManager entityManager ) : ITickStep { private readonly double _spawnChance = options.Value.PowerUpSpawnChance; private readonly int _maxCount = options.Value.MaxPowerUpCount; public ValueTask TickAsync(TimeSpan delta) { if (entityManager.PowerUps.Count() >= _maxCount) return ValueTask.CompletedTask; if (Random.Shared.NextDouble() > _spawnChance * delta.TotalSeconds) return ValueTask.CompletedTask; var type = Random.Shared.Next(10) < 3 ? PowerUpType.MagazineSizeUpgrade : PowerUpType.MagazineTypeUpgrade; MagazineType? magazineType = type switch { PowerUpType.MagazineTypeUpgrade => Random.Shared.Next(0, 4) switch { 0 => MagazineType.Fast, 1 => MagazineType.Explosive, 2 => MagazineType.Smart, 3 => MagazineType.Mine, _ => throw new UnreachableException() }, _ => null }; entityManager.SpawnPowerUp(type, magazineType); return ValueTask.CompletedTask; } }