move upgrades to tank, serialize objects directly

This commit is contained in:
Vinzenz Schroeter 2024-05-08 00:29:33 +02:00
parent b1df817ece
commit 827b3a9330
16 changed files with 135 additions and 180 deletions

View file

@ -1,13 +1,14 @@
using System.Diagnostics;
using System.Text.Json.Serialization;
using TanksServer.GameLogic;
namespace TanksServer.Models;
internal sealed class Tank : IMapEntity
internal sealed class Tank(Player owner) : IMapEntity
{
private double _rotation;
public required Player Owner { get; init; }
[JsonIgnore] public Player Owner { get; } = owner;
public double Rotation
{
@ -26,11 +27,17 @@ internal sealed class Tank : IMapEntity
public required FloatPosition Position { get; set; }
public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);
[JsonIgnore] public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);
public int Orientation => (int)Math.Round(Rotation * 16) % 16;
public required Magazine Magazine { get; set; }
public int UsedBullets { get; set; }
public int MaxBullets { get; set; }
public DateTime ReloadingUntil { get; set; }
public required BulletStats BulletStats { get; set; }
}
internal sealed record class BulletStats(double Speed, double Acceleration, bool Explosive, bool Smart);