diff --git a/BGS/DiscordLogGenerator.cs b/BGS/DiscordLogGenerator.cs index ffde1ce..b89a0fd 100644 --- a/BGS/DiscordLogGenerator.cs +++ b/BGS/DiscordLogGenerator.cs @@ -77,7 +77,7 @@ namespace EliteBGS.BGS { log.AppendFormat("{0}\n", GenerateFooter()); - return log.ToString(); + return log.ToString().Trim(); } } } diff --git a/BGS/LogGenerator/VoucherFormat.cs b/BGS/LogGenerator/VoucherFormat.cs index 5392630..85684ae 100644 --- a/BGS/LogGenerator/VoucherFormat.cs +++ b/BGS/LogGenerator/VoucherFormat.cs @@ -18,7 +18,7 @@ namespace EliteBGS.BGS.LogGenerator { builder.AppendFormat("\n"); } - return builder.ToString(); + return builder.ToString().Trim(); } } } diff --git a/BGS/Report.cs b/BGS/Report.cs index 0c52681..6446e7b 100644 --- a/BGS/Report.cs +++ b/BGS/Report.cs @@ -71,6 +71,7 @@ namespace EliteBGS.BGS { Dictionary buyCost = new Dictionary(); Dictionary systems = new Dictionary(); Dictionary npcfactions = new Dictionary(); + Dictionary> system_factions = new Dictionary>(); string current_system = null; ulong current_system_address = 0; @@ -106,6 +107,11 @@ namespace EliteBGS.BGS { if (!systems.ContainsKey(fsd.SystemAddress)) { systems.Add(fsd.SystemAddress, fsd.StarSystem); } + + if (!system_factions.ContainsKey(fsd.StarSystem) && + fsd.SystemFactions.Count > 0) { + system_factions[fsd.StarSystem] = fsd.SystemFactions; + } } else if (e.Is(Events.Location)) { /* Get current system, faction name and station from Location message */ @@ -124,6 +130,11 @@ namespace EliteBGS.BGS { if (!string.IsNullOrEmpty(location.StationName)) { current_station = location.StationName; } + + if (!system_factions.ContainsKey(location.StarSystem) && + location.SystemFactions.Count > 0) { + system_factions[location.StarSystem] = location.SystemFactions; + } } else if (e.Is(Events.ShipTargeted)) { ShipTargetedEntry targeted = e as ShipTargetedEntry; @@ -252,14 +263,34 @@ namespace EliteBGS.BGS { collate = true; } else if (e.Is(Events.RedeemVoucher)) { - /* Same for selling combat vouchers. Only the current controlling faction matters here. - */ - results.Add(new Vouchers(e as RedeemVoucherEntry) { - System = current_system, - Station = current_station, - Faction = (e as RedeemVoucherEntry).Factions.FirstOrDefault() ?? "", - ControllingFaction = controlling_faction, - }); + RedeemVoucherEntry voucher = e as RedeemVoucherEntry; + List current_factions = new List(); + + if (system_factions.ContainsKey(current_system)) { + current_factions = system_factions[current_system]; + } else { + OnLog?.Invoke("There are no current system factions, so turned in vouchers were ignored."); + continue; + } + + foreach (string faction in voucher.Factions) { + if (current_factions.Find(x => x.Name == faction) == null) { + OnLog?.Invoke( + string.Format("Vouchers for \"{0}\" were ignored in \"{1}\" since said " + + "faction is not present there.", faction, current_system) + ); + continue; /* faction is not present, so it is ignored */ + } + + /* Same for selling combat vouchers. Only the current controlling faction matters here. + */ + results.Add(new Vouchers(voucher) { + System = current_system, + Station = current_station, + Faction = faction, + ControllingFaction = controlling_faction, + }); + } collate = true; } else if (e.Is(Events.SellMicroResources)) { diff --git a/BGS/Vouchers.cs b/BGS/Vouchers.cs index 8974e40..bbf6d03 100644 --- a/BGS/Vouchers.cs +++ b/BGS/Vouchers.cs @@ -13,11 +13,12 @@ namespace EliteBGS.BGS { Entries.Add(e); } - public int TotalSum { + public long TotalSum { get { return Entries - .Where(x => x.GetType() == typeof(RedeemVoucherEntry)) - .Sum(x => (x as RedeemVoucherEntry).Amount) + .OfType() + .Where(x => x.FactionBounties.ContainsKey(Faction)) + .Sum(x => x.FactionBounties[Faction]) ; } } @@ -44,12 +45,15 @@ namespace EliteBGS.BGS { } public override int CompareTo(LogEntry other) { - if (other.GetType() != typeof(Vouchers)) { + if (other == null || other.GetType() != typeof(Vouchers)) { return -1; } - var b = other as Vouchers; - if (b.Type == Type) { + Vouchers b = other as Vouchers; + if (b.Type == Type && + b.Faction == Faction && + b.System == System && + b.Station == Station) { return 0; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 183f861..5714e80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * Added search and rescue. * For mourders try to determine the faction of the victim. The CommitCrime event lists the faction that issues the bounty, and not the faction of the victim. +* Vouchers are now properly treated. Each individual voucher is assigned a separate + objective, if the target faction for said voucher is present in the system. ## 0.1.0-beta9 on 07.02.2022