]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Try fix KeyNotFoundException in KillTrackingSystem (#28553)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Mon, 3 Jun 2024 13:36:07 +0000 (01:36 +1200)
committerGitHub <noreply@github.com>
Mon, 3 Jun 2024 13:36:07 +0000 (09:36 -0400)
Content.Server/KillTracking/KillTrackingSystem.cs

index 63627fd1b97198a47da18a2e87a793461ed79d0d..ba27ea5d9e5a0d1e415c5056d32096191984a3c7 100644 (file)
@@ -2,6 +2,7 @@ using Content.Server.NPC.HTN;
 using Content.Shared.Damage;
 using Content.Shared.FixedPoint;
 using Content.Shared.Mobs;
+using Content.Shared.Mobs.Systems;
 using Robust.Shared.Player;
 
 namespace Content.Server.KillTracking;
@@ -14,7 +15,8 @@ public sealed class KillTrackingSystem : EntitySystem
     /// <inheritdoc/>
     public override void Initialize()
     {
-        SubscribeLocalEvent<KillTrackerComponent, DamageChangedEvent>(OnDamageChanged);
+        // Add damage to LifetimeDamage before MobStateChangedEvent gets raised
+        SubscribeLocalEvent<KillTrackerComponent, DamageChangedEvent>(OnDamageChanged, before: [ typeof(MobThresholdSystem) ]);
         SubscribeLocalEvent<KillTrackerComponent, MobStateChangedEvent>(OnMobStateChanged);
     }
 
@@ -50,7 +52,7 @@ public sealed class KillTrackingSystem : EntitySystem
         var largestSource = GetLargestSource(component.LifetimeDamage);
         largestSource ??= killImpulse;
 
-        KillSource? killSource;
+        KillSource killSource;
         KillSource? assistSource = null;
 
         if (killImpulse is KillEnvironmentSource)
@@ -69,13 +71,13 @@ public sealed class KillTrackingSystem : EntitySystem
             killSource = killImpulse;
 
             // no assist is given to environmental kills
-            if (largestSource is not KillEnvironmentSource)
+            if (largestSource is not KillEnvironmentSource
+                && component.LifetimeDamage.TryGetValue(largestSource, out var largestDamage))
             {
-                // you have to do at least 50% of largest source's damage to get the assist.
-                if (component.LifetimeDamage[largestSource] >= component.LifetimeDamage[killSource] / 2)
-                {
+                var killDamage = component.LifetimeDamage.GetValueOrDefault(killSource);
+                // you have to do at least twice as much damage as the killing source to get the assist.
+                if (largestDamage >= killDamage / 2)
                     assistSource = largestSource;
-                }
             }
         }