From 41a7782a7c6ffc70ee5c9d0953a319c8e06d1235 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 27 Jan 2022 23:19:10 +0100 Subject: [PATCH] provide system address for lookup of system specific influence gains --- DockedEntry.cs | 2 ++ FSDJumpEntry.cs | 13 +++++++------ MissionCompletedEntry.cs | 41 +++++++++++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/DockedEntry.cs b/DockedEntry.cs index a1c0c42..5485d88 100644 --- a/DockedEntry.cs +++ b/DockedEntry.cs @@ -4,11 +4,13 @@ namespace EDJournal { 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("StationName") ?? ""; StarSystem = JSON.Value("StarSystem") ?? ""; + SystemAddress = JSON.Value("SystemAddress") ?? 0; JObject faction = JSON.Value("StationFaction"); if (faction != null) { StationFaction = faction.Value("Name") ?? ""; diff --git a/FSDJumpEntry.cs b/FSDJumpEntry.cs index 9e31b49..389b6a2 100644 --- a/FSDJumpEntry.cs +++ b/FSDJumpEntry.cs @@ -2,17 +2,18 @@ namespace EDJournal { public class FSDJumpEntry : Entry { - private string starsystem = null; - private string systemfaction = null; protected override void Initialise() { - starsystem = JSON.Value("StarSystem"); + SystemAddress = JSON.Value("SystemAddress") ?? 0; + StarSystem = JSON.Value("StarSystem"); var faction = JSON.Value("SystemFaction"); if (faction != null) { - systemfaction = faction.Value("Name"); + SystemFaction = faction.Value("Name"); } } - public string StarSystem => starsystem; + public string StarSystem { get; set; } - public string SystemFaction => systemfaction; + public string SystemFaction { get; set; } + + public ulong SystemAddress { get; set; } } } diff --git a/MissionCompletedEntry.cs b/MissionCompletedEntry.cs index 3e39b4d..5dedad4 100644 --- a/MissionCompletedEntry.cs +++ b/MissionCompletedEntry.cs @@ -1,14 +1,17 @@ using System.Collections.Generic; using System.Text; +using System.Linq; using Newtonsoft.Json.Linq; namespace EDJournal { public class MissionCompletedEntry : Entry { - private Dictionary influences = new Dictionary(); + private Dictionary> influences = new Dictionary>(); private List affected = new List(); private string readable_name = null; private bool readable_name_generated = false; + public Dictionary> Influences => influences; + protected override void Initialise() { MissionID = JSON.Value("MissionID") ?? 0; Name = JSON.Value("Name"); @@ -38,12 +41,23 @@ namespace EDJournal { var influence = effect.Value("Influence"); if (influence == null || influence.Count == 0) { // No influence reward, happens sometimes, but we have to accept it - influences.Add(faction, ""); + influences.Add(faction, new Dictionary()); } else { foreach (var infl in influence.Children()) { infl.TryGetValue("Influence", out JToken result); - if (result != null && result.Type == JTokenType.String) { - influences.Add(faction, result.ToString()); + infl.TryGetValue("SystemAddress", out JToken systemaddr); + if (result != null && result.Type == JTokenType.String && + systemaddr != null && systemaddr.Type == JTokenType.Integer) { + ulong system = systemaddr.ToObject() ?? 0; + string inf = result.ToString(); + + if (!influences.ContainsKey(faction)) { + influences.Add(faction, new Dictionary()); + } + + if (!influences[faction].ContainsKey(system)) { + influences[faction].Add(system, inf); + } } } } @@ -110,11 +124,24 @@ namespace EDJournal { public string[] AffectedFactions => affected.ToArray(); public string GetInfluenceForFaction(string faction) { - if (influences.ContainsKey(faction)) { - return influences[faction]; + if (!influences.ContainsKey(faction)) { + return ""; } - return ""; + var inf = influences[faction]; + return string.Join("", inf.Values); + } + + public string GetInfluenceForFaction(string faction, ulong systemaddr) { + if (!influences.ContainsKey(faction)) { + return ""; + } + + if (!influences[faction].ContainsKey(systemaddr)) { + return ""; + } + + return influences[faction][systemaddr]; } } }