diff --git a/BGS/NonaDiscordLog.cs b/BGS/NonaDiscordLog.cs index 0d6cbdb..673738a 100644 --- a/BGS/NonaDiscordLog.cs +++ b/BGS/NonaDiscordLog.cs @@ -59,8 +59,39 @@ namespace EliteBGS.BGS { return builder.ToString(); } - foreach (SellCargo sell in sold) { - builder.AppendFormat("{0}\n", sell.ToString()); + + // This groups everything together by cargo sold, and then by market sold to. + // Dictionary > + var entries = sold.GroupBy(x => x.Cargo, + (key, cargos) => new { + Cargo = key, + Markets = cargos.GroupBy(y => y.Market, + (market, markets) => new { + Market = market, + Amount = markets.Sum(x => x.Amount), + Profit = markets.Sum(x => x.Profit) + }) + } + ) + ; + + foreach (var cargo in entries) { + foreach (var market in cargo.Markets) { + builder.AppendFormat("Sold {0} {1} to the {2}", + market.Amount, + cargo.Cargo, + market.Market + ); + + if (market.Profit != 0) { + builder.AppendFormat(" ({0} {1})", + Credits.FormatCredits(market.Profit), + market.Profit < 0 ? "loss" : "profit" + ); + } + + builder.Append("\n"); + } } builder.AppendFormat("\n"); diff --git a/BGS/SellCargo.cs b/BGS/SellCargo.cs index fbca0c2..45fb841 100644 --- a/BGS/SellCargo.cs +++ b/BGS/SellCargo.cs @@ -12,16 +12,10 @@ namespace EliteBGS.BGS { Entries.Add(e); } - public override string ToString() { - StringBuilder builder = new StringBuilder(); - var sold = Entries.OfType().ToArray(); - - if (sold == null || sold.Length == 0) { - return builder.ToString(); - } - - foreach (MarketSellEntry sell in sold) { + public string Cargo { + get { string cargo; + var sell = Entries.OfType().First(); if (!string.IsNullOrEmpty(sell.TypeLocalised)) { cargo = sell.TypeLocalised; @@ -32,10 +26,34 @@ namespace EliteBGS.BGS { } } + return cargo; + } + } + + public string Market { + get { + var sell = Entries.OfType().First(); + return sell.BlackMarket ? "Black Market" : "Commodity Market"; + } + } + + public long Amount { + get { return Entries.OfType().Sum(x => x.Count); } + } + + public override string ToString() { + StringBuilder builder = new StringBuilder(); + var sold = Entries.OfType().ToArray(); + + if (sold == null || sold.Length == 0) { + return builder.ToString(); + } + + foreach (MarketSellEntry sell in sold) { builder.AppendFormat("Sold {0} {1} to the {2}", sell.Count, - cargo, - sell.BlackMarket ? "Black Market" : "Commodity Market" + Cargo, + Market ); if (Profit != 0) {