2020-09-06 16:11:53 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components.Interactable;
|
2020-07-18 22:51:56 -07:00
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
using Content.Shared.Maps;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
using Content.Shared.Utility;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
2020-12-17 10:45:04 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-05-20 10:55:17 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Interactable
|
|
|
|
|
|
{
|
|
|
|
|
|
[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-03-05 01:08:38 +01:00
|
|
|
|
[DataField("toolComponentNeeded")]
|
2020-05-20 10:55:17 +02:00
|
|
|
|
private bool _toolComponentNeeded = true;
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
|
|
if (!tileDef.CanCrowbar) return;
|
|
|
|
|
|
|
2020-08-18 14:39:08 +02:00
|
|
|
|
if (_toolComponentNeeded && !await tool!.UseTool(user, null, 0f, ToolQuality.Prying))
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|