This repository has been archived on 2026-07-13. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
servicepoint-tanks/TanksServer/GameLogic/SpawnPowerUp.cs
Vinzenz Schroeter 2a94a47a96 max power up count
2024-04-17 20:12:36 +02:00

21 lines
641 B
C#

namespace TanksServer.GameLogic;
internal sealed class SpawnPowerUp(
IOptions<GameRules> options,
MapEntityManager entityManager
) : ITickStep
{
private readonly double _spawnChance = options.Value.PowerUpSpawnChance;
private readonly int _maxCount = options.Value.MaxPowerUpCount;
public Task TickAsync(TimeSpan delta)
{
if (entityManager.PowerUps.Count() >= _maxCount)
return Task.CompletedTask;
if (Random.Shared.NextDouble() > _spawnChance * delta.TotalSeconds)
return Task.CompletedTask;
entityManager.SpawnPowerUp();
return Task.CompletedTask;
}
}