From ce54430137fbc7e8172167f7c7ac22cd273cf9dd Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 24 Nov 2022 14:25:31 +0100 Subject: [PATCH] change abandoned and failed towards newest Mission --- EDPlayerJournal/BGS/MissionFailed.cs | 8 +++++--- EDPlayerJournal/BGS/Report.cs | 14 ++++---------- EDPlayerJournal/BGS/TransactionParser.cs | 8 ++++++-- .../Entries/MissionAbandonedEntry.cs | 6 ++++-- EDPlayerJournal/Entries/MissionFailedEntry.cs | 18 +++++++----------- EDPlayerJournal/Mission.cs | 12 ++++++++++++ 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/EDPlayerJournal/BGS/MissionFailed.cs b/EDPlayerJournal/BGS/MissionFailed.cs index 922c656..98770f2 100644 --- a/EDPlayerJournal/BGS/MissionFailed.cs +++ b/EDPlayerJournal/BGS/MissionFailed.cs @@ -28,8 +28,9 @@ public class MissionFailed : Transaction { } /* if it is the same mission name, the same faction and the same system, - * collate mission failures together */ - if (failed.Failed?.HumanReadableName == Failed?.HumanReadableName && + * collate mission failures together + */ + if (string.Compare(failed.Failed?.Mission?.Name, Failed?.Mission?.Name) == 0 && failed.Faction == Faction && failed.System == System) { return 0; @@ -50,7 +51,8 @@ public class MissionFailed : Transaction { builder.AppendFormat("{0}x Mission failed: \"{1}\"", Amount, - Failed.HumanReadableName != null ? Failed.HumanReadableName : Failed.Name + Failed?.Mission?.LocalisedName != null ? + Failed?.Mission?.LocalisedName : Failed?.Mission?.Name ); return builder.ToString(); diff --git a/EDPlayerJournal/BGS/Report.cs b/EDPlayerJournal/BGS/Report.cs index 6017e20..317bd38 100644 --- a/EDPlayerJournal/BGS/Report.cs +++ b/EDPlayerJournal/BGS/Report.cs @@ -423,11 +423,11 @@ public class Report { string? accepted_system; string? accepted_station; - if (failed == null) { + if (failed == null || failed.Mission == null) { continue; } - if (!acceptedMissions.TryGetValue(failed.MissionID, out accepted)) { + if (!acceptedMissions.TryGetValue(failed.Mission.MissionID, out accepted)) { OnLog?.Invoke("A mission failed which wasn't accepted in the given time frame. " + "Please adjust start date to when the mission was accepted to include it in the list."); continue; @@ -437,7 +437,7 @@ public class Report { continue; } - if (!acceptedSystems.TryGetValue(failed.MissionID, out accepted_address)) { + if (!acceptedSystems.TryGetValue(failed.Mission.MissionID, out accepted_address)) { OnLog?.Invoke(string.Format( "Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Mission.Name )); @@ -451,7 +451,7 @@ public class Report { continue; } - if (!acceptedStations.TryGetValue(failed.MissionID, out accepted_station)) { + if (!acceptedStations.TryGetValue(failed.Mission.MissionID, out accepted_station)) { OnLog?.Invoke(string.Format( "Unable to figure out in which station mission \"{0}\" was accepted.", accepted.Mission.Name )); @@ -466,12 +466,6 @@ public class Report { SystemAddress = accepted_address, }); - if (failed.HumanReadableName == null) { - OnLog?.Invoke("Human readable name for mission \"" + - failed.Name + - "\" was not recognised"); - } - /* Mission failed should be collated if they are in the same system/station */ collate = true; diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index d93450c..f278edb 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -389,14 +389,18 @@ internal class MissionFailedParser : TransactionParserPart { throw new NotImplementedException(); } - if (!context.AcceptedMissions.TryGetValue(entry.MissionID, out accepted)) { + if (entry.Mission == null) { + throw new InvalidJournalEntryException("No mission specified in mission failure"); + } + + if (!context.AcceptedMissions.TryGetValue(entry.Mission.MissionID, out accepted)) { transactions.AddIncomplete(new MissionFailed(), "Mission acceptance was not found" ); return; } - if (!context.AcceptedMissionLocation.TryGetValue(entry.MissionID, out accepted_location)) { + if (!context.AcceptedMissionLocation.TryGetValue(entry.Mission.MissionID, out accepted_location)) { transactions.AddIncomplete(new MissionFailed(), "Unable to figure out where failed mission was accepted" ); diff --git a/EDPlayerJournal/Entries/MissionAbandonedEntry.cs b/EDPlayerJournal/Entries/MissionAbandonedEntry.cs index 6aa8f91..49e70cc 100644 --- a/EDPlayerJournal/Entries/MissionAbandonedEntry.cs +++ b/EDPlayerJournal/Entries/MissionAbandonedEntry.cs @@ -1,7 +1,9 @@ namespace EDPlayerJournal.Entries; + public class MissionAbandonedEntry : Entry { - public ulong MissionID { get; set; } + public Mission? Mission { get; set; } + protected override void Initialise() { - MissionID = JSON.Value("MissionID") ?? 0; + Mission = Mission.FromMissionAbandoned(JSON); } } diff --git a/EDPlayerJournal/Entries/MissionFailedEntry.cs b/EDPlayerJournal/Entries/MissionFailedEntry.cs index c3bfa34..01b23c8 100644 --- a/EDPlayerJournal/Entries/MissionFailedEntry.cs +++ b/EDPlayerJournal/Entries/MissionFailedEntry.cs @@ -1,19 +1,15 @@ -namespace EDPlayerJournal.Entries; +namespace EDPlayerJournal.Entries; + public class MissionFailedEntry : Entry { - public string? Name { get; set; } - public ulong MissionID { get; set; } + /// + /// Fine imposed for mission failure. + /// public int Fine { get; set; } - public string? HumanReadableName { - get { - if (Name == null) return null; - return HumanReadableMissionName.MakeHumanReadableName(Name); - } - } + public Mission? Mission { get; set; } protected override void Initialise() { - Name = JSON.Value("Name"); - MissionID = JSON.Value("MissionID") ?? 0; + Mission = Mission.FromMissionFailed(JSON); Fine = JSON.Value("Fine") ?? 0; } } diff --git a/EDPlayerJournal/Mission.cs b/EDPlayerJournal/Mission.cs index f74ea98..5e591bc 100644 --- a/EDPlayerJournal/Mission.cs +++ b/EDPlayerJournal/Mission.cs @@ -186,4 +186,16 @@ public class Mission : IComparable { public static Mission FromMissionAccepted(JObject o) { return FromJSON(o); } + + public static Mission FromMissionAbandoned(JObject o) { + return FromJSON(o); + } + + public static Mission FromMissionFailed(JObject o) { + return FromJSON(o); + } + + public static Mission FromMissionCompleted(JObject o) { + return FromJSON(o); + } }