move mission related logic to mission class

This commit is contained in:
2022-11-24 15:53:40 +01:00
parent ce54430137
commit f4bbdfd1b3
8 changed files with 309 additions and 230 deletions

View File

@@ -25,8 +25,8 @@ public class InfluenceSupport : Transaction {
StringBuilder builder = new StringBuilder();
string? missionname;
if (RelevantMission != null) {
missionname = RelevantMission.HumanReadableName;
if (RelevantMission != null && RelevantMission.Mission != null) {
missionname = RelevantMission.Mission.LocalisedName;
} else {
missionname = "UNKNOWN MISSION";
}

View File

@@ -12,14 +12,14 @@ public class MissionCompleted : Transaction {
public string MissionName {
get {
MissionCompletedEntry? c = Entries[0] as MissionCompletedEntry;
if (c == null) {
if (c == null || c.Mission == null) {
return "";
}
if (string.IsNullOrEmpty(c.HumanReadableName)) {
return (c.Name ?? "");
if (string.IsNullOrEmpty(c.Mission.LocalisedName)) {
return (c.Mission.Name ?? "");
} else {
return c.HumanReadableName;
return c.Mission.LocalisedName;
}
}
}
@@ -28,15 +28,11 @@ public class MissionCompleted : Transaction {
get {
MissionCompletedEntry? e = (Entries[0] as MissionCompletedEntry);
if (e == null || Faction == null) {
if (e == null || Faction == null || e.Mission == null) {
return "";
}
if (SystemAddress == 0) {
return (e.GetInfluenceForFaction(Faction) ?? "");
} else {
return (e.GetInfluenceForFaction(Faction, SystemAddress) ?? "");
}
return (e.Mission.GetInfluenceForFaction(Faction, SystemAddress) ?? "");
}
}
@@ -48,11 +44,11 @@ public class MissionCompleted : Transaction {
StringBuilder builder = new StringBuilder();
var entry = Entries[0] as MissionCompletedEntry;
if (entry == null) {
if (entry == null || entry.Mission == null) {
return "";
}
var influence = entry.GetInfluenceForFaction(Faction, SystemAddress);
var influence = entry.Mission.GetInfluenceForFaction(Faction, SystemAddress);
builder.AppendFormat("{0}", MissionName);
if (influence != "") {

View File

@@ -231,7 +231,7 @@ public class Report {
MissionCompletedEntry? completed = e as MissionCompletedEntry;
if (completed == null ||
completed.MissionID == null) {
completed.Mission == null) {
continue;
}
@@ -240,48 +240,38 @@ public class Report {
ulong accepted_address;
string? accepted_system;
string? target_faction_name = completed.TargetFaction;
string? source_faction_name = completed.Faction;
string? target_faction_name = completed.Mission.TargetFaction;
string? source_faction_name = completed.Mission.Faction;
if (!acceptedMissions.TryGetValue(completed.MissionID.Value, out accepted)) {
if (!acceptedMissions.TryGetValue(completed.Mission.MissionID, out accepted)) {
OnLog?.Invoke(string.Format(
"Unable to find mission acceptance for mission \"{0}\". " +
"Please extend range to include the mission acceptance.", completed.HumanReadableName
"Please extend range to include the mission acceptance.", completed.Mission.LocalisedName
));
continue;
}
if (!acceptedSystems.TryGetValue(completed.MissionID.Value, out accepted_address)) {
if (!acceptedSystems.TryGetValue(completed.Mission.MissionID, out accepted_address)) {
OnLog?.Invoke(string.Format(
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.Mission.LocalisedName
));
continue;
}
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
OnLog?.Invoke(string.Format(
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.Mission.LocalisedName
));
continue;
}
if (completed.HumanReadableNameWasGenerated) {
/* If the human readable name was generated, we send a log message. Because the
* generated names all sort of suck, we should have more human readable names in
* in the lookup dictionary.
*/
OnLog?.Invoke("Human readable name for mission \"" +
completed.Name +
"\" was generated, please report this.");
}
foreach (var other in completed.Influences) {
foreach (var other in completed.Mission.Influences) {
string faction = other.Key;
if (string.IsNullOrEmpty(faction)) {
OnLog?.Invoke(string.Format(
"Mission \"{0}\" has empty faction name in influence block, "+
"so this influence support was ignored. " +
"Please check the README on why this happens.", completed.HumanReadableName)
"Please check the README on why this happens.", completed.Mission.LocalisedName)
);
continue;
}
@@ -294,7 +284,7 @@ public class Report {
"Mission \"{0}\" gave no influence to \"{1}\", so we assume this is because the " +
"faction is in a conflict and cannot gain influence right now. " +
"If this assessment is wrong, just remove the entry from the objective list.",
completed.HumanReadableName, faction
completed.Mission.LocalisedName, faction
));
if (string.Compare(target_faction_name, faction, true) == 0) {
@@ -310,7 +300,7 @@ public class Report {
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the target faction " +
"of the mission, we assume the influence was gained in \"{2}\". " +
"Please remove the entry if this assumption is wrong.",
completed.HumanReadableName, faction, current_system
completed.Mission.LocalisedName, faction, current_system
));
} else if (string.Compare(source_faction_name, faction, true) == 0) {
/* source faction of the mission is not getting any influence. This could be because
@@ -324,7 +314,7 @@ public class Report {
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the source faction " +
"of the mission, we assume the influence was gained in \"{2}\". " +
"Please remove the entry if this assumption is wrong.",
completed.HumanReadableName, faction, accepted_system
completed.Mission.LocalisedName, faction, accepted_system
));
/* check if source/target faction are equal, in which case we also need an entry
@@ -338,7 +328,7 @@ public class Report {
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the source and target faction " +
"of the mission, we assume the influence was also gained in target system \"{2}\". " +
"Please remove the entry if this assumption is wrong.",
completed.HumanReadableName, faction, current_system
completed.Mission.LocalisedName, faction, current_system
));
}
}
@@ -349,7 +339,7 @@ public class Report {
string? system;
string? accepted_station;
if (completed.MissionID == null) {
if (completed.Mission == null) {
continue;
}
@@ -360,9 +350,9 @@ public class Report {
continue;
}
if (!acceptedStations.TryGetValue(completed.MissionID.Value, out accepted_station)) {
if (!acceptedStations.TryGetValue(completed.Mission.MissionID, out accepted_station)) {
OnLog?.Invoke(string.Format(
"Unable to figure out in which station mission \"{0}\" was accepted.", completed.HumanReadableName
"Unable to figure out in which station mission \"{0}\" was accepted.", completed.Mission.LocalisedName
));
continue;
}

View File

@@ -272,38 +272,34 @@ internal class MissionAcceptedParser : TransactionParserPart {
internal class MissionCompletedParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
MissionCompletedEntry? entry = e as MissionCompletedEntry;
if (entry == null) {
if (entry == null || entry.Mission == null) {
throw new NotImplementedException();
}
if (entry.MissionID == null) {
throw new InvalidJournalEntryException("mission completed has no mission ID");
}
MissionAcceptedEntry? accepted = null;
Location? accepted_location = null;
string? target_faction_name = entry.TargetFaction;
string? source_faction_name = entry.Faction;
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.MissionID.Value, out accepted)) {
if (!context.AcceptedMissions.TryGetValue(entry.Mission.MissionID, out accepted)) {
transactions.AddIncomplete(new MissionCompleted(),
String.Format("Mission acceptance for mission id {0} was not found",
entry.MissionID.Value));
entry.Mission.MissionID));
return;
}
if (!context.AcceptedMissionLocation.TryGetValue(entry.MissionID.Value, out accepted_location)) {
if (!context.AcceptedMissionLocation.TryGetValue(entry.Mission.MissionID, out accepted_location)) {
transactions.AddIncomplete(new MissionCompleted(),
String.Format("Location for acceptance for mission id {0} was not found",
entry.MissionID.Value));
entry.Mission.MissionID));
return;
}
// This block does some preliminary "repairs" on the influences block of a completed
// mission. Sometimes these entries are broken, or are missing information for later
// parsing.
foreach (var other in entry.Influences) {
foreach (var other in entry.Mission.Influences) {
string faction = other.Key;
if (string.IsNullOrEmpty(faction)) {
// Target faction might be empty string, in special cases. For example if you