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); } }
/// <summary> /// This function gets called when the user clicked on an item in the storage UI. This will either place the /// item in the user's hand if it is currently empty, or interact with the item using the user's currently /// held item. /// </summary> private void OnInteractWithItem(EntityUid uid, ServerStorageComponent storageComp, StorageInteractWithItemEvent args) { // TODO move this to shared for prediction. if (args.Session.AttachedEntity is not EntityUid player) { return; } if (!_actionBlockerSystem.CanInteract(player, args.InteractedItemUID)) { return; } if (storageComp.Storage == null || !storageComp.Storage.Contains(args.InteractedItemUID)) { return; } // Does the player have hands? if (!TryComp(player, out HandsComponent? hands) || hands.Count == 0) { return; } // If the user's active hand is empty, try pick up the item. if (hands.ActiveHandEntity == null) { if (_sharedHandsSystem.TryPickupAnyHand(player, args.InteractedItemUID, handsComp: hands) && storageComp.StorageRemoveSound != null) { SoundSystem.Play(storageComp.StorageRemoveSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, AudioParams.Default); } return; } // Else, interact using the held item _interactionSystem.InteractUsing(player, hands.ActiveHandEntity.Value, args.InteractedItemUID, Transform(args.InteractedItemUID).Coordinates, checkCanInteract: false); }