Beispiel #1
0
        private void DeconstructionBegin(DeconstructionBeginEvent begin)
        {
            GameObject    deconstructing = NitroxEntity.RequireObjectFrom(begin.PieceId);
            Constructable constructable  = deconstructing.RequireComponent <Constructable>();

            constructable.SetState(false, false);
        }
Beispiel #2
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            Log.Info("Constructed completed " + constructionCompleted.Guid);
            GameObject constructing = GuidHelper.RequireObjectFrom(constructionCompleted.Guid);

            ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>();

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructableBase)
            {
                constructableBase.constructedAmount = 1f;
                constructableBase.SetState(true, true);

                Optional <object> opBasePiece   = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE);
                GameObject        finishedPiece = (GameObject)opBasePiece.Get();
                UnityEngine.Object.Destroy(constructableBase.gameObject);
                GuidHelper.SetNewGuid(finishedPiece, constructionCompleted.Guid);
            }
            else
            {
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);
            }

            if (constructionCompleted.BaseGuid != null && GuidHelper.GetObjectFrom(constructionCompleted.BaseGuid).IsEmpty())
            {
                Log.Info("Creating base: " + constructionCompleted.BaseGuid);
                ConfigureNewlyConstructedBase(constructionCompleted.BaseGuid);
            }
        }
Beispiel #3
0
        public override void Process(DeconstructionBegin packet)
        {
            GameObject    deconstructing = GuidHelper.RequireObjectFrom(packet.Guid);
            Constructable constructable  = deconstructing.RequireComponent <Constructable>();

            constructable.SetState(false, false);
        }
Beispiel #4
0
        private void DeconstructionBegin(DeconstructionBeginEvent begin)
        {
            GameObject    deconstructing = GuidHelper.RequireObjectFrom(begin.Guid);
            Constructable constructable  = deconstructing.RequireComponent <Constructable>();

            constructable.SetState(false, false);
        }
Beispiel #5
0
        public static GameObject TryPlaceFurniture(SubRoot currentSub)
        {
            MultiplayerBuilder.Initialize();
            global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);

            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab);
            bool       flag       = false;
            bool       flag2      = false;

            if (currentSub != null)
            {
                flag  = currentSub.isBase;
                flag2 = currentSub.isCyclops;
                gameObject.transform.parent = currentSub.GetModulesRoot();
            }
            else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside)
            {
                SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>();
                if (componentInParent2 != null)
                {
                    gameObject.transform.parent = componentInParent2.GetModulesRoot();
                }
            }

            Transform expr_138 = gameObject.transform;

            expr_138.position = MultiplayerBuilder.placePosition;
            expr_138.rotation = MultiplayerBuilder.placeRotation;
            Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>();

            componentInParent3.SetState(false, true);
            global::Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1);
            if (MultiplayerBuilder.ghostModel != null)
            {
                UnityEngine.Object.Destroy(MultiplayerBuilder.ghostModel);
            }

            componentInParent3.SetIsInside(flag || flag2);
            SkyEnvironmentChanged.Send(gameObject, currentSub);

            if (currentSub != null && currentSub.isCyclops)
            {
                gameObject.transform.localPosition = overridePosition;
                gameObject.transform.localRotation = overrideQuaternion;
            }
            else
            {
                gameObject.transform.position = overridePosition;
                gameObject.transform.rotation = overrideQuaternion;
            }

            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;

            return(gameObject);
        }
Beispiel #6
0
        public static GameObject TryPlaceFurniture(SubRoot currentSub)
        {
#pragma warning disable CS0618
            //Disabling warning as we dont have the FModAsset to use instead.
            Utils.PlayEnvSound(PLACE_SOUND, ghostModel.transform.position);
#pragma warning restore CS0618

            GameObject gameObject = Object.Instantiate <GameObject>(prefab);
            bool       flag       = false;
            bool       flag2      = false;
            if (currentSub != null)
            {
                flag  = currentSub.isBase;
                flag2 = currentSub.isCyclops;
                gameObject.transform.parent = currentSub.GetModulesRoot();
            }
            else if (placementTarget != null && allowedOutside)
            {
                SubRoot componentInParent2 = placementTarget.GetComponentInParent <SubRoot>();
                if (componentInParent2 != null)
                {
                    gameObject.transform.parent = componentInParent2.GetModulesRoot();
                }
            }

            Transform expr138 = gameObject.transform;
            expr138.position = PlacePosition;
            expr138.rotation = PlaceRotation;
            Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>();
            componentInParent3.SetState(false);
            Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"));
            if (ghostModel != null)
            {
                Object.Destroy(ghostModel);
            }

            componentInParent3.SetIsInside(flag || flag2);
            SkyEnvironmentChanged.Send(gameObject, currentSub);

            if (currentSub != null && currentSub.isCyclops)
            {
                gameObject.transform.localPosition = OverridePosition;
                gameObject.transform.localRotation = OverrideQuaternion;
            }
            else
            {
                gameObject.transform.position = OverridePosition;
                gameObject.transform.rotation = OverrideQuaternion;
            }

            ghostModel       = null;
            prefab           = null;
            RotationMetadata = Optional.Empty;

            return(gameObject);
        }
Beispiel #7
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject    constructing  = GuidHelper.RequireObjectFrom(constructionCompleted.Guid);
            Constructable constructable = constructing.GetComponent <Constructable>();

            constructable.constructedAmount = 1f;
            constructable.SetState(true, true);

            if (constructionCompleted.NewBaseCreatedGuid.IsPresent())
            {
                string newBaseGuid = constructionCompleted.NewBaseCreatedGuid.Get();
                ConfigureNewlyConstructedBase(newBaseGuid);
            }
        }
Beispiel #8
0
        public override void Process(ConstructionCompleted completedPacket)
        {
            Log.Debug("Processing ConstructionCompleted " + completedPacket.Guid + " " + completedPacket.NewBaseCreatedGuid);

            GameObject    constructing  = GuidHelper.RequireObjectFrom(completedPacket.Guid);
            Constructable constructable = constructing.GetComponent <Constructable>();

            constructable.constructedAmount = 1f;
            constructable.SetState(true, true);

            if (completedPacket.NewBaseCreatedGuid.IsPresent())
            {
                string newBaseGuid = completedPacket.NewBaseCreatedGuid.Get();
                ConfigureNewlyConstructedBase(newBaseGuid);
            }
        }
Beispiel #9
0
        public override void Process(ConstructionCompleted completedPacket)
        {
            Console.WriteLine("Processing ConstructionCompleted " + completedPacket.Guid + " " + completedPacket.PlayerId + " " + completedPacket.NewBaseCreatedGuid);

            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(completedPacket.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject constructing = opGameObject.Get();

                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);

                if (completedPacket.NewBaseCreatedGuid.IsPresent())
                {
                    String newBaseGuid = completedPacket.NewBaseCreatedGuid.Get();
                    configureNewlyConstructedBase(newBaseGuid);
                }
            }
        }
Beispiel #10
0
        public override void Process(DeconstructionBegin packet)
        {
            Log.Info("Received deconstruction packet for id: " + packet.Id);

            GameObject deconstructing = NitroxEntity.RequireObjectFrom(packet.Id);

            Constructable       constructable       = deconstructing.GetComponent <Constructable>();
            BaseDeconstructable baseDeconstructable = deconstructing.GetComponent <BaseDeconstructable>();

            using (packetSender.Suppress <DeconstructionBegin>())
            {
                if (baseDeconstructable != null)
                {
                    TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, packet.Id);
                    baseDeconstructable.Deconstruct();
                }
                else if (constructable != null)
                {
                    constructable.SetState(false, false);
                }
            }
        }
        public override void Process(DeconstructionBegin packet)
        {
            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(packet.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject    deconstructing = opGameObject.Get();
                Constructable constructable  = deconstructing.GetComponent <Constructable>();

                if (constructable != null)
                {
                    constructable.SetState(false, false);
                }
                else
                {
                    Console.WriteLine("Gameobject did not have a valid constructable component!");
                }
            }
            else
            {
                Console.WriteLine("Could not find game object to deconstruct: " + packet.Guid);
            }
        }
        // Static reproduction of Constructable.Construct to replace the body of the existing method
        public static bool Construct(Constructable constructable)
        {
            if (constructable._constructed)
            {
                return(false);
            }

            var resourceMap = ConstructableResourceMap.GetValue(constructable) as List <TechType>;

            var count = resourceMap.Count;

            var resourceID = (int)ConstructableGetResourceId.Invoke(constructable, new object[] { });

            constructable.constructedAmount += Time.deltaTime / ((float)count * (float)ConstructableGetConstructInterval.Invoke(constructable, new object[] { }));
            constructable.constructedAmount  = Mathf.Clamp01(constructable.constructedAmount);

            var resourceID2 = (int)ConstructableGetResourceId.Invoke(constructable, new object[] { });

            if (resourceID != resourceID2)
            {
                var techType = resourceMap[resourceID2 - 1];
                if (!CrafterLogicHelper.DestroyItemInLocalContainers(techType) && GameModeUtils.RequiresIngredients())
                {
                    constructable.constructedAmount = (float)resourceID / (float)count;
                    return(false);
                }
            }

            ConstructableUpdateMaterial.Invoke(constructable, new object[] { });
            if (constructable.constructedAmount >= 1f)
            {
                constructable.SetState(true, true);
            }

            return(true);
        }
Beispiel #13
0
        public static bool Prefix(Constructable __instance)
        {
            var player = Player.main;

            if (player.isPiloting && GameModeUtils.RequiresIngredients())
            {
                if (__instance._constructed)
                {
                    return(false);
                }
#if BZ
                if (player.GetComponentInParent <Hoverbike>() is not null)
                {
                    return(true);
                }
#endif

                var count      = __instance.resourceMap.Count;
                var resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / (count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                var resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    var destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    var thisVehicle     = player.GetVehicle();
                    var storageCheck    = false;
                    if (thisVehicle != null)
                    {
                        switch (thisVehicle)
                        {
                        case Exosuit exosuit:
                            if (exosuit.storageContainer.container.Contains(destroyTechType) &&
                                exosuit.storageContainer.container.DestroyItem(destroyTechType))
                            {
                                storageCheck = true;
                            }
                            break;

                        case SeaMoth seaMoth:
                            for (var i = 0; i < 12; i++)
                            {
                                try
                                {
                                    var storage = seaMoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                    if (storage == null || !storage.Contains(destroyTechType))
                                    {
                                        continue;
                                    }
                                    if (!storage.DestroyItem(destroyTechType))
                                    {
                                        continue;
                                    }
                                    storageCheck = true;
                                    break;
                                }
                                catch
                                {
                                    // ignored
                                }
                            }
                            break;
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#if BZ
                    var seaTruck = player.GetComponentInParent <SeaTruckUpgrades>();
                    if (seaTruck != null)
                    {
                        foreach (var storageContainer in seaTruck.GetComponentsInChildren <StorageContainer>() ?? new StorageContainer[0])
                        {
                            try
                            {
                                if (!storageContainer.container.DestroyItem(destroyTechType))
                                {
                                    continue;
                                }
                                storageCheck = true;
                                break;
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
#endif
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    _ = __instance.SetState(true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #14
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null)
            {
                var thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(false);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    TechType destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        var storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                        {
                            storageContainer.container.DestroyItem(destroyTechType);
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  seamoth      = (SeaMoth)thisVehicle;
                        bool storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                var storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                                {
                                    storage.DestroyItem(destroyTechType);
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
        // Token: 0x06002B9D RID: 11165
        public static bool TryPlace()
        {
            MultiplayerBuilder.Initialize();
            if (MultiplayerBuilder.prefab == null || !MultiplayerBuilder.canPlace)
            {
                return(false);
            }
            global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();

            if (componentInParent != null)
            {
                BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();
                component.GhostBase.transform.position = overridePosition;
                component.Place();

                componentInParent.transform.position = overridePosition;

                component.transform.position = overridePosition;
                component.transform.rotation = overrideQuaternion;
                if (component.TargetBase != null)
                {
                    componentInParent.transform.SetParent(component.TargetBase.transform, true);
                }
                componentInParent.SetState(false, true);

                component.GhostBase.transform.position = overridePosition;

                if (component.TargetBase != null)
                {
                    component.TargetBase.transform.position = overridePosition;
                }
            }
            else
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab);
                bool       flag       = false;
                bool       flag2      = false;
                SubRoot    currentSub = Player.main.GetCurrentSub();
                if (currentSub != null)
                {
                    flag  = currentSub.isBase;
                    flag2 = currentSub.isCyclops;
                    gameObject.transform.parent = currentSub.GetModulesRoot();
                }
                else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside)
                {
                    SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>();
                    if (componentInParent2 != null)
                    {
                        gameObject.transform.parent = componentInParent2.GetModulesRoot();
                    }
                }
                Transform expr_138 = gameObject.transform;
                expr_138.position = MultiplayerBuilder.placePosition;
                expr_138.rotation = MultiplayerBuilder.placeRotation;
                Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>();
                componentInParent3.SetState(false, true);
                global::Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1);
                componentInParent3.SetIsInside(flag | flag2);
                SkyEnvironmentChanged.Send(gameObject, currentSub);
                gameObject.transform.position = overridePosition;
                gameObject.transform.rotation = overrideQuaternion;
            }
            Console.WriteLine("mBuilder.ghostModel.transform.position: " + MultiplayerBuilder.ghostModel.transform.position);
            Console.WriteLine("mBuilder.placePosition: " + MultiplayerBuilder.placePosition);
            Console.WriteLine("m op: " + MultiplayerBuilder.overridePosition);
            Console.WriteLine("m oq: " + MultiplayerBuilder.overrideQuaternion);
            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;
            return(true);
        }
Beispiel #16
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId);

            ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>();

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructableBase)
            {
                constructableBase.constructedAmount = 1f;
                constructableBase.SetState(true, true);

                Optional <object> latestBaseOp = TransientLocalObjectManager.Get(TransientObjectType.LATEST_BASE_WITH_NEW_CONSTRUCTION);

                Int3 latestCell;
                Base latestBase;

                if (latestBaseOp.IsPresent())
                {
                    latestCell = TransientLocalObjectManager.Require <Int3>(TransientObjectType.LATEST_BASE_CELL_WITH_NEW_CONSTRUCTION);
                    latestBase = (Base)latestBaseOp.Get();
                }
                else
                {
                    Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
                    latestBase = ((GameObject)opConstructedBase.Get()).GetComponent <Base>();
                    Validate.NotNull(latestBase, "latestBase can not be null");

                    Vector3 worldPosition;
                    float   distance;

                    latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out worldPosition, out distance);
                }

                Transform  cellTransform = latestBase.GetCellObject(latestCell);
                GameObject finishedPiece = null;

                // There can be multiple objects in a cell (such as a corridor with hatces built into it)
                // we look for a object that is able to be deconstucted that hasn't been tagged yet.
                foreach (Transform child in cellTransform)
                {
                    bool isNewBasePiece = (child.GetComponent <NitroxEntity>() == null &&
                                           child.GetComponent <BaseDeconstructable>() != null);

                    if (isNewBasePiece)
                    {
                        finishedPiece = child.gameObject;
                        break;
                    }
                }

                Validate.NotNull(finishedPiece, "Could not find finished piece in cell " + latestCell);

                Log.Info("Construction completed on a base piece: " + constructionCompleted.PieceId + " " + finishedPiece.name);

                UnityEngine.Object.Destroy(constructableBase.gameObject);
                NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId);

                BasePieceSpawnProcessor customSpawnProcessor = BasePieceSpawnProcessor.From(finishedPiece.GetComponent <BaseDeconstructable>());
                customSpawnProcessor.SpawnPostProcess(latestBase, latestCell, finishedPiece);
            }
            else
            {
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);

                Log.Info("Construction completed on a piece of furniture: " + constructionCompleted.PieceId + " " + constructable.gameObject.name);
            }

            if (constructionCompleted.BaseId != null && NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).IsEmpty())
            {
                Log.Info("Creating base: " + constructionCompleted.BaseId);
                ConfigureNewlyConstructedBase(constructionCompleted.BaseId);
            }
        }
Beispiel #17
0
        //=====================================================================
        // HandleInput
        //
        // Called by Update. Checks for input events and operates the Builder
        // accordingly
        //=====================================================================
        private void HandleInput()
        {
            if (this.handleInputFrame == Time.frameCount)
            {
                return;
            }
            this.handleInputFrame = Time.frameCount;
            if (Builder.isPlacing || !AvatarInputHandler.main.IsEnabled())
            {
                return;
            }
            Targeting.AddToIgnoreList(Player.main.gameObject);
            GameObject gameObject;
            float      num;

            // Range increased to 40 to give the seamoth more room
            Targeting.GetTarget(hitRange, out gameObject, out num, null);
            if (gameObject == null)
            {
                return;
            }
            // Bring up the construct menu on alt tool use
            //      (because the seamoth has lights bound to right hand)
            if (GameInput.GetButtonDown(GameInput.Button.AltTool))
            {
                uGUI_BuilderMenu.Show();
                return;
            }
            bool          constructHeld   = GameInput.GetButtonHeld(GameInput.Button.LeftHand);
            bool          deconstructDown = GameInput.GetButtonDown(GameInput.Button.Deconstruct);
            bool          deconstructHeld = GameInput.GetButtonHeld(GameInput.Button.Deconstruct);
            Constructable constructable   = gameObject.GetComponentInParent <Constructable>();

            if (constructable != null && num > constructable.placeMaxDistance)
            {
                constructable = null;
            }
            if (constructable != null)
            {
                this.OnHover(constructable);
                string text;
                if (constructHeld)
                {
                    this.Construct(constructable, true);
                }
                else if (constructable.DeconstructionAllowed(out text))
                {
                    if (deconstructHeld)
                    {
                        if (constructable.constructed)
                        {
                            constructable.SetState(false, false);
                        }
                        else
                        {
                            this.Construct(constructable, false);
                        }
                    }
                }
                else if (deconstructDown && !string.IsNullOrEmpty(text))
                {
                    ErrorMessage.AddMessage(text);
                }
            }
            else
            {
                BaseDeconstructable baseDeconstructable = gameObject.GetComponentInParent <BaseDeconstructable>();
                if (baseDeconstructable == null)
                {
                    BaseExplicitFace componentInParent = gameObject.GetComponentInParent <BaseExplicitFace>();
                    if (componentInParent != null)
                    {
                        baseDeconstructable = componentInParent.parent;
                    }
                }
                if (baseDeconstructable != null)
                {
                    string text;
                    if (baseDeconstructable.DeconstructionAllowed(out text))
                    {
                        this.OnHover(baseDeconstructable);
                        if (deconstructDown)
                        {
                            baseDeconstructable.Deconstruct();
                        }
                    }
                    else if (deconstructDown && !string.IsNullOrEmpty(text))
                    {
                        ErrorMessage.AddMessage(text);
                    }
                }
            }
        }
Beispiel #18
0
        // Token: 0x060030FF RID: 12543 RVA: 0x0012D7E8 File Offset: 0x0012B9E8
        public static bool TryPlace(out GameObject outObject, out Constructable outConstructable)
        {
            outObject        = null;
            outConstructable = null;

            MultiplayerBuilder.Initialize();

            if (MultiplayerBuilder.prefab == null)
            {
                return(false);
            }

            Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();

            if (componentInParent != null)
            {
                MultiplayerBuilder.Update();
                BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();

                component.Place();
                if (component.TargetBase != null)
                {
                    componentInParent.transform.SetParent(component.TargetBase.transform, true);
                }
                componentInParent.SetState(false, true);

                componentInParent.transform.position = overridePosition;
                componentInParent.transform.rotation = overrideRotation;

                outObject        = componentInParent.gameObject;
                outConstructable = componentInParent;
            }
            else
            {
                MultiplayerBuilder.placementTarget = GuidHelper.Find(targetGuid);

                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab);
                bool       flag       = false;
                bool       flag2      = false;

                SubRoot currentSub = Player.main.GetCurrentSub();
                if (currentSub != null)
                {
                    flag  = currentSub.isBase;
                    flag2 = currentSub.isCyclops;
                    gameObject.transform.parent = currentSub.GetModulesRoot();
                }
                else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside)
                {
                    SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>();
                    if (componentInParent2 != null)
                    {
                        gameObject.transform.parent = componentInParent2.GetModulesRoot();
                    }
                }
                Transform transform = gameObject.transform;
                transform.localPosition = overridePosition;
                transform.localRotation = overrideRotation;

                Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>();
                componentInParent3.SetState(false, true);
                Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1);
                if (MultiplayerBuilder.ghostModel != null)
                {
                    UnityEngine.Object.Destroy(MultiplayerBuilder.ghostModel);
                }
                componentInParent3.SetIsInside(flag || flag2);
                SkyEnvironmentChanged.Send(gameObject, currentSub);

                transform.localPosition = overridePosition;
                transform.localRotation = overrideRotation;

                outObject        = gameObject;
                outConstructable = componentInParent3;
            }
            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;
            return(true);
        }
Beispiel #19
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null || Player.main.GetComponentInParent <SeaTruckSegment>() != null)
            {
                var thisVehicle  = Player.main.GetVehicle();
                var thisSeatruck = Player.main.GetComponentInParent <SeaTruckSegment>();

                if (__instance._constructed)
                {
                    return(false);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    bool     storageCheck    = false;
                    TechType destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    if (thisVehicle != null)
                    {
                        if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                        {
                            StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                            if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                            {
                                storageContainer.container.DestroyItem(destroyTechType);
                                storageCheck = true;
                            }
                        }
                    }
                    else if (thisSeatruck != null)
                    {
                        SeaTruckSegment[]         seaTruckSegments = thisSeatruck.GetComponents <SeaTruckSegment>();
                        List <StorageContainer[]> containers       = new List <StorageContainer[]>();
                        foreach (SeaTruckSegment seaTruckSegment in seaTruckSegments)
                        {
                            containers.Add(seaTruckSegment.GetComponentsInChildren <StorageContainer>());
                        }
                        foreach (StorageContainer[] storageContainers in containers)
                        {
                            foreach (StorageContainer storageContainer in storageContainers)
                            {
                                if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                                {
                                    storageContainer.container.DestroyItem(destroyTechType);
                                    storageCheck = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #20
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId);

            ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>();

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructableBase)
            {
                Int3 latestCell = default(Int3);
                Base latestBase = null;

                // must fetch BEFORE setState or else the BaseGhost gets destroyed
                BaseGhost baseGhost = constructing.GetComponentInChildren <BaseGhost>();

                if (baseGhost)
                {
                    latestCell = baseGhost.TargetOffset;
                    latestBase = baseGhost.TargetBase;
                }

                constructableBase.constructedAmount = 1f;
                constructableBase.SetState(true, true);

                if (latestBase == null)
                {
                    Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
                    latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                    Validate.NotNull(latestBase, "latestBase can not be null");
                }

                Transform cellTransform = latestBase.GetCellObject(latestCell);

                if (latestCell == default(Int3) || cellTransform == null)
                {
                    Vector3 worldPosition;
                    float   distance;

                    latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out worldPosition, out distance);
                    cellTransform = latestBase.GetCellObject(latestCell);

                    Validate.NotNull(cellTransform, "Must have a cell transform, one not found near " + constructing.gameObject.transform.position + " for latestcell " + latestCell);
                }

                GameObject finishedPiece = null;

                // There can be multiple objects in a cell (such as a corridor with hatces built into it)
                // we look for a object that is able to be deconstucted that hasn't been tagged yet.
                foreach (Transform child in cellTransform)
                {
                    bool isNewBasePiece = (child.GetComponent <NitroxEntity>() == null &&
                                           child.GetComponent <BaseDeconstructable>() != null);

                    if (isNewBasePiece)
                    {
                        finishedPiece = child.gameObject;
                        break;
                    }
                }

                Validate.NotNull(finishedPiece, "Could not find finished piece in cell " + latestCell + " when constructing " + constructionCompleted.PieceId + " " + finishedPiece.name);

                Log.Info("Construction completed on a base piece: " + constructionCompleted.PieceId + " " + finishedPiece.name);

                UnityEngine.Object.Destroy(constructableBase.gameObject);
                NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId);

                BasePieceSpawnProcessor customSpawnProcessor = BasePieceSpawnProcessor.From(finishedPiece.GetComponent <BaseDeconstructable>());
                customSpawnProcessor.SpawnPostProcess(latestBase, latestCell, finishedPiece);
            }
            else
            {
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);

                Log.Info("Construction completed on a piece of furniture: " + constructionCompleted.PieceId + " " + constructable.gameObject.name);
            }

            if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue)
            {
                Log.Info("Creating base: " + constructionCompleted.BaseId);
                ConfigureNewlyConstructedBase(constructionCompleted.BaseId);
            }
        }
        private void HandleInput()
        {
            if (handleInputFrame == Time.frameCount)
            {
                return;
            }
            handleInputFrame = Time.frameCount;
            if (!AvatarInputHandler.main.IsEnabled())
            {
                return;
            }
            bool flag = TryDisplayNoPowerTooltip();

            if (flag)
            {
                return;
            }
            Targeting.AddToIgnoreList(Player.main.gameObject);
            Targeting.GetTarget(60f, out GameObject gameObject, out float num);
            if (gameObject == null)
            {
                return;
            }
            bool          buttonHeld    = GameInput.GetButtonHeld(GameInput.Button.LeftHand);
            bool          buttonDown    = GameInput.GetButtonDown(GameInput.Button.Deconstruct);
            bool          buttonHeld2   = GameInput.GetButtonHeld(GameInput.Button.Deconstruct);
            bool          quickbuild    = GameInput.GetButtonHeld(GameInput.Button.Sprint);
            Constructable constructable = gameObject.GetComponentInParent <Constructable>();

            if (constructable != null && num > constructable.placeMaxDistance * 2)
            {
                constructable = null;
            }
            if (constructable != null)
            {
                OnHover(constructable);
                if (buttonHeld)
                {
                    Construct(constructable, true);
                    if (quickbuild)
                    {
                        Construct(constructable, true);
                        Construct(constructable, true);
                        Construct(constructable, true);
                    }
                }
                else if (constructable.DeconstructionAllowed(out string text))
                {
                    if (buttonHeld2)
                    {
                        if (constructable.constructed)
                        {
                            constructable.SetState(false, false);
                        }
                        else
                        {
                            Construct(constructable, false);
                            if (quickbuild)
                            {
                                Construct(constructable, false);
                                Construct(constructable, false);
                                Construct(constructable, false);
                            }
                        }
                    }
                }
                else if (buttonDown && !string.IsNullOrEmpty(text))
                {
                    ErrorMessage.AddMessage(text);
                }
            }
            else
            {
                BaseDeconstructable baseDeconstructable = gameObject.GetComponentInParent <BaseDeconstructable>();
                if (baseDeconstructable == null)
                {
                    BaseExplicitFace componentInParent = gameObject.GetComponentInParent <BaseExplicitFace>();
                    if (componentInParent != null)
                    {
                        baseDeconstructable = componentInParent.parent;
                    }
                }
                else
                {
                    if (baseDeconstructable.DeconstructionAllowed(out string text))
                    {
                        OnHover(baseDeconstructable);
                        if (buttonDown)
                        {
                            baseDeconstructable.Deconstruct();
                        }
                    }
                    else if (buttonDown && !string.IsNullOrEmpty(text))
                    {
                        ErrorMessage.AddMessage(text);
                    }
                }
            }
        }
Beispiel #22
0
        public static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients())
            {
                Type            ConstructableType          = typeof(Constructable);
                List <TechType> resourceMapField           = (List <TechType>)AccessTools.Field(ConstructableType, "resourceMap").GetValue(__instance);
                MethodInfo      getResourceIDMethod        = AccessTools.Method(ConstructableType, "GetResourceID");
                MethodInfo      GetConstructIntervalMethod = AccessTools.Method(ConstructableType, "GetConstructInterval");
                MethodInfo      updateMaterialMethod       = AccessTools.Method(ConstructableType, "UpdateMaterial");


                Vehicle thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(false);
                }
                int   count      = resourceMapField.Count;
                int   resourceID = (int)getResourceIDMethod.Invoke(__instance, null);
                float backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / (count * (float)GetConstructIntervalMethod.Invoke(__instance, null));
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = (int)getResourceIDMethod.Invoke(__instance, null);
                if (resourceID2 != resourceID)
                {
                    TechType destroyTechType = resourceMapField[resourceID2 - 1];
                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.Contains(destroyTechType))
                        {
                            _ = storageContainer.container.DestroyItem(destroyTechType);
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  seamoth      = (SeaMoth)thisVehicle;
                        bool storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.Contains(destroyTechType))
                                {
                                    if (storage.DestroyItem(destroyTechType))
                                    {
                                        storageCheck = true;
                                        break;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                _ = updateMaterialMethod.Invoke(__instance, null);
                if (__instance.constructedAmount >= 1f)
                {
                    _ = __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }