Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make moving items inside containers require an empty hand #32706

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Client.UserInterface.Systems.Storage.Controls;
using Content.Client.Verbs.UI;
using Content.Shared.CCVar;
using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.Item;
Expand Down Expand Up @@ -233,6 +234,15 @@ private void OnPiecePressed(GUIBoundKeyEventArgs args, ItemGridPiece control)

if (args.Function == ContentKeyFunctions.MoveStoredItem)
{
var handsSystem = _entity.System<HandsSystem>();

if (handsSystem.TryGetPlayerHands(out HandsComponent? handsComponent) &&
handsComponent.ActiveHandEntity != null)
{
args.Handle();
return;
}

DraggingRotation = control.Location.Rotation;

_menuDragHelper.MouseDown(control);
Expand Down
37 changes: 34 additions & 3 deletions Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,24 +631,34 @@ private void OnSetItemLocation(StorageSetItemLocationEvent msg, EntitySessionEve
if (!ValidateInput(args, msg.StorageEnt, msg.ItemEnt, out var player, out var storage, out var item))
return;

if (!ValidateEmptyHand(args, out var hand))
return;

if (_sharedHandsSystem.TryPickup(player, item, hand, animate: false, handsComp: player.Comp))
InsertAt(storage!, item!, msg.Location, out _, player, true, false);

_adminLog.Add(
LogType.Storage,
LogImpact.Low,
$"{ToPrettyString(player):player} is updating the location of {ToPrettyString(item):item} within {ToPrettyString(storage):storage}");

TrySetItemStorageLocation(item!, storage!, msg.Location);
}

private void OnRemoveItem(StorageRemoveItemEvent msg, EntitySessionEventArgs args)
{
if (!ValidateInput(args, msg.StorageEnt, msg.ItemEnt, out var player, out var storage, out var item))
return;

if (!ValidateEmptyHand(args, out var hand))
return;

_sharedHandsSystem.TryPickup(player, item, hand, animate: false, handsComp: player.Comp);

_adminLog.Add(
LogType.Storage,
LogImpact.Low,
$"{ToPrettyString(player):player} is removing {ToPrettyString(item):item} from {ToPrettyString(storage):storage}");
TransformSystem.DropNextTo(item.Owner, player.Owner);
_sharedHandsSystem.TryDrop(player, hand);

Audio.PlayPredicted(storage.Comp.StorageRemoveSound, storage, player, _audioParams);
}

Expand Down Expand Up @@ -1522,6 +1532,27 @@ private bool ValidateInput(EntitySessionEventArgs args,
return true;
}

/// <summary>
/// Check if the entity interacting with the container is doing so with an empty hand.
/// </summary>
private bool ValidateEmptyHand(EntitySessionEventArgs args, [NotNullWhen(true)] out Hand? emptyHand)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO a name like TryGetEmptyHand (to parallel TryComp) fits better with the out var semantics.
But at the same time I have next to no experience with out vars, so I dunno.

{
emptyHand = null;

if (args.SenderSession.AttachedEntity is not { } playerUid)
return false;

if (!TryComp(playerUid, out HandsComponent? hands) || hands.Count == 0)
return false;

if (hands.ActiveHand == null || hands.ActiveHand.HeldEntity != null)
return false;

emptyHand = hands.ActiveHand;

return true;
}

[Serializable, NetSerializable]
protected sealed class StorageComponentState : ComponentState
{
Expand Down
Loading