Add do_after to TryInsert (#1938)
Add delay to flushing Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.GameObjects.EntitySystems.DoAfter;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Items;
|
||||
using Content.Server.Utility;
|
||||
@@ -68,6 +69,12 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
[ViewVariables]
|
||||
private TimeSpan _automaticEngageTime;
|
||||
|
||||
[ViewVariables]
|
||||
private TimeSpan _flushDelay;
|
||||
|
||||
[ViewVariables]
|
||||
private float _entryDelay;
|
||||
|
||||
/// <summary>
|
||||
/// Token used to cancel the automatic engage of a disposal unit
|
||||
/// after an entity enters it.
|
||||
@@ -174,13 +181,34 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
UpdateVisualState();
|
||||
}
|
||||
|
||||
public bool TryInsert(IEntity entity)
|
||||
public async Task<bool> TryInsert(IEntity entity, IEntity? user = default)
|
||||
{
|
||||
if (!CanInsert(entity) || !_container.Insert(entity))
|
||||
{
|
||||
if (!CanInsert(entity))
|
||||
return false;
|
||||
|
||||
if (user != null && _entryDelay > 0f)
|
||||
{
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
|
||||
var doAfterArgs = new DoAfterEventArgs(user, _entryDelay, default, Owner)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = false,
|
||||
};
|
||||
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
|
||||
if (result == DoAfterStatus.Cancelled)
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (!_container.Insert(entity))
|
||||
return false;
|
||||
|
||||
AfterInsert(entity);
|
||||
|
||||
return true;
|
||||
@@ -225,9 +253,9 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
{
|
||||
Engaged ^= true;
|
||||
|
||||
if (Engaged)
|
||||
if (Engaged && CanFlush())
|
||||
{
|
||||
TryFlush();
|
||||
Timer.Spawn(_flushDelay, () => TryFlush());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,10 +515,16 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
() => (int) _automaticEngageTime.TotalSeconds);
|
||||
|
||||
serializer.DataReadWriteFunction(
|
||||
"automaticEngageTime",
|
||||
30,
|
||||
seconds => _automaticEngageTime = TimeSpan.FromSeconds(seconds),
|
||||
() => (int) _automaticEngageTime.TotalSeconds);
|
||||
"flushDelay",
|
||||
3,
|
||||
seconds => _flushDelay = TimeSpan.FromSeconds(seconds),
|
||||
() => (int) _flushDelay.TotalSeconds);
|
||||
|
||||
serializer.DataReadWriteFunction(
|
||||
"entryDelay",
|
||||
0.5f,
|
||||
seconds => _entryDelay = seconds,
|
||||
() => (int) _entryDelay);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -620,7 +654,8 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
|
||||
bool IDragDropOn.DragDropOn(DragDropEventArgs eventArgs)
|
||||
{
|
||||
return TryInsert(eventArgs.Dropped);
|
||||
_ = TryInsert(eventArgs.Dropped, eventArgs.User);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Verb]
|
||||
@@ -642,7 +677,7 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
|
||||
protected override void Activate(IEntity user, DisposalUnitComponent component)
|
||||
{
|
||||
component.TryInsert(user);
|
||||
_ = component.TryInsert(user, user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user