2024-04-17 19:34:19 +02:00
|
|
|
namespace TanksServer.GameLogic;
|
|
|
|
|
|
|
|
internal sealed class SpawnPowerUp(
|
|
|
|
IOptions<GameRules> options,
|
|
|
|
MapEntityManager entityManager
|
|
|
|
) : ITickStep
|
|
|
|
{
|
|
|
|
private readonly double _spawnChance = options.Value.PowerUpSpawnChance;
|
2024-04-17 20:12:36 +02:00
|
|
|
private readonly int _maxCount = options.Value.MaxPowerUpCount;
|
2024-04-17 19:34:19 +02:00
|
|
|
|
|
|
|
public Task TickAsync(TimeSpan delta)
|
|
|
|
{
|
2024-04-17 20:12:36 +02:00
|
|
|
if (entityManager.PowerUps.Count() >= _maxCount)
|
|
|
|
return Task.CompletedTask;
|
2024-04-17 19:34:19 +02:00
|
|
|
if (Random.Shared.NextDouble() > _spawnChance * delta.TotalSeconds)
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
entityManager.SpawnPowerUp();
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|