From 2f07a8f2a91c5c7403a399bfab9af74d225f0a22 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Fri, 21 Jan 2022 20:37:21 +0100 Subject: [PATCH] give a list of affected factions --- MissionCompletedEntry.cs | 82 ++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/MissionCompletedEntry.cs b/MissionCompletedEntry.cs index 46c843b..3e39b4d 100644 --- a/MissionCompletedEntry.cs +++ b/MissionCompletedEntry.cs @@ -5,34 +5,56 @@ using Newtonsoft.Json.Linq; namespace EDJournal { public class MissionCompletedEntry : Entry { private Dictionary influences = new Dictionary(); + private List affected = new List(); private string readable_name = null; private bool readable_name_generated = false; - private string name = null; - private string commodity = null; - private int count = 0; - private int donated = 0; - private int id = 0; protected override void Initialise() { - id = JSON.Value("MissionID") ?? 0; - name = JSON.Value("Name"); + MissionID = JSON.Value("MissionID") ?? 0; + Name = JSON.Value("Name"); if (JSON.ContainsKey("Commodity_Localised")) { - commodity = JSON.Value("Commodity_Localised"); + Commodity = JSON.Value("Commodity_Localised"); } if (JSON.ContainsKey("Count")) { - count = JSON.Value("Count"); + Count = JSON.Value("Count"); } if (JSON.ContainsKey("Donated")) { - donated = JSON.Value("Donated"); + Donated = JSON.Value("Donated"); } MakeHumanReadableName(); + BuildInfluenceList(); } - public string Name => name; - public string Commodity => commodity; - public int Count => count; - public int MissionID => id; + private void BuildInfluenceList() { + influences.Clear(); + affected.Clear(); + + var effects = JSON.Value("FactionEffects"); + foreach (var effect in effects.Children()) { + string faction = effect.Value("Faction"); + affected.Add(faction); + + 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, ""); + } 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()); + } + } + } + } + } + + public string Name { get; set; } + public string Commodity { get; set; } + public int Count { get; set; } + public int Donated { get; set; } + public int MissionID { get; set; } private void MakeHumanReadableName() { if (readable_name != null || Name == null) { @@ -60,12 +82,12 @@ namespace EDJournal { builder.Append(readable); } - if (count > 0 && commodity != null) { - builder.AppendFormat(" ({0} {1})", count, commodity); + if (Count > 0 && Commodity != null) { + builder.AppendFormat(" ({0} {1})", Count, Commodity); } - if (donated > 0) { - builder.AppendFormat(" ({0})", Credits.FormatCredits(donated)); + if (Donated > 0) { + builder.AppendFormat(" ({0})", Credits.FormatCredits(Donated)); } readable_name = builder.ToString().Trim(); @@ -85,33 +107,13 @@ namespace EDJournal { } } + public string[] AffectedFactions => affected.ToArray(); + public string GetInfluenceForFaction(string faction) { if (influences.ContainsKey(faction)) { return influences[faction]; } - var effects = JSON.Value("FactionEffects"); - foreach (var effect in effects.Children()) { - if (effect.GetValue("Faction").ToString() != faction) { - continue; - } - - var influence = effect.Value("Influence"); - if (influence == null || influence.Count == 0) { - // No influence reward, happens on courier missions sometimes. - // There is always one point of rep, even if the mission won't state it - influences.Add(faction, "+"); - } - - foreach (var infl in influence.Children()) { - infl.TryGetValue("Influence", out JToken result); - if (result != null && result.Type == JTokenType.String) { - influences.Add(faction, result.ToString()); - return result.ToString(); - } - } - } - return ""; } }