diff --git a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs index 5148071820..f85e7b64ea 100644 --- a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs @@ -162,6 +162,7 @@ namespace Content.Server.GameObjects.Components.Interactable if (_pointLightComponent != null) _pointLightComponent.Enabled = false; PlaySoundCollection("WelderOff", -5); + _welderSystem.Unsubscribe(this); return true; } @@ -178,6 +179,7 @@ namespace Content.Server.GameObjects.Components.Interactable if (_pointLightComponent != null) _pointLightComponent.Enabled = true; PlaySoundCollection("WelderOn", -5); + _welderSystem.Subscribe(this); Owner.Transform.GridPosition .GetTileAtmosphere()?.HotspotExpose(700f, 50f, true); @@ -208,9 +210,15 @@ namespace Content.Server.GameObjects.Components.Interactable } } + protected override void Shutdown() + { + base.Shutdown(); + _welderSystem.Unsubscribe(this); + } + public void OnUpdate(float frameTime) { - if (!HasQuality(ToolQuality.Welding) || !WelderLit) + if (!HasQuality(ToolQuality.Welding) || !WelderLit || Owner.Deleted) return; _solutionComponent?.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime)); diff --git a/Content.Server/GameObjects/EntitySystems/WelderSystem.cs b/Content.Server/GameObjects/EntitySystems/WelderSystem.cs index d8b9081e2a..411e3546fc 100644 --- a/Content.Server/GameObjects/EntitySystems/WelderSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/WelderSystem.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using Content.Server.GameObjects.Components.Interactable; -using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; namespace Content.Server.GameObjects.EntitySystems @@ -11,12 +10,23 @@ namespace Content.Server.GameObjects.EntitySystems /// public class WelderSystem : EntitySystem { + private readonly HashSet _activeWelders = new HashSet(); + + public bool Subscribe(WelderComponent welder) + { + return _activeWelders.Add(welder); + } + + public bool Unsubscribe(WelderComponent welder) + { + return _activeWelders.Remove(welder); + } + public override void Update(float frameTime) { - foreach (var welder in EntityManager.ComponentManager.EntityQuery()) + foreach (var tool in _activeWelders.ToArray()) { - if(welder.WelderLit && !welder.Owner.Deleted) - welder.OnUpdate(frameTime); + tool.OnUpdate(frameTime); } } }