include failed missions in mission format
Since we now have to calculate negative INF with the normal INF (in case both happens), mission formatter now also handles failed missions.
This commit is contained in:
parent
c43c6f742a
commit
4c75515a70
@ -13,6 +13,21 @@ public class MissionFailed : Transaction {
|
||||
Failed = failed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the amount of influence generated by failing this mission. The
|
||||
/// system returns no influence for one INF missions, but sadly also for
|
||||
/// when the influence had no affect at all (i.e. during a war).
|
||||
/// </summary>
|
||||
public long InfluenceAmount {
|
||||
get {
|
||||
if (Mission == null || string.IsNullOrEmpty(Mission.Influence)) {
|
||||
return -1;
|
||||
} else {
|
||||
return Mission.Influence.Length * -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(MissionFailed)) {
|
||||
return -1;
|
||||
|
@ -4,14 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using EliteBGS.LogGenerator;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace EliteBGS;
|
||||
|
||||
public class DiscordLogGenerator {
|
||||
protected List<LogFormatter> formatters = new List<LogFormatter>() {
|
||||
new MissionFormat(),
|
||||
new FailedMissionFormat(),
|
||||
new MurderFormat(),
|
||||
new VoucherFormat(),
|
||||
new ThargoidFormatter(),
|
||||
|
@ -1,60 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using EDPlayerJournal.BGS;
|
||||
|
||||
namespace EliteBGS.LogGenerator;
|
||||
|
||||
public class FailedMissionFormat : LogFormatter {
|
||||
public string GenerateLog(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();
|
||||
}
|
||||
|
||||
public string GenerateSummary(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();
|
||||
}
|
||||
}
|
@ -6,6 +6,59 @@ using EDPlayerJournal.BGS;
|
||||
namespace EliteBGS.LogGenerator;
|
||||
|
||||
public class MissionFormat : LogFormatter {
|
||||
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();
|
||||
}
|
||||
|
||||
public string GenerateLog(Objective objective) {
|
||||
Dictionary<string, Dictionary<string, int>> collated = new();
|
||||
Dictionary<string, ulong> passengers = new();
|
||||
@ -14,9 +67,11 @@ public class MissionFormat : LogFormatter {
|
||||
|
||||
var missions = objective.EnabledOfType<MissionCompleted>();
|
||||
var support = objective.EnabledOfType<InfluenceSupport>();
|
||||
var failed = objective.EnabledOfType<MissionFailed>();
|
||||
|
||||
if ((missions == null || missions.Count == 0) &&
|
||||
(support == null || support.Count == 0)) {
|
||||
(support == null || support.Count == 0) &&
|
||||
(failed == null || failed.Count == 0)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -60,6 +115,14 @@ public class MissionFormat : LogFormatter {
|
||||
|
||||
output.Append("\n");
|
||||
|
||||
// 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);
|
||||
|
||||
foreach (InfluenceSupport inf in support) {
|
||||
output.Append(inf.ToString());
|
||||
output.Append("\n");
|
||||
@ -86,11 +149,22 @@ public class MissionFormat : LogFormatter {
|
||||
.EnabledOfType<InfluenceSupport>()
|
||||
.Sum(x => x.Influence.InfluenceAmount)
|
||||
;
|
||||
long failed = objective
|
||||
.EnabledOfType<MissionFailed>()
|
||||
.Sum(x => x.InfluenceAmount)
|
||||
;
|
||||
|
||||
if (influence == 0 && support == 0) {
|
||||
if (influence == 0 && support == 0 && failed == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return string.Format("INF: {0}", influence + support);
|
||||
string failedsummary = GenerateFailedSummary(objective);
|
||||
string summary = string.Format("INF: {0}", influence + support + failed);
|
||||
|
||||
if (!string.IsNullOrEmpty(failedsummary)) {
|
||||
string.Join("; ", summary, failedsummary);
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user