示例#1
0
    public void ServerPerformInteraction(HandApply interaction)
    {
        //unscrew
        ToolUtils.ServerUseToolWithActionMessages(interaction, secondsToScrewdrive,
                                                  "You start to disconnect the monitor...",
                                                  $"{interaction.Performer.ExpensiveName()} starts to disconnect the monitor...",
                                                  "You disconnect the monitor.",
                                                  $"{interaction.Performer.ExpensiveName()} disconnects the monitor.",
                                                  () =>
        {
            //drop all our contents
            ItemStorage itemStorage = null;
            // rare cases were gameObject is destroyed for some reason and then the method is called
            if (gameObject != null)
            {
                itemStorage = GetComponent <ItemStorage>();
            }

            if (itemStorage != null)
            {
                itemStorage.ServerDropAll();
            }
            var frame = Spawn.ServerPrefab(framePrefab, SpawnDestination.At(gameObject)).GameObject;
            frame.GetComponent <ComputerFrame>().ServerInitFromComputer(this);
            Despawn.ServerSingle(gameObject);
        });
    }
示例#2
0
        public void WhenDestroyed(DestructionInfo info)
        {
            if (circuitBoardSlot.IsOccupied)
            {
                Inventory.ServerDrop(circuitBoardSlot);
            }

            if (CurrentState == glassAddedState)
            {
                //1-2
                Spawn.ServerPrefab(CommonPrefabs.Instance.GlassSheet, SpawnDestination.At(gameObject), UnityEngine.Random.Range(1, 3));
                //1-5
                Spawn.ServerPrefab(CommonPrefabs.Instance.SingleCableCoil, SpawnDestination.At(gameObject), UnityEngine.Random.Range(1, 6));
            }

            if (CurrentState == cablesAddedState)
            {
                //1-5
                Spawn.ServerPrefab(CommonPrefabs.Instance.SingleCableCoil, SpawnDestination.At(gameObject), UnityEngine.Random.Range(1, 6));
            }

            //1-5
            Spawn.ServerPrefab(CommonPrefabs.Instance.Metal, SpawnDestination.At(gameObject), UnityEngine.Random.Range(1, 6));

            integrity.OnWillDestroyServer.RemoveListener(WhenDestroyed);
        }
示例#3
0
    public virtual void OnSpawnServer(SpawnInfo info)
    {
        if (initialContents != null)
        {
            //populate initial contents on spawn
            var result = initialContents.SpawnAt(SpawnDestination.At(gameObject));
            foreach (var spawned in result.GameObjects)
            {
                var objBehavior = spawned.GetComponent <ObjectBehaviour>();
                if (objBehavior != null)
                {
                    ServerAddInternalItem(objBehavior);
                }
            }
        }

        //always spawn closed, all lockable closets locked
        SyncStatus(statusSync, ClosetStatus.Closed);
        if (IsLockable)
        {
            SyncLocked(isLocked, true);
        }
        else
        {
            SyncLocked(isLocked, false);
        }

        //if this is a mapped spawn, stick any items mapped on top of us in
        if (info.SpawnType == SpawnType.Mapped)
        {
            CloseItemHandling();
        }
    }
示例#4
0
        public void WhenDestroyed(DestructionInfo info)
        {
            //drop all our contents
            ItemStorage itemStorage = null;

            // rare cases were gameObject is destroyed for some reason and then the method is called
            if (gameObject == null)
            {
                return;
            }

            itemStorage = GetComponent <ItemStorage>();

            if (itemStorage != null)
            {
                itemStorage.ServerDropAll();
            }

            var frame = Spawn.ServerPrefab(framePrefab, SpawnDestination.At(gameObject)).GameObject;

            frame.GetComponent <MachineFrame>().ServerInitFromComputer(this);

            Despawn.ServerSingle(gameObject);

            integrity.OnWillDestroyServer.RemoveListener(WhenDestroyed);
        }
示例#5
0
 private void DeconstructSwitch()
 {
     SetState(SwitchState.Off);
     conveyorBelts.Clear();
     Spawn.ServerPrefab(CommonPrefabs.Instance.Metal, SpawnDestination.At(gameObject), 5);
     _ = Despawn.ServerSingle(gameObject);
 }
示例#6
0
    public override void ServerPerformInteraction(TileApply interaction)
    {
        ToolUtils.ServerUseToolWithActionMessages(interaction, seconds,
                                                  performerStartActionMessage,
                                                  Chat.ReplacePerformer(othersStartActionMessage, interaction.Performer),
                                                  performerFinishActionMessage,
                                                  Chat.ReplacePerformer(othersFinishActionMessage, interaction.Performer),
                                                  () =>
        {
            interaction.TileChangeManager.RemoveTile(interaction.TargetCellPos, interaction.BasicTile.LayerType);
            interaction.TileChangeManager.RemoveFloorWallOverlaysOfType(interaction.TargetCellPos, TileChangeManager.OverlayType.Cleanable);

            //spawn things that need to be spawned
            if (interaction.BasicTile.SpawnOnDeconstruct != null &&
                interaction.BasicTile.SpawnAmountOnDeconstruct > 0)
            {
                Spawn.ServerPrefab(interaction.BasicTile.SpawnOnDeconstruct, interaction.WorldPositionTarget,
                                   count: interaction.BasicTile.SpawnAmountOnDeconstruct);
            }

            if (objectsToSpawn != null)
            {
                objectsToSpawn.SpawnAt(SpawnDestination.At(interaction.WorldPositionTarget));
            }

            interaction.TileChangeManager.SubsystemManager.UpdateAt(interaction.TargetCellPos);
        });
    }
示例#7
0
        /// <summary>Spawns the initial contents when needed, not always on game start so that there's less game objects
        public void TrySpawnInitialContents(bool hideContents = false)
        {
            if (initialContentsSpawned)
            {
                return;
            }
            initialContentsSpawned = true;

            // Null check after setting true so we only do the null check once not every opening
            if (initialContents == null)
            {
                return;
            }

            // populate initial contents
            var result = initialContents.SpawnAt(SpawnDestination.At(gameObject));

            // Only hide if on spawn as the closet will be closed // TODO: when would we onl wantto spawn objects at hthe point andasdf
            if (hideContents == false)
            {
                return;
            }

            StoreObjects(result.GameObjects);
        }
示例#8
0
            /// <summary>
            /// build this at the indicated location.
            /// </summary>
            /// <param name="at"></param>
            /// <param name="buildingMaterial">object being used in hand to build this.</param>
            /// <returns>true game object if successful</returns>
            public GameObject ServerBuild(SpawnDestination at, BuildingMaterial buildingMaterial)
            {
                var stackable = buildingMaterial.GetComponent <Stackable>();

                if (stackable != null)
                {
                    if (stackable.Amount < cost)
                    {
                        Logger.LogWarningFormat("Server logic error. " +
                                                "Tried building {0} with insufficient materials in hand ({1})." +
                                                " Build will not be performed.", Category.Construction, name,
                                                buildingMaterial);
                        return(null);
                    }
                    stackable.ServerConsume(cost);
                }
                else
                {
                    if (cost > 1)
                    {
                        Logger.LogWarningFormat("Server logic error. " +
                                                "Tried building {0} with insufficient materials in hand ({1})." +
                                                " Build will not be performed.", Category.Construction, name,
                                                buildingMaterial);
                        return(null);
                    }

                    Inventory.ServerDespawn(buildingMaterial.GetComponent <Pickupable>().ItemSlot);
                }

                return(Spawn.ServerPrefab(prefab, at, spawnAmount)?.GameObject);
            }
示例#9
0
        public void WhenDestroyed(DestructionInfo info)
        {
            // rare cases were gameObject is destroyed for some reason and then the method is called
            if (gameObject == null)
            {
                return;
            }

            Inventory.ServerSpawnPrefab(powerControlModule, powerControlSlot, ReplacementStrategy.Cancel);
            Inventory.ServerSpawnPrefab(powerCell, powerCellSlot, ReplacementStrategy.Cancel);

            SpawnResult frameSpawn = Spawn.ServerPrefab(APCFrameObj, SpawnDestination.At(gameObject));

            if (frameSpawn.Successful == false)
            {
                Logger.LogError($"Failed to spawn frame! Is {this} missing references in the inspector?", Category.Construction);
                return;
            }

            GameObject frame = frameSpawn.GameObject;

            frame.GetComponent <APCFrame>().ServerInitFromComputer(this);

            var Directional = frame.GetComponent <Directional>();

            if (Directional != null)
            {
                Directional.FaceDirection(gameObject.GetComponent <Directional>().CurrentDirection);
            }

            _ = Despawn.ServerSingle(gameObject);

            integrity.OnWillDestroyServer.RemoveListener(WhenDestroyed);
        }
示例#10
0
        private void TryDeconstruct(HandApply interaction)
        {
            //Only deconstruct if no AI inside
            if (linkedPlayer != null)
            {
                Chat.AddExamineMsgFromServer(interaction.Performer, "Transfer the Ai to an intelicard before you deconstruct");
                return;
            }

            ToolUtils.ServerUseToolWithActionMessages(interaction, 5f,
                                                      "You start unscrewing in the glass on the Ai core...",
                                                      $"{interaction.Performer.ExpensiveName()} starts unscrewing the glass on the Ai core...",
                                                      "You unscrew the glass on the Ai core.",
                                                      $"{interaction.Performer.ExpensiveName()} unscrews the glass on the Ai core.",
                                                      () =>
            {
                var newCoreFrame = Spawn.ServerPrefab(aiCoreFramePrefab, SpawnDestination.At(gameObject), 1);

                if (newCoreFrame.Successful)
                {
                    newCoreFrame.GameObject.GetComponent <AiCoreFrame>().SetUp();
                }

                _ = Despawn.ServerSingle(gameObject);
            });
        }
示例#11
0
    public void ServerPerformInteraction(InventoryApply interaction)
    {
        //is the target item cuttable?
        ItemAttributesV2 attr       = interaction.TargetObject.GetComponent <ItemAttributesV2>();
        Ingredient       ingredient = new Ingredient(attr.ArticleName);
        GameObject       roll       = CraftingManager.Roll.FindRecipe(new List <Ingredient> {
            ingredient
        });

        if (roll)
        {
            Inventory.ServerDespawn(interaction.TargetSlot);

            SpawnResult spwn = Spawn.ServerPrefab(CraftingManager.Roll.FindOutputMeal(roll.name),
                                                  SpawnDestination.At(), 1);

            if (spwn.Successful)
            {
                Inventory.ServerAdd(spwn.GameObject, interaction.TargetSlot);
            }
        }
        else
        {
            Chat.AddExamineMsgFromServer(interaction.Performer, "You can't roll this out.");
        }
    }
示例#12
0
    public SpawnableResult ClientSpawnAt(SpawnDestination destination)
    {
        bool isPooled;         // not used for Client-only instantiation
        var  go = Spawn._PoolInstantiate(prefab, destination, out isPooled);

        return(SpawnableResult.Single(go, destination));
    }
示例#13
0
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        if (!SpawnableUtils.IsValidDestination(destination))
        {
            return(SpawnableResult.Fail(destination));
        }

        if (prefab == null)
        {
            Logger.LogWarning("Cannot spawn, prefab to use is null", Category.ItemSpawn);
            return(SpawnableResult.Fail(destination));
        }
        Logger.LogTraceFormat("Spawning using prefab {0}", Category.ItemSpawn, prefab);

        bool isPooled;

        GameObject tempObject = Spawn._PoolInstantiate(prefab, destination,
                                                       out isPooled);

        if (!isPooled)
        {
            Logger.LogTrace("Prefab to spawn was not pooled, spawning new instance.", Category.ItemSpawn);
            NetworkServer.Spawn(tempObject);
            tempObject.GetComponent <CustomNetTransform>()
            ?.NotifyPlayers();                     //Sending clientState for newly spawned items
        }
        else
        {
            Logger.LogTrace("Prefab to spawn was pooled, reusing it...", Category.ItemSpawn);
        }

        return(SpawnableResult.Single(tempObject, destination));
    }
示例#14
0
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        var prefab = Spawn.DeterminePrefab(toClone);

        if (prefab == null)
        {
            Logger.LogErrorFormat(
                "Object {0} cannot be cloned because it has no PoolPrefabTracker and its name" +
                " does not match a prefab name, so we cannot" +
                " determine the prefab to instantiate. Please fix this object so that it" +
                " has an attached PoolPrefabTracker or so its name matches the prefab it was created from.",
                Category.ItemSpawn, toClone);
            return(SpawnableResult.Fail(destination));
        }

        GameObject tempObject = Spawn._PoolInstantiate(prefab, destination,
                                                       out var isPooled);

        if (!isPooled)
        {
            NetworkServer.Spawn(tempObject);
            tempObject.GetComponent <CustomNetTransform>()
            ?.NotifyPlayers();                     //Sending clientState for newly spawned items
        }

        return(SpawnableResult.Single(tempObject, destination));
    }
示例#15
0
        /// <summary>
        /// Stage 2, Add the power control module to continue contruction, 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.Frame);
            }
            else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.PowerControlBoard))
            {
                //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, powerControlSlot);

                stateful.ServerChangeState(powerControlAddedState);

                spriteHandler.ChangeSprite((int)SpriteStates.FrameCircuit);
            }
        }
示例#16
0
 /// <summary>
 /// Stage 3, add airlock electronics which contains data of access, or use wirecutters to move to stage 2
 /// </summary>
 /// <param name="interaction"></param>
 private void CablesAddedStateInteraction(HandApply interaction)
 {
     if (Validations.HasUsedComponent <AirlockElectronics>(interaction) && airlockElectronicsSlot.IsEmpty)
     {
         ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                   "You start to install electronics into the airlock assembly...",
                                                   $"{interaction.Performer.ExpensiveName()} starts to install the electronics into the airlock assembly...",
                                                   "You install the airlock electronics.",
                                                   $"{interaction.Performer.ExpensiveName()} installs the electronics into the airlock assembly.",
                                                   () =>
         {
             if (Inventory.ServerTransfer(interaction.HandSlot, airlockElectronicsSlot))
             {
                 stateful.ServerChangeState(electronicsAddedState);
                 overlayHackingHandler.ChangeSprite((int)Panel.ElectronicsAdded);
             }
         });
     }
     else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Wirecutter))
     {
         //cut out cables
         ToolUtils.ServerUseToolWithActionMessages(interaction, 2f,
                                                   "You start to cut the cables from the airlock assembly...",
                                                   $"{interaction.Performer.ExpensiveName()} starts to cut the cables from the airlock assembly...",
                                                   "You cut the cables from the airlock assembly.",
                                                   $"{interaction.Performer.ExpensiveName()} cuts the cables from the airlock assembly.",
                                                   () =>
         {
             Spawn.ServerPrefab(CommonPrefabs.Instance.SingleCableCoil, SpawnDestination.At(gameObject));
             stateful.ServerChangeState(wrenchedState);
             overlayHackingHandler.ChangeSprite((int)Panel.EmptyPanel);
         });
     }
 }
示例#17
0
        /// <summary>
        /// Stage 5, complete construction, or remove board and return to stage 3.
        /// </summary>
        /// <param name="interaction"></param>
        private void PartsAddedStateInteraction(HandApply interaction)
        {
            //Complete construction, spawn new machine and send data over to it.
            if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Screwdriver))
            {
                var spawnedObject = Spawn.ServerPrefab(machineParts.machine, SpawnDestination.At(gameObject)).GameObject.GetComponent <Machine>();

                if (spawnedObject == null)
                {
                    Logger.LogWarning(machineParts.machine + " is missing the machine script!", Category.ItemSpawn);
                    return;
                }

                //Send circuit board data to the new machine
                spawnedObject.SetBasicPartsUsed(basicPartsUsed);
                spawnedObject.SetPartsInFrame(partsInFrame);
                spawnedObject.SetMachineParts(machineParts);

                //Despawn frame
                Despawn.ServerSingle(gameObject);
            }
            else if (Validations.HasUsedItemTrait(interaction, CommonTraits.Instance.Crowbar) && circuitBoardSlot.IsOccupied)
            {
                //wrench out the circuit board, when it has all the parts in.
                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);

                RemoveCircuitAndParts();
            }
        }
示例#18
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);
         });
     }
 }
示例#19
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");
                }
            }
        }
示例#20
0
        /// <summary>
        /// Spawns the initial contents when needed, not always on game start so that theres less game objects
        /// </summary>
        public void TrySpawnContents(bool hideContents = false)
        {
            if (contentsSpawned)
            {
                return;
            }
            contentsSpawned = true;

            //Null check after setting true so we only do the null check once not every opening
            if (initialContents == null)
            {
                return;
            }

            //populate initial contents
            var result = initialContents.SpawnAt(SpawnDestination.At(gameObject));

            //Only hide if on spawn as the closet will be closed
            if (hideContents == false)
            {
                return;
            }

            foreach (var spawned in result.GameObjects)
            {
                var objBehavior = spawned.GetComponent <ObjectBehaviour>();
                if (objBehavior != null)
                {
                    ServerAddInternalItem(objBehavior);
                }
            }
        }
示例#21
0
        public Scanner ToggleScannerLid(GameObject scannerObj)
        {
            if (ScannerOpen)
            {
                return(new Scanner(false, ScannerEmpty, DocumentText, ScannedText));
            }
            else
            {
                //If we're opening the scanner and it aint empty spawn paper
                if (!ScannerEmpty)
                {
                    var prefab = Spawn.GetPrefabByName("Paper");
                    var result = Spawn.ServerPrefab(prefab, SpawnDestination.At(scannerObj));
                    if (!result.Successful)
                    {
                        throw new InvalidOperationException("Spawn paper failed!");
                    }

                    var paperObj = result.GameObject;
                    var paper    = paperObj.GetComponent <Paper>();
                    paper.SetServerString(DocumentText);
                    return(new Scanner(true, true, null, ScannedText));
                }
                else
                {
                    return(new Scanner(true, ScannerEmpty, DocumentText, ScannedText));
                }
            }
        }
示例#22
0
        /// <summary>
        /// Stage 1, Add cable to continue or welder to destroy frame.
        /// </summary>
        /// <param name="interaction"></param>
        private void InitialStateInteraction(HandApply interaction)
        {
            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);

                    spriteHandler.ChangeSprite((int)SpriteStates.BoxCable);
                });
            }
            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);
                });
            }
        }
示例#23
0
        public void WhenDestroyed(DestructionInfo info)
        {
            //drop all our contents
            ItemStorage itemStorage = null;

            // rare cases were gameObject is destroyed for some reason and then the method is called
            if (gameObject == null)
            {
                return;
            }

            itemStorage = GetComponent <ItemStorage>();

            if (itemStorage != null)
            {
                itemStorage.ServerDropAll();
            }

            SpawnResult frameSpawn = Spawn.ServerPrefab(framePrefab, SpawnDestination.At(gameObject));

            if (!frameSpawn.Successful)
            {
                Logger.LogError($"Failed to spawn frame! Is {this} missing reference to {nameof(framePrefab)} in the inspector?");
                return;
            }

            GameObject frame = frameSpawn.GameObject;

            frame.GetComponent <MachineFrame>().ServerInitFromComputer(this);

            Despawn.ServerSingle(gameObject);

            integrity.OnWillDestroyServer.RemoveListener(WhenDestroyed);
        }
示例#24
0
    public void ServerPerformInteraction(InventoryApply interaction)
    {
        //is the target item chopable?
        ItemAttributesV2 attr       = interaction.TargetObject.GetComponent <ItemAttributesV2>();
        Ingredient       ingredient = new Ingredient(attr.ArticleName);
        GameObject       cut        = CraftingManager.Logs.FindRecipe(new List <Ingredient> {
            ingredient
        });

        if (cut != null)
        {
            Inventory.ServerDespawn(interaction.TargetSlot);

            SpawnResult spwn = Spawn.ServerPrefab(CraftingManager.Logs.FindOutputMeal(cut.name),
                                                  SpawnDestination.At(), 1);

            if (spwn.Successful)
            {
                //foreach (GameObject obj in spwn.GameObjects)
                //{
                //	Inventory.ServerAdd(obj,interaction.TargetSlot);
                //}

                Inventory.ServerAdd(spwn.GameObject, interaction.TargetSlot);
            }
        }
        else
        {
            Chat.AddExamineMsgFromServer(interaction.Performer, "You can't chop this.");
        }
    }
示例#25
0
    /// <summary>
    /// Spawns the things defined in this list at the indicated destination
    /// </summary>
    /// <param name="destination"></param>
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        if (!SpawnableUtils.IsValidDestination(destination))
        {
            return(SpawnableResult.Fail(destination));
        }

        List <GameObject> spawned = new List <GameObject>();

        foreach (var prefab in contents)
        {
            var result = Spawn.ServerPrefab(prefab, destination);
            if (!result.Successful)
            {
                Logger.LogWarningFormat("An item in SpawnableList {0} is missing, please fix prefab reference.", Category.ItemSpawn,
                                        name);
            }
            else
            {
                spawned.AddRange(result.GameObjects);
            }
        }

        return(SpawnableResult.Multiple(spawned, destination));
    }
示例#26
0
 private SpawnableResult(bool successful, GameObject gameObject,
                         IEnumerable <GameObject> gameObjects, SpawnDestination spawnDestination)
 {
     Successful       = successful;
     GameObject       = gameObject;
     SpawnDestination = spawnDestination;
     GameObjects      = gameObjects;
 }
示例#27
0
    /// <summary>
    /// Spawning multiple objects was successful
    /// </summary>
    /// <param name="spawned">objects that were newly spawned</param>
    /// <param name="destination">destination the objects were spawned at</param>
    /// <returns></returns>
    public static SpawnableResult Multiple(IEnumerable <GameObject> spawned, SpawnDestination destination)
    {
        var gameObjects = spawned as GameObject[] ?? spawned.ToArray();

        return(new SpawnableResult(true, gameObjects.First(),
                                   gameObjects,
                                   destination));
    }
示例#28
0
 /// <summary>
 /// Spawn the specified prefab locally, for this client only.
 /// </summary>
 /// <param name="prefabName">name of prefab to spawn an instance of. This is intended to be made to work for pretty much any prefab, but don't
 /// be surprised if it doesn't as there are LOTS of prefabs in the game which all have unique behavior for how they should spawn. If you are trying
 /// to instantiate something and it isn't properly setting itself up, check to make sure each component that needs to set something up has
 /// properly implemented necessary lifecycle methods.</param>
 /// <param name="worldPosition">world position to appear at. Defaults to HiddenPos (hidden / invisible)</param>
 /// <param name="localRotation">local rotation to spawn with, defaults to Quaternion.identity</param>
 /// <param name="parent">Parent to spawn under, defaults to no parent. Most things
 /// should always be spawned under the Objects transform in their matrix. Many objects (due to RegisterTile)
 /// usually take care of properly parenting themselves when spawned so in many cases you can leave it null.</param>
 /// <param name="count">number of instances to spawn, defaults to 1</param>
 /// <param name="scatterRadius">radius to scatter the spawned instances by from their spawn position. Defaults to
 /// null (no scatter).</param>
 /// <returns>the newly created GameObject</returns>
 public static SpawnResult ClientPrefab(string prefabName, Vector3?worldPosition = null, Transform parent = null, Quaternion?localRotation = null, int count = 1, float?scatterRadius = null)
 {
     return(Client(
                SpawnInfo.Spawnable(
                    SpawnablePrefab.For(prefabName),
                    SpawnDestination.At(worldPosition, parent, localRotation),
                    count, scatterRadius)));
 }
示例#29
0
 /// <summary>
 /// Spawn the specified prefab, syncing it to all clients
 /// </summary>
 /// <param name="prefab">Prefab to spawn an instance of. This is intended to be made to work for pretty much any prefab, but don't
 /// be surprised if it doesn't as there are LOTS of prefabs in the game which all have unique behavior for how they should spawn. If you are trying
 /// to instantiate something and it isn't properly setting itself up, check to make sure each component that needs to set something up has
 /// properly implemented necessary lifecycle methods.</param>
 /// <param name="destination">destination to spawn at</param>
 /// <param name="count">number of instances to spawn, defaults to 1</param>
 /// <param name="scatterRadius">radius to scatter the spawned instances by from their spawn position. Defaults to
 /// null (no scatter).</param>
 /// <returns>the newly created GameObject</returns>
 public static SpawnResult ServerPrefab(GameObject prefab, SpawnDestination destination, int count = 1, float?scatterRadius = null)
 {
     return(Server(
                SpawnInfo.Spawnable(
                    SpawnablePrefab.For(prefab),
                    destination,
                    count, scatterRadius)));
 }
        public void ServerPerformInteraction(HandApply interaction)
        {
            if (interaction.TargetObject != gameObject)
            {
                return;
            }

            if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.PlasteelSheet))
            {
                if (strutsUnsecured == false)
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 5f,
                                                              "You start finalizing the reinforced wall...",
                                                              $"{interaction.Performer.ExpensiveName()} starts finalizing the reinforced wall...",
                                                              "You fully reinforce the wall.",
                                                              $"{interaction.Performer.ExpensiveName()} fully reinforces the wall.",
                                                              () => ConstructReinforcedWall(interaction));
                }
            }
            else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Screwdriver))
            {
                if (strutsUnsecured == false)
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start unsecuring the support struts...",
                                                              $"{interaction.Performer.ExpensiveName()} starts unsecuring the support struts...",
                                                              "You unsecure the support struts.",
                                                              $"{interaction.Performer.ExpensiveName()} unsecures the support struts.",
                                                              () => strutsUnsecured = true);
                }
                else
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start securing the support struts...",
                                                              $"{interaction.Performer.ExpensiveName()} starts securing the support struts...",
                                                              "You secure the support struts.",
                                                              $"{interaction.Performer.ExpensiveName()} secure the support struts.",
                                                              () => strutsUnsecured = false);
                }
            }
            else if (Validations.HasItemTrait(interaction.HandObject, CommonTraits.Instance.Wirecutter))
            {
                if (strutsUnsecured)
                {
                    ToolUtils.ServerUseToolWithActionMessages(interaction, 4f,
                                                              "You start removing the inner grille...",
                                                              $"{interaction.Performer.ExpensiveName()} starts removing the inner grille...",
                                                              "You remove the inner grille.",
                                                              $"{interaction.Performer.ExpensiveName()} removes the inner grille.",
                                                              () =>
                    {
                        Spawn.ServerPrefab(girder, SpawnDestination.At(gameObject));
                        Spawn.ServerPrefab(CommonPrefabs.Instance.Plasteel, SpawnDestination.At(gameObject));
                        _ = Despawn.ServerSingle(gameObject);
                    });
                }
            }
        }