EDBGS/EDPlayerJournal/Entries/DiedEntry.cs

40 lines
1.3 KiB
C#

using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class Killer {
public string? Name { get; set; }
public string? Rank { get; set; }
public string? Ship { get; set; }
}
public class DiedEntry : Entry {
private readonly List<Killer> killers = new List<Killer>();
public List<Killer> Killers => killers;
public Killer? Killer => killers.Count > 0 ? killers[0] : null;
public bool WasWing => killers.Count > 1;
protected override void Initialise() {
var wing = JSON.Value<JArray>("Killers");
if (wing != null) {
/* a wing killed us */
foreach (JObject child in wing.Children<JObject>()) {
Killer killer = new Killer {
Name = child.Value<string>("Name"),
Rank = child.Value<string>("Rank"),
Ship = child.Value<string>("Ship")
};
killers.Add(killer);
}
} else {
/* a single ship killed us */
Killer killer = new Killer {
Name = JSON.Value<string>("KillerName"),
Rank = JSON.Value<string>("KillerRank"),
Ship = JSON.Value<string>("KillerShip")
};
killers.Add(killer);
}
}
}