2023-06-19 02:04:30 -05:00
|
|
|
using Content.Shared.Database;
|
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-01-30 14:48:18 +11:00
|
|
|
using Robust.Shared.Map;
|
2023-10-24 00:20:33 +11:00
|
|
|
using Robust.Shared.Map.Components;
|
2022-01-30 14:48:18 +11:00
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
namespace Content.Shared.Tools.Systems;
|
2022-01-30 14:48:18 +11:00
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
public abstract partial class SharedToolSystem
|
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)
|
|
|
|
|
{
|
2023-10-24 00:20:33 +11:00
|
|
|
if (args.Handled || !args.CanReach || args.Target != null && !HasComp<PuddleComponent>(args.Target))
|
|
|
|
|
return;
|
2023-02-26 00:33:06 -05:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var coords = GetCoordinates(args.Coordinates);
|
|
|
|
|
var gridUid = coords.GetGridUid(EntityManager);
|
2023-10-24 00:20:33 +11:00
|
|
|
if (!TryComp(gridUid, out MapGridComponent? grid))
|
2022-06-20 12:14:35 +12:00
|
|
|
{
|
2023-07-06 16:43:49 +12:00
|
|
|
Log.Error("Attempted to pry from a non-existent grid?");
|
2022-06-20 12:14:35 +12:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
var tile = _maps.GetTileRef(gridUid.Value, grid, coords);
|
|
|
|
|
var center = _turfs.GetTileCenter(tile);
|
|
|
|
|
|
2023-06-19 02:04:30 -05:00
|
|
|
if (args.Used != null)
|
|
|
|
|
{
|
2023-08-15 00:11:54 -05:00
|
|
|
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
2023-10-24 00:20:33 +11:00
|
|
|
$"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
|
2023-06-19 02:04:30 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-15 00:11:54 -05:00
|
|
|
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
2023-10-24 00:20:33 +11:00
|
|
|
$"{ToPrettyString(args.User):actor} pried {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
|
2023-06-19 02:04:30 -05:00
|
|
|
}
|
|
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
if (_netManager.IsServer)
|
|
|
|
|
_tiles.PryTile(tile, component.Advanced);
|
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-09-20 10:12:48 +10:00
|
|
|
if (!TryComp<ToolComponent>(toolEntity, out var tool) && component.ToolComponentNeeded)
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out var gridUid, out var mapGrid))
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
var tile = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
|
|
|
|
|
var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, tile.GridIndices);
|
2022-01-30 14:48:18 +11:00
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
2023-10-24 00:20:33 +11:00
|
|
|
var tileDef = (ContentTileDefinition) _tileDefManager[tile.Tile.TypeId];
|
2022-01-30 14:48:18 +11:00
|
|
|
|
2023-07-17 11:47:20 +04:00
|
|
|
if (!tileDef.CanCrowbar && !(tileDef.CanAxe && component.Advanced))
|
2022-01-30 14:48:18 +11:00
|
|
|
return false;
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var ev = new TilePryingDoAfterEvent(GetNetCoordinates(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
|
|
|
}
|