add a highly rudimentary combat zone detector

This commit is contained in:
2022-11-25 17:13:17 +01:00
parent fe28a4d17d
commit 955a108f2e
7 changed files with 331 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
using EDPlayerJournal.Entries;
using System.Collections.Generic;
using System.Reflection.Metadata.Ecma335;
using System.Transactions;
namespace EDPlayerJournal.BGS;
@@ -10,6 +11,22 @@ internal class TransactionParserContext {
public string? CurrentStation { get; set; }
public string? ControllingFaction { get; set; }
public bool IsOnFoot { get; set; } = false;
public string? LastRecordedAwardingFaction { get; set; }
public ulong? HighestCombatBond { get; set; }
/// <summary>
/// How many on foot kills were done.
/// </summary>
public ulong OnFootKills { get; set; } = 0;
/// <summary>
/// How many ship kills were done.
/// </summary>
public ulong ShipKills { get; set; } = 0;
/// <summary>
/// A list of accepted missions index by their mission ID
/// </summary>
@@ -32,6 +49,67 @@ internal class TransactionParserContext {
/// </summary>
public Dictionary<string, long> BuyCost = new();
public void DiscernCombatZone(TransactionList transactions) {
string grade = "Low";
string cztype;
ulong? highest = HighestCombatBond;
if (highest == null || LastRecordedAwardingFaction == null) {
return;
}
if (OnFootKills > 0) {
cztype = "OnFoot";
// High on foot combat zones have enforcers that bring 80k a pop
if (highest >= 80000) {
grade = "High";
} else if (highest >= 4000) {
grade = "Medium";
}
} else if (ShipKills > 0) {
// Ship combat zones can be identified by the amount of kills
if (ShipKills > 20) {
grade = "High";
} else if (ShipKills > 10) {
grade = "Medium";
}
cztype = "Ship";
} else {
transactions.AddIncomplete(new CombatZone(), "Failed to discern combat zone type");
return;
}
CombatZone zone = new CombatZone() {
System = CurrentSystem,
Faction = LastRecordedAwardingFaction,
Grade = grade,
Type = cztype,
Amount = 1,
};
transactions.Add(zone);
}
public void RecordCombatBond(FactionKillBondEntry e) {
if (HighestCombatBond == null || e.Reward > HighestCombatBond) {
HighestCombatBond = e.Reward;
}
LastRecordedAwardingFaction = e.AwardingFaction;
if (IsOnFoot) {
++OnFootKills;
} else {
++ShipKills;
}
}
public void ResetCombatZone() {
HighestCombatBond = null;
LastRecordedAwardingFaction = null;
OnFootKills = 0;
ShipKills = 0;
}
public void BoughtCargo(string? cargo, long? cost) {
if (cargo == null || cost == null) {
return;
@@ -610,7 +688,36 @@ internal class FactionKillBondParser : TransactionParserPart {
Faction = Factions.PilotsFederation,
Station = context.CurrentStation,
});
// We are done
return;
}
context.RecordCombatBond(entry);
}
}
internal class EmbarkDisembarkParser : TransactionParserPart {
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
if (e.Is(Events.Embark)) {
context.IsOnFoot = false;
} else if (e.Is(Events.Disembark)) {
context.IsOnFoot = true;
}
}
}
internal class SupercruiseEntryParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
context.DiscernCombatZone(transactions);
context.ResetCombatZone();
}
}
internal class ShutdownParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
context.DiscernCombatZone(transactions);
context.ResetCombatZone();
}
}
@@ -618,7 +725,9 @@ public class TransactionParser {
private static Dictionary<string, TransactionParserPart> ParserParts { get; } = new()
{
{ Events.CommitCrime, new CommitCrimeParser() },
{ Events.Disembark, new EmbarkDisembarkParser() },
{ Events.Docked, new DockedParser() },
{ Events.Embark, new EmbarkDisembarkParser() },
{ Events.FactionKillBond, new FactionKillBondParser() },
{ Events.FSDJump, new FSDJumpParser() },
{ Events.Location, new LocationParser() },
@@ -634,6 +743,8 @@ public class TransactionParser {
{ Events.SellMicroResources, new SellMicroResourcesParser() },
{ Events.SellOrganicData, new SellOrganicDataParser() },
{ Events.ShipTargeted, new ShipTargetedParser() },
{ Events.Shutdown, new ShutdownParser() },
{ Events.SupercruiseEntry, new SupercruiseEntryParser() },
};
public List<Transaction>? Parse(IEnumerable<Entry> entries) {