Exemple #1
0
    public override void SetData(PlanetFactory factory, int eId)
    {
        int sId = factory.entityPool[eId].fractionateId;

        //读取接口数据
        factory.ReadObjectConn(eId, 0, out bool out0, out int belt0, out int slot0);
        factory.ReadObjectConn(eId, 1, out bool out1, out int belt1, out int slot1);
        factory.ReadObjectConn(eId, 2, out bool out2, out int belt2, out int slot2);
        //对数据进行连接
        if (belt0 > 0)
        {
            int beltId = factory.entityPool[belt0].beltId;
            factory.factorySystem.SetFractionateBelt(sId, beltId, 0, out0);
        }
        if (belt1 > 0)
        {
            int beltId = factory.entityPool[belt1].beltId;
            factory.factorySystem.SetFractionateBelt(sId, beltId, 1, out1);
        }
        if (belt2 > 0)
        {
            int beltId = factory.entityPool[belt2].beltId;
            factory.factorySystem.SetFractionateBelt(sId, beltId, 2, out2);
        }
    }
    public override void SetData(PlanetFactory factory, int eId)
    {
        int sId = factory.entityPool[eId].splitterId;

        //读取接口数据
        factory.ReadObjectConn(eId, 0, out bool out0, out int belt0, out int slot0);
        factory.ReadObjectConn(eId, 1, out bool out1, out int belt1, out int slot1);
        factory.ReadObjectConn(eId, 2, out bool out2, out int belt2, out int slot2);
        factory.ReadObjectConn(eId, 3, out bool out3, out int belt3, out int slot3);
        //对数据进行连接
        if (belt0 > 0)
        {
            int beltId = factory.entityPool[belt0].beltId;
            factory.cargoTraffic.ConnectToSplitter(sId, beltId, 0, !out0);
        }
        if (belt1 > 0)
        {
            int beltId = factory.entityPool[belt1].beltId;
            factory.cargoTraffic.ConnectToSplitter(sId, beltId, 1, !out1);
        }
        if (belt2 > 0)
        {
            int beltId = factory.entityPool[belt2].beltId;
            factory.cargoTraffic.ConnectToSplitter(sId, beltId, 2, !out2);
        }
        if (belt3 > 0)
        {
            int beltId = factory.entityPool[belt3].beltId;
            factory.cargoTraffic.ConnectToSplitter(sId, beltId, 3, !out3);
        }
    }
    public override void SetData(PlanetFactory factory, int eId)
    {
        factory.powerSystem.excPool[factory.entityPool[eId].powerExcId].targetState = state;
        //读取接口数据
        factory.ReadObjectConn(eId, 0, out bool out0, out int belt0, out int slot0);
        factory.ReadObjectConn(eId, 1, out bool out1, out int belt1, out int slot1);
        factory.ReadObjectConn(eId, 2, out bool out2, out int belt2, out int slot2);
        factory.ReadObjectConn(eId, 3, out bool out3, out int belt3, out int slot3);
        int exid = factory.entityPool[eId].powerExcId;

        if (belt0 > 0)
        {
            int beltId = factory.entityPool[belt0].beltId;
            factory.powerSystem.SetExchangerBelt(exid, beltId, 0, out0);
        }
        if (belt1 > 0)
        {
            int beltId = factory.entityPool[belt1].beltId;
            factory.powerSystem.SetExchangerBelt(exid, beltId, 1, out1);
        }
        if (belt2 > 0)
        {
            int beltId = factory.entityPool[belt2].beltId;
            factory.powerSystem.SetExchangerBelt(exid, beltId, 2, out2);
        }
        if (belt3 > 0)
        {
            int beltId = factory.entityPool[belt3].beltId;
            factory.powerSystem.SetExchangerBelt(exid, beltId, 3, out3);
        }
    }
Exemple #4
0
        public static void PlanetFactory_CreateEntityLogicComponents_Postfix(PlanetFactory __instance, int entityId, PrefabDesc desc)
        {
            // this ensure that buildings built AFTER a connected belt are correctly configured
            // the game by default already does something like this but only for belts to belts / splitter / logistic stations
            // See PlanetFactory.CreateEntityLogicComponents
            var entity = __instance.entityPool[entityId];

            for (var i = 0; i < 4; i++)
            {
                __instance.ReadObjectConn(entityId, i, out bool isOutput, out int otherId, out _);

                // ignore unbuilt or connections that are not belts
                if (otherId <= 0 || __instance.entityPool[otherId].beltId <= 0)
                {
                    continue;
                }

                var beltId = __instance.entityPool[otherId].beltId;

                if (desc.isTank)
                {
                    __instance.factoryStorage.SetTankBelt(entity.tankId, beltId, i, isOutput);
                }
                if (desc.isFractionate)
                {
                    __instance.factorySystem.SetFractionateBelt(entity.fractionateId, beltId, i, isOutput);
                }
                if (desc.isPowerExchanger)
                {
                    __instance.powerSystem.SetExchangerBelt(entity.powerExcId, beltId, i, isOutput);
                }
            }
        }
    public IEnumerator CheckBelt(float time)
    {
        yield return(new WaitForSeconds(time));

        List <int> temp = new List <int>();

        foreach (var d in CheckBeltData)
        {
            int  eid     = d.Key;
            var  id      = factory.entityPool[eid].beltId;
            var  data    = factory.cargoTraffic.beltPool[id];
            var  outBelt = factory.cargoTraffic.beltPool[data.outputId];
            bool flag2;
            int  slot;
            factory.ReadObjectConn(eid, 0, out flag2, out int out1, out slot);
            factory.ReadObjectConn(eid, 1, out flag2, out int in1, out slot);
            factory.ReadObjectConn(eid, 2, out flag2, out int in2, out slot);
            factory.ReadObjectConn(eid, 3, out flag2, out int in3, out slot);
            out1 = EIdIsBeltId(out1);
            in1  = EIdIsBeltId(in1);
            in2  = EIdIsBeltId(in2);
            in3  = EIdIsBeltId(in3);
            if (out1 > 0)
            {
                temp.Add(d.Key);
                d.Value.beltOut = out1;
                d.Value.beltIn1 = in1;
                d.Value.beltIn2 = in2;
                d.Value.beltIn3 = in3;
            }
            else if (outBelt.entityId > 0)
            {
                temp.Add(d.Key);
                d.Value.beltOut = out1;
            }
        }
        foreach (int i in temp)
        {
            CheckBeltData.Remove(i);
        }
    }
Exemple #6
0
        public static Pose[] GetLocalSlots(PlanetFactory factory, int objId)
        {
            if (objId == 0)
            {
                return(emptyPoseArr);
            }
            PrefabDesc prefabDesc;

            if (objId > 0)
            {
                ModelProto modelProto = LDB.models.Select(factory.entityPool[objId].modelIndex);
                if (modelProto == null)
                {
                    return(emptyPoseArr);
                }
                prefabDesc = modelProto.prefabDesc;
            }
            else
            {
                ModelProto modelProto2 = LDB.models.Select(factory.prebuildPool[-objId].modelIndex);
                if (modelProto2 == null)
                {
                    return(emptyPoseArr);
                }
                prefabDesc = modelProto2.prefabDesc;
            }
            if (!prefabDesc.multiLevel || prefabDesc.multiLevelAllowPortsOrSlots)
            {
                return(prefabDesc.slotPoses);
            }
            factory.ReadObjectConn(objId, 14, out var _, out var otherObjId, out var _);
            if (otherObjId != 0)
            {
                return(emptyPoseArr);
            }
            return(prefabDesc.slotPoses);
        }
Exemple #7
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);
        }
Exemple #8
0
        public static BeltCopy CopyBelt(EntityData sourceEntity, EntityData referenceEntity)
        {
            PlanetFactory factory = GameMain.data.localPlanet.factory;

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

            if (!sourceEntityProto.prefabDesc.isBelt)
            {
                return(null);
            }

            BeltComponent belt         = factory.cargoTraffic.beltPool[sourceEntity.beltId];
            Vector2       sourceSprPos = sourceEntity.pos.ToSpherical();

            BeltCopy copiedBelt = new BeltCopy()
            {
                originalId   = sourceEntity.id,
                protoId      = sourceEntityProto.ID,
                itemProto    = sourceEntityProto,
                altitude     = Mathf.RoundToInt(2 * (sourceEntity.pos.magnitude - GameMain.localPlanet.realRadius - 0.2f) / 1.3333333f),
                backInputId  = factory.cargoTraffic.beltPool[belt.backInputId].entityId,
                leftInputId  = factory.cargoTraffic.beltPool[belt.leftInputId].entityId,
                rightInputId = factory.cargoTraffic.beltPool[belt.rightInputId].entityId,
                outputId     = factory.cargoTraffic.beltPool[belt.outputId].entityId,
            };

            factory.ReadObjectConn(sourceEntity.id, 0, out bool isOutput, out int otherId, out int otherSlot);
            if (otherId > 0 && factory.entityPool[otherId].beltId == 0)
            {
                copiedBelt.connectedBuildingId       = otherId;
                copiedBelt.connectedBuildingIsOutput = isOutput;
                copiedBelt.connectedBuildingSlot     = otherSlot;
            }

            factory.ReadObjectConn(sourceEntity.id, 1, out isOutput, out otherId, out otherSlot);
            if (otherId > 0 && factory.entityPool[otherId].beltId == 0)
            {
                copiedBelt.connectedBuildingId       = otherId;
                copiedBelt.connectedBuildingIsOutput = isOutput;
                copiedBelt.connectedBuildingSlot     = otherSlot;
            }

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

            data.copiedBelts.Add(copiedBelt);

            factory.ReadObjectConn(sourceEntity.id, 4, out _, out otherId, out _);

            if (otherId != 0)
            {
                // only copy belt to belt inserter if both belts are part fo the blueprint
                factory.ReadObjectConn(otherId, 0, out _, out int endId, out _);
                factory.ReadObjectConn(otherId, 1, out _, out int startId, out _);

                int idToFind = sourceEntity.id == endId ? startId : endId;

                if (data.copiedBelts.FindIndex(x => x.originalId == idToFind) != -1)
                {
                    EntityData inserterEntity = factory.entityPool[otherId];
                    CopyInserter(inserterEntity, sourceEntity);
                }
            }

            hasData = true;
            return(copiedBelt);
        }
Exemple #9
0
            public static bool DetermineDestructPreviewsPatch(PlayerAction_Build __instance,
                                                              ref NearColliderLogic ___nearcdLogic,
                                                              ref PlanetFactory ___factory)
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl))
                {
                    if (!VFInput.onGUI)
                    {
                        UICursor.SetCursor(ECursor.Delete);
                    }
                }
                else
                {
                    return(true);
                }

                if (!Utils.CheckIfInBuildDistance(__instance.cursorTarget))
                {
                    // Out of reach
                    UnityEngine.Debug.Log("out of reach");
                    return(true);
                }

                List <EntityData> deleteEntitiesList = new List <EntityData>();
                ItemProto         itemProto          = Traverse.Create(__instance).Method(
                    "GetItemProto", __instance.castObjId).GetValue <ItemProto>();

                __instance.ClearBuildPreviews();

                if (VFInput.reformMinusKey.onDown)
                {
                    if (__instance.reformSize >= 0)
                    {
                        __instance.reformSize--;
                    }
                }

                if (VFInput.reformPlusKey.onDown)
                {
                    if (__instance.reformSize < _configDisassemblingRadiusMax.Value)
                    {
                        __instance.reformSize++;
                    }
                }

                // Management of the sphere delete
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    int[] buildingIdsToDelete = new int[_maxArrayOfBuildingSize.Value];
                    if (itemProto != null)
                    {
                        ___nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.castObjPos, __instance.reformSize, buildingIdsToDelete);
                    }
                    else
                    {
                        ___nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.cursorTarget, __instance.reformSize, buildingIdsToDelete);
                    }

                    List <int> listBuildingIdsToDelete = new List <int>();

                    foreach (var id in buildingIdsToDelete)
                    {
                        if (id != 0)
                        {
                            listBuildingIdsToDelete.Add(id);
                        }
                    }

                    foreach (var item in listBuildingIdsToDelete)
                    {
                        deleteEntitiesList.Add(___factory.entityPool[item]);
                    }

                    // Management of both
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        if (itemProto != null)
                        {
                            deleteEntitiesList = Utils.GetEntitySortedByTypeAndRadius(itemProto, deleteEntitiesList,
                                                                                      __instance.castObjPos, __instance.reformSize);
                        }
                    }
                }

                // Management of the Mass Item delete
                if (Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.LeftControl))
                {
                    __instance.previewPose.position = Vector3.zero;
                    __instance.previewPose.rotation = Quaternion.identity;
                    if ((uint)__instance.castObjId > 0U)
                    {
                        if (itemProto != null)
                        {
                            if ((uint)___factory.entityPool[__instance.castObjId].beltId > 0U)
                            {
                                CargoPath pathByBeltId = Utils.GetPathWithBeltId(___factory,
                                                                                 ___factory.entityPool[__instance.castObjId].beltId);
                                deleteEntitiesList = Utils.GetBeltsEntitiesByCargoPathBuildRange(___factory, pathByBeltId);
                            }
                            else
                            {
                                // deleteEntitiesList = Utils.GetEntitiesByProtoBuildRange(___factory, itemProto);
                                return(true);
                            }
                        }
                    }
                }


                foreach (var entityData in deleteEntitiesList)
                {
                    __instance.AddBuildPreview(new BuildPreview());
                }

                // Common Code
                for (int index = 0; index < __instance.buildPreviews.Count; ++index)
                {
                    BuildPreview buildPreview = __instance.buildPreviews[index];
                    ItemProto    itemProto2   = Traverse.Create(__instance).Method(
                        "GetItemProto", deleteEntitiesList[index].id).GetValue <ItemProto>();
                    buildPreview.item  = itemProto2;
                    buildPreview.desc  = itemProto2.prefabDesc;
                    buildPreview.lpos  = deleteEntitiesList[index].pos;
                    buildPreview.lrot  = deleteEntitiesList[index].rot;
                    buildPreview.objId = deleteEntitiesList[index].id;
                    int num = buildPreview.desc.lodCount <= 0
                        ? 0
                        : ((Object)buildPreview.desc.lodMeshes[0] != (Object)null ? 1 : 0);
                    buildPreview.needModel  = num != 0;
                    buildPreview.isConnNode = true;
                    if (buildPreview.desc.isInserter)
                    {
                        Pose pose = Traverse.Create(__instance).Method("GetObjectPose2", buildPreview.objId)
                                    .GetValue <Pose>();
                        buildPreview.lpos2 = pose.position;
                        buildPreview.lrot2 = pose.rotation;
                    }

                    if ((buildPreview.lpos - __instance.player.position).sqrMagnitude >
                        __instance.player.mecha.buildArea *
                        __instance.player.mecha.buildArea)
                    {
                        buildPreview.condition   = EBuildCondition.OutOfReach;
                        __instance.cursorText    = "目标超出范围".Translate();
                        __instance.cursorWarning = true;
                    }
                    else
                    {
                        buildPreview.condition = EBuildCondition.Ok;
                        __instance.cursorText  = "拆除".Translate() + buildPreview.item.name;
                    }

                    if (buildPreview.desc.multiLevel)
                    {
                        ___factory.ReadObjectConn(buildPreview.objId, 15, out bool _, out int otherObjId,
                                                  out int _);
                        if ((uint)otherObjId > 0U)
                        {
                            buildPreview.condition = EBuildCondition.Covered;
                            __instance.cursorText  = buildPreview.conditionText;
                        }
                    }
                }


                return(false);
            }
        public static bool DetermineDestructPreviewsPatch(PlayerAction_Build __instance)
        {
            if (!Input.GetKey(KeyCode.LeftShift))
            {
                return(true);
            }
            var           _this   = __instance;
            PlanetFactory factory = Traverse.Create(_this).Field("factory").GetValue <PlanetFactory>();

            if (!VFInput.onGUI)
            {
                UICursor.SetCursor(ECursor.Delete);
            }
            _this.previewPose.position = Vector3.zero;
            _this.previewPose.rotation = Quaternion.identity;
            if (_this.castObjId > 0)
            {
                ItemProto itemProto = Traverse.Create(_this).Method("GetItemProto", _this.castObjId).GetValue <ItemProto>();
                if (itemProto != null)
                {
                    _this.ClearBuildPreviews();
                    List <EntityData> entityList;
                    if (factory.entityPool[_this.castObjId].beltId != 0)
                    {
                        var path = GetPathByBeltId(factory, factory.entityPool[_this.castObjId].beltId);
                        entityList = GetEntitysByPath(factory, path);
                    }
                    else
                    {
                        entityList = GetEntitysByProto(factory, itemProto, _this.castObjPos);
                    }
                    for (int i = 0; i < entityList.Count; i++)
                    {
                        _this.AddBuildPreview(new BuildPreview());
                    }
                    for (int i = 0; i < _this.buildPreviews.Count; i++)
                    {
                        BuildPreview buildPreview = _this.buildPreviews[i];
                        ItemProto    proto        = Traverse.Create(_this).Method("GetItemProto", entityList[i].id).GetValue <ItemProto>();
                        buildPreview.item  = proto;
                        buildPreview.desc  = proto.prefabDesc;
                        buildPreview.lpos  = entityList[i].pos;
                        buildPreview.lrot  = entityList[i].rot;
                        buildPreview.objId = entityList[i].id;
                        if (buildPreview.desc.lodCount > 0 && buildPreview.desc.lodMeshes[0] != null)
                        {
                            buildPreview.needModel = true;
                        }
                        else
                        {
                            buildPreview.needModel = false;
                        }
                        buildPreview.isConnNode = true;
                        bool isInserter = buildPreview.desc.isInserter;
                        if (isInserter)
                        {
                            Pose objectPose2 = Traverse.Create(_this).Method("GetObjectPose2", buildPreview.objId).GetValue <Pose>();
                            buildPreview.lpos2 = objectPose2.position;
                            buildPreview.lrot2 = objectPose2.rotation;
                        }
                        if ((buildPreview.lpos - _this.castObjPos).sqrMagnitude > DestructArea.Value * DestructArea.Value)
                        {
                            buildPreview.condition = EBuildCondition.OutOfReach;
                            _this.cursorText       = "目标超出范围".Translate();
                            _this.cursorWarning    = true;
                        }
                        else
                        {
                            buildPreview.condition = EBuildCondition.Ok;
                            _this.cursorText       = "拆除".Translate() + buildPreview.item.name;
                        }
                        if (buildPreview.desc.multiLevel)
                        {
                            bool flag;
                            int  num;
                            int  num2;
                            factory.ReadObjectConn(buildPreview.objId, 15, out flag, out num, out num2);
                            if (num != 0)
                            {
                                buildPreview.condition = EBuildCondition.Covered;
                                _this.cursorText       = buildPreview.conditionText;
                            }
                        }
                    }
                }
                else
                {
                    _this.ClearBuildPreviews();
                }
            }
            else
            {
                _this.ClearBuildPreviews();
            }
            return(false);
        }
Exemple #11
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);
        }
Exemple #12
0
        /// <summary>
        /// 根据传送带List控制红x的显示,大部分都是游戏内原本的代码
        /// </summary>
        public static void CustomDestructPreviews(PlayerAction_Build __instance, List <EntityData> beltList)
        {
            var           _this   = __instance;
            PlanetFactory factory = Traverse.Create(_this).Field("factory").GetValue <PlanetFactory>();

            for (int i = 0; i < beltList.Count; i++)
            {
                _this.AddBuildPreview(new BuildPreview());
            }

            for (int i = 0; i < _this.buildPreviews.Count; i++)
            {
                BuildPreview buildPreview = _this.buildPreviews[i];
                ItemProto    proto        = Traverse.Create(_this).Method("GetItemProto", beltList[i].id).GetValue <ItemProto>();
                buildPreview.item  = proto;
                buildPreview.desc  = proto.prefabDesc;
                buildPreview.lpos  = beltList[i].pos;
                buildPreview.lrot  = beltList[i].rot;
                buildPreview.objId = beltList[i].id;


                if (buildPreview.desc.lodCount > 0 && buildPreview.desc.lodMeshes[0] != null)
                {
                    buildPreview.needModel = true;
                }
                else
                {
                    buildPreview.needModel = false;
                }
                buildPreview.isConnNode = true;
                bool isInserter = buildPreview.desc.isInserter;

                if (isInserter)
                {
                    Pose objectPose2 = Traverse.Create(_this).Method("GetObjectPose2", buildPreview.objId).GetValue <Pose>();
                    buildPreview.lpos2 = objectPose2.position;
                    buildPreview.lrot2 = objectPose2.rotation;
                }
                if ((buildPreview.lpos - _this.player.position).sqrMagnitude > _this.player.mecha.buildArea * _this.player.mecha.buildArea)
                {
                    buildPreview.condition = EBuildCondition.OutOfReach;
                    //_this.cursorText = "目标超出范围".Translate();
                    _this.cursorWarning = true;
                }
                else
                {
                    buildPreview.condition = EBuildCondition.Ok;
                    //_this.cursorText = "拆除".Translate() + buildPreview.item.name;
                }
                if (buildPreview.desc.multiLevel)
                {
                    bool flag;
                    int  num;
                    int  num2;
                    factory.ReadObjectConn(buildPreview.objId, 15, out flag, out num, out num2);
                    if (num != 0)
                    {
                        buildPreview.condition = EBuildCondition.Covered;
                        //_this.cursorText = buildPreview.conditionText;
                    }
                }
            }
        }
Exemple #13
0
            /// <summary>
            /// Orignal PlayerAction_Build::DetermineDestructPreviews
            /// </summary>
            public static void CreateEntityDestructPreview(
                PlayerAction_Build __instance,
                List <int> idList,
                List <EObjectType> typeList,
                DeterminePreviews.PreviewsFilter filter
                )
            {
                if (!VFInput.onGUI)
                {
                    UICursor.SetCursor(ECursor.Delete);
                }

                __instance.previewPose.position = Vector3.zero;
                __instance.previewPose.rotation = Quaternion.identity;

                __instance.ClearBuildPreviews();

                foreach (int entityId in idList)
                {
                    //int entityId = typeList[index] != EObjectType.Entity ? -entityIdList[index] : entityIdList[index];

                    ItemProto itemProto  = (ItemProto)Traverse.Create(__instance).Method("GetItemProto", entityId).GetValue();
                    Pose      objectPose = (Pose)Traverse.Create(__instance).Method("GetObjectPose", entityId).GetValue();

                    if (itemProto != null &&
                        filter(itemProto) == false)
                    {
                        //Add Build Preview
                        __instance.AddBuildPreview(new BuildPreview());

                        BuildPreview buildPreview = __instance.buildPreviews[__instance.buildPreviews.Count - 1];
                        buildPreview.item  = itemProto;
                        buildPreview.desc  = itemProto.prefabDesc;
                        buildPreview.lpos  = objectPose.position;
                        buildPreview.lrot  = objectPose.rotation;
                        buildPreview.objId = entityId;

                        int num = buildPreview.desc.lodCount <= 0 ? 0 : ((Object)buildPreview.desc.lodMeshes[0] != (Object)null ? 1 : 0);
                        buildPreview.needModel  = num != 0;
                        buildPreview.isConnNode = true;

                        if (buildPreview.desc.isInserter)
                        {
                            Pose objectPose2 = (Pose)Traverse.Create(__instance).Method("GetObjectPose2", buildPreview.objId).GetValue();
                            buildPreview.lpos2 = objectPose2.position;
                            buildPreview.lrot2 = objectPose2.rotation;
                        }

                        PlanetData planetData = __instance.player.planetData;
                        Vector3    vector3_1  = __instance.player.position;

                        if (planetData.type == EPlanetType.Gas)
                        {
                            vector3_1 = vector3_1.normalized;
                            Vector3 vector3_2 = vector3_1 * planetData.realRadius;
                        }
                        else
                        {
                            buildPreview.condition = EBuildCondition.Ok;
                            __instance.cursorText  = "拆除".Translate() + buildPreview.item.name + "\r\n" + "连锁拆除提示".Translate();
                        }

                        if (buildPreview.desc.multiLevel)
                        {
                            int           otherObjId;
                            PlanetFactory factory = Traverse.Create((object)__instance).Field("factory").GetValue <PlanetFactory>();
                            factory.ReadObjectConn(buildPreview.objId, 15, out bool _, out otherObjId, out int _);
                            if ((uint)otherObjId > 0U)
                            {
                                buildPreview.condition = EBuildCondition.Covered;
                                __instance.cursorText  = buildPreview.conditionText;
                            }
                        }
                    }
                }
            }
    public void CopyBuildData(PlanetFactory factory, int i)
    {
        var fSystem = factory.factorySystem;
        var ed      = factory.entityPool[i];


        if (ed.protoId > 0)
        {
            if (ed.labId > 0 && ed.storageId > 0 || ed.tankId > 0)
            {
                return;
            }
            MyPreBuildData temp = null;

            if (ed.splitterId > 0)
            {
                var ap = factory.cargoTraffic.splitterPool[ed.splitterId];
                int c0 = factory.entityConnPool[16 * ap.entityId];
                int c1 = factory.entityConnPool[16 * ap.entityId + 1];
                int c2 = factory.entityConnPool[16 * ap.entityId + 2];
                int c3 = factory.entityConnPool[16 * ap.entityId + 3];
                temp = new Splitter(GetPreDate(ed), c0, c1, c2, c3);
            }
            else if (ed.stationId > 0)
            {
                var ap = factory.transport.stationPool[ed.stationId];
                if (ap != null)
                {
                    temp = new Station(GetPreDate(ed), ap);
                }
            }
            else if (ed.inserterId > 0)
            {
                var ip = fSystem.inserterPool[ed.inserterId];
                InserterComponent tempp = ip;
                int outConn             = factory.entityConnPool[i * 16];
                int inConn = factory.entityConnPool[i * 16 + 1];
                temp = new Inserter(GetPreDate(tempp, ed), ip, outConn, inConn);
            }
            else if (ed.beltId > 0)
            {
                var  ap = factory.cargoTraffic.beltPool[ed.beltId];
                bool flag2;
                int  slot;
                factory.ReadObjectConn(i, 0, out flag2, out int out1, out slot);
                factory.ReadObjectConn(i, 1, out flag2, out int in1, out slot);
                factory.ReadObjectConn(i, 2, out flag2, out int in2, out slot);
                factory.ReadObjectConn(i, 3, out flag2, out int in3, out slot);
                temp = new Belt(GetPreDate(ap, ed), ap, out1, in1, in2, in3);
                Belt tBelt = (Belt)temp;
                if (out1 == 0)
                {
                    CheckBeltData.Add(i, tBelt);
                }

                tBelt.beltOut = EIdIsBeltId(out1);
                tBelt.beltIn1 = EIdIsBeltId(in1);
                tBelt.beltIn2 = EIdIsBeltId(in2);
                tBelt.beltIn3 = EIdIsBeltId(in3);
            }
            else if (ed.fractionateId > 0)
            {
                var ap = factory.factorySystem.fractionatePool[ed.fractionateId];
                int c0 = factory.entityConnPool[i * 16];
                int c1 = factory.entityConnPool[i * 16 + 1];
                int c2 = factory.entityConnPool[i * 16 + 2];
                temp = new Fractionate(GetPreDate(ed), c0, c1, c2);
            }
            else if (ed.powerExcId > 0)
            {
                var ap = factory.powerSystem.excPool[ed.powerExcId];
                int c0 = factory.entityConnPool[i * 16];
                int c1 = factory.entityConnPool[i * 16 + 1];
                int c2 = factory.entityConnPool[i * 16 + 2];
                int c3 = factory.entityConnPool[i * 16 + 3];
                temp = new PowerExchanger(GetPreDate(ed), c0, c1, c2, c3, ap.targetState);
            }
            else if (ed.assemblerId > 0)
            {
                var ap = fSystem.assemblerPool[ed.assemblerId];
                temp = new Assembler(GetPreDate(ap, ed));
            }
            else if (ed.ejectorId > 0)
            {
                var ap = fSystem.ejectorPool[ed.ejectorId];
                temp = new Assembler(GetPreDate(ed));
            }
            else if (ed.siloId > 0)
            {
                var ap = fSystem.siloPool[ed.siloId];
                temp = new Assembler(GetPreDate(ed));
            }
            else if (ed.powerGenId > 0)
            {
                var ap = factory.powerSystem.genPool[ed.powerGenId];
                if (ap.gamma)
                {
                    int c0 = factory.entityConnPool[16 * ap.entityId];
                    int c1 = factory.entityConnPool[16 * ap.entityId + 1];
                    temp = new Gamm(GetPreDate(ed), ap.productId, c0, c1);
                }
                else
                {
                    temp      = new Assembler(GetPreDate(ed));
                    temp.type = EDataType.PowGen;
                }
            }
            else if (ed.powerNodeId > 0)
            {
                var ap = factory.powerSystem.nodePool[ed.powerNodeId];
                temp = new Assembler(GetPreDate(ed));
            }
            //else if (ed.storageId > 0)
            //{
            //	var ap = factory.factoryStorage.storagePool[ed.storageId];
            //    if (ap.next == 0)
            //    {
            //		temp = new Assembler(GetPreDate(ed));
            //    }
            //}

            if (temp != null)
            {
                temp.oldEId = i;
                AllData.Add(temp);
                AddItemCount(ed.protoId);
            }
        }
    }