Add project files.

This commit is contained in:
2022-11-01 18:01:28 +01:00
parent f7069a830d
commit dadae23393
73 changed files with 7076 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EDPlayerJournal.Entries;
/**
* This entry appears whenever a bounty is awarded.
*/
public class BountyEntry : Entry {
private string? victimfaction = null;
private string? target = null;
private int rewards = 0;
protected override void Initialise() {
rewards = JSON.Value<int?>("TotalReward") ?? 0;
victimfaction = JSON.Value<string>("VictimFaction") ?? "";
target = JSON.Value<string>("Target_Localised") ?? "";
}
public string? VictimFaction => victimfaction;
public string? Target => target;
public int Rewards => rewards;
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EDPlayerJournal.Entries;
public class CommanderEntry : Entry {
public string? Name { get; set; }
public string? FID { get; set; }
protected override void Initialise() {
Name = JSON.Value<string>("Name") ?? "";
FID = JSON.Value<string>("FID") ?? "";
}
}

View File

@@ -0,0 +1,22 @@
namespace EDPlayerJournal.Entries;
public class CommitCrimeEntry : Entry {
public string? CrimeType { get; set; }
public string? Faction { get; set; }
public string? Victim { get; set; }
public string? VictimLocalised { get; set; }
public long Bounty { get; set; }
public long Fine { get; set; }
protected override void Initialise() {
CrimeType = JSON.Value<string>("CrimeType") ?? "assault";
Faction = JSON.Value<string>("Faction") ?? "";
Victim = JSON.Value<string>("Victim") ?? "";
VictimLocalised = JSON.Value<string>("Victim_Localised") ?? "";
Bounty = JSON.Value<long?>("Bounty") ?? 0;
Fine = JSON.Value<long?>("Fine") ?? 0;
}
public bool IsMurder {
get { return CrimeType?.CompareTo(CrimeTypes.Murder) == 0 || CrimeType?.CompareTo(CrimeTypes.OnFootMurder) == 0; }
}
}

View File

@@ -0,0 +1,39 @@
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);
}
}
}

View File

@@ -0,0 +1,19 @@
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class DockedEntry : Entry {
public string? StationName { get; set; }
public string? StarSystem { get; set; }
public ulong? SystemAddress { get; set; }
public string? StationFaction { get; set; }
protected override void Initialise() {
StationName = JSON.Value<string>("StationName");
StarSystem = JSON.Value<string>("StarSystem");
SystemAddress = JSON.Value<ulong?>("SystemAddress");
JObject? faction = JSON.Value<JObject>("StationFaction");
if (faction != null) {
StationFaction = faction.Value<string>("Name") ?? "";
}
}
}

View File

@@ -0,0 +1,130 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class InvalidJournalEntryException : Exception {
public InvalidJournalEntryException() { }
public InvalidJournalEntryException(string message) : base(message) { }
}
/// <summary>
/// Base class for a single entry within the player journal. If no specific sub class is available
/// this class gives basic information, such as EventType or date when it happened. It also allows
/// base classes access to the underlying JSON object. Base classes should be named after the event
/// type that they map + Entry. So "FSDJump" event is handled by FSDJumpEntry.
/// </summary>
public class Entry {
private static readonly Dictionary<string, Type> classes = new Dictionary<string, Type> {
{ Events.Bounty, typeof(BountyEntry) },
{ Events.Commander, typeof(CommanderEntry) },
{ Events.CommitCrime, typeof(CommitCrimeEntry) },
{ Events.Died, typeof(DiedEntry) },
{ Events.Docked, typeof(DockedEntry) },
{ Events.FactionKillBond, typeof(FactionKillBondEntry) },
{ Events.FSDJump, typeof(FSDJumpEntry) },
{ Events.HullDamage, typeof(HullDamageEntry) },
{ Events.LoadGame, typeof(LoadGameEntry) },
{ Events.Location, typeof(LocationEntry) },
{ Events.MarketBuy, typeof(MarketBuyEntry) },
{ Events.MarketSell, typeof(MarketSellEntry) },
{ Events.MissionAbandoned, typeof(MissionAbandonedEntry) },
{ Events.MissionAccepted, typeof(MissionAcceptedEntry) },
{ Events.MissionCompleted, typeof(MissionCompletedEntry) },
{ Events.MissionFailed, typeof(MissionFailedEntry) },
{ Events.MissionRedirected, typeof(MissionRedirectedEntry) },
{ Events.MultiSellExplorationData, typeof(MultiSellExplorationDataEntry) },
{ Events.RedeemVoucher, typeof(RedeemVoucherEntry) },
{ Events.SearchAndRescue, typeof(SearchAndRescueEntry) },
{ Events.SellExplorationData, typeof(SellExplorationDataEntry) },
{ Events.SellMicroResources, typeof(SellMicroResourcesEntry) },
{ Events.SellOrganicData, typeof(SellOrganicDataEntry) },
{ Events.ShieldState, typeof(ShieldStateEntry) },
{ Events.ShipTargeted, typeof(ShipTargetedEntry) },
{ Events.UnderAttack, typeof(UnderAttackEntry) },
};
private string? eventtype = null;
private string? datetime = null;
private DateTime timestamp;
private string? jsonstr = null;
protected JObject? json = null;
public Entry() {
}
public static Entry? Parse(string journalline) {
var json = JObject.Parse(journalline);
if (json == null) {
return null;
}
return Parse(json);
}
public static Entry? Parse(JObject json) {
string? event_name = json.Value<string?>("event");
if (event_name == null) {
return null;
}
classes.TryGetValue(event_name, out Type? classhandler);
if (classhandler == null) {
// No specific handler available so use base class
classhandler = typeof(Entry);
}
Entry? obj = (Entry?)Activator.CreateInstance(classhandler);
if (obj == null) {
return null;
}
obj.InternalInitialise(json);
obj.Initialise();
return obj;
}
private void InternalInitialise(JObject jobject) {
this.json = jobject;
this.jsonstr = json.ToString(formatting: Formatting.None);
this.eventtype = json.Value<string>("event");
// Do not change this or JSON parser will conver the string to
// datetime object and call .ToString() on it which changes the
// date and time format
this.datetime = json.GetValue("timestamp")?.ToString();
if (!string.IsNullOrEmpty(this.datetime)) {
this.timestamp = DateTime.Parse(this.datetime);
}
}
protected virtual void Initialise() {
}
public bool Is(string eventtype) {
if (eventtype == null || this.eventtype == null) {
return false;
}
return String.Equals(this.eventtype, eventtype, StringComparison.OrdinalIgnoreCase);
}
public string? Event {
get { return eventtype; }
}
public DateTime Timestamp {
get { return timestamp; }
}
public JObject JSON {
get { return this.json ?? new JObject(); }
}
public override string ToString() {
return jsonstr ?? "";
}
}

View File

@@ -0,0 +1,31 @@
namespace EDPlayerJournal.Entries;
public class Events {
public static readonly string Bounty = "Bounty";
public static readonly string Commander = "Commander";
public static readonly string CommitCrime = "CommitCrime";
public static readonly string Died = "Died";
public static readonly string Docked = "Docked";
public static readonly string FactionKillBond = "FactionKillBond";
public static readonly string FighterDestroyed = "FighterDestroyed";
public static readonly string FSDJump = "FSDJump";
public static readonly string HullDamage = "HullDamage";
public static readonly string LoadGame = "LoadGame";
public static readonly string Location = "Location";
public static readonly string MarketBuy = "MarketBuy";
public static readonly string MarketSell = "MarketSell";
public static readonly string MissionAbandoned = "MissionAbandoned";
public static readonly string MissionAccepted = "MissionAccepted";
public static readonly string MissionCompleted = "MissionCompleted";
public static readonly string MissionFailed = "MissionFailed";
public static readonly string MissionRedirected = "MissionRedirected";
public static readonly string MultiSellExplorationData = "MultiSellExplorationData";
public static readonly string RedeemVoucher = "RedeemVoucher";
public static readonly string SearchAndRescue = "SearchAndRescue";
public static readonly string SellExplorationData = "SellExplorationData";
public static readonly string SellMicroResources = "SellMicroResources";
public static readonly string SellOrganicData = "SellOrganicData";
public static readonly string ShieldState = "ShieldState";
public static readonly string ShipTargeted = "ShipTargeted";
public static readonly string UnderAttack = "UnderAttack";
}

View File

@@ -0,0 +1,35 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class FSDJumpEntry : Entry {
protected override void Initialise() {
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
StarSystem = JSON.Value<string>("StarSystem");
var pos = JSON.Value<JArray>("SarPos");
if (pos != null) {
StarPos = pos.ToObject<long[]>();
}
var faction = JSON.Value<JObject>("SystemFaction");
if (faction != null) {
SystemFaction = faction.Value<string>("Name");
}
var factions = JSON.Value<JArray>("Factions");
if (factions != null) {
foreach (JObject system_faction in factions) {
Faction? f = Faction.FromJSON(system_faction);
if (f != null) {
SystemFactions.Add(f);
}
}
}
}
public long[]? StarPos { get; set; }
public string? StarSystem { get; set; }
public string? SystemFaction { get; set; }
public ulong SystemAddress { get; set; }
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
}

View File

@@ -0,0 +1,13 @@
namespace EDPlayerJournal.Entries;
public class FactionKillBondEntry : Entry {
public int Reward { get; set; }
public string? AwardingFaction { get; set; }
public string? VictimFaction { get; set; }
protected override void Initialise() {
Reward = JSON.Value<int?>("Reward") ?? 0;
AwardingFaction = JSON.Value<string>("AwardingFaction");
VictimFaction = JSON.Value<string>("VictimFaction");
}
}

View File

@@ -0,0 +1,16 @@
namespace EDPlayerJournal.Entries;
public class HullDamageEntry : Entry {
private double health = 0;
private bool playerpilot = false;
private bool fighter = false;
public double Health => health;
public bool PlayerPilot => playerpilot;
public bool Fighter => fighter;
protected override void Initialise() {
health = JSON.Value<double?>("Health") ?? 100.0;
playerpilot = JSON.Value<bool?>("PlayerPilot") ?? true;
fighter = JSON.Value<bool?>("Fighter") ?? false;
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EDPlayerJournal.Entries;
public class LoadGameEntry : Entry {
public string? Commander { get; set; }
public string? FID { get; set; }
public bool Horizons { get; set; }
public bool Odyssey { get; set; }
public string? Ship { get; set; }
public long ShipID { get; set; }
public bool StartLanded { get; set; }
public bool StartDead { get; set; }
public string? GameMode { get; set; }
public string? Group { get; set; }
public long Credits { get; set; }
public long Loan { get; set; }
public string? ShipName { get; set; }
public string? ShipIdent { get; set; }
public double FuelLevel { get; set; }
public double FuelCapacity { get; set; }
protected override void Initialise() {
Commander = JSON.Value<string>("Commander");
FID = JSON.Value<string>("FID");
// Game
Horizons = JSON.Value<bool?>("Horizons") ?? false;
Odyssey = JSON.Value<bool?>("Odyssey") ?? false;
// Ships
Ship = JSON.Value<string>("Ship");
ShipID = JSON.Value<long?>("ShipID") ?? 0;
ShipName = JSON.Value<string>("ShipName");
ShipIdent = JSON.Value<string>("ShipIdent");
// Fuel
FuelLevel = JSON.Value<double?>("FuelLevel") ?? 0.0;
FuelCapacity = JSON.Value<double?>("FuelCapacity") ?? 0.0;
// Landed/Dead
StartLanded = JSON.Value<bool?>("StartLanded") ?? false;
StartDead = JSON.Value<bool?>("StartDead") ?? false;
// GameMode
GameMode = JSON.Value<string>("GameMode");
// Group
Group = JSON.Value<string>("Group");
// Wealth
Credits = JSON.Value<long?>("Credits") ?? 0;
Loan = JSON.Value<long?>("Loan") ?? 0;
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class LocationEntry : Entry {
public string? StarSystem { get; set; }
public string? SystemFaction { get; set; }
public string? StationName { get; set; }
public ulong SystemAddress { get; set; }
public string? Body { get; set; }
public bool Docked { get; set; }
public long[]? StarPos { get; set; }
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
protected override void Initialise() {
StarSystem = JSON.Value<string>("StarSystem") ?? "";
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
Docked = JSON.Value<bool?>("Docked") ?? false;
StationName = JSON.Value<string>("StationName") ?? "";
var pos = JSON.Value<JArray>("StarPos");
if (pos != null) {
StarPos = pos.ToObject<long[]>();
}
JObject? systemfaction = JSON.Value<JObject>("SystemFaction");
if (systemfaction != null) {
SystemFaction = systemfaction.Value<string>("Name") ?? "";
}
JArray? factions = JSON.Value<JArray>("Factions");
if (factions != null) {
foreach (JObject system_faction in factions) {
Faction? f = Faction.FromJSON(system_faction);
if (f != null) {
SystemFactions.Add(f);
}
}
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EDPlayerJournal.Entries;
public class MarketBuyEntry : Entry {
public string? Type { get; set; }
public string? TypeLocalised { get; set; }
public long Count { get; set; }
public long BuyPrice { get; set; }
public long TotalCost { get; set; }
protected override void Initialise() {
Type = JSON.Value<string>("Type");
TypeLocalised = JSON.Value<string>("Type_Localised");
Count = JSON.Value<long?>("Count") ?? 0;
BuyPrice = JSON.Value<long?>("BuyPrice") ?? 0;
TotalCost = JSON.Value<long?>("TotalCost") ?? 0;
}
}

View File

@@ -0,0 +1,50 @@
namespace EDPlayerJournal.Entries;
public class MarketSellEntry : Entry {
/// <summary>
/// Total value
/// </summary>
public int TotalSale { get; set; }
/// <summary>
/// How many.
/// </summary>
public int Count { get; set; }
/// <summary>
/// Average price paid
/// </summary>
public int AvgPricePaid { get; set; }
/// <summary>
/// Cargo type
/// </summary>
public string? Type { get; set; }
/// <summary>
/// Localised name of the cargo sold, may be null.
/// </summary>
public string? TypeLocalised { get; set; }
/// <summary>
/// Price per unit
/// </summary>
public int SellPrice { get; set; }
/// <summary>
/// Whether the goods were illegal in the target system.
/// </summary>
public bool IllegalGoods { get; set; }
/// <summary>
/// Whether the goods were stolen
/// </summary>
public bool StolenGoods { get; set; }
/// <summary>
/// Whether the goods were sold to the black market
/// </summary>
public bool BlackMarket { get; set; }
protected override void Initialise() {
Type = JSON.Value<string>("Type");
TypeLocalised = JSON.Value<string>("Type_Localised");
TotalSale = JSON.Value<int?>("TotalSale") ?? 0;
Count = JSON.Value<int?>("Count") ?? 0;
AvgPricePaid = JSON.Value<int?>("AvgPricePaid") ?? 0;
IllegalGoods = JSON.Value<bool?>("IllegalGoods") ?? false;
StolenGoods = JSON.Value<bool?>("StolenGoods") ?? false;
BlackMarket = JSON.Value<bool?>("BlackMarket") ?? false;
}
}

View File

@@ -0,0 +1,7 @@
namespace EDPlayerJournal.Entries;
public class MissionAbandonedEntry : Entry {
public ulong MissionID { get; set; }
protected override void Initialise() {
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
}
}

View File

@@ -0,0 +1,22 @@
namespace EDPlayerJournal.Entries;
public class MissionAcceptedEntry : Entry {
public string? Faction { get; set; }
public string? TargetFaction { get; set; }
public string? Name { get; set; }
public string? LocalisedName { get; set; }
public string? LocalisedTargetType { get; set; }
public int KillCount { get; set; }
public ulong MissionID { get; set; }
public long Reward { get; set; }
protected override void Initialise() {
Faction = JSON.Value<string>("Faction");
TargetFaction = JSON.Value<string>("TargetFaction");
Name = JSON.Value<string>("Name");
LocalisedName = JSON.Value<string>("LocalisedName");
LocalisedTargetType = JSON.Value<string>("TargetType_Localised");
KillCount = JSON.Value<int?>("KillCount") ?? 0;
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
Reward = JSON.Value<long?>("Reward") ?? 0;
}
}

View File

@@ -0,0 +1,159 @@
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class MissionCompletedEntry : Entry {
public Dictionary<string, Dictionary<ulong, string>> Influences { get; set; } = new Dictionary<string, Dictionary<ulong, string>>();
private List<string> Affected { get; set; } = new List<string>();
private string? readable_name = null;
private bool readable_name_generated = false;
protected override void Initialise() {
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
Name = JSON.Value<string>("Name");
Faction = JSON.Value<string>("Faction") ?? "";
TargetFaction = JSON.Value<string>("TargetFaction") ?? "";
if (JSON.ContainsKey("Commodity_Localised")) {
Commodity = JSON.Value<string>("Commodity_Localised");
}
if (JSON.ContainsKey("Count")) {
Count = JSON.Value<int>("Count");
}
if (JSON.ContainsKey("Donated")) {
Donated = JSON.Value<int>("Donated");
}
MakeHumanReadableName();
BuildInfluenceList();
}
private void BuildInfluenceList() {
Influences.Clear();
Affected.Clear();
var effects = JSON.Value<JArray>("FactionEffects");
if (effects == null) {
return;
}
foreach (var effect in effects.Children<JObject>()) {
string? faction = effect.Value<string>("Faction");
if (faction == null) {
continue;
}
Affected.Add(faction);
var influence = effect.Value<JArray>("Influence");
if (influence == null || influence.Count == 0) {
// No influence reward, happens sometimes, but we have to accept it
Influences.Add(faction, new Dictionary<ulong, string>());
} else {
foreach (var infl in influence.Children<JObject>()) {
infl.TryGetValue("Influence", out JToken? result);
infl.TryGetValue("SystemAddress", out JToken? systemaddr);
if (result != null && result.Type == JTokenType.String &&
systemaddr != null && systemaddr.Type == JTokenType.Integer) {
ulong system = systemaddr.ToObject<ulong?>() ?? 0;
string inf = result.ToString();
if (!Influences.ContainsKey(faction)) {
Influences.Add(faction, new Dictionary<ulong, string>());
}
if (!Influences[faction].ContainsKey(system)) {
Influences[faction].Add(system, inf);
}
}
}
}
}
}
public string? Name { get; set; }
public string? Commodity { get; set; }
public int? Count { get; set; }
public int? Donated { get; set; }
public ulong? MissionID { get; set; }
public string? Faction { get; set; }
public string? TargetFaction { get; set; }
private void MakeHumanReadableName() {
if (readable_name != null || Name == null) {
return;
}
string? readable = HumanReadableMissionName.MakeHumanReadableName(Name);
StringBuilder builder = new StringBuilder();
if (readable == null) {
builder = new StringBuilder(Name);
builder.Replace("Mission_", "");
builder.Replace("_name", "");
builder.Replace("_MB", "");
builder.Replace('_', ' ');
builder.Replace("Illegal", " (Illegal)");
builder.Replace("OnFoot", "On Foot");
builder.Replace(" BS", "");
builder.Replace("HackMegaship", "Hack Megaship");
builder.Replace("Boom", "");
builder.Replace("RebootRestore", "Reboot/Restore");
builder.Replace("CivilLiberty", "");
readable_name_generated = true;
} else {
builder.Append(readable);
}
if (Count > 0 && Commodity != null) {
builder.AppendFormat(" ({0} {1})", Count, Commodity);
}
if (Donated != null || Donated > 0) {
builder.AppendFormat(" ({0})", Credits.FormatCredits(Donated ?? 0));
}
readable_name = builder.ToString().Trim();
}
public string? HumanReadableName {
get {
MakeHumanReadableName();
return readable_name;
}
}
public bool HumanReadableNameWasGenerated {
get {
MakeHumanReadableName();
return readable_name_generated;
}
}
public string[] AffectedFactions => Affected.ToArray();
public string? GetInfluenceForFaction(string faction) {
if (Influences == null || !Influences.ContainsKey(faction)) {
return null;
}
var inf = Influences[faction];
return string.Join("", inf.Values);
}
public string? GetInfluenceForFaction(string faction, ulong systemaddr) {
if (!Influences.ContainsKey(faction)) {
return null;
}
if (!Influences[faction].ContainsKey(systemaddr)) {
return null;
}
return Influences[faction][systemaddr];
}
}

View File

@@ -0,0 +1,19 @@
namespace EDPlayerJournal.Entries;
public class MissionFailedEntry : Entry {
public string? Name { get; set; }
public ulong MissionID { get; set; }
public int Fine { get; set; }
public string? HumanReadableName {
get {
if (Name == null) return null;
return HumanReadableMissionName.MakeHumanReadableName(Name);
}
}
protected override void Initialise() {
Name = JSON.Value<string>("Name");
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
Fine = JSON.Value<int?>("Fine") ?? 0;
}
}

View File

@@ -0,0 +1,16 @@
namespace EDPlayerJournal.Entries;
public class MissionRedirectedEntry : Entry {
public int MissionID { get; set; } = 0;
public string? Name { get; set; }
public string? NewDestinationStation { get; set; }
public string? NewDestinationSystem { get; set; }
public string? OldDestinationSystem { get; set; }
protected override void Initialise() {
MissionID = (JSON.Value<int?>("MissionID") ?? 0);
Name = JSON.Value<string>("Name");
NewDestinationStation = JSON.Value<string>("NewDestinationStation");
NewDestinationSystem = JSON.Value<string>("NewDestinationSystem");
OldDestinationSystem = JSON.Value<string>("OldDestinationSystem");
}
}

View File

@@ -0,0 +1,8 @@
namespace EDPlayerJournal.Entries;
public class MultiSellExplorationDataEntry : Entry {
protected override void Initialise() {
TotalEarnings = (JSON.Value<int?>("TotalEarnings") ?? 0);
}
public int TotalEarnings { get; set; } = 0;
}

View File

@@ -0,0 +1,42 @@
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace EDPlayerJournal.Entries;
public class RedeemVoucherEntry : Entry {
protected override void Initialise() {
Amount = (JSON.Value<int?>("Amount") ?? 0);
Type = JSON.Value<string>("Type");
/* according to API, there should be a Factions structure */
JToken? factions = JSON.GetValue("Factions");
if (factions != null) {
foreach (JObject faction in factions.Children<JObject>()) {
string? faction_name = faction.Value<string>("Faction");
long? faction_bounty = faction.Value<long?>("Amount");
if (faction_name == null || faction_name.Length <= 0 || faction_bounty == null) {
continue;
}
Factions.Add(faction_name);
if (!FactionBounties.ContainsKey(faction_name)) {
FactionBounties[faction_name] = 0;
}
FactionBounties[faction_name] += (faction_bounty ?? 0);
}
}
/* but there also might be just a Faction entry */
string? single_faction = JSON.Value<string>("Faction");
if (single_faction != null) {
Factions.Add(single_faction);
if (!FactionBounties.ContainsKey(single_faction)) {
FactionBounties[single_faction] = 0;
}
FactionBounties[single_faction] += Amount;
}
}
public int Amount { get; set; } = 0;
public string? Type { get; set; } = "Bounty";
public List<string> Factions { get; set; } = new List<string>();
public Dictionary<string, long> FactionBounties { get; set; } = new Dictionary<string, long>();
}

View File

@@ -0,0 +1,18 @@
namespace EDPlayerJournal.Entries;
public class SearchAndRescueEntry : Entry {
public long MarketID { get; set; }
public string? Name { get; set; }
public string? NameLocalised { get; set; }
public long Count { get; set; }
public long Reward { get; set; }
protected override void Initialise() {
MarketID = JSON.Value<long?>("MarketID") ?? 0;
Name = JSON.Value<string>("Name") ?? "";
NameLocalised = JSON.Value<string>("Name_Localised");
Count = JSON.Value<long?>("Count") ?? 0;
Reward = JSON.Value<long?>("Reward") ?? 0;
}
}

View File

@@ -0,0 +1,29 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Linq;
namespace EDPlayerJournal.Entries;
public class SellExplorationDataEntry : Entry {
public long BaseValue { get; set; }
public long Bonus { get; set; }
public long TotalEarnings { get; set; }
public List<string> Systems { get; set; } = new List<string>();
public List<string> Discovered { get; set; } = new List<string>();
protected override void Initialise() {
BaseValue = JSON.Value<long?>("BaseValue") ?? 0;
Bonus = JSON.Value<long?>("Bonus") ?? 0;
TotalEarnings = JSON.Value<long?>("TotalEarnings") ?? 0;
var sys = JSON.Value<JArray>("Systems");
if (sys != null) {
Systems = sys.Select(x => x.ToString()).ToList<string>();
}
var dis = JSON.Value<JArray>("Discovered");
if (dis != null) {
Discovered = dis.Select(x => x.ToString()).ToList<string>();
}
}
}

View File

@@ -0,0 +1,8 @@
namespace EDPlayerJournal.Entries;
public class SellMicroResourcesEntry : Entry {
protected override void Initialise() {
Price = JSON.Value<int>("Price");
}
public int Price { get; set; }
}

View File

@@ -0,0 +1,42 @@
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal.Entries;
public class BioData {
public string? Genus { get; set; }
public string? GenusLocalised { get; set; }
public string? Species { get; set; }
public string? SpeciesLocalised { get; set; }
public long Value { get; set; } = 0;
public long Bonus { get; set; } = 0;
public long TotalValue => Value + Bonus;
}
public class SellOrganicDataEntry : Entry {
public long MarketID { get; set; }
public List<BioData> BioData => new List<BioData>();
protected override void Initialise() {
MarketID = JSON.Value<long?>("MarketID") ?? 0;
var biodata = JSON.Value<JArray>("BioData");
if (biodata == null) {
return;
}
foreach (JObject item in biodata) {
BioData data = new BioData {
Bonus = item.Value<long?>("Bonus") ?? 0,
Value = item.Value<long?>("Value") ?? 0,
Species = item.Value<string>("Species"),
Genus = item.Value<string>("Genus"),
GenusLocalised = item.Value<string>("Genus_Localised"),
SpeciesLocalised = item.Value<string>("Species_Localised")
};
BioData.Add(data);
}
}
public long TotalValue {
get { return BioData.Sum(x => x.TotalValue); }
}
}

View File

@@ -0,0 +1,7 @@
namespace EDPlayerJournal.Entries;
public class ShieldStateEntry : Entry {
public bool ShieldsUp { get; set; } = false;
protected override void Initialise() {
ShieldsUp = JSON.Value<bool?>("ShieldsUp") ?? true;
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
namespace EDPlayerJournal.Entries;
public class ShipTargetedEntry : Entry {
public string? Ship { get; set; }
public long ScanStage { get; set; }
public string? PilotName { get; set; }
public string? PilotNameLocalised { get; set; }
public string? PilotRank { get; set; }
public double ShieldHealth { get; set; }
public double HullHealth { get; set; }
public long Bounty { get; set; }
public string? LegalStatus { get; set; }
public string? Faction { get; set; }
public string? Power { get; set; }
protected override void Initialise() {
ScanStage = JSON.Value<long?>("ScanStage") ?? 0;
Ship = JSON.Value<string>("Ship_Localised");
PilotName = JSON.Value<string>("PilotName");
PilotNameLocalised = JSON.Value<string>("PilotName_Localised");
PilotRank = JSON.Value<string>("PilotRank");
ShieldHealth = JSON.Value<double?>("ShieldHealth") ?? 0.0;
HullHealth = JSON.Value<double?>("HullHealth") ?? 0.0;
Bounty = JSON.Value<long?>("Bounty") ?? 0;
LegalStatus = JSON.Value<string>("LegalStatus") ?? "Clean";
Faction = JSON.Value<string>("Faction");
Power = JSON.Value<string>("Power");
}
}

View File

@@ -0,0 +1,7 @@
namespace EDPlayerJournal.Entries;
public class UnderAttackEntry : Entry {
public string? Target { get; set; }
protected override void Initialise() {
Target = JSON.Value<string>("Target");
}
}