public static bool DoDismantleObject_Prefix(PlayerAction_Build __instance, int objId)
        {
            if (!SimulatedWorld.Initialized)
            {
                return(true);
            }

            int planetId = FactoryManager.TargetPlanet != FactoryManager.PLANET_NONE ? FactoryManager.TargetPlanet : __instance.planet?.id ?? -1;

            // TODO: handle if 2 clients or if host and client trigger a destruct of the same object at the same time

            // If the object is a prebuild, remove it from the prebuild request list
            if (LocalPlayer.IsMasterClient && objId < 0)
            {
                if (!FactoryManager.ContainsPrebuildRequest(planetId, -objId))
                {
                    Log.Warn($"DestructFinally was called without having a corresponding PrebuildRequest for the prebuild {-objId} on the planet {planetId}");
                    return(false);
                }

                FactoryManager.RemovePrebuildRequest(planetId, -objId);
            }


            if (LocalPlayer.IsMasterClient || !FactoryManager.EventFromServer)
            {
                LocalPlayer.SendPacket(new DestructEntityRequest(planetId, objId, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor));
            }

            return(LocalPlayer.IsMasterClient || FactoryManager.EventFromServer);
        }
Esempio n. 2
0
        public static void UpdatePreviews_Postfix(ref PlayerAction_Build __instance)
        {
            if (__instance.buildPreviews.Count > 0)
            {
                var counter = new Dictionary <string, int>();

                foreach (var buildPreview in __instance.buildPreviews)
                {
                    var name = buildPreview.item.name;

                    if (!counter.ContainsKey(name))
                    {
                        counter.Add(name, 0);
                    }

                    counter[name]++;
                }

                __instance.cursorText += $"\nUsing:";
                foreach (var entry in counter)
                {
                    __instance.cursorText += $"\n{SPACING}- {entry.Value} x {entry.Key}";
                }
            }
        }
        public override void ProcessPacket(DestructEntityRequest packet, NebulaConnection conn)
        {
            using (Multiplayer.Session.Factories.IsIncomingRequest.On())
            {
                PlanetData         planet = GameMain.galaxy.PlanetById(packet.PlanetId);
                PlayerAction_Build pab    = GameMain.mainPlayer.controller != null ? GameMain.mainPlayer.controller.actionBuild : null;

                // We only execute the code if the client has loaded the factory at least once.
                // Else they will get it once they go to the planet for the first time.
                if (planet?.factory == null || pab == null)
                {
                    return;
                }

                Multiplayer.Session.Factories.TargetPlanet = packet.PlanetId;
                Multiplayer.Session.Factories.PacketAuthor = packet.AuthorId;
                PlanetFactory tmpFactory = pab.factory;
                pab.factory          = planet.factory;
                pab.noneTool.factory = planet.factory;

                Multiplayer.Session.Factories.AddPlanetTimer(packet.PlanetId);

                // setting specifyPlanet here to avoid accessing a null object (see GPUInstancingManager activePlanet getter)
                PlanetData pData = GameMain.gpuiManager.specifyPlanet;

                GameMain.gpuiManager.specifyPlanet = GameMain.galaxy.PlanetById(packet.PlanetId);
                pab.DoDismantleObject(packet.ObjId);
                GameMain.gpuiManager.specifyPlanet = pData;

                pab.factory          = tmpFactory;
                pab.noneTool.factory = tmpFactory;
                Multiplayer.Session.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE;
                Multiplayer.Session.Factories.PacketAuthor = NebulaModAPI.AUTHOR_NONE;
            }
        }
Esempio n. 4
0
        public static bool PlayerAction_Build_CreatePrebuilds_Prefix(ref PlayerAction_Build __instance)
        {
            var runOriginal = true;

            if (__instance.waitConfirm && VFInput._buildConfirm.onDown && __instance.buildPreviews.Count > 0 &&
                MultiBuild.IsMultiBuildEnabled() && !__instance.multiLevelCovering)
            {
                if (MultiBuild.startPos == Vector3.zero)
                {
                    MultiBuild.startPos = __instance.groundSnappedPos;
                    lastPosition        = Vector3.zero;
                    runOriginal         = false;
                }
                else
                {
                    MultiBuild.startPos = Vector3.zero;
                    runOriginal         = true;
                }
            }
            if (__instance.waitConfirm && VFInput._buildConfirm.onDown && __instance.buildPreviews.Count > 1)
            {
                for (var i = 0; i < __instance.buildPreviews.Count; i++)
                {
                    var bp = __instance.buildPreviews[i];
                    if (bp.desc.isInserter && !IsInserterConnected(bp))
                    {
                        __instance.RemoveBuildPreview(bp);
                        --i;
                    }
                }
            }

            return(runOriginal);
        }
Esempio n. 5
0
        public static void RegularDeleteEntities(PlanetFactory factory, List <int> targetIds)
        {
            var player = GameMain.mainPlayer;

            PlayerAction_Build actionBuild = player.controller.actionBuild;

            using IDisposable toggle = UndoManager.IgnoreAllEvents.On();

            var stopwatch = new HighStopwatch();

            stopwatch.Begin();

            foreach (int objId in targetIds)
            {
                if (factory.entityPool[objId].stationId > 0 && BlueprintTweaksPlugin.excludeStations.Value)
                {
                    continue;
                }

                try
                {
                    DoDismantleObject(actionBuild, objId);
                }
                catch (Exception e)
                {
                    BlueprintTweaksPlugin.logger.LogWarning($"Error while dismantling entity {objId}, message: {e.Message}, stacktrace:\n{e.StackTrace}");
                }
            }

            var durationInS = stopwatch.duration;

            BlueprintTweaksPlugin.logger.LogDebug($"Took {durationInS} s to delete entities");
        }
Esempio n. 6
0
            public static void PlayerAction_BuildDetermineBuildPreviewsPostfix(PlayerAction_Build __instance)
            {
                // Do we have cached inserters?
                var ci = PatchCopyInserters.cachedInserters;

                if (CopyInserters.copyEnabled && ci.Count > 0)
                {
                    var bpCount = __instance.buildPreviews.Count;
                    for (int i = 0; i < bpCount; i++)
                    {
                        BuildPreview buildingPreview = __instance.buildPreviews[i];

                        if (!buildingPreview.item.prefabDesc.isInserter)
                        {
                            foreach (var inserter in ci)
                            {
                                var bp = BuildPreview.CreateSingle(LDB.items.Select(inserter.protoId), LDB.items.Select(inserter.protoId).prefabDesc, true);
                                bp.ResetInfos();

                                bp.lpos           = buildingPreview.lpos + buildingPreview.lrot * inserter.posDelta;
                                bp.lrot           = buildingPreview.lrot * inserter.rot;
                                bp.lpos2          = buildingPreview.lpos + buildingPreview.lrot * inserter.pos2Delta;
                                bp.lrot2          = buildingPreview.lrot * inserter.rot2;
                                bp.ignoreCollider = true;
                                __instance.AddBuildPreview(bp);
                            }
                        }
                    }
                }
            }
Esempio n. 7
0
        public void CheckAndFixConnections(PlayerAction_Build pab, PlanetData planet)
        {
            //Check and fix references to prebuilds
            Vector3 tmpVector = Vector3.zero;

            foreach (BuildPreview preview in pab.buildPreviews)
            {
                //Check only, if buildPreview has some connection to another prebuild
                if (preview.coverObjId < 0)
                {
                    tmpVector = pab.previewPose.position + pab.previewPose.rotation * preview.lpos;
                    if (planet.factory.prebuildPool[-preview.coverObjId].id != 0)
                    {
                        //Prebuild exists, check if it is same prebuild that client wants by comparing prebuild positions
                        if (tmpVector == planet.factory.prebuildPool[-preview.coverObjId].pos)
                        {
                            //Position of prebuilds are same, everything is OK.
                            continue;
                        }
                    }
                    // Prebuild does not exists, check what is the new ID of the finished building that was constructed from prebuild
                    // or
                    // Positions of prebuilds are different, which means this is different prebuild and we need to find ID of contructed building
                    foreach (EntityData entity in planet.factory.entityPool)
                    {
                        // `entity.pos == tmpVector` does not work in every cases (rounding errors?).
                        if ((entity.pos - tmpVector).sqrMagnitude < 0.1f)
                        {
                            preview.coverObjId = entity.id;
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public static void PlayerAction_Build_SetCopyInfo_Postfix(ref PlayerAction_Build __instance, int objectId)
        {
            if (bpMode)
            {
                EndBpMode(true);
            }
            BlueprintManager.Reset();
            if (objectId < 0)
            {
                return;
            }

            var itemProto = LDB.items.Select(__instance.factory.entityPool[objectId].protoId);

            if (itemProto.prefabDesc.insertPoses.Length > 0)
            {
                var toAdd = new List <int>()
                {
                    objectId
                };
                BlueprintManager.CopyEntities(toAdd);

                if (BlueprintManager.hasData)
                {
                    BlueprintManager.data.copiedBuildings[0].recipeId = __instance.copyRecipeId;
                    __instance.yaw = 0f;
                }
            }
        }
Esempio n. 9
0
        public static PlayerAction_Build ClonePlayerAction_Build(PlayerAction_Build original)
        {
            var nearcdClone = new NearColliderLogic()
            {
                planet             = original.nearcdLogic.planet,
                colChunks          = original.nearcdLogic.colChunks,
                activeColHashes    = new int[600],
                activeColHashCount = 0,
                colliderObjs       = original.nearcdLogic.colliderObjs
            };

            var clone = new PlayerAction_Build()
            {
                factory       = original.factory,
                player        = original.player,
                nearcdLogic   = nearcdClone,
                tmpPackage    = original.tmpPackage,
                planetAux     = original.planetAux,
                cursorTarget  = original.cursorTarget,
                buildPreviews = original.buildPreviews,
                planetPhysics = original.planetPhysics,
                previewPose   = new Pose(Vector3.zero, Quaternion.identity),
                posePairs     = new List <PlayerAction_Build.PosePair>(64),
                startSlots    = new List <PlayerAction_Build.SlotPoint>(64),
                endSlots      = new List <PlayerAction_Build.SlotPoint>(64)
            };

            return(clone);
        }
        public static void UpdatePreviews_Postfix(PlayerAction_Build __instance, List <Renderer> ___previewRenderers)
        {
            if (CopyInserters.IsCopyAvailable() && CopyInserters.copyEnabled)
            {
                var bpCount = __instance.buildPreviews.Count;
                for (int i = 0; i < bpCount; i++)
                {
                    BuildPreview buildPreview = __instance.buildPreviews[i];

                    if (buildPreview.item.prefabDesc.isInserter &&
                        buildPreview.condition == EBuildCondition.Ok &&
                        buildPreview.outputObjId == 0 && buildPreview.inputObjId == 0)
                    {
                        var originalMaterial = ___previewRenderers[buildPreview.previewIndex].sharedMaterial;

                        // this makes the inserter preview white-ish if not connected
                        var newMaterial = UnityEngine.Object.Instantiate <Material>(Configs.builtin.previewGizmoMat_Inserter);
                        newMaterial.SetVector("_Position1", originalMaterial.GetVector("_Position1"));
                        newMaterial.SetVector("_Position2", originalMaterial.GetVector("_Position2"));
                        newMaterial.SetVector("_Rotation1", originalMaterial.GetVector("_Rotation1"));
                        newMaterial.SetVector("_Rotation2", originalMaterial.GetVector("_Rotation2"));
                        ___previewRenderers[buildPreview.previewIndex].sharedMaterial = newMaterial;
                    }
                }
            }
        }
        public void ProcessPacket(DestructEntityRequest packet, NebulaConnection conn)
        {
            PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);

            // We only execute the code if the client has loaded the factory at least once.
            // Else it will get it once it goes to the planet for the first time.
            if (planet.factory != null)
            {
                int protoId = 0;
                using (FactoryManager.EventFromServer.On())
                    using (FactoryManager.DoNotAddItemsFromBuildingOnDestruct.On(packet.AuthorId != LocalPlayer.PlayerId))
                    {
                        if (packet.AuthorId == LocalPlayer.PlayerId)
                        {
                            //I am author so I will take item as a building
                            PlayerAction_Build pab = GameMain.mainPlayer.controller?.actionBuild;
                            if (pab != null)
                            {
                                int itemId = (packet.ObjId > 0 ? LDB.items.Select((int)planet.factory.entityPool[packet.ObjId].protoId) : LDB.items.Select((int)planet.factory.prebuildPool[-packet.ObjId].protoId))?.ID ?? -1;
                                //Todo: Check for the full accumulator building
                                if (itemId != -1)
                                {
                                    GameMain.mainPlayer.TryAddItemToPackage(itemId, 1, true, packet.ObjId);
                                    UIItemup.Up(itemId, 1);
                                }
                            }
                        }
                        planet.factory.DestructFinally(GameMain.mainPlayer, packet.ObjId, ref protoId);
                    }
            }
        }
Esempio n. 12
0
        public static void DestructEntityRequest(DestructEntityRequest packet)
        {
            PlanetData         planet = GameMain.galaxy.PlanetById(packet.PlanetId);
            PlayerAction_Build pab    = GameMain.mainPlayer.controller != null ? GameMain.mainPlayer.controller.actionBuild : null;

            // We only execute the code if the client has loaded the factory at least once.
            // Else they will get it once they go to the planet for the first time.
            if (planet?.factory == null || pab == null)
            {
                return;
            }

            FactoryManager.TargetPlanet = packet.PlanetId;
            FactoryManager.PacketAuthor = packet.AuthorId;
            PlanetFactory tmpFactory = pab.factory;

            pab.factory          = planet.factory;
            pab.noneTool.factory = planet.factory;

            FactoryManager.AddPlanetTimer(packet.PlanetId);
            pab.DoDismantleObject(packet.ObjId);

            pab.factory                 = tmpFactory;
            pab.noneTool.factory        = tmpFactory;
            FactoryManager.TargetPlanet = FactoryManager.PLANET_NONE;
            FactoryManager.PacketAuthor = -1;
        }
Esempio n. 13
0
        public static void ConcurrentEnoughItemCheck(BuildPreview buildPreview)
        {
            if (buildPreview.condition != EBuildCondition.Ok)
            {
                return;
            }

            PlayerAction_Build actionBuild = GameMain.data.mainPlayer.controller.actionBuild;

            lock (actionBuild)
            {
                // only check that we have enough items
                if (buildPreview.coverObjId == 0 || buildPreview.willCover)
                {
                    int id  = buildPreview.item.ID;
                    int num = 1;
                    if (actionBuild.tmpInhandId == id && actionBuild.tmpInhandCount > 0)
                    {
                        num = 1;
                        actionBuild.tmpInhandCount--;
                    }
                    else
                    {
                        actionBuild.tmpPackage.TakeTailItems(ref id, ref num, false);
                    }


                    if (num == 0)
                    {
                        buildPreview.condition = EBuildCondition.NotEnoughItem;
                    }
                }
            }
        }
Esempio n. 14
0
        public static bool DoDismantleObject_Prefix(PlayerAction_Build __instance, int objId)
        {
            if (!Multiplayer.IsActive)
            {
                return(true);
            }

            int planetId = Multiplayer.Session.Factories.TargetPlanet != NebulaModAPI.PLANET_NONE ? Multiplayer.Session.Factories.TargetPlanet : __instance.planet?.id ?? -1;

            // TODO: handle if 2 clients or if host and client trigger a destruct of the same object at the same time

            // If the object is a prebuild, remove it from the prebuild request list
            if (Multiplayer.Session.LocalPlayer.IsHost && objId < 0)
            {
                if (!Multiplayer.Session.Factories.ContainsPrebuildRequest(planetId, -objId))
                {
                    Log.Warn($"DestructFinally was called without having a corresponding PrebuildRequest for the prebuild {-objId} on the planet {planetId}");
                    return(false);
                }

                Multiplayer.Session.Factories.RemovePrebuildRequest(planetId, -objId);
            }


            if (Multiplayer.Session.LocalPlayer.IsHost || !Multiplayer.Session.Factories.IsIncomingRequest.Value)
            {
                Multiplayer.Session.Network.SendPacket(new DestructEntityRequest(planetId, objId, Multiplayer.Session.Factories.PacketAuthor == NebulaModAPI.AUTHOR_NONE ? Multiplayer.Session.LocalPlayer.Id : Multiplayer.Session.Factories.PacketAuthor));
            }

            return(Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.Factories.IsIncomingRequest.Value);
        }
Esempio n. 15
0
        public static bool DetermineBuildPreviewsPrePatch(PlayerAction_Build __instance)
        {
            var          _this = __instance;
            CommandState cmd   = _this.controller.cmd;

            if (_this.player.planetData.type != EPlanetType.Gas)
            {
                if (_this.handPrefabDesc != null)
                {
                    if (cmd.mode == 1)
                    {
                        if (_this.cursorValid)
                        {
                            if (_this.handPrefabDesc.minerType == EMinerType.None)
                            {
                                if (!_this.handPrefabDesc.multiLevel)
                                {
                                    if (!_this.multiLevelCovering)
                                    {
                                        DetermineBuildPreviews(_this);
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            begin = false;
            return(true);
        }
Esempio n. 16
0
        public static void AlterReference(PlayerAction_Build __instance)
        {
            if (referenceSelectionGizmo == null)
            {
                referenceSelectionGizmo                 = BoxGizmo.Create(Vector3.zero, Quaternion.identity, Vector3.zero, new Vector3(0.5f, 100f, 0.5f));
                referenceSelectionGizmo.multiplier      = 1f;
                referenceSelectionGizmo.alphaMultiplier = 0.5f;
                referenceSelectionGizmo.fadeInScale     = referenceSelectionGizmo.fadeOutScale = 1.3f;
                referenceSelectionGizmo.fadeInTime      = referenceSelectionGizmo.fadeOutTime = 0.05f;
                referenceSelectionGizmo.fadeInFalloff   = referenceSelectionGizmo.fadeOutFalloff = 0.5f;
                referenceSelectionGizmo.color           = Color.cyan;
            }

            if (areaSelectionGizmo != null)
            {
                areaSelectionGizmo.Close();
                areaSelectionGizmo = null;
            }

            bool isValidReference = false;

            if (__instance.castObjId != 0 && __instance.castObjId != referenceId && bpSelection.TryGetValue(__instance.castObjId, out BoxGizmo reference))
            {
                var       entityData = __instance.factory.entityPool[__instance.castObjId];
                ItemProto itemProto  = LDB.items.Select((int)entityData.protoId);
                if (__instance.castObjId == entityData.id &&
                    !itemProto.prefabDesc.isInserter &&
                    !itemProto.prefabDesc.isBelt &&
                    itemProto.prefabDesc.minerType == EMinerType.None)
                {
                    referenceSelectionGizmo.transform.position = reference.transform.position;
                    referenceSelectionGizmo.transform.rotation = reference.transform.rotation;
                    referenceSelectionGizmo.center             = reference.center;

                    isValidReference = true;
                }
            }


            if (isValidReference)
            {
                referenceSelectionGizmo.Open();
            }
            else
            {
                referenceSelectionGizmo.Close();
                referenceSelectionGizmo = null;
            }

            if (VFInput._buildConfirm.pressing && isValidReference)
            {
                referenceId = __instance.castObjId;

                referenceGizmo.transform.position = referenceSelectionGizmo.transform.position;
                referenceGizmo.transform.rotation = referenceSelectionGizmo.transform.rotation;
                referenceGizmo.center             = referenceSelectionGizmo.center;
            }
        }
Esempio n. 17
0
        public static bool CreatePrebuilds_Prefix(PlayerAction_Build __instance)
        {
            if (__instance.waitConfirm && VFInput._buildConfirm.onDown && __instance.buildPreviews.Count > 0)
            {
                if (!SimulatedWorld.Initialized)
                {
                    return(true);
                }

                // Host will just broadcast event to other players
                if (LocalPlayer.IsMasterClient)
                {
                    int planetId = FactoryManager.EventFactory?.planetId ?? GameMain.localPlanet?.id ?? -1;
                    LocalPlayer.SendPacket(new CreatePrebuildsRequest(planetId, __instance.buildPreviews, __instance.previewPose, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor));
                }

                //If client builds, he need to first send request to the host and wait for reply
                if (!LocalPlayer.IsMasterClient && !FactoryManager.EventFromServer)
                {
                    //Check what client can build from his inventory
                    List <BuildPreview> canBuild = new List <BuildPreview>();
                    //Remove required items from the player's inventory and build only what client can
                    foreach (BuildPreview buildPreview in __instance.buildPreviews)
                    {
                        //This code with flag was taken from original method:
                        bool flag = true;
                        if (buildPreview.coverObjId == 0 || buildPreview.willCover)
                        {
                            int id  = buildPreview.item.ID;
                            int num = 1;
                            if (__instance.player.inhandItemId == id && __instance.player.inhandItemCount > 0)
                            {
                                __instance.player.UseHandItems(1);
                            }
                            else
                            {
                                __instance.player.package.TakeTailItems(ref id, ref num, false);
                            }
                            flag = (num == 1);
                            if (flag)
                            {
                                //Give item back to player inventory and wait for the response from the server
                                __instance.player.package.AddItem(id, num);
                            }
                        }
                        if (flag)
                        {
                            canBuild.Add(buildPreview);
                        }
                    }

                    LocalPlayer.SendPacket(new CreatePrebuildsRequest(GameMain.localPlanet?.id ?? -1, canBuild, __instance.previewPose, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor));
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 18
0
            public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, RedoRequestPacket packet, INebulaConnection conn)
            {
                INebulaPlayer player = NebulaModAPI.MultiplayerSession.Network.PlayerManager.GetPlayer(conn);

                if (UndoManager.undos[player.Id].TryRedo(out string message, out bool sound))
                {
                    conn.SendPacket(new ActionResultPacket(message, sound));
                }
            }
Esempio n. 19
0
 public static void InitTool(PlayerAction_Build __instance)
 {
     BuildTool[] buildTools = __instance.tools;
     BuildTool[] ourTools   = new BuildTool[buildTools.Length + 1];
     buildTools.CopyTo(ourTools, 0);
     BlueprintTweaksPlugin.tool    = new DragRemoveBuildTool();
     ourTools[ourTools.Length - 1] = BlueprintTweaksPlugin.tool;
     __instance.tools = ourTools;
 }
Esempio n. 20
0
        public static void PrepareThreads()
        {
            PlayerAction_Build actionBuild = GameMain.data.mainPlayer.controller.actionBuild;

            for (var i = 0; i < Util.MAX_THREADS; i++)
            {
                _abs[i]           = Util.ClonePlayerAction_Build(actionBuild);
                _nearObjectIds[i] = new int[128];
            }
        }
Esempio n. 21
0
            public static bool Prefix(PlayerAction_Build __instance)
            {
                if (PrefixPreProcess(__instance) == true)
                {
                    return(true);
                }

                CreateEntityUpgradePreview(__instance, entityIdList, entityTypeList, PreviewsTypeFilter);
                return(false);
            }
Esempio n. 22
0
        public static void UpdateGrid(UIBuildingGrid __instance)
        {
            Player mainPlayer = GameMain.mainPlayer;

            PlanetFactory planetFactory = GameMain.localPlanet?.factory;

            if (planetFactory == null)
            {
                return;
            }

            if (GameMain.localPlanet.type == EPlanetType.Gas)
            {
                return;
            }

            PlayerAction_Build actionBuild = mainPlayer?.controller.actionBuild;

            if (actionBuild == null)
            {
                return;
            }

            if (actionBuild.blueprintMode != EBlueprintMode.None)
            {
                return;
            }

            if (!BlueprintTweaksPlugin.tool.active)
            {
                return;
            }
            if (BlueprintTweaksPlugin.tool.isSelecting)
            {
                __instance.blueprintMaterial.SetColor(tintColor, Color.clear);
                __instance.blueprintMaterial.SetVector(cursorGratBox, (Vector4)BlueprintTweaksPlugin.tool.preSelectGratBox);
                __instance.blueprintMaterial.SetVector(selectColor, __instance.dismantleColor);
                __instance.blueprintMaterial.SetFloat(showDivideLine, 0f);
                __instance.blueprintGridRnd.enabled = true;
            }
            else
            {
                __instance.blueprintMaterial.SetColor(tintColor, __instance.blueprintColor);
                __instance.blueprintMaterial.SetVector(cursorGratBox, Vector4.zero);
                __instance.blueprintMaterial.SetVector(selectColor, Vector4.one);
                __instance.blueprintMaterial.SetFloat(showDivideLine, 0f);
                __instance.blueprintGridRnd.enabled = false;
            }

            for (int l = 0; l < 64; l++)
            {
                __instance.blueprintMaterial.SetVector($"_CursorGratBox{l}", Vector4.zero);
                __instance.blueprintMaterial.SetFloat($"_CursorGratBoxInfo{l}", 0f);
            }
        }
Esempio n. 23
0
 public void HandlePlayerInput(PlayerAction_Build __instance)
 {
     if (Input.GetKeyDown(KeyCode.LeftControl))
     {
         Enable(Input.mousePosition);
     }
     else if (Input.GetKeyUp(KeyCode.LeftControl))
     {
         Disable();
     }
 }
Esempio n. 24
0
 public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, FastRemoveRequestPacket packet, INebulaConnection conn)
 {
     if (packet.UseEdgeVariant)
     {
         FastRemoveHelper.SwitchDelete(factory, packet.ObjIds.ToList(), packet.EdgeObjIds.ToList());
     }
     else
     {
         FastRemoveHelper.SwitchDelete(factory, packet.ObjIds.ToList());
     }
 }
Esempio n. 25
0
        public override void ProcessPacket(ReformPasteEventPacket packet, INebulaConnection conn)
        {
            PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);

            if (planet.factory == null)
            {
                return;
            }

            PlayerAction_Build       pab       = GameMain.mainPlayer.controller != null ? GameMain.mainPlayer.controller.actionBuild : null;
            BuildTool_BlueprintPaste buildTool = pab.blueprintPasteTool;

            IFactoryManager factoryManager = NebulaModAPI.MultiplayerSession.Factories;

            if (buildTool == null)
            {
                return;
            }

            factoryManager.TargetPlanet = packet.PlanetId;
            factoryManager.PacketAuthor = packet.AuthorId;

            PlanetFactory tmpFactory             = null;
            bool          loadExternalPlanetData = GameMain.localPlanet?.id != planet.id;

            if (loadExternalPlanetData)
            {
                tmpFactory = buildTool.factory;
                factoryManager.AddPlanetTimer(packet.PlanetId);
            }

            factoryManager.EventFactory = planet.factory;

            buildTool.factory = planet.factory;
            pab.factory       = planet.factory;

            using (factoryManager.IsIncomingRequest.On())
            {
                packet.GetData(out List <ReformData> reforms, out Color[] colors);
                BlueprintPasteExtension.CalculatePositions(buildTool, reforms, colors);
            }

            if (loadExternalPlanetData)
            {
                buildTool.factory = tmpFactory;
                pab.factory       = tmpFactory;
            }

            GameMain.mainPlayer.mecha.buildArea = Configs.freeMode.mechaBuildArea;
            factoryManager.EventFactory         = null;

            factoryManager.TargetPlanet = NebulaModAPI.PLANET_NONE;
            factoryManager.PacketAuthor = NebulaModAPI.AUTHOR_NONE;
        }
Esempio n. 26
0
        public override bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild)
        {
            using (UndoManager.IgnoreAllEvents.On())
            {
                FastRemoveHelper.SwitchDelete(factory, objectIds);
            }

            undoData.notifyBuildListeners.Remove(this);

            return(true);
        }
Esempio n. 27
0
        public static bool UpdatePreviewsPrePatch(PlayerAction_Build __instance)
        {
            var _this = __instance;

            if (begin)
            {
                UpdatePreviews(_this);
                return(false);
            }
            return(true);
        }
Esempio n. 28
0
        public static bool CreatePrebuildsPrePatch(PlayerAction_Build __instance)
        {
            var _this = __instance;

            if (begin)
            {
                CreatePrebuilds(_this);
                return(false);
            }
            return(true);
        }
Esempio n. 29
0
        public static bool CheckBuildConditionsPrePatch(PlayerAction_Build __instance)
        {
            var _this = __instance;

            if (begin)
            {
                _this.previewPose.position = Vector3.zero;
                _this.previewPose.rotation = Quaternion.identity;
            }
            return(true);
        }
Esempio n. 30
0
        public static void SizePatch(PlayerAction_Build __instance)
        {
            __instance.reformIndices = new int[900];
            __instance.reformPoints  = new Vector3[900];

            //if (BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.buildanywhere"))
            //         {
            //	FreeFoundationsFreeSoilPlugin.logger.LogWarning("You have installed \"BuildAnywhere\" Mod by Alejandro which unfortunately locks the Reform-Size to 10x10");
            //	//FreeFoundationsFreeSoilPlugin.BuildAnyWhereWarningShowed = true;

            //}
        }