From c3df5c3882bd6c2a4ca157e21a66915b9f5e84bb Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Fri, 23 Oct 2020 01:33:27 -0700 Subject: [PATCH] Fix exiting med scanner (#2365) * Reorganize fields and properties * Add exit on move to MedicalScanner * Fix crash when MedicalScanner contains an entity Fixes #2331 --- .../Medical/MedicalScannerComponent.cs | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs index 505712ad94..33ce3f5c8b 100644 --- a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Content.Server.GameObjects.Components.Body; using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; @@ -22,6 +21,7 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; @@ -32,18 +32,23 @@ namespace Content.Server.GameObjects.Components.Medical [RegisterComponent] [ComponentReference(typeof(IActivate))] [ComponentReference(typeof(SharedMedicalScannerComponent))] - public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDragDropOn + public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDragDropOn, IDestroyAct { - private ContainerSlot _bodyContainer = default!; - private readonly Vector2 _ejectOffset = new Vector2(-0.5f, 0f); - + [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IPlayerManager _playerManager = null!; - public bool IsOccupied => _bodyContainer.ContainedEntity != null; + + private static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5); + private TimeSpan _lastInternalOpenAttempt; + + private ContainerSlot _bodyContainer = default!; + private readonly Vector2 _ejectOffset = new Vector2(0f, 0f); [ViewVariables] private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; + [ViewVariables] + private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MedicalScannerUiKey.Key); - [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MedicalScannerUiKey.Key); + public bool IsOccupied => _bodyContainer.ContainedEntity != null; public override void Initialize() { @@ -63,6 +68,31 @@ namespace Content.Server.GameObjects.Components.Medical UpdateUserInterface(); } + /// + public override void HandleMessage(ComponentMessage message, IComponent? component) + { + base.HandleMessage(message, component); + + switch (message) + { + case RelayMovementEntityMessage msg: + { + if (ActionBlockerSystem.CanInteract(msg.Entity)) + { + if (_gameTiming.CurTime < + _lastInternalOpenAttempt + InternalOpenAttemptDelay) + { + break; + } + + _lastInternalOpenAttempt = _gameTiming.CurTime; + EjectBody(); + } + break; + } + } + } + private static readonly MedicalScannerBoundUserInterfaceState EmptyUIState = new MedicalScannerBoundUserInterfaceState( null, @@ -259,5 +289,10 @@ namespace Content.Server.GameObjects.Components.Medical _bodyContainer.Insert(eventArgs.Dragged); return true; } + + void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs) + { + EjectBody(); + } } }