5dplomacy/MultiversalDiplomacy/Model/Unit.cs

66 lines
1.9 KiB
C#

using System.Text.Json.Serialization;
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>
public string? Past { get; }
/// <summary>
/// The location on the map where the unit is.
/// </summary>
public string Location { get; }
/// <summary>
/// The season in time when the unit is.
/// </summary>
public Season Season { get; }
/// <summary>
/// The allegiance of the unit.
/// </summary>
public Power Power { get; }
/// <summary>
/// The type of unit.
/// </summary>
public UnitType Type { get; }
/// <summary>
/// A unique designation for this unit.
/// </summary>
[JsonIgnore]
public string Designation => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
public Unit(string? past, string location, Season season, Power power, UnitType type)
{
this.Past = past;
this.Location = location;
this.Season = season;
this.Power = power;
this.Type = type;
}
public override string ToString()
=> $"{Power.Name[0]} {Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
/// <summary>
/// Create a new unit. No validation is performed; the adjudicator should only call this
/// method after accepting a build order.
/// </summary>
public static Unit Build(string location, Season season, Power power, UnitType type)
=> new(past: null, location, season, power, type);
/// <summary>
/// Advance this unit's timeline to a new location and season.
/// </summary>
public Unit Next(string location, Season season)
=> new(past: this.Designation, location, season, this.Power, this.Type);
}