コード例 #1
0
        /// <summary>
        /// Uses a item/object on an entity
        /// Finds components with the InteractUsing interface and calls their function
        /// NOTE: Does not have an InRangeUnobstructed check
        /// </summary>
        public async void InteractUsing(
            EntityUid user,
            EntityUid used,
            EntityUid target,
            EntityCoordinates clickLocation,
            bool checkCanInteract = true,
            bool checkCanUse      = true)
        {
            if (checkCanInteract && !_actionBlockerSystem.CanInteract(user, target))
            {
                return;
            }

            if (checkCanUse && !_actionBlockerSystem.CanUseHeldEntity(user))
            {
                return;
            }

            if (RangedInteractDoBefore(user, used, target, clickLocation, true))
            {
                return;
            }

            // all interactions should only happen when in range / unobstructed, so no range check is needed
            var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);

            RaiseLocalEvent(target, interactUsingEvent, true);
            if (interactUsingEvent.Handled)
            {
                return;
            }

            InteractDoAfter(user, used, target, clickLocation, canReach: true);
        }
コード例 #2
0
        /// <summary>
        /// Uses a item/object on an entity
        /// Finds components with the InteractUsing interface and calls their function
        /// NOTE: Does not have an InRangeUnobstructed check
        /// </summary>
        public async void InteractUsing(
            EntityUid user,
            EntityUid used,
            EntityUid target,
            EntityCoordinates clickLocation,
            bool predicted        = false,
            bool checkCanInteract = true,
            bool checkCanUse      = true)
        {
            if (checkCanInteract && !_actionBlockerSystem.CanInteract(user, target))
            {
                return;
            }

            if (checkCanUse && !_actionBlockerSystem.CanUseHeldEntity(user))
            {
                return;
            }

            if (RangedInteractDoBefore(user, used, target, clickLocation, true))
            {
                return;
            }

            // all interactions should only happen when in range / unobstructed, so no range check is needed
            var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation, predicted);

            RaiseLocalEvent(target, interactUsingEvent);
            if (interactUsingEvent.Handled)
            {
                return;
            }

            var interactUsingEventArgs = new InteractUsingEventArgs(user, clickLocation, used, target);

            var interactUsings = AllComps <IInteractUsing>(target).OrderByDescending(x => x.Priority);

            foreach (var interactUsing in interactUsings)
            {
                // If an InteractUsing returns a status completion we finish our interaction
                if (await interactUsing.InteractUsing(interactUsingEventArgs))
                {
                    return;
                }
            }

            InteractDoAfter(user, used, target, clickLocation, canReach: true);
        }
コード例 #3
0
        /// <summary>
        /// Uses a item/object on an entity
        /// Finds components with the InteractUsing interface and calls their function
        /// NOTE: Does not have an InRangeUnobstructed check
        /// </summary>
        public async Task InteractUsing(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation)
        {
            if (!_actionBlockerSystem.CanInteract(user))
            {
                return;
            }

            if (InteractDoBefore(user, used, target, clickLocation, true))
            {
                return;
            }

            // all interactions should only happen when in range / unobstructed, so no range check is needed
            var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);

            RaiseLocalEvent(target, interactUsingEvent);
            if (interactUsingEvent.Handled)
            {
                return;
            }

            var interactUsingEventArgs = new InteractUsingEventArgs(user, clickLocation, used, target);

            var interactUsings = AllComps <IInteractUsing>(target).OrderByDescending(x => x.Priority);

            foreach (var interactUsing in interactUsings)
            {
                // If an InteractUsing returns a status completion we finish our interaction
                if (await interactUsing.InteractUsing(interactUsingEventArgs))
                {
                    return;
                }
            }

            // If we aren't directly interacting with the nearby object, lets see if our item has an after interact we can do
            await InteractDoAfter(user, used, target, clickLocation, true);
        }