Fix RCD not being able to place hull tiles in space (#42740)
Fall back on player's grid if RCD is clicked on empty space
This commit is contained in:
parent
f6a0ccc4a6
commit
a074566940
|
|
@ -145,7 +145,13 @@ public sealed class RCDSystem : EntitySystem
|
|||
if (!location.IsValid(EntityManager))
|
||||
return;
|
||||
|
||||
var gridUid = _transform.GetGrid(location);
|
||||
// Get grid corresponding to user's click location.
|
||||
// If that doesn't exist, try using the one they're standing on.
|
||||
// In the future we might want to also check adjacent spaces for grids,
|
||||
// in case the user is floating in space for whatever reason.
|
||||
var clickGridUid = _transform.GetGrid(location);
|
||||
var userGridUid = _transform.GetGrid(user);
|
||||
var gridUid = clickGridUid.HasValue ? clickGridUid : userGridUid;
|
||||
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var mapGrid))
|
||||
{
|
||||
|
|
@ -217,9 +223,14 @@ public sealed class RCDSystem : EntitySystem
|
|||
#endregion
|
||||
|
||||
// Try to start the do after
|
||||
var effect = Spawn(effectPrototype, location);
|
||||
var ev = new RCDDoAfterEvent(GetNetCoordinates(location), component.ConstructionDirection, component.ProtoId, cost, GetNetEntity(effect));
|
||||
|
||||
var effect = Spawn(effectPrototype, _mapSystem.ToCenterCoordinates(tile, mapGrid));
|
||||
var ev = new RCDDoAfterEvent(
|
||||
GetNetCoordinates(location),
|
||||
GetNetEntity(gridUid.Value),
|
||||
component.ConstructionDirection,
|
||||
component.ProtoId,
|
||||
cost,
|
||||
GetNetEntity(effect));
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager, user, delay, ev, uid, target: args.Target, used: uid)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
|
|
@ -249,9 +260,7 @@ public sealed class RCDSystem : EntitySystem
|
|||
}
|
||||
|
||||
// Ensure the RCD operation is still valid
|
||||
var location = GetCoordinates(args.Event.Location);
|
||||
|
||||
var gridUid = _transform.GetGrid(location);
|
||||
var gridUid = GetEntity(args.Event.TargetGridId);
|
||||
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var mapGrid))
|
||||
{
|
||||
|
|
@ -259,11 +268,11 @@ public sealed class RCDSystem : EntitySystem
|
|||
return;
|
||||
}
|
||||
|
||||
var location = GetCoordinates(args.Event.Location);
|
||||
var tile = _mapSystem.GetTileRef(gridUid, mapGrid, location);
|
||||
var position = _mapSystem.TileIndicesFor(gridUid, mapGrid, location);
|
||||
|
||||
var tile = _mapSystem.GetTileRef(gridUid.Value, mapGrid, location);
|
||||
var position = _mapSystem.TileIndicesFor(gridUid.Value, mapGrid, location);
|
||||
|
||||
if (!IsRCDOperationStillValid(uid, component, gridUid.Value, mapGrid, tile, position, args.Event.Direction, args.Event.Target, args.Event.User))
|
||||
if (!IsRCDOperationStillValid(uid, component, gridUid, mapGrid, tile, position, args.Event.Direction, args.Event.Target, args.Event.User))
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
|
|
@ -282,22 +291,23 @@ public sealed class RCDSystem : EntitySystem
|
|||
|
||||
args.Handled = true;
|
||||
|
||||
var location = GetCoordinates(args.Location);
|
||||
|
||||
var gridUid = _transform.GetGrid(location);
|
||||
var gridUid = GetEntity(args.TargetGridId);
|
||||
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var mapGrid))
|
||||
return;
|
||||
|
||||
var tile = _mapSystem.GetTileRef(gridUid.Value, mapGrid, location);
|
||||
var position = _mapSystem.TileIndicesFor(gridUid.Value, mapGrid, location);
|
||||
var location = GetCoordinates(args.Location);
|
||||
var tile = _mapSystem.GetTileRef(gridUid, mapGrid, location);
|
||||
var position = _mapSystem.TileIndicesFor(gridUid, mapGrid, location);
|
||||
|
||||
// Ensure the RCD operation is still valid
|
||||
if (!IsRCDOperationStillValid(uid, component, gridUid.Value, mapGrid, tile, position, args.Direction, args.Target, args.User))
|
||||
if (!IsRCDOperationStillValid(uid, component, gridUid, mapGrid, tile, position, args.Direction, args.Target, args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Finalize the operation (this should handle prediction properly)
|
||||
FinalizeRCDOperation(uid, component, gridUid.Value, mapGrid, tile, position, args.Direction, args.Target, args.User);
|
||||
FinalizeRCDOperation(uid, component, gridUid, mapGrid, tile, position, args.Direction, args.Target, args.User);
|
||||
|
||||
// Play audio and consume charges
|
||||
_audio.PlayPredicted(component.SuccessSound, uid, args.User);
|
||||
|
|
@ -652,6 +662,9 @@ public sealed partial class RCDDoAfterEvent : DoAfterEvent
|
|||
[DataField(required: true)]
|
||||
public NetCoordinates Location { get; private set; }
|
||||
|
||||
[DataField(required: true)]
|
||||
public NetEntity TargetGridId {get ; private set; }
|
||||
|
||||
[DataField]
|
||||
public Direction Direction { get; private set; }
|
||||
|
||||
|
|
@ -666,9 +679,17 @@ public sealed partial class RCDDoAfterEvent : DoAfterEvent
|
|||
|
||||
private RCDDoAfterEvent() { }
|
||||
|
||||
public RCDDoAfterEvent(NetCoordinates location, Direction direction, ProtoId<RCDPrototype> startingProtoId, int cost, NetEntity? effect = null)
|
||||
public RCDDoAfterEvent(
|
||||
NetCoordinates location,
|
||||
NetEntity targetGridId,
|
||||
Direction direction,
|
||||
ProtoId<RCDPrototype>
|
||||
startingProtoId,
|
||||
int cost,
|
||||
NetEntity? effect = null)
|
||||
{
|
||||
Location = location;
|
||||
TargetGridId = targetGridId;
|
||||
Direction = direction;
|
||||
StartingProtoId = startingProtoId;
|
||||
Cost = cost;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
parent: Plating
|
||||
name: tiles-rcd-plating
|
||||
baseWhitelist:
|
||||
- Space
|
||||
- TrainLattice
|
||||
- FloorPlanetDirt
|
||||
- FloorDesert
|
||||
|
|
|
|||
Loading…
Reference in New Issue