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