using System.Text.Json.Serialization;
namespace MultiversalDiplomacy.Model;
///
/// Represents a locus of connectivity in a province. Land-locked and ocean/sea provinces
/// have one location. Coastal provinces have a land location and some number of named
/// water locations.
///
public class Location
{
///
/// The province to which this location belongs.
///
[JsonIgnore]
public Province Province { get; }
public string ProvinceName => Province.Name;
///
/// The location's full human-readable name.
///
public string Name { get; }
///
/// The location's shorthand abbreviation.
///
public string Abbreviation { get; }
///
/// The location's type.
///
public LocationType Type { get; }
///
/// The locations that border this location.
///
[JsonIgnore]
public IEnumerable Adjacents => this.AdjacentList;
private List AdjacentList { get; set; }
///
/// The unique name of this location in the map.
///
public string Key => $"{this.ProvinceName}/{this.Abbreviation}";
public Location(Province province, string name, string abbreviation, LocationType type)
{
this.Province = province;
this.Name = name;
this.Abbreviation = abbreviation;
this.Type = type;
this.AdjacentList = new List();
}
public static (string province, string location) SplitKey(string locationKey)
{
var split = locationKey.Split(['/'], 2);
return (split[0], split[1]);
}
///
/// Whether a name is the name or abbreviation of this location.
///
public bool Is(string name)
=> name.EqualsAnyCase(Name) || name.EqualsAnyCase(Abbreviation);
public override string ToString()
{
return this.Name == "land" || this.Name == "water"
? $"{this.Province.Name} ({this.Type})"
: $"{this.Province.Name} ({this.Type}:{this.Name}]";
}
///
/// Set another location as bordering this location.
///
public void AddBorder(Location other)
{
if (!this.AdjacentList.Contains(other)) this.AdjacentList.Add(other);
if (!other.AdjacentList.Contains(this)) other.AdjacentList.Add(this);
}
}