provide system address for lookup of system specific influence gains

This commit is contained in:
Florian Stinglmayr 2022-01-27 23:19:10 +01:00
parent 325e9ad1a7
commit 41a7782a7c
3 changed files with 43 additions and 13 deletions

View File

@ -4,11 +4,13 @@ namespace EDJournal {
public class DockedEntry : Entry { public class DockedEntry : Entry {
public string StationName { get; set; } public string StationName { get; set; }
public string StarSystem { get; set; } public string StarSystem { get; set; }
public ulong SystemAddress { get; set; }
public string StationFaction { get; set; } public string StationFaction { get; set; }
protected override void Initialise() { protected override void Initialise() {
StationName = JSON.Value<string>("StationName") ?? ""; StationName = JSON.Value<string>("StationName") ?? "";
StarSystem = JSON.Value<string>("StarSystem") ?? ""; StarSystem = JSON.Value<string>("StarSystem") ?? "";
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
JObject faction = JSON.Value<JObject>("StationFaction"); JObject faction = JSON.Value<JObject>("StationFaction");
if (faction != null) { if (faction != null) {
StationFaction = faction.Value<string>("Name") ?? ""; StationFaction = faction.Value<string>("Name") ?? "";

View File

@ -2,17 +2,18 @@
namespace EDJournal { namespace EDJournal {
public class FSDJumpEntry : Entry { public class FSDJumpEntry : Entry {
private string starsystem = null;
private string systemfaction = null;
protected override void Initialise() { protected override void Initialise() {
starsystem = JSON.Value<string>("StarSystem"); SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
StarSystem = JSON.Value<string>("StarSystem");
var faction = JSON.Value<JObject>("SystemFaction"); var faction = JSON.Value<JObject>("SystemFaction");
if (faction != null) { if (faction != null) {
systemfaction = faction.Value<string>("Name"); SystemFaction = faction.Value<string>("Name");
} }
} }
public string StarSystem => starsystem; public string StarSystem { get; set; }
public string SystemFaction => systemfaction; public string SystemFaction { get; set; }
public ulong SystemAddress { get; set; }
} }
} }

View File

@ -1,14 +1,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Linq;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace EDJournal { namespace EDJournal {
public class MissionCompletedEntry : Entry { public class MissionCompletedEntry : Entry {
private Dictionary<string, string> influences = new Dictionary<string, string>(); private Dictionary<string, Dictionary<ulong, string>> influences = new Dictionary<string, Dictionary<ulong, string>>();
private List<string> affected = new List<string>(); private List<string> affected = new List<string>();
private string readable_name = null; private string readable_name = null;
private bool readable_name_generated = false; private bool readable_name_generated = false;
public Dictionary<string, Dictionary<ulong, string>> Influences => influences;
protected override void Initialise() { protected override void Initialise() {
MissionID = JSON.Value<int?>("MissionID") ?? 0; MissionID = JSON.Value<int?>("MissionID") ?? 0;
Name = JSON.Value<string>("Name"); Name = JSON.Value<string>("Name");
@ -38,12 +41,23 @@ namespace EDJournal {
var influence = effect.Value<JArray>("Influence"); var influence = effect.Value<JArray>("Influence");
if (influence == null || influence.Count == 0) { if (influence == null || influence.Count == 0) {
// No influence reward, happens sometimes, but we have to accept it // No influence reward, happens sometimes, but we have to accept it
influences.Add(faction, ""); influences.Add(faction, new Dictionary<ulong, string>());
} else { } else {
foreach (var infl in influence.Children<JObject>()) { foreach (var infl in influence.Children<JObject>()) {
infl.TryGetValue("Influence", out JToken result); infl.TryGetValue("Influence", out JToken result);
if (result != null && result.Type == JTokenType.String) { infl.TryGetValue("SystemAddress", out JToken systemaddr);
influences.Add(faction, result.ToString()); 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);
}
} }
} }
} }
@ -110,11 +124,24 @@ namespace EDJournal {
public string[] AffectedFactions => affected.ToArray(); public string[] AffectedFactions => affected.ToArray();
public string GetInfluenceForFaction(string faction) { public string GetInfluenceForFaction(string faction) {
if (influences.ContainsKey(faction)) { if (!influences.ContainsKey(faction)) {
return influences[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];
}
} }
} }