DoAfter Refactor (#13225)

Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
keronshb
2023-02-24 19:01:25 -05:00
committed by GitHub
parent 7a9baa79c2
commit 9ebb452a3c
129 changed files with 2624 additions and 4132 deletions

View File

@@ -19,17 +19,10 @@ public sealed partial class ToolSystem
{
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
SubscribeLocalEvent<TilePryingComponent, TilePryingCompleteEvent>(OnTilePryComplete);
SubscribeLocalEvent<TilePryingComponent, TilePryingCancelledEvent>(OnTilePryCancelled);
}
private void OnTilePryCancelled(EntityUid uid, TilePryingComponent component, TilePryingCancelledEvent args)
{
component.CancelToken = null;
}
private void OnTilePryComplete(EntityUid uid, TilePryingComponent component, TilePryingCompleteEvent args)
{
component.CancelToken = null;
var gridUid = args.Coordinates.GetGridUid(EntityManager);
if (!_mapManager.TryGetGrid(gridUid, out var grid))
{
@@ -45,18 +38,13 @@ public sealed partial class ToolSystem
{
if (args.Handled || !args.CanReach || (args.Target != null && !HasComp<PuddleComponent>(args.Target))) return;
if (TryPryTile(args.User, component, args.ClickLocation))
if (TryPryTile(uid, args.User, component, args.ClickLocation))
args.Handled = true;
}
private bool TryPryTile(EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
{
if (component.CancelToken != null)
{
return true;
}
if (!TryComp<ToolComponent?>(component.Owner, out var tool) && component.ToolComponentNeeded)
if (!TryComp<ToolComponent?>(toolEntity, out var tool) && component.ToolComponentNeeded)
return false;
if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid))
@@ -74,34 +62,22 @@ public sealed partial class ToolSystem
if (!tileDef.CanCrowbar)
return false;
var token = new CancellationTokenSource();
component.CancelToken = token;
var toolEvData = new ToolEventData(new TilePryingCompleteEvent(clickLocation), targetEntity:toolEntity);
bool success = UseTool(
component.Owner,
user,
null,
0f,
component.Delay,
new [] {component.QualityNeeded},
new TilePryingCompleteEvent
{
Coordinates = clickLocation,
},
new TilePryingCancelledEvent(),
toolComponent: tool,
doAfterEventTarget: component.Owner,
cancelToken: token.Token);
if (!success)
component.CancelToken = null;
if (!UseTool(toolEntity, user, null, component.Delay, new[] { component.QualityNeeded }, toolEvData, toolComponent: tool))
return false;
return true;
}
private sealed class TilePryingCompleteEvent : EntityEventArgs
{
public EntityCoordinates Coordinates { get; init; }
public readonly EntityCoordinates Coordinates;
public TilePryingCompleteEvent(EntityCoordinates coordinates)
{
Coordinates = coordinates;
}
}
private sealed class TilePryingCancelledEvent : EntityEventArgs