Archived
1
0
This repository has been archived on 2021-10-19. You can view files and clone it, but cannot push or open issues or pull requests.
nonabgs/BGS/NonaDiscordLog.cs

164 lines
5.7 KiB
C#
Raw Normal View History

2021-07-09 11:03:30 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2021-08-25 16:36:57 +02:00
using EDJournal;
2021-07-09 11:03:30 +02:00
namespace NonaBGS.BGS {
public class NonaDiscordLog : IDiscordLogGenerator {
private string FormatDate() {
StringBuilder date = new StringBuilder();
DateTime today = DateTime.Now;
string suffix;
if (today.Day == 1 || today.Day == 21 || today.Day == 31) {
suffix = "st";
} else if (today.Day == 2 || today.Day == 22) {
suffix = "nd";
} else {
suffix = "th";
}
date.AppendFormat("{0} {1}{2}, {3}",
today.ToString("MMMM"), today.Day, suffix,
today.Year + EliteDangerous.YearOffset
);
return date.ToString();
}
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} CR)\n", pages, sum);
}
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} CR worth of Micro Resources\n", sum);
}
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} CR)\n", 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();
2021-08-22 11:50:43 +02:00
int total_influence = 0;
2021-07-09 11:03:30 +02:00
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];
2021-08-22 11:50:43 +02:00
total_influence += m.Influence.Length;
2021-07-09 11:03:30 +02:00
}
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);
}
2021-08-22 11:50:43 +02:00
2021-07-09 11:03:30 +02:00
return output.ToString();
}
public string GenerateDiscordLog(Report report) {
StringBuilder log = new StringBuilder();
log.AppendFormat(":clock2: `Date:` {0}\n", FormatDate());
foreach (var objective in report.Objectives) {
if (objective.LogEntries.Count <= 0) {
continue;
}
log.AppendFormat(":globe_with_meridians: `Location:` {0}\n", objective.ToShortString());
log.Append(":clipboard: `Conducted:`\n");
log.Append("```\n");
StringBuilder entries = new StringBuilder();
var missions = BuildMissionList(objective);
entries.Append(missions);
var vouchers = BuildVouchers(objective);
entries.Append(vouchers);
var carto = BuildCartoGraphics(objective);
entries.Append(carto);
var micro = BuildMicroResourcesSold(objective);
entries.Append(micro);
log.Append(entries.ToString().Trim());
log.Append("\n```\n");
}
return log.ToString();
}
}
}