add power ups collected score
This commit is contained in:
parent
bf22fd6c85
commit
259d63d683
8 changed files with 45 additions and 32 deletions
|
@ -20,8 +20,9 @@ internal sealed class CollectPowerUp(
|
|||
position.Y < topLeft.Y || position.Y > bottomRight.Y)
|
||||
continue;
|
||||
|
||||
// this works because now the tank overlaps the power up
|
||||
// now the tank overlaps the power up by at least 0.5 tiles
|
||||
tank.ExplosiveBullets += 10;
|
||||
tank.Owner.Scores.PowerUpsCollected++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace TanksServer.GameLogic;
|
|||
internal sealed class TankSpawnQueue(
|
||||
IOptions<GameRules> options,
|
||||
MapEntityManager entityManager
|
||||
): ITickStep
|
||||
) : ITickStep
|
||||
{
|
||||
private readonly ConcurrentQueue<Player> _queue = new();
|
||||
private readonly ConcurrentDictionary<Player, DateTime> _spawnTimes = new();
|
||||
|
@ -16,31 +16,8 @@ internal sealed class TankSpawnQueue(
|
|||
|
||||
public void EnqueueForDelayedSpawn(Player player)
|
||||
{
|
||||
_queue.Enqueue(player);
|
||||
_spawnTimes.AddOrUpdate(player, DateTime.MinValue, (_, _) => DateTime.Now + _spawnDelay);
|
||||
}
|
||||
|
||||
private bool TryDequeueNext([MaybeNullWhen(false)] out Player player)
|
||||
{
|
||||
if (!_queue.TryDequeue(out player))
|
||||
return false; // no one on queue
|
||||
|
||||
if (player.LastInput + _idleTimeout < DateTime.Now)
|
||||
{
|
||||
// player idle
|
||||
_queue.Enqueue(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
if (_spawnTimes.GetOrAdd(player, DateTime.MinValue) > now)
|
||||
{
|
||||
// spawn delay
|
||||
_queue.Enqueue(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
_queue.Enqueue(player);
|
||||
}
|
||||
|
||||
public ValueTask TickAsync(TimeSpan _)
|
||||
|
@ -51,4 +28,29 @@ internal sealed class TankSpawnQueue(
|
|||
entityManager.SpawnTank(player);
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
private bool TryDequeueNext([MaybeNullWhen(false)] out Player player)
|
||||
{
|
||||
if (!_queue.TryDequeue(out player))
|
||||
return false; // no one on queue
|
||||
|
||||
var now = DateTime.Now;
|
||||
if (player.LastInput + _idleTimeout < now)
|
||||
{
|
||||
// player idle
|
||||
_queue.Enqueue(player);
|
||||
player = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_spawnTimes.GetOrAdd(player, DateTime.MinValue) > now)
|
||||
{
|
||||
// spawn delay
|
||||
_queue.Enqueue(player);
|
||||
player = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ namespace TanksServer.Interactivity;
|
|||
|
||||
[JsonSerializable(typeof(Player))]
|
||||
[JsonSerializable(typeof(IEnumerable<Player>))]
|
||||
[JsonSerializable(typeof(Guid))]
|
||||
[JsonSerializable(typeof(NameId))]
|
||||
[JsonSerializable(typeof(IEnumerable<string>))]
|
||||
[JsonSerializable(typeof(PlayerInfo))]
|
||||
internal sealed partial class AppSerializerContext : JsonSerializerContext;
|
||||
|
|
|
@ -22,5 +22,12 @@ internal sealed record class Scores
|
|||
|
||||
public int ShotsFired { get; set; }
|
||||
|
||||
public int OverallScore => Math.Max(0, 10000 * Kills - 1000 * Deaths + 10 * ShotsFired + 10 * WallsDestroyed);
|
||||
public int PowerUpsCollected { get; set; }
|
||||
|
||||
public int OverallScore => Math.Max(0,
|
||||
10000 * Kills
|
||||
- 1000 * Deaths
|
||||
+ 100 * PowerUpsCollected
|
||||
+ 10 * (ShotsFired + WallsDestroyed)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ using TanksServer.Interactivity;
|
|||
|
||||
namespace TanksServer;
|
||||
|
||||
internal sealed record class NameId(string Name, Guid Id);
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue