2022-01-30 14:48:18 +11:00
|
|
|
using System.Threading;
|
2022-06-20 22:03:54 -04:00
|
|
|
using Content.Server.Fluids.Components;
|
2022-01-30 14:48:18 +11:00
|
|
|
using Content.Server.Tools.Components;
|
2023-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.DoAfter;
|
2023-04-10 15:37:03 +10:00
|
|
|
using Content.Shared.Fluids.Components;
|
2022-01-30 14:48:18 +11:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Maps;
|
2022-04-02 16:52:44 +13:00
|
|
|
using Content.Shared.Tools.Components;
|
2022-06-28 20:50:58 +10:00
|
|
|
using Robust.Shared.Audio;
|
2022-01-30 14:48:18 +11:00
|
|
|
using Robust.Shared.Map;
|
2022-06-28 20:50:58 +10:00
|
|
|
using Robust.Shared.Player;
|
2022-06-20 12:14:35 +12:00
|
|
|
using Robust.Shared.Utility;
|
2022-01-30 14:48:18 +11:00
|
|
|
|
|
|
|
|
namespace Content.Server.Tools;
|
|
|
|
|
|
|
|
|
|
public sealed partial class ToolSystem
|
|
|
|
|
{
|
2022-02-17 15:40:03 +13:00
|
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
|
|
|
|
|
2022-01-30 14:48:18 +11:00
|
|
|
private void InitializeTilePrying()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
|
2023-04-03 13:13:48 +12:00
|
|
|
SubscribeLocalEvent<TilePryingComponent, TilePryingDoAfterEvent>(OnTilePryComplete);
|
2023-02-26 00:33:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled || !args.CanReach || (args.Target != null && !HasComp<PuddleComponent>(args.Target))) return;
|
|
|
|
|
|
|
|
|
|
if (TryPryTile(uid, args.User, component, args.ClickLocation))
|
|
|
|
|
args.Handled = true;
|
2022-01-30 14:48:18 +11:00
|
|
|
}
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
private void OnTilePryComplete(EntityUid uid, TilePryingComponent component, TilePryingDoAfterEvent args)
|
2022-01-30 14:48:18 +11:00
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
if (args.Cancelled)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-20 12:14:35 +12:00
|
|
|
var gridUid = args.Coordinates.GetGridUid(EntityManager);
|
|
|
|
|
if (!_mapManager.TryGetGrid(gridUid, out var grid))
|
|
|
|
|
{
|
|
|
|
|
Logger.Error("Attempted to pry from a non-existent grid?");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 04:24:50 -06:00
|
|
|
var tile = grid.GetTileRef(args.Coordinates);
|
|
|
|
|
_tile.PryTile(tile);
|
2022-01-30 14:48:18 +11:00
|
|
|
}
|
|
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
|
2022-01-30 14:48:18 +11:00
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
if (!TryComp<ToolComponent?>(toolEntity, out var tool) && component.ToolComponentNeeded)
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
2023-04-12 12:18:30 +12:00
|
|
|
if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out var mapGrid))
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var tile = mapGrid.GetTileRef(clickLocation);
|
|
|
|
|
|
|
|
|
|
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
|
|
|
|
|
2022-02-17 15:40:03 +13:00
|
|
|
if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
|
|
|
|
|
|
|
|
|
if (!tileDef.CanCrowbar)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-04-12 12:18:30 +12:00
|
|
|
var ev = new TilePryingDoAfterEvent(coordinates);
|
2022-05-10 19:48:59 +10:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
return UseTool(toolEntity, user, toolEntity, component.Delay, component.QualityNeeded, ev, toolComponent: tool);
|
2022-05-10 19:48:59 +10:00
|
|
|
}
|
2022-01-30 14:48:18 +11:00
|
|
|
}
|