2021-10-07 08:52:19 +02:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace EDJournal {
|
2021-08-25 18:24:44 +02:00
|
|
|
|
public class RedeemVoucherEntry : Entry {
|
|
|
|
|
protected override void Initialise() {
|
2021-10-07 08:52:19 +02:00
|
|
|
|
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");
|
2022-02-12 18:59:48 +01:00
|
|
|
|
long faction_bounty = faction.Value<long?>("Amount") ?? 0;
|
2021-10-07 08:52:19 +02:00
|
|
|
|
if (faction_name == null || faction_name.Length <= 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Factions.Add(faction_name);
|
2022-02-12 18:59:48 +01:00
|
|
|
|
if (!FactionBounties.ContainsKey(faction_name)) {
|
|
|
|
|
FactionBounties[faction_name] = 0;
|
|
|
|
|
}
|
|
|
|
|
FactionBounties[faction_name] += faction_bounty;
|
2021-10-07 08:52:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* but there also might be just a Faction entry */
|
|
|
|
|
string single_faction = JSON.Value<string>("Faction");
|
|
|
|
|
if (single_faction != null) {
|
|
|
|
|
Factions.Add(single_faction);
|
2022-02-12 19:04:23 +01:00
|
|
|
|
if (!FactionBounties.ContainsKey(single_faction)) {
|
|
|
|
|
FactionBounties[single_faction] = 0;
|
|
|
|
|
}
|
|
|
|
|
FactionBounties[single_faction] += Amount;
|
2021-10-07 08:52:19 +02:00
|
|
|
|
}
|
2021-08-25 18:24:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 08:52:19 +02:00
|
|
|
|
public int Amount { get; set; } = 0;
|
|
|
|
|
public string Type { get; set; } = "Bounty";
|
|
|
|
|
public List<string> Factions { get; set; } = new List<string>();
|
2022-02-12 18:59:48 +01:00
|
|
|
|
public Dictionary<string, long> FactionBounties { get; set; } = new Dictionary<string, long>();
|
2021-08-25 18:24:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|