properly handle vouchers and their BGS effect

This commit is contained in:
Florian Stinglmayr 2022-02-12 19:50:26 +01:00
parent 1bc7269221
commit 6a73a08b00
5 changed files with 53 additions and 16 deletions

View File

@ -77,7 +77,7 @@ namespace EliteBGS.BGS {
log.AppendFormat("{0}\n", GenerateFooter()); log.AppendFormat("{0}\n", GenerateFooter());
return log.ToString(); return log.ToString().Trim();
} }
} }
} }

View File

@ -18,7 +18,7 @@ namespace EliteBGS.BGS.LogGenerator {
builder.AppendFormat("\n"); builder.AppendFormat("\n");
} }
return builder.ToString(); return builder.ToString().Trim();
} }
} }
} }

View File

@ -71,6 +71,7 @@ namespace EliteBGS.BGS {
Dictionary<string, long> buyCost = new Dictionary<string, long>(); Dictionary<string, long> buyCost = new Dictionary<string, long>();
Dictionary<ulong, string> systems = new Dictionary<ulong, string>(); Dictionary<ulong, string> systems = new Dictionary<ulong, string>();
Dictionary<string, string> npcfactions = new Dictionary<string, string>(); Dictionary<string, string> npcfactions = new Dictionary<string, string>();
Dictionary<string, List<Faction>> system_factions = new Dictionary<string, List<Faction>>();
string current_system = null; string current_system = null;
ulong current_system_address = 0; ulong current_system_address = 0;
@ -106,6 +107,11 @@ namespace EliteBGS.BGS {
if (!systems.ContainsKey(fsd.SystemAddress)) { if (!systems.ContainsKey(fsd.SystemAddress)) {
systems.Add(fsd.SystemAddress, fsd.StarSystem); 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)) { } else if (e.Is(Events.Location)) {
/* Get current system, faction name and station from Location message /* Get current system, faction name and station from Location message
*/ */
@ -124,6 +130,11 @@ namespace EliteBGS.BGS {
if (!string.IsNullOrEmpty(location.StationName)) { if (!string.IsNullOrEmpty(location.StationName)) {
current_station = 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)) { } else if (e.Is(Events.ShipTargeted)) {
ShipTargetedEntry targeted = e as ShipTargetedEntry; ShipTargetedEntry targeted = e as ShipTargetedEntry;
@ -252,14 +263,34 @@ namespace EliteBGS.BGS {
collate = true; collate = true;
} else if (e.Is(Events.RedeemVoucher)) { } else if (e.Is(Events.RedeemVoucher)) {
/* Same for selling combat vouchers. Only the current controlling faction matters here. RedeemVoucherEntry voucher = e as RedeemVoucherEntry;
*/ List<Faction> current_factions = new List<Faction>();
results.Add(new Vouchers(e as RedeemVoucherEntry) {
System = current_system, if (system_factions.ContainsKey(current_system)) {
Station = current_station, current_factions = system_factions[current_system];
Faction = (e as RedeemVoucherEntry).Factions.FirstOrDefault() ?? "", } else {
ControllingFaction = controlling_faction, 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; collate = true;
} else if (e.Is(Events.SellMicroResources)) { } else if (e.Is(Events.SellMicroResources)) {

View File

@ -13,11 +13,12 @@ namespace EliteBGS.BGS {
Entries.Add(e); Entries.Add(e);
} }
public int TotalSum { public long TotalSum {
get { get {
return Entries return Entries
.Where(x => x.GetType() == typeof(RedeemVoucherEntry)) .OfType<RedeemVoucherEntry>()
.Sum(x => (x as RedeemVoucherEntry).Amount) .Where(x => x.FactionBounties.ContainsKey(Faction))
.Sum(x => x.FactionBounties[Faction])
; ;
} }
} }
@ -44,12 +45,15 @@ namespace EliteBGS.BGS {
} }
public override int CompareTo(LogEntry other) { public override int CompareTo(LogEntry other) {
if (other.GetType() != typeof(Vouchers)) { if (other == null || other.GetType() != typeof(Vouchers)) {
return -1; return -1;
} }
var b = other as Vouchers; Vouchers b = other as Vouchers;
if (b.Type == Type) { if (b.Type == Type &&
b.Faction == Faction &&
b.System == System &&
b.Station == Station) {
return 0; return 0;
} }

View File

@ -5,6 +5,8 @@
* Added search and rescue. * Added search and rescue.
* For mourders try to determine the faction of the victim. The CommitCrime event * 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. 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 ## 0.1.0-beta9 on 07.02.2022