コード例 #1
0
    private static bool CheckInteractInternal <T>(IBaseInteractable <T> interactable, T interaction,
                                                  NetworkSide side)
        where T : Interaction
    {
        if (Cooldowns.IsOn(interaction, CooldownID.Asset(CommonCooldowns.Instance.Interaction, side)))
        {
            return(false);
        }
        var result = false;

        //check if client side interaction should be triggered
        if (side == NetworkSide.Client && interactable is IClientInteractable <T> clientInteractable)
        {
            result = clientInteractable.Interact(interaction);
            if (result)
            {
                Logger.LogTraceFormat("ClientInteractable triggered from {0} on {1} for object {2}",
                                      Category.Interaction, typeof(T).Name, clientInteractable.GetType().Name,
                                      (clientInteractable as Component).gameObject.name);
                Cooldowns.TryStartClient(interaction, CommonCooldowns.Instance.Interaction);
                return(true);
            }
        }

        //check other kinds of interactions
        if (interactable is ICheckable <T> checkable)
        {
            result = checkable.WillInteract(interaction, side);
            if (result)
            {
                Logger.LogTraceFormat("WillInteract triggered from {0} on {1} for object {2}", Category.Interaction,
                                      typeof(T).Name, checkable.GetType().Name,
                                      (checkable as Component).gameObject.name);
                return(true);
            }
        }
        else if (interactable is IInteractable <T> )
        {
            //use default logic
            result = DefaultWillInteract.Default(interaction, side);
            if (result)
            {
                Logger.LogTraceFormat("WillInteract triggered from {0} on {1} for object {2}", Category.Interaction,
                                      typeof(T).Name, interactable.GetType().Name,
                                      (interactable as Component).gameObject.name);

                return(true);
            }
        }

        Logger.LogTraceFormat("No interaction triggered from {0} on {1} for object {2}", Category.Interaction,
                              typeof(T).Name, interactable.GetType().Name,
                              (interactable as Component).gameObject.name);

        return(false);
    }
コード例 #2
0
        public bool WillInteract(PositionalHandApply interaction, NetworkSide side)
        {
            if (DefaultWillInteract.Default(interaction, side) == false)
            {
                return(false);
            }
            // must be targeting us
            if (interaction.TargetObject != gameObject)
            {
                return(false);
            }
            // allowed to attack due to cooldown?
            // note: actual cooldown is started in WeaponNetworkActions melee logic on server side,
            // clientPredictInteraction on clientside
            if (side == NetworkSide.Client && Cooldowns.IsOn(interaction, CooldownID.Asset(CommonCooldowns.Instance.Melee, side)))
            {
                return(false);
            }

            bool LocalItemCheck()
            {
                return(interaction.HandObject.OrNull()?.Item().CanBeUsedOnSelfOnHelpIntent ?? false);
            }

            // not punching unless harm intent
            if (interaction.Intent != Intent.Harm && !LocalItemCheck())
            {
                return(false);
            }

            // if attacking tiles, only some layers are allowed to be attacked
            if (interactableTiles != null)
            {
                var tileAt = interactableTiles.LayerTileAt(interaction.WorldPositionTarget, true);

                // Nothing there, could be space?
                if (tileAt == null)
                {
                    return(false);
                }

                if (attackableLayers.Contains(tileAt.LayerType) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
    public bool WillInteract(PositionalHandApply interaction, NetworkSide side)
    {
        if (!DefaultWillInteract.Default(interaction, side))
        {
            return(false);
        }

        //Is melee on cooldown?
        if (Cooldowns.IsOn(interaction, CooldownID.Asset(CommonCooldowns.Instance.Melee, side)))
        {
            return(false);
        }

        return(true);
    }
コード例 #4
0
    public bool WillInteract(PositionalHandApply interaction, NetworkSide side)
    {
        //are we in range
        if (!DefaultWillInteract.Default(interaction, side))
        {
            return(false);
        }
        //must be targeting us
        if (interaction.TargetObject != gameObject)
        {
            return(false);
        }
        //allowed to attack due to cooldown?
        //note: actual cooldown is started in WeaponNetworkActions melee logic on server side,
        //clientPredictInteraction on clientside
        if (Cooldowns.IsOn(interaction, CooldownID.Asset(CommonCooldowns.Instance.Melee, side)))
        {
            interaction = PositionalHandApply.Invalid;
            return(true);
        }

        //not punching unless harm intent
        if (interaction.Intent != Intent.Harm)
        {
            return(false);
        }

        //if attacking tiles, only some layers are allowed to be attacked
        if (interactableTiles != null)
        {
            var tileAt = interactableTiles.LayerTileAt(interaction.WorldPositionTarget, true);

            //Nothing there, could be space?
            if (tileAt == null)
            {
                return(false);
            }

            if (!attackableLayers.Contains(tileAt.LayerType))
            {
                return(interaction.Intent == Intent.Harm && harmIntentOnlyAttackableLayers.Contains(tileAt.LayerType));
            }
        }

        return(true);
    }
コード例 #5
0
ファイル: InteractionUtils.cs プロジェクト: ewy0/unitystation
    private static bool CheckInteractInternal <T>(this IBaseInteractable <T> interactable, T interaction,
                                                  NetworkSide side, out bool wasClientInteractable)
        where T : Interaction
    {
        wasClientInteractable = false;
        //interactions targeting an object at hiddenpos are NEVER allowed (except for inventory actions,
        //since they can target an object in inventory which means its at hiddenpos)
        if (!(interaction is InventoryApply) && interaction is TargetedInteraction targetedInteraction)
        {
            if (targetedInteraction.TargetObject != null &&
                targetedInteraction.TargetObject.IsAtHiddenPos())
            {
                Logger.LogTraceFormat("Aborting {0} interaction on object {1} because the object is hidden.",
                                      Category.Interaction, typeof(T).Name, targetedInteraction.TargetObject.name);
                return(false);
            }
        }
        if (Cooldowns.IsOn(interaction, CooldownID.Asset(CommonCooldowns.Instance.Interaction, side)))
        {
            return(false);
        }
        var result = false;

        //check if client side interaction should be triggered
        if (side == NetworkSide.Client && interactable is IClientInteractable <T> clientInteractable)
        {
            result = clientInteractable.Interact(interaction);
            if (result)
            {
                Logger.LogTraceFormat("ClientInteractable triggered from {0} on {1} for object {2}", Category.Interaction, typeof(T).Name, clientInteractable.GetType().Name,
                                      (clientInteractable as Component).gameObject.name);
                Cooldowns.TryStartClient(interaction, CommonCooldowns.Instance.Interaction);
                wasClientInteractable = true;
                return(true);
            }
        }
        //check other kinds of interactions
        if (interactable is ICheckable <T> checkable)
        {
            result = checkable.WillInteract(interaction, side);
            if (result)
            {
                Logger.LogTraceFormat("WillInteract triggered from {0} on {1} for object {2}", Category.Interaction, typeof(T).Name, checkable.GetType().Name,
                                      (checkable as Component).gameObject.name);
                wasClientInteractable = false;
                return(true);
            }
        }
        else if (interactable is IInteractable <T> )
        {
            //use default logic
            result = DefaultWillInteract.Default(interaction, side);
            if (result)
            {
                Logger.LogTraceFormat("WillInteract triggered from {0} on {1} for object {2}", Category.Interaction, typeof(T).Name, interactable.GetType().Name,
                                      (interactable as Component).gameObject.name);
                wasClientInteractable = false;
                return(true);
            }
        }

        Logger.LogTraceFormat("No interaction triggered from {0} on {1} for object {2}", Category.Interaction, typeof(T).Name, interactable.GetType().Name,
                              (interactable as Component).gameObject.name);

        wasClientInteractable = false;
        return(false);
    }