RCD and tile placement fixes (#21132)

This commit is contained in:
metalgearsloth
2023-10-22 16:53:39 +11:00
committed by GitHub
parent e2352fc28e
commit a5f1683f54
2 changed files with 34 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ using Content.Shared.Physics;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.RCD.Components; using Content.Shared.RCD.Components;
using Content.Shared.Tag; using Content.Shared.Tag;
using Content.Shared.Tiles;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
@@ -22,17 +23,19 @@ namespace Content.Shared.RCD.Systems;
public sealed class RCDSystem : EntitySystem public sealed class RCDSystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mapMan = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
[Dependency] private readonly FloorTileSystem _floors = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedChargesSystem _charges = default!; [Dependency] private readonly SharedChargesSystem _charges = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!; [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!; [Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly IMapManager _mapMan = default!; [Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly TagSystem _tag = default!; [Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly TurfSystem _turf = default!; [Dependency] private readonly TurfSystem _turf = default!;
private readonly int RcdModeCount = Enum.GetValues(typeof(RcdMode)).Length; private readonly int RcdModeCount = Enum.GetValues(typeof(RcdMode)).Length;
@@ -156,10 +159,17 @@ public sealed class RCDSystem : EntitySystem
var tile = mapGrid.GetTileRef(location); var tile = mapGrid.GetTileRef(location);
var snapPos = mapGrid.TileIndicesFor(location); var snapPos = mapGrid.TileIndicesFor(location);
// I love that this uses entirely separate code to construction and tile placement!!!
switch (comp.Mode) switch (comp.Mode)
{ {
//Floor mode just needs the tile to be a space tile (subFloor) //Floor mode just needs the tile to be a space tile (subFloor)
case RcdMode.Floors: case RcdMode.Floors:
if (!_floors.CanPlaceTile(gridId.Value, mapGrid, out var reason))
{
_popup.PopupClient(reason, user, user);
return;
}
mapGrid.SetTile(snapPos, new Tile(_tileDefMan[comp.Floor].TileId)); mapGrid.SetTile(snapPos, new Tile(_tileDefMan[comp.Floor].TileId));
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridUid} {snapPos} to {comp.Floor}"); _adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridUid} {snapPos} to {comp.Floor}");

View File

@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
@@ -123,14 +124,10 @@ public sealed class FloorTileSystem : EntitySystem
if (mapGrid != null) if (mapGrid != null)
{ {
var gridUid = mapGrid.Owner; var gridUid = mapGrid.Owner;
var ev = new FloorTileAttemptEvent();
RaiseLocalEvent(mapGrid);
if (HasComp<ProtectedGridComponent>(gridUid) || ev.Cancelled) if (!CanPlaceTile(gridUid, mapGrid, out var reason))
{ {
if (_netManager.IsClient && _timing.IsFirstTimePredicted) _popup.PopupClient(reason, args.User, args.User);
_popup.PopupEntity(Loc.GetString("invalid-floor-placement"), args.User);
return; return;
} }
@@ -177,9 +174,25 @@ public sealed class FloorTileSystem : EntitySystem
{ {
_adminLogger.Add(LogType.Tile, LogImpact.Low, $"{ToPrettyString(user):actor} placed tile {_tileDefinitionManager[tileId].Name} at {ToPrettyString(gridUid)} {location}"); _adminLogger.Add(LogType.Tile, LogImpact.Low, $"{ToPrettyString(user):actor} placed tile {_tileDefinitionManager[tileId].Name} at {ToPrettyString(gridUid)} {location}");
var variant = ((ContentTileDefinition) _tileDefinitionManager[tileId]).PickVariant(); // TODO: Proper predicted RNG.
var variant = (byte) (_timing.CurTick.Value % ((ContentTileDefinition) _tileDefinitionManager[tileId]).Variants);
mapGrid.SetTile(location.Offset(new Vector2(offset, offset)), new Tile(tileId, 0, variant)); mapGrid.SetTile(location.Offset(new Vector2(offset, offset)), new Tile(tileId, 0, variant));
_audio.PlayPredicted(placeSound, location, user, AudioHelpers.WithVariation(0.125f, _random)); _audio.PlayPredicted(placeSound, location, user, AudioHelpers.WithVariation(0.125f, _random));
} }
public bool CanPlaceTile(EntityUid gridUid, MapGridComponent component, [NotNullWhen(false)] out string? reason)
{
var ev = new FloorTileAttemptEvent();
RaiseLocalEvent(gridUid, ref ev);
if (HasComp<ProtectedGridComponent>(gridUid) || ev.Cancelled)
{
reason = Loc.GetString("invalid-floor-placement");
return false;
}
reason = null;
return true;
}
} }