From 9994a45d06781b4ea9c26a005a70c95781c98821 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Mon, 29 Jan 2024 18:23:19 +0100 Subject: [PATCH] fix location not updating on carrier jumps --- .../BGS/Parsers/CarrierJumpParser.cs | 30 +++++++++++++ EDPlayerJournal/BGS/TransactionParser.cs | 1 + EDPlayerJournal/Entries/CarrierJump.cs | 44 +++++++++++++++++++ EDPlayerJournal/Entries/Entry.cs | 1 + EDPlayerJournal/Entries/Events.cs | 1 + 5 files changed, 77 insertions(+) create mode 100644 EDPlayerJournal/BGS/Parsers/CarrierJumpParser.cs create mode 100644 EDPlayerJournal/Entries/CarrierJump.cs diff --git a/EDPlayerJournal/BGS/Parsers/CarrierJumpParser.cs b/EDPlayerJournal/BGS/Parsers/CarrierJumpParser.cs new file mode 100644 index 0000000..0c1520c --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/CarrierJumpParser.cs @@ -0,0 +1,30 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS.Parsers; + +internal class CarrierJumpParser : ITransactionParserPart { + public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + CarrierJump? jump = entry as CarrierJump; + + if (jump == null) { + return; + } + + if (!jump.Docked) { + return; + } + + context.CurrentSystem = jump.StarSystem; + context.CurrentSystemAddress = jump.SystemAddress; + + context.SystemsByID.TryAdd(jump.SystemAddress, jump.StarSystem); + + if (!string.IsNullOrEmpty(jump.SystemFaction)) { + context.ControllingFaction = jump.SystemFaction; + } + + if (jump.SystemFactions != null && jump.SystemFactions.Count > 0) { + context.SystemFactions[jump.StarSystem] = jump.SystemFactions; + } + } +} diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index 73cea6a..027c223 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -665,6 +665,7 @@ public class TransactionParser { { { Events.ApproachSettlement, new ApproachSettlementParser() }, { Events.CapShipBond, new CapShipBondParser() }, + { Events.CarrierJump, new CarrierJumpParser() }, { Events.Commander, new CommanderParser() }, { Events.CommitCrime, new CommitCrimeParser() }, { Events.Died, new DiedParser() }, diff --git a/EDPlayerJournal/Entries/CarrierJump.cs b/EDPlayerJournal/Entries/CarrierJump.cs new file mode 100644 index 0000000..27b6860 --- /dev/null +++ b/EDPlayerJournal/Entries/CarrierJump.cs @@ -0,0 +1,44 @@ +using Newtonsoft.Json.Linq; + +namespace EDPlayerJournal.Entries; + +public class CarrierJump : Entry { + public bool Docked { get; set; } = false; + + public string? StationName { get; set; } = null; + + public string? StationType { get; set; } = null; + + public string? StarSystem { get; set; } = null; + + public ulong SystemAddress { get; set; } = 0; + + public string? SystemFaction { get; set; } = null; + + public List SystemFactions { get; set; } = new List(); + + protected override void Initialise() { + Docked = JSON.Value("Docked") ?? false; + + StarSystem = JSON.Value("StarSystem"); + SystemAddress = JSON.Value("SystemAddress") ?? 0; + + StationName = JSON.Value("StationName"); + StationType = JSON.Value("StationType"); + + var faction = JSON.Value("SystemFaction"); + if (faction != null) { + SystemFaction = faction.Value("Name"); + } + + var factions = JSON.Value("Factions"); + if (factions != null) { + foreach (JObject system_faction in factions) { + Faction? f = Faction.FromJSON(system_faction); + if (f != null) { + SystemFactions.Add(f); + } + } + } + } +} diff --git a/EDPlayerJournal/Entries/Entry.cs b/EDPlayerJournal/Entries/Entry.cs index 3a9b01b..41d5abc 100644 --- a/EDPlayerJournal/Entries/Entry.cs +++ b/EDPlayerJournal/Entries/Entry.cs @@ -15,6 +15,7 @@ public class Entry { { Events.ApproachSettlement, typeof(ApproachSettlementEntry) }, { Events.Bounty, typeof(BountyEntry) }, { Events.CapShipBond, typeof(CapShipBondEntry) }, + { Events.CarrierJump, typeof(CarrierJump) }, { Events.Commander, typeof(CommanderEntry) }, { Events.CommitCrime, typeof(CommitCrimeEntry) }, { Events.Died, typeof(DiedEntry) }, diff --git a/EDPlayerJournal/Entries/Events.cs b/EDPlayerJournal/Entries/Events.cs index 88afa82..5e286a4 100644 --- a/EDPlayerJournal/Entries/Events.cs +++ b/EDPlayerJournal/Entries/Events.cs @@ -4,6 +4,7 @@ public class Events { public static readonly string ApproachSettlement = "ApproachSettlement"; public static readonly string Bounty = "Bounty"; public static readonly string CapShipBond = "CapShipBond"; + public static readonly string CarrierJump = "CarrierJump"; public static readonly string Commander = "Commander"; public static readonly string CommitCrime = "CommitCrime"; public static readonly string Died = "Died";