fix mission fails

This commit is contained in:
Florian Stinglmayr 2022-12-20 18:33:09 +01:00
parent 3bd0cc1055
commit a9ce5be266
6 changed files with 84 additions and 39 deletions

View File

@ -17,9 +17,9 @@ public class InfluenceSupport : Transaction {
public MissionCompletedEntry? RelevantMission { get; set; }
/// <summary>
/// Mission accepted entry
/// Mission information
/// </summary>
public MissionAcceptedEntry? AcceptedEntry { get; set; }
public Mission? Mission { get; set; }
public override DateTime? CompletedAtDateTime {
get {

View File

@ -9,6 +9,8 @@ public class MissionCompleted : Transaction {
public MissionAcceptedEntry? AcceptedEntry { get; set; }
public Mission? Mission { get; set; }
public MissionCompleted() { }
public override DateTime? CompletedAtDateTime {
@ -45,15 +47,13 @@ public class MissionCompleted : Transaction {
/// </summary>
public override bool SystemContribution {
get {
if (AcceptedEntry == null ||
AcceptedEntry.Mission == null ||
AcceptedEntry.Mission.Name == null) {
if (Mission == null || Mission.Name == null) {
return false;
}
// If the mission starts with the name for thargoid war mission
// names, we assume its a system contribution
if (AcceptedEntry.Mission.Name.Contains("Mission_TW_")) {
if (Mission.Name.Contains("Mission_TW_")) {
return true;
}

View File

@ -4,16 +4,13 @@ using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS;
public class MissionFailed : Transaction {
public MissionFailedEntry? Failed { get; set; }
public MissionAcceptedEntry? Accepted { get; set; }
public Mission? Mission { get; set; }
public MissionFailed() { }
public MissionFailed(MissionAcceptedEntry accepted) {
if (accepted.Mission == null) {
throw new Exception("Mission cannot be null");
}
Accepted = accepted;
Faction = accepted.Mission.Faction;
public MissionFailed(MissionFailedEntry failed) {
Entries.Add(failed);
Failed = failed;
}
public override int CompareTo(Transaction? other) {
@ -46,13 +43,13 @@ public class MissionFailed : Transaction {
public override string ToString() {
StringBuilder builder = new StringBuilder();
if (Failed == null || Accepted == null) {
if (Failed == null || Mission == null) {
return "";
}
builder.AppendFormat("{0}x Mission failed: \"{1}\"",
Amount,
Failed?.Mission?.FriendlyName
Mission?.FriendlyName
);
return builder.ToString();

View File

@ -450,7 +450,7 @@ public class Report {
continue;
}
results.Add(new MissionFailed(accepted) {
results.Add(new MissionFailed(failed) {
Failed = failed,
System = accepted_system,
Station = accepted_station,

View File

@ -1,4 +1,5 @@
using EDPlayerJournal.Entries;
using EDPlayerJournal;
using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS;
@ -52,7 +53,7 @@ internal class TransactionParserContext {
/// <summary>
/// A list of accepted missions index by their mission ID
/// </summary>
public Dictionary<ulong, MissionAcceptedEntry> AcceptedMissions { get; } = new();
public Dictionary<ulong, Mission> AcceptedMissions { get; } = new();
public Dictionary<ulong, Location> AcceptedMissionLocation { get; } = new();
/// <summary>
/// A way to lookup a system by its system id
@ -187,16 +188,24 @@ internal class TransactionParserContext {
return SystemFactions[system];
}
public void MissionAccepted(MissionAcceptedEntry accepted) {
public void MissionAccepted(MissionAcceptedEntry? entry) {
if (entry == null) {
return;
}
MissionAccepted(entry.Mission);
}
public void MissionAccepted(Mission? mission) {
if (CurrentSystem == null || CurrentSystemAddress == null) {
throw new Exception("Mission accepted without knowing where.");
}
if (accepted.Mission == null) {
if (mission == null) {
throw new Exception("Mission is null");
}
AcceptedMissions.TryAdd(accepted.Mission.MissionID, accepted);
AcceptedMissions.TryAdd(mission.MissionID, mission);
Location location = new() {
StarSystem = CurrentSystem,
@ -204,7 +213,7 @@ internal class TransactionParserContext {
Station = (CurrentStation ?? ""),
};
AcceptedMissionLocation.TryAdd(accepted.Mission.MissionID, location);
AcceptedMissionLocation.TryAdd(mission.MissionID, location);
}
}
@ -420,6 +429,35 @@ internal class CommitCrimeParser : TransactionParserPart {
}
}
internal class MissionsParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
MissionsEntry? missions = entry as MissionsEntry;
if (missions == null) {
return;
}
if (context.CurrentSystem == null || context.CurrentSystemAddress == null) {
transactions.AddIncomplete(new MissionCompleted(),
"Could not determine current location on Missions event.",
entry
);
return;
}
foreach (Mission mission in missions.Active) {
try {
context.MissionAccepted(mission);
} catch (Exception exception) {
transactions.AddIncomplete(new MissionCompleted(),
exception.Message,
entry
);
}
}
}
}
internal class MissionAcceptedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
MissionAcceptedEntry? entry = e as MissionAcceptedEntry;
@ -453,13 +491,13 @@ internal class MissionCompletedParser : TransactionParserPart {
throw new NotImplementedException();
}
MissionAcceptedEntry? accepted = null;
Mission? mission = null;
Location? accepted_location = null;
string? target_faction_name = entry.Mission.TargetFaction;
string? source_faction_name = entry.Mission.Faction;
// We did not find when the mission was accepted.
if (!context.AcceptedMissions.TryGetValue(entry.Mission.MissionID, out accepted)) {
if (!context.AcceptedMissions.TryGetValue(entry.Mission.MissionID, out mission)) {
transactions.AddIncomplete(new MissionCompleted(),
String.Format("Mission acceptance for mission id {0} was not found",
entry.Mission.MissionID), e);
@ -529,7 +567,7 @@ internal class MissionCompletedParser : TransactionParserPart {
// for the source system. So we make a full mission completed entry.
transactions.Add(new MissionCompleted() {
CompletedEntry = entry,
AcceptedEntry = accepted,
Mission = mission,
System = accepted_location.StarSystem,
Faction = source_faction_name,
SystemAddress = accepted_location.SystemAddress,
@ -543,7 +581,7 @@ internal class MissionCompletedParser : TransactionParserPart {
// differs. Sometimes missions go to different systems but to
// the same faction.
transactions.Add(new InfluenceSupport() {
AcceptedEntry = accepted,
Mission = mission,
Faction = faction,
Influence = influences.Value,
System = system,
@ -559,7 +597,7 @@ internal class MissionCompletedParser : TransactionParserPart {
internal class MissionFailedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
MissionAcceptedEntry? accepted = null;
Mission? mission = null;
Location? accepted_location = null;
string? accepted_system = null;
@ -572,14 +610,14 @@ internal class MissionFailedParser : TransactionParserPart {
throw new InvalidJournalEntryException("No mission specified in mission failure");
}
if (!context.AcceptedMissions.TryGetValue(entry.Mission.MissionID, out accepted)) {
if (!context.AcceptedMissions.TryGetValue(entry.Mission.MissionID, out mission)) {
transactions.AddIncomplete(new MissionFailed(),
"Mission acceptance was not found", e
);
return;
}
if (!context.AcceptedMissionLocation.TryGetValue(entry.Mission.MissionID, out accepted_location)) {
if (!context.AcceptedMissionLocation.TryGetValue(mission.MissionID, out accepted_location)) {
transactions.AddIncomplete(new MissionFailed(),
"Unable to figure out where failed mission was accepted", e
);
@ -593,10 +631,9 @@ internal class MissionFailedParser : TransactionParserPart {
return;
}
transactions.Add(new MissionFailed() {
Accepted = accepted,
Faction = accepted.Mission?.Faction,
Failed = entry,
transactions.Add(new MissionFailed(entry) {
Faction = mission?.Faction,
Mission = mission,
Station = accepted_location.Station,
System = accepted_location.StarSystem,
SystemAddress = accepted_location.SystemAddress,
@ -931,6 +968,7 @@ public class TransactionParser {
{ Events.MissionAccepted, new MissionAcceptedParser() },
{ Events.MissionCompleted, new MissionCompletedParser() },
{ Events.MissionFailed, new MissionFailedParser() },
{ Events.Missions, new MissionsParser() },
{ Events.MultiSellExplorationData, new MultiSellExplorationDataParser() },
{ Events.ReceiveText, new ReceiveTextParser() },
{ Events.RedeemVoucher, new RedeemVoucherParser() },

View File

@ -14,13 +14,23 @@ public class FailedMissionFormat : LogFormatter {
return "";
}
foreach (MissionFailed failed in missions) {
foreach (var failed in missions) {
MissionFailedEntry f = failed.Failed;
builder.AppendFormat("Failed {0} mission(s) \"{1}\" targeting {2}\n",
failed.Amount,
string.IsNullOrEmpty(f.Mission.LocalisedName) ? f.Mission.Name : f.Mission.LocalisedName,
failed.Faction
);
string name;
if (!string.IsNullOrEmpty(f.Mission.FriendlyName)) {
name = f.Mission.FriendlyName;
} else if (!string.IsNullOrEmpty(f.Mission.LocalisedName)) {
name = f.Mission.LocalisedName;
} else {
name = f.Mission.Name;
}
if (!string.IsNullOrEmpty(failed.Faction)) {
builder.AppendFormat("Failed mission \"{0}\" targeting {1}\n", name, failed.Faction);
} else {
builder.AppendFormat("Failed mission \"{0}\"\n", name);
}
}
return builder.ToString().Trim();