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 EntityUid? Used => DoAfter.Args.Used;
|
||||||
public DoAfterArgs Args => DoAfter.Args;
|
public DoAfterArgs Args => DoAfter.Args;
|
||||||
#endregion
|
#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>
|
/// <summary>
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((conditions & DuplicateConditions.SameEvent) != 0
|
if ((conditions & DuplicateConditions.SameEvent) != 0
|
||||||
&& args.Event.GetType() != otherArgs.Event.GetType())
|
&& !args.Event.IsDuplicate(otherArgs.Event))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,15 +30,24 @@ public sealed partial class ToolTileCompatibleComponent : Component
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed partial class TileToolDoAfterEvent : DoAfterEvent
|
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()
|
public override DoAfterEvent Clone()
|
||||||
{
|
{
|
||||||
return this;
|
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))
|
if (!TryComp<ToolComponent>(ent, out var tool))
|
||||||
return;
|
return;
|
||||||
var coordinates = GetCoordinates(args.Coordinates);
|
|
||||||
|
|
||||||
var gridUid = coordinates.GetGridUid(EntityManager);
|
var gridUid = GetEntity(args.Grid);
|
||||||
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
||||||
{
|
{
|
||||||
Log.Error("Attempted use tool on a non-existent grid?");
|
Log.Error("Attempted use tool on a non-existent grid?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tileRef = _maps.GetTileRef(gridUid.Value, grid, coordinates);
|
var tileRef = _maps.GetTileRef(gridUid, grid, args.GridTile);
|
||||||
if (comp.RequiresUnobstructed && _turfs.IsTileBlocked(gridUid.Value, tileRef.GridIndices, CollisionGroup.MobMask))
|
var coords = _maps.ToCoordinates(tileRef, grid);
|
||||||
|
if (comp.RequiresUnobstructed && _turfs.IsTileBlocked(gridUid, tileRef.GridIndices, CollisionGroup.MobMask))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!TryDeconstructWithToolQualities(tileRef, tool.Qualities))
|
if (!TryDeconstructWithToolQualities(tileRef, tool.Qualities))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AdminLogger.Add(LogType.LatticeCut, LogImpact.Medium,
|
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;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public abstract partial class SharedToolSystem
|
|||||||
var comp = ent.Comp1!;
|
var comp = ent.Comp1!;
|
||||||
var tool = ent.Comp2!;
|
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;
|
return false;
|
||||||
|
|
||||||
var tileRef = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
|
var tileRef = _maps.GetTileRef(gridUid, mapGrid, clickLocation);
|
||||||
@@ -85,7 +85,7 @@ public abstract partial class SharedToolSystem
|
|||||||
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
if (!InteractionSystem.InRangeUnobstructed(user, coordinates, popup: false))
|
||||||
return 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);
|
UseTool(ent, user, ent, comp.Delay, tool.Qualities, args, out _, toolComponent: tool);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,6 +271,11 @@ public abstract partial class SharedToolSystem : EntitySystem
|
|||||||
|
|
||||||
return new ToolDoAfterEvent(Fuel, evClone, OriginalTarget);
|
return new ToolDoAfterEvent(Fuel, evClone, OriginalTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsDuplicate(DoAfterEvent other)
|
||||||
|
{
|
||||||
|
return other is ToolDoAfterEvent toolDoAfter && WrappedEvent.IsDuplicate(toolDoAfter.WrappedEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
Reference in New Issue
Block a user