Predict tile-prying (#21167)
This commit is contained in:
26
Content.Shared/Tools/Components/TilePryingComponent.cs
Normal file
26
Content.Shared/Tools/Components/TilePryingComponent.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Tools.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Allows prying tiles up on a grid.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class TilePryingComponent : Component
|
||||
{
|
||||
[DataField("toolComponentNeeded"), AutoNetworkedField]
|
||||
public bool ToolComponentNeeded = true;
|
||||
|
||||
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>)), AutoNetworkedField]
|
||||
public string QualityNeeded = "Prying";
|
||||
|
||||
/// <summary>
|
||||
/// Whether this tool can pry tiles with CanAxe.
|
||||
/// </summary>
|
||||
[DataField("advanced"), AutoNetworkedField]
|
||||
public bool Advanced = false;
|
||||
|
||||
[DataField("delay"), AutoNetworkedField]
|
||||
public float Delay = 1f;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Prying.Components;
|
||||
using Content.Shared.Tools.Components;
|
||||
|
||||
namespace Content.Shared.Tools;
|
||||
namespace Content.Shared.Tools.Systems;
|
||||
|
||||
public abstract partial class SharedToolSystem : EntitySystem
|
||||
{
|
||||
|
||||
82
Content.Shared/Tools/Systems/SharedToolSystem.TilePrying.cs
Normal file
82
Content.Shared/Tools/Systems/SharedToolSystem.TilePrying.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
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;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Content.Shared.Tools.Systems;
|
||||
|
||||
public abstract partial class SharedToolSystem
|
||||
{
|
||||
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 (!TryComp(gridUid, out MapGridComponent? grid))
|
||||
{
|
||||
Log.Error("Attempted to pry from a non-existent grid?");
|
||||
return;
|
||||
}
|
||||
|
||||
var tile = _maps.GetTileRef(gridUid.Value, grid, coords);
|
||||
var center = _turfs.GetTileCenter(tile);
|
||||
|
||||
if (args.Used != null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):actor} used {ToPrettyString(args.Used.Value):tool} to pry {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_adminLogger.Add(LogType.Tile, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):actor} pried {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
|
||||
}
|
||||
|
||||
if (_netManager.IsServer)
|
||||
_tiles.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 var gridUid, out var mapGrid))
|
||||
return false;
|
||||
|
||||
var tile = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
|
||||
var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, tile.GridIndices);
|
||||
|
||||
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||
return false;
|
||||
|
||||
var tileDef = (ContentTileDefinition) _tileDefManager[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);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,35 @@
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Tools;
|
||||
namespace Content.Shared.Tools.Systems;
|
||||
|
||||
public abstract partial class SharedToolSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly INetManager _netManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] protected readonly SharedInteractionSystem InteractionSystem = default!;
|
||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly TileSystem _tiles = default!;
|
||||
[Dependency] private readonly TurfSystem _turfs = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
InitializeMultipleTool();
|
||||
InitializeTilePrying();
|
||||
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user