Predict tile-prying (#21167)
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using System.Threading;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Tools.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed partial class TilePryingComponent : Component
|
||||
{
|
||||
[DataField("toolComponentNeeded")]
|
||||
public bool ToolComponentNeeded = true;
|
||||
|
||||
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string QualityNeeded = "Prying";
|
||||
|
||||
/// <summary>
|
||||
/// Whether this tool can pry tiles with CanAxe.
|
||||
/// </summary>
|
||||
[DataField("advanced")]
|
||||
public bool Advanced = false;
|
||||
|
||||
[DataField("delay")]
|
||||
public float Delay = 1f;
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,14 @@ public sealed partial class ToolSystem
|
||||
|
||||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
||||
|
||||
if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||
return false;
|
||||
|
||||
if (_tileDefinitionManager[tile.Tile.TypeId] is not ContentTileDefinition tileDef
|
||||
|| !tileDef.CanWirecutter
|
||||
|| string.IsNullOrEmpty(tileDef.BaseTurf)
|
||||
|| _tileDefinitionManager[tileDef.BaseTurf] is not ContentTileDefinition newDef
|
||||
|| tile.IsBlockedTurf(true))
|
||||
|| _tileDefinitionManager[tileDef.BaseTurf] is not ContentTileDefinition ||
|
||||
tile.IsBlockedTurf(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Fluids.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Tools;
|
||||
|
||||
public sealed partial class ToolSystem
|
||||
{
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
|
||||
private void InitializeTilePrying()
|
||||
{
|
||||
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
|
||||
SubscribeLocalEvent<TilePryingComponent, TilePryingDoAfterEvent>(OnTilePryComplete);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void OnTilePryComplete(EntityUid uid, TilePryingComponent component, TilePryingDoAfterEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
var coords = GetCoordinates(args.Coordinates);
|
||||
var gridUid = coords.GetGridUid(EntityManager);
|
||||
if (!_mapManager.TryGetGrid(gridUid, out var grid))
|
||||
{
|
||||
Log.Error("Attempted to pry from a non-existent grid?");
|
||||
return;
|
||||
}
|
||||
|
||||
var tile = grid.GetTileRef(coords);
|
||||
var center = _turf.GetTileCenter(tile);
|
||||
if (args.Used != null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):actor} pried {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
|
||||
}
|
||||
|
||||
_tile.PryTile(tile, component.Advanced);
|
||||
}
|
||||
|
||||
private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
|
||||
{
|
||||
if (!TryComp<ToolComponent>(toolEntity, out var tool) && component.ToolComponentNeeded)
|
||||
return false;
|
||||
|
||||
if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out _, out var mapGrid))
|
||||
return false;
|
||||
|
||||
var tile = mapGrid.GetTileRef(clickLocation);
|
||||
|
||||
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
||||
|
||||
if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||
return false;
|
||||
|
||||
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
||||
|
||||
if (!tileDef.CanCrowbar && !(tileDef.CanAxe && component.Advanced))
|
||||
return false;
|
||||
|
||||
var ev = new TilePryingDoAfterEvent(GetNetCoordinates(coordinates));
|
||||
|
||||
return UseTool(toolEntity, user, toolEntity, component.Delay, component.QualityNeeded, ev, toolComponent: tool);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Maps;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||
|
||||
namespace Content.Server.Tools
|
||||
{
|
||||
@@ -21,13 +22,11 @@ namespace Content.Server.Tools
|
||||
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly TurfSystem _turf = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
InitializeTilePrying();
|
||||
InitializeLatticeCutting();
|
||||
InitializeWelders();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user