add a Mission class for accepted missions
This commit is contained in:
parent
607171f050
commit
1d19a8f73c
@ -9,8 +9,11 @@ public class MissionFailed : Transaction {
|
||||
public MissionFailed() { }
|
||||
|
||||
public MissionFailed(MissionAcceptedEntry accepted) {
|
||||
if (accepted.Mission == null) {
|
||||
throw new Exception("Mission cannot be null");
|
||||
}
|
||||
Accepted = accepted;
|
||||
Faction = accepted.Faction;
|
||||
Faction = accepted.Mission.Faction;
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
|
@ -401,7 +401,11 @@ public class Report {
|
||||
continue;
|
||||
}
|
||||
|
||||
ulong id = accepted.MissionID;
|
||||
if (accepted.Mission == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ulong id = accepted.Mission.MissionID;
|
||||
|
||||
if (!acceptedMissions.ContainsKey(id)) {
|
||||
acceptedMissions[id] = accepted;
|
||||
@ -429,23 +433,27 @@ public class Report {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (accepted.Mission == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedSystems.TryGetValue(failed.MissionID, out accepted_address)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Name
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Mission.Name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Name
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Mission.Name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedStations.TryGetValue(failed.MissionID, out accepted_station)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which station mission \"{0}\" was accepted.", accepted.Name
|
||||
"Unable to figure out in which station mission \"{0}\" was accepted.", accepted.Mission.Name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
@ -454,7 +462,7 @@ public class Report {
|
||||
Failed = failed,
|
||||
System = accepted_system,
|
||||
Station = accepted_station,
|
||||
Faction = accepted.Faction,
|
||||
Faction = accepted.Mission.Faction,
|
||||
SystemAddress = accepted_address,
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,11 @@ internal class TransactionParserContext {
|
||||
throw new Exception("Mission accepted without knowing where.");
|
||||
}
|
||||
|
||||
AcceptedMissions.TryAdd(accepted.MissionID, accepted);
|
||||
if (accepted.Mission == null) {
|
||||
throw new Exception("Mission is null");
|
||||
}
|
||||
|
||||
AcceptedMissions.TryAdd(accepted.Mission.MissionID, accepted);
|
||||
|
||||
Location location = new() {
|
||||
StarSystem = CurrentSystem,
|
||||
@ -61,7 +65,7 @@ internal class TransactionParserContext {
|
||||
Station = (CurrentStation ?? ""),
|
||||
};
|
||||
|
||||
AcceptedMissionLocation.TryAdd(accepted.MissionID, location);
|
||||
AcceptedMissionLocation.TryAdd(accepted.Mission.MissionID, location);
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,7 +412,7 @@ internal class MissionFailedParser : TransactionParserPart {
|
||||
|
||||
transactions.Add(new MissionFailed() {
|
||||
Accepted = accepted,
|
||||
Faction = accepted.Faction,
|
||||
Faction = accepted.Mission?.Faction,
|
||||
Failed = entry,
|
||||
Station = accepted_location.Station,
|
||||
System = accepted_location.StarSystem,
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
|
||||
@ -55,11 +56,14 @@ public class Entry {
|
||||
}
|
||||
|
||||
public static Entry? Parse(string journalline) {
|
||||
var json = JObject.Parse(journalline);
|
||||
if (json == null) {
|
||||
return null;
|
||||
using (JsonReader reader = new JsonTextReader(new StringReader(journalline))) {
|
||||
reader.DateParseHandling = DateParseHandling.None;
|
||||
var json = JObject.Load(reader);
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
return Parse(json);
|
||||
}
|
||||
return Parse(json);
|
||||
}
|
||||
|
||||
public static Entry? Parse(JObject json) {
|
||||
|
@ -1,22 +1,9 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
|
||||
public class MissionAcceptedEntry : Entry {
|
||||
public string? Faction { get; set; }
|
||||
public string? TargetFaction { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? LocalisedName { get; set; }
|
||||
public string? LocalisedTargetType { get; set; }
|
||||
public int KillCount { get; set; }
|
||||
public ulong MissionID { get; set; }
|
||||
public long Reward { get; set; }
|
||||
public Mission? Mission { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
Faction = JSON.Value<string>("Faction");
|
||||
TargetFaction = JSON.Value<string>("TargetFaction");
|
||||
Name = JSON.Value<string>("Name");
|
||||
LocalisedName = JSON.Value<string>("LocalisedName");
|
||||
LocalisedTargetType = JSON.Value<string>("TargetType_Localised");
|
||||
KillCount = JSON.Value<int?>("KillCount") ?? 0;
|
||||
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
|
||||
Reward = JSON.Value<long?>("Reward") ?? 0;
|
||||
Mission = Mission.FromMissionAccepted(JSON);
|
||||
}
|
||||
}
|
||||
|
189
EDPlayerJournal/Mission.cs
Normal file
189
EDPlayerJournal/Mission.cs
Normal file
@ -0,0 +1,189 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
|
||||
public class Mission : IComparable<Mission> {
|
||||
public ulong MissionID { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the mission, in machine readable format.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Localised, human readable mission name.
|
||||
/// </summary>
|
||||
public string? LocalisedName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Target of the mission. Optional.
|
||||
/// </summary>
|
||||
public string? Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Target of the mission as a localised human readable string.
|
||||
/// </summary>
|
||||
public string? TargetLocalised { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Target system of the mission
|
||||
/// </summary>
|
||||
public string? DestinationSystem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Destination station.
|
||||
/// </summary>
|
||||
public string? DestinationStation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Destination settlement
|
||||
/// </summary>
|
||||
public string? DestinationSettlement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// In case of redirection, these values denote the new system.
|
||||
/// </summary>
|
||||
public string? NewDestinationSystem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// In case of redirection, these values denote the new station.
|
||||
/// </summary>
|
||||
public string? NewDestinationStation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Faction offering the mission.
|
||||
/// </summary>
|
||||
public string? Faction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Target faction (for example for courier missions).
|
||||
/// </summary>
|
||||
public string? TargetFaction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the mission is a wing message.
|
||||
/// </summary>
|
||||
public bool Wing { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Expiry date for the mission.
|
||||
/// </summary>
|
||||
public string? Expiry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Influence reward offered. This is for accepting missions only, see the
|
||||
/// mission effects for actual effects once the mission is complete.
|
||||
/// </summary>
|
||||
public string? Influence { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reputation reward offered.
|
||||
/// </summary>
|
||||
public string? Reputation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of kills required for massacre missions.
|
||||
/// </summary>
|
||||
public ulong? KillCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Monatery reward offered for the mission. Optional, as donate missions don't give
|
||||
/// a monatery reward.
|
||||
/// </summary>
|
||||
public ulong? Reward { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Amount donated for donation missions, optional. If this is null, then
|
||||
/// the mission was not a donation mission.
|
||||
/// </summary>
|
||||
public ulong? Donation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Actual amount donated.
|
||||
/// </summary>
|
||||
public ulong? Donated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Commodity delivered, or donated. Optional, if this is null, then no
|
||||
/// commodity was donated or delivered.
|
||||
/// </summary>
|
||||
public string? Commodity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Amount of the commodity donated or delivered. Optional.
|
||||
/// </summary>
|
||||
public ulong? Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// How many passengers are being transported.
|
||||
/// </summary>
|
||||
public ulong? PassengerCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If the passengers are VIPs.
|
||||
/// </summary>
|
||||
public bool? PassengerVIPs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If the passengers are wanted.
|
||||
/// </summary>
|
||||
public bool? PassengerWanted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// What sort of passengers are being transported.
|
||||
/// </summary>
|
||||
public string? PassengerType { get; set; }
|
||||
|
||||
public int CompareTo(Mission? other) {
|
||||
if (other == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return MissionID.CompareTo(other.MissionID);
|
||||
}
|
||||
|
||||
private static Mission FromJSON(JObject o) {
|
||||
Mission mission = new Mission();
|
||||
|
||||
mission.MissionID = o.Value<ulong?>("MissionID") ?? 0;
|
||||
|
||||
mission.Reputation = o.Value<string>("Reputation");
|
||||
mission.Influence = o.Value<string>("Influence");
|
||||
|
||||
mission.DestinationSystem = o.Value<string>("DestinationSystem");
|
||||
mission.DestinationSettlement = o.Value<string>("DestinationSettlement");
|
||||
mission.DestinationStation = o.Value<string>("DestinationStation");
|
||||
|
||||
mission.NewDestinationSystem = o.Value<string>("NewDestinationSystem");
|
||||
mission.NewDestinationStation = o.Value<string>("NewDestinationSystem");
|
||||
|
||||
mission.Reward = o.Value<ulong?>("Reward");
|
||||
|
||||
mission.Target = o.Value<string>("Target");
|
||||
mission.TargetLocalised = o.Value<string>("Target_Localised");
|
||||
|
||||
mission.Expiry = o.Value<JToken>("Expiry")?.ToString();
|
||||
mission.Wing = o.Value<bool?>("Wing") ?? false;
|
||||
|
||||
mission.Name = o.Value<string>("Name");
|
||||
mission.LocalisedName = o.Value<string>("LocalisedName");
|
||||
|
||||
mission.Faction = o.Value<string?>("Faction");
|
||||
|
||||
mission.Donation = o.Value<ulong?>("Donation");
|
||||
mission.Donated = o.Value<ulong?>("Donated");
|
||||
|
||||
mission.PassengerCount = o.Value<ulong?>("PassengerCount");
|
||||
mission.PassengerVIPs = o.Value<bool?>("PassengerVIPs");
|
||||
mission.PassengerWanted = o.Value<bool?>("PassengerWanted");
|
||||
mission.PassengerType = o.Value<string>("PassengerType");
|
||||
|
||||
mission.KillCount = o.Value<ulong?>("KillCount");
|
||||
|
||||
return mission;
|
||||
}
|
||||
|
||||
public static Mission FromMissionAccepted(JObject o) {
|
||||
return FromJSON(o);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
|
37
EDPlayerJournalTests/MissionTest.cs
Normal file
37
EDPlayerJournalTests/MissionTest.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournalTests;
|
||||
|
||||
[TestClass]
|
||||
public class MissionTest {
|
||||
|
||||
[TestMethod]
|
||||
public void TestMissionAccepted() {
|
||||
string altruism = /*lang=json,strict*/ """{ "timestamp":"2022-11-23T08:05:54Z", "event":"MissionAccepted", "Faction":"HIP 6182 Federal Inc", "Name":"Mission_AltruismCredits", "LocalisedName":"Donate 1,000,000 Cr to the cause", "Donation":"1000000", "Expiry":"2022-11-23T11:50:52Z", "Wing":false, "Influence":"++", "Reputation":"++", "MissionID":901601358 }""";
|
||||
|
||||
Entry? entry = Entry.Parse(altruism);
|
||||
|
||||
Assert.IsNotNull(entry);
|
||||
Assert.IsInstanceOfType(entry, typeof(MissionAcceptedEntry));
|
||||
|
||||
MissionAcceptedEntry? accepted = entry as MissionAcceptedEntry;
|
||||
|
||||
Assert.IsNotNull(accepted);
|
||||
Assert.IsNotNull(accepted.Mission);
|
||||
|
||||
Assert.AreEqual(accepted.Mission.MissionID, (ulong)901601358);
|
||||
Assert.AreEqual(accepted.Mission.Faction, "HIP 6182 Federal Inc");
|
||||
Assert.AreEqual(accepted.Mission.Name, "Mission_AltruismCredits");
|
||||
Assert.AreEqual(accepted.Mission.LocalisedName, "Donate 1,000,000 Cr to the cause");
|
||||
Assert.AreEqual(accepted.Mission.Donation, (ulong)1000000);
|
||||
Assert.AreEqual(accepted.Mission.Expiry, "2022-11-23T11:50:52Z");
|
||||
Assert.AreEqual(accepted.Mission.Wing, false);
|
||||
Assert.AreEqual(accepted.Mission.Reputation, "++");
|
||||
Assert.AreEqual(accepted.Mission.Influence, "++");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user