edjournal/RedeemVoucherEntry.cs

44 lines
1.8 KiB
C#

using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace EDJournal {
public class RedeemVoucherEntry : Entry {
protected override void Initialise() {
Amount = JSON.Value<int>("Amount");
Type = JSON.Value<string>("Type");
/* according to API, there should be a Factions structure */
JToken factions = JSON.GetValue("Factions");
if (factions != null) {
foreach (JObject faction in factions.Children<JObject>()) {
string faction_name = faction.Value<string>("Faction");
long faction_bounty = faction.Value<long?>("Amount") ?? 0;
if (faction_name == null || faction_name.Length <= 0) {
continue;
}
Factions.Add(faction_name);
if (!FactionBounties.ContainsKey(faction_name)) {
FactionBounties[faction_name] = 0;
}
FactionBounties[faction_name] += faction_bounty;
}
}
/* but there also might be just a Faction entry */
string single_faction = JSON.Value<string>("Faction");
if (single_faction != null) {
Factions.Add(single_faction);
if (!FactionBounties.ContainsKey(single_faction)) {
FactionBounties[single_faction] = 0;
}
FactionBounties[single_faction] += Amount;
}
}
public int 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>();
}
}