Compare commits

..

No commits in common. "6dbc46671362a01c5ca0e2f2c2e92c5f4bf43ced" and "df6b5bf10d6f3852770dfeebe6a2e8633d554109" have entirely different histories.

2 changed files with 40 additions and 44 deletions

View File

@ -5,56 +5,34 @@ 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, string> influences = new Dictionary<string, 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;
private string name = null;
private string commodity = null;
private int count = 0;
private int donated = 0;
private int id = 0;
protected override void Initialise() { protected override void Initialise() {
MissionID = JSON.Value<int?>("MissionID") ?? 0; id = JSON.Value<int?>("MissionID") ?? 0;
Name = JSON.Value<string>("Name"); name = JSON.Value<string>("Name");
if (JSON.ContainsKey("Commodity_Localised")) { if (JSON.ContainsKey("Commodity_Localised")) {
Commodity = JSON.Value<string>("Commodity_Localised"); commodity = JSON.Value<string>("Commodity_Localised");
} }
if (JSON.ContainsKey("Count")) { if (JSON.ContainsKey("Count")) {
Count = JSON.Value<int>("Count"); count = JSON.Value<int>("Count");
} }
if (JSON.ContainsKey("Donated")) { if (JSON.ContainsKey("Donated")) {
Donated = JSON.Value<int>("Donated"); donated = JSON.Value<int>("Donated");
} }
MakeHumanReadableName(); MakeHumanReadableName();
BuildInfluenceList();
} }
private void BuildInfluenceList() { public string Name => name;
influences.Clear(); public string Commodity => commodity;
affected.Clear(); public int Count => count;
public int MissionID => id;
var effects = JSON.Value<JArray>("FactionEffects");
foreach (var effect in effects.Children<JObject>()) {
string faction = effect.Value<string>("Faction");
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, "");
} else {
foreach (var infl in influence.Children<JObject>()) {
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() { private void MakeHumanReadableName() {
if (readable_name != null || Name == null) { if (readable_name != null || Name == null) {
@ -82,12 +60,12 @@ namespace EDJournal {
builder.Append(readable); builder.Append(readable);
} }
if (Count > 0 && Commodity != null) { if (count > 0 && commodity != null) {
builder.AppendFormat(" ({0} {1})", Count, Commodity); builder.AppendFormat(" ({0} {1})", count, commodity);
} }
if (Donated > 0) { if (donated > 0) {
builder.AppendFormat(" ({0})", Credits.FormatCredits(Donated)); builder.AppendFormat(" ({0})", Credits.FormatCredits(donated));
} }
readable_name = builder.ToString().Trim(); readable_name = builder.ToString().Trim();
@ -107,13 +85,33 @@ namespace EDJournal {
} }
} }
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 influences[faction];
} }
var effects = JSON.Value<JArray>("FactionEffects");
foreach (var effect in effects.Children<JObject>()) {
if (effect.GetValue("Faction").ToString() != faction) {
continue;
}
var influence = effect.Value<JArray>("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<JObject>()) {
infl.TryGetValue("Influence", out JToken result);
if (result != null && result.Type == JTokenType.String) {
influences.Add(faction, result.ToString());
return result.ToString();
}
}
}
return ""; return "";
} }
} }

View File

@ -50,8 +50,6 @@
<Mission Name="Mission_OnFoot_RebootRestore_MB_name">On Foot Reboot/Restore</Mission> <Mission Name="Mission_OnFoot_RebootRestore_MB_name">On Foot Reboot/Restore</Mission>
<Mission Name="Mission_OnFoot_Sabotage_Production_Covert_MB_name">On Foot Sabotage Production (Covert)</Mission> <Mission Name="Mission_OnFoot_Sabotage_Production_Covert_MB_name">On Foot Sabotage Production (Covert)</Mission>
<Mission Name="Mission_OnFoot_Salvage_MB_name">On Foot Salvage</Mission> <Mission Name="Mission_OnFoot_Salvage_MB_name">On Foot Salvage</Mission>
<Mission Name="Mission_PassengerBulk_AIDWORKER_ARRIVING">Aid Workers Seeking Transport</Mission>
<Mission Name="Mission_PassengerVIP">Passenger (VIP)</Mission>
<Mission Name="Mission_PassengerVIP_name">Passenger (VIP)</Mission> <Mission Name="Mission_PassengerVIP_name">Passenger (VIP)</Mission>
<Mission Name="Mission_PassengerVIP_Scientist_FAMINE_name">Passenger (VIP) (Famine)</Mission> <Mission Name="Mission_PassengerVIP_Scientist_FAMINE_name">Passenger (VIP) (Famine)</Mission>
<Mission Name="Mission_Rescue_Planet_name">Planet Rescue</Mission> <Mission Name="Mission_Rescue_Planet_name">Planet Rescue</Mission>