From 88b770e5ec93ff0767b072120d363c62dd7735e7 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 14 Nov 2024 13:52:17 +0100 Subject: [PATCH] add format for merits gained in log --- EliteBGS/DiscordLogGenerator.cs | 1 + EliteBGS/LogGenerator/MeritsGainedFormat.cs | 50 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 EliteBGS/LogGenerator/MeritsGainedFormat.cs diff --git a/EliteBGS/DiscordLogGenerator.cs b/EliteBGS/DiscordLogGenerator.cs index d941366..22a23ed 100644 --- a/EliteBGS/DiscordLogGenerator.cs +++ b/EliteBGS/DiscordLogGenerator.cs @@ -21,6 +21,7 @@ public class DiscordLogGenerator { new CargoSoldFormatter(), new VistaGenomicsFormat(), new SearchAndRescueFormat(), + new MeritsGainedFormat(), }; protected virtual string GetToolVersion() { diff --git a/EliteBGS/LogGenerator/MeritsGainedFormat.cs b/EliteBGS/LogGenerator/MeritsGainedFormat.cs new file mode 100644 index 0000000..d0148f3 --- /dev/null +++ b/EliteBGS/LogGenerator/MeritsGainedFormat.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using EDPlayerJournal; +using EDPlayerJournal.BGS; + +namespace EliteBGS.LogGenerator; + +public class MeritsGainedFormat : LogFormatter { + public string GenerateLog(Objective objective) { + var builder = new StringBuilder(); + + var merits = objective + .EnabledOfType() + .GroupBy(x => x.Power) + .ToDictionary(x => x.Key, x => x.Sum(x => x.Merits)) + ; + + if (merits == null || merits.Count == 0) { + return ""; + } + + foreach (var merit in merits) { + builder.AppendFormat("{0} merits gained for {1}\n", merit.Value, merit.Key); + } + + return builder.ToString().Trim(); + } + + public string GenerateSummary(Objective objective) { + var builder = new StringBuilder(); + + var merits = objective + .EnabledOfType() + .GroupBy(x => x.Power) + .ToDictionary(x => x.Key, x => x.Sum(x => x.Merits)) + ; + + if (merits == null || merits.Count == 0) { + return ""; + } + + foreach (var merit in merits) { + builder.AppendFormat("MRT: {0}, {1}; ", merit.Key, merit.Value); + } + + return builder.ToString().Trim(); + } +}