Another round of DoAfter fixes (#14295)
This commit is contained in:
@@ -88,7 +88,7 @@ namespace Content.IntegrationTests.Tests.DoAfter
|
||||
});
|
||||
|
||||
await server.WaitRunTicks(3);
|
||||
Assert.That(data.Cancelled, Is.False);
|
||||
Assert.That(data.Cancelled, Is.True);
|
||||
|
||||
await pairTracker.CleanReturnAsync();
|
||||
}
|
||||
|
||||
@@ -582,6 +582,7 @@ namespace Content.Server.Construction
|
||||
{
|
||||
RaiseLocalEvent(args.Args.Target.Value, args.AdditionalData.CancelEvent);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
RaiseLocalEvent(args.Args.Target.Value, args.AdditionalData.CompleteEvent);
|
||||
|
||||
@@ -270,7 +270,17 @@ public sealed class MoppingSystem : SharedMoppingSystem
|
||||
|
||||
private void OnDoAfter(EntityUid uid, AbsorbentComponent component, DoAfterEvent<AbsorbantData> args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null)
|
||||
if (args.Args.Target == null)
|
||||
return;
|
||||
|
||||
if (args.Cancelled)
|
||||
{
|
||||
//Remove the interacting entities or else it breaks the mop
|
||||
component.InteractingEntities.Remove(args.Args.Target.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
_audio.PlayPvs(args.AdditionalData.Sound, uid);
|
||||
|
||||
@@ -77,12 +77,19 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
if (TryComp<ButcherableComponent>(args.Args.Target.Value, out var butcherable))
|
||||
butcherable.BeingButchered = false;
|
||||
|
||||
if (args.Handled || args.Cancelled)
|
||||
if (args.Cancelled)
|
||||
{
|
||||
component.InUse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (Spikeable(uid, args.Args.User, args.Args.Target.Value, component, butcherable))
|
||||
Spike(uid, args.Args.User, args.Args.Target.Value, component);
|
||||
|
||||
component.InUse = false;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Resist;
|
||||
|
||||
[RegisterComponent]
|
||||
@@ -8,4 +10,9 @@ public sealed class CanEscapeInventoryComponent : Component
|
||||
/// </summary>
|
||||
[DataField("baseResistTime")]
|
||||
public float BaseResistTime = 5f;
|
||||
|
||||
[DataField("isEscaping")]
|
||||
public bool IsEscaping;
|
||||
|
||||
public CancellationTokenSource? CancelToken;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -18,8 +18,5 @@ public sealed class ResistLockerComponent : Component
|
||||
[ViewVariables]
|
||||
public bool IsResisting = false;
|
||||
|
||||
/// <summary>
|
||||
/// Used to cancel the DoAfter when a locker is open
|
||||
/// </summary>
|
||||
public Shared.DoAfter.DoAfter? DoAfter;
|
||||
public CancellationTokenSource? CancelToken;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Threading;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Storage.Components;
|
||||
@@ -44,7 +45,9 @@ public sealed class ResistLockerSystem : EntitySystem
|
||||
if (!Resolve(target, ref storageComponent, ref resistLockerComponent))
|
||||
return;
|
||||
|
||||
var doAfterEventArgs = new DoAfterEventArgs(user, resistLockerComponent.ResistTime, target:target)
|
||||
resistLockerComponent.CancelToken = new CancellationTokenSource();
|
||||
|
||||
var doAfterEventArgs = new DoAfterEventArgs(user, resistLockerComponent.ResistTime, cancelToken:resistLockerComponent.CancelToken.Token, target:target)
|
||||
{
|
||||
BreakOnTargetMove = false,
|
||||
BreakOnUserMove = true,
|
||||
@@ -55,13 +58,13 @@ public sealed class ResistLockerSystem : EntitySystem
|
||||
|
||||
resistLockerComponent.IsResisting = true;
|
||||
_popupSystem.PopupEntity(Loc.GetString("resist-locker-component-start-resisting"), user, user, PopupType.Large);
|
||||
resistLockerComponent.DoAfter = _doAfterSystem.DoAfter(doAfterEventArgs);
|
||||
_doAfterSystem.DoAfter(doAfterEventArgs);
|
||||
}
|
||||
|
||||
private void OnRemoved(EntityUid uid, ResistLockerComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (component.DoAfter != null)
|
||||
_doAfterSystem.Cancel(uid, component.DoAfter);
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = null;
|
||||
}
|
||||
|
||||
private void OnDoAfter(EntityUid uid, ResistLockerComponent component, DoAfterEvent args)
|
||||
@@ -69,6 +72,7 @@ public sealed class ResistLockerSystem : EntitySystem
|
||||
if (args.Cancelled)
|
||||
{
|
||||
component.IsResisting = false;
|
||||
component.CancelToken = null;
|
||||
_popupSystem.PopupEntity(Loc.GetString("resist-locker-component-resist-interrupted"), args.Args.User, args.Args.User, PopupType.Medium);
|
||||
return;
|
||||
}
|
||||
@@ -89,6 +93,7 @@ public sealed class ResistLockerSystem : EntitySystem
|
||||
_entityStorage.TryOpenStorage(args.Args.User, uid);
|
||||
}
|
||||
|
||||
component.CancelToken = null;
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ public sealed class WiresSystem : EntitySystem
|
||||
}
|
||||
else if (!component.IsScrewing && _toolSystem.HasQuality(args.Used, "Screwing", tool))
|
||||
{
|
||||
var toolEvData = new ToolEventData(new WireToolFinishedEvent(uid, args.User));
|
||||
var toolEvData = new ToolEventData(new WireToolFinishedEvent(uid, args.User), cancelledEv: new WireToolCanceledEvent(uid));
|
||||
|
||||
component.IsScrewing = _toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, new[] { "Screwing" }, toolEvData, toolComponent: tool);
|
||||
args.Handled = component.IsScrewing;
|
||||
|
||||
@@ -179,19 +179,16 @@ public abstract class SharedDoAfterSystem : EntitySystem
|
||||
/// Use this if you don't have any extra data to send with the DoAfter
|
||||
/// </summary>
|
||||
/// <param name="eventArgs">The DoAfterEventArgs</param>
|
||||
public DoAfter DoAfter(DoAfterEventArgs eventArgs)
|
||||
public void DoAfter(DoAfterEventArgs eventArgs)
|
||||
{
|
||||
var doAfter = CreateDoAfter(eventArgs);
|
||||
|
||||
doAfter.Done = cancelled => { Send(cancelled, eventArgs); };
|
||||
|
||||
return doAfter;
|
||||
}
|
||||
|
||||
private DoAfter CreateDoAfter(DoAfterEventArgs eventArgs)
|
||||
{
|
||||
// Setup
|
||||
eventArgs.CancelToken = new CancellationToken();
|
||||
var doAfter = new DoAfter(eventArgs, EntityManager);
|
||||
// Caller's gonna be responsible for this I guess
|
||||
var doAfterComponent = Comp<DoAfterComponent>(eventArgs.User);
|
||||
|
||||
Reference in New Issue
Block a user