add support for thargoid vouchers

This commit is contained in:
2022-11-25 15:48:00 +01:00
parent e8de768d01
commit 8514331701
5 changed files with 101 additions and 12 deletions

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace EDPlayerJournal.Entries;
public class RedeemVoucherEntry : Entry {
protected override void Initialise() {
Amount = (JSON.Value<int?>("Amount") ?? 0);
Amount = (JSON.Value<ulong?>("Amount") ?? 0);
Type = JSON.Value<string>("Type");
/* according to API, there should be a Factions structure */
@@ -12,7 +12,7 @@ public class RedeemVoucherEntry : Entry {
if (factions != null) {
foreach (JObject faction in factions.Children<JObject>()) {
string? faction_name = faction.Value<string>("Faction");
long? faction_bounty = faction.Value<long?>("Amount");
ulong? faction_bounty = faction.Value<ulong?>("Amount");
if (faction_name == null || faction_name.Length <= 0 || faction_bounty == null) {
continue;
}
@@ -35,8 +35,29 @@ public class RedeemVoucherEntry : Entry {
}
}
public int Amount { get; set; } = 0;
public ulong GetBountyForFaction(string? a) {
if (a == null) {
return 0;
}
var relevant = FactionBounties.Where(x => EDPlayerJournal.Factions.CompareFactions(x.Key, a) == 0).ToList();
if (relevant == null || relevant.Count() == 0) {
return 0;
}
return (ulong)relevant.Sum(x => (decimal)x.Value);
}
public ulong Amount { get; set; } = 0;
public string? Type { get; set; } = "Bounty";
public List<string> Factions { get; set; } = new List<string>();
public Dictionary<string, long> FactionBounties { get; set; } = new Dictionary<string, long>();
/// <summary>
/// List of factions
/// </summary>
public List<string> Factions { get; set; } = new();
/// <summary>
/// Bounties awarded by faction
/// </summary>
public Dictionary<string, ulong> FactionBounties { get; set; } = new();
}