HandsSystem Refactor (#38438)
* checkpoint * pt 2 * pt... i forgot * pt 4 * patch * More test fixes * optimization!!! * the REAL hand system * fix RetractableItemActionSystem.cs oversight * the review * test * remove test usage of body prototype * Update Content.IntegrationTests/Tests/Interaction/InteractionTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * hellcode * hellcode 2 * Minor cleanup * test * Chasing the last of the bugs * changes --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
This commit is contained in:
@@ -83,7 +83,7 @@ public abstract partial class InventorySystem
|
||||
if (!TryComp(actor, out InventoryComponent? inventory) || !TryComp<HandsComponent>(actor, out var hands))
|
||||
return;
|
||||
|
||||
var held = hands.ActiveHandEntity;
|
||||
var held = _handsSystem.GetActiveItem((actor, hands));
|
||||
TryGetSlotEntity(actor, ev.Slot, out var itemUid, inventory);
|
||||
|
||||
// attempt to perform some interaction
|
||||
@@ -115,7 +115,7 @@ public abstract partial class InventorySystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_handsSystem.CanDropHeld(actor, hands.ActiveHand!, checkActionBlocker: false))
|
||||
if (!_handsSystem.CanDropHeld(actor, hands.ActiveHandId!, checkActionBlocker: false))
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(held.Value, new HandDeselectedEvent(actor));
|
||||
|
||||
@@ -16,12 +16,9 @@ public partial class InventorySystem
|
||||
{
|
||||
if (Resolve(user.Owner, ref user.Comp1, false))
|
||||
{
|
||||
foreach (var hand in user.Comp1.Hands.Values)
|
||||
foreach (var held in _handsSystem.EnumerateHeld(user))
|
||||
{
|
||||
if (hand.HeldEntity == null)
|
||||
continue;
|
||||
|
||||
yield return hand.HeldEntity.Value;
|
||||
yield return held;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
@@ -8,7 +7,6 @@ using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Inventory.VirtualItem;
|
||||
@@ -88,9 +86,9 @@ public abstract class SharedVirtualItemSystem : EntitySystem
|
||||
|
||||
// if the user is holding the real item the virtual item points to,
|
||||
// we allow them to use it in the interaction
|
||||
foreach (var hand in _handsSystem.EnumerateHands(args.User))
|
||||
foreach (var held in _handsSystem.EnumerateHeld(args.User))
|
||||
{
|
||||
if (hand.HeldEntity == ent.Comp.BlockingEntity)
|
||||
if (held == ent.Comp.BlockingEntity)
|
||||
{
|
||||
args.Used = ent.Comp.BlockingEntity;
|
||||
return;
|
||||
@@ -112,7 +110,7 @@ public abstract class SharedVirtualItemSystem : EntitySystem
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TrySpawnVirtualItemInHand(Robust.Shared.GameObjects.EntityUid,Robust.Shared.GameObjects.EntityUid,bool)"/>
|
||||
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user, [NotNullWhen(true)] out EntityUid? virtualItem, bool dropOthers = false, Hand? empty = null)
|
||||
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user, [NotNullWhen(true)] out EntityUid? virtualItem, bool dropOthers = false, string? empty = null)
|
||||
{
|
||||
virtualItem = null;
|
||||
if (empty == null && !_handsSystem.TryGetEmptyHand(user, out empty))
|
||||
@@ -122,7 +120,7 @@ public abstract class SharedVirtualItemSystem : EntitySystem
|
||||
|
||||
foreach (var hand in _handsSystem.EnumerateHands(user))
|
||||
{
|
||||
if (hand.HeldEntity is not { } held)
|
||||
if (!_handsSystem.TryGetHeldItem(user, hand, out var held))
|
||||
continue;
|
||||
|
||||
if (held == blockingEnt)
|
||||
@@ -155,11 +153,11 @@ public abstract class SharedVirtualItemSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void DeleteInHandsMatching(EntityUid user, EntityUid matching)
|
||||
{
|
||||
foreach (var hand in _handsSystem.EnumerateHands(user))
|
||||
foreach (var held in _handsSystem.EnumerateHeld(user))
|
||||
{
|
||||
if (TryComp(hand.HeldEntity, out VirtualItemComponent? virt) && virt.BlockingEntity == matching)
|
||||
if (TryComp(held, out VirtualItemComponent? virt) && virt.BlockingEntity == matching)
|
||||
{
|
||||
DeleteVirtualItem((hand.HeldEntity.Value, virt), user);
|
||||
DeleteVirtualItem((held, virt), user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user