/// <summary> /// Will attempt to equip or unequip an item to/from the clicked slot. If the user clicked on an occupied slot /// with some entity, will instead attempt to interact with this entity. /// </summary> private void OnUseSlot(UseSlotNetworkMessage ev, EntitySessionEventArgs eventArgs) { if (eventArgs.SenderSession.AttachedEntity is not EntityUid { Valid : true } actor) { return; } if (!TryComp(actor, out InventoryComponent? inventory) || !TryComp <SharedHandsComponent>(actor, out var hands)) { return; } hands.TryGetActiveHeldEntity(out var held); TryGetSlotEntity(actor, ev.Slot, out var itemUid, inventory); // attempt to perform some interaction if (held != null && itemUid != null) { _interactionSystem.InteractUsing(actor, held.Value, itemUid.Value, new EntityCoordinates(), predicted: true); return; } // un-equip to hands if (itemUid != null) { if (hands.CanPickupEntityToActiveHand(itemUid.Value) && TryUnequip(actor, ev.Slot, inventory: inventory)) { hands.PutInHand(itemUid.Value, false); } return; } // finally, just try to equip the held item. if (held == null) { return; } // before we drop the item, check that it can be equipped in the first place. if (!CanEquip(actor, held.Value, ev.Slot, out var reason)) { if (_gameTiming.IsFirstTimePredicted) { _popup.PopupCursor(Loc.GetString(reason), Filter.Local()); } return; } if (hands.TryDropNoInteraction()) { TryEquip(actor, actor, held.Value, ev.Slot, predicted: true, inventory: inventory); } }
private void OnUseSlot(UseSlotNetworkMessage ev) { if (!TryComp <HandsComponent>(ev.Uid, out var hands) || !TryGetSlotEntity(ev.Uid, ev.Slot, out var itemUid)) { return; } var activeHand = hands.GetActiveHandItem; if (activeHand != null) { _interactionSystem.InteractUsing(ev.Uid, activeHand.Owner, itemUid.Value, new EntityCoordinates()); } else if (TryUnequip(ev.Uid, ev.Slot)) { hands.PutInHand(itemUid.Value); } }