From aeaa6b5220babfe172c44b3a246ebd4aed11f29a Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 14 Nov 2024 13:30:31 +0100 Subject: [PATCH] add preliminary support for merits gained --- EDPlayerJournal/BGS/MeritsGained.cs | 25 ++++++++++++++++ .../BGS/Parsers/PowerplayParser.cs | 29 +++++++++++++++++++ EDPlayerJournal/BGS/TransactionParser.cs | 1 + .../BGS/TransactionParserContext.cs | 10 +++++++ 4 files changed, 65 insertions(+) create mode 100644 EDPlayerJournal/BGS/MeritsGained.cs create mode 100644 EDPlayerJournal/BGS/Parsers/PowerplayParser.cs diff --git a/EDPlayerJournal/BGS/MeritsGained.cs b/EDPlayerJournal/BGS/MeritsGained.cs new file mode 100644 index 0000000..872b018 --- /dev/null +++ b/EDPlayerJournal/BGS/MeritsGained.cs @@ -0,0 +1,25 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS; + +public class MeritsGained : Transaction { + public MeritsGained() { } + + public MeritsGained(Entry entry) { + Entries.Add(entry); + } + + /// + /// Number of merits gained + /// + public long Merits { get; set; } = 0; + + /// + /// For what power those merits were gained + /// + public string Power { get; set; } = string.Empty; + + public override string ToString() { + return string.Format("{0} Merits gained for {1}", Merits, Power); + } +} diff --git a/EDPlayerJournal/BGS/Parsers/PowerplayParser.cs b/EDPlayerJournal/BGS/Parsers/PowerplayParser.cs new file mode 100644 index 0000000..2550628 --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/PowerplayParser.cs @@ -0,0 +1,29 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS.Parsers; + +internal class PowerplayParser : ITransactionParserPart { + public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + PowerplayEntry? p = entry as PowerplayEntry; + if (p == null) { + return; + } + + if (context.LastMerits == null) { + context.LastMerits = p.Merits; + } + + context.CurrentMerits = p.Merits; + + if (context.LastMerits != context.CurrentMerits) { + transactions.Add(new MeritsGained(entry) { + Merits = ((long)(context.CurrentMerits - context.LastMerits)), + Power = p.Power, + System = context.CurrentSystem, + Faction = p.Power, + }); + } + + context.LastMerits = context.CurrentMerits; + } +} diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index 32c7bb6..e34240a 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -638,6 +638,7 @@ public class TransactionParser { { Events.Missions, new MissionsParser() }, { Events.MultiSellExplorationData, new MultiSellExplorationDataParser() }, { Events.Music, new MusicParser() }, + { Events.Powerplay, new PowerplayParser() }, { Events.ReceiveText, new ReceiveTextParser() }, { Events.RedeemVoucher, new RedeemVoucherParser() }, { Events.SearchAndRescue, new SearchAndRescueParser() }, diff --git a/EDPlayerJournal/BGS/TransactionParserContext.cs b/EDPlayerJournal/BGS/TransactionParserContext.cs index 94647fa..04a0f22 100644 --- a/EDPlayerJournal/BGS/TransactionParserContext.cs +++ b/EDPlayerJournal/BGS/TransactionParserContext.cs @@ -69,6 +69,16 @@ internal class TransactionParserContext { /// public string? Settlement { get; set; } = null; + /// + /// Current Merits + /// + public long? CurrentMerits { get; set; } = null; + + /// + /// Merits from last login + /// + public long? LastMerits { get; set; } = null; + /// /// Returns true if the current session is legacy ///