Compare commits

...

3 Commits

13 changed files with 230 additions and 97 deletions

View File

@ -2,11 +2,11 @@
namespace EDPlayerJournal.BGS;
public class FactionKillBonds : Transaction {
public int TotalSum {
public ulong TotalSum {
get {
return Entries
return (ulong)Entries
.OfType<FactionKillBondEntry>()
.Sum(x => x.Reward)
.Sum(x => (decimal)x.Reward)
;
}
}

View File

@ -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 {
/// <summary>
/// Thargoid vessel that was killed
/// </summary>
public ThargoidVessel ThargoidType { get; set; } = ThargoidVessel.Unknown;
/// <summary>
/// Name of the thargoid type killed
/// </summary>
public string? ThargoidName { get; set; }
/// <summary>
/// Total reward received
/// </summary>
public ulong TotalReward {
get { return (ulong)Entries.OfType<FactionKillBondEntry>().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);
}
}

View File

@ -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<string, TransactionParserPart> 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() },

View File

@ -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);
}

View File

@ -1,13 +1,32 @@
namespace EDPlayerJournal.Entries;
public class FactionKillBondEntry : Entry {
public int Reward { get; set; }
/// <summary>
/// Reward given
/// </summary>
public ulong Reward { get; set; } = 0;
/// <summary>
/// Faction that awarded the kill bond
/// </summary>
public string? AwardingFaction { get; set; }
/// <summary>
/// Localised string of the awarding faction if available
/// </summary>
public string? AwardingFactionLocalised { get; set; }
/// <summary>
/// Victim faction, internal name
/// </summary>
public string? VictimFaction { get; set; }
/// <summary>
/// Localised name of the victim faction
/// </summary>
public string? VictimFactionLocalised { get; set; }
protected override void Initialise() {
Reward = JSON.Value<int?>("Reward") ?? 0;
Reward = JSON.Value<ulong?>("Reward") ?? 0;
AwardingFaction = JSON.Value<string>("AwardingFaction");
AwardingFactionLocalised = JSON.Value<string>("AwardingFaction_Localised");
VictimFaction = JSON.Value<string>("VictimFaction");
VictimFactionLocalised = JSON.Value<string>("VictimFaction_Localised");
}
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace EDPlayerJournal;
public class FactionState {
public string? State { get; set; }
public long? Trend { get; set; }
@ -28,6 +29,18 @@ public class FactionState {
}
}
public class Factions {
/// <summary>
/// Internal name for the Pilots Federation faction
/// </summary>
public static string PilotsFederation = "$faction_PilotsFederation;";
/// <summary>
/// Internal name for the Thargoid faction
/// </summary>
public static string Thargoid = "$faction_Thargoid;";
}
public class Faction {
public string? Name { get; set; }
public string? FactionState { get; set; }

View File

@ -1,63 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
namespace EDPlayerJournal;
public class HumanReadableMissionName {
private static Dictionary<string, string>? humanreadable = null;
private static void LoadMissions() {
try {
string dir = AppDomain.CurrentDomain.BaseDirectory;
string file = Path.Combine(dir, "MissionNames.xml");
XmlDocument document = new XmlDocument();
using (FileStream stream = new FileStream(file, FileMode.Open)) {
document.Load(stream);
XmlNode? missions = document.DocumentElement;
if (missions == null ||
missions.Name != "Missions" ||
missions.ChildNodes == null) {
throw new ApplicationException("Invalid XML");
}
humanreadable = new Dictionary<string, string>();
foreach (XmlNode mission in missions.ChildNodes) {
if (mission.Attributes == null) {
continue;
}
string? mission_key = mission.Attributes["Name"]?.Value;
string? mission_name = mission.InnerText;
if (mission_key == null || mission_name == null) {
continue;
}
humanreadable.Add(mission_key, mission_name);
}
}
} catch (Exception) {
humanreadable = null;
}
}
public static string? MakeHumanReadableName(string name) {
LoadMissions();
if (humanreadable == null || name == null) {
return null;
}
if (humanreadable.ContainsKey(name)) {
return humanreadable[name];
}
return null;
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EDPlayerJournal;
public enum ThargoidVessel {
Unknown = 0,
Scout = 1,
/// <summary>
/// According to AX wiki no longer found ingame
/// </summary>
Orthrus = 2,
Cyclops = 3,
Basilisk = 4,
Medusa = 5,
Hydra = 6,
}
public class Thargoid {
public static string ThargoidFaction = Factions.Thargoid;
public static Dictionary<ulong, ThargoidVessel> VesselPayout { get; } = new() {
{ 80000, ThargoidVessel.Scout },
{ 8000000, ThargoidVessel.Cyclops },
{ 24000000, ThargoidVessel.Basilisk },
{ 40000000, ThargoidVessel.Medusa },
{ 60000000, ThargoidVessel.Hydra },
};
public static Dictionary<ThargoidVessel, string?> VesselNames { get; } = new() {
{ ThargoidVessel.Unknown, null },
{ ThargoidVessel.Scout, "Thargoid Scout" },
{ ThargoidVessel.Orthrus, "Orthrus" },
{ ThargoidVessel.Cyclops, "Cyclops" },
{ ThargoidVessel.Basilisk, "Basilisk" },
{ ThargoidVessel.Medusa, "Medusa" },
{ ThargoidVessel.Hydra, "Hydra" },
};
public static ThargoidVessel GetVesselByPayout(ulong payout) {
if (VesselPayout.ContainsKey(payout)) {
return VesselPayout[payout];
}
return ThargoidVessel.Unknown;
}
public static string? GetVesselName(ThargoidVessel v) {
if (VesselNames.ContainsKey(v)) {
return VesselNames[v];
}
return null;
}
}

View File

@ -44,6 +44,9 @@
<None Update="SellOrganicData.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ThargoidKills.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,25 @@
using EDPlayerJournal.Entries;
namespace EDPlayerJournalTests;
public class Helper {
public static List<Entry>? LoadTestData(string filename) {
string path = Path.GetFullPath("./" + filename);
string[] lines = File.ReadAllLines(path);
List<Entry> 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;
}
}

View File

@ -6,31 +6,11 @@ namespace EDPlayerJournalTests;
[TestClass]
public class TestTransactionParser {
private List<Entry>? LoadTestData(string filename) {
string path = Path.GetFullPath("./" + filename);
string[] lines = File.ReadAllLines(path);
List<Entry> 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<Entry>? entries = LoadTestData("double-five-inf.txt");
List<Entry>? 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<Entry>? entries = LoadTestData("double-support.txt");
List<Entry>? 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<Entry>? entries = LoadTestData("mission-failed.txt");
List<Entry>? 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<Entry>? entries = LoadTestData("mission-noinfforsourceortarget.txt");
List<Entry>? 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<Entry>? entries = LoadTestData("murder.txt");
List<Entry>? 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<Entry>? entries = LoadTestData("nofactionname-andnoinfluence.txt");
List<Entry>? 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<Entry>? entries = LoadTestData("SellOrganicData.txt");
List<Entry>? entries = Helper.LoadTestData("SellOrganicData.txt");
Assert.IsNotNull(entries, "could not load test data");
if (entries == null) {

View File

@ -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<Entry>? entries = Helper.LoadTestData("ThargoidKills.txt");
Assert.IsNotNull(entries, "could not load test data");
if (entries == null) {
return;
}
List<Transaction>? 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");
}
}

View File

@ -0,0 +1,4 @@
{ "timestamp":"2022-11-25T09:50:45Z", "event":"FactionKillBond", "Reward":80000, "AwardingFaction":"$faction_PilotsFederation;", "AwardingFaction_Localised":"Pilots' Federation", "VictimFaction":"$faction_Thargoid;", "VictimFaction_Localised":"Thargoids" }
{ "timestamp":"2022-11-25T09:52:28Z", "event":"FactionKillBond", "Reward":24000000, "AwardingFaction":"$faction_PilotsFederation;", "AwardingFaction_Localised":"Pilots' Federation", "VictimFaction":"$faction_Thargoid;", "VictimFaction_Localised":"Thargoids" }
{ "timestamp":"2022-11-25T09:47:19Z", "event":"FactionKillBond", "Reward":80000, "AwardingFaction":"$faction_PilotsFederation;", "AwardingFaction_Localised":"Pilots' Federation", "VictimFaction":"$faction_Thargoid;", "VictimFaction_Localised":"Thargoids" }
{ "timestamp":"2022-11-25T10:13:53Z", "event":"RedeemVoucher", "Type":"CombatBond", "Amount":24240000, "Faction":"PilotsFederation" }