improve detection of combat zones by listening for messages

This commit is contained in:
Florian Stinglmayr 2022-12-07 16:42:44 +01:00
parent 43ae93658f
commit 123fa15884
4 changed files with 53 additions and 8 deletions

View File

@ -44,6 +44,11 @@ internal class TransactionParserContext {
/// </summary>
public ulong ThargoidInterceptorKills { get; set; } = 0;
/// <summary>
/// Whether we have seen an AX warzone NPC talk to us with ReceiveText
/// </summary>
public bool HaveSeenAXWarzoneNPC { get; set; } = false;
/// <summary>
/// A list of accepted missions index by their mission ID
/// </summary>
@ -69,11 +74,8 @@ internal class TransactionParserContext {
public void DiscernCombatZone(TransactionList transactions, Entry e) {
string? grade = CombatZones.DifficultyLow;
string cztype;
ulong? highest = HighestCombatBond;
if (highest == null || LastRecordedAwardingFaction == null) {
return;
}
ulong highest = HighestCombatBond ?? 0;
string? faction = LastRecordedAwardingFaction;
if (OnFootKills > 0) {
cztype = CombatZones.GroundCombatZone;
@ -110,7 +112,8 @@ internal class TransactionParserContext {
}
}
cztype = CombatZones.ShipCombatZone;
} else if (ThargoidScoutKills > 0 && ThargoidInterceptorKills > 0) {
} else if ((ThargoidScoutKills > 0 && ThargoidInterceptorKills > 0) ||
HaveSeenAXWarzoneNPC == true) {
// Could be a thargoid combat zones if interceptors and scouts are there
cztype = CombatZones.AXCombatZone;
// Still unknown
@ -122,7 +125,7 @@ internal class TransactionParserContext {
CombatZone zone = new CombatZone() {
System = CurrentSystem,
Faction = LastRecordedAwardingFaction,
Faction = faction,
IsLegacy = IsLegacy,
Grade = grade,
Type = cztype,
@ -161,6 +164,7 @@ internal class TransactionParserContext {
ShipKills = 0;
ThargoidInterceptorKills = 0;
ThargoidScoutKills = 0;
HaveSeenAXWarzoneNPC = false;
}
public void BoughtCargo(string? cargo, long? cost) {
@ -856,11 +860,38 @@ internal class FileHeaderParser : TransactionParserPart {
}
}
internal class ReceiveTextParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
ReceiveTextEntry? receivetext = entry as ReceiveTextEntry;
if (receivetext == null) {
return;
}
if (string.Compare(receivetext.Channel, Channels.NPC) != 0) {
return;
}
if (string.Compare(receivetext.NPCCategory, NPCs.AXMilitary) == 0) {
context.HaveSeenAXWarzoneNPC = true;
}
}
}
internal class DiedParser : TransactionParserPart {
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions) {
// You can't complete a combat zone if you die in it. Others might keep it open
// for you, but still you will not have completed it unless you jump back in.
context.ResetCombatZone();
}
}
public class TransactionParser {
private static Dictionary<string, TransactionParserPart> ParserParts { get; } = new()
{
{ Events.CapShipBond, new CapShipBondParser() },
{ Events.CommitCrime, new CommitCrimeParser() },
{ Events.Died, new DiedParser() },
{ Events.Disembark, new EmbarkDisembarkParser() },
{ Events.Docked, new DockedParser() },
{ Events.Embark, new EmbarkDisembarkParser() },
@ -874,6 +905,7 @@ public class TransactionParser {
{ Events.MissionCompleted, new MissionCompletedParser() },
{ Events.MissionFailed, new MissionFailedParser() },
{ Events.MultiSellExplorationData, new MultiSellExplorationDataParser() },
{ Events.ReceiveText, new ReceiveTextParser() },
{ Events.RedeemVoucher, new RedeemVoucherParser() },
{ Events.SearchAndRescue, new SearchAndRescueParser() },
{ Events.SellExplorationData, new SellExplorationDataParser() },

View File

@ -0,0 +1,8 @@
namespace EDPlayerJournal;
public class Channels {
/// <summary>
/// Channel NPCs use to talk to the commander.
/// </summary>
public static readonly string NPC = "npc";
}

View File

@ -46,7 +46,7 @@ public class ReceiveTextEntry : Entry {
return null;
}
return parts[0];
return string.Format("{0};", parts[0]);
}
}

View File

@ -41,6 +41,11 @@ public class NPCs {
/// </summary>
public static string WarzoneCorrespondent = "$LUASC_Scenario_Warzone_NPC_WarzoneCorrespondent;";
/// <summary>
/// AX Military NPC
/// </summary>
public static string AXMilitary = "$Name_AX_Military;";
/// <summary>
/// Returns true if the pilotname is either a captain, specops, or correspondent
/// </summary>