Пример #1
0
 /// <summary>
 /// Stage 1, Wrench down to continue construction, or welder to destroy airlock.
 /// </summary>
 /// <param name="interaction"></param>
 private void InitialStateInteraction(HandApply interaction)
 {
     if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
     {
         if (!ServerValidations.IsAnchorBlocked(interaction))
         {
             //wrench in place
             ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                       "You start to secure the airlock assembly to the floor...",
                                                       $"{interaction.Performer.ExpensiveName()} starts to secure the airlock assembly to the floor...",
                                                       "You secure the airlock assembly.",
                                                       $"{interaction.Performer.ExpensiveName()} secures the airlock assembly to the floor.",
                                                       () => objectBehaviour.ServerSetAnchored(true, interaction.Performer));
             stateful.ServerChangeState(wrenchedState);
         }
         else
         {
             Chat.AddExamineMsgFromServer(interaction.Performer, "Unable to secure airlock assembly");
         }
     }
     else if (Validations.HasUsedActiveWelder(interaction))
     {
         //deconsruct, spawn 4 metals
         ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                   "You start to disassemble the airlock assembly...",
                                                   $"{interaction.Performer.ExpensiveName()} starts to disassemble the airlock assembly...",
                                                   "You disassemble the airlock assembly.",
                                                   $"{interaction.Performer.ExpensiveName()} disassembles the airlock assembly.",
                                                   () =>
         {
             Spawn.ServerPrefab(airlockMaterial, SpawnDestination.At(gameObject), 4);
             _ = Despawn.ServerSingle(gameObject);
         });
     }
 }
Пример #2
0
        /// <summary>
        /// Stage 2, Wrench down to continue construction, anchors machine, or wirecutters to move to stage 1
        /// </summary>
        /// <param name="interaction"></param>
        private void CablesAddedStateInteraction(HandApply interaction)
        {
            if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wirecutter))
            {
                //cut out cables
                Chat.AddActionMsgToChat(interaction, $"You remove the cables.",
                                        $"{interaction.Performer.ExpensiveName()} removes the cables.");
                ToolUtils.ServerPlayToolSound(interaction);
                Spawn.ServerPrefab(CommonPrefabs.Instance.SingleCableCoil, SpawnDestination.At(gameObject), 5);
                stateful.ServerChangeState(initialState);

                spriteHandler.ChangeSprite((int)SpriteStates.Box);
            }
            else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
            {
                if (!ServerValidations.IsAnchorBlocked(interaction))
                {
                    //wrench in place
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start wrenching the frame into place...",
                                                              $"{interaction.Performer.ExpensiveName()} starts wrenching the frame into place...",
                                                              "You wrench the frame into place.",
                                                              $"{interaction.Performer.ExpensiveName()} wrenches the frame into place.",
                                                              () => objectBehaviour.ServerSetAnchored(true, interaction.Performer));
                    stateful.ServerChangeState(wrenchedState);
                }
                else
                {
                    Chat.AddExamineMsgFromServer(interaction.Performer, "Unable to wrench frame");
                }
            }
        }
Пример #3
0
 private void Secure()
 {
     ToolUtils.ServerUseToolWithActionMessages(currentInteraction, wrenchTime,
                                               wrenchTime == 0 ? "" : $"You start securing the {objectName} to the floor...",
                                               wrenchTime == 0 ? "" : $"{currentInteraction.Performer.ExpensiveName()} starts securing the {objectName} to the floor...",
                                               $"You secure the {objectName} to the floor.",
                                               $"{currentInteraction.Performer.ExpensiveName()} secures the {objectName} to the floor.",
                                               () => behaviour.ServerSetAnchored(true, currentInteraction.Performer)
                                               );
 }
        public void ServerPerformInteraction(HandApply interaction)
        {
            if (interaction.TargetObject != gameObject)
            {
                return;
            }


            if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Screwdriver))
            {
                if (objectBehaviour.IsPushable)
                {
                    //secure it if there's floor
                    if (MatrixManager.IsSpaceAt(registerObject.WorldPositionServer, true, registerObject.Matrix.MatrixInfo))
                    {
                        Chat.AddExamineMsg(interaction.Performer, "A floor must be present to secure the window!");
                        return;
                    }

                    if (!ServerValidations.IsAnchorBlocked(interaction))
                    {
                        ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                                  "You start securing the window...",
                                                                  $"{interaction.Performer.ExpensiveName()} starts securing the window...",
                                                                  "You secure the window.",
                                                                  $"{interaction.Performer.ExpensiveName()} secures the window.",
                                                                  () => ScrewToFloor(interaction));
                        return;
                    }
                }
                else
                {
                    //unsecure it
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start unsecuring the girder...",
                                                              $"{interaction.Performer.ExpensiveName()} starts unsecuring the window...",
                                                              "You unsecure the window.",
                                                              $"{interaction.Performer.ExpensiveName()} unsecures the window.",
                                                              () => objectBehaviour.ServerSetAnchored(false, interaction.Performer));
                }
            }
            else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Wrench))
            {
                //disassemble if it's unanchored
                if (objectBehaviour.IsPushable)
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start to disassemble the window...",
                                                              $"{interaction.Performer.ExpensiveName()} starts to disassemble the window...",
                                                              "You disassemble the window.",
                                                              $"{interaction.Performer.ExpensiveName()} disassembles the window.",
                                                              () => Disassemble(interaction));
                    return;
                }
                else
                {
                    Chat.AddExamineMsg(interaction.Performer, "You must unsecure it first.");
                }
            }
        }
Пример #5
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        if (interaction.TargetObject != gameObject)
        {
            return;
        }

        else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Screwdriver))
        {
            if (objectBehaviour.IsPushable)
            {
                //secure it if there's floor
                if (MatrixManager.IsSpaceAt(registerObject.WorldPositionServer, true))
                {
                    Chat.AddExamineMsg(interaction.Performer, "A floor must be present to secure the grille!");
                    return;
                }

                if (!ServerValidations.IsAnchorBlocked(interaction))
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 0.5f,
                                                              "You start securing the grille...",
                                                              $"{interaction.Performer.ExpensiveName()} starts securing the grille...",
                                                              "You secure the grille.",
                                                              $"{interaction.Performer.ExpensiveName()} secures the grille.",
                                                              () => ScrewInPlace(interaction));


                    return;
                }
            }
            else
            {
                //unsecure it
                ToolUtils.ServerUseToolWithActionMessages(interaction, 0.5f,
                                                          "You start unsecuring the grille...",
                                                          $"{interaction.Performer.ExpensiveName()} starts unsecuring the grille...",
                                                          "You unsecure the grille.",
                                                          $"{interaction.Performer.ExpensiveName()} unsecures the grille.",
                                                          () => objectBehaviour.ServerSetAnchored(false, interaction.Performer));
                SoundManager.PlayNetworkedAtPos("screwdriver2", gameObject.TileWorldPosition().To3Int(), Random.Range(0.9f, 1.1f));
            }
        }
        else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Wirecutter))
        {
            ToolUtils.ServerUseToolWithActionMessages(interaction, 1f,
                                                      "You start to disassemble the grille...",
                                                      $"{interaction.Performer.ExpensiveName()} starts to disassemble the grille...",
                                                      "You disassemble the grille.",
                                                      $"{interaction.Performer.ExpensiveName()} disassembles the grille.",
                                                      () => Disassemble(interaction));


            return;
        }
    }
Пример #6
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        if (interaction.TargetObject != gameObject)
        {
            return;
        }

        if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Wrench))
        {
            if (objectBehaviour.IsPushable)
            {
                //secure it if there's floor (or table, might want a check for the latter).
                if (MatrixManager.IsSpaceAt(registerObject.WorldPositionServer, true))
                {
                    Chat.AddExamineMsg(interaction.Performer, "A floor must be present to secure the object!");
                    return;
                }
                //Need to replace "object" with the target object's name eventually.
                if (!ServerValidations.IsAnchorBlocked(interaction))
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, secondsToSecure,
                                                              "You start securing the object...",
                                                              $"{interaction.Performer.ExpensiveName()} starts securing the object...",
                                                              "You secure the object.",
                                                              $"{interaction.Performer.ExpensiveName()} secures the object.",
                                                              () => objectBehaviour.ServerSetAnchored(true, interaction.Performer));
                }
            }
            else
            {
                //unsecure it
                ToolUtils.ServerUseToolWithActionMessages(interaction, secondsToUnsecure,
                                                          "You start unsecuring the object...",
                                                          $"{interaction.Performer.ExpensiveName()} starts unsecuring the object...",
                                                          "You unsecure the object.",
                                                          $"{interaction.Performer.ExpensiveName()} unsecures the object.",
                                                          () => objectBehaviour.ServerSetAnchored(false, interaction.Performer));
            }
        }
    }
Пример #7
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        if (interaction.TargetObject != gameObject)
        {
            return;
        }

        if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.MetalSheet))
        {
            if (objectBehaviour.IsPushable)
            {
                if (!Validations.HasAtLeast(interaction.HandObject, 2))
                {
                    Chat.AddExamineMsg(interaction.Performer, "You need two sheets of metal to finish a false wall!");
                    return;
                }
                ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                          "You start adding plating...",
                                                          $"{interaction.Performer.ExpensiveName()} begins adding plating...",
                                                          "You create a false wall.",
                                                          $"{interaction.Performer.ExpensiveName()} creates a false wall.",
                                                          () => ConstructFalseWall(interaction));
            }
            else
            {
                if (!Validations.HasAtLeast(interaction.HandObject, 2))
                {
                    Chat.AddExamineMsg(interaction.Performer, "You need two sheets of metal to finish a wall!");
                    return;
                }
                ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                          "You start adding plating...",
                                                          $"{interaction.Performer.ExpensiveName()} begins adding plating...",
                                                          "You create a wall.",
                                                          $"{interaction.Performer.ExpensiveName()} creates a wall.",
                                                          () => ConstructWall(interaction));
            }
        }
        else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.PlasteelSheet))
        {
            if (objectBehaviour.IsPushable)
            {
                if (!Validations.HasAtLeast(interaction.HandObject, 2))
                {
                    Chat.AddExamineMsg(interaction.Performer, "You need at least two sheets to create a reinforced false wall!");
                    return;
                }
                ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                          "You start adding plating...",
                                                          $"{interaction.Performer.ExpensiveName()} begins adding plating...",
                                                          "You add the plating.",
                                                          $"{interaction.Performer.ExpensiveName()} adds the plating.",
                                                          () => ConstructReinforcedFalseWall(interaction));
            }
            else
            {
                //add plasteel for constructing reinforced girder
                ToolUtils.ServerUseToolWithActionMessages(interaction, 6f,
                                                          "You start reinforcing the girder...",
                                                          $"{interaction.Performer.ExpensiveName()} starts reinforcing the girder...",
                                                          "You reinforce the girder.",
                                                          $"{interaction.Performer.ExpensiveName()} reinforces the girder.",
                                                          () => ReinforceGirder(interaction));
            }
        }
        else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Wrench))
        {
            if (objectBehaviour.IsPushable)
            {
                //secure it if there's floor
                if (MatrixManager.IsSpaceAt(registerObject.WorldPositionServer, true))
                {
                    Chat.AddExamineMsg(interaction.Performer, "A floor must be present to secure the girder!");
                    return;
                }

                if (!ServerValidations.IsAnchorBlocked(interaction))
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start securing the girder...",
                                                              $"{interaction.Performer.ExpensiveName()} starts securing the girder...",
                                                              "You secure the girder.",
                                                              $"{interaction.Performer.ExpensiveName()} secures the girder.",
                                                              () => objectBehaviour.ServerSetAnchored(true, interaction.Performer));
                }
            }
            else
            {
                //unsecure it
                ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                          "You start unsecuring the girder...",
                                                          $"{interaction.Performer.ExpensiveName()} starts unsecuring the girder...",
                                                          "You unsecure the girder.",
                                                          $"{interaction.Performer.ExpensiveName()} unsecures the girder.",
                                                          () => objectBehaviour.ServerSetAnchored(false, interaction.Performer));
            }
        }
        else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Screwdriver))
        {
            //disassemble if it's unanchored
            if (objectBehaviour.IsPushable)
            {
                ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                          "You start to disassemble the girder...",
                                                          $"{interaction.Performer.ExpensiveName()} starts to disassemble the girder...",
                                                          "You disassemble the girder.",
                                                          $"{interaction.Performer.ExpensiveName()} disassembles the girder.",
                                                          () => Disassemble(interaction));
            }
            else
            {
                Chat.AddExamineMsg(interaction.Performer, "You must unsecure it first.");
            }
        }
    }
Пример #8
0
 public void ServerPerformInteraction(HandApply interaction)
 {
     if (CurrentState == initialState)
     {
         if (objectBehaviour.IsPushable)
         {
             if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
             {
                 if (!ServerValidations.IsAnchorBlocked(interaction))
                 {
                     //wrench in place
                     ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                               "You start wrenching the frame into place...",
                                                               $"{interaction.Performer.ExpensiveName()} starts wrenching the frame into place...",
                                                               "You wrench the frame into place.",
                                                               $"{interaction.Performer.ExpensiveName()} wrenches the frame into place.",
                                                               () => objectBehaviour.ServerSetAnchored(true, interaction.Performer));
                 }
             }
             else if (Validations.HasUsedActiveWelder(interaction))
             {
                 //deconsruct
                 ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                           "You start deconstructing the frame...",
                                                           $"{interaction.Performer.ExpensiveName()} starts deconstructing the frame...",
                                                           "You deconstruct the frame.",
                                                           $"{interaction.Performer.ExpensiveName()} deconstructs the frame.",
                                                           () =>
                 {
                     Spawn.ServerPrefab(CommonPrefabs.Instance.Metal, SpawnDestination.At(gameObject), 5);
                     _ = Despawn.ServerSingle(gameObject);
                 });
             }
         }
         else
         {
             //already wrenched in place
             if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
             {
                 //unwrench
                 ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                           "You start to unfasten the frame...",
                                                           $"{interaction.Performer.ExpensiveName()} starts to unfasten the frame...",
                                                           "You unfasten the frame.",
                                                           $"{interaction.Performer.ExpensiveName()} unfastens the frame.",
                                                           () => objectBehaviour.ServerSetAnchored(false, interaction.Performer));
             }
             else if (Validations.HasUsedComponent <ComputerCircuitboard>(interaction) && circuitBoardSlot.IsEmpty)
             {
                 //stick in the circuit board
                 Chat.AddActionMsgToChat(interaction, $"You place the {interaction.UsedObject.ExpensiveName()} inside the frame.",
                                         $"{interaction.Performer.ExpensiveName()} places the {interaction.UsedObject.ExpensiveName()} inside the frame.");
                 Inventory.ServerTransfer(interaction.HandSlot, circuitBoardSlot);
             }
             else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver) && circuitBoardSlot.IsOccupied)
             {
                 //screw in the circuit board
                 Chat.AddActionMsgToChat(interaction, $"You screw {circuitBoardSlot.ItemObject.ExpensiveName()} into place.",
                                         $"{interaction.Performer.ExpensiveName()} screws {circuitBoardSlot.ItemObject.ExpensiveName()} into place.");
                 ToolUtils.ServerPlayToolSound(interaction);
                 stateful.ServerChangeState(circuitScrewedState);
             }
             else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Crowbar) &&
                      circuitBoardSlot.IsOccupied)
             {
                 //wrench out the circuit board
                 Chat.AddActionMsgToChat(interaction, $"You remove the {circuitBoardSlot.ItemObject.ExpensiveName()} from the frame.",
                                         $"{interaction.Performer.ExpensiveName()} removes the {circuitBoardSlot.ItemObject.ExpensiveName()} from the frame.");
                 ToolUtils.ServerPlayToolSound(interaction);
                 Inventory.ServerDrop(circuitBoardSlot);
             }
         }
     }
     else if (CurrentState == circuitScrewedState)
     {
         if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
         {
             //unscrew circuit board
             Chat.AddActionMsgToChat(interaction, $"You unfasten the circuit board.",
                                     $"{interaction.Performer.ExpensiveName()} unfastens the circuit board.");
             ToolUtils.ServerPlayToolSound(interaction);
             stateful.ServerChangeState(initialState);
         }
         else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Cable) &&
                  Validations.HasUsedAtLeast(interaction, 5))
         {
             //add 5 cables
             ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                       "You start adding cables to the frame...",
                                                       $"{interaction.Performer.ExpensiveName()} starts adding cables to the frame...",
                                                       "You add cables to the frame.",
                                                       $"{interaction.Performer.ExpensiveName()} adds cables to the frame.",
                                                       () =>
             {
                 Inventory.ServerConsume(interaction.HandSlot, 5);
                 stateful.ServerChangeState(cablesAddedState);
             });
         }
     }
     else if (CurrentState == cablesAddedState)
     {
         if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wirecutter))
         {
             //cut out cables
             Chat.AddActionMsgToChat(interaction, $"You remove the cables.",
                                     $"{interaction.Performer.ExpensiveName()} removes the cables.");
             ToolUtils.ServerPlayToolSound(interaction);
             Spawn.ServerPrefab(CommonPrefabs.Instance.SingleCableCoil, SpawnDestination.At(gameObject), 5);
             stateful.ServerChangeState(circuitScrewedState);
         }
         else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.GlassSheet) &&
                  Validations.HasUsedAtLeast(interaction, 2))
         {
             //add glass
             ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                       "You start to put in the glass panel...",
                                                       $"{interaction.Performer.ExpensiveName()} starts to put in the glass panel...",
                                                       "You put in the glass panel.",
                                                       $"{interaction.Performer.ExpensiveName()} puts in the glass panel.",
                                                       () =>
             {
                 Inventory.ServerConsume(interaction.HandSlot, 2);
                 stateful.ServerChangeState(glassAddedState);
             });
         }
     }
     else if (CurrentState == glassAddedState)
     {
         if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
         {
             //screw in monitor, completing construction
             Chat.AddActionMsgToChat(interaction, $"You connect the monitor.",
                                     $"{interaction.Performer.ExpensiveName()} connects the monitor.");
             ToolUtils.ServerPlayToolSound(interaction);
             var circuitBoard = circuitBoardSlot.ItemObject?.GetComponent <ComputerCircuitboard>();
             if (circuitBoard == null)
             {
                 Logger.LogWarningFormat("Cannot complete computer, circuit board not in frame {0}. Probably a coding error.",
                                         Category.Construction, name);
                 return;
             }
             Spawn.ServerPrefab(circuitBoard.ComputerToSpawn, SpawnDestination.At(gameObject));
             _ = Despawn.ServerSingle(gameObject);
         }
         else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Crowbar))
         {
             //remove glass
             Chat.AddActionMsgToChat(interaction, $"You remove the glass panel.",
                                     $"{interaction.Performer.ExpensiveName()} removes the glass panel.");
             ToolUtils.ServerPlayToolSound(interaction);
             Spawn.ServerPrefab(CommonPrefabs.Instance.GlassSheet, SpawnDestination.At(gameObject), 2);
             stateful.ServerChangeState(cablesAddedState);
         }
     }
 }
Пример #9
0
        public void ServerPerformInteraction(HandApply interaction)
        {
            //Anchor or disassemble
            if (CurrentState == initialState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
                {
                    if (ServerValidations.IsAnchorBlocked(interaction) == false)
                    {
                        //wrench in place
                        ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                                  "You start wrenching the Ai core frame into place...",
                                                                  $"{interaction.Performer.ExpensiveName()} starts wrenching the Ai core frame into place...",
                                                                  "You wrench the Ai core frame into place.",
                                                                  $"{interaction.Performer.ExpensiveName()} wrenches the Ai core frame into place.",
                                                                  () =>
                        {
                            objectBehaviour.ServerSetAnchored(true, interaction.Performer);

                            stateful.ServerChangeState(anchoredState);
                        });

                        return;
                    }

                    Chat.AddExamineMsgFromServer(interaction.Performer, "Unable to anchor Ai core frame here");
                }
                else if (Validations.HasUsedActiveWelder(interaction))
                {
                    //Deconstruct
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start deconstructing the Ai core frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts deconstructing the Ai core frame...",
                                                              "You deconstruct the Ai core frame.",
                                                              $"{interaction.Performer.ExpensiveName()} deconstructs the Ai core frame.",
                                                              () =>
                    {
                        Spawn.ServerPrefab(CommonPrefabs.Instance.Plasteel, SpawnDestination.At(gameObject), 5);
                        _ = Despawn.ServerSingle(gameObject);
                    });
                }

                return;
            }

            //Adding Circuit board or unanchor
            if (CurrentState == anchoredState)
            {
                if (Validations.HasUsedItemTrait(interaction, aiCoreCircuitBoardTrait))
                {
                    //Add Circuit board
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start adding the circuit board to the Ai core frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts adding a circuit board to the Ai core frame...",
                                                              "You add a circuit board to the Ai core frame.",
                                                              $"{interaction.Performer.ExpensiveName()} adds a circuit board to the Ai core frame.",
                                                              () =>
                    {
                        Inventory.ServerConsume(interaction.HandSlot, 1);
                        stateful.ServerChangeState(circuitAddedState);
                        spriteHandler.ChangeSprite(1);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
                {
                    //Unanchor
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start unwrenching the Ai core frame from the floor...",
                                                              $"{interaction.Performer.ExpensiveName()} starts unwrenching the Ai core frame from the floor...",
                                                              "You unwrench the Ai core frame from the floor.",
                                                              $"{interaction.Performer.ExpensiveName()} unwrenches the Ai core frame from the floor.",
                                                              () =>
                    {
                        objectBehaviour.ServerSetAnchored(false, interaction.Performer);
                        stateful.ServerChangeState(initialState);
                    });
                }

                return;
            }

            //Screwdriver or remove Circuit board
            if (CurrentState == circuitAddedState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
                {
                    //Screwdriver
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start screwing in the circuit board...",
                                                              $"{interaction.Performer.ExpensiveName()} starts screwing in the circuit board...",
                                                              "You screw in the circuit board.",
                                                              $"{interaction.Performer.ExpensiveName()} screws in the circuit board.",
                                                              () =>
                    {
                        stateful.ServerChangeState(screwState);
                        spriteHandler.ChangeSprite(2);
                    });
                }
                else if (interaction.HandObject == null)
                {
                    //Remove Circuit board
                    Chat.AddActionMsgToChat(interaction, "You remove the circuit board from the frame",
                                            $"{interaction.Performer.ExpensiveName()} removes the circuit board from the frame");

                    Spawn.ServerPrefab(aiCoreCircuitBoardPrefab, SpawnDestination.At(gameObject));
                    stateful.ServerChangeState(anchoredState);
                    spriteHandler.ChangeSprite(0);
                }

                return;
            }

            //Add wire or unscrew
            if (CurrentState == screwState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Cable))
                {
                    //Add wire
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start adding wire to the Ai core frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts adding wire to the Ai core frame...",
                                                              "You add wire to the Ai core frame.",
                                                              $"{interaction.Performer.ExpensiveName()} adds wire to the Ai core frame.",
                                                              () =>
                    {
                        Inventory.ServerConsume(interaction.HandSlot, 1);
                        stateful.ServerChangeState(wireAddedState);
                        spriteHandler.ChangeSprite(3);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
                {
                    //Remove unscrew
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start unscrewing in the circuit board...",
                                                              $"{interaction.Performer.ExpensiveName()} starts unscrewing in the circuit board...",
                                                              "You remove unscrew the circuit board.",
                                                              $"{interaction.Performer.ExpensiveName()} unscrews the circuit board.",
                                                              () =>
                    {
                        stateful.ServerChangeState(circuitAddedState);
                        spriteHandler.ChangeSprite(1);
                    });
                }

                return;
            }

            //Add brain, or skip brain and add reinforced glass or remove wire
            if (CurrentState == wireAddedState)
            {
                //TODO add brain adding interaction
                // if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.brain))
                // {
                //  //Add brain
                //  Chat.AddActionMsgToChat(interaction, $"You place the {interaction.UsedObject.ExpensiveName()} inside the turret frame.",
                //      $"{interaction.Performer.ExpensiveName()} places the {interaction.UsedObject.ExpensiveName()} inside the turret frame.");
                //  _ = Despawn.ServerSingle(interaction.UsedObject);
                //  stateful.ServerChangeState(brainAddedState);

                //	spriteHandler.ChangeSprite(4);
                // }
                /*else */ if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.ReinforcedGlassSheet))
                {
                    //Skip adding brain and add reinforced glass straight away instead
                    if (Validations.HasUsedAtLeast(interaction, 2) == false)
                    {
                        Chat.AddExamineMsgFromServer(interaction.Performer, "You need to use 2 reinforced glass sheets");
                        return;
                    }

                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start adding the reinforced glass to the front of the Ai core...",
                                                              $"{interaction.Performer.ExpensiveName()} starts add reinforced glass to the front of the Ai core...",
                                                              "You add reinforced glass to the front of the Ai core.",
                                                              $"{interaction.Performer.ExpensiveName()} adds reinforced glass to the front of the Ai core.",
                                                              () =>
                    {
                        Inventory.ServerConsume(interaction.HandSlot, 2);
                        stateful.ServerChangeState(glassState);
                        spriteHandler.ChangeSprite(5);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wirecutter))
                {
                    //Remove wire
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start cutting out the wire...",
                                                              $"{interaction.Performer.ExpensiveName()} starts cutting out the wire...",
                                                              "You cut out the wire.",
                                                              $"{interaction.Performer.ExpensiveName()} cuts out the wire.",
                                                              () =>
                    {
                        Spawn.ServerPrefab(CommonPrefabs.Instance.SingleCableCoil, SpawnDestination.At(gameObject), 1);
                        stateful.ServerChangeState(screwState);
                        spriteHandler.ChangeSprite(2);
                    });
                }

                return;
            }

            //Add reinforced glass or remove brain
            if (CurrentState == brainAddedState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.ReinforcedGlassSheet))
                {
                    //Add reinforced glass
                    if (Validations.HasUsedAtLeast(interaction, 2) == false)
                    {
                        Chat.AddExamineMsgFromServer(interaction.Performer, "You need to use 2 reinforced glass sheets");
                        return;
                    }

                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start adding the reinforced glass to the front of the Ai core...",
                                                              $"{interaction.Performer.ExpensiveName()} starts add reinforced glass to the front of the Ai core...",
                                                              "You add reinforced glass to the front of the Ai core.",
                                                              $"{interaction.Performer.ExpensiveName()} adds reinforced glass to the front of the Ai core.",
                                                              () =>
                    {
                        Inventory.ServerConsume(interaction.HandSlot, 2);
                        stateful.ServerChangeState(glassState);
                        spriteHandler.ChangeSprite(5);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Crowbar))
                {
                    //Remove brain
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start removing the MMI/Positron Brain from the Ai core...",
                                                              $"{interaction.Performer.ExpensiveName()} starts removing the MMI/Positron Brain from the Ai core...",
                                                              "You remove the MMI/Positron Brain from the Ai core.",
                                                              $"{interaction.Performer.ExpensiveName()} removes the MMI/Positron Brain from the Ai core.",
                                                              () =>
                    {
                        //TODO remove brain logic
                        stateful.ServerChangeState(wireAddedState);
                        spriteHandler.ChangeSprite(3);
                    });
                }

                return;
            }

            //Screw to finish or remove glass
            if (CurrentState == glassState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
                {
                    //Finish
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start screwing in the glass to the frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts screwing in the glass to the frame...",
                                                              "You screw in the glass to the frame.",
                                                              $"{interaction.Performer.ExpensiveName()} screws in the glass to the frame.",
                                                              () =>
                    {
                        var newCore = Spawn.ServerPrefab(aiCorePrefab, SpawnDestination.At(gameObject), 1);

                        if (newCore.Successful)
                        {
                            //TODO set up ai core when we have brain
                            newCore.GameObject.GetComponent <AiVessel>().SetLinkedPlayer(null);
                        }

                        _ = Despawn.ServerSingle(gameObject);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Crowbar))
                {
                    //Crowbar out glass
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start removing the reinforced glass from the Ai core frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts removing removing the reinforced glass from the Ai core frame...",
                                                              "You remove the reinforced glass from the Ai core frame.",
                                                              $"{interaction.Performer.ExpensiveName()} removes the reinforced glass from the Ai core frame.",
                                                              () =>
                    {
                        //TODO check for brain
                        // if ()
                        // {
                        //  stateful.ServerChangeState(brainAddedState);
                        //	spriteHandler.ChangeSprite(4);
                        //  return;
                        // }

                        Spawn.ServerPrefab(CommonPrefabs.Instance.ReinforcedGlassSheet, SpawnDestination.At(gameObject), 2);
                        stateful.ServerChangeState(wireAddedState);
                        spriteHandler.ChangeSprite(3);
                    });
                }
            }
        }
Пример #10
0
        public void ServerPerformInteraction(HandApply interaction)
        {
            //Anchor or disassemble
            if (CurrentState == initialState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
                {
                    if (!ServerValidations.IsAnchorBlocked(interaction))
                    {
                        //wrench in place
                        ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                                  "You start wrenching the turret frame into place...",
                                                                  $"{interaction.Performer.ExpensiveName()} starts wrenching the turret frame into place...",
                                                                  "You wrench the turret frame into place.",
                                                                  $"{interaction.Performer.ExpensiveName()} wrenches the turret frame into place.",
                                                                  () =>
                        {
                            objectBehaviour.ServerSetAnchored(true, interaction.Performer);

                            stateful.ServerChangeState(anchoredState);
                        });

                        return;
                    }

                    Chat.AddExamineMsgFromServer(interaction.Performer, "Unable to anchor turret frame here");
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Crowbar))
                {
                    //deconstruct
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start deconstructing the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts deconstructing the turret frame...",
                                                              "You deconstruct the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} deconstructs the turret frame.",
                                                              () =>
                    {
                        Spawn.ServerPrefab(CommonPrefabs.Instance.Metal, SpawnDestination.At(gameObject), 5);
                        _ = Despawn.ServerSingle(gameObject);
                    });
                }

                return;
            }

            //Adding metal or unanchor
            if (CurrentState == anchoredState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.MetalSheet))
                {
                    //Add metal
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start adding a metal cover to the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts adding a metal cover to the turret frame...",
                                                              "You add a metal cover to the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} adds a metal cover to the turret frame.",
                                                              () =>
                    {
                        Inventory.ServerConsume(interaction.HandSlot, 1);
                        stateful.ServerChangeState(metalAddedState);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
                {
                    //Unanchor
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start unwrenching the turret frame from the floor...",
                                                              $"{interaction.Performer.ExpensiveName()} starts unwrenching the turret frame from the floor...",
                                                              "You unwrench the turret frame from the floor.",
                                                              $"{interaction.Performer.ExpensiveName()} unwrenches the turret frame from the floor.",
                                                              () =>
                    {
                        objectBehaviour.ServerSetAnchored(false, interaction.Performer);

                        stateful.ServerChangeState(initialState);
                    });
                }

                return;
            }

            //Wrench or remove metal
            if (CurrentState == metalAddedState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
                {
                    //Wrench
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start wrenching the bolts on the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts wrenching the bolts on the turret frame...",
                                                              "You wrench the bolts on the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} wrenches the bolts on the turret frame.",
                                                              () =>
                    {
                        stateful.ServerChangeState(wrenchState);
                    });
                }
                else if (Validations.HasUsedActiveWelder(interaction))
                {
                    //Remove metal
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start removing the metal cover from the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts removing the metal cover from the turret frame...",
                                                              "You remove the metal cover from the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} removes the metal cover from the turret frame.",
                                                              () =>
                    {
                        Spawn.ServerPrefab(CommonPrefabs.Instance.Metal, SpawnDestination.At(gameObject), 1);
                        stateful.ServerChangeState(anchoredState);
                    });
                }

                return;
            }

            //Add gun or unwrench
            if (CurrentState == wrenchState)
            {
                if (Validations.HasUsedItemTrait(interaction, gunTrait))
                {
                    //Add energy gun
                    Chat.AddActionMsgToChat(interaction, $"You place the {interaction.UsedObject.ExpensiveName()} inside the turret frame.",
                                            $"{interaction.Performer.ExpensiveName()} places the {interaction.UsedObject.ExpensiveName()} inside the turret frame.");
                    Inventory.ServerTransfer(interaction.HandSlot, gunSlot);
                    stateful.ServerChangeState(gunAddedState);
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wrench))
                {
                    //Remove unwrench bolts
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start removing the bolts from the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts removing the bolts from the turret frame...",
                                                              "You remove the bolts from the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} removes the bolts from the turret frame.",
                                                              () =>
                    {
                        stateful.ServerChangeState(metalAddedState);
                    });
                }

                return;
            }

            //Add prox or remove gun
            if (CurrentState == gunAddedState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.ProximitySensor))
                {
                    //Add proximity sensor
                    Chat.AddActionMsgToChat(interaction, $"You place the {interaction.UsedObject.ExpensiveName()} inside the turret frame.",
                                            $"{interaction.Performer.ExpensiveName()} places the {interaction.UsedObject.ExpensiveName()} inside the turret frame.");
                    _ = Despawn.ServerSingle(interaction.UsedObject);
                    stateful.ServerChangeState(proxAddedState);
                }
                else if (interaction.HandObject == null)
                {
                    //Remove gun
                    Chat.AddActionMsgToChat(interaction, $"You remove the {gunSlot.ItemObject.ExpensiveName()} from the frame.",
                                            $"{interaction.Performer.ExpensiveName()} removes the {gunSlot.ItemObject.ExpensiveName()} from the frame.");
                    Inventory.ServerDrop(gunSlot);

                    stateful.ServerChangeState(wrenchState);
                }

                return;
            }

            //Screw or remove prox
            if (CurrentState == proxAddedState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
                {
                    //Screw
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start closing the internal hatch of the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts closing the internal hatch of the turret frame...",
                                                              "You close the internal hatch of the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} closes the internal hatch of the turret frame.",
                                                              () =>
                    {
                        stateful.ServerChangeState(screwState);
                    });
                }
                else if (interaction.HandObject == null)
                {
                    //Remove prox
                    Chat.AddActionMsgToChat(interaction, $"You remove the {gunSlot.ItemObject.ExpensiveName()} from the frame.",
                                            $"{interaction.Performer.ExpensiveName()} removes the {gunSlot.ItemObject.ExpensiveName()} from the frame.");
                    Spawn.ServerPrefab(proximityPrefab, objectBehaviour.registerTile.WorldPosition, transform.parent);

                    stateful.ServerChangeState(gunAddedState);
                }

                return;
            }

            //Add metal or unscrew
            if (CurrentState == screwState)
            {
                if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.MetalSheet))
                {
                    //Add metal
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start adding a metal cover to the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts adding a metal cover to the turret frame...",
                                                              "You add a metal cover to the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} adds a metal cover to the turret frame.",
                                                              () =>
                    {
                        Inventory.ServerConsume(interaction.HandSlot, 1);
                        stateful.ServerChangeState(secondMetalAddedState);
                    });
                }
                else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
                {
                    //Unscrew
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start removing the bolts from the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts removing the bolts from the turret frame...",
                                                              "You remove the bolts from the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} removes the bolts from the turret frame.",
                                                              () =>
                    {
                        stateful.ServerChangeState(proxAddedState);
                    });
                }

                return;
            }

            //Finish construction, or remove metal
            if (CurrentState == secondMetalAddedState)
            {
                if (Validations.HasUsedActiveWelder(interaction))
                {
                    //Weld to finish turret
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                              "You start welding the outer metal cover to the turret frame...",
                                                              $"{interaction.Performer.ExpensiveName()} starts welding the outer metal cover to the turret frame...",
                                                              "You weld the outer metal cover to the turret frame.",
                                                              $"{interaction.Performer.ExpensiveName()} welds the outer metal cover to the turret frame.",
                                                              () =>
                    {
                        var spawnedTurret = Spawn.ServerPrefab(turretPrefab, objectBehaviour.registerTile.WorldPosition, transform.parent);

                        if (spawnedTurret.Successful && spawnedTurret.GameObject.TryGetComponent <Turret>(out var turret))
                        {
                            turret.SetUpTurret(gunSlot.Item.GetComponent <Gun>(), gunSlot);
                        }

                        _ = Despawn.ServerSingle(gameObject);
                    });