From bec73931b9bc6a3df7f135f01bdfb9d3902754a9 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Mon, 15 May 2023 18:15:38 +0200 Subject: [PATCH] add an option to ignore Fleet Carrier faction --- .../BGS/Parsers/MarketBuyParser.cs | 44 +++++ .../BGS/Parsers/MarketSellParser.cs | 45 ++++++ .../Parsers/MultiSellExplorationDataParser.cs | 33 ++++ .../BGS/Parsers/SellExplorationDataParser.cs | 33 ++++ .../BGS/Parsers/SellOrganicDataParser.cs | 38 +++++ EDPlayerJournal/BGS/TransactionParser.cs | 153 +----------------- 6 files changed, 198 insertions(+), 148 deletions(-) create mode 100644 EDPlayerJournal/BGS/Parsers/MarketBuyParser.cs create mode 100644 EDPlayerJournal/BGS/Parsers/MarketSellParser.cs create mode 100644 EDPlayerJournal/BGS/Parsers/MultiSellExplorationDataParser.cs create mode 100644 EDPlayerJournal/BGS/Parsers/SellExplorationDataParser.cs create mode 100644 EDPlayerJournal/BGS/Parsers/SellOrganicDataParser.cs diff --git a/EDPlayerJournal/BGS/Parsers/MarketBuyParser.cs b/EDPlayerJournal/BGS/Parsers/MarketBuyParser.cs new file mode 100644 index 0000000..fe6cb8f --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/MarketBuyParser.cs @@ -0,0 +1,44 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS; + +internal class MarketBuyParser : ITransactionParserPart { + public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + MarketBuyEntry? entry = e as MarketBuyEntry; + if (entry == null) { + throw new NotImplementedException(); + } + + context.BoughtCargo(entry.Type, entry.BuyPrice); + + // We still want the information on buy price for profit, + // but if the option is on, we don't care for parsing it + // further. + // TODO: might be wise to split this parser into two; one for + // determining profit, the other for the BGS information + if (options.IgnoreMarketBuy) { + return; + } + + if (context.StationOwner == null) { + transactions.AddIncomplete( + new OrganicData(), + "Could not discern the station owner for market buy.", + e); + return; + } + + // Ignore if its a fleet carrier faction. + if (string.Compare(context.StationOwner, Factions.FleetCarrier, StringComparison.OrdinalIgnoreCase) == 0 && + options.IgnoreFleetCarrierFaction) { + return; + } + + transactions.Add(new BuyCargo(entry) { + System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, + IsLegacy = context.IsLegacy, + }); + } +} diff --git a/EDPlayerJournal/BGS/Parsers/MarketSellParser.cs b/EDPlayerJournal/BGS/Parsers/MarketSellParser.cs new file mode 100644 index 0000000..74e9293 --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/MarketSellParser.cs @@ -0,0 +1,45 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS; + +internal class MarketSellParser : ITransactionParserPart { + public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + long profit = 0; + + if (context.StationOwner == null) { + transactions.AddIncomplete( + new SellCargo(), + "Could not discern the station owner market sell.", + e); + return; + } + + // Ignore if its a fleet carrier faction. + if (string.Compare(context.StationOwner, Factions.FleetCarrier, StringComparison.OrdinalIgnoreCase) == 0 && + options.IgnoreFleetCarrierFaction) { + return; + } + + MarketSellEntry? entry = e as MarketSellEntry; + if (entry == null) { + throw new NotImplementedException(); + } + + if (entry.Type == null) { + throw new InvalidJournalEntryException("market sell contains no cargo type"); + } + + if (context.BuyCost.ContainsKey(entry.Type)) { + long avg = context.BuyCost[entry.Type]; + profit = (long)entry.TotalSale - (avg * entry.Count); + } + + transactions.Add(new SellCargo(entry) { + System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, + Profit = profit, + IsLegacy = context.IsLegacy, + }); + } +} diff --git a/EDPlayerJournal/BGS/Parsers/MultiSellExplorationDataParser.cs b/EDPlayerJournal/BGS/Parsers/MultiSellExplorationDataParser.cs new file mode 100644 index 0000000..1106183 --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/MultiSellExplorationDataParser.cs @@ -0,0 +1,33 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS; + +internal class MultiSellExplorationDataParser : ITransactionParserPart { + public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + MultiSellExplorationDataEntry? entry = e as MultiSellExplorationDataEntry; + if (entry == null) { + throw new NotImplementedException(); + } + + if (context.StationOwner == null) { + transactions.AddIncomplete( + new Cartographics(), + "Could not discern the station owner for cartographics sell.", + e); + return; + } + + // Ignore if its a fleet carrier faction. + if (string.Compare(context.StationOwner, Factions.FleetCarrier, StringComparison.OrdinalIgnoreCase) == 0 && + options.IgnoreFleetCarrierFaction) { + return; + } + + transactions.Add(new Cartographics(entry) { + System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, + IsLegacy = context.IsLegacy, + }); + } +} diff --git a/EDPlayerJournal/BGS/Parsers/SellExplorationDataParser.cs b/EDPlayerJournal/BGS/Parsers/SellExplorationDataParser.cs new file mode 100644 index 0000000..b1ab5be --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/SellExplorationDataParser.cs @@ -0,0 +1,33 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS; + +internal class SellExplorationDataParser : ITransactionParserPart { + public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + SellExplorationDataEntry? entry = e as SellExplorationDataEntry; + if (entry == null) { + throw new NotImplementedException(); + } + + if (context.StationOwner == null) { + transactions.AddIncomplete( + new Cartographics(), + "Could not discern the station owner for cartographics sell.", + e); + return; + } + + // Ignore if its a fleet carrier faction. + if (string.Compare(context.StationOwner, Factions.FleetCarrier, StringComparison.OrdinalIgnoreCase) == 0 && + options.IgnoreFleetCarrierFaction) { + return; + } + + transactions.Add(new Cartographics(entry) { + System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, + IsLegacy = context.IsLegacy, + }); + } +} diff --git a/EDPlayerJournal/BGS/Parsers/SellOrganicDataParser.cs b/EDPlayerJournal/BGS/Parsers/SellOrganicDataParser.cs new file mode 100644 index 0000000..c7b97ad --- /dev/null +++ b/EDPlayerJournal/BGS/Parsers/SellOrganicDataParser.cs @@ -0,0 +1,38 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournal.BGS; + +internal class SellOrganicDataParser : ITransactionParserPart { + public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { + // If exo biology is ignored, simply do nothing + if (options.IgnoreExoBiology) { + return; + } + + SellOrganicDataEntry? entry = e as SellOrganicDataEntry; + if (entry == null) { + throw new NotImplementedException(); + } + + if (context.StationOwner == null) { + transactions.AddIncomplete( + new OrganicData(), + "Could not discern the station owner for organic data sell.", + e); + return; + } + + // Ignore if its a fleet carrier faction. + if (string.Compare(context.StationOwner, Factions.FleetCarrier, StringComparison.OrdinalIgnoreCase) == 0 && + options.IgnoreFleetCarrierFaction) { + return; + } + + transactions.Add(new OrganicData(entry) { + System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, + IsLegacy = context.IsLegacy, + }); + } +} diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index 0d9672a..9992e5f 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -23,6 +23,11 @@ public class TransactionParserOptions { /// disabled. /// public bool IgnoreMarketBuy { get; set; } = false; + + /// + /// Whether we should ignore things done for the fleet carrier faction. + /// + public bool IgnoreFleetCarrierFaction { get; set; } = true; } public class TransactionList : List { @@ -452,83 +457,6 @@ internal class MissionFailedParser : ITransactionParserPart { } } -internal class SellExplorationDataParser : ITransactionParserPart { - public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - SellExplorationDataEntry? entry = e as SellExplorationDataEntry; - if (entry == null) { - throw new NotImplementedException(); - } - - if (context.StationOwner == null) { - transactions.AddIncomplete( - new Cartographics(), - "Could not discern the station owner for cartographics sell.", - e); - return; - } - - transactions.Add(new Cartographics(entry) { - System = context.CurrentSystem, - Station = context.CurrentStation, - Faction = context.StationOwner, - IsLegacy = context.IsLegacy, - }); - } -} - -internal class SellOrganicDataParser : ITransactionParserPart { - public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - // If exo biology is ignored, simply do nothing - if (options.IgnoreExoBiology) { - return; - } - - SellOrganicDataEntry? entry = e as SellOrganicDataEntry; - if (entry == null) { - throw new NotImplementedException(); - } - - if (context.StationOwner == null) { - transactions.AddIncomplete( - new OrganicData(), - "Could not discern the station owner for organic data sell.", - e); - return; - } - - transactions.Add(new OrganicData(entry) { - System = context.CurrentSystem, - Station = context.CurrentStation, - Faction = context.StationOwner, - IsLegacy = context.IsLegacy, - }); - } -} - -internal class MultiSellExplorationDataParser : ITransactionParserPart { - public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - MultiSellExplorationDataEntry? entry = e as MultiSellExplorationDataEntry; - if (entry == null) { - throw new NotImplementedException(); - } - - if (context.StationOwner == null) { - transactions.AddIncomplete( - new Cartographics(), - "Could not discern the station owner for cartographics sell.", - e); - return; - } - - transactions.Add(new Cartographics(entry) { - System = context.CurrentSystem, - Station = context.CurrentStation, - Faction = context.StationOwner, - IsLegacy = context.IsLegacy, - }); - } -} - internal class RedeemVoucherParser : ITransactionParserPart { public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { RedeemVoucherEntry? entry = e as RedeemVoucherEntry; @@ -634,77 +562,6 @@ internal class SearchAndRescueParser : ITransactionParserPart { } } -internal class MarketBuyParser : ITransactionParserPart { - public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - MarketBuyEntry? entry = e as MarketBuyEntry; - if (entry == null) { - throw new NotImplementedException(); - } - - context.BoughtCargo(entry.Type, entry.BuyPrice); - - // We still want the information on buy price for profit, - // but if the option is on, we don't care for parsing it - // further. - // TODO: might be wise to split this parser into two; one for - // determining profit, the other for the BGS information - if (options.IgnoreMarketBuy) { - return; - } - - if (context.StationOwner == null) { - transactions.AddIncomplete( - new OrganicData(), - "Could not discern the station owner for market buy.", - e); - return; - } - - transactions.Add(new BuyCargo(entry) { - System = context.CurrentSystem, - Station = context.CurrentStation, - Faction = context.StationOwner, - IsLegacy = context.IsLegacy, - }); - } -} - -internal class MarketSellParser : ITransactionParserPart { - public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - long profit = 0; - - if (context.StationOwner == null) { - transactions.AddIncomplete( - new OrganicData(), - "Could not discern the station owner market sell.", - e); - return; - } - - MarketSellEntry? entry = e as MarketSellEntry; - if (entry == null) { - throw new NotImplementedException(); - } - - if (entry.Type == null) { - throw new InvalidJournalEntryException("market sell contains no cargo type"); - } - - if (context.BuyCost.ContainsKey(entry.Type)) { - long avg = context.BuyCost[entry.Type]; - profit = (long)entry.TotalSale - (avg * entry.Count); - } - - transactions.Add(new SellCargo(entry) { - System = context.CurrentSystem, - Station = context.CurrentStation, - Faction = context.StationOwner, - Profit = profit, - IsLegacy = context.IsLegacy, - }); - } -} - internal class FactionKillBondParser : ITransactionParserPart { public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { FactionKillBondEntry? entry = e as FactionKillBondEntry;