From: Chronophylos Date: Sat, 2 Dec 2023 17:00:31 +0000 (+0100) Subject: Refactor NPCRetaliationSystem::Update to fix crash caused by Debug Assertion (#21785) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=b8ded78305f093bf574e811ad4797e18a758b179;p=space-station-14.git Refactor NPCRetaliationSystem::Update to fix crash caused by Debug Assertion (#21785) * refactor names for clarity * remove check adding entity to deaggro queue twice * merge loops * remove unused queue * add back check for terminating or deleted entities * trigger workflow --- diff --git a/Content.Server/NPC/Systems/NPCRetaliationSystem.cs b/Content.Server/NPC/Systems/NPCRetaliationSystem.cs index a8bf1766f0..cde8decefc 100644 --- a/Content.Server/NPC/Systems/NPCRetaliationSystem.cs +++ b/Content.Server/NPC/Systems/NPCRetaliationSystem.cs @@ -8,16 +8,14 @@ using Robust.Shared.Timing; namespace Content.Server.NPC.Systems; /// -/// Handles NPC which become aggressive after being attacked. +/// Handles NPC which become aggressive after being attacked. /// public sealed class NPCRetaliationSystem : EntitySystem { - [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly NpcFactionSystem _npcFaction = default!; + [Dependency] private readonly IGameTiming _timing = default!; - private readonly HashSet _deAggroQueue = new(); - - /// + /// public override void Initialize() { SubscribeLocalEvent(OnDamageChanged); @@ -54,9 +52,7 @@ public sealed class NPCRetaliationSystem : EntitySystem _npcFaction.AggroEntity(uid, target); if (component.AttackMemoryLength is { } memoryLength) - { component.AttackMemories[target] = _timing.CurTime + memoryLength; - } return true; } @@ -65,25 +61,15 @@ public sealed class NPCRetaliationSystem : EntitySystem { base.Update(frameTime); - var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var comp, out var factionException, out var metaData)) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var retaliationComponent, out var factionException)) { - _deAggroQueue.Clear(); - - foreach (var ent in new ValueList(comp.AttackMemories.Keys)) + foreach (var entity in new ValueList(retaliationComponent.AttackMemories.Keys)) { - if (_timing.CurTime < comp.AttackMemories[ent]) + if (!TerminatingOrDeleted(entity) && _timing.CurTime < retaliationComponent.AttackMemories[entity]) continue; - if (TerminatingOrDeleted(ent, metaData)) - _deAggroQueue.Add(ent); - - _deAggroQueue.Add(ent); - } - - foreach (var ent in _deAggroQueue) - { - _npcFaction.DeAggroEntity(uid, ent, factionException); + _npcFaction.DeAggroEntity(uid, entity, factionException); } } }