Files
territory-autobattler/microservices/LocationsApi/Models/Dto.cs
T

83 lines
2.1 KiB
C#

namespace LocationsApi.Models;
public class UpsertLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
public string Terrain { get; set; } = "Field";
public string? Label { get; set; }
public int Level { get; set; } = 1;
}
public class ClaimLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
}
public class LocationResponse
{
public string Id { get; set; } = "";
public int Q { get; set; }
public int R { get; set; }
public string Terrain { get; set; } = "Field";
public string Kind { get; set; } = "Open";
public string? OwnerUsername { get; set; }
public string? Label { get; set; }
public int Level { get; set; }
public DateTime? HomeAssignedAtUtc { get; set; }
public DateTime UpdatedAtUtc { get; set; }
public bool IsVisible { get; set; } = true;
public static LocationResponse FromLocation(Location location) => new()
{
Id = location.Id,
Q = location.Q,
R = location.R,
Terrain = location.Terrain,
Kind = location.Kind,
OwnerUsername = location.OwnerUsername,
Label = location.Label,
Level = location.Level,
HomeAssignedAtUtc = location.HomeAssignedAtUtc,
UpdatedAtUtc = location.UpdatedAtUtc,
IsVisible = true
};
public static LocationResponse FromCoordinate(int q, int r) => new()
{
Q = q,
R = r,
Terrain = LocationTerrain.FromCoordinate(q, r),
Kind = "Open",
Level = 1,
UpdatedAtUtc = DateTime.UtcNow,
IsVisible = true
};
}
public static class LocationTerrain
{
public static string FromCoordinate(int q, int r)
{
var height = Math.Max(Math.Max(Math.Abs(q), Math.Abs(r)), Math.Abs(-q - r));
if (height <= 1)
{
return "Command";
}
if ((q * 19 + r * 7) % 5 == 0)
{
return "Highland";
}
if ((q + r) % 4 == 0)
{
return "Forest";
}
if ((q * 3 - r) % 6 == 0)
{
return "Ore";
}
return "Field";
}
}