From 808791f498f79005d74c36b7c3cdd05563fd7a84 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sat, 1 Aug 2020 14:10:24 +0200 Subject: [PATCH] Fix disposal unit power issues (#1564) * Fix being forever eaten by an unpowered unit * Add 0 hands check to getting out of an unit * Add engage check when the power is changed * Remove redundant serializable field * Add queueing an autoengage when power is turned back on, the unit is engaged and it doesnt flush with items inside * Make TryQueueEngage check for no contained entities * Remove redundant check * Fix flushing animation not being played when powering an engaged unit --- .../Disposal/DisposalUnitComponent.cs | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 31f1c56c7d..c4c86b38bb 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -61,9 +61,6 @@ namespace Content.Server.GameObjects.Components.Disposal private bool _engaged; - [ViewVariables] - private TimeSpan _engageTime; - [ViewVariables] private TimeSpan _automaticEngageTime; @@ -131,11 +128,27 @@ namespace Content.Server.GameObjects.Components.Disposal return _container.CanInsert(entity); } - private void AfterInsert(IEntity entity) + private void TryQueueEngage() { + if (!Powered && ContainedEntities.Count == 0) + { + return; + } + _automaticEngageToken = new CancellationTokenSource(); - Timer.Spawn(_automaticEngageTime, () => TryFlush(), _automaticEngageToken.Token); + Timer.Spawn(_automaticEngageTime, () => + { + if (!TryFlush()) + { + TryQueueEngage(); + } + }, _automaticEngageToken.Token); + } + + private void AfterInsert(IEntity entity) + { + TryQueueEngage(); if (entity.TryGetComponent(out IActorComponent actor)) { @@ -404,7 +417,18 @@ namespace Content.Server.GameObjects.Components.Disposal private void PowerStateChanged(object? sender, PowerStateEventArgs args) { + if (!args.Powered) + { + _automaticEngageToken?.Cancel(); + _automaticEngageToken = null; + } + UpdateVisualState(); + + if (Engaged && !TryFlush()) + { + TryQueueEngage(); + } } public override void ExposeData(ObjectSerializer serializer) @@ -418,10 +442,10 @@ namespace Content.Server.GameObjects.Components.Disposal () => _pressure); serializer.DataReadWriteFunction( - "engageTime", - 2, - seconds => _engageTime = TimeSpan.FromSeconds(seconds), - () => (int) _engageTime.TotalSeconds); + "automaticEngageTime", + 30, + seconds => _automaticEngageTime = TimeSpan.FromSeconds(seconds), + () => (int) _automaticEngageTime.TotalSeconds); serializer.DataReadWriteFunction( "automaticEngageTime", @@ -493,8 +517,8 @@ namespace Content.Server.GameObjects.Components.Disposal switch (message) { case RelayMovementEntityMessage msg: - if (Engaged || - !msg.Entity.HasComponent() || + if (!msg.Entity.TryGetComponent(out HandsComponent hands) || + hands.Count == 0 || _gameTiming.CurTime < _lastExitAttempt + ExitAttemptDelay) { break;