DoAfter Refactor (#13225)
Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Threading;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Maps;
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Shared.Database;
|
||||
@@ -19,17 +18,10 @@ public sealed partial class ToolSystem
|
||||
{
|
||||
SubscribeLocalEvent<LatticeCuttingComponent, AfterInteractEvent>(OnLatticeCuttingAfterInteract);
|
||||
SubscribeLocalEvent<LatticeCuttingComponent, LatticeCuttingCompleteEvent>(OnLatticeCutComplete);
|
||||
SubscribeLocalEvent<LatticeCuttingComponent, LatticeCuttingCancelledEvent>(OnLatticeCutCancelled);
|
||||
}
|
||||
|
||||
private void OnLatticeCutCancelled(EntityUid uid, LatticeCuttingComponent component, LatticeCuttingCancelledEvent args)
|
||||
{
|
||||
component.CancelTokenSource = null;
|
||||
}
|
||||
|
||||
private void OnLatticeCutComplete(EntityUid uid, LatticeCuttingComponent component, LatticeCuttingCompleteEvent args)
|
||||
{
|
||||
component.CancelTokenSource = null;
|
||||
var gridUid = args.Coordinates.GetGridUid(EntityManager);
|
||||
if (gridUid == null)
|
||||
return;
|
||||
@@ -52,17 +44,14 @@ public sealed partial class ToolSystem
|
||||
if (args.Handled || !args.CanReach || args.Target != null)
|
||||
return;
|
||||
|
||||
if (TryCut(args.User, component, args.ClickLocation))
|
||||
if (TryCut(uid, args.User, component, args.ClickLocation))
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private bool TryCut(EntityUid user, LatticeCuttingComponent component, EntityCoordinates clickLocation)
|
||||
private bool TryCut(EntityUid toolEntity, EntityUid user, LatticeCuttingComponent component, EntityCoordinates clickLocation)
|
||||
{
|
||||
if (component.CancelTokenSource != null)
|
||||
return true;
|
||||
|
||||
ToolComponent? tool = null;
|
||||
if (component.ToolComponentNeeded && !TryComp<ToolComponent?>(component.Owner, out tool))
|
||||
if (component.ToolComponentNeeded && !TryComp<ToolComponent?>(toolEntity, out tool))
|
||||
return false;
|
||||
|
||||
if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid))
|
||||
@@ -82,17 +71,10 @@ public sealed partial class ToolSystem
|
||||
|| tile.IsBlockedTurf(true))
|
||||
return false;
|
||||
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
component.CancelTokenSource = tokenSource;
|
||||
var toolEvData = new ToolEventData(new LatticeCuttingCompleteEvent(clickLocation, user), targetEntity: toolEntity);
|
||||
|
||||
if (!UseTool(component.Owner, user, null, 0f, component.Delay, new[] {component.QualityNeeded},
|
||||
new LatticeCuttingCompleteEvent
|
||||
{
|
||||
Coordinates = clickLocation,
|
||||
User = user
|
||||
}, new LatticeCuttingCancelledEvent(), toolComponent: tool, doAfterEventTarget: component.Owner,
|
||||
cancelToken: tokenSource.Token))
|
||||
component.CancelTokenSource = null;
|
||||
if (!UseTool(toolEntity, user, null, component.Delay, new[] {component.QualityNeeded}, toolEvData, toolComponent: tool))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -101,10 +83,12 @@ public sealed partial class ToolSystem
|
||||
{
|
||||
public EntityCoordinates Coordinates;
|
||||
public EntityUid User;
|
||||
}
|
||||
|
||||
private sealed class LatticeCuttingCancelledEvent : EntityEventArgs
|
||||
{
|
||||
public LatticeCuttingCompleteEvent(EntityCoordinates coordinates, EntityUid user)
|
||||
{
|
||||
Coordinates = coordinates;
|
||||
User = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user