[HarmonyPrefix] // We're attempting to replace the geometry building method
            public static bool Prefix(ref Base __instance, Int3 cell)
            {
                Int3 v = Base.CellSize[7];

                Int3.Bounds         bounds = new Int3.Bounds(cell, cell + v - 1);
                BaseDeconstructable parent = null;

                if (__instance.GetCellMask(cell))
                {
                    Transform transform = __instance.SpawnPiece(Base.Piece.Moonpool, cell);
                    parent        = BaseDeconstructable.MakeCellDeconstructable(transform, bounds, TechType.BaseMoonpool);
                    transform.tag = "MainPieceGeometry";
                }
                for (int i = 0; i < Base.moonpoolFaces.Length; i++)
                {
                    Base.RoomFace roomFace = Base.moonpoolFaces[i];
                    Base.Face     face     = new Base.Face(cell + roomFace.offset, roomFace.direction);
                    if (__instance.GetFaceMask(face))
                    {
                        Base.FaceType face2         = __instance.GetFace(face);
                        Base.Piece    moonpoolPiece = __instance.GetMoonpoolPiece(face, face2);
                        if (moonpoolPiece != Base.Piece.Invalid)
                        {
                            Transform transform2 = __instance.SpawnPiece(moonpoolPiece, cell, roomFace.rotation, null);
                            transform2.localPosition = Int3.Scale(roomFace.offset, Base.cellSize) + roomFace.localOffset;
                            if (face2 != Base.FaceType.Solid)
                            {
                                TechType            recipe = Base.FaceToRecipe[(int)face2];
                                BaseDeconstructable baseDeconstructable = BaseDeconstructable.MakeFaceDeconstructable(transform2, bounds, face, face2, recipe);
                                if (!__instance.isGhost)
                                {
                                    transform2.GetComponentsInChildren <IBaseModuleGeometry>(true, Base.sBaseModulesGeometry);
                                    int j     = 0;
                                    int count = Base.sBaseModulesGeometry.Count;
                                    while (j < count)
                                    {
                                        IBaseModuleGeometry baseModuleGeometry = Base.sBaseModulesGeometry[j];
                                        baseModuleGeometry.geometryFace = face;
                                        j++;
                                    }
                                    Base.sBaseModulesGeometry.Clear();
                                    if (face2 == Base.FaceType.UpgradeConsole)
                                    {
                                        baseDeconstructable.LinkModule(new Base.Face?(new Base.Face(face.cell - __instance.anchor, face.direction)));
                                    }
                                }
                            }
                            else if (!__instance.isGhost)
                            {
                                BaseExplicitFace.MakeFaceDeconstructable(transform2, face, parent);
                            }
                        }
                    }
                }
                return(false);
            }
        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);
                    }
                }
            }
        }
Example #3
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);
                    }
                }
            }
        }