From 5c9d9c91537f75bff9c65039ae1e959cce2c4de8 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Wed, 19 Apr 2023 09:01:32 +0200 Subject: [PATCH] correct black market trade by properly setting StationOwner --- EDPlayerJournal/BGS/Cartographics.cs | 5 +- EDPlayerJournal/BGS/OrganicData.cs | 4 + EDPlayerJournal/BGS/TransactionParser.cs | 94 ++++++++++++++++++++---- 3 files changed, 85 insertions(+), 18 deletions(-) diff --git a/EDPlayerJournal/BGS/Cartographics.cs b/EDPlayerJournal/BGS/Cartographics.cs index 70cce99..1698817 100644 --- a/EDPlayerJournal/BGS/Cartographics.cs +++ b/EDPlayerJournal/BGS/Cartographics.cs @@ -1,10 +1,11 @@ -using System.Linq; -using System.Text; +using System.Text; using EDPlayerJournal.Entries; namespace EDPlayerJournal.BGS; public class Cartographics : Transaction { + public Cartographics() { } + public Cartographics(MultiSellExplorationDataEntry e) { Entries.Add(e); } diff --git a/EDPlayerJournal/BGS/OrganicData.cs b/EDPlayerJournal/BGS/OrganicData.cs index 3f998a5..46291df 100644 --- a/EDPlayerJournal/BGS/OrganicData.cs +++ b/EDPlayerJournal/BGS/OrganicData.cs @@ -4,6 +4,8 @@ using EDPlayerJournal.Entries; namespace EDPlayerJournal.BGS; public class OrganicData : Transaction { + public OrganicData() { } + public OrganicData(SellOrganicDataEntry e) { Entries.Add(e); } @@ -36,6 +38,8 @@ public class OrganicData : Transaction { /* Selling organic data only helps the controlling faction, just like * selling cartographic data. + * + * Right now: Organic data helps no one. */ public override bool OnlyControllingFaction => true; } diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index a5466d8..2ea4c83 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -51,6 +51,12 @@ internal class LocationParser : TransactionParserPart { context.CurrentStation = entry.StationName; } + if (!string.IsNullOrEmpty(entry.StationFaction)) { + context.StationOwner = entry.StationFaction; + } else { + context.StationOwner = null; + } + if (!context.SystemFactions.ContainsKey(entry.StarSystem) && entry.SystemFactions != null && entry.SystemFactions.Count > 0) { context.SystemFactions[entry.StarSystem] = entry.SystemFactions; @@ -108,7 +114,7 @@ internal class DockedParser : TransactionParserPart { context.SystemsByID.TryAdd(entry.SystemAddress.Value, entry.StarSystem); if (!string.IsNullOrEmpty(entry.StationFaction)) { - context.ControllingFaction = entry.StationFaction; + context.StationOwner = entry.StationFaction; } if (!string.IsNullOrEmpty(entry.StationName)) { @@ -274,8 +280,8 @@ internal class MissionCompletedParser : TransactionParserPart { throw new NotImplementedException(); } - Mission? mission = null; - Location? accepted_location = null; + Mission? mission; + Location? accepted_location; string? target_faction_name = entry.Mission.TargetFaction; string? source_faction_name = entry.Mission.Faction; @@ -384,9 +390,9 @@ internal class MissionCompletedParser : TransactionParserPart { internal class MissionFailedParser : TransactionParserPart { public void Parse(Entry e, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) { - Mission? mission = null; - Location? accepted_location = null; - string? accepted_system = null; + Mission? mission; + Location? accepted_location; + string? accepted_system; MissionFailedEntry? entry = e as MissionFailedEntry; if (entry == null) { @@ -444,10 +450,18 @@ internal class SellExplorationDataParser : TransactionParserPart { 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.ControllingFaction, + Faction = context.StationOwner, IsLegacy = context.IsLegacy, }); } @@ -465,10 +479,18 @@ internal class SellOrganicDataParser : TransactionParserPart { 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.ControllingFaction, + Faction = context.StationOwner, IsLegacy = context.IsLegacy, }); } @@ -481,10 +503,18 @@ internal class MultiSellExplorationDataParser : TransactionParserPart { 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.ControllingFaction, + Faction = context.StationOwner, IsLegacy = context.IsLegacy, }); } @@ -554,10 +584,18 @@ internal class SellMicroResourcesParser : TransactionParserPart { throw new NotImplementedException(); } + if (context.StationOwner == null) { + transactions.AddIncomplete( + new SellMicroResources(), + "Could not discern the station owner for micro resources sell.", + e); + return; + } + transactions.Add(new SellMicroResources(entry) { System = context.CurrentSystem, Station = context.CurrentStation, - Faction = context.ControllingFaction, + Faction = context.StationOwner, IsLegacy = context.IsLegacy, }); } @@ -570,10 +608,18 @@ internal class SearchAndRescueParser : TransactionParserPart { throw new NotImplementedException(); } + if (context.StationOwner == null) { + transactions.AddIncomplete( + new OrganicData(), + "Could not discern the station owner for S&R operations.", + e); + return; + } + transactions.Add(new SearchAndRescue(entry) { - Faction = context.ControllingFaction, - Station = context.CurrentStation, System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, IsLegacy = context.IsLegacy, }); } @@ -586,12 +632,20 @@ internal class MarketBuyParser : TransactionParserPart { throw new NotImplementedException(); } + if (context.StationOwner == null) { + transactions.AddIncomplete( + new OrganicData(), + "Could not discern the station owner for market buy.", + e); + return; + } + context.BoughtCargo(entry.Type, entry.BuyPrice); transactions.Add(new BuyCargo(entry) { - Faction = context.ControllingFaction, - Station = context.CurrentStation, System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, IsLegacy = context.IsLegacy, }); } @@ -601,6 +655,14 @@ internal class MarketSellParser : TransactionParserPart { 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(); @@ -616,9 +678,9 @@ internal class MarketSellParser : TransactionParserPart { } transactions.Add(new SellCargo(entry) { - Faction = context.ControllingFaction, - Station = context.CurrentStation, System = context.CurrentSystem, + Station = context.CurrentStation, + Faction = context.StationOwner, Profit = profit, IsLegacy = context.IsLegacy, });