Tile prying do_after (#6341)
This commit is contained in:
@@ -1,61 +1,30 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Maps;
|
||||
using System.Threading;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Tools.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class TilePryingComponent : Component, IAfterInteract
|
||||
[RegisterComponent, ComponentProtoName("TilePrying")]
|
||||
public sealed class TilePryingComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public override string Name => "TilePrying";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("toolComponentNeeded")]
|
||||
private bool _toolComponentNeeded = true;
|
||||
public bool ToolComponentNeeded = true;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
private string _qualityNeeded = "Prying";
|
||||
public string QualityNeeded = "Prying";
|
||||
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
TryPryTile(eventArgs.User, eventArgs.ClickLocation);
|
||||
return true;
|
||||
}
|
||||
[ViewVariables]
|
||||
[DataField("delay")]
|
||||
public float Delay = 1f;
|
||||
|
||||
public async void TryPryTile(EntityUid user, EntityCoordinates clickLocation)
|
||||
{
|
||||
if (!_entMan.TryGetComponent<ToolComponent?>(Owner, out var tool) && _toolComponentNeeded)
|
||||
return;
|
||||
|
||||
if (!_mapManager.TryGetGrid(clickLocation.GetGridId(_entMan), out var mapGrid))
|
||||
return;
|
||||
|
||||
var tile = mapGrid.GetTileRef(clickLocation);
|
||||
|
||||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
||||
|
||||
if (!user.InRangeUnobstructed(coordinates, popup: false))
|
||||
return;
|
||||
|
||||
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
if (!tileDef.CanCrowbar)
|
||||
return;
|
||||
|
||||
if (_toolComponentNeeded && !await EntitySystem.Get<ToolSystem>().UseTool(Owner, user, null, 0f, 0f, _qualityNeeded, toolComponent:tool))
|
||||
return;
|
||||
|
||||
coordinates.PryTile(_entMan, _mapManager);
|
||||
}
|
||||
/// <summary>
|
||||
/// Used for do_afters.
|
||||
/// </summary>
|
||||
public CancellationTokenSource? CancelToken = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user