From 4c75515a70f6e45a89e79b0c9080e36a139aaba1 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Fri, 8 Sep 2023 11:43:05 +0200 Subject: [PATCH] include failed missions in mission format Since we now have to calculate negative INF with the normal INF (in case both happens), mission formatter now also handles failed missions. --- EDPlayerJournal/BGS/MissionFailed.cs | 15 ++++ EliteBGS/DiscordLogGenerator.cs | 2 - EliteBGS/LogGenerator/FailedMissionFormat.cs | 60 --------------- EliteBGS/LogGenerator/MissionFormat.cs | 80 +++++++++++++++++++- 4 files changed, 92 insertions(+), 65 deletions(-) delete mode 100644 EliteBGS/LogGenerator/FailedMissionFormat.cs diff --git a/EDPlayerJournal/BGS/MissionFailed.cs b/EDPlayerJournal/BGS/MissionFailed.cs index 0e4728c..e99a930 100644 --- a/EDPlayerJournal/BGS/MissionFailed.cs +++ b/EDPlayerJournal/BGS/MissionFailed.cs @@ -13,6 +13,21 @@ public class MissionFailed : Transaction { Failed = failed; } + /// + /// Returns the amount of influence generated by failing this mission. The + /// system returns no influence for one INF missions, but sadly also for + /// when the influence had no affect at all (i.e. during a war). + /// + public long InfluenceAmount { + get { + if (Mission == null || string.IsNullOrEmpty(Mission.Influence)) { + return -1; + } else { + return Mission.Influence.Length * -1; + } + } + } + public override int CompareTo(Transaction? other) { if (other == null || other.GetType() != typeof(MissionFailed)) { return -1; diff --git a/EliteBGS/DiscordLogGenerator.cs b/EliteBGS/DiscordLogGenerator.cs index 87b135a..797d8cf 100644 --- a/EliteBGS/DiscordLogGenerator.cs +++ b/EliteBGS/DiscordLogGenerator.cs @@ -4,14 +4,12 @@ using System.Collections.Generic; using System.Text; using EliteBGS.LogGenerator; using System.Reflection; -using System.Runtime.CompilerServices; namespace EliteBGS; public class DiscordLogGenerator { protected List formatters = new List() { new MissionFormat(), - new FailedMissionFormat(), new MurderFormat(), new VoucherFormat(), new ThargoidFormatter(), diff --git a/EliteBGS/LogGenerator/FailedMissionFormat.cs b/EliteBGS/LogGenerator/FailedMissionFormat.cs deleted file mode 100644 index 601cf96..0000000 --- a/EliteBGS/LogGenerator/FailedMissionFormat.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Linq; -using System.Text; -using EDPlayerJournal.BGS; - -namespace EliteBGS.LogGenerator; - -public class FailedMissionFormat : LogFormatter { - public string GenerateLog(Objective objective) { - var missions = objective.EnabledOfType(); - - if (missions.Count <= 0) { - return ""; - } - - StringBuilder builder = new StringBuilder(); - - var grouping = missions - .GroupBy(x => x.Mission.IsOnFoot) - ; - - foreach (var group in grouping) { - int amount = group.Count(); - - if (group.Key) { - builder.AppendFormat("Failed {0} On Foot Mission(s)\n", amount); - } else { - builder.AppendFormat("Failed {0} Ship Mission(s)\n", amount); - } - } - - return builder.ToString().Trim(); - } - - public string GenerateSummary(Objective objective) { - var missions = objective.EnabledOfType(); - - if (missions.Count <= 0) { - return ""; - } - - StringBuilder sb = new(); - - int onFootFails = missions.Where(x => x.Mission.IsOnFoot).Count(); - int shipFails = missions.Where(x => !x.Mission.IsOnFoot).Count(); - - sb.Append("Fails: "); - if (onFootFails > 0) { - sb.AppendFormat("{0} Ground", onFootFails); - } - - if (shipFails > 0) { - if (onFootFails > 0) { - sb.Append(", "); - } - sb.AppendFormat("{0} Ship", shipFails); - } - - return sb.ToString(); - } -} diff --git a/EliteBGS/LogGenerator/MissionFormat.cs b/EliteBGS/LogGenerator/MissionFormat.cs index 3c06c03..c92e539 100644 --- a/EliteBGS/LogGenerator/MissionFormat.cs +++ b/EliteBGS/LogGenerator/MissionFormat.cs @@ -6,6 +6,59 @@ using EDPlayerJournal.BGS; namespace EliteBGS.LogGenerator; public class MissionFormat : LogFormatter { + private string GenerateFailedLog(Objective objective) { + var missions = objective.EnabledOfType(); + + if (missions.Count <= 0) { + return ""; + } + + StringBuilder builder = new StringBuilder(); + + var grouping = missions + .GroupBy(x => x.Mission.IsOnFoot) + ; + + foreach (var group in grouping) { + int amount = group.Count(); + + if (group.Key) { + builder.AppendFormat("Failed {0} On Foot Mission(s)\n", amount); + } else { + builder.AppendFormat("Failed {0} Ship Mission(s)\n", amount); + } + } + + return builder.ToString().Trim(); + } + + private string GenerateFailedSummary(Objective objective) { + var missions = objective.EnabledOfType(); + + if (missions.Count <= 0) { + return ""; + } + + StringBuilder sb = new(); + + int onFootFails = missions.Where(x => x.Mission.IsOnFoot).Count(); + int shipFails = missions.Where(x => !x.Mission.IsOnFoot).Count(); + + sb.Append("Fails: "); + if (onFootFails > 0) { + sb.AppendFormat("{0} Ground", onFootFails); + } + + if (shipFails > 0) { + if (onFootFails > 0) { + sb.Append(", "); + } + sb.AppendFormat("{0} Ship", shipFails); + } + + return sb.ToString(); + } + public string GenerateLog(Objective objective) { Dictionary> collated = new(); Dictionary passengers = new(); @@ -14,9 +67,11 @@ public class MissionFormat : LogFormatter { var missions = objective.EnabledOfType(); var support = objective.EnabledOfType(); + var failed = objective.EnabledOfType(); if ((missions == null || missions.Count == 0) && - (support == null || support.Count == 0)) { + (support == null || support.Count == 0) && + (failed == null || failed.Count == 0)) { return ""; } @@ -60,6 +115,14 @@ public class MissionFormat : LogFormatter { output.Append("\n"); + // Handle failed missions, and add them to the log and influence tally + string failedlog = GenerateFailedLog(objective); + if (!string.IsNullOrEmpty(failedlog)) { + output.Append(failedlog); + output.Append("\n"); + } + total_influence += failed.Sum(x => x.InfluenceAmount); + foreach (InfluenceSupport inf in support) { output.Append(inf.ToString()); output.Append("\n"); @@ -86,11 +149,22 @@ public class MissionFormat : LogFormatter { .EnabledOfType() .Sum(x => x.Influence.InfluenceAmount) ; + long failed = objective + .EnabledOfType() + .Sum(x => x.InfluenceAmount) + ; - if (influence == 0 && support == 0) { + if (influence == 0 && support == 0 && failed == 0) { return ""; } - return string.Format("INF: {0}", influence + support); + string failedsummary = GenerateFailedSummary(objective); + string summary = string.Format("INF: {0}", influence + support + failed); + + if (!string.IsNullOrEmpty(failedsummary)) { + string.Join("; ", summary, failedsummary); + } + + return summary; } }