示例#1
0
        protected void InteractionActivate(EntityUid user, EntityUid used)
        {
            if (EntityManager.TryGetComponent <UseDelayComponent?>(used, out var delayComponent))
            {
                if (delayComponent.ActiveDelay)
                {
                    return;
                }

                delayComponent.BeginDelay();
            }

            if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user))
            {
                return;
            }

            // all activates should only fire when in range / unobstructed
            if (!InRangeUnobstructed(user, used, ignoreInsideBlocker: true, popup: true))
            {
                return;
            }

            // Check if interacted entity is in the same container, the direct child, or direct parent of the user.
            // This is bypassed IF the interaction happened through an item slot (e.g., backpack UI)
            if (!user.IsInSameOrParentContainer(used) && !CanAccessViaStorage(user, used))
            {
                return;
            }

            var activateMsg = new ActivateInWorldEvent(user, used);

            RaiseLocalEvent(used, activateMsg);
            if (activateMsg.Handled)
            {
                _adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{user} activated {used}");
                return;
            }

            if (!EntityManager.TryGetComponent(used, out IActivate? activateComp))
            {
                return;
            }

            var activateEventArgs = new ActivateEventArgs(user, used);

            activateComp.Activate(activateEventArgs);
            _adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{user} activated {used}"); // No way to check success.
        }
        protected void InteractionActivate(IEntity user, IEntity used)
        {
            if (used.TryGetComponent <UseDelayComponent>(out var delayComponent))
            {
                if (delayComponent.ActiveDelay)
                {
                    return;
                }

                delayComponent.BeginDelay();
            }

            if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user))
            {
                return;
            }

            // all activates should only fire when in range / unobstructed
            if (!InRangeUnobstructed(user, used, ignoreInsideBlocker: true, popup: true))
            {
                return;
            }

            var activateMsg = new ActivateInWorldEvent(user, used);

            RaiseLocalEvent(used.Uid, activateMsg);
            if (activateMsg.Handled)
            {
                return;
            }

            if (!used.TryGetComponent(out IActivate? activateComp))
            {
                return;
            }

            var activateEventArgs = new ActivateEventArgs(user, used);

            activateComp.Activate(activateEventArgs);
        }