]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict tile-prying (#21167)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 23 Oct 2023 13:20:33 +0000 (00:20 +1100)
committerGitHub <noreply@github.com>
Mon, 23 Oct 2023 13:20:33 +0000 (00:20 +1100)
28 files changed:
Content.Client/Tools/ToolSystem.cs
Content.Server/Administration/Commands/VariantizeCommand.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs
Content.Server/Construction/ConstructionSystem.cs
Content.Server/Construction/RefiningSystem.cs
Content.Server/Decals/DecalSystem.cs
Content.Server/DeviceLinking/Systems/LogicGateSystem.cs
Content.Server/Interaction/TilePryCommand.cs
Content.Server/Medical/CryoPodSystem.cs
Content.Server/Power/EntitySystems/CableSystem.cs
Content.Server/Repairable/RepairableSystem.cs
Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
Content.Server/Toilet/ToiletSystem.cs
Content.Server/Tools/Components/TilePryingComponent.cs [deleted file]
Content.Server/Tools/ToolSystem.LatticeCutting.cs
Content.Server/Tools/ToolSystem.cs
Content.Server/Wires/WiresSystem.cs
Content.Server/Worldgen/Systems/Debris/BlobFloorPlanBuilderSystem.cs
Content.Server/Worldgen/Systems/Debris/DebrisFeaturePlacerSystem.cs
Content.Shared/Construction/EntitySystems/AnchorableSystem.cs
Content.Shared/Decals/SharedDecalSystem.cs
Content.Shared/Maps/TileSystem.cs [moved from Content.Server/Maps/TileSystem.cs with 68% similarity]
Content.Shared/Maps/TurfHelpers.cs
Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs
Content.Shared/Tools/Components/TilePryingComponent.cs [new file with mode: 0644]
Content.Shared/Tools/Systems/SharedToolSystem.MultipleTool.cs
Content.Shared/Tools/Systems/SharedToolSystem.TilePrying.cs [moved from Content.Server/Tools/ToolSystem.TilePrying.cs with 66% similarity]
Content.Shared/Tools/Systems/SharedToolSystem.cs

index f4dc480b41584b8570cde0d236f82224df53d3a7..966f37146e84691f5427a0cba7155716fe1a3b8b 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.Tools;
 using Content.Shared.Tools.Components;
 using Robust.Client.GameObjects;
 using Robust.Shared.GameStates;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Client.Tools
 {
index 1b5cbbd4d505b74c025ccd6c30aaa4dbf8e0ebfe..7aabd76335e8f52ecc1bbc979be646437dd66ced 100644 (file)
@@ -12,6 +12,7 @@ public sealed class VariantizeCommand : IConsoleCommand
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
 
     public string Command => "variantize";
 
@@ -39,11 +40,14 @@ public sealed class VariantizeCommand : IConsoleCommand
             return;
         }
 
-        foreach (var tile in gridComp.GetAllTiles())
+        var mapsSystem = _entManager.System<SharedMapSystem>();
+        var tileSystem = _entManager.System<TileSystem>();
+
+        foreach (var tile in mapsSystem.GetAllTiles(euid.Value, gridComp))
         {
-            var def = tile.GetContentTileDefinition();
-            var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, def.PickVariant(_random));
-            gridComp.SetTile(tile.GridIndices, newTile);
+            var def = tile.GetContentTileDefinition(_tileDefManager);
+            var newTile = new Tile(tile.Tile.TypeId, tile.Tile.Flags, tileSystem.PickVariant(def));
+            mapsSystem.SetTile(euid.Value, gridComp, tile.GridIndices, newTile);
         }
     }
 }
index 91634de8d7afc47fce7f2ec7e9ed7b2e07e14fbd..d8364b652b83a3068843013aa39d0678dd1227f3 100644 (file)
@@ -4,6 +4,7 @@ using Content.Server.Body.Systems;
 using Content.Server.Maps;
 using Content.Server.NodeContainer.EntitySystems;
 using Content.Shared.Atmos.EntitySystems;
+using Content.Shared.Maps;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
 using Robust.Shared.Containers;
index 76d37432cb567429e74e7e0d9a6e8534df7712bd..6e40b7b856c37c6f63b4dbe596d007bbf0388818 100644 (file)
@@ -7,6 +7,7 @@ using JetBrains.Annotations;
 using Robust.Server.Containers;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Construction
 {
index 40f69c51f817f88e62aefaac506a36bbc6b2aac3..b9d80c7170a7e2635809c82bee66c719ac7fbdfd 100644 (file)
@@ -6,6 +6,7 @@ using Content.Shared.Interaction;
 using Content.Shared.Stacks;
 using Content.Shared.Tools;
 using Robust.Shared.Serialization;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Construction
 {
index d5a5bf9affa8bcc1a5c8129fdb9d57dc9faa9256..ed281e05ba79bea0787ff30680599d49c2786eec 100644 (file)
@@ -305,10 +305,10 @@ namespace Content.Server.Decals
             return true;
         }
 
-        public bool RemoveDecal(EntityUid gridId, uint decalId, DecalGridComponent? component = null)
+        public override bool RemoveDecal(EntityUid gridId, uint decalId, DecalGridComponent? component = null)
             => RemoveDecalInternal(gridId, decalId, out _, component);
 
-        public HashSet<(uint Index, Decal Decal)> GetDecalsInRange(EntityUid gridId, Vector2 position, float distance = 0.75f, Func<Decal, bool>? validDelegate = null)
+        public override HashSet<(uint Index, Decal Decal)> GetDecalsInRange(EntityUid gridId, Vector2 position, float distance = 0.75f, Func<Decal, bool>? validDelegate = null)
         {
             var decalIds = new HashSet<(uint, Decal)>();
             var chunkCollection = ChunkCollection(gridId);
index 360f86eebe914b6194a08345f006678f4f38db35..5641b0b4aee8240b318b92a4c0f8707bd0306490 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.Examine;
 using Content.Shared.Interaction;
 using Content.Shared.Tools;
 using Content.Shared.Popups;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 using SignalReceivedEvent = Content.Server.DeviceLinking.Events.SignalReceivedEvent;
 
 namespace Content.Server.DeviceLinking.Systems;
index 157fa2cc80ce005baea8d761567b75515f787fae..4fe3599df97e9ebfcc2d1ab13115deafcfb2fbec 100644 (file)
@@ -3,6 +3,7 @@ using Content.Server.Administration;
 using Content.Server.Tools.Components;
 using Content.Shared.Administration;
 using Content.Shared.Maps;
+using Content.Shared.Tools.Components;
 using Robust.Server.Player;
 using Robust.Shared.Console;
 using Robust.Shared.Map;
@@ -10,7 +11,7 @@ using Robust.Shared.Map;
 namespace Content.Server.Interaction
 {
     /// <summary>
-    /// <see cref="TilePryingComponent.TryPryTile"/>
+    /// <see cref="Shared.Tools.Components.TilePryingComponent.TryPryTile"/>
     /// </summary>
     [AdminCommand(AdminFlags.Debug)]
     sealed class TilePryCommand : IConsoleCommand
index b94d6de6de022a2588937ea6980eb524a644ca2f..82f7b9cb0a00697540d776f917f7ab12c9d73211 100644 (file)
@@ -32,6 +32,7 @@ using Content.Shared.Tools;
 using Content.Shared.Verbs;
 using Robust.Server.GameObjects;
 using Robust.Shared.Timing;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Medical;
 
index 8dd09fab3531cb09da5bd80df3458acc4a0f10f7..a5c9591d9ad64ea7166f33ba362dfcac344646d9 100644 (file)
@@ -8,6 +8,8 @@ using Content.Shared.Interaction;
 using Content.Shared.Tools;
 using Content.Shared.Tools.Components;
 using Robust.Shared.Map;
+using CableCuttingFinishedEvent = Content.Shared.Tools.Systems.CableCuttingFinishedEvent;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Power.EntitySystems;
 
index 486ac756e3adf8a1664e9deddedd2376b69bad2c..5bd580756daeab32cfbd6cc70a5328b18b6a6aa6 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.Interaction;
 using Content.Shared.Popups;
 using Content.Shared.Repairable;
 using Content.Shared.Tools;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Repairable
 {
index b3caced0daf72c1a589db55d16462f1d9e7b06a9..cb20a1b86834cc76814ebb0f502610c8728169bc 100644 (file)
@@ -21,6 +21,7 @@ using Content.Shared.DoAfter;
 using Content.Shared.Emag.Systems;
 using Content.Shared.FixedPoint;
 using Content.Shared.Humanoid;
+using Content.Shared.Maps;
 using Content.Shared.Mobs;
 using Content.Shared.Mobs.Components;
 using Content.Shared.Mobs.Systems;
index 57467397c6dc9d8cfba4c78ae89ea01b121d082e..b10feae4533e04249c039cc5a04d8cf36c8a93d8 100644 (file)
@@ -19,6 +19,7 @@ using Content.Shared.Verbs;
 using Robust.Shared.Audio;
 using Robust.Shared.Player;
 using Robust.Shared.Random;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Toilet
 {
diff --git a/Content.Server/Tools/Components/TilePryingComponent.cs b/Content.Server/Tools/Components/TilePryingComponent.cs
deleted file mode 100644 (file)
index 99d7144..0000000
+++ /dev/null
@@ -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;
-    }
-}
index 674a8102390a6a47eb87cd751734dbe3cfa7b168..ab289c1ae24358b213c86cca1bb759937fbc6554 100644 (file)
@@ -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;
         }
index 63642338f38714607d37c4069729dc582ea9dd1f..88a96dc1e8daaf9af95b741287313ed64769d274 100644 (file)
@@ -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();
         }
index df61e89d4dd5bf31cc8da4e2f6d6bf3d26b79ccf..e75ad0a9efb7e3b8099350b545ee89f1dd88a3f3 100644 (file)
@@ -19,6 +19,7 @@ using Robust.Server.GameObjects;
 using Robust.Server.Player;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Server.Wires;
 
index a90faef9959eaed7bd9833f0cd7051837f170ec7..a09416e5937be2637439f7355933483683350277 100644 (file)
@@ -14,6 +14,7 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem
 {
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly ITileDefinitionManager _tileDefinition = default!;
+    [Dependency] private readonly TileSystem _tiles = default!;
 
     /// <inheritdoc />
     public override void Initialize()
@@ -30,6 +31,8 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem
     private void PlaceFloorplanTiles(BlobFloorPlanBuilderComponent comp, MapGridComponent grid)
     {
         // NO MORE THAN TWO ALLOCATIONS THANK YOU VERY MUCH.
+        // TODO: Just put these on a field instead then?
+        // Also the end of the method has a big LINQ which is gonna blow this out the water.
         var spawnPoints = new HashSet<Vector2i>(comp.FloorPlacements * 6);
         var taken = new Dictionary<Vector2i, Tile>(comp.FloorPlacements * 5);
 
@@ -56,7 +59,7 @@ public sealed class BlobFloorPlanBuilderSystem : BaseWorldSystem
                 spawnPoints.Add(west);
 
             var tileDef = _tileDefinition[_random.Pick(comp.FloorTileset)];
-            taken.Add(point, new Tile(tileDef.TileId, 0, ((ContentTileDefinition)tileDef).PickVariant(_random)));
+            taken.Add(point, new Tile(tileDef.TileId, 0, _tiles.PickVariant((ContentTileDefinition) tileDef)));
         }
 
         PlaceTile(Vector2i.Zero);
index b2d8df4de92a61026011c87e3117f69f3e96f7bf..65af0b68cb76189713a4e75a05b786bd2c9b89db 100644 (file)
@@ -46,7 +46,7 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
             return; // Redundant logic, prolly needs it's own handler for your custom system.
 
         var placer = Comp<DebrisFeaturePlacerControllerComponent>(component.OwningController);
-        var xform = Transform(uid);
+        var xform = args.Component;
         var ownerXform = Transform(component.OwningController);
         if (xform.MapUid is null || ownerXform.MapUid is null)
             return; // not our problem
index 3e1cf5584c1bb0ae75743843fc12f59ecbef8141..b40c04956228211d16b0dff5a3b1d5cb1cd8876a 100644 (file)
@@ -18,6 +18,7 @@ using Content.Shared.Tag;
 using Robust.Shared.Player;
 using Robust.Shared.Serialization;
 using Robust.Shared.Utility;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Shared.Construction.EntitySystems;
 
index 79bf826eedbd19af4e4eb28e0d22801ce51538a3..02f73bdacb38520c797f0371d2dc9adf70f1975d 100644 (file)
@@ -1,3 +1,4 @@
+using System.Collections;
 using System.Diagnostics.CodeAnalysis;
 using System.Numerics;
 using Robust.Shared.GameStates;
@@ -107,6 +108,18 @@ namespace Content.Shared.Decals
         {
             // used by client-side overlay code
         }
+
+        public virtual HashSet<(uint Index, Decal Decal)> GetDecalsInRange(EntityUid gridId, Vector2 position, float distance = 0.75f, Func<Decal, bool>? validDelegate = null)
+        {
+            // NOOP on client atm.
+            return new HashSet<(uint Index, Decal Decal)>();
+        }
+
+        public virtual bool RemoveDecal(EntityUid gridId, uint decalId, DecalGridComponent? component = null)
+        {
+            // NOOP on client atm.
+            return true;
+        }
     }
 
     // TODO: Pretty sure paul was moving this somewhere but just so people know
similarity index 68%
rename from Content.Server/Maps/TileSystem.cs
rename to Content.Shared/Maps/TileSystem.cs
index 1423f76d9719cd4d6e535c0d8729fae32ec9ff82..2c09375d593cb743409f13cc4fec143f3a8fbbc1 100644 (file)
@@ -1,13 +1,13 @@
+using System.Linq;
 using System.Numerics;
-using Content.Server.Decals;
 using Content.Shared.Coordinates.Helpers;
 using Content.Shared.Decals;
-using Content.Shared.Maps;
 using Robust.Shared.Map;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Random;
+using Robust.Shared.Utility;
 
-namespace Content.Server.Maps;
+namespace Content.Shared.Maps;
 
 /// <summary>
 ///     Handles server-side tile manipulation like prying/deconstructing tiles.
@@ -15,15 +15,39 @@ namespace Content.Server.Maps;
 public sealed class TileSystem : EntitySystem
 {
     [Dependency] private readonly IMapManager _mapManager = default!;
-    [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
     [Dependency] private readonly IRobustRandom _robustRandom = default!;
-    [Dependency] private readonly DecalSystem _decal = default!;
+    [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
+    [Dependency] private readonly SharedDecalSystem _decal = default!;
+    [Dependency] private readonly SharedMapSystem _maps = default!;
     [Dependency] private readonly TurfSystem _turf = default!;
 
+    /// <summary>
+    ///     Returns a weighted pick of a tile variant.
+    /// </summary>
+    public byte PickVariant(ContentTileDefinition tile)
+    {
+        var variants = tile.PlacementVariants;
+
+        var sum = variants.Sum();
+        var accumulated = 0f;
+        var rand = _robustRandom.NextFloat() * sum;
+
+        for (byte i = 0; i < variants.Length; ++i)
+        {
+            accumulated += variants[i];
+
+            if (accumulated >= rand)
+                return i;
+        }
+
+        // Shouldn't happen
+        throw new InvalidOperationException($"Invalid weighted variantize tile pick for {tile.ID}!");
+    }
+
     public bool PryTile(Vector2i indices, EntityUid gridId)
     {
-        var grid = _mapManager.GetGrid(gridId);
-        var tileRef = grid.GetTileRef(indices);
+        var grid = Comp<MapGridComponent>(gridId);
+        var tileRef = _maps.GetTileRef(gridId, grid, indices);
         return PryTile(tileRef);
     }
 
@@ -71,16 +95,20 @@ public sealed class TileSystem : EntitySystem
 
     public bool ReplaceTile(TileRef tileref, ContentTileDefinition replacementTile, EntityUid grid, MapGridComponent? component = null)
     {
+        DebugTools.Assert(tileref.GridUid == grid);
+
         if (!Resolve(grid, ref component))
             return false;
 
-        var variant = replacementTile.PickVariant();
+
+        var variant = PickVariant(replacementTile);
         var decals = _decal.GetDecalsInRange(tileref.GridUid, _turf.GetTileCenter(tileref).Position, 0.5f);
         foreach (var (id, _) in decals)
         {
             _decal.RemoveDecal(tileref.GridUid, id);
         }
-        component.SetTile(tileref.GridIndices, new Tile(replacementTile.TileId, 0, variant));
+
+        _maps.SetTile(grid, component, tileref.GridIndices, new Tile(replacementTile.TileId, 0, variant));
         return true;
     }
 
@@ -94,12 +122,13 @@ public sealed class TileSystem : EntitySystem
         if (string.IsNullOrEmpty(tileDef.BaseTurf))
             return false;
 
-        var mapGrid = _mapManager.GetGrid(tileRef.GridUid);
+        var gridUid = tileRef.GridUid;
+        var mapGrid = Comp<MapGridComponent>(gridUid);
 
         const float margin = 0.1f;
         var bounds = mapGrid.TileSize - margin * 2;
         var indices = tileRef.GridIndices;
-        var coordinates = mapGrid.GridTileToLocal(indices)
+        var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, indices)
             .Offset(new Vector2(
                 (_robustRandom.NextFloat() - 0.5f) * bounds,
                 (_robustRandom.NextFloat() - 0.5f) * bounds));
@@ -109,15 +138,14 @@ public sealed class TileSystem : EntitySystem
         Transform(tileItem).LocalRotation = _robustRandom.NextDouble() * Math.Tau;
 
         // Destroy any decals on the tile
-        var decals = _decal.GetDecalsInRange(tileRef.GridUid, coordinates.SnapToGrid(EntityManager, _mapManager).Position, 0.5f);
+        var decals = _decal.GetDecalsInRange(gridUid, coordinates.SnapToGrid(EntityManager, _mapManager).Position, 0.5f);
         foreach (var (id, _) in decals)
         {
             _decal.RemoveDecal(tileRef.GridUid, id);
         }
 
         var plating = _tileDefinitionManager[tileDef.BaseTurf];
-
-        mapGrid.SetTile(tileRef.GridIndices, new Tile(plating.TileId));
+        _maps.SetTile(gridUid, mapGrid, tileRef.GridIndices, new Tile(plating.TileId));
 
         return true;
     }
index 857244d658ced6165de8e13567e4b20743d30b7d..a87b8c97d159945389b321e022a002ca41744022 100644 (file)
@@ -86,30 +86,6 @@ namespace Content.Shared.Maps
             return tile.Tile.IsSpace(tileDefinitionManager);
         }
 
-        /// <summary>
-        ///     Returns a weighted pick of a tile variant.
-        /// </summary>
-        public static byte PickVariant(this ContentTileDefinition tile, IRobustRandom? random = null)
-        {
-            IoCManager.Resolve(ref random);
-            var variants = tile.PlacementVariants;
-
-            var sum = variants.Sum();
-            var accumulated = 0f;
-            var rand = random.NextFloat() * sum;
-
-            for (byte i = 0; i < variants.Length; ++i)
-            {
-                accumulated += variants[i];
-
-                if (accumulated >= rand)
-                    return i;
-            }
-
-            // Shouldn't happen
-            throw new InvalidOperationException($"Invalid weighted variantize tile pick for {tile.ID}!");
-        }
-
         /// <summary>
         ///     Helper that returns all entities in a turf.
         /// </summary>
index 3d2ce2fd00ae14c36ea2c448df583241bfc60109..eb97fe41133b5bb3bbd3e2e8c7b348b73efd8652 100644 (file)
@@ -14,6 +14,7 @@ using Robust.Shared.Network;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization;
 using Robust.Shared.Timing;
+using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
 
 namespace Content.Shared.Radio.EntitySystems;
 
diff --git a/Content.Shared/Tools/Components/TilePryingComponent.cs b/Content.Shared/Tools/Components/TilePryingComponent.cs
new file mode 100644 (file)
index 0000000..4c123ca
--- /dev/null
@@ -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;
+}
index 39a1dc50f32ae8dd7a03de49436fde56819fb5f1..cb8830060a2d1223a5c4af8bb7585cd9a7b16c80 100644 (file)
@@ -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
 {
similarity index 66%
rename from Content.Server/Tools/ToolSystem.TilePrying.cs
rename to Content.Shared/Tools/Systems/SharedToolSystem.TilePrying.cs
index faaed6abb87e51f3234b6393a65e8a1b31bc4286..81592f5a98270c0009cf8b6b74548741c051d93b 100644 (file)
@@ -1,17 +1,15 @@
-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;
+using Robust.Shared.Map.Components;
 
-namespace Content.Server.Tools;
+namespace Content.Shared.Tools.Systems;
 
-public sealed partial class ToolSystem
+public abstract partial class SharedToolSystem
 {
-    [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
-
     private void InitializeTilePrying()
     {
         SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
@@ -20,7 +18,8 @@ public sealed partial class ToolSystem
 
     private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args)
     {
-        if (args.Handled || !args.CanReach || (args.Target != null && !HasComp<PuddleComponent>(args.Target))) return;
+        if (args.Handled || !args.CanReach || args.Target != null && !HasComp<PuddleComponent>(args.Target))
+            return;
 
         if (TryPryTile(uid, args.User, component, args.ClickLocation))
             args.Handled = true;
@@ -33,26 +32,28 @@ public sealed partial class ToolSystem
 
         var coords = GetCoordinates(args.Coordinates);
         var gridUid = coords.GetGridUid(EntityManager);
-        if (!_mapManager.TryGetGrid(gridUid, out var grid))
+        if (!TryComp(gridUid, out MapGridComponent? grid))
         {
             Log.Error("Attempted to pry from a non-existent grid?");
             return;
         }
 
-        var tile = grid.GetTileRef(coords);
-        var center = _turf.GetTileCenter(tile);
+        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 {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
+                $"{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 {_tileDefinitionManager[tile.Tile.TypeId].Name} at {center}");
+                $"{ToPrettyString(args.User):actor} pried {_tileDefManager[tile.Tile.TypeId].Name} at {center}");
         }
 
-        _tile.PryTile(tile, component.Advanced);
+        if (_netManager.IsServer)
+            _tiles.PryTile(tile, component.Advanced);
     }
 
     private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
@@ -60,17 +61,16 @@ public sealed partial class ToolSystem
         if (!TryComp<ToolComponent>(toolEntity, out var tool) && component.ToolComponentNeeded)
             return false;
 
-        if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out _, out var mapGrid))
+        if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out var gridUid, out var mapGrid))
             return false;
 
-        var tile = mapGrid.GetTileRef(clickLocation);
-
-        var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
+        var tile = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
+        var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, tile.GridIndices);
 
-        if (!_interactionSystem.InRangeUnobstructed(user, coordinates, popup: false))
+        if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
             return false;
 
-        var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
+        var tileDef = (ContentTileDefinition) _tileDefManager[tile.Tile.TypeId];
 
         if (!tileDef.CanCrowbar && !(tileDef.CanAxe && component.Advanced))
             return false;
index 716a9332d0ebf9a9cfedfe2085e4751444ff9bee..c1a2bdc2ddae35cac6bcaf90c1a7bd5f2d2f5f2a 100644 (file)
@@ -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);
     }