You can now pry multiple tiles at once (#29231)
* 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.
This commit is contained in:
committed by
GitHub
parent
d15eafe133
commit
cf374ac905
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user