edjournal/DiedEntry.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2021-09-02 16:18:02 +02:00
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace EDJournal {
public class Killer {
private string name;
private string rank;
private string ship;
public string Name {
get => name;
set => name = value;
}
public string Rank {
get => rank;
set => rank = value;
}
public string Ship {
get => ship;
set => ship = value;
}
}
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);
}
}
}
}