From 2a94a47a96126a120193d794dfe39e9027bee265 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Wed, 17 Apr 2024 20:12:36 +0200 Subject: [PATCH] max power up count --- TanksServer/GameLogic/GameRules.cs | 2 ++ TanksServer/GameLogic/SpawnPowerUp.cs | 3 +++ TanksServer/appsettings.json | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/TanksServer/GameLogic/GameRules.cs b/TanksServer/GameLogic/GameRules.cs index b9e4e49..287ea50 100644 --- a/TanksServer/GameLogic/GameRules.cs +++ b/TanksServer/GameLogic/GameRules.cs @@ -5,4 +5,6 @@ internal sealed class GameRules public bool DestructibleWalls { get; set; } = true; public double PowerUpSpawnChance { get; set; } + + public int MaxPowerUpCount { get; set; } = int.MaxValue; } diff --git a/TanksServer/GameLogic/SpawnPowerUp.cs b/TanksServer/GameLogic/SpawnPowerUp.cs index 16c418c..bc362bb 100644 --- a/TanksServer/GameLogic/SpawnPowerUp.cs +++ b/TanksServer/GameLogic/SpawnPowerUp.cs @@ -6,9 +6,12 @@ internal sealed class SpawnPowerUp( ) : 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; diff --git a/TanksServer/appsettings.json b/TanksServer/appsettings.json index a3ec103..5501994 100644 --- a/TanksServer/appsettings.json +++ b/TanksServer/appsettings.json @@ -27,7 +27,8 @@ }, "GameRules": { "DestructibleWalls": true, - "PowerUpSpawnChance": 0.1 + "PowerUpSpawnChance": 0.1, + "MaxPowerUpCount": 15 }, "Players": { "SpawnDelayMs": 3000,