2022-11-24 19:38:19 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using EDPlayerJournal.BGS;
|
|
|
|
|
|
|
|
|
|
namespace EliteBGS.LogGenerator;
|
|
|
|
|
|
|
|
|
|
public class MissionFormat : LogFormatter {
|
2023-09-08 11:43:05 +02:00
|
|
|
|
private string GenerateFailedLog(Objective objective) {
|
|
|
|
|
var missions = objective.EnabledOfType<MissionFailed>();
|
|
|
|
|
|
|
|
|
|
if (missions.Count <= 0) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
var grouping = missions
|
|
|
|
|
.GroupBy(x => x.Mission.IsOnFoot)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
foreach (var group in grouping) {
|
|
|
|
|
int amount = group.Count();
|
|
|
|
|
|
|
|
|
|
if (group.Key) {
|
|
|
|
|
builder.AppendFormat("Failed {0} On Foot Mission(s)\n", amount);
|
|
|
|
|
} else {
|
|
|
|
|
builder.AppendFormat("Failed {0} Ship Mission(s)\n", amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.ToString().Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GenerateFailedSummary(Objective objective) {
|
|
|
|
|
var missions = objective.EnabledOfType<MissionFailed>();
|
|
|
|
|
|
|
|
|
|
if (missions.Count <= 0) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
|
|
|
|
|
|
int onFootFails = missions.Where(x => x.Mission.IsOnFoot).Count();
|
|
|
|
|
int shipFails = missions.Where(x => !x.Mission.IsOnFoot).Count();
|
|
|
|
|
|
|
|
|
|
sb.Append("Fails: ");
|
|
|
|
|
if (onFootFails > 0) {
|
|
|
|
|
sb.AppendFormat("{0} Ground", onFootFails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shipFails > 0) {
|
|
|
|
|
if (onFootFails > 0) {
|
|
|
|
|
sb.Append(", ");
|
|
|
|
|
}
|
|
|
|
|
sb.AppendFormat("{0} Ship", shipFails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 19:38:19 +01:00
|
|
|
|
public string GenerateLog(Objective objective) {
|
2022-12-07 23:21:36 +01:00
|
|
|
|
Dictionary<string, Dictionary<string, int>> collated = new();
|
|
|
|
|
Dictionary<string, ulong> passengers = new();
|
2022-11-24 19:38:19 +01:00
|
|
|
|
StringBuilder output = new StringBuilder();
|
2023-09-08 11:20:49 +02:00
|
|
|
|
long total_influence = 0;
|
2022-11-24 19:38:19 +01:00
|
|
|
|
|
|
|
|
|
var missions = objective.EnabledOfType<MissionCompleted>();
|
2022-12-14 18:19:46 +01:00
|
|
|
|
var support = objective.EnabledOfType<InfluenceSupport>();
|
2023-09-08 11:43:05 +02:00
|
|
|
|
var failed = objective.EnabledOfType<MissionFailed>();
|
2022-11-24 19:38:19 +01:00
|
|
|
|
|
2022-12-14 18:19:46 +01:00
|
|
|
|
if ((missions == null || missions.Count == 0) &&
|
2023-09-08 11:43:05 +02:00
|
|
|
|
(support == null || support.Count == 0) &&
|
|
|
|
|
(failed == null || failed.Count == 0)) {
|
2022-11-24 19:38:19 +01:00
|
|
|
|
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;
|
2022-12-07 23:21:36 +01:00
|
|
|
|
|
|
|
|
|
if (m.AcceptedEntry != null &&
|
|
|
|
|
m.AcceptedEntry.Mission != null &&
|
|
|
|
|
m.AcceptedEntry.Mission.IsPassengerMission) {
|
|
|
|
|
if (!passengers.ContainsKey(m.MissionName)) {
|
|
|
|
|
passengers[m.MissionName] = 0;
|
|
|
|
|
}
|
|
|
|
|
passengers[m.MissionName] += (m.AcceptedEntry.Mission.PassengerCount ?? 0);
|
|
|
|
|
}
|
2022-11-24 19:38:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var mission in collated) {
|
2022-11-25 17:45:03 +01:00
|
|
|
|
output.AppendFormat("{0}: ", mission.Key);
|
2022-11-24 19:38:19 +01:00
|
|
|
|
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 ", "
|
2022-12-07 23:21:36 +01:00
|
|
|
|
output.Append(")");
|
|
|
|
|
|
|
|
|
|
if (passengers.ContainsKey(mission.Key)) {
|
|
|
|
|
output.AppendFormat(" ({0} Passengers)", passengers[mission.Key]);
|
|
|
|
|
}
|
2022-12-14 20:05:57 +01:00
|
|
|
|
|
|
|
|
|
output.Append("\n");
|
2022-11-24 19:38:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 20:05:57 +01:00
|
|
|
|
output.Append("\n");
|
2022-12-07 23:21:36 +01:00
|
|
|
|
|
2023-09-08 11:43:05 +02:00
|
|
|
|
// Handle failed missions, and add them to the log and influence tally
|
|
|
|
|
string failedlog = GenerateFailedLog(objective);
|
|
|
|
|
if (!string.IsNullOrEmpty(failedlog)) {
|
|
|
|
|
output.Append(failedlog);
|
|
|
|
|
output.Append("\n");
|
|
|
|
|
}
|
|
|
|
|
total_influence += failed.Sum(x => x.InfluenceAmount);
|
|
|
|
|
|
2022-11-24 19:38:19 +01:00
|
|
|
|
foreach (InfluenceSupport inf in support) {
|
|
|
|
|
output.Append(inf.ToString());
|
|
|
|
|
output.Append("\n");
|
2023-09-08 11:20:49 +02:00
|
|
|
|
total_influence += inf.Influence.InfluenceAmount;
|
2022-11-24 19:38:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (support.Count() > 0) {
|
|
|
|
|
output.Append("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 11:20:49 +02:00
|
|
|
|
if (total_influence != 0) {
|
2022-11-24 19:38:19 +01:00
|
|
|
|
output.AppendFormat("Total Influence: {0}", total_influence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output.ToString().Trim();
|
|
|
|
|
}
|
2023-02-23 21:44:55 +01:00
|
|
|
|
|
|
|
|
|
public string GenerateSummary(Objective objective) {
|
|
|
|
|
long influence = objective
|
|
|
|
|
.EnabledOfType<MissionCompleted>()
|
|
|
|
|
.Sum(x => x.Influence.Length)
|
|
|
|
|
;
|
|
|
|
|
long support = objective
|
|
|
|
|
.EnabledOfType<InfluenceSupport>()
|
2023-09-08 11:20:49 +02:00
|
|
|
|
.Sum(x => x.Influence.InfluenceAmount)
|
2023-02-23 21:44:55 +01:00
|
|
|
|
;
|
2023-09-08 11:43:05 +02:00
|
|
|
|
long failed = objective
|
|
|
|
|
.EnabledOfType<MissionFailed>()
|
|
|
|
|
.Sum(x => x.InfluenceAmount)
|
|
|
|
|
;
|
2023-02-23 21:44:55 +01:00
|
|
|
|
|
2023-09-08 11:43:05 +02:00
|
|
|
|
if (influence == 0 && support == 0 && failed == 0) {
|
2023-02-23 21:44:55 +01:00
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 11:43:05 +02:00
|
|
|
|
string failedsummary = GenerateFailedSummary(objective);
|
|
|
|
|
string summary = string.Format("INF: {0}", influence + support + failed);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(failedsummary)) {
|
|
|
|
|
string.Join("; ", summary, failedsummary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return summary;
|
2023-02-23 21:44:55 +01:00
|
|
|
|
}
|
2022-11-24 19:38:19 +01:00
|
|
|
|
}
|