From 5120c7991fbcb102fe5ecb3445044ac159869d70 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 23 Feb 2023 21:44:55 +0100 Subject: [PATCH] implement a summary line For Pony's bot, implement a summary line that just shows the highlights of the log --- EDPlayerJournal/Credits.cs | 12 +++++ EliteBGS/DiscordLogGenerator.cs | 30 +++++++++++++ EliteBGS/LogGenerator/CargoSoldFormatter.cs | 12 +++++ EliteBGS/LogGenerator/CartographicsFormat.cs | 11 +++++ EliteBGS/LogGenerator/CombatZoneFormat.cs | 44 +++++++++++++++++++ EliteBGS/LogGenerator/FailedMissionFormat.cs | 27 +++++++++++- EliteBGS/LogGenerator/GenericFormat.cs | 4 ++ EliteBGS/LogGenerator/LogFormatter.cs | 1 + EliteBGS/LogGenerator/MicroResourcesFormat.cs | 4 ++ EliteBGS/LogGenerator/MissionFormat.cs | 17 +++++++ EliteBGS/LogGenerator/MurderFormat.cs | 14 ++++++ EliteBGS/LogGenerator/ThargoidFormatter.cs | 26 +++++++++++ EliteBGS/LogGenerator/VoucherFormat.cs | 28 ++++++++++++ EliteBGS/MainWindow.xaml.cs | 2 - EliteBGS/NonaDiscordLog.cs | 5 +++ 15 files changed, 234 insertions(+), 3 deletions(-) diff --git a/EDPlayerJournal/Credits.cs b/EDPlayerJournal/Credits.cs index e9bfd11..ed0840f 100644 --- a/EDPlayerJournal/Credits.cs +++ b/EDPlayerJournal/Credits.cs @@ -34,4 +34,16 @@ public class Credits { return string.Format("{0} CR", amount.ToString("N", format)); } + + public static string FormatMillions(long amount) { + double millions = (amount / 1000000.0); + + if (amount >= 100000) { + return string.Format("{0:0.0}M", millions); + } else if (amount >= 10000) { + return string.Format("{0:0.00}M", millions); + } + + return ""; + } } diff --git a/EliteBGS/DiscordLogGenerator.cs b/EliteBGS/DiscordLogGenerator.cs index aab79fa..c404978 100644 --- a/EliteBGS/DiscordLogGenerator.cs +++ b/EliteBGS/DiscordLogGenerator.cs @@ -24,6 +24,31 @@ public class DiscordLogGenerator { new SearchAndRescueFormat(), }; + protected virtual string GenerateSummary(Objective objective) { + StringBuilder sb = new StringBuilder(); + + foreach (var formatter in formatters) { + string summary = ""; + + try { + summary = formatter.GenerateSummary(objective); + } catch (NotImplementedException) { + } + + if (string.IsNullOrEmpty(summary)) { + continue; + } + + if (sb.Length > 0) { + sb.Append(", "); + } + + sb.Append(summary); + } + + return sb.ToString(); + } + protected virtual string GenerateHeader() { return ""; } @@ -50,8 +75,13 @@ public class DiscordLogGenerator { .Count() ; + string summary = GenerateSummary(objective); + log.AppendFormat("**Date:** {0}\n", DateTime.Now.ToString("dd/MM/yyyy")); log.AppendFormat("**Target:** {0}\n", location); + if (!string.IsNullOrEmpty(summary)) { + log.AppendFormat("**Summary**: {0}\n", summary); + } if (legacycount > 0) { log.AppendFormat("**Warning:** Some actions were performed on ED Legacy\n"); } diff --git a/EliteBGS/LogGenerator/CargoSoldFormatter.cs b/EliteBGS/LogGenerator/CargoSoldFormatter.cs index 7c16882..ced96de 100644 --- a/EliteBGS/LogGenerator/CargoSoldFormatter.cs +++ b/EliteBGS/LogGenerator/CargoSoldFormatter.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Text; +using System.Windows.Documents; using EDPlayerJournal; using EDPlayerJournal.BGS; @@ -53,4 +54,15 @@ public class CargoSoldFormatter : LogFormatter { return builder.ToString(); } + + public string GenerateSummary(Objective objective) { + SellCargo[] sold = objective.EnabledOfType().ToArray(); + long totalProfit = sold.Sum(x => x.Profit); + + if (totalProfit >= 100000) { + return string.Format("Trade: {0}", Credits.FormatMillions(totalProfit)); + } + + return ""; + } } diff --git a/EliteBGS/LogGenerator/CartographicsFormat.cs b/EliteBGS/LogGenerator/CartographicsFormat.cs index b9e206b..7448869 100644 --- a/EliteBGS/LogGenerator/CartographicsFormat.cs +++ b/EliteBGS/LogGenerator/CartographicsFormat.cs @@ -19,4 +19,15 @@ public class CartographicsFormat : LogFormatter { pages, Credits.FormatCredits(sum) ); } + + public string GenerateSummary(Objective objective) { + Cartographics[] sold = objective.EnabledOfType().ToArray(); + long totalProfit = sold.Sum(x => x.TotalSum); + + if (totalProfit >= 100000) { + return string.Format("Explo: {0}", Credits.FormatMillions(totalProfit)); + } + + return ""; + } } diff --git a/EliteBGS/LogGenerator/CombatZoneFormat.cs b/EliteBGS/LogGenerator/CombatZoneFormat.cs index 1057047..2304a10 100644 --- a/EliteBGS/LogGenerator/CombatZoneFormat.cs +++ b/EliteBGS/LogGenerator/CombatZoneFormat.cs @@ -43,4 +43,48 @@ class CombatZoneFormat : LogFormatter { return builder.ToString().Trim(); } + + public string GenerateSummary(Objective objective) { + var logs = objective + .EnabledOfType() + .GroupBy(x => new { x.Type, x.Grade }) + .ToDictionary(x => x.Key, x => x.ToList()) + ; + StringBuilder builder = new StringBuilder(); + + if (logs == null || logs.Count() <= 0) { + return ""; + } + + foreach (var log in logs) { + int optionals = log.Value + .Sum(x => x.OptionalObjectivesCompleted) + ; + if (builder.Length > 0) { + builder.Append(", "); + } + if (!string.IsNullOrEmpty(log.Key.Grade)) { + string grade = log.Key.Grade.Substring(0, 1); + if (log.Key.Grade == CombatZones.DifficultyVeryHigh) { + grade = "VH"; + } + builder.AppendFormat("CZ: {0}x{1}{2}", + log.Value.Count, + log.Key.Grade.Substring(0, 1), + log.Key.Type.Substring(0, 1) + ); + } else { + builder.AppendFormat("CZ: {0}x?{1}", + log.Value.Count, + log.Key.Type.Substring(0, 1) + ); + } + + if (optionals > 0) { + builder.AppendFormat("+ {0} OPTS", optionals); + } + } + + return builder.ToString().Trim(); + } } diff --git a/EliteBGS/LogGenerator/FailedMissionFormat.cs b/EliteBGS/LogGenerator/FailedMissionFormat.cs index 5d5c35b..8dccf02 100644 --- a/EliteBGS/LogGenerator/FailedMissionFormat.cs +++ b/EliteBGS/LogGenerator/FailedMissionFormat.cs @@ -1,6 +1,5 @@ using System.Linq; using System.Text; -using EDPlayerJournal.Entries; using EDPlayerJournal.BGS; namespace EliteBGS.LogGenerator; @@ -31,4 +30,30 @@ public class FailedMissionFormat : LogFormatter { 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(); + + if (onFootFails > 0) { + sb.AppendFormat("Fails: {0} Ground", onFootFails); + } + + if (shipFails > 0) { + if (sb.Length> 0) { + sb.Append(", "); + } + sb.AppendFormat("{0} Ship", shipFails); + } + + return sb.ToString(); + } } diff --git a/EliteBGS/LogGenerator/GenericFormat.cs b/EliteBGS/LogGenerator/GenericFormat.cs index 00141d8..699c5bd 100644 --- a/EliteBGS/LogGenerator/GenericFormat.cs +++ b/EliteBGS/LogGenerator/GenericFormat.cs @@ -25,4 +25,8 @@ public class GenericFormat : LogFormatter where Type : Transaction { return builder.ToString(); } + + public string GenerateSummary(Objective objective) { + throw new System.NotImplementedException(); + } } diff --git a/EliteBGS/LogGenerator/LogFormatter.cs b/EliteBGS/LogGenerator/LogFormatter.cs index 3253f61..a8585cc 100644 --- a/EliteBGS/LogGenerator/LogFormatter.cs +++ b/EliteBGS/LogGenerator/LogFormatter.cs @@ -2,4 +2,5 @@ public interface LogFormatter { string GenerateLog(Objective objective); + string GenerateSummary(Objective objective); } diff --git a/EliteBGS/LogGenerator/MicroResourcesFormat.cs b/EliteBGS/LogGenerator/MicroResourcesFormat.cs index bd31113..15bde1a 100644 --- a/EliteBGS/LogGenerator/MicroResourcesFormat.cs +++ b/EliteBGS/LogGenerator/MicroResourcesFormat.cs @@ -16,4 +16,8 @@ public class MicroResourcesFormat : LogFormatter { return string.Format("Sold {0} worth of Micro Resources\n", Credits.FormatCredits(sum)); } + + public string GenerateSummary(Objective objective) { + return ""; + } } diff --git a/EliteBGS/LogGenerator/MissionFormat.cs b/EliteBGS/LogGenerator/MissionFormat.cs index 0721e2f..bdf899c 100644 --- a/EliteBGS/LogGenerator/MissionFormat.cs +++ b/EliteBGS/LogGenerator/MissionFormat.cs @@ -76,4 +76,21 @@ public class MissionFormat : LogFormatter { return output.ToString().Trim(); } + + public string GenerateSummary(Objective objective) { + long influence = objective + .EnabledOfType() + .Sum(x => x.Influence.Length) + ; + long support = objective + .EnabledOfType() + .Sum(x => x.Influence.Length) + ; + + if (influence + support <= 0) { + return ""; + } + + return string.Format("INF: {0}", influence + support); + } } diff --git a/EliteBGS/LogGenerator/MurderFormat.cs b/EliteBGS/LogGenerator/MurderFormat.cs index 260cfbf..ddb057c 100644 --- a/EliteBGS/LogGenerator/MurderFormat.cs +++ b/EliteBGS/LogGenerator/MurderFormat.cs @@ -45,4 +45,18 @@ public class MurderFormat : LogFormatter { return builder.ToString(); } + + public string GenerateSummary(Objective objective) { + long murders = objective + .EnabledOfType() + .Where(x => x.CrimeType == CrimeTypes.Murder || x.CrimeType == CrimeTypes.OnFootMurder) + .Count() + ; + + if (murders <= 0) { + return ""; + } + + return string.Format("Kills: {0}", murders); + } } diff --git a/EliteBGS/LogGenerator/ThargoidFormatter.cs b/EliteBGS/LogGenerator/ThargoidFormatter.cs index 9c4f4e6..f934413 100644 --- a/EliteBGS/LogGenerator/ThargoidFormatter.cs +++ b/EliteBGS/LogGenerator/ThargoidFormatter.cs @@ -29,4 +29,30 @@ public class ThargoidFormatter : LogFormatter { return builder.ToString(); } + + public string GenerateSummary(Objective objective) { + List kills = objective.EnabledOfType().ToList(); + + if (kills.Count == 0 ) { + return ""; + } + + int scouts = kills.Where(x => x.ThargoidType == ThargoidVessel.Scout).Count(); + int interceptors = kills.Count - scouts; + + StringBuilder builder = new StringBuilder(); + + builder.Append("AX: "); + if (interceptors > 0) { + builder.AppendFormat("{0} INT", interceptors); + } + if (scouts > 0) { + if (builder.Length> 0) { + builder.Append(", "); + } + builder.AppendFormat("{0} SCT", scouts); + } + + return builder.ToString(); + } } diff --git a/EliteBGS/LogGenerator/VoucherFormat.cs b/EliteBGS/LogGenerator/VoucherFormat.cs index 86e7bb4..4f16fbf 100644 --- a/EliteBGS/LogGenerator/VoucherFormat.cs +++ b/EliteBGS/LogGenerator/VoucherFormat.cs @@ -25,4 +25,32 @@ public class VoucherFormat : LogFormatter { return builder.ToString().Trim(); } + + public string GenerateSummary(Objective objective) { + long bounties = objective + .EnabledOfType() + .Where(x => x.Type == "Bounty") + .Sum(x => x.TotalSum) + ; + long bonds = objective + .EnabledOfType() + .Where(x => x.Type == "Combat Bond") + .Sum(x => x.TotalSum) + ; + + StringBuilder sb = new(); + + if (bounties > 0) { + sb.AppendFormat("Bounties: {0}", Credits.FormatMillions(bounties)); + } + + if (bonds > 0) { + if (sb.Length > 0) { + sb.Append(", "); + } + sb.AppendFormat("Bonds: {0}", Credits.FormatMillions(bonds)); + } + + return sb.ToString(); + } } diff --git a/EliteBGS/MainWindow.xaml.cs b/EliteBGS/MainWindow.xaml.cs index 4a744bd..f5a5c22 100644 --- a/EliteBGS/MainWindow.xaml.cs +++ b/EliteBGS/MainWindow.xaml.cs @@ -12,9 +12,7 @@ using EDPlayerJournal.Entries; using EliteBGS.BGS; using EliteBGS.Util; using System.Globalization; -using System.Windows.Forms; using System.Windows.Controls.Primitives; -using ControlzEx.Theming; using MahApps.Metro.Controls; using ControlzEx.Theming; using System.Windows.Media; diff --git a/EliteBGS/NonaDiscordLog.cs b/EliteBGS/NonaDiscordLog.cs index f18c728..33f7937 100644 --- a/EliteBGS/NonaDiscordLog.cs +++ b/EliteBGS/NonaDiscordLog.cs @@ -51,7 +51,12 @@ public class NonaDiscordLog : DiscordLogGenerator { .Count() ; + string summary = GenerateSummary(objective); + log.AppendFormat(":globe_with_meridians: `Target:` {0}\n", location); + if (!string.IsNullOrEmpty(summary)) { + log.AppendFormat(":scroll: `Summary:` {0}\n", summary); + } if (legacycount > 0) { log.Append(":rotating_light: `Warning`: Some actions were done in E:D Legacy\n"); }