diff --git a/EDPlayerJournal/BGS/InfluenceSupport.cs b/EDPlayerJournal/BGS/InfluenceSupport.cs index 3e9e249..0eab0dd 100644 --- a/EDPlayerJournal/BGS/InfluenceSupport.cs +++ b/EDPlayerJournal/BGS/InfluenceSupport.cs @@ -9,7 +9,7 @@ namespace EDPlayerJournal.BGS; /// faction to another. Both sometimes gain influence. /// public class InfluenceSupport : Transaction { - public string Influence { get; set; } = ""; + public MissionInfluence? Influence { get; set; } = null; /// /// Relevant mission completed entry @@ -46,7 +46,7 @@ public class InfluenceSupport : Transaction { builder.AppendFormat("Influence gained from \"{0}\": \"{1}\"", missionname, - string.IsNullOrEmpty(Influence) ? "NONE" : Influence + Influence == null ? "NONE" : Influence.TrendAdjustedInfluence ); return builder.ToString(); diff --git a/EDPlayerJournal/BGS/MissionCompleted.cs b/EDPlayerJournal/BGS/MissionCompleted.cs index e5b87ae..67c7dc8 100644 --- a/EDPlayerJournal/BGS/MissionCompleted.cs +++ b/EDPlayerJournal/BGS/MissionCompleted.cs @@ -38,7 +38,14 @@ public class MissionCompleted : Transaction { return ""; } - return (CompletedEntry.Mission.GetInfluenceForFaction(Faction, SystemAddress) ?? ""); + return string.Join("", + CompletedEntry + .Mission + .GetInfluenceForFaction(Faction, SystemAddress) + .Select(x => x.Influence) + .ToArray() + ) + ; } } @@ -70,8 +77,10 @@ public class MissionCompleted : Transaction { var influence = CompletedEntry.Mission.GetInfluenceForFaction(Faction, SystemAddress); builder.AppendFormat("{0}", MissionName); - if (influence != "") { - builder.AppendFormat(", Influence: {0}", influence); + if (influence != null && influence.Length > 0) { + builder.AppendFormat(", Influence: {0}", + influence.Select(x => x.InfluenceAmount).Sum() + ); } return builder.ToString(); diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index 8199a42..73cea6a 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -298,20 +298,20 @@ internal class MissionCompletedParser : ITransactionParserPart { if (context.CurrentSystemAddress == null) { continue; } - other.Value.Add(context.CurrentSystemAddress.Value, ""); + other.Value.Add(context.CurrentSystemAddress.Value, new MissionInfluence()); // Mission gave no influence to the target faction, so we assume // the target faction was in the same system. } else if (string.Compare(source_faction_name, faction, true) == 0) { // This happens if the source faction is not getting any influence // This could be if the source faction is in a conflict, and thus does // not gain any influence at all. - other.Value.Add(accepted_location.SystemAddress, ""); + other.Value.Add(accepted_location.SystemAddress, new MissionInfluence()); // Just check if the target/source faction are the same, in which case // we also have to make an additional entry if (string.Compare(source_faction_name, target_faction_name, true) == 0 && context.CurrentSystemAddress != null) { - other.Value.Add(context.CurrentSystemAddress.Value, ""); + other.Value.Add(context.CurrentSystemAddress.Value, new MissionInfluence()); } } } diff --git a/EDPlayerJournal/Mission.cs b/EDPlayerJournal/Mission.cs index 0f1f1d7..0373645 100644 --- a/EDPlayerJournal/Mission.cs +++ b/EDPlayerJournal/Mission.cs @@ -36,6 +36,31 @@ public class MissionInfluence { /// public string Influence { get; set; } = string.Empty; + public long InfluenceAmount { + get { + string trend = TrendAdjustedInfluence; + return (long) + (trend.Count(x => x == '-') * -1) + + trend.Count(x => x == '+') + ; + } + } + + /// + /// Returns how much influence was made, represented in pluses for positive influence, + /// and minuses with negative influence. This takes Trend (up, bad etc.) into account. + /// + public string TrendAdjustedInfluence { + get { + if (!string.IsNullOrEmpty(Trend) && + Trend.Contains("bad", StringComparison.OrdinalIgnoreCase)) { + return new string('-', Influence.Length); + } else { + return new string('+', Influence.Length); + } + } + } + public static MissionInfluence FromJSON(JObject obj) { MissionInfluence missionInfluence = new MissionInfluence(); @@ -394,27 +419,29 @@ public class Mission : IComparable { /// Faction name in question. /// Star System address /// null if no entry was found, or a string denoting pluses for the amount influence gained. - public string? GetInfluenceForFaction(string faction, ulong systemaddr) { + public MissionInfluence[]? GetInfluenceForFaction(string faction, ulong systemaddr) { var results = FactionEffects .Where(x => string.Compare(x.Faction, faction) == 0) .SelectMany(x => x.Influences) .Where(x => (x.SystemAddress != null && x.SystemAddress == systemaddr)) - .Select(x => x.Influence) + .Select(x => x) .ToArray() ; if (results == null || results.Length == 0) { - return null; + return new MissionInfluence[0]; } - return string.Join("", results); + return results; } /// /// A convenient Dictionary containing all influences given out by faction, - /// then by system address and then by influence handed out. + /// then by system address and then by influence handed out. Influence can + /// be either a series of "+" for positive influence, or "-" for negative + /// influence. /// - public Dictionary> Influences { + public Dictionary> Influences { get { return FactionEffects .Where(x => x.Faction != null) @@ -422,7 +449,10 @@ public class Mission : IComparable { x => (x.Faction ?? string.Empty), x => x.Influences .Where(x => x.SystemAddress != null) - .ToDictionary(x => (x.SystemAddress ?? 0), x => x.Influence) + .ToDictionary( + x => (x.SystemAddress ?? 0), + x => x + ) ); } } diff --git a/EDPlayerJournalTests/MissionTest.cs b/EDPlayerJournalTests/MissionTest.cs index fe346c8..be6e293 100644 --- a/EDPlayerJournalTests/MissionTest.cs +++ b/EDPlayerJournalTests/MissionTest.cs @@ -59,9 +59,9 @@ public class MissionTest { Assert.IsTrue(e.IsEmptyFaction); Assert.AreEqual(e.Faction, string.Empty); - string? influence = m.GetInfluenceForFaction("", 251012319587UL); + var influence = m.GetInfluenceForFaction("", 251012319587UL); Assert.IsNotNull(influence); - Assert.AreEqual(influence, "+"); + Assert.AreEqual(influence[0].Influence, "+"); e = m.FactionEffects[1]; Assert.AreEqual(e.Faction, "Social LHS 6103 Confederation"); @@ -101,22 +101,25 @@ public class MissionTest { Assert.AreEqual(effect.Reputation, "++"); - string? influence; - - influence = m.GetInfluenceForFaction("Salus Imperial Society", 1865919973739UL); - Assert.AreEqual(influence, "++"); + var influence = m.GetInfluenceForFaction("Salus Imperial Society", 1865919973739UL); + Assert.IsNotNull(influence); + Assert.IsTrue(influence.Length > 0); + Assert.AreEqual(influence[0].Influence, "++"); influence = m.GetInfluenceForFaction("Salus Imperial Society", 1733186884306UL); - Assert.AreEqual(influence, "++"); + Assert.IsNotNull(influence); + Assert.IsTrue(influence.Length > 0); + Assert.AreEqual(influence[0].Influence, "++"); influence = m.GetInfluenceForFaction("Saelishi Saxons", 1733186884306UL); - Assert.IsNull(influence); + Assert.IsNotNull(influence); + Assert.AreEqual(influence.Length, 0); // Only one entry are we only have Salus Assert.AreEqual(m.Influences.Count, 1); Assert.AreEqual(m.Influences["Salus Imperial Society"].Count, 2); - Assert.AreEqual(m.Influences["Salus Imperial Society"][1865919973739UL], "++"); - Assert.AreEqual(m.Influences["Salus Imperial Society"][1733186884306UL], "++"); + Assert.AreEqual(m.Influences["Salus Imperial Society"][1865919973739UL].Influence, "++"); + Assert.AreEqual(m.Influences["Salus Imperial Society"][1733186884306UL].Influence, "++"); } [TestMethod] diff --git a/EDPlayerJournalTests/TestTransactionParser.cs b/EDPlayerJournalTests/TestTransactionParser.cs index a2e5cbe..d72629f 100644 --- a/EDPlayerJournalTests/TestTransactionParser.cs +++ b/EDPlayerJournalTests/TestTransactionParser.cs @@ -19,7 +19,13 @@ public class TestTransactionParser { return; } - List? transactions = parser.Parse(entries); + var options = new TransactionParserOptions() { + IgnoreInfluenceSupport = false, + IgnoreExoBiology = false, + IgnoreFleetCarrierFaction = false, + IgnoreMarketBuy = false, + }; + List? transactions = parser.Parse(entries, options); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 3); @@ -144,7 +150,14 @@ public class TestTransactionParser { return; } - List? transactions = parser.Parse(entries); + var options = new TransactionParserOptions() { + IgnoreInfluenceSupport = false, + IgnoreExoBiology = false, + IgnoreFleetCarrierFaction = false, + IgnoreMarketBuy = false, + }; + + List? transactions = parser.Parse(entries, options); Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 1); Assert.IsInstanceOfType(transactions[0], typeof(OrganicData), "result is not of type Organic Data"); diff --git a/EDPlayerJournalTests/ThargoidKills.cs b/EDPlayerJournalTests/ThargoidKills.cs index aa06803..d95b38b 100644 --- a/EDPlayerJournalTests/ThargoidKills.cs +++ b/EDPlayerJournalTests/ThargoidKills.cs @@ -22,14 +22,17 @@ public class ThargoidKills { Assert.IsNotNull(transactions, "could not parse entries"); Assert.AreEqual(transactions.Count, 3); + // In recent updates the payout was changed, that's why this test reports unknown thargoid vessels + // This test makes sure the new parser does not conflict with legacy values + // Assert.IsInstanceOfType(transactions[0], typeof(ThargoidKill), "result is not of type ThargoidKill"); - Assert.AreEqual(transactions[0].ThargoidType, EDPlayerJournal.ThargoidVessel.Scout); + Assert.AreEqual(transactions[0].ThargoidType, EDPlayerJournal.ThargoidVessel.Unknown); Assert.IsInstanceOfType(transactions[1], typeof(ThargoidKill), "result is not of type ThargoidKill"); - Assert.AreEqual(transactions[1].ThargoidType, EDPlayerJournal.ThargoidVessel.Basilisk); + Assert.AreEqual(transactions[1].ThargoidType, EDPlayerJournal.ThargoidVessel.Unknown); Assert.IsInstanceOfType(transactions[2], typeof(ThargoidKill), "result is not of type ThargoidKill"); - Assert.AreEqual(transactions[2].ThargoidType, EDPlayerJournal.ThargoidVessel.Scout); + Assert.AreEqual(transactions[2].ThargoidType, EDPlayerJournal.ThargoidVessel.Unknown); } [TestMethod] diff --git a/EliteBGS/LogGenerator/MissionFormat.cs b/EliteBGS/LogGenerator/MissionFormat.cs index bdf899c..3c06c03 100644 --- a/EliteBGS/LogGenerator/MissionFormat.cs +++ b/EliteBGS/LogGenerator/MissionFormat.cs @@ -10,7 +10,7 @@ public class MissionFormat : LogFormatter { Dictionary> collated = new(); Dictionary passengers = new(); StringBuilder output = new StringBuilder(); - int total_influence = 0; + long total_influence = 0; var missions = objective.EnabledOfType(); var support = objective.EnabledOfType(); @@ -63,14 +63,14 @@ public class MissionFormat : LogFormatter { foreach (InfluenceSupport inf in support) { output.Append(inf.ToString()); output.Append("\n"); - total_influence += inf.Influence.Length; + total_influence += inf.Influence.InfluenceAmount; } if (support.Count() > 0) { output.Append("\n"); } - if (total_influence > 0) { + if (total_influence != 0) { output.AppendFormat("Total Influence: {0}", total_influence); } @@ -84,10 +84,10 @@ public class MissionFormat : LogFormatter { ; long support = objective .EnabledOfType() - .Sum(x => x.Influence.Length) + .Sum(x => x.Influence.InfluenceAmount) ; - if (influence + support <= 0) { + if (influence == 0 && support == 0) { return ""; }