diff --git a/EDPlayerJournal/BGS/FactionKillBonds.cs b/EDPlayerJournal/BGS/FactionKillBonds.cs index cdeb0c0..505a951 100644 --- a/EDPlayerJournal/BGS/FactionKillBonds.cs +++ b/EDPlayerJournal/BGS/FactionKillBonds.cs @@ -2,11 +2,11 @@ namespace EDPlayerJournal.BGS; public class FactionKillBonds : Transaction { - public int TotalSum { + public ulong TotalSum { get { - return Entries + return (ulong)Entries .OfType() - .Sum(x => x.Reward) + .Sum(x => (decimal)x.Reward) ; } } diff --git a/EDPlayerJournal/BGS/ThargoidKill.cs b/EDPlayerJournal/BGS/ThargoidKill.cs new file mode 100644 index 0000000..b2986ea --- /dev/null +++ b/EDPlayerJournal/BGS/ThargoidKill.cs @@ -0,0 +1,44 @@ +using EDPlayerJournal.Entries; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EDPlayerJournal.BGS; + +public class ThargoidKill : Transaction { + /// + /// Thargoid vessel that was killed + /// + public ThargoidVessel ThargoidType { get; set; } = ThargoidVessel.Unknown; + + /// + /// Name of the thargoid type killed + /// + public string? ThargoidName { get; set; } + + /// + /// Total reward received + /// + public ulong TotalReward { + get { return (ulong)Entries.OfType().Sum(x => (decimal)x.Reward); } + } + + public ThargoidKill() { } + + public ThargoidKill(FactionKillBondEntry entry) { + if (string.Compare(entry.VictimFaction, Thargoid.ThargoidFaction) != 0) { + throw new Exception("Not a valid thargoid kill"); + } + + Entries.Add(entry); + + ThargoidType = Thargoid.GetVesselByPayout(entry.Reward); + ThargoidName = Thargoid.GetVesselName(ThargoidType); + } + + public override string ToString() { + return string.Format("{0}x {1} killed", Entries.Count, ThargoidName); + } +} diff --git a/EDPlayerJournal/BGS/TransactionParser.cs b/EDPlayerJournal/BGS/TransactionParser.cs index 968452c..2527701 100644 --- a/EDPlayerJournal/BGS/TransactionParser.cs +++ b/EDPlayerJournal/BGS/TransactionParser.cs @@ -580,11 +580,26 @@ internal class MarketSellParser : TransactionParserPart { } } +internal class FactionKillBondParser : TransactionParserPart { + public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) { + FactionKillBondEntry? entry = e as FactionKillBondEntry; + if (entry == null) { + throw new NotImplementedException(); + } + + if (string.Compare(entry.VictimFaction, Thargoid.ThargoidFaction) == 0) { + // Thargoid bonk + transactions.Add(new ThargoidKill(entry)); + } + } +} + public class TransactionParser { private static Dictionary ParserParts { get; } = new() { { Events.CommitCrime, new CommitCrimeParser() }, { Events.Docked, new DockedParser() }, + { Events.FactionKillBond, new FactionKillBondParser() }, { Events.FSDJump, new FSDJumpParser() }, { Events.Location, new LocationParser() }, { Events.MarketBuy, new MarketBuyParser() }, diff --git a/EDPlayerJournal/Credits.cs b/EDPlayerJournal/Credits.cs index f176640..e9bfd11 100644 --- a/EDPlayerJournal/Credits.cs +++ b/EDPlayerJournal/Credits.cs @@ -3,7 +3,11 @@ namespace EDPlayerJournal; public class Credits { - public static string FormatCredits(int amount) { + public static string FormatCredits(uint amount) { + return FormatCredits((long)amount); + } + + public static string FormatCredits(ulong amount) { return FormatCredits((long)amount); } diff --git a/EDPlayerJournal/Entries/FactionKillBondEntry.cs b/EDPlayerJournal/Entries/FactionKillBondEntry.cs index 6e43941..58ca35b 100644 --- a/EDPlayerJournal/Entries/FactionKillBondEntry.cs +++ b/EDPlayerJournal/Entries/FactionKillBondEntry.cs @@ -4,7 +4,7 @@ public class FactionKillBondEntry : Entry { /// /// Reward given /// - public int Reward { get; set; } + public ulong Reward { get; set; } = 0; /// /// Faction that awarded the kill bond /// @@ -23,7 +23,7 @@ public class FactionKillBondEntry : Entry { public string? VictimFactionLocalised { get; set; } protected override void Initialise() { - Reward = JSON.Value("Reward") ?? 0; + Reward = JSON.Value("Reward") ?? 0; AwardingFaction = JSON.Value("AwardingFaction"); AwardingFactionLocalised = JSON.Value("AwardingFaction_Localised"); VictimFaction = JSON.Value("VictimFaction"); diff --git a/EDPlayerJournalTests/EDPlayerJournalTests.csproj b/EDPlayerJournalTests/EDPlayerJournalTests.csproj index 2f36a27..cd5a563 100644 --- a/EDPlayerJournalTests/EDPlayerJournalTests.csproj +++ b/EDPlayerJournalTests/EDPlayerJournalTests.csproj @@ -44,6 +44,9 @@ Always + + Always + diff --git a/EDPlayerJournalTests/Helper.cs b/EDPlayerJournalTests/Helper.cs new file mode 100644 index 0000000..61ec421 --- /dev/null +++ b/EDPlayerJournalTests/Helper.cs @@ -0,0 +1,25 @@ +using EDPlayerJournal.Entries; + +namespace EDPlayerJournalTests; + +public class Helper { + public static List? LoadTestData(string filename) { + string path = Path.GetFullPath("./" + filename); + string[] lines = File.ReadAllLines(path); + List entries = new(); + + foreach (string line in lines) { + line.Trim(); + if (string.IsNullOrEmpty(line)) { + continue; + } + + Entry? entry = Entry.Parse(line); + if (entry != null) { + entries.Add(entry); + } + } + + return entries; + } +} diff --git a/EDPlayerJournalTests/TestTransactionParser.cs b/EDPlayerJournalTests/TestTransactionParser.cs index 4a25135..1cbd8dd 100644 --- a/EDPlayerJournalTests/TestTransactionParser.cs +++ b/EDPlayerJournalTests/TestTransactionParser.cs @@ -6,31 +6,11 @@ namespace EDPlayerJournalTests; [TestClass] public class TestTransactionParser { - private List? LoadTestData(string filename) { - string path = Path.GetFullPath("./" + filename); - string[] lines = File.ReadAllLines(path); - List entries = new(); - - foreach (string line in lines) { - line.Trim(); - if (string.IsNullOrEmpty(line)) { - continue; - } - - Entry? entry = Entry.Parse(line); - if (entry != null) { - entries.Add(entry); - } - } - - return entries; - } - [TestMethod] public void DoubleFiveINF() { TransactionParser parser = new(); - List? entries = LoadTestData("double-five-inf.txt"); + List? entries = Helper.LoadTestData("double-five-inf.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { @@ -46,7 +26,7 @@ public class TestTransactionParser { public void DoubleSupport() { TransactionParser parser = new(); - List? entries = LoadTestData("double-support.txt"); + List? entries = Helper.LoadTestData("double-support.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { @@ -62,7 +42,7 @@ public class TestTransactionParser { public void MissionFailed() { TransactionParser parser = new(); - List? entries = LoadTestData("mission-failed.txt"); + List? entries = Helper.LoadTestData("mission-failed.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { @@ -78,7 +58,7 @@ public class TestTransactionParser { public void MissionNoINF() { TransactionParser parser = new(); - List? entries = LoadTestData("mission-noinfforsourceortarget.txt"); + List? entries = Helper.LoadTestData("mission-noinfforsourceortarget.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { @@ -94,7 +74,7 @@ public class TestTransactionParser { public void Murder() { TransactionParser parser = new(); - List? entries = LoadTestData("murder.txt"); + List? entries = Helper.LoadTestData("murder.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { @@ -118,7 +98,7 @@ public class TestTransactionParser { public void NoFactionNameNoInfluence() { TransactionParser parser = new(); - List? entries = LoadTestData("nofactionname-andnoinfluence.txt"); + List? entries = Helper.LoadTestData("nofactionname-andnoinfluence.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { @@ -134,7 +114,7 @@ public class TestTransactionParser { public void SellOrganicData() { TransactionParser parser = new(); - List? entries = LoadTestData("SellOrganicData.txt"); + List? entries = Helper.LoadTestData("SellOrganicData.txt"); Assert.IsNotNull(entries, "could not load test data"); if (entries == null) { diff --git a/EDPlayerJournalTests/ThargoidKills.cs b/EDPlayerJournalTests/ThargoidKills.cs new file mode 100644 index 0000000..0e78145 --- /dev/null +++ b/EDPlayerJournalTests/ThargoidKills.cs @@ -0,0 +1,33 @@ +using EDPlayerJournal.BGS; +using EDPlayerJournal.Entries; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EDPlayerJournalTests; + +[TestClass] +public class ThargoidKills { + [TestMethod] + public void ThargoidBonks() { + TransactionParser parser = new(); + + List? entries = Helper.LoadTestData("ThargoidKills.txt"); + Assert.IsNotNull(entries, "could not load test data"); + + if (entries == null) { + return; + } + + List? transactions = parser.Parse(entries); + + Assert.IsNotNull(transactions, "could not parse entries"); + Assert.AreEqual(transactions.Count, 4); + + Assert.IsInstanceOfType(transactions[0], typeof(ThargoidKill), "result is not of type ThargoidKill"); + Assert.IsInstanceOfType(transactions[1], typeof(ThargoidKill), "result is not of type ThargoidKill"); + Assert.IsInstanceOfType(transactions[2], typeof(ThargoidKill), "result is not of type ThargoidKill"); + } +}