change to a more generic bgs logger
This commit is contained in:
parent
df38f96dd1
commit
9657627273
217
BGS/GenericDiscordLog.cs
Normal file
217
BGS/GenericDiscordLog.cs
Normal file
@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using EDJournal;
|
||||
|
||||
namespace EliteBGS.BGS {
|
||||
public class GenericDiscordLog : IDiscordLogGenerator {
|
||||
private string FormatDate() {
|
||||
DateTime today = DateTime.Now;
|
||||
return today.ToShortDateString();
|
||||
}
|
||||
|
||||
private string BuildCartoGraphics(Objective objective) {
|
||||
var total = from entries in objective.LogEntries
|
||||
where entries.GetType() == typeof(Cartographics)
|
||||
select entries
|
||||
;
|
||||
var pages = total.Count();
|
||||
var sum = total.Sum(x => (x as Cartographics).TotalSum);
|
||||
|
||||
if (pages <= 0 || sum <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return string.Format("Sold {0} page(s) worth of universal cartographics\n" +
|
||||
"(Total value: {1})\n", pages, Credits.FormatCredits(sum));
|
||||
}
|
||||
|
||||
private string BuildCargoSold(Objective objective) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
SellCargo[] sold = objective.LogEntries
|
||||
.OfType<SellCargo>()
|
||||
.ToArray()
|
||||
;
|
||||
|
||||
if (sold == null && sold.Length > 0) {
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
foreach (SellCargo sell in sold) {
|
||||
builder.AppendFormat("{0}\n", sell.ToString());
|
||||
}
|
||||
|
||||
builder.AppendFormat("\n");
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private string BuildMicroResourcesSold(Objective objective) {
|
||||
var total = from entries in objective.LogEntries
|
||||
where entries.GetType() == typeof(SellMicroResources)
|
||||
select entries
|
||||
;
|
||||
var sum = total.Sum(x => (x as SellMicroResources).TotalSum);
|
||||
|
||||
if (sum <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return string.Format("Sold {0} worth of Micro Resources\n",
|
||||
Credits.FormatCredits(sum));
|
||||
}
|
||||
|
||||
private string BuildKillBonds(Objective objective) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
FactionKillBonds[] bonds = objective.LogEntries
|
||||
.OfType<FactionKillBonds>()
|
||||
.ToArray()
|
||||
;
|
||||
|
||||
if (bonds == null || bonds.Length == 0) {
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
foreach (FactionKillBonds bond in bonds) {
|
||||
builder.AppendFormat("{0}\n", bond.ToString());
|
||||
}
|
||||
|
||||
builder.AppendFormat("\n");
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private string BuildVouchers(Objective objective) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
var missions = from entries in objective.LogEntries
|
||||
where entries.GetType() == typeof(Vouchers)
|
||||
select entries
|
||||
;
|
||||
|
||||
if (missions == null || missions.Count() <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
foreach (var mission in missions) {
|
||||
var m = mission as Vouchers;
|
||||
builder.AppendFormat("Handed in {0} vouchers for {1}\n", m.Type, m.Faction);
|
||||
builder.AppendFormat("(Total value: {0})\n", Credits.FormatCredits(m.TotalSum));
|
||||
builder.AppendFormat("\n");
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private string BuildMissionList(Objective objective) {
|
||||
Dictionary<string, Dictionary<string, int>> collated = new Dictionary<string, Dictionary<string, int>>();
|
||||
StringBuilder output = new StringBuilder();
|
||||
int total_influence = 0;
|
||||
|
||||
var missions = from entries in objective.LogEntries
|
||||
where entries.GetType() == typeof(MissionCompleted)
|
||||
select entries
|
||||
;
|
||||
|
||||
if (missions == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
foreach (MissionCompleted m in missions) {
|
||||
if (!collated.ContainsKey(m.MissionName)) {
|
||||
collated[m.MissionName] = new Dictionary<string, int>();
|
||||
}
|
||||
if (!collated[m.MissionName].ContainsKey(m.Influence)) {
|
||||
collated[m.MissionName][m.Influence] = 0;
|
||||
}
|
||||
|
||||
++collated[m.MissionName][m.Influence];
|
||||
|
||||
total_influence += m.Influence.Length;
|
||||
}
|
||||
|
||||
foreach (var mission in collated) {
|
||||
if (objective.Faction != null) {
|
||||
output.AppendFormat("{0} for {1}\n", mission.Key, objective.Faction);
|
||||
} else {
|
||||
output.AppendFormat("{0}\n", mission.Key);
|
||||
}
|
||||
output.Append("(");
|
||||
foreach (var influence in mission.Value.OrderBy(x => x.Key.Length)) {
|
||||
output.AppendFormat("Inf{0} x{1}, ", influence.Key, influence.Value);
|
||||
}
|
||||
output.Remove(output.Length - 2, 2); // remove last ", "
|
||||
output.Append(")\n\n");
|
||||
}
|
||||
|
||||
if (total_influence > 0) {
|
||||
output.AppendFormat("Total Influence: {0}\n\n", total_influence);
|
||||
}
|
||||
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
private string BuildCombatZones(Objective objective) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
CombatZone[] zones = objective.LogEntries
|
||||
.OfType<CombatZone>()
|
||||
.ToArray()
|
||||
;
|
||||
|
||||
if (zones == null || zones.Length == 0) {
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
foreach (CombatZone zone in zones) {
|
||||
builder.AppendFormat("{0}\n", zone.ToString());
|
||||
}
|
||||
|
||||
builder.Append("\n");
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public string GenerateDiscordLog(Report report) {
|
||||
StringBuilder log = new StringBuilder();
|
||||
|
||||
foreach (var objective in report.Objectives) {
|
||||
if (objective.LogEntries.Count <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
log.AppendFormat("**Date:** {0}\n", FormatDate());
|
||||
log.AppendFormat("**Location:** {0}\n", objective.ToShortString());
|
||||
log.Append("\n");
|
||||
log.Append("```\n");
|
||||
|
||||
StringBuilder entries = new StringBuilder();
|
||||
|
||||
var missions = BuildMissionList(objective);
|
||||
entries.Append(missions);
|
||||
|
||||
var vouchers = BuildVouchers(objective);
|
||||
entries.Append(vouchers);
|
||||
|
||||
var zones = BuildCombatZones(objective);
|
||||
entries.Append(zones);
|
||||
|
||||
var bonds = BuildKillBonds(objective);
|
||||
entries.Append(bonds);
|
||||
|
||||
var carto = BuildCartoGraphics(objective);
|
||||
entries.Append(carto);
|
||||
|
||||
var micro = BuildMicroResourcesSold(objective);
|
||||
entries.Append(micro);
|
||||
|
||||
var sold = BuildCargoSold(objective);
|
||||
entries.Append(sold);
|
||||
|
||||
log.Append(entries.ToString().Trim());
|
||||
log.Append("\n```\n");
|
||||
}
|
||||
|
||||
return log.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -78,6 +78,7 @@
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="BGS\DiscordLogGenerator.cs" />
|
||||
<Compile Include="BGS\GenericDiscordLog.cs" />
|
||||
<Compile Include="BGS\NonaDiscordLog.cs" />
|
||||
<Compile Include="BGS\SellCargo.cs" />
|
||||
<Compile Include="BGS\SellMicroResources.cs" />
|
||||
|
@ -155,7 +155,7 @@ namespace EliteBGS {
|
||||
}
|
||||
|
||||
private void GenerateDiscord_Click(object sender, RoutedEventArgs e) {
|
||||
NonaDiscordLog discord = new NonaDiscordLog();
|
||||
GenericDiscordLog discord = new GenericDiscordLog();
|
||||
string report = discord.GenerateDiscordLog(Report);
|
||||
|
||||
DiscordLog.Text = report;
|
||||
|
Loading…
Reference in New Issue
Block a user