コード例 #1
0
 private void OnDisarmAttemptEvent(EntityUid uid, WieldableComponent component, DisarmAttemptEvent args)
 {
     if (component.Wielded)
     {
         args.Cancel();
     }
 }
コード例 #2
0
 private void OnUseInHand(EntityUid uid, WieldableComponent component, UseInHandEvent args)
 {
     if (args.Handled)
     {
         return;
     }
     if (!component.Wielded)
     {
         AttemptWield(uid, component, args.User);
     }
     else
     {
         AttemptUnwield(uid, component, args.User);
     }
 }
コード例 #3
0
        /// <summary>
        ///     Attempts to wield an item, creating a DoAfter..
        /// </summary>
        public void AttemptWield(EntityUid used, WieldableComponent component, EntityUid user)
        {
            if (!CanWield(used, component, user))
            {
                return;
            }
            var ev = new BeforeWieldEvent();

            RaiseLocalEvent(used, ev, false);

            if (ev.Cancelled)
            {
                return;
            }

            var doargs = new DoAfterEventArgs(
                user,
                component.WieldTime,
コード例 #4
0
        private void AddToggleWieldVerb(EntityUid uid, WieldableComponent component, GetInteractionVerbsEvent args)
        {
            if (args.Hands == null || !args.CanAccess || !args.CanInteract)
            {
                return;
            }

            // TODO VERB TOOLTIPS Make CanWield or some other function return string, set as verb tooltip and disable
            // verb. Or just don't add it to the list if the action is not executable.

            Verb verb = new();

            // TODO VERBS ICON + localization
            verb.Text = component.Wielded ? "Unwield" : "Wield";
            verb.Act  = component.Wielded
                ? () => AttemptUnwield(component.Owner.Uid, component, args.User)
                : () => AttemptWield(component.Owner.Uid, component, args.User);

            args.Verbs.Add(verb);
        }
コード例 #5
0
        public bool CanWield(EntityUid uid, WieldableComponent component, EntityUid user, bool quiet = false)
        {
            // Do they have enough hands free?
            if (!EntityManager.TryGetComponent <HandsComponent>(user, out var hands))
            {
                if (!quiet)
                {
                    user.PopupMessage(Loc.GetString("wieldable-component-no-hands"));
                }
                return(false);
            }

            if (hands.CountFreeHands()
                < component.FreeHandsRequired)
            {
                // TODO FLUENT need function to change 'hands' to 'hand' when there's only 1 required
                if (!quiet)
                {
                    user.PopupMessage(Loc.GetString("wieldable-component-not-enough-free-hands",
                                                    ("number", component.FreeHandsRequired),
                                                    ("item", uid)));
                }

                return(false);
            }

            // Is it.. actually in one of their hands?
            if (!_handsSystem.IsHolding(user, uid, out _, hands))
            {
                if (!quiet)
                {
                    user.PopupMessage(Loc.GetString("wieldable-component-not-in-hands", ("item", uid)));
                }

                return(false);
            }

            // Seems legit.
            return(true);
        }