From 8796078b67d2474478b42c8b12ece828efa2d814 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Wed, 4 Aug 2021 17:50:46 +0200 Subject: [PATCH] allow bounties to be collated together if they are the same type --- BGS/LogEntry.cs | 6 +++++- BGS/Report.cs | 19 ++++++++++++++++++- BGS/Vouchers.cs | 13 +++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/BGS/LogEntry.cs b/BGS/LogEntry.cs index 8aa3c76..bc31f7c 100644 --- a/BGS/LogEntry.cs +++ b/BGS/LogEntry.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using NonaBGS.Journal; namespace NonaBGS.BGS { - public class LogEntry { + public class LogEntry : IComparable { private List entries = new List(); public List Entries => entries; @@ -20,5 +20,9 @@ namespace NonaBGS.BGS { public virtual bool OnlyControllingFaction { get { return false; } } + + public virtual int CompareTo(LogEntry other) { + throw new NotImplementedException("not implemented"); + } } } diff --git a/BGS/Report.cs b/BGS/Report.cs index 2e8bd60..1924e09 100644 --- a/BGS/Report.cs +++ b/BGS/Report.cs @@ -60,6 +60,7 @@ namespace NonaBGS.BGS { foreach (var e in relevant) { LogEntry entry = null; + bool collate = false; if (e.Is(Events.Docked)) { /* gleem the current station from this message @@ -95,6 +96,8 @@ namespace NonaBGS.BGS { entry.System = current_system; entry.Station = current_station; entry.Faction = controlling_faction; + + collate = true; } else if (e.Is(Events.SellMicroResources)) { entry = new SellMicroResources(current_system, current_station); entry.Entries.Add(e); @@ -122,7 +125,21 @@ namespace NonaBGS.BGS { .First() ; - if (objective != null) { + if (objective == null) { + continue; + } + + LogEntry existing = null; + + try { + existing = objective.LogEntries.Find(x => x.CompareTo(entry) == 0); + } catch (NotImplementedException) { + // Equivalent to not having found anything + existing = null; + } + if (collate && existing != null) { + existing.Entries.Add(e); + } else if (!collate || existing == null) { objective.LogEntries.Add(entry); } } diff --git a/BGS/Vouchers.cs b/BGS/Vouchers.cs index f7b92bf..a457596 100644 --- a/BGS/Vouchers.cs +++ b/BGS/Vouchers.cs @@ -30,6 +30,19 @@ namespace NonaBGS.BGS { } } + public override int CompareTo(LogEntry other) { + if (other.GetType() != typeof(Vouchers)) { + return -1; + } + + var b = other as Vouchers; + if (b.Type == Type) { + return 0; + } + + return -1; + } + public override string ToString() { return string.Format("{0} Vouchers: {1}", Type, Credits.FormatCredits(TotalSum)); }