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());
return log.ToString();
return log.ToString().Trim();
}
}
}

View File

@ -18,7 +18,7 @@ namespace EliteBGS.BGS.LogGenerator {
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<ulong, string> systems = new Dictionary<ulong, string>();
Dictionary<string, string> npcfactions = new Dictionary<string, string>();
Dictionary<string, List<Faction>> system_factions = new Dictionary<string, List<Faction>>();
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)) {
RedeemVoucherEntry voucher = e as RedeemVoucherEntry;
List<Faction> current_factions = new List<Faction>();
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(e as RedeemVoucherEntry) {
results.Add(new Vouchers(voucher) {
System = current_system,
Station = current_station,
Faction = (e as RedeemVoucherEntry).Factions.FirstOrDefault() ?? "",
Faction = faction,
ControllingFaction = controlling_faction,
});
}
collate = true;
} else if (e.Is(Events.SellMicroResources)) {

View File

@ -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<RedeemVoucherEntry>()
.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;
}

View File

@ -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