Example #1
0
        public void ConstructionComplete(GameObject ghost)
        {
            NitroxId          baseId            = null;
            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            NitroxId id = NitroxEntity.GetId(ghost);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                baseId = NitroxEntity.GetId(constructedBase);
            }

            // For base pieces, we must switch the id from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>() != null)
            {
                Optional <object> opBasePiece   = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE);
                GameObject        finishedPiece = (GameObject)opBasePiece.Get();

                UnityEngine.Object.Destroy(ghost);
                NitroxEntity.SetNewId(finishedPiece, id);

                if (baseId == null)
                {
                    baseId = NitroxEntity.GetId(finishedPiece.GetComponentInParent <Base>().gameObject);
                }
            }

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(id, baseId);

            packetSender.Send(constructionCompleted);
        }
Example #2
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            if (!parent.HasValue)
            {
                return(Optional.Empty);
            }

            if (parent.Value.transform.childCount - 1 < entity.ExistingGameObjectChildIndex.Value)
            {
                Log.Error($"Parent {parent.Value} did not have a child at index {entity.ExistingGameObjectChildIndex.Value}");
                return(Optional.Empty);
            }

            GameObject gameObject = parent.Value.transform.GetChild(entity.ExistingGameObjectChildIndex.Value).gameObject;

            NitroxEntity.SetNewId(gameObject, entity.Id);

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
Example #3
0
    protected override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameObject finishedPiece)
    {
        bool builtLadderOnFloor = finishedPiece.name.Contains("Bottom");
        int  searchDirection    = builtLadderOnFloor ? -1 : 1;

        Int3 cellToSearch = Int3.zero;
        Optional <GameObject> otherLadderPiece = Optional.Empty;
        int  searchOffset = searchDirection;
        IMap map          = NitroxServiceLocator.LocateService <IMap>();
        int  maxY         = map.DimensionsInBatches.Y * map.BatchDimensions.Y;

        for (int i = 0; i < maxY; i++)
        {
            cellToSearch = new Int3(latestCell.x, latestCell.y + searchOffset, latestCell.z);

            if (!TryFindSecondLadderPiece(latestBase, cellToSearch, out otherLadderPiece) || otherLadderPiece.HasValue)
            {
                break;
            }
            searchOffset += searchDirection;
        }

        if (otherLadderPiece.HasValue)
        {
            // Ladders are one of the rare instances where we want to assign the same id to two different objects.
            // This happens because the ladder can be deconstructed from two locations (the top and bottom).
            NitroxId id = NitroxEntity.GetId(finishedPiece);
            NitroxEntity.SetNewId(otherLadderPiece.Value, id);
            Log.Debug($"Successfully set new id to other piece: {otherLadderPiece.Value.name}, id={id}");
        }
        else
        {
            Log.Error($"Could not locate other ladder piece when searching cells : {cellToSearch}, builtLadderOnFloor: {builtLadderOnFloor}");
        }
    }
        protected override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameObject finishedPiece)
        {
            NitroxId pieceId = NitroxEntity.GetId(finishedPiece);

            WaterParkPiece waterParkPiece = finishedPiece.GetComponent <WaterParkPiece>();

            if (!waterParkPiece)
            {
                // The BaseWater has multiple base pieces, but only one of them (the bottom) contains the WaterParkPiece component...
                return;
            }

            WaterPark waterPark = waterParkPiece.GetWaterParkModule();

            Validate.NotNull(waterPark, "WaterParkPiece without WaterParkModule?!?");

            // assuming there could be multiple pieces sharing the same waterpark we only create an ID if there is none.
            NitroxEntity waterEntity = waterPark.gameObject.GetComponent <NitroxEntity>();

            if (!waterEntity)
            {
                NitroxId newWaterparkId = pieceId.Increment();
                NitroxEntity.SetNewId(waterPark.gameObject, newWaterparkId);

                NitroxId newPlanterId = newWaterparkId.Increment();
                NitroxEntity.SetNewId(waterPark.planter.gameObject, newPlanterId);

                Log.Debug($"BaseRoomWaterParkProcessor: Created new Waterpark {newWaterparkId} and Planter {newPlanterId}");
            }
        }
Example #5
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            GameObject gameObject = SerializationHelper.GetGameObject(entity.SerializedGameObject);

            gameObject.transform.position   = entity.Transform.Position.ToUnity();
            gameObject.transform.rotation   = entity.Transform.Rotation.ToUnity();
            gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity();

            if (entity.WaterParkId != null)
            {
                AssignToWaterPark(gameObject, entity.WaterParkId);
            }

            EnableRigidBody(gameObject);
            ExecuteDropItemAction(entity.TechType.ToUnity(), gameObject);

            NitroxEntity.SetNewId(gameObject, entity.Id);

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
Example #6
0
        public static bool Prefix(Rocket __instance)
        {
            GameObject gameObject = __instance.gameObject;
            NitroxId   id         = NitroxEntity.GetId(gameObject);
            Optional <NeptuneRocketModel> model = NitroxServiceLocator.LocateService <Vehicles>().TryGetVehicle <NeptuneRocketModel>(id);

            if (!model.HasValue)
            {
                Log.Error($"{nameof(Rocket_Start_Patch)}: Could not find NeptuneRocketModel by Nitrox id {id}.\nGO containing wrong id: {__instance.GetHierarchyPath()}");
                return(false);
            }

            __instance.currentRocketStage = model.Value.CurrentStage;

            RocketConstructor rocketConstructor = gameObject.GetComponentInChildren <RocketConstructor>(true);

            if (rocketConstructor)
            {
                NitroxEntity.SetNewId(rocketConstructor.gameObject, model.Value.ConstructorId);
            }
            else
            {
                Log.Error($"{nameof(Rocket_Start_Patch)}: Could not find attached RocketConstructor to rocket with id {id}");
            }

            if (__instance.currentRocketStage > 0)
            {
                __instance.elevatorState    = model.Value.ElevatorUp ? Rocket.RocketElevatorStates.AtTop : Rocket.RocketElevatorStates.AtBottom;
                __instance.elevatorPosition = model.Value.ElevatorUp ? 1f : 0f;
                __instance.ReflectionCall("SetElevatorPosition", false, false);
            }

            return(true);
        }
Example #7
0
        public void AssignPlayerToEscapePod(EscapePodModel escapePod, bool firstTimeSpawning)
        {
            Validate.NotNull(escapePod, "Escape pod can not be null");
            NitroxEntity.SetNewId(EscapePod.main.gameObject, escapePod.Id);
            EscapePod.main.transform.position   = escapePod.Location.ToUnity();
            EscapePod.main.playerSpawn.position = escapePod.Location.ToUnity() + playerSpawnRelativeToEscapePodPosition; // This Might not correctly handle rotated EscapePods

            Rigidbody rigidbody = EscapePod.main.GetComponent <Rigidbody>();

            if (rigidbody != null)
            {
                Log.Debug("Freezing escape pod rigidbody");
                rigidbody.constraints = RigidbodyConstraints.FreezeAll;
            }
            else
            {
                Log.Error("Escape pod did not have a rigid body!");
            }

            Player.main.transform.position = EscapePod.main.playerSpawn.position;
            Player.main.transform.rotation = EscapePod.main.playerSpawn.rotation;
            if (firstTimeSpawning)
            {
                Player.main.currentEscapePod = EscapePod.main;
            }
            Player.main.escapePod.Update(true); // Tells the game to update various EscapePod features
            MyEscapePodId = escapePod.Id;
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int storageSlotsSynced = 0;

            HashSet <NitroxId> onlinePlayers = new HashSet <NitroxId> {
                packet.PlayerGameObjectId
            };

            onlinePlayers.AddRange(packet.RemotePlayerData.Select(playerData => playerData.PlayerContext.PlayerNitroxId));

            // Removes any batteries which are in inventories from offline players
            List <ItemData> currentlyIgnoredItems = packet.InventoryItems.Where(item => !onlinePlayers.Any(player => player.Equals(item.ContainerId))).ToList();

            packet.StorageSlotItems.RemoveAll(storageItem => currentlyIgnoredItems.Any(ignoredItem => ignoredItem.ItemId.Equals(storageItem.ContainerId)));

            using (packetSender.Suppress <StorageSlotItemAdd>())
            {
                foreach (ItemData itemData in packet.StorageSlotItems)
                {
                    waitScreenItem.SetProgress(storageSlotsSynced, packet.StorageSlotItems.Count);

                    GameObject item = SerializationHelper.GetGameObject(itemData.SerializedData);

                    Log.Debug($"Initial StorageSlot item data for {item.name} giving to container {itemData.ContainerId}");

                    NitroxEntity.SetNewId(item, itemData.ItemId);
                    slots.AddItem(item, itemData.ContainerId, true);

                    storageSlotsSynced++;
                    yield return(null);
                }
            }
        }
Example #9
0
    protected override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameObject finishedPiece)
    {
        NitroxId          moonpoolId = NitroxEntity.GetId(finishedPiece);
        VehicleDockingBay dockingBay = finishedPiece.RequireComponentInChildren <VehicleDockingBay>();

        NitroxId dockingBayId = moonpoolId.Increment();

        NitroxEntity.SetNewId(dockingBay.gameObject, dockingBayId);
    }
Example #10
0
        public override void Process(StorageSlotItemAdd packet)
        {
            ItemData   itemData = packet.ItemData;
            GameObject item     = SerializationHelper.GetGameObject(itemData.SerializedData);

            NitroxEntity.SetNewId(item, itemData.ItemId);

            storageSlots.AddItem(item, itemData.ContainerId);
        }
Example #11
0
 private void UpdateBasePieceIdIfPossible(GameObject gameObject, string key)
 {
     if (NitroxIdByObjectKey.TryGetValue(key, out NitroxId id))
     {
         Log.Debug("When respawning geometry, found face-based id to copy to new object: " + key + " " + id);
         NitroxEntity.SetNewId(gameObject, id);
         NitroxIdByObjectKey.Remove(key);
     }
 }
        public override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameObject finishedPiece)
        {
            NitroxId reactorId = NitroxEntity.GetId(finishedPiece);
            BaseBioReactorGeometry bioReactor       = finishedPiece.RequireComponent <BaseBioReactorGeometry>();
            GameObject             bioReactorModule = ((BaseBioReactor)bioReactor.ReflectionCall("GetModule")).gameObject;

            NitroxId moduleId = reactorId.Increment();

            NitroxEntity.SetNewId(bioReactorModule, moduleId);
        }
Example #13
0
        public static void Prefix(Base __instance, Base sourceBase)
        {
            NitroxEntity entity = sourceBase.GetComponent <NitroxEntity>();

            if (!sourceBase.GetComponent <BaseRoot>())
            {
                entity = sourceBase.transform.parent.GetComponent <NitroxEntity>();
            }

            NitroxEntity.SetNewId(__instance.gameObject, entity.Id);
        }
Example #14
0
        public GameObject CreateNewEscapePod(EscapePodModel model)
        {
            SURPRESS_ESCAPE_POD_AWAKE_METHOD = true;

            GameObject escapePod;

            if (model.Id == MyEscapePodId)
            {
                escapePod = EscapePod.main.gameObject;
            }
            else
            {
                escapePod = Object.Instantiate(EscapePod.main.gameObject);
                NitroxEntity.SetNewId(escapePod, model.Id);
            }

            escapePod.transform.position = model.Location.ToUnity();

            StorageContainer storageContainer = escapePod.RequireComponentInChildren <StorageContainer>();

            using (packetSender.Suppress <ItemContainerRemove>())
            {
                storageContainer.container.Clear();
            }

            NitroxEntity.SetNewId(storageContainer.gameObject, model.StorageContainerId);

            MedicalCabinet medicalCabinet = escapePod.RequireComponentInChildren <MedicalCabinet>();

            NitroxEntity.SetNewId(medicalCabinet.gameObject, model.MedicalFabricatorId);

            Fabricator fabricator = escapePod.RequireComponentInChildren <Fabricator>();

            NitroxEntity.SetNewId(fabricator.gameObject, model.FabricatorId);

            Radio radio = escapePod.RequireComponentInChildren <Radio>();

            NitroxEntity.SetNewId(radio.gameObject, model.RadioId);

            DamageEscapePod(model.Damaged, model.RadioDamaged);
            FixStartMethods(escapePod);

            // Start() isn't executed for the EscapePod, why? Idk, maybe because it's a scene...
            MultiplayerCinematicReference reference = escapePod.AddComponent <MultiplayerCinematicReference>();

            foreach (PlayerCinematicController controller in escapePod.GetComponentsInChildren <PlayerCinematicController>())
            {
                reference.AddController(controller);
            }

            SURPRESS_ESCAPE_POD_AWAKE_METHOD = false;

            return(escapePod);
        }
 public override void Process(InitialPlayerSync packet)
 {
     using (packetSender.Suppress <StorageSlotItemAdd>())
     {
         foreach (ItemData itemData in packet.StorageSlots)
         {
             GameObject item = SerializationHelper.GetGameObject(itemData.SerializedData);
             NitroxEntity.SetNewId(item, itemData.ItemId);
             slots.AddItem(item, itemData.ContainerId, true);
         }
     }
 }
Example #16
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int totalEquippedItemsDone = 0;

            using (packetSender.Suppress <ItemContainerAdd>())
            {
                foreach (EquippedItemData equippedItem in packet.EquippedItems)
                {
                    waitScreenItem.SetProgress(totalEquippedItemsDone, packet.EquippedItems.Count);

                    GameObject gameObject = SerializationHelper.GetGameObject(equippedItem.SerializedData);
                    NitroxEntity.SetNewId(gameObject, equippedItem.ItemId);

                    Pickupable            pickupable   = gameObject.RequireComponent <Pickupable>();
                    Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(equippedItem.ContainerId);

                    if (opGameObject.HasValue)
                    {
                        GameObject owner = opGameObject.Value;

                        Optional <Equipment> opEquipment = EquipmentHelper.FindEquipmentComponent(owner);

                        if (opEquipment.HasValue)
                        {
                            Equipment     equipment     = opEquipment.Value;
                            InventoryItem inventoryItem = new(pickupable);
                            inventoryItem.container = equipment;
                            inventoryItem.item.Reparent(equipment.tr);

                            Dictionary <string, InventoryItem> itemsBySlot = equipment.equipment;
                            itemsBySlot[equippedItem.Slot] = inventoryItem;

                            equipment.UpdateCount(pickupable.GetTechType(), true);
                            Equipment.SendEquipmentEvent(pickupable, 0, owner, equippedItem.Slot);
                            equipment.NotifyEquip(equippedItem.Slot, inventoryItem);
                        }
                        else
                        {
                            Log.Info("Could not find equipment type for " + gameObject.name);
                        }
                    }
                    else
                    {
                        Log.Info("Could not find Container for " + gameObject.name);
                    }

                    totalEquippedItemsDone++;
                    yield return(null);
                }
            }

            Log.Info("Recieved initial sync with " + totalEquippedItemsDone + " pieces of equipped items");
        }
        /**
         * On base pieces we need to have special logic during deconstruction to transfer the id from the main
         * object to the ghost.  This method will see if we have a stored LATEST_DECONSTRUCTED_BASE_PIECE_GUID
         * (set from deconstructor patch).  If we do, then we'll copy the id to the new ghost.  This is in
         * amount changed as we don't currently have a good hook for 'startDeconstruction'; this method will
         * run its logic on the first amount changed instead - effectively the same thing.
         */
        public static void CheckToCopyIdToGhost(Constructable __instance)
        {
            Optional <object> opId = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

            if (opId.IsPresent())
            {
                TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, null);

                NitroxId id = (NitroxId)opId.Get();
                Log.Info("Setting ghost id " + id);
                NitroxEntity.SetNewId(__instance.gameObject, id);
            }
        }
Example #18
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            NitroxInt3 cellId  = entity.AbsoluteEntityCell.CellId;
            NitroxInt3 batchId = entity.AbsoluteEntityCell.BatchId;

            cellRoot.liveRoot.name = string.Format("CellRoot {0}, {1}, {2}; Batch {3}, {4}, {5}", cellId.X, cellId.Y, cellId.Z, batchId.X, batchId.Y, batchId.Z);

            NitroxEntity.SetNewId(cellRoot.liveRoot, entity.Id);

            LargeWorldStreamer.main.cellManager.QueueForAwake(cellRoot);

            return(cellRoot.liveRoot);
        }
Example #19
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            NitroxInt3 cellId  = entity.AbsoluteEntityCell.CellId;
            NitroxInt3 batchId = entity.AbsoluteEntityCell.BatchId;

            cellRoot.liveRoot.name = $"CellRoot {cellId.X}, {cellId.Y}, {cellId.Z}; Batch {batchId.X}, {batchId.Y}, {batchId.Z}";

            NitroxEntity.SetNewId(cellRoot.liveRoot, entity.Id);

            LargeWorldStreamer.main.cellManager.QueueForAwake(cellRoot);

            return(Optional.OfNullable(cellRoot.liveRoot));
        }
        public override void Process(ItemContainerAdd packet)
        {
            ItemData   itemData = packet.ItemData;
            GameObject item     = SerializationHelper.GetGameObject(itemData.SerializedData);

            NitroxEntity.SetNewId(item, itemData.ItemId);

            itemContainer.AddItem(item, itemData.ContainerId);

            ContainerAddItemPostProcessor postProcessor = ContainerAddItemPostProcessor.From(item);

            postProcessor.process(item, itemData);
        }
Example #21
0
    /**
     * On base pieces we need to have special logic during deconstruction to transfer the id from the main
     * object to the ghost.  This method will see if we have a stored LATEST_DECONSTRUCTED_BASE_PIECE_GUID
     * (set from deconstructor patch or incoming deconstruction packet).  If we do, then we'll copy the id
     * to the new ghost.
     */
    public static void Postfix(Constructable __instance)
    {
        Optional <object> opId = Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

        if (opId.HasValue)
        {
            Remove(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

            NitroxId id = (NitroxId)opId.Value;
            Log.Debug($"Setting ghost id via Constructable_SetState_Patch {id} of GameObject: {__instance.gameObject}");
            NitroxEntity.SetNewId(__instance.gameObject, id);
        }
    }
Example #22
0
        /**
         * Crash fish are spawned by the CrashHome in the Monobehaviours Start method
         */
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            if (parent.HasValue)
            {
                CrashHome crashHome = parent.Value.GetComponent <CrashHome>();

                GameObject gameObject = Object.Instantiate(crashHome.crashPrefab, Vector3.zero, Quaternion.Euler(-90f, 0f, 0f));
                gameObject.transform.SetParent(crashHome.transform, false);
                NitroxEntity.SetNewId(gameObject, entity.Id);
                crashHome.crash = gameObject.GetComponent <Crash>();
            }

            return(Optional.Empty);
        }
Example #23
0
        protected override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameObject finishedPiece)
        {
            NitroxId   mapRoomGeometryPieceId = NitroxEntity.GetId(finishedPiece);
            GameObject mapRoomFunctionality   = FindUntaggedMapRoomFunctionality(latestBase);

            NitroxId mapRoomFunctionalityId = mapRoomGeometryPieceId.Increment();

            NitroxEntity.SetNewId(mapRoomFunctionality, mapRoomFunctionalityId);

            GameObject mapRoomModules   = mapRoomFunctionality.FindChild("MapRoomUpgrades");
            NitroxId   mapRoomModulesId = mapRoomFunctionalityId.Increment();

            NitroxEntity.SetNewId(mapRoomModules, mapRoomModulesId);
        }
Example #24
0
        /**
         * Crash fish are spawned by the CrashHome in the Monobehaviours Start method
         */
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            if (parent.IsPresent())
            {
                CrashHome crashHome = parent.Get().GetComponent <CrashHome>();

                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(crashHome.crashPrefab, Vector3.zero, Quaternion.Euler(-90f, 0f, 0f));
                gameObject.transform.SetParent(crashHome.transform, false);
                NitroxEntity.SetNewId(gameObject, entity.Id);
                ReflectionHelper.ReflectionSet <CrashHome>(crashHome, "crash", gameObject.GetComponent <Crash>());
            }

            return(Optional <GameObject> .Empty());
        }
Example #25
0
        public static void Prefix(Base __instance, Base sourceBase)
        {
            NitroxEntity entity = sourceBase.GetComponent <NitroxEntity>();

            // The game will clone the base when doing things like rebuilding gemometry or placing a new
            // piece.  The copy is normally between a base ghost and a base - and vise versa.  When building
            // a face piece, such as a window, this will clone a ghost base to stage the change which is later
            // integrated into the real base.  For now, prevent guid copies to these staging ghost bases; however,
            // there is still a pending edge case when a base converts to a BaseGhost for deconstruction.
            if (entity != null && __instance.gameObject.name != "BaseGhost")
            {
                Log.Debug("Transfering base id : " + entity.Id + " from " + sourceBase.name + " to " + __instance.name);
                NitroxEntity.SetNewId(__instance.gameObject, entity.Id);
            }
        }
Example #26
0
        /**
         * This function is called directly after the game clears all base pieces (to update
         * the view model - this is done in Base.ClearGeometry, see that patch).  The game will
         * respawn each object and we need to copy over their ids.  We reference the dictionary
         * in the ClearGemometry patch so know what ids to update.
         */
        public static void Postfix(Base __instance, Transform __result)
        {
            if (__instance == null || __result == null)
            {
                return;
            }

            NitroxId id;

            string key = Base_ClearGeometry_Patch.getObjectKey(__result.name, __result.position);

            if (Base_ClearGeometry_Patch.NitroxIdByObjectKey.TryGetValue(key, out id))
            {
                NitroxEntity.SetNewId(__result.gameObject, id);
            }
        }
Example #27
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            TechType       techType = entity.TechType.Enum();
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId);

            if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Optional.Of(Utils.CreateGenericLoot(techType)));
                }
            }

            GameObject gameObject = Utils.SpawnFromPrefab(prefab, null);

            gameObject.transform.position   = entity.Transform.Position;
            gameObject.transform.rotation   = entity.Transform.Rotation;
            gameObject.transform.localScale = entity.Transform.LocalScale;

            NitroxEntity.SetNewId(gameObject, entity.Id);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            if (parent.HasValue)
            {
                gameObject.transform.SetParent(parent.Value.transform, true);
            }

            if (parent.HasValue && !parent.Value.GetComponent <LargeWorldEntityCell>())
            {
                LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
            }
            else
            {
                gameObject.SetActive(true);
            }

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
Example #28
0
        public GameObject CreateNewEscapePod(EscapePodModel model)
        {
            SURPRESS_ESCAPE_POD_AWAKE_METHOD = true;

            GameObject escapePod;

            if (model.Id == MyEscapePodId)
            {
                escapePod = EscapePod.main.gameObject;
            }
            else
            {
                escapePod = Object.Instantiate(EscapePod.main.gameObject);
                NitroxEntity.SetNewId(escapePod, model.Id);
            }

            escapePod.transform.position = model.Location.ToUnity();

            StorageContainer storageContainer = escapePod.RequireComponentInChildren <StorageContainer>();

            using (packetSender.Suppress <ItemContainerRemove>())
            {
                storageContainer.container.Clear();
            }

            NitroxEntity.SetNewId(storageContainer.gameObject, model.StorageContainerId);

            MedicalCabinet medicalCabinet = escapePod.RequireComponentInChildren <MedicalCabinet>();

            NitroxEntity.SetNewId(medicalCabinet.gameObject, model.MedicalFabricatorId);

            Fabricator fabricator = escapePod.RequireComponentInChildren <Fabricator>();

            NitroxEntity.SetNewId(fabricator.gameObject, model.FabricatorId);

            Radio radio = escapePod.RequireComponentInChildren <Radio>();

            NitroxEntity.SetNewId(radio.gameObject, model.RadioId);

            DamageEscapePod(model.Damaged, model.RadioDamaged);
            FixStartMethods(escapePod);

            SURPRESS_ESCAPE_POD_AWAKE_METHOD = false;

            return(escapePod);
        }
Example #29
0
        public RemotePlayer(GameObject playerBody, PlayerContext playerContext, List <TechType> equippedTechTypes, List <Pickupable> inventoryItems, PlayerModelManager modelManager)
        {
            PlayerContext = playerContext;

            Body      = playerBody;
            Body.name = PlayerName;

            equipment = new HashSet <TechType>(equippedTechTypes);

            RigidBody            = Body.AddComponent <Rigidbody>();
            RigidBody.useGravity = false;

            NitroxEntity.SetNewId(Body, playerContext.PlayerNitroxId);

            // Get player
            PlayerModel = Body.RequireGameObject("player_view");
            // Move variables to keep player animations from mirroring and for identification
            ArmsController = PlayerModel.GetComponent <ArmsController>();
            ArmsController.smoothSpeedUnderWater = 0;
            ArmsController.smoothSpeedAboveWater = 0;

            // ConditionRules has Player.Main based conditions from ArmsController
            PlayerModel.GetComponent <ConditionRules>().enabled = false;

            AnimationController = PlayerModel.AddComponent <AnimationController>();

            Transform inventoryTransform = new GameObject("Inventory").transform;

            inventoryTransform.SetParent(Body.transform);
            Inventory = new ItemsContainer(6, 8, inventoryTransform, "NitroxInventoryStorage_" + PlayerName, null);
            foreach (Pickupable item in inventoryItems)
            {
                Inventory.UnsafeAdd(new InventoryItem(item));
                Log.Debug($"Added {item.name} to {playerContext.PlayerName}.");
            }

            ItemAttachPoint = PlayerModel.transform.Find(PlayerEquipmentConstants.ITEM_ATTACH_POINT_GAME_OBJECT_NAME);

            playerModelManager = modelManager;
            playerModelManager.AttachPing(this);
            playerModelManager.BeginApplyPlayerColor(this);
            playerModelManager.RegisterEquipmentVisibilityHandler(PlayerModel);
            UpdateEquipmentVisibility();

            ErrorMessage.AddMessage($"{PlayerName} joined the game.");
        }
        public static void SetInteractiveChildrenIds(GameObject constructedObject, List <InteractiveChildObjectIdentifier> interactiveChildIdentifiers)
        {
            foreach (InteractiveChildObjectIdentifier childIdentifier in interactiveChildIdentifiers)
            {
                Transform transform = constructedObject.transform.Find(childIdentifier.GameObjectNamePath);

                if (transform != null)
                {
                    GameObject gameObject = transform.gameObject;
                    NitroxEntity.SetNewId(gameObject, childIdentifier.Id);
                }
                else
                {
                    Log.Error("Error GUID tagging interactive child due to not finding it: " + childIdentifier.GameObjectNamePath);
                }
            }
        }