Tile prying do_after (#6341)

This commit is contained in:
metalgearsloth
2022-01-30 14:48:18 +11:00
committed by GitHub
parent d7275f5c6b
commit e8b95dd88a
4 changed files with 125 additions and 54 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Chemistry.EntitySystems;
@@ -11,6 +12,7 @@ using Content.Shared.Audio;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
@@ -18,6 +20,8 @@ namespace Content.Server.Tools
{
public partial class ToolSystem : EntitySystem
{
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
@@ -30,6 +34,7 @@ namespace Content.Server.Tools
{
base.Initialize();
InitializeTilePrying();
InitializeWelders();
InitializeMultipleTools();
@@ -94,14 +99,24 @@ namespace Content.Server.Tools
/// <param name="doAfterEventTarget">Where to direct the do-after events. If null, events are broadcast</param>
/// <param name="doAfterCheck">An optional check to perform for the doAfter.</param>
/// <param name="toolComponent">The tool component.</param>
/// <param name="cancelToken">Token to provide to do_after for cancelling</param>
/// <returns>Whether initially, using the tool succeeded. If there's a doAfter delay, you'll need to listen to
/// the <see cref="doAfterCompleteEvent"/> and <see cref="doAfterCancelledEvent"/> being broadcast
/// to see whether using the tool succeeded or not. If the <see cref="doAfterDelay"/> is zero,
/// this simply returns whether using the tool succeeded or not.</returns>
public bool UseTool(EntityUid tool, EntityUid user, EntityUid? target, float fuel,
float doAfterDelay, IEnumerable<string> toolQualitiesNeeded,
object? doAfterCompleteEvent = null, object? doAfterCancelledEvent = null, EntityUid? doAfterEventTarget = null,
Func<bool>? doAfterCheck = null, ToolComponent? toolComponent = null)
public bool UseTool(
EntityUid tool,
EntityUid user,
EntityUid? target,
float fuel,
float doAfterDelay,
IEnumerable<string> toolQualitiesNeeded,
object? doAfterCompleteEvent = null,
object? doAfterCancelledEvent = null,
EntityUid? doAfterEventTarget = null,
Func<bool>? doAfterCheck = null,
ToolComponent? toolComponent = null,
CancellationToken? cancelToken = null)
{
// No logging here, after all that'd mean the caller would need to check if the component is there or not.
if (!Resolve(tool, ref toolComponent, false))
@@ -112,7 +127,7 @@ namespace Content.Server.Tools
if (doAfterDelay > 0f)
{
var doAfterArgs = new DoAfterEventArgs(user, doAfterDelay / toolComponent.SpeedModifier, default, target)
var doAfterArgs = new DoAfterEventArgs(user, doAfterDelay / toolComponent.SpeedModifier, cancelToken ?? default, target)
{
ExtraCheck = doAfterCheck,
BreakOnDamage = true,