implement reloading

This commit is contained in:
Vinzenz Schroeter 2024-04-29 17:17:44 +02:00
parent 9164d90443
commit a5a3ca3013
5 changed files with 34 additions and 8 deletions

View file

@ -21,11 +21,16 @@ internal sealed class CollectPowerUp(
continue;
// now the tank overlaps the power up by at least 0.5 tiles
tank.Magazine = tank.Magazine with
{
UsedBullets = 0,
Type = MagazineType.Explosive
Type = tank.Magazine.Type | MagazineType.Explosive
};
if (tank.ReloadingUntil >= DateTime.Now)
tank.ReloadingUntil = DateTime.Now;
tank.Owner.Scores.PowerUpsCollected++;
return true;
}

View file

@ -23,4 +23,6 @@ internal sealed class GameRules
public int IdleTimeoutMs { get; set; }
public byte MagazineSize { get; set; } = 5;
public int ReloadDelayMs { get; set; } = 3000;
}

View file

@ -19,12 +19,25 @@ internal sealed class ShootFromTanks(
{
if (!tank.Owner.Controls.Shoot)
return;
if (tank.Magazine.Empty)
var now = DateTime.Now;
if (tank.NextShotAfter >= now)
return;
if (tank.NextShotAfter >= DateTime.Now)
if (tank.ReloadingUntil >= now)
return;
tank.NextShotAfter = DateTime.Now.AddMilliseconds(_config.ShootDelayMs);
if (tank.Magazine.Empty)
{
tank.ReloadingUntil = now.AddMilliseconds(_config.ReloadDelayMs);
tank.Magazine = tank.Magazine with
{
UsedBullets = 0,
Type = MagazineType.Basic
};
return;
}
tank.NextShotAfter = now.AddMilliseconds(_config.ShootDelayMs);
tank.Magazine = tank.Magazine with
{
UsedBullets = (byte)(tank.Magazine.UsedBullets + 1)