diff --git a/AutoTrackR2/Constants/ShipManufacturers.cs b/AutoTrackR2/Constants/ShipManufacturers.cs new file mode 100644 index 0000000..0e3cac9 --- /dev/null +++ b/AutoTrackR2/Constants/ShipManufacturers.cs @@ -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" + }; +} \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs b/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs index 7160648..56741f5 100644 --- a/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs +++ b/AutoTrackR2/LogEventHandlers/ActorDeathEvent.cs @@ -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); - } - - } \ No newline at end of file diff --git a/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs b/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs index 62ab732..a6759eb 100644 --- a/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs +++ b/AutoTrackR2/LogEventHandlers/InstancedInteriorEvent.cs @@ -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,