servicepoint-tanks/tanks-backend/TanksServer/Models/Tank.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2024-04-12 18:32:10 +02:00
using System.Diagnostics;
using System.Text.Json.Serialization;
2024-04-17 19:34:19 +02:00
using TanksServer.GameLogic;
2024-04-07 21:09:36 +02:00
2024-04-07 13:02:49 +02:00
namespace TanksServer.Models;
2024-05-08 01:01:11 +02:00
internal sealed class Tank(Player owner, FloatPosition position) : IMapEntity
2024-04-07 13:02:49 +02:00
{
2024-04-07 17:17:11 +02:00
private double _rotation;
2024-04-07 18:18:26 +02:00
[JsonIgnore] public Player Owner { get; } = owner;
2024-04-07 17:17:11 +02:00
2024-05-08 01:01:11 +02:00
[JsonIgnore] public double Rotation
2024-04-07 17:17:11 +02:00
{
get => _rotation;
2024-04-12 18:32:10 +02:00
set
{
var newRotation = (value % 1d + 1d) % 1d;
Debug.Assert(newRotation is >= 0 and < 1);
_rotation = newRotation;
}
2024-04-07 17:17:11 +02:00
}
public DateTime NextShotAfter { get; set; }
2024-04-07 21:09:36 +02:00
2024-04-22 19:44:28 +02:00
public bool Moving { get; set; }
2024-05-08 01:01:11 +02:00
[JsonIgnore] public FloatPosition Position { get; set; } = position;
public PixelPosition PixelPosition => Position.ToPixelPosition();
[JsonIgnore] public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);
2024-04-13 18:35:36 +02:00
public int Orientation => (int)Math.Round(Rotation * 16) % 16;
public int UsedBullets { get; set; }
public int MaxBullets { get; set; }
2024-04-29 17:17:44 +02:00
public DateTime ReloadingUntil { get; set; }
public required BulletStats BulletStats { get; set; }
}
internal sealed record class BulletStats(double Speed, double Acceleration, bool Explosive, bool Smart);