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

Prevent virtual item storage and popups #30020

Merged
Merged
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
11 changes: 6 additions & 5 deletions Content.Shared/Interaction/SmartEquipSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,22 @@ private void HandleSmartEquip(ICommonSession? session, string equipmentSlot)
if (playerSession.AttachedEntity is not { Valid: true } uid || !Exists(uid))
return;

if (!_actionBlocker.CanInteract(uid, null))
return;

// early out if we don't have any hands or a valid inventory slot
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null)
return;

var handItem = hands.ActiveHand.HeldEntity;

// can the user interact, and is the item interactable? e.g. virtual items
if (!_actionBlocker.CanInteract(uid, handItem))
return;

if (!TryComp<InventoryComponent>(uid, out var inventory) || !_inventory.HasSlot(uid, equipmentSlot, inventory))
{
_popup.PopupClient(Loc.GetString("smart-equip-missing-equipment-slot", ("slotName", equipmentSlot)), uid, uid);
return;
}

var handItem = hands.ActiveHand.HeldEntity;

// early out if we have an item and cant drop it at all
if (handItem != null && !_hands.CanDropHeld(uid, hands.ActiveHand))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.Hands;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Popups;
Expand Down Expand Up @@ -43,6 +44,7 @@ public override void Initialize()
SubscribeLocalEvent<VirtualItemComponent, BeingUnequippedAttemptEvent>(OnBeingUnequippedAttempt);

SubscribeLocalEvent<VirtualItemComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
SubscribeLocalEvent<VirtualItemComponent, GettingInteractedWithAttemptEvent>(OnGettingInteractedWithAttemptEvent);
}

/// <summary>
Expand Down Expand Up @@ -72,6 +74,12 @@ private void OnBeforeRangedInteract(Entity<VirtualItemComponent> ent, ref Before
args.Handled = true;
}

private void OnGettingInteractedWithAttemptEvent(Entity<VirtualItemComponent> ent, ref GettingInteractedWithAttemptEvent args)
{
// No interactions with a virtual item, please.
args.Cancelled = true;
}

#region Hands

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Virtual/virtual_item.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
noSpawn: true
components:
- type: Item
size: Ginormous # no storage insertion visuals
Comment on lines 7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing logic for drawing the item grid preview doesn't check action blocker (StorageContainer.cs line 341).

I could add that check, which would get run a lot in a FrameUpdate(). I thought that might be expensive, so setting the size to Ginormous achieves the same thing of hiding the grid preview.

I can switch to that solution if you prefer. I could also update that yml comment to be clearer.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I was almost tempted to say it should probably have its own thing but I also realised the effort is likely not worth the separation.

- type: VirtualItem
Loading