Esempio n. 1
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        //Server actions
        // Close the door if it's open
        if (!Controller.IsClosed)
        {
            Controller.ServerTryClose();
        }
        else
        {
            if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Welder))             // welding the door (only if closed and not helping)
            {
                if (Controller.IsWeldable)
                {
                    var welder = interaction.HandObject.GetComponent <Welder>();
                    if (welder.IsOn && interaction.Intent != Intent.Help)
                    {
                        void ProgressComplete()
                        {
                            if (Controller != null)
                            {
                                Chat.AddExamineMsgFromServer(interaction.Performer,
                                                             "You " + (Controller.IsWelded ? "unweld" : "weld") + " the door.");
                                Controller.ServerTryWeld();
                            }
                        }

                        var bar = StandardProgressAction.CreateForWelder(ProgressConfig, ProgressComplete, welder)
                                  .ServerStartProgress(interaction.Performer.transform.position, weldTime, interaction.Performer);
                        if (bar != null)
                        {
                            SoundManager.PlayNetworkedAtPos("Weld", interaction.Performer.transform.position, Random.Range(0.8f, 1.2f), sourceObj: interaction.Performer);
                            Chat.AddExamineMsgFromServer(interaction.Performer, "You start " + (Controller.IsWelded ? "unwelding" : "welding") + " the door...");
                        }

                        return;
                    }
                }
                else if (!Controller.IsAutomatic)
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start to disassemble the false wall...",
                                                              $"{interaction.Performer.ExpensiveName()} starts to disassemble the false wall...",
                                                              "You disassemble the girder.",
                                                              $"{interaction.Performer.ExpensiveName()} disassembles the false wall.",
                                                              () => Controller.ServerDisassemble(interaction));
                    return;
                }
            }
            // Attempt to open if it's closed
            Controller.ServerTryOpen(interaction.Performer);
        }

        allowInput = false;
        StartCoroutine(DoorInputCoolDown());
    }
Esempio n. 2
0
    /// <summary>
    /// Performs common tool usage logic, such as playing the correct sound.
    /// If item is not a tool, simply performs the progress action normally.
    /// </summary>
    /// <param name="performer">player using the tool</param>
    /// <param name="tool">tool being used</param>
    /// <param name="actionTarget">target of the action</param>
    /// <param name="seconds">seconds taken to perform the action, 0 if it should be instant</param>
    /// <param name="progressCompleteAction">completion callback (will also be called instantly if completion is instant)</param>
    /// <param name="playSound">Whether to play default tool sound</param>
    /// <returns>progress bar spawned, null if progress did not start or this was instant</returns>
    public static ProgressBar ServerUseTool(GameObject performer, GameObject tool, ActionTarget actionTarget,
                                            float seconds, Action progressCompleteAction, bool playSound = true)
    {
        //check tool stats
        var toolStats = tool.GetComponent <Tool>();

        if (toolStats != null)
        {
            seconds /= toolStats.SpeedMultiplier;
        }

        if (seconds <= 0f)
        {
            if (playSound)
            {
                ServerPlayToolSound(tool, actionTarget.TargetWorldPosition, performer);
            }

            // Check for null as ServerUseTool(interaction) accepts null Action
            if (progressCompleteAction != null)
            {
                progressCompleteAction.Invoke();
            }
            return(null);
        }
        else
        {
            var         welder = tool.GetComponent <Welder>();
            ProgressBar bar;
            if (welder != null)
            {
                bar = StandardProgressAction.CreateForWelder(ProgressConfig, progressCompleteAction, welder)
                      .ServerStartProgress(actionTarget, seconds, performer);
            }
            else
            {
                bar = StandardProgressAction.Create(ProgressConfig, progressCompleteAction)
                      .ServerStartProgress(actionTarget, seconds, performer);
            }

            if (bar != null && playSound)
            {
                ServerPlayToolSound(tool, actionTarget.TargetWorldPosition, performer);
            }

            return(bar);
        }
    }
    public void ServerPerformInteraction(HandApply interaction)
    {
        //Server actions
        // Close the door if it's open
        if (Controller.IsOpened)
        {
            Controller.ServerTryClose();
        }
        else
        {
            if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Welder) && Controller.IsWeldable && (interaction.Intent != Intent.Help))             // welding the door (only if closed and not helping)
            {
                var welder = interaction.HandObject.GetComponent <Welder>();
                if (welder.IsOn)
                {
                    void ProgressComplete()
                    {
                        Chat.AddExamineMsgFromServer(interaction.Performer, "You " + (Controller.IsWelded ? "unweld" : "weld") + " the door.");
                        Controller.ServerTryWeld();
                    }

                    var bar = StandardProgressAction.CreateForWelder(ProgressConfig, ProgressComplete, welder)
                              .ServerStartProgress(interaction.Performer.transform.position, weldTime, interaction.Performer);
                    if (bar != null)
                    {
                        SoundManager.PlayNetworkedAtPos("Weld", interaction.Performer.transform.position, Random.Range(0.8f, 1.2f));
                        Chat.AddExamineMsgFromServer(interaction.Performer, "You start " + (Controller.IsWelded ? "unwelding" : "welding") + " the door...");
                    }

                    return;
                }
            }
            // Attempt to open if it's closed
            Controller.ServerTryOpen(interaction.Performer);
        }

        allowInput = false;
        StartCoroutine(DoorInputCoolDown());
    }
Esempio n. 4
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Crowbar))
        {
            if (Controller.IsHackable)
            {
                HackingNode onAttemptClose = Controller.HackingProcess.GetNodeWithInternalIdentifier("OnAttemptClose");
                onAttemptClose.SendOutputToConnectedNodes(interaction.Performer);
            }
            else
            {
                TryCrowbar(interaction.Performer);
            }
        }
        else if (!Controller.IsClosed)
        {
            TryClose();             // Close the door if it's open
        }
        else
        {
            if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Welder))             // welding the door (only if closed and not helping)
            {
                if (Controller.IsWeldable)
                {
                    var welder = interaction.HandObject.GetComponent <Welder>();
                    if (welder.IsOn && interaction.Intent != Intent.Help)
                    {
                        void ProgressComplete()
                        {
                            if (Controller != null)
                            {
                                Chat.AddExamineMsgFromServer(interaction.Performer,
                                                             "You " + (Controller.IsWelded ? "unweld" : "weld") + " the door.");
                                Controller.ServerTryWeld();
                            }
                        }

                        var bar = StandardProgressAction.CreateForWelder(ProgressConfig, ProgressComplete, welder)
                                  .ServerStartProgress(interaction.Performer.transform.position, weldTime, interaction.Performer);
                        if (bar != null)
                        {
                            SoundManager.PlayNetworkedAtPos("Weld", interaction.Performer.transform.position, UnityEngine.Random.Range(0.8f, 1.2f), sourceObj: interaction.Performer);
                            Chat.AddExamineMsgFromServer(interaction.Performer, "You start " + (Controller.IsWelded ? "unwelding" : "welding") + " the door...");
                        }

                        return;
                    }
                }
                else if (!Controller.IsAutomatic)
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start to disassemble the false wall...",
                                                              $"{interaction.Performer.ExpensiveName()} starts to disassemble the false wall...",
                                                              "You disassemble the girder.",
                                                              $"{interaction.Performer.ExpensiveName()} disassembles the false wall.",
                                                              () => Controller.ServerDisassemble(interaction));
                    return;
                }
            }

            // Attempt to open if it's closed
            //Tell the OnAttemptOpen node to activate.
            if (Controller.IsHackable)
            {
                HackingNode onAttemptOpen = Controller.HackingProcess.GetNodeWithInternalIdentifier("OnAttemptOpen");
                onAttemptOpen.SendOutputToConnectedNodes(interaction.Performer);
            }
            else
            {
                Controller.ServerTryOpen(interaction.Performer);
            }
        }

        StartInputCoolDown();
    }