Another round of DoAfter fixes (#14295)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Threading;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Contests;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -65,11 +66,16 @@ public sealed class EscapeInventorySystem : EntitySystem
|
||||
|
||||
private void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component, float multiplier = 1f)
|
||||
{
|
||||
if (component.IsEscaping)
|
||||
return;
|
||||
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
component.IsEscaping = true;
|
||||
var escapeEvent = new EscapeInventoryEvent();
|
||||
var doAfterEventArgs = new DoAfterEventArgs(user, component.BaseResistTime * multiplier, target:container)
|
||||
var doAfterEventArgs = new DoAfterEventArgs(user, component.BaseResistTime * multiplier, cancelToken: component.CancelToken.Token, target:container)
|
||||
{
|
||||
BreakOnTargetMove = false,
|
||||
BreakOnUserMove = false,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
NeedHand = false
|
||||
@@ -82,17 +88,27 @@ public sealed class EscapeInventorySystem : EntitySystem
|
||||
|
||||
private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, DoAfterEvent<EscapeInventoryEvent> args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled)
|
||||
if (args.Cancelled)
|
||||
{
|
||||
component.CancelToken = null;
|
||||
component.IsEscaping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
Transform(uid).AttachParentToContainerOrGrid(EntityManager);
|
||||
|
||||
component.CancelToken = null;
|
||||
component.IsEscaping = false;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, DroppedEvent args)
|
||||
{
|
||||
//TODO: Enter cancel logic here
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = null;
|
||||
}
|
||||
|
||||
private sealed class EscapeInventoryEvent : EntityEventArgs
|
||||
|
||||
Reference in New Issue
Block a user