From a2de32d4c46785fe0d32e5ed0476b046860f4f4e Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Fri, 30 Oct 2020 01:05:18 +0100 Subject: [PATCH] Make CloningSystem properly reset and not use static (#2448) --- .../Components/Medical/CloningPodComponent.cs | 16 +++++++++------- .../Medical/MedicalScannerComponent.cs | 11 ++++++++--- .../GameObjects/EntitySystems/CloningSystem.cs | 16 +++++++++++----- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs b/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs index b943f6cfc1..dd41fae7ba 100644 --- a/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs @@ -1,7 +1,5 @@ #nullable enable using System; -using System.Linq; -using System.Threading.Tasks; using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Observer; using Content.Server.GameObjects.Components.Power.ApcNetComponents; @@ -19,6 +17,7 @@ using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; @@ -76,12 +75,12 @@ namespace Content.Server.GameObjects.Components.Medical HandleGhostReturn); } - public void Update(float frametime) + public void Update(float frameTime) { if (_bodyContainer.ContainedEntity != null && Powered) { - _cloningProgress += frametime; + _cloningProgress += frameTime; _cloningProgress = MathHelper.Clamp(_cloningProgress, 0f, _cloningTime); } @@ -122,7 +121,9 @@ namespace Content.Server.GameObjects.Components.Medical private CloningPodBoundUserInterfaceState GetUserInterfaceState() { - return new CloningPodBoundUserInterfaceState(CloningSystem.getIdToUser(), _cloningProgress, + var idToUser = EntitySystem.Get().GetIdToUser(); + + return new CloningPodBoundUserInterfaceState(idToUser, _cloningProgress, (_status == CloningPodStatus.Cloning)); } @@ -152,11 +153,12 @@ namespace Content.Server.GameObjects.Components.Medical switch (message.Button) { case UiButton.Clone: - if (message.ScanId == null) return; + var cloningSystem = EntitySystem.Get(); + if (_bodyContainer.ContainedEntity != null || - !CloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind)) + !cloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind)) { return; } diff --git a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs index 33ce3f5c8b..5f395d2c36 100644 --- a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs @@ -20,6 +20,7 @@ using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; @@ -126,9 +127,12 @@ namespace Content.Server.GameObjects.Components.Medical return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, true); } + var cloningSystem = EntitySystem.Get(); + var scanned = _bodyContainer.ContainedEntity.TryGetComponent(out MindComponent? mindComponent) && + mindComponent.Mind != null && + cloningSystem.HasDnaScan(mindComponent.Mind); - return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, - CloningSystem.HasDnaScan(_bodyContainer.ContainedEntity.GetComponent().Mind)); + return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, scanned); } private void UpdateUserInterface() @@ -261,7 +265,8 @@ namespace Content.Server.GameObjects.Components.Medical if (_bodyContainer.ContainedEntity != null) { //TODO: Show a 'ERROR: Body is completely devoid of soul' if no Mind owns the entity. - CloningSystem.AddToDnaScans(_playerManager + var cloningSystem = EntitySystem.Get(); + cloningSystem.AddToDnaScans(_playerManager .GetPlayersBy(playerSession => { var mindOwnedMob = playerSession.ContentData()?.Mind?.OwnedEntity; diff --git a/Content.Server/GameObjects/EntitySystems/CloningSystem.cs b/Content.Server/GameObjects/EntitySystems/CloningSystem.cs index 5f4e9377b5..8be1900553 100644 --- a/Content.Server/GameObjects/EntitySystems/CloningSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/CloningSystem.cs @@ -2,11 +2,12 @@ using System.Linq; using Content.Server.GameObjects.Components.Medical; using Content.Server.Mobs; +using Content.Shared.GameTicking; using Robust.Shared.GameObjects.Systems; namespace Content.Server.GameObjects.EntitySystems { - internal sealed class CloningSystem : EntitySystem + internal sealed class CloningSystem : EntitySystem, IResettingEntitySystem { public override void Update(float frameTime) { @@ -16,9 +17,9 @@ namespace Content.Server.GameObjects.EntitySystems } } - public static Dictionary Minds = new Dictionary(); + public readonly Dictionary Minds = new Dictionary(); - public static void AddToDnaScans(Mind mind) + public void AddToDnaScans(Mind mind) { if (!Minds.ContainsValue(mind)) { @@ -26,14 +27,19 @@ namespace Content.Server.GameObjects.EntitySystems } } - public static bool HasDnaScan(Mind mind) + public bool HasDnaScan(Mind mind) { return Minds.ContainsValue(mind); } - public static Dictionary getIdToUser() + public Dictionary GetIdToUser() { return Minds.ToDictionary(m => m.Key, m => m.Value.CharacterName); } + + public void Reset() + { + Minds.Clear(); + } } }