5dplomacy/MultiversalDiplomacy/Model/Unit.cs

66 lines
1.9 KiB
C#
Raw Normal View History

using System.Text.Json.Serialization;
2022-02-18 20:13:23 +00:00
namespace MultiversalDiplomacy.Model;
/// <summary>
/// Represents a unit at a particular point in time.
/// </summary>
public class Unit
{
/// <summary>
/// The previous iteration of a unit. This is null if the unit was just built.
/// </summary>
2024-08-14 15:39:19 +00:00
public string? Past { get; }
2022-02-18 20:13:23 +00:00
/// <summary>
/// The location on the map where the unit is.
/// </summary>
2024-08-14 15:20:04 +00:00
public string Location { get; }
2022-02-18 20:13:23 +00:00
/// <summary>
/// The season in time when the unit is.
/// </summary>
public Season Season { get; }
/// <summary>
/// The allegiance of the unit.
/// </summary>
2024-08-15 14:37:05 +00:00
public string Power { get; }
2022-02-18 20:13:23 +00:00
/// <summary>
/// The type of unit.
/// </summary>
public UnitType Type { get; }
2024-08-14 15:39:19 +00:00
/// <summary>
/// A unique designation for this unit.
/// </summary>
[JsonIgnore]
2024-08-15 13:52:08 +00:00
public string Key => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
2024-08-14 15:39:19 +00:00
2024-08-15 14:37:05 +00:00
public Unit(string? past, string location, Season season, string power, UnitType type)
2022-02-18 20:13:23 +00:00
{
this.Past = past;
this.Location = location;
this.Season = season;
this.Power = power;
this.Type = type;
}
public override string ToString()
2024-08-15 14:37:05 +00:00
=> $"{Power[0]} {Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
2022-02-18 20:13:23 +00:00
/// <summary>
/// Create a new unit. No validation is performed; the adjudicator should only call this
/// method after accepting a build order.
/// </summary>
2024-08-15 14:37:05 +00:00
public static Unit Build(string location, Season season, string power, UnitType type)
2024-08-13 15:17:34 +00:00
=> new(past: null, location, season, power, type);
2022-02-18 20:13:23 +00:00
/// <summary>
/// Advance this unit's timeline to a new location and season.
/// </summary>
2024-08-14 15:20:04 +00:00
public Unit Next(string location, Season season)
2024-08-15 13:52:08 +00:00
=> new(past: this.Key, location, season, this.Power, this.Type);
2022-02-18 20:13:23 +00:00
}