add support for thargoid vouchers
This commit is contained in:
		
							parent
							
								
									e8de768d01
								
							
						
					
					
						commit
						8514331701
					
				@ -28,7 +28,7 @@ public class ThargoidKill : Transaction {
 | 
				
			|||||||
    public ThargoidKill() { }
 | 
					    public ThargoidKill() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public ThargoidKill(FactionKillBondEntry entry) {
 | 
					    public ThargoidKill(FactionKillBondEntry entry) {
 | 
				
			||||||
        if (string.Compare(entry.VictimFaction, Thargoid.ThargoidFaction) != 0) {
 | 
					        if (!Factions.IsThargoid(entry.VictimFaction)) {
 | 
				
			||||||
            throw new Exception("Not a valid thargoid kill");
 | 
					            throw new Exception("Not a valid thargoid kill");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -488,9 +488,12 @@ internal class RedeemVoucherParser : TransactionParserPart {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        foreach (string faction in entry.Factions) {
 | 
					        foreach (string faction in entry.Factions) {
 | 
				
			||||||
            bool relevantBond = false;
 | 
					            bool relevantBond = false;
 | 
				
			||||||
 | 
					            string relevantFaction = faction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (string.Compare(faction, Factions.PilotsFederationVouchers) == 0) {
 | 
					            if (string.Compare(faction, Factions.PilotsFederationVouchers) == 0) {
 | 
				
			||||||
                // Target faction is pilots' federation, so we assume thargoid bonks
 | 
					                // Target faction is pilots' federation, so we assume thargoid bonks
 | 
				
			||||||
 | 
					                // Also assign this combat bond to the Pilots Federation
 | 
				
			||||||
 | 
					                relevantFaction = Factions.PilotsFederation;
 | 
				
			||||||
                relevantBond = true;
 | 
					                relevantBond = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -511,7 +514,7 @@ internal class RedeemVoucherParser : TransactionParserPart {
 | 
				
			|||||||
                transactions.Add(new Vouchers(entry) {
 | 
					                transactions.Add(new Vouchers(entry) {
 | 
				
			||||||
                    System = context.CurrentSystem,
 | 
					                    System = context.CurrentSystem,
 | 
				
			||||||
                    Station = context.CurrentStation,
 | 
					                    Station = context.CurrentStation,
 | 
				
			||||||
                    Faction = faction,
 | 
					                    Faction = relevantFaction,
 | 
				
			||||||
                    ControllingFaction = context.ControllingFaction,
 | 
					                    ControllingFaction = context.ControllingFaction,
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -600,9 +603,13 @@ internal class FactionKillBondParser : TransactionParserPart {
 | 
				
			|||||||
            throw new NotImplementedException();
 | 
					            throw new NotImplementedException();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (string.Compare(entry.VictimFaction, Thargoid.ThargoidFaction) == 0) {
 | 
					        if (Factions.IsThargoid(entry.VictimFaction)) {
 | 
				
			||||||
            // Thargoid bonk
 | 
					            // Thargoid bonk
 | 
				
			||||||
            transactions.Add(new ThargoidKill(entry));
 | 
					            transactions.Add(new ThargoidKill(entry) {
 | 
				
			||||||
 | 
					                System = context.CurrentSystem,
 | 
				
			||||||
 | 
					                Faction = Factions.PilotsFederation,
 | 
				
			||||||
 | 
					                Station = context.CurrentStation,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,8 +20,8 @@ public class Vouchers : Transaction {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            return Entries
 | 
					            return Entries
 | 
				
			||||||
                .OfType<RedeemVoucherEntry>()
 | 
					                .OfType<RedeemVoucherEntry>()
 | 
				
			||||||
                .Where(x => x.FactionBounties.ContainsKey(Faction))
 | 
					                .ToList()
 | 
				
			||||||
                .Sum(x => x.FactionBounties[Faction])
 | 
					                .Sum(x => (long)x.GetBountyForFaction(Faction))
 | 
				
			||||||
                ;
 | 
					                ;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@ using System.Collections.Generic;
 | 
				
			|||||||
namespace EDPlayerJournal.Entries; 
 | 
					namespace EDPlayerJournal.Entries; 
 | 
				
			||||||
public class RedeemVoucherEntry : Entry {
 | 
					public class RedeemVoucherEntry : Entry {
 | 
				
			||||||
    protected override void Initialise() {
 | 
					    protected override void Initialise() {
 | 
				
			||||||
        Amount = (JSON.Value<int?>("Amount") ?? 0);
 | 
					        Amount = (JSON.Value<ulong?>("Amount") ?? 0);
 | 
				
			||||||
        Type = JSON.Value<string>("Type");
 | 
					        Type = JSON.Value<string>("Type");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* according to API, there should be a Factions structure */
 | 
					        /* according to API, there should be a Factions structure */
 | 
				
			||||||
@ -12,7 +12,7 @@ public class RedeemVoucherEntry : Entry {
 | 
				
			|||||||
        if (factions != null) {
 | 
					        if (factions != null) {
 | 
				
			||||||
            foreach (JObject faction in factions.Children<JObject>()) {
 | 
					            foreach (JObject faction in factions.Children<JObject>()) {
 | 
				
			||||||
                string? faction_name = faction.Value<string>("Faction");
 | 
					                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) {
 | 
					                if (faction_name == null || faction_name.Length <= 0 || faction_bounty == null) {
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -35,8 +35,29 @@ public class RedeemVoucherEntry : Entry {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int Amount { get; set; } = 0;
 | 
					    public ulong GetBountyForFaction(string? a) {
 | 
				
			||||||
    public string? Type { get; set; } = "Bounty";
 | 
					        if (a == null) {
 | 
				
			||||||
    public List<string> Factions { get; set; } = new List<string>();
 | 
					            return 0;
 | 
				
			||||||
    public Dictionary<string, long> FactionBounties { get; set; } = new Dictionary<string, long>();
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <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();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -40,10 +40,71 @@ public class Factions {
 | 
				
			|||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    public static string PilotsFederationVouchers = "PilotsFederation";
 | 
					    public static string PilotsFederationVouchers = "PilotsFederation";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Friendly name of the Pilots Federation
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    public static string PilotsFederation = "Pilots' Federation";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// Internal name for the Thargoid faction
 | 
					    /// Internal name for the Thargoid faction
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    public static string Thargoid = "$faction_Thargoid;";
 | 
					    public static string ThargoidInternal = "$faction_Thargoid;";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Localised name of the Thargoids
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    public static string Thargoid = "Thargoids";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static bool IsPilotsFederation(string? name) {
 | 
				
			||||||
 | 
					        if (name == null) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (string.Compare(name, PilotsFederationInternal) == 0 ||
 | 
				
			||||||
 | 
					            string.Compare(name, PilotsFederationVouchers) == 0 ||
 | 
				
			||||||
 | 
					            string.Compare(name, PilotsFederation) == 0) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static bool IsThargoid(string? name) {
 | 
				
			||||||
 | 
					        if (name == null) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (string.Compare(name, ThargoidInternal) == 0 ||
 | 
				
			||||||
 | 
					            string.Compare(name, Thargoid) == 0) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Compares two factions names and sees if they are the same faction. Since
 | 
				
			||||||
 | 
					    /// factions can have an internal name, and a public name, this function takes
 | 
				
			||||||
 | 
					    /// these into account.
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <param name="a"></param>
 | 
				
			||||||
 | 
					    /// <param name="b"></param>
 | 
				
			||||||
 | 
					    /// <returns></returns>
 | 
				
			||||||
 | 
					    public static int CompareFactions(string? a, string? b) {
 | 
				
			||||||
 | 
					        if (a == null || b == null) {
 | 
				
			||||||
 | 
					            return -1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (IsPilotsFederation(a) && IsPilotsFederation(b)) {
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (IsThargoid(a) && IsThargoid(b)) {
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return string.Compare(a, b);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Faction {
 | 
					public class Faction {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user