fix(combat): replace reflection with direct kill patterns array

The static constructor used reflection to read KillTracker.KillPatterns
which caused a TypeInitializationException — making _combatStatsTracker
null and silently disabling the entire combat tracking pipeline.

Replaced with a direct copy of the 35 kill regex patterns. No reflection,
no static constructor, no silent failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-12 09:58:33 +02:00
parent 00d713a134
commit 77e87484e8
2 changed files with 39 additions and 13 deletions

View file

@ -306,20 +306,46 @@ namespace MosswartMassacre
return false;
}
// ── Kill messages — reuse KillTracker patterns ──
private static readonly Regex[] _killPatterns;
static CombatStatsTracker()
// ── Kill messages — same patterns as KillTracker ──
private static readonly Regex[] _killPatterns = new[]
{
// Build compiled kill regexes from KillTracker's string patterns
var field = typeof(KillTracker).GetField("KillPatterns",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
string[] patterns = field?.GetValue(null) as string[] ?? Array.Empty<string>();
var list = new List<Regex>(patterns.Length);
foreach (var p in patterns)
list.Add(new Regex(p, RegexOptions.Compiled));
_killPatterns = list.ToArray();
}
new Regex(@"^You flatten (?<targetname>.+)'s body with the force of your assault!$", RegexOptions.Compiled),
new Regex(@"^You bring (?<targetname>.+) to a fiery end!$", RegexOptions.Compiled),
new Regex(@"^You beat (?<targetname>.+) to a lifeless pulp!$", RegexOptions.Compiled),
new Regex(@"^You smite (?<targetname>.+) mightily!$", RegexOptions.Compiled),
new Regex(@"^You obliterate (?<targetname>.+)!$", RegexOptions.Compiled),
new Regex(@"^You run (?<targetname>.+) through!$", RegexOptions.Compiled),
new Regex(@"^You reduce (?<targetname>.+) to a sizzling, oozing mass!$", RegexOptions.Compiled),
new Regex(@"^You knock (?<targetname>.+) into next Morningthaw!$", RegexOptions.Compiled),
new Regex(@"^You split (?<targetname>.+) apart!$", RegexOptions.Compiled),
new Regex(@"^You cleave (?<targetname>.+) in twain!$", RegexOptions.Compiled),
new Regex(@"^You slay (?<targetname>.+) viciously enough to impart death several times over!$", RegexOptions.Compiled),
new Regex(@"^You reduce (?<targetname>.+) to a drained, twisted corpse!$", RegexOptions.Compiled),
new Regex(@"^Your killing blow nearly turns (?<targetname>.+) inside-out!$", RegexOptions.Compiled),
new Regex(@"^Your attack stops (?<targetname>.+) cold!$", RegexOptions.Compiled),
new Regex(@"^Your lightning coruscates over (?<targetname>.+)'s mortal remains!$", RegexOptions.Compiled),
new Regex(@"^Your assault sends (?<targetname>.+) to an icy death!$", RegexOptions.Compiled),
new Regex(@"^You killed (?<targetname>.+)!$", RegexOptions.Compiled),
new Regex(@"^The thunder of crushing (?<targetname>.+) is followed by the deafening silence of death!$", RegexOptions.Compiled),
new Regex(@"^The deadly force of your attack is so strong that (?<targetname>.+)'s ancestors feel it!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+)'s seared corpse smolders before you!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is reduced to cinders!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is shattered by your assault!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) catches your attack, with dire consequences!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is utterly destroyed by your attack!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) suffers a frozen fate!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+)'s perforated corpse falls before you!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is fatally punctured!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+)'s death is preceded by a sharp, stabbing pain!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is torn to ribbons by your assault!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is liquified by your attack!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+)'s last strength dissolves before you!$", RegexOptions.Compiled),
new Regex(@"^Electricity tears (?<targetname>.+) apart!$", RegexOptions.Compiled),
new Regex(@"^Blistered by lightning, (?<targetname>.+) falls!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+)'s last strength withers before you!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is dessicated by your attack!$", RegexOptions.Compiled),
new Regex(@"^(?<targetname>.+) is incinerated by your assault!$", RegexOptions.Compiled),
};
private bool TryParseKill(string text, string myName)
{