Example #1
0
 public static void OnSetRecipe(ref LabComponent __instance)
 {
     if (__instance.recipeId > 0)
     {
         __instance.recipeIsLocked = GameMain.history.RecipeUnlocked(__instance.recipeId);
     }
 }
Example #2
0
        public static bool CheckAssemblerRecipe(ref LabComponent __instance)
        {
            if (!__instance.recipeIsLocked)
            {
                __instance.recipeIsLocked = GameMain.history.RecipeUnlocked(__instance.recipeId);
            }

            return(__instance.recipeIsLocked);
        }
Example #3
0
        public static void OnUIUpdate(UILabWindow __instance)
        {
            if (__instance.labId == 0 || __instance.factory == null)
            {
                return;
            }
            LabComponent labComponent = __instance.factorySystem.labPool[__instance.labId];

            if (!labComponent.recipeIsLocked)
            {
                __instance.stateText.text  = "recipeLockedWarn".Translate();
                __instance.stateText.color = __instance.workStoppedColor;
            }
        }
Example #4
0
        public static void OnItemButtonClick_Prefix(UILabWindow __instance)
        {
            LabComponent labComponent = GameMain.localPlanet.factory.factorySystem.labPool[__instance.labId];

            if (labComponent.matrixMode)
            {
                //Notify about withdrawing produced cubes
                LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateEventPacket(-3, __instance.labId, GameMain.localPlanet?.factoryIndex ?? -1));
            }
            else if (!labComponent.researchMode)
            {
                //Notify about selection of research mode
                LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateEventPacket(-1, __instance.labId, GameMain.localPlanet?.factoryIndex ?? -1));
            }
        }
Example #5
0
        public static void OnItemButtonClick_Prefix(UILabWindow __instance, int index, ref bool __state)
        {
            if (!Multiplayer.IsActive)
            {
                return;
            }

            __state = false;
            LabComponent labComponent = GameMain.localPlanet.factory.factorySystem.labPool[__instance.labId];

            if (!labComponent.researchMode && !labComponent.matrixMode)
            {
                //Notify about changing matrix selection
                Multiplayer.Session.Network.SendPacketToLocalStar(new LaboratoryUpdateEventPacket(index, __instance.labId, GameMain.localPlanet?.id ?? -1));
                __state = true;
            }
        }
Example #6
0
        public static void OnItemButtonClick_Postfix(UILabWindow __instance, int index, bool __state)
        {
            // Skip if lab was in neither researchMode nor matrixMode
            if (!Multiplayer.IsActive || __state)
            {
                return;
            }

            LabComponent labComponent = GameMain.localPlanet.factory.factorySystem.labPool[__instance.labId];

            if (labComponent.researchMode)
            {
                Multiplayer.Session.Network.SendPacketToLocalStar(new LaboratoryUpdateCubesPacket(labComponent.matrixServed[index], labComponent.matrixIncServed[index], index, __instance.labId, GameMain.localPlanet?.id ?? -1));
            }
            else if (labComponent.matrixMode)
            {
                Multiplayer.Session.Network.SendPacketToLocalStar(new LaboratoryUpdateStoragePacket(labComponent.served[index], labComponent.incServed[index], index, __instance.labId, GameMain.localPlanet?.id ?? -1));
            }
        }
Example #7
0
        public static void OnItemButtonClick_Prefix(UILabWindow __instance, int index)
        {
            if (!SimulatedWorld.Initialized)
            {
                return;
            }

            LabComponent labComponent = GameMain.localPlanet.factory.factorySystem.labPool[__instance.labId];

            if (labComponent.researchMode)
            {
                if (GameMain.mainPlayer.inhandItemId > 0 && GameMain.mainPlayer.inhandItemCount > 0)
                {
                    //Notify about depositing source cubes
                    ItemProto[] matrixProtos = (ItemProto[])AccessTools.Field(typeof(UILabWindow), "matrixProtos").GetValue(__instance);
                    int         id           = matrixProtos[index].ID;
                    if (GameMain.mainPlayer.inhandItemId == id)
                    {
                        int num  = labComponent.matrixServed[index] / 3600;
                        int num2 = 100 - num;
                        if (num2 < 0)
                        {
                            num2 = 0;
                        }
                        int num3 = (GameMain.mainPlayer.inhandItemCount >= num2) ? num2 : GameMain.mainPlayer.inhandItemCount;
                        if (num3 > 0)
                        {
                            LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateCubesPacket(labComponent.matrixServed[index] + num3 * 3600, index, __instance.labId, GameMain.localPlanet?.id ?? -1));
                        }
                    }
                }
                else
                {
                    //Notify about widthrawing source cubes
                    if ((int)(labComponent.matrixServed[index] / 3600) > 0)
                    {
                        LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateCubesPacket(0, index, __instance.labId, GameMain.localPlanet?.id ?? -1));
                    }
                }
            }
            else if (labComponent.matrixMode)
            {
                if (GameMain.mainPlayer.inhandItemId > 0 && GameMain.mainPlayer.inhandItemCount > 0)
                {
                    //Notify about depositing source items to the center
                    int num7 = labComponent.served[index];
                    int num8 = 100 - num7;
                    if (num8 < 0)
                    {
                        num8 = 0;
                    }
                    int num9 = (GameMain.mainPlayer.inhandItemCount >= num8) ? num8 : GameMain.mainPlayer.inhandItemCount;
                    if (num9 > 0)
                    {
                        LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateStoragePacket(labComponent.served[index] + num9, index, __instance.labId, GameMain.localPlanet?.id ?? -1));
                    }
                }
                else
                {
                    //Notify about withdrawing source items from the center
                    if (labComponent.served[index] > 0)
                    {
                        LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateStoragePacket(0, index, __instance.labId, GameMain.localPlanet?.id ?? -1));
                    }
                }
            }
            else
            {
                //Notify about changing matrix selection
                LocalPlayer.SendPacketToLocalStar(new LaboratoryUpdateEventPacket(index, __instance.labId, GameMain.localPlanet?.id ?? -1));
            }
        }
Example #8
0
        public static BuildingCopy CopyBuilding(EntityData sourceEntity, EntityData referenceEntity)
        {
            PlanetFactory factory = GameMain.data.localPlanet.factory;

            ItemProto sourceEntityProto = LDB.items.Select(sourceEntity.protoId);

            Vector3    sourcePos = sourceEntity.pos;
            Quaternion sourceRot = sourceEntity.rot;

            Quaternion zeroRot = Maths.SphericalRotation(sourcePos, 0f);
            float      yaw     = Vector3.SignedAngle(zeroRot.Forward(), sourceRot.Forward(), zeroRot.Up());


            BuildingCopy copiedBuilding = new BuildingCopy()
            {
                originalId = sourceEntity.id,
                protoId    = sourceEntityProto.ID,
                itemProto  = sourceEntityProto,
                modelIndex = sourceEntity.modelIndex
            };


            if (sourceEntity.assemblerId > 0)
            {
                copiedBuilding.recipeId = factory.factorySystem.assemblerPool[sourceEntity.assemblerId].recipeId;
            }
            else if (sourceEntity.labId > 0)
            {
                LabComponent labComponent = factory.factorySystem.labPool[sourceEntity.labId];
                copiedBuilding.recipeId = ((!labComponent.researchMode) ? labComponent.recipeId : -1);
            }
            else if (sourceEntity.powerGenId > 0)
            {
                PowerGeneratorComponent powerGeneratorComponent = factory.powerSystem.genPool[sourceEntity.powerGenId];
                if (powerGeneratorComponent.gamma)
                {
                    copiedBuilding.recipeId = ((powerGeneratorComponent.productId <= 0) ? 0 : 1);
                }
            }
            else if (sourceEntity.powerExcId > 0)
            {
                copiedBuilding.recipeId = Mathf.RoundToInt(factory.powerSystem.excPool[sourceEntity.powerExcId].targetState);
            }
            else if (sourceEntity.ejectorId > 0)
            {
                copiedBuilding.recipeId = factory.factorySystem.ejectorPool[sourceEntity.ejectorId].orbitId;
            }
            else if (sourceEntity.stationId > 0)
            {
                StationComponent stationComponent = factory.transport.stationPool[sourceEntity.stationId];

                for (int i = 0; i < stationComponent.slots.Length; i++)
                {
                    if (stationComponent.slots[i].storageIdx != 0)
                    {
                        copiedBuilding.slotFilters.Add(new SlotFilter()
                        {
                            slotIndex  = i,
                            storageIdx = stationComponent.slots[i].storageIdx
                        });
                    }
                }

                for (int i = 0; i < stationComponent.storage.Length; i++)
                {
                    if (stationComponent.storage[i].itemId != 0)
                    {
                        copiedBuilding.stationSettings.Add(new StationSetting()
                        {
                            index       = i,
                            itemId      = stationComponent.storage[i].itemId,
                            max         = stationComponent.storage[i].max,
                            localLogic  = stationComponent.storage[i].localLogic,
                            remoteLogic = stationComponent.storage[i].remoteLogic
                        });
                    }
                }
            }
            else if (sourceEntity.splitterId > 0)
            {
                // TODO: find a way to restore splitter settings
                // SplitterComponent splitterComponent = factory.cargoTraffic.splitterPool[sourceEntity.splitterId];
            }

            Vector2 sourceSprPos = sourcePos.ToSpherical();

            if (sourceEntity.id == referenceEntity.id)
            {
                data.referencePos = sourceSprPos;
                copiedBuilding.cursorRelativeYaw = yaw;
            }
            else
            {
                copiedBuilding.originalSegmentCount = sourceSprPos.GetSegmentsCount();
                copiedBuilding.cursorRelativePos    = (sourceSprPos - data.referencePos).Clamp();
                copiedBuilding.cursorRelativeYaw    = yaw;
            }

            data.copiedBuildings.Add(copiedBuilding);

            for (int i = 0; i < sourceEntityProto.prefabDesc.insertPoses.Length; i++)
            {
                factory.ReadObjectConn(sourceEntity.id, i, out bool _, out int otherObjId, out int _);

                if (otherObjId > 0)
                {
                    EntityData inserterEntity = factory.entityPool[otherObjId];
                    CopyInserter(inserterEntity, sourceEntity);
                }
            }

            hasData = true;
            return(copiedBuilding);
        }
Example #9
0
        public static BuildingCopy CopyBuilding(BlueprintData data, EntityData sourceEntity, EntityData referenceEntity)
        {
            PlanetFactory factory = GameMain.data.localPlanet.factory;

            ItemProto sourceEntityProto = LDB.items.Select(sourceEntity.protoId);

            Vector3    sourcePos = sourceEntity.pos;
            Quaternion sourceRot = sourceEntity.rot;

            Quaternion zeroRot = Maths.SphericalRotation(sourcePos, 0f);
            float      yaw     = Vector3.SignedAngle(zeroRot.Forward(), sourceRot.Forward(), zeroRot.Up());


            BuildingCopy copiedBuilding = new BuildingCopy()
            {
                originalId = sourceEntity.id,
                protoId    = sourceEntityProto.ID,
                itemProto  = sourceEntityProto,
                modelIndex = sourceEntity.modelIndex,
            };

            var prefabDesc = BlueprintManager.GetPrefabDesc(copiedBuilding);

            if (sourceEntity.assemblerId > 0)
            {
                copiedBuilding.recipeId = factory.factorySystem.assemblerPool[sourceEntity.assemblerId].recipeId;
            }
            else if (sourceEntity.labId > 0)
            {
                LabComponent labComponent = factory.factorySystem.labPool[sourceEntity.labId];
                copiedBuilding.recipeId = ((!labComponent.researchMode) ? labComponent.recipeId : -1);
            }
            else if (sourceEntity.powerGenId > 0)
            {
                PowerGeneratorComponent powerGeneratorComponent = factory.powerSystem.genPool[sourceEntity.powerGenId];
                if (powerGeneratorComponent.gamma)
                {
                    copiedBuilding.recipeId = ((powerGeneratorComponent.productId <= 0) ? 0 : 1);
                }
            }
            else if (sourceEntity.powerExcId > 0)
            {
                copiedBuilding.recipeId = Mathf.RoundToInt(factory.powerSystem.excPool[sourceEntity.powerExcId].targetState);
            }
            else if (sourceEntity.ejectorId > 0)
            {
                copiedBuilding.recipeId = factory.factorySystem.ejectorPool[sourceEntity.ejectorId].orbitId;
            }
            else if (sourceEntity.stationId > 0)
            {
                StationComponent stationComponent = factory.transport.stationPool[sourceEntity.stationId];

                copiedBuilding.stationConfig = new StationConfig()
                {
                    workEnergyPerTick     = factory.powerSystem.consumerPool[stationComponent.pcId].workEnergyPerTick,
                    tripRangeDrones       = stationComponent.tripRangeDrones,
                    tripRangeShips        = stationComponent.tripRangeShips,
                    warpEnableDist        = stationComponent.warpEnableDist,
                    warperNecessary       = stationComponent.warperNecessary,
                    includeOrbitCollector = stationComponent.includeOrbitCollector,
                    deliveryDrones        = stationComponent.deliveryDrones,
                    deliveryShips         = stationComponent.deliveryShips
                };

                for (int i = 0; i < stationComponent.slots.Length; i++)
                {
                    if (stationComponent.slots[i].storageIdx != 0)
                    {
                        copiedBuilding.slotFilters.Add(new SlotFilter()
                        {
                            slotIndex  = i,
                            storageIdx = stationComponent.slots[i].storageIdx
                        });
                    }
                }

                for (int i = 0; i < stationComponent.storage.Length; i++)
                {
                    if (stationComponent.storage[i].itemId != 0)
                    {
                        copiedBuilding.stationSettings.Add(new StationSetting()
                        {
                            index       = i,
                            itemId      = stationComponent.storage[i].itemId,
                            max         = stationComponent.storage[i].max,
                            localLogic  = stationComponent.storage[i].localLogic,
                            remoteLogic = stationComponent.storage[i].remoteLogic
                        });
                    }
                }
            }
            else if (sourceEntity.splitterId > 0)
            {
                var splitterComponent = factory.cargoTraffic.splitterPool[sourceEntity.splitterId];
                copiedBuilding.splitterSettings = new SplitterSettings()
                {
                    inPriority  = splitterComponent.inPriority,
                    outPriority = splitterComponent.outPriority,
                    outFilter   = splitterComponent.outFilter
                };

                var slots = new List <int>(4)
                {
                    splitterComponent.beltA, splitterComponent.beltB, splitterComponent.beltC, splitterComponent.beltD
                };
                if (copiedBuilding.splitterSettings.inPriority)
                {
                    copiedBuilding.splitterSettings.inPrioritySlot = slots.IndexOf(splitterComponent.input0);
                }
                if (copiedBuilding.splitterSettings.outPriority)
                {
                    copiedBuilding.splitterSettings.outPrioritySlot = slots.IndexOf(splitterComponent.output0);
                }
                // TODO: find a way to restore splitter settings
                // SplitterComponent splitterComponent = factory.cargoTraffic.splitterPool[sourceEntity.splitterId];
            }
            else if (sourceEntity.storageId > 0)
            {
                copiedBuilding.recipeId = factory.factoryStorage.storagePool[sourceEntity.storageId].bans;
            }

            Vector2 sourceSprPos = sourcePos.ToSpherical();

            if (sourceEntity.id == referenceEntity.id)
            {
                data.referencePos = sourceSprPos;
                copiedBuilding.cursorRelativeYaw = yaw;
            }
            else
            {
                copiedBuilding.originalSegmentCount = sourceSprPos.GetSegmentsCount();
                copiedBuilding.cursorRelativePos    = (sourceSprPos - data.referencePos).Clamp();
                copiedBuilding.cursorRelativeYaw    = yaw;
            }

            data.copiedBuildings.Add(copiedBuilding);

            for (int i = 0; i < sourceEntityProto.prefabDesc.insertPoses.Length; i++)
            {
                factory.ReadObjectConn(sourceEntity.id, i, out bool _, out int otherObjId, out int _);

                if (otherObjId > 0)
                {
                    EntityData inserterEntity = factory.entityPool[otherObjId];
                    CopyInserter(data, inserterEntity, sourceEntity);
                }
            }

            if (sourceEntityProto.prefabDesc.multiLevel)
            {
                copiedBuilding.altitude = Mathf.RoundToInt((sourceEntity.pos.magnitude - GameMain.localPlanet.realRadius - 0.2f) / prefabDesc.lapJoint.magnitude);

                if (copiedBuilding.altitude > 0)
                {
                    copiedBuilding.connectedBuildingId = referenceEntity.id;
                }

                factory.ReadObjectConn(sourceEntity.id, 15, out bool _, out int otherObjId, out int _);

                if (otherObjId > 0)
                {
                    EntityData stackedEntity = factory.entityPool[otherObjId];
                    CopyBuilding(data, stackedEntity, sourceEntity);
                }
            }


            return(copiedBuilding);
        }