change one line discord log to only show summaries

This commit is contained in:
Florian Stinglmayr 2023-04-19 10:06:10 +02:00
parent fce534c88f
commit 8cf8d7f529
7 changed files with 121 additions and 12 deletions

View File

@ -58,11 +58,20 @@ public class CargoSoldFormatter : LogFormatter {
public string GenerateSummary(Objective objective) { public string GenerateSummary(Objective objective) {
SellCargo[] sold = objective.EnabledOfType<SellCargo>().ToArray(); SellCargo[] sold = objective.EnabledOfType<SellCargo>().ToArray();
long totalProfit = sold.Sum(x => x.Profit); long totalProfit = sold.Sum(x => x.Profit);
long tons = sold.Sum(x => x.Amount);
if (totalProfit >= 100000) { if (tons <= 0) {
return string.Format("Trade: {0}", Credits.FormatMillions(totalProfit));
}
return ""; return "";
} }
StringBuilder builder = new();
builder.Append("Trade: ");
builder.AppendFormat("{0}t", tons);
if (totalProfit >= 100000) {
builder.AppendFormat(", {0} Profit", Credits.FormatMillions(totalProfit));
}
return builder.ToString();
}
} }

View File

@ -26,7 +26,7 @@ public class GenericFormat<Type> : LogFormatter where Type : Transaction {
return builder.ToString(); return builder.ToString();
} }
public string GenerateSummary(Objective objective) { public virtual string GenerateSummary(Objective objective) {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
} }

View File

@ -1,6 +1,38 @@
using EDPlayerJournal.BGS; using EDPlayerJournal;
using EDPlayerJournal.BGS;
using System.Linq;
using System.Text;
namespace EliteBGS.LogGenerator; namespace EliteBGS.LogGenerator;
public class KillBondsFormat : GenericFormat<FactionKillBonds> { public class KillBondsFormat : GenericFormat<FactionKillBonds> {
public override string GenerateSummary(Objective objective) {
StringBuilder builder = new StringBuilder();
var bonds = objective
.EnabledOfType<FactionKillBonds>()
.GroupBy(x => x.VictimFaction)
.ToDictionary(x => x.Key, x => x.ToList())
;
if (bonds.Count <= 0) {
return "";
}
builder.Append("Killbonds: ");
foreach (var entry in bonds) {
long sum = (long)entry.Value.Sum(x => (decimal)x.TotalSum);
builder.AppendFormat("{0} against {1}, ",
Credits.FormatMillions(sum),
entry.Key
);
}
if (builder.Length > 2) {
// Remove trailing comma
builder.Remove(builder.Length - 2, 2);
}
return builder.ToString();
}
} }

View File

@ -1,6 +1,17 @@
using EDPlayerJournal.BGS; using EDPlayerJournal.BGS;
using System.Linq;
namespace EliteBGS.LogGenerator; namespace EliteBGS.LogGenerator;
public class MarketBuyFormat : GenericFormat<BuyCargo> { public class MarketBuyFormat : GenericFormat<BuyCargo> {
public override string GenerateSummary(Objective objective) {
long tons = objective
.EnabledOfType<BuyCargo>()
.Sum(x => x.Amount)
;
if (tons <= 0) {
return "";
}
return string.Format("Market: {0}t bought", tons);
}
} }

View File

@ -1,6 +1,18 @@
using EDPlayerJournal.BGS; using EDPlayerJournal;
using EDPlayerJournal.BGS;
using System.Linq;
namespace EliteBGS.LogGenerator; namespace EliteBGS.LogGenerator;
public class SearchAndRescueFormat : GenericFormat<SearchAndRescue> { public class SearchAndRescueFormat : GenericFormat<SearchAndRescue> {
public override string GenerateSummary(Objective objective) {
long profit = objective
.EnabledOfType<SearchAndRescue>()
.Sum(x => x.Count)
;
if (profit <= 0) {
return "";
}
return string.Format("S&R: {0}t", profit);
}
} }

View File

@ -1,6 +1,18 @@
using EDPlayerJournal.BGS; using EDPlayerJournal;
using EDPlayerJournal.BGS;
using System.Linq;
namespace EliteBGS.LogGenerator; namespace EliteBGS.LogGenerator;
class VistaGenomicsFormat : GenericFormat<OrganicData> { class VistaGenomicsFormat : GenericFormat<OrganicData> {
public override string GenerateSummary(Objective objective) {
long profit = objective
.EnabledOfType<OrganicData>()
.Sum(x => x.TotalValue)
;
if (profit <= 0) {
return "";
}
return string.Format("Organic: {0} Profit", Credits.FormatMillions(profit));
}
} }

View File

@ -1,4 +1,8 @@
namespace EliteBGS; using EliteBGS.LogGenerator;
using System.Linq;
using System.Text;
namespace EliteBGS;
public class OneLineDiscordLog : DiscordLogGenerator { public class OneLineDiscordLog : DiscordLogGenerator {
protected override string GenerateObjectiveHeader(Objective objective) { protected override string GenerateObjectiveHeader(Objective objective) {
@ -10,7 +14,7 @@ public class OneLineDiscordLog : DiscordLogGenerator {
} }
protected override string GenerateObjectiveFooter(Objective objective) { protected override string GenerateObjectiveFooter(Objective objective) {
return ""; return "\n";
} }
protected override string GenerateFooter() { protected override string GenerateFooter() {
@ -21,9 +25,38 @@ public class OneLineDiscordLog : DiscordLogGenerator {
return ""; return "";
} }
protected override string TransformFinalLogForObjective(Objective objective, string log) { public override string GenerateDiscordLog(Report report) {
string[] lines = log.Split("\n", System.StringSplitOptions.RemoveEmptyEntries); StringBuilder log = new StringBuilder();
return string.Join(", ", lines);
if (report == null) {
return "";
}
var objectives = report.Objectives
.Where(x => x.IsEnabled && x.Transactions.Count() > 0)
;
if (objectives == null || objectives.Count() <= 0) {
return "";
}
foreach (Objective objective in objectives) {
log.AppendFormat("{0}", GenerateObjectiveHeader(objective));
foreach (LogFormatter formatter in formatters) {
string text = formatter.GenerateSummary(objective);
text = text.Trim();
if (!string.IsNullOrEmpty(text)) {
log.AppendFormat("{0}; ", text);
}
}
log.AppendFormat("{0}", GenerateObjectiveFooter(objective));
}
log.AppendFormat("{0}", GenerateFooter());
return log.ToString().Trim();
} }
public override string ToString() { public override string ToString() {