refactor missions a bit

This commit is contained in:
Florian Stinglmayr 2022-12-03 14:16:45 +01:00
parent ac3d1cd8b9
commit 8d72808fbf
5 changed files with 66 additions and 20 deletions

View File

@ -10,8 +10,17 @@ namespace EDPlayerJournal.BGS;
/// </summary> /// </summary>
public class InfluenceSupport : Transaction { public class InfluenceSupport : Transaction {
public string Influence { get; set; } = ""; public string Influence { get; set; } = "";
/// <summary>
/// Relevant mission completed entry
/// </summary>
public MissionCompletedEntry? RelevantMission { get; set; } public MissionCompletedEntry? RelevantMission { get; set; }
/// <summary>
/// Mission accepted entry
/// </summary>
public MissionAcceptedEntry? AcceptedEntry { get; set; }
public override string CompletedAt { public override string CompletedAt {
get { get {
if (RelevantMission == null) { if (RelevantMission == null) {

View File

@ -1,50 +1,52 @@
using System.Text; using System.Collections.Generic;
using System.Text;
using EDPlayerJournal.Entries; using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS; namespace EDPlayerJournal.BGS;
public class MissionCompleted : Transaction { public class MissionCompleted : Transaction {
public MissionCompletedEntry? CompletedEntry { get; set; }
public MissionAcceptedEntry? AcceptedEntry { get; set; }
public MissionCompleted() { } public MissionCompleted() { }
public MissionCompleted(MissionCompletedEntry e) {
Entries.Add(e); public override string CompletedAt {
get {
if (CompletedEntry == null) {
return "";
}
return CompletedEntry.Timestamp.ToString("dd.MM.yyyy HH:mm UTC");
}
} }
public string MissionName { public string MissionName {
get { get {
MissionCompletedEntry? c = Entries[0] as MissionCompletedEntry; if (CompletedEntry == null || CompletedEntry.Mission == null) {
if (c == null || c.Mission == null) {
return ""; return "";
} }
return c.Mission.FriendlyName; return CompletedEntry.Mission.FriendlyName;
} }
} }
public string Influence { public string Influence {
get { get {
MissionCompletedEntry? e = (Entries[0] as MissionCompletedEntry); if (CompletedEntry == null || Faction == null || CompletedEntry.Mission == null) {
if (e == null || Faction == null || e.Mission == null) {
return ""; return "";
} }
return (e.Mission.GetInfluenceForFaction(Faction, SystemAddress) ?? ""); return (CompletedEntry.Mission.GetInfluenceForFaction(Faction, SystemAddress) ?? "");
} }
} }
public override string ToString() { public override string ToString() {
if (Faction == null || Entries.Count <= 0) { if (Faction == null || CompletedEntry == null || CompletedEntry.Mission == null) {
return ""; return "";
} }
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
var entry = Entries[0] as MissionCompletedEntry; var influence = CompletedEntry.Mission.GetInfluenceForFaction(Faction, SystemAddress);
if (entry == null || entry.Mission == null) {
return "";
}
var influence = entry.Mission.GetInfluenceForFaction(Faction, SystemAddress);
builder.AppendFormat("{0}", MissionName); builder.AppendFormat("{0}", MissionName);
if (influence != "") { if (influence != "") {

View File

@ -360,7 +360,9 @@ public class Report {
if (faction.Equals(source_faction_name) && system_address == accepted_address) { if (faction.Equals(source_faction_name) && system_address == accepted_address) {
/* This is the influence block for the origin of the mission. /* This is the influence block for the origin of the mission.
*/ */
main_mission = new MissionCompleted(completed) { main_mission = new MissionCompleted() {
CompletedEntry = completed,
AcceptedEntry = accepted,
System = accepted_system, System = accepted_system,
Faction = source_faction_name, Faction = source_faction_name,
SystemAddress = accepted_address, SystemAddress = accepted_address,

View File

@ -499,7 +499,9 @@ internal class MissionCompletedParser : TransactionParserPart {
system_address == accepted_location.SystemAddress) { system_address == accepted_location.SystemAddress) {
// Source and target faction are the same, and this is the block // Source and target faction are the same, and this is the block
// for the source system. So we make a full mission completed entry. // for the source system. So we make a full mission completed entry.
transactions.Add(new MissionCompleted(entry) { transactions.Add(new MissionCompleted() {
CompletedEntry = entry,
AcceptedEntry = accepted,
System = accepted_location.StarSystem, System = accepted_location.StarSystem,
Faction = source_faction_name, Faction = source_faction_name,
SystemAddress = accepted_location.SystemAddress, SystemAddress = accepted_location.SystemAddress,
@ -513,6 +515,7 @@ internal class MissionCompletedParser : TransactionParserPart {
// differs. Sometimes missions go to different systems but to // differs. Sometimes missions go to different systems but to
// the same faction. // the same faction.
transactions.Add(new InfluenceSupport() { transactions.Add(new InfluenceSupport() {
AcceptedEntry = accepted,
Faction = faction, Faction = faction,
Influence = influences.Value, Influence = influences.Value,
System = system, System = system,

View File

@ -109,6 +109,11 @@ public class MissionFactionEffects {
} }
public class Mission : IComparable<Mission> { public class Mission : IComparable<Mission> {
/// <summary>
/// Passenger type for refugees
/// </summary>
public static readonly string PassengerTypeRefugee = "PassengerRefugee";
public ulong MissionID { get; set; } = 0; public ulong MissionID { get; set; } = 0;
/// <summary> /// <summary>
@ -250,6 +255,31 @@ public class Mission : IComparable<Mission> {
/// </summary> /// </summary>
public List<MissionFactionEffects> FactionEffects { get; set; } = new List<MissionFactionEffects>(); public List<MissionFactionEffects> FactionEffects { get; set; } = new List<MissionFactionEffects>();
public bool IsPassengerMission {
get {
if (PassengerCount == null || PassengerCount == 0) {
return false;
}
return true;
}
}
public bool IsRescueMission {
get {
if (!IsPassengerMission) {
return false;
}
if (string.Compare(PassengerType, PassengerTypeRefugee) == 0) {
return true;
}
return false;
}
}
/// <summary> /// <summary>
/// Returns a friendly human-readable name for the mission. If a localised name is available /// Returns a friendly human-readable name for the mission. If a localised name is available
/// it will use that, baring that it will check EnglishMissionNames for a translation, and /// it will use that, baring that it will check EnglishMissionNames for a translation, and