Added basic detection for Player and Passenger Kills

This will override the victim ship to be a Passenger or a Player. I've also moved the ship manufactures to constants because we'll need to reference them elsewhere.
This commit is contained in:
Heavy Bob 2025-04-11 03:52:38 +10:00
parent b34e7d0165
commit 281f714ec4
3 changed files with 73 additions and 38 deletions

View file

@ -0,0 +1,28 @@
using System.Collections.Generic;
namespace AutoTrackR2.Constants;
public static class ShipManufacturers
{
public static readonly List<string> List = new List<string>
{
"ORIG",
"CRUS",
"RSI",
"AEGS",
"VNCL",
"DRAK",
"ANVL",
"BANU",
"MISC",
"CNOU",
"XIAN",
"GAMA",
"TMBL",
"ESPR",
"KRIG",
"GRIN",
"XNAA",
"MRAI"
};
}

View file

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using AutoTrackR2.Constants;
namespace AutoTrackR2.LogEventHandlers;
@ -16,17 +17,32 @@ public struct ActorDeathData
public class ActorDeathEvent : ILogEventHandler
{
public Regex Pattern { get; }
private Regex _cleanUpPattern = new Regex(@"^(.+?)_\d+$");
private Regex _shipManufacturerPattern;
private string _lastKillShip = string.Empty;
public ActorDeathEvent()
{
Pattern = new Regex(@"<(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)> \[Notice\] <Actor Death> CActor::Kill: '(?<EnemyPilot>[^']+)' \[\d+\] in zone '(?<EnemyShip>[^']+)' killed by '(?<Player>[^']+)' \[[^']+\] using '(?<Weapon>[^']+)' \[Class (?<Class>[^\]]+)\] with damage type '(?<DamageType>[^']+)");
_shipManufacturerPattern = new Regex($"^({string.Join("|", ShipManufacturers.List)})");
}
private bool IsValidShip(string shipName)
{
// Clean up the ship name first
if (_cleanUpPattern.IsMatch(shipName))
{
shipName = _cleanUpPattern.Match(shipName).Groups[1].Value;
}
// A valid ship must start with a known manufacturer
return _shipManufacturerPattern.IsMatch(shipName);
}
Regex cleanUpPattern = new Regex(@"^(.+?)_\d+$");
public void Handle(LogEntry entry)
{
if (entry.Message is null) return;
var match = Pattern.Match(entry.Message);
if (!match.Success) return;
@ -40,21 +56,32 @@ public class ActorDeathEvent : ILogEventHandler
DamageType = match.Groups["DamageType"].Value,
Timestamp = match.Groups["Timestamp"].Value
};
if (cleanUpPattern.IsMatch(data.VictimShip))
// Clean up weapon name
if (_cleanUpPattern.IsMatch(data.Weapon))
{
data.VictimShip = cleanUpPattern.Match(data.VictimShip).Groups[1].Value;
data.Weapon = _cleanUpPattern.Match(data.Weapon).Groups[1].Value;
}
if (cleanUpPattern.IsMatch(data.Weapon))
// First check if this is a valid ship
if (!IsValidShip(data.VictimShip))
{
data.Weapon = cleanUpPattern.Match(data.Weapon).Groups[1].Value;
data.VictimShip = "Player";
}
else
{
// For valid ships, check for passenger flag
if (data.VictimShip == _lastKillShip)
{
data.VictimShip = "Passenger";
}
else
{
_lastKillShip = data.VictimShip;
}
}
TrackREventDispatcher.OnActorDeathEvent(data);
}
}

View file

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using AutoTrackR2.Constants;
namespace AutoTrackR2.LogEventHandlers;
@ -18,33 +19,11 @@ public class InstancedInteriorEvent : ILogEventHandler
private Regex _shipManufacturerPattern;
private Regex _cleanUpPattern = new Regex(@"(.+?)_\d+$");
private List<string> _shipManufacturers = new List<string>
{
"ORIG",
"CRUS",
"RSI",
"AEGS",
"VNCL",
"DRAK",
"ANVL",
"BANU",
"MISC",
"CNOU",
"XIAN",
"GAMA",
"TMBL",
"ESPR",
"KRIG",
"GRIN",
"XNAA",
"MRAI"
};
public InstancedInteriorEvent()
{
Pattern = new Regex(@"\[InstancedInterior\] OnEntityLeaveZone - InstancedInterior \[(?<InstancedInterior>[^\]]+)\] \[\d+\] -> Entity \[(?<Entity>[^\]]+)\] \[\d+\] -- m_openDoors\[\d+\], m_managerGEID\[(?<ManagerGEID>\d+)\], m_ownerGEID\[(?<OwnerGEID>[^\[]+)\]");
_shipManufacturerPattern = new Regex($"^({string.Join("|", _shipManufacturers)})");
_shipManufacturerPattern = new Regex($"^({string.Join("|", ShipManufacturers.List)})");
}
public void Handle(LogEntry entry)
@ -52,8 +31,9 @@ public class InstancedInteriorEvent : ILogEventHandler
if (entry.Message is null) return;
var match = Pattern.Match(entry.Message);
if (!match.Success) return;
var data = new InstancedInteriorData {
var data = new InstancedInteriorData
{
Entity = match.Groups["Entity"].Value,
OwnerGEID = match.Groups["OwnerGEID"].Value,
ManagerGEID = match.Groups["ManagerGEID"].Value,