]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
You can now pry multiple tiles at once (#29231)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Thu, 20 Jun 2024 14:05:40 +0000 (16:05 +0200)
committerGitHub <noreply@github.com>
Thu, 20 Jun 2024 14:05:40 +0000 (00:05 +1000)
* You can now pry multiple tiles at once

* More advanced do after duplicate checking.

Instead of just saying "lol tile prying can raise duplicates", we now have a system so tile prying can properly distinguish events on 2 different tiles. This is achieved with a virtual function on DoAfterEvent.

Content.Shared/DoAfter/DoAfterEvent.cs
Content.Shared/DoAfter/SharedDoAfterSystem.cs
Content.Shared/Tools/Components/ToolTileCompatibleComponent.cs
Content.Shared/Tools/Systems/SharedToolSystem.Tile.cs
Content.Shared/Tools/Systems/SharedToolSystem.cs

index bc9abdab87b693535d62f12b336445bfaf567437..5affbe748502de7ccf5fce50604a1a406cd94a94 100644 (file)
@@ -34,6 +34,14 @@ public abstract partial class DoAfterEvent : HandledEntityEventArgs
     public EntityUid? Used => DoAfter.Args.Used;
     public DoAfterArgs Args => DoAfter.Args;
     #endregion
+
+    /// <summary>
+    /// Check whether this event is "the same" as another event for duplicate checking.
+    /// </summary>
+    public virtual bool IsDuplicate(DoAfterEvent other)
+    {
+        return GetType() == other.GetType();
+    }
 }
 
 /// <summary>
index 9ad649683dd0e2bc56fedbc4463466ef021f80f7..77b47415333c2b9dd1a683214d98180bb74fe05f 100644 (file)
@@ -310,7 +310,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
         }
 
         if ((conditions & DuplicateConditions.SameEvent) != 0
-            && args.Event.GetType() != otherArgs.Event.GetType())
+            && !args.Event.IsDuplicate(otherArgs.Event))
         {
             return false;
         }
index caac41a3def1ef0e19b4fbc6e876f45bbd968b6f..57058a5781ac8cbba7a1d08a830fa2598355155a 100644 (file)
@@ -30,15 +30,24 @@ public sealed partial class ToolTileCompatibleComponent : Component
 [Serializable, NetSerializable]
 public sealed partial class TileToolDoAfterEvent : DoAfterEvent
 {
-    public NetCoordinates Coordinates;
+    public NetEntity Grid;
+    public Vector2i GridTile;
 
-    public TileToolDoAfterEvent(NetCoordinates coordinates)
+    public TileToolDoAfterEvent(NetEntity grid, Vector2i gridTile)
     {
-        Coordinates = coordinates;
+        Grid = grid;
+        GridTile = gridTile;
     }
 
     public override DoAfterEvent Clone()
     {
         return this;
     }
+
+    public override bool IsDuplicate(DoAfterEvent other)
+    {
+        return other is TileToolDoAfterEvent otherTile
+               && Grid == otherTile.Grid
+               && GridTile == otherTile.GridTile;
+    }
 }
index 4ccdb2ef4941a3f156403230e465f1d597980327..f392b31740696d56f8527ef52fc6fe5fbb58629d 100644 (file)
@@ -37,24 +37,24 @@ public abstract partial class SharedToolSystem
 
         if (!TryComp<ToolComponent>(ent, out var tool))
             return;
-        var coordinates = GetCoordinates(args.Coordinates);
 
-        var gridUid = coordinates.GetGridUid(EntityManager);
+        var gridUid = GetEntity(args.Grid);
         if (!TryComp<MapGridComponent>(gridUid, out var grid))
         {
             Log.Error("Attempted use tool on a non-existent grid?");
             return;
         }
 
-        var tileRef = _maps.GetTileRef(gridUid.Value, grid, coordinates);
-        if (comp.RequiresUnobstructed && _turfs.IsTileBlocked(gridUid.Value, tileRef.GridIndices, CollisionGroup.MobMask))
+        var tileRef = _maps.GetTileRef(gridUid, grid, args.GridTile);
+        var coords = _maps.ToCoordinates(tileRef, grid);
+        if (comp.RequiresUnobstructed && _turfs.IsTileBlocked(gridUid, tileRef.GridIndices, CollisionGroup.MobMask))
             return;
 
         if (!TryDeconstructWithToolQualities(tileRef, tool.Qualities))
             return;
 
         AdminLogger.Add(LogType.LatticeCut, LogImpact.Medium,
-                $"{ToPrettyString(args.User):player} used {ToPrettyString(ent)} to edit the tile at {args.Coordinates}");
+                $"{ToPrettyString(args.User):player} used {ToPrettyString(ent)} to edit the tile at {coords}");
         args.Handled = true;
     }
 
@@ -66,7 +66,7 @@ public abstract partial class SharedToolSystem
         var comp = ent.Comp1!;
         var tool = ent.Comp2!;
 
-        if (!_mapManager.TryFindGridAt(clickLocation.ToMap(EntityManager, _transformSystem), out var gridUid, out var mapGrid))
+        if (!_mapManager.TryFindGridAt(_transformSystem.ToMapCoordinates(clickLocation), out var gridUid, out var mapGrid))
             return false;
 
         var tileRef = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
@@ -85,7 +85,7 @@ public abstract partial class SharedToolSystem
         if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
             return false;
 
-        var args = new TileToolDoAfterEvent(GetNetCoordinates(coordinates));
+        var args = new TileToolDoAfterEvent(GetNetEntity(gridUid), tileRef.GridIndices);
         UseTool(ent, user, ent, comp.Delay, tool.Qualities, args, out _, toolComponent: tool);
         return true;
     }
index 72e984fd82a12e194d1d49aef5907d81644da9a6..56ce81413fb5c90bc689e0bff5694305d9a24e54 100644 (file)
@@ -271,6 +271,11 @@ public abstract partial class SharedToolSystem : EntitySystem
 
             return new ToolDoAfterEvent(Fuel, evClone, OriginalTarget);
         }
+
+        public override bool IsDuplicate(DoAfterEvent other)
+        {
+            return other is ToolDoAfterEvent toolDoAfter && WrappedEvent.IsDuplicate(toolDoAfter.WrappedEvent);
+        }
     }
 
     [Serializable, NetSerializable]