add preliminary support for merits gained

This commit is contained in:
Florian Stinglmayr 2024-11-14 13:30:31 +01:00
parent cdbca10f2d
commit aeaa6b5220
4 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,25 @@
using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS;
public class MeritsGained : Transaction {
public MeritsGained() { }
public MeritsGained(Entry entry) {
Entries.Add(entry);
}
/// <summary>
/// Number of merits gained
/// </summary>
public long Merits { get; set; } = 0;
/// <summary>
/// For what power those merits were gained
/// </summary>
public string Power { get; set; } = string.Empty;
public override string ToString() {
return string.Format("{0} Merits gained for {1}", Merits, Power);
}
}

View File

@ -0,0 +1,29 @@
using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS.Parsers;
internal class PowerplayParser : ITransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
PowerplayEntry? p = entry as PowerplayEntry;
if (p == null) {
return;
}
if (context.LastMerits == null) {
context.LastMerits = p.Merits;
}
context.CurrentMerits = p.Merits;
if (context.LastMerits != context.CurrentMerits) {
transactions.Add(new MeritsGained(entry) {
Merits = ((long)(context.CurrentMerits - context.LastMerits)),
Power = p.Power,
System = context.CurrentSystem,
Faction = p.Power,
});
}
context.LastMerits = context.CurrentMerits;
}
}

View File

@ -638,6 +638,7 @@ public class TransactionParser {
{ Events.Missions, new MissionsParser() },
{ Events.MultiSellExplorationData, new MultiSellExplorationDataParser() },
{ Events.Music, new MusicParser() },
{ Events.Powerplay, new PowerplayParser() },
{ Events.ReceiveText, new ReceiveTextParser() },
{ Events.RedeemVoucher, new RedeemVoucherParser() },
{ Events.SearchAndRescue, new SearchAndRescueParser() },

View File

@ -69,6 +69,16 @@ internal class TransactionParserContext {
/// </summary>
public string? Settlement { get; set; } = null;
/// <summary>
/// Current Merits
/// </summary>
public long? CurrentMerits { get; set; } = null;
/// <summary>
/// Merits from last login
/// </summary>
public long? LastMerits { get; set; } = null;
/// <summary>
/// Returns true if the current session is legacy
/// </summary>