Beispiel #1
0
 private void OnVisualsChanged(EntityUid uid, HandsComponent component, VisualsChangedEvent args)
 {
     // update hands visuals if this item is in a hand (rather then inventory or other container).
     if (component.TryGetHand(args.ContainerId, out var hand))
     {
         UpdateHandVisuals(uid, args.Item, hand, component);
     }
 }
        /// <summary>
        ///     Called when a user clicked on their hands GUI
        /// </summary>
        public void UIHandClick(HandsComponent hands, string handName)
        {
            if (!hands.TryGetHand(handName, out var pressedHand))
            {
                return;
            }

            if (!hands.TryGetActiveHand(out var activeHand))
            {
                return;
            }

            var pressedEntity = pressedHand.HeldEntity;
            var activeEntity  = activeHand.HeldEntity;

            if (pressedHand == activeHand && activeEntity != null)
            {
                // use item in hand
                // it will always be attack_self() in my heart.
                RaiseNetworkEvent(new UseInHandMsg());
                return;
            }

            if (pressedHand != activeHand && pressedEntity == null)
            {
                // change active hand
                EntityManager.RaisePredictiveEvent(new RequestSetHandEvent(handName));
                return;
            }

            if (pressedHand != activeHand && pressedEntity != null && activeEntity != null)
            {
                // use active item on held item
                RaiseNetworkEvent(new ClientInteractUsingInHandMsg(pressedHand.Name));
                return;
            }

            if (pressedHand != activeHand && pressedEntity != default && activeEntity == default)
            {
                // use active item on held item
                RaiseNetworkEvent(new MoveItemFromHandMsg(pressedHand.Name));
            }
        }