Fix exiting med scanner (#2365)

* Reorganize fields and properties

* Add exit on move to MedicalScanner

* Fix crash when MedicalScanner contains an entity

Fixes #2331
This commit is contained in:
ShadowCommander
2020-10-23 01:33:27 -07:00
committed by GitHub
parent bae8816c44
commit c3df5c3882

View File

@@ -2,7 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Body;
using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
@@ -22,6 +21,7 @@ using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player; using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths; using Robust.Shared.Maths;
@@ -32,18 +32,23 @@ namespace Content.Server.GameObjects.Components.Medical
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(SharedMedicalScannerComponent))] [ComponentReference(typeof(SharedMedicalScannerComponent))]
public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDragDropOn public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDragDropOn, IDestroyAct
{ {
private ContainerSlot _bodyContainer = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
private readonly Vector2 _ejectOffset = new Vector2(-0.5f, 0f);
[Dependency] private readonly IPlayerManager _playerManager = null!; [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] [ViewVariables]
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; 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() public override void Initialize()
{ {
@@ -63,6 +68,31 @@ namespace Content.Server.GameObjects.Components.Medical
UpdateUserInterface(); UpdateUserInterface();
} }
/// <inheritdoc />
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 = private static readonly MedicalScannerBoundUserInterfaceState EmptyUIState =
new MedicalScannerBoundUserInterfaceState( new MedicalScannerBoundUserInterfaceState(
null, null,
@@ -259,5 +289,10 @@ namespace Content.Server.GameObjects.Components.Medical
_bodyContainer.Insert(eventArgs.Dragged); _bodyContainer.Insert(eventArgs.Dragged);
return true; return true;
} }
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
EjectBody();
}
} }
} }