2021-06-09 22:19:39 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
using Content.Shared.Maps;
|
2021-10-07 13:01:27 +02:00
|
|
|
|
using Content.Shared.Tools;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Map;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-10-07 13:01:27 +02:00
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Tools.Components
|
2020-05-20 10:55:17 +02:00
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
2020-05-24 13:47:13 +02:00
|
|
|
|
public class TilePryingComponent : Component, IAfterInteract
|
2020-05-20 10:55:17 +02:00
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
|
|
|
|
|
|
public override string Name => "TilePrying";
|
2021-10-07 13:01:27 +02:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("toolComponentNeeded")]
|
2020-05-20 10:55:17 +02:00
|
|
|
|
private bool _toolComponentNeeded = true;
|
|
|
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
|
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
|
|
|
|
|
private string _qualityNeeded = "Prying";
|
|
|
|
|
|
|
2021-02-04 17:50:28 +01:00
|
|
|
|
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
2020-05-20 10:55:17 +02:00
|
|
|
|
{
|
|
|
|
|
|
TryPryTile(eventArgs.User, eventArgs.ClickLocation);
|
2021-02-03 14:05:31 +01:00
|
|
|
|
return true;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
public async void TryPryTile(EntityUid user, EntityCoordinates clickLocation)
|
2020-05-20 10:55:17 +02:00
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
|
if (!_entMan.TryGetComponent<ToolComponent?>(Owner, out var tool) && _toolComponentNeeded)
|
2020-05-20 10:55:17 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
|
if (!_mapManager.TryGetGrid(clickLocation.GetGridId(_entMan), out var mapGrid))
|
2020-10-21 17:13:41 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-05-20 10:55:17 +02:00
|
|
|
|
var tile = mapGrid.GetTileRef(clickLocation);
|
|
|
|
|
|
|
|
|
|
|
|
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
|
|
|
|
|
|
2020-09-06 19:08:04 +02:00
|
|
|
|
if (!user.InRangeUnobstructed(coordinates, popup: false))
|
2020-05-20 10:55:17 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
|
|
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
|
if (!tileDef.CanCrowbar)
|
|
|
|
|
|
return;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
|
if (_toolComponentNeeded && !await EntitySystem.Get<ToolSystem>().UseTool(Owner, user, null, 0f, 0f, _qualityNeeded, toolComponent:tool))
|
2020-05-20 10:55:17 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
|
coordinates.PryTile(_entMan, _mapManager);
|
2020-05-20 10:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|