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;
|
|
|
|
|
|
using Content.Shared.Tools.Components;
|
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
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
public async void TryPryTile(IEntity user, EntityCoordinates clickLocation)
|
2020-05-20 10:55:17 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!Owner.TryGetComponent<ToolComponent>(out var tool) && _toolComponentNeeded)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-10-21 17:13:41 +02:00
|
|
|
|
if (!_mapManager.TryGetGrid(clickLocation.GetGridId(Owner.EntityManager), out var mapGrid))
|
|
|
|
|
|
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-10-07 23:08:16 +02:00
|
|
|
|
if (_toolComponentNeeded && !await EntitySystem.Get<ToolSystem>().UseTool(Owner.Uid, user.Uid, null, 0f, 0f, _qualityNeeded, toolComponent:tool))
|
2020-05-20 10:55:17 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
coordinates.PryTile(Owner.EntityManager, _mapManager);
|
2020-05-20 10:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|