fix mission fails
This commit is contained in:
@@ -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() },
|
||||
|
||||
Reference in New Issue
Block a user