2022-11-01 18:01:28 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using EDPlayerJournal.Entries;
|
|
|
|
|
|
|
|
|
|
namespace EDPlayerJournal.BGS;
|
|
|
|
|
public class MissionFailed : Transaction {
|
|
|
|
|
public MissionFailedEntry? Failed { get; set; }
|
|
|
|
|
public MissionAcceptedEntry? Accepted { get; set; }
|
|
|
|
|
|
|
|
|
|
public MissionFailed() { }
|
|
|
|
|
|
|
|
|
|
public MissionFailed(MissionAcceptedEntry accepted) {
|
2022-11-24 14:18:27 +01:00
|
|
|
|
if (accepted.Mission == null) {
|
|
|
|
|
throw new Exception("Mission cannot be null");
|
|
|
|
|
}
|
2022-11-01 18:01:28 +01:00
|
|
|
|
Accepted = accepted;
|
2022-11-24 14:18:27 +01:00
|
|
|
|
Faction = accepted.Mission.Faction;
|
2022-11-01 18:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int CompareTo(Transaction? other) {
|
|
|
|
|
if (other == null || other.GetType() != typeof(MissionFailed)) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MissionFailed? failed = other as MissionFailed;
|
|
|
|
|
|
|
|
|
|
if (failed == null) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if it is the same mission name, the same faction and the same system,
|
|
|
|
|
* collate mission failures together */
|
|
|
|
|
if (failed.Failed?.HumanReadableName == Failed?.HumanReadableName &&
|
|
|
|
|
failed.Faction == Faction &&
|
|
|
|
|
failed.System == System) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// +1 since the other entries are just copies of the one we have in our properties
|
|
|
|
|
public int Amount => Entries.Count + 1;
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
if (Failed == null || Accepted == null) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.AppendFormat("{0}x Mission failed: \"{1}\"",
|
|
|
|
|
Amount,
|
|
|
|
|
Failed.HumanReadableName != null ? Failed.HumanReadableName : Failed.Name
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return builder.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|