From 6dda7cfde4388d6b2d0a9a1ab1f356d40ebf5999 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Fri, 12 Nov 2021 22:23:40 +0100 Subject: [PATCH] implement failed missions which give negative INF --- BGS/GenericDiscordLog.cs | 21 +++++++++++++++++++++ BGS/MissionCompleted.cs | 8 +++----- BGS/MissionFailed.cs | 28 ++++++++++++++++++++++++++++ BGS/Report.cs | 22 +++++++++++++++++++++- EliteBGS.csproj | 1 + 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 BGS/MissionFailed.cs diff --git a/BGS/GenericDiscordLog.cs b/BGS/GenericDiscordLog.cs index c2a39b8..af86147 100644 --- a/BGS/GenericDiscordLog.cs +++ b/BGS/GenericDiscordLog.cs @@ -103,6 +103,24 @@ namespace EliteBGS.BGS { return builder.ToString(); } + private string BuildFailedMissions(Objective objective) { + MissionFailed[] missions = objective.LogEntries.OfType().ToArray(); + StringBuilder builder = new StringBuilder(); + + if (missions.Length <= 0) { + return ""; + } + + foreach (MissionFailed failed in missions) { + MissionFailedEntry f = failed.Failed; + builder.AppendFormat("Failed mission \"{0}\"\n", + f.HumanReadableName == null ? f.Name : f.HumanReadableName + ); + } + + return builder.ToString(); + } + private string BuildMissionList(Objective objective) { Dictionary> collated = new Dictionary>(); StringBuilder output = new StringBuilder(); @@ -190,6 +208,9 @@ namespace EliteBGS.BGS { var missions = BuildMissionList(objective); entries.Append(missions); + var failed = BuildFailedMissions(objective); + entries.Append(failed); + var vouchers = BuildVouchers(objective); entries.Append(vouchers); diff --git a/BGS/MissionCompleted.cs b/BGS/MissionCompleted.cs index fb8afa7..d1ae6f7 100644 --- a/BGS/MissionCompleted.cs +++ b/BGS/MissionCompleted.cs @@ -3,11 +3,9 @@ using EDJournal; namespace EliteBGS.BGS { public class MissionCompleted : LogEntry { - public MissionCompleted(MissionCompletedEntry e, string system, string station) { - this.Entries.Add(e); - this.Faction = e.JSON.GetValue("Faction").ToString(); - this.System = system; - this.Station = station; + public MissionCompleted(MissionCompletedEntry e) { + Entries.Add(e); + Faction = e.JSON.GetValue("Faction").ToString(); } public string MissionName { diff --git a/BGS/MissionFailed.cs b/BGS/MissionFailed.cs new file mode 100644 index 0000000..e734331 --- /dev/null +++ b/BGS/MissionFailed.cs @@ -0,0 +1,28 @@ +using System.Text; +using EDJournal; + +namespace EliteBGS.BGS { + public class MissionFailed : LogEntry { + public MissionFailedEntry Failed { get; set; } + public MissionAcceptedEntry Accepted { get; set; } + + public MissionFailed(MissionAcceptedEntry accepted) { + Accepted = accepted; + Faction = accepted.Faction; + } + + public override string ToString() { + StringBuilder builder = new StringBuilder(); + + if (Failed == null || Accepted == null) { + return ""; + } + + builder.AppendFormat("Mission failed: \"{0}\"", + Failed.HumanReadableName != null ? Failed.HumanReadableName : Failed.Name + ); + + return builder.ToString(); + } + } +} diff --git a/BGS/Report.cs b/BGS/Report.cs index 0025946..37a967e 100644 --- a/BGS/Report.cs +++ b/BGS/Report.cs @@ -30,6 +30,8 @@ namespace EliteBGS.BGS { private bool IsRelevant(Entry e) { return e.Is(Events.MissionCompleted) || + e.Is(Events.MissionFailed) || + e.Is(Events.MissionAccepted) || e.Is(Events.Docked) || e.Is(Events.FSDJump) || e.Is(Events.MultiSellExplorationData) || @@ -50,6 +52,8 @@ namespace EliteBGS.BGS { select log ; + Dictionary acceptedMissions = new Dictionary(); + string current_system = null; string current_station = null; string controlling_faction = null; @@ -71,7 +75,7 @@ namespace EliteBGS.BGS { controlling_faction = (e as FSDJumpEntry).SystemFaction; } else if (e.Is(Events.MissionCompleted)) { var completed = e as MissionCompletedEntry; - entry = new MissionCompleted(completed, current_system, current_station); + entry = new MissionCompleted(completed) { System = current_system, Station = current_station }; if (completed.HumanReadableNameWasGenerated) { /* If the human readable name was generated, we send a log message. Because the * generated names all sort of suck, we should have more human readable names in @@ -81,6 +85,22 @@ namespace EliteBGS.BGS { completed.Name + "\" was generated, please report this."); } + } else if (e.Is(Events.MissionAccepted)) { + MissionAcceptedEntry accepted = e as MissionAcceptedEntry; + acceptedMissions[accepted.MissionID] = accepted; + } else if (e.Is(Events.MissionFailed)) { + var failed = e as MissionFailedEntry; + var accepted = acceptedMissions[failed.MissionID]; + if (accepted == null) { + OnLog?.Invoke("Mission failed that wasn't accepted, please adjust time frame."); + continue; + } + entry = new MissionFailed(accepted) { Failed = failed, System = current_system }; + if (failed.HumanReadableName == null) { + OnLog?.Invoke("Human readable name for mission \"" + + failed.Name + + "\" was not recognised"); + } } else if (e.Is(Events.MultiSellExplorationData)) { /* For multi-sell-exploraton-data only the controlling faction of the station sold to matters. */ diff --git a/EliteBGS.csproj b/EliteBGS.csproj index 7d5e747..02adaa2 100644 --- a/EliteBGS.csproj +++ b/EliteBGS.csproj @@ -79,6 +79,7 @@ +