add merits to the log

This commit is contained in:
Florian Stinglmayr 2025-04-16 15:09:56 +02:00
parent 693d49be14
commit 4cefc393b5
6 changed files with 50 additions and 38 deletions

View File

@ -12,7 +12,14 @@ public class MeritsGained : Transaction {
/// <summary> /// <summary>
/// Number of merits gained /// Number of merits gained
/// </summary> /// </summary>
public long Merits { get; set; } = 0; public long Merits {
get {
return Entries
.OfType<PowerplayMeritsEntry>()
.Sum(x => x.MeritsGained)
;
}
}
/// <summary> /// <summary>
/// For what power those merits were gained /// For what power those merits were gained

View File

@ -0,0 +1,31 @@
using EDPlayerJournal.Entries;
namespace EDPlayerJournal.BGS.Parsers;
internal class PowerplayMeritsParser : ITransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionParserOptions options, TransactionList transactions) {
PowerplayMeritsEntry? e = entry as PowerplayMeritsEntry;
if (e == null) {
throw new ApplicationException("not a valid PowerplayMerits entry");
}
MeritsGained? transaction = null;
transaction = transactions
.OfType<MeritsGained>()
.Where(x => x.System == context.CurrentSystem &&
x.Power == e.Power)
.FirstOrDefault()
;
if (transaction == null) {
transaction = new MeritsGained(e) {
System = context.CurrentSystem,
Power = e.Power,
Faction = e.Power,
};
transactions.Add(transaction);
} else {
transaction.Entries.Add(e);
}
}
}

View File

@ -1,31 +0,0 @@
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) {
if (!options.IgnorePowerplay) {
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

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

View File

@ -2,6 +2,14 @@
public class PowerplayMeritsEntry : Entry { public class PowerplayMeritsEntry : Entry {
protected override void Initialise() { protected override void Initialise() {
// TODO Power = JSON.Value<string?>("Power") ?? string.Empty;
MeritsGained = JSON.Value<long?>("MeritsGained") ?? 0;
TotalMerits = JSON.Value<long?>("TotalMerits") ?? 0;
} }
public string Power { get; set; } = string.Empty;
public long MeritsGained { get; set; } = 0;
public long TotalMerits { get; set; } = 0;
} }

View File

@ -1,8 +1,5 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using EDPlayerJournal;
using EDPlayerJournal.BGS; using EDPlayerJournal.BGS;
namespace EliteBGS.LogGenerator; namespace EliteBGS.LogGenerator;