Skip to content
Open
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
"preLaunchTask": "build"
}
]
}
}
33 changes: 32 additions & 1 deletion Content.Client/Atmos/AlignAtmosPipeLayers.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Content.Client.Construction;
using Content.Client.Hands.Systems; // WL-Changes: RPD
using Content.Shared.Atmos.Components;
using Content.Shared.Atmos.EntitySystems;
using Content.Shared.Construction.Prototypes;
using Content.Shared.RCD; // WL-Changes: RPD
using Content.Shared.RCD.Components; // WL-Changes: RPD
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Placement;
using Robust.Client.Placement.Modes;
using Robust.Client.Utility;
using Robust.Client.Player; // WL-Changes: RPD
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
Expand All @@ -29,11 +32,13 @@ public sealed partial class AlignAtmosPipeLayers : SnapgridCenter
[Dependency] private IPrototypeManager _protoManager = default!;
[Dependency] private IMapManager _mapManager = default!;
[Dependency] private IEyeManager _eyeManager = default!;
[Dependency] private IPlayerManager _playerManager = default!; // WL-Changes: pipe layers RPD

private readonly SharedMapSystem _mapSystem;
private readonly SharedTransformSystem _transformSystem;
private readonly SharedAtmosPipeLayersSystem _pipeLayersSystem;
private readonly SpriteSystem _spriteSystem;
private readonly HandsSystem _handsSystem; // WL-Changes: pipe layers RPD

private const float SearchBoxSize = 2f;
private EntityCoordinates _unalignedMouseCoords = default;
Expand All @@ -51,6 +56,7 @@ public AlignAtmosPipeLayers(PlacementManager pMan) : base(pMan)
_transformSystem = _entityManager.System<SharedTransformSystem>();
_pipeLayersSystem = _entityManager.System<SharedAtmosPipeLayersSystem>();
_spriteSystem = _entityManager.System<SpriteSystem>();
_handsSystem = _entityManager.System<HandsSystem>(); // WL-Changes: pipe layers RPD
}

/// <inheritdoc/>
Expand Down Expand Up @@ -172,14 +178,39 @@ private void UpdatePlacer(AtmosPipeLayer layer)
if (!currentProto.TryGetComponent<AtmosPipeLayersComponent>(out var atmosPipeLayers, _entityManager.ComponentFactory))
return;

// WL-Changes-start: pipe layers
Entity<RCDComponent>? rcd = null;

if (_playerManager.LocalSession?.AttachedEntity is { } player
&& _handsSystem.TryGetActiveItem(player, out var item)
&& _entityManager.TryGetComponent<RCDComponent>(item, out var rcdComp))
{
rcd = (item.Value, rcdComp);
}

if (!_pipeLayersSystem.TryGetAlternativePrototype(atmosPipeLayers, layer, out var newProtoId))
{
if (rcd is { } rcdEnt
&& rcdEnt.Comp.OverrideProtoId != null) // don't dirty if it already null
_entityManager.RaisePredictiveEvent(new RCDOverrideProtoIdEvent(_entityManager.GetNetEntity(rcd.Value.Owner), null));
return;
}
// WL-Changes-end

if (_protoManager.TryIndex<EntityPrototype>(newProtoId, out var newProto))
{
// Update the placed prototype
pManager.CurrentPermission.EntityType = newProtoId;

// WL-Changes-start: RPD pipe layers
if (rcd is { } rcdEnt
&& rcdEnt.Comp.OverrideProtoId != (string?)newProtoId)
{
rcdEnt.Comp.OverrideProtoId = newProtoId;
_entityManager.RaisePredictiveEvent(new RCDOverrideProtoIdEvent(_entityManager.GetNetEntity(rcdEnt.Owner), newProtoId));
}
// WL-Changes-end

// Update the appearance of the ghost sprite
if (newProto.TryGetComponent<SpriteComponent>(out var sprite, _entityManager.ComponentFactory))
{
Expand Down
68 changes: 57 additions & 11 deletions Content.Client/RCD/AlignRCDConstruction.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
using System.Numerics;
using Content.Client.Atmos; // WL-Changes: RPD
using Content.Client.Gameplay;
using Content.Client.Hands.Systems;
using Content.Shared.Hands.Components;
using Content.Shared.Atmos.Components; // WL-Changes: RPD
using Content.Shared.Interaction;
using Content.Shared.RCD; // WL-Changes: RPD
using Content.Shared.RCD.Components;
using Content.Shared.RCD.Systems;
using Robust.Client.Graphics; // WL-Changes: RPD
using Robust.Client.Placement;
using Robust.Client.Player;
using Robust.Client.State;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes; // WL-Changes: RPD

namespace Content.Client.RCD;

public sealed partial class AlignRCDConstruction : PlacementMode
{
[Dependency] private IEntityManager _entityManager = default!;
[Dependency] private IMapManager _mapManager = default!;
// WL-Changes-start: pipe layers RPD
[Dependency] private IPlayerManager _playerManager = default!;
[Dependency] private IStateManager _stateManager = default!;
[Dependency] private IPrototypeManager _protoManager = default!;
// WL-Changes-end
private readonly SharedMapSystem _mapSystem;
private readonly HandsSystem _handsSystem;
private readonly RCDSystem _rcdSystem;
private readonly SharedTransformSystem _transformSystem;
[Dependency] private IPlayerManager _playerManager = default!;
[Dependency] private IStateManager _stateManager = default!;
private AlignAtmosPipeLayers _pipeLayers; // WL-Changes: pipe layers RPD

private const float SearchBoxSize = 2f;
private const float PlaceColorBaseAlpha = 0.5f;
Expand All @@ -39,12 +47,48 @@ public AlignRCDConstruction(PlacementManager pMan) : base(pMan)
_handsSystem = _entityManager.System<HandsSystem>();
_rcdSystem = _entityManager.System<RCDSystem>();
_transformSystem = _entityManager.System<SharedTransformSystem>();
_pipeLayers = new AlignAtmosPipeLayers(pMan); // WL-Changes: pipe layers RPD

ValidPlaceColor = ValidPlaceColor.WithAlpha(PlaceColorBaseAlpha);
}

// WL-Changes-start: pipe layers
public override void Render(in OverlayDrawArgs args)
{
if (pManager.CurrentPermission?.EntityType is { } entType
&& _protoManager.TryIndex<EntityPrototype>(entType, out var currentProto)
&& currentProto.TryGetComponent<AtmosPipeLayersComponent>(out _, _entityManager.ComponentFactory))
{
_pipeLayers.Render(args);
return;
}

base.Render(args);
}
// WL-Changes-end

public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
{
// WL-Changes-start: RPD pipe layers
if (pManager.CurrentPermission?.EntityType is { } entType
&& _protoManager.TryIndex<EntityPrototype>(entType, out var curProto))
{
if (curProto.TryGetComponent<AtmosPipeLayersComponent>(out _, _entityManager.ComponentFactory))
{
_pipeLayers.AlignPlacementMode(mouseScreen);
return;
}
else
{
if (_playerManager.LocalSession?.AttachedEntity is { } player
&& _handsSystem.TryGetActiveItem(player, out var item)
&& _entityManager.TryGetComponent<RCDComponent>(item.Value, out var rcdComp)
&& rcdComp.OverrideProtoId != null)
_entityManager.RaisePredictiveEvent(new RCDOverrideProtoIdEvent(_entityManager.GetNetEntity(item.Value), null));
}
}
// WL-Changes-end

_unalignedMouseCoords = ScreenToCursorGrid(mouseScreen);
MouseCoords = _unalignedMouseCoords.AlignWithClosestGridTile(SearchBoxSize, _entityManager, _mapManager);

Expand Down Expand Up @@ -78,7 +122,16 @@ public override bool IsValidPosition(EntityCoordinates position)
if (!_entityManager.TryGetComponent<TransformComponent>(player, out var xform))
return false;

if (!_transformSystem.InRange(xform.Coordinates, position, SharedInteractionSystem.InteractionRange))
// WL-Changes-start: rescheduled
if (!_handsSystem.TryGetActiveItem(player.Value, out var heldEntity))
return false;

if (!_entityManager.TryGetComponent<RCDComponent>(heldEntity, out var rcd))
return false;

// SharedInteractionSystem.InteractionRange -> rcd.Range > 0 ? rcd.Range : SharedInteractionSystem.MaxRaycastRange
if (!_transformSystem.InRange(xform.Coordinates, position, rcd.Range > 0 ? rcd.Range : SharedInteractionSystem.MaxRaycastRange))
// WL-Changes-end
{
InvalidPlaceColor = InvalidPlaceColor.WithAlpha(0);
return false;
Expand All @@ -90,13 +143,6 @@ public override bool IsValidPosition(EntityCoordinates position)
InvalidPlaceColor = InvalidPlaceColor.WithAlpha(PlaceColorBaseAlpha);
}

// Determine if player is carrying an RCD in their active hand
if (!_handsSystem.TryGetActiveItem(player.Value, out var heldEntity))
return false;

if (!_entityManager.TryGetComponent<RCDComponent>(heldEntity, out var rcd))
return false;

var gridUid = _transformSystem.GetGrid(position);
if (!_entityManager.TryGetComponent<MapGridComponent>(gridUid, out var mapGrid))
return false;
Expand Down
89 changes: 85 additions & 4 deletions Content.Client/RCD/RCDConstructionGhostSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System.ComponentModel.Design;
using Content.Client.Hands.Systems;
using Content.Shared.Input; // WL-Changes: RPD
using Content.Shared.Interaction;
using Content.Shared.RCD;
using Content.Shared.RCD.Components;
using Robust.Client.Placement;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Input; // WL-Changes: RPD
using Robust.Shared.Input.Binding; // WL-Changes: RPD
using Robust.Shared.Prototypes;

namespace Content.Client.RCD;
Expand All @@ -22,6 +26,54 @@ public sealed partial class RCDConstructionGhostSystem : EntitySystem
[Dependency] private HandsSystem _hands = default!;

private Direction _placementDirection = default;
// WL-Changes-start: RPD port from Goob-Station
private bool _useMirrorPrototype;
private EntityUid? _lastPlacer; // WL-Changes: fix network issue
public override void Initialize()
{
base.Initialize();

CommandBinds.Builder
.Bind(ContentKeyFunctions.EditorFlipObject,
new PointerInputCmdHandler(HandleFlip, outsidePrediction: true))
.Register<RCDConstructionGhostSystem>();
}

public override void Shutdown()
{
CommandBinds.Unregister<RCDConstructionGhostSystem>();
base.Shutdown();
}

private bool HandleFlip(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (args.State == BoundKeyState.Down)
{
if (!_placementManager.IsActive || _placementManager.Eraser)
return false;

var placerEntity = _placementManager.CurrentPermission?.MobUid;

if (!TryComp<RCDComponent>(placerEntity, out var rcd))
return false;

var prototype = _protoManager.Index(rcd.ProtoId);
if (string.IsNullOrEmpty(prototype.MirrorPrototype))
return false;

_useMirrorPrototype = !_useMirrorPrototype;

var useProto = _useMirrorPrototype ? prototype.MirrorPrototype : prototype.Prototype;
CreatePlacer(placerEntity.Value, rcd, useProto, prototype.Mode);

// tell the server

RaiseNetworkEvent(new RCDConstructionGhostFlipEvent(GetNetEntity(placerEntity.Value), _useMirrorPrototype));
}

return true;
}
// WL-Changes-end

public override void Update(float frameTime)
{
Expand Down Expand Up @@ -57,29 +109,58 @@ public override void Update(float frameTime)
}
var prototype = _protoManager.Index(rcd.ProtoId);

// WL-Changes-start: fix network issue
if (_lastPlacer != heldEntity)
{
_useMirrorPrototype = rcd.UseMirrorPrototype;
_lastPlacer = heldEntity;
}
// Wl-Changes-end

// Update the direction the RCD prototype based on the placer direction
if (_placementDirection != _placementManager.Direction)
{
_placementDirection = _placementManager.Direction;
RaiseNetworkEvent(new RCDConstructionGhostRotationEvent(GetNetEntity(heldEntity.Value), _placementDirection));
}

// If the placer has not changed, exit
if (heldEntity == placerEntity && prototype.Prototype == placerProto)
return;
// WL-Changes-start: RPD port from Goob-Station
// If the placer has not changed, build it
var useProto = (_useMirrorPrototype && !string.IsNullOrEmpty(prototype.MirrorPrototype)) ? prototype.MirrorPrototype : prototype.Prototype;
if (heldEntity != placerEntity || useProto != placerProto)
CreatePlacer(heldEntity.Value, rcd, useProto, prototype.Mode);

/* moved into another method
// Create a new placer
var newObjInfo = new PlacementInformation
{
MobUid = heldEntity.Value,
PlacementOption = PlacementMode,
EntityType = prototype.Prototype,
Range = (int)Math.Ceiling(SharedInteractionSystem.InteractionRange),
IsTile = (prototype.Mode == RcdMode.ConstructTile),
IsTile = prototype.Mode == RcdMode.ConstructTile,
UseEditorContext = false,
};

_placementManager.Clear();
_placementManager.BeginPlacing(newObjInfo);
*/
}

private void CreatePlacer(EntityUid uid, RCDComponent component, string? prototype, RcdMode mode)
{
var newObjInfo = new PlacementInformation
{
MobUid = uid,
PlacementOption = PlacementMode,
EntityType = component.OverrideProtoId ?? prototype, // WL-Changes: pipe layers
Range = (int)Math.Ceiling(component.Range > 0 ? component.Range : SharedInteractionSystem.MaxRaycastRange),
IsTile = mode == RcdMode.ConstructTile,
UseEditorContext = false
};

_placementManager.Clear();
_placementManager.BeginPlacing(newObjInfo);
}
// WL-Changes-end
}
Loading
Loading