diff --git a/Content.Server/Cloning/CloningConsoleSystem.cs b/Content.Server/Cloning/CloningConsoleSystem.cs index c124dfc3d6..a2cb0adf98 100644 --- a/Content.Server/Cloning/CloningConsoleSystem.cs +++ b/Content.Server/Cloning/CloningConsoleSystem.cs @@ -1,6 +1,8 @@ +using System.Linq; using JetBrains.Annotations; using Content.Server.Medical.Components; using Content.Server.Cloning.Components; +using Content.Server.MachineLinking.Components; using Content.Server.Power.Components; using Content.Server.Mind.Components; using Content.Server.MachineLinking.System; @@ -34,6 +36,7 @@ namespace Content.Server.Cloning SubscribeLocalEvent(OnButtonPressed); SubscribeLocalEvent(OnUIOpen); SubscribeLocalEvent(OnPowerChanged); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnNewLink); SubscribeLocalEvent(OnPortDisconnected); SubscribeLocalEvent(OnAnchorChanged); @@ -63,6 +66,27 @@ namespace Content.Server.Cloning UpdateUserInterface(component); } + private void OnMapInit(EntityUid uid, CloningConsoleComponent component, MapInitEvent args) + { + if (!TryComp(uid, out var receiver)) + return; + + foreach (var port in receiver.Outputs.Values.SelectMany(ports => ports)) + { + if (TryComp(port.Uid, out var scanner)) + { + component.GeneticScanner = port.Uid; + scanner.ConnectedConsole = uid; + } + + if (TryComp(port.Uid, out var pod)) + { + component.CloningPod = port.Uid; + pod.ConnectedConsole = uid; + } + } + } + private void OnNewLink(EntityUid uid, CloningConsoleComponent component, NewLinkEvent args) { if (TryComp(args.Receiver, out var scanner) && args.TransmitterPort == CloningConsoleComponent.ScannerPort) @@ -107,15 +131,17 @@ namespace Content.Server.Cloning public void UpdateUserInterface(CloningConsoleComponent consoleComponent) { + var ui = _uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key); + if (ui == null) + return; if (!_powerReceiverSystem.IsPowered(consoleComponent.Owner)) { - _uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key)?.CloseAll(); + _uiSystem.CloseAll(ui); return; } var newState = GetUserInterfaceState(consoleComponent); - - _uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key)?.SetState(newState); + _uiSystem.SetUiState(ui, newState); } public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent? cloningPod = null, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null) @@ -171,8 +197,8 @@ namespace Content.Server.Cloning string scanBodyInfo = Loc.GetString("generic-unknown"); bool scannerConnected = false; bool scannerInRange = consoleComponent.GeneticScannerInRange; - if (consoleComponent.GeneticScanner != null && TryComp(consoleComponent.GeneticScanner, out var scanner)) { - + if (consoleComponent.GeneticScanner != null && TryComp(consoleComponent.GeneticScanner, out var scanner)) + { scannerConnected = true; EntityUid? scanBody = scanner.BodyContainer.ContainedEntity; @@ -191,7 +217,7 @@ namespace Content.Server.Cloning } else { - if (mindComp == null || mindComp.Mind == null || mindComp.Mind.UserId == null || !_playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out var client)) + if (mindComp == null || mindComp.Mind == null || mindComp.Mind.UserId == null || !_playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out _)) { clonerStatus = ClonerStatus.NoMindDetected; }