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
This commit is contained in:
@@ -61,9 +61,6 @@ namespace Content.Server.GameObjects.Components.Disposal
|
|||||||
|
|
||||||
private bool _engaged;
|
private bool _engaged;
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
private TimeSpan _engageTime;
|
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private TimeSpan _automaticEngageTime;
|
private TimeSpan _automaticEngageTime;
|
||||||
|
|
||||||
@@ -131,11 +128,27 @@ namespace Content.Server.GameObjects.Components.Disposal
|
|||||||
return _container.CanInsert(entity);
|
return _container.CanInsert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AfterInsert(IEntity entity)
|
private void TryQueueEngage()
|
||||||
{
|
{
|
||||||
|
if (!Powered && ContainedEntities.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_automaticEngageToken = new CancellationTokenSource();
|
_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))
|
if (entity.TryGetComponent(out IActorComponent actor))
|
||||||
{
|
{
|
||||||
@@ -404,7 +417,18 @@ namespace Content.Server.GameObjects.Components.Disposal
|
|||||||
|
|
||||||
private void PowerStateChanged(object? sender, PowerStateEventArgs args)
|
private void PowerStateChanged(object? sender, PowerStateEventArgs args)
|
||||||
{
|
{
|
||||||
|
if (!args.Powered)
|
||||||
|
{
|
||||||
|
_automaticEngageToken?.Cancel();
|
||||||
|
_automaticEngageToken = null;
|
||||||
|
}
|
||||||
|
|
||||||
UpdateVisualState();
|
UpdateVisualState();
|
||||||
|
|
||||||
|
if (Engaged && !TryFlush())
|
||||||
|
{
|
||||||
|
TryQueueEngage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
@@ -418,10 +442,10 @@ namespace Content.Server.GameObjects.Components.Disposal
|
|||||||
() => _pressure);
|
() => _pressure);
|
||||||
|
|
||||||
serializer.DataReadWriteFunction(
|
serializer.DataReadWriteFunction(
|
||||||
"engageTime",
|
"automaticEngageTime",
|
||||||
2,
|
30,
|
||||||
seconds => _engageTime = TimeSpan.FromSeconds(seconds),
|
seconds => _automaticEngageTime = TimeSpan.FromSeconds(seconds),
|
||||||
() => (int) _engageTime.TotalSeconds);
|
() => (int) _automaticEngageTime.TotalSeconds);
|
||||||
|
|
||||||
serializer.DataReadWriteFunction(
|
serializer.DataReadWriteFunction(
|
||||||
"automaticEngageTime",
|
"automaticEngageTime",
|
||||||
@@ -493,8 +517,8 @@ namespace Content.Server.GameObjects.Components.Disposal
|
|||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case RelayMovementEntityMessage msg:
|
case RelayMovementEntityMessage msg:
|
||||||
if (Engaged ||
|
if (!msg.Entity.TryGetComponent(out HandsComponent hands) ||
|
||||||
!msg.Entity.HasComponent<HandsComponent>() ||
|
hands.Count == 0 ||
|
||||||
_gameTiming.CurTime < _lastExitAttempt + ExitAttemptDelay)
|
_gameTiming.CurTime < _lastExitAttempt + ExitAttemptDelay)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user