Ejemplo n.º 1
0
        public static void SetMinerInsertTarget(FactorySystem system, int slotId, int minerId, int insertTarget)
        {
            if (slotId == 0)
            {
                system.SetMinerInsertTarget(minerId, insertTarget);
                return;
            }

            if (minerId == 0 || system.minerPool[minerId].id != minerId)
            {
                return;
            }
            if (insertTarget > 0 && system.factory.entityPool[insertTarget].id == insertTarget)
            {
                if (slotId == 1)
                {
                    system.minerPool[minerId].insertTarget2 = insertTarget;
                }
                else
                {
                    system.minerPool[minerId].insertTarget3 = insertTarget;
                }
                return;
            }

            if (slotId == 1)
            {
                system.minerPool[minerId].insertTarget2 = 0;
            }
            else
            {
                system.minerPool[minerId].insertTarget3 = 0;
            }
        }
Ejemplo n.º 2
0
 public static void modInserter(FactorySystem __instance, ref int __result)
 {
     if (isModInserter)
     {
         __instance.inserterPool[__result].speed = (int)(10000 * p);
     }
 }
Ejemplo n.º 3
0
        private void ShowDebugInfo()
        {
            PlanetData planetData = GameMain.localPlanet;

            if (planetData != null)
            {
                PlanetFactory planetFactory = planetData.factory;

                Debug.LogFormat("enties:{0},prebuild:{1},vein:{2},vege:{3}", planetFactory.entityCursor, planetFactory.prebuildCursor, planetFactory.veinCursor, planetFactory.vegeCursor);

                if (planetFactory != null)
                {
                    FactorySystem factorySystem = planetFactory.factorySystem;
                    Debug.LogFormat("miner:{0},insert:{1},Assembler:{2},Fractionate:{3},Ejector:{4},silo:{5},lab:{6}",
                                    factorySystem.minerCursor, factorySystem.inserterCursor, factorySystem.assemblerCursor, factorySystem.fractionateCursor,
                                    factorySystem.ejectorCursor, factorySystem.siloCursor, factorySystem.labCursor
                                    );
                }
            }

            foreach (var ed in m_SelectEntities)
            {
                var    dict = SerializeObject(ed);
                string s    = "";
                foreach (var it in dict)
                {
                    s += it.Key + "=" + it.Value + ",";
                }
                Debug.Log(s);
            }
        }
Ejemplo n.º 4
0
        public static void DysonSphereRelatedGameTick(FactorySystem __instance)
        {
            IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
            {
                CodeMatcher matcher = new CodeMatcher(instructions);

                List <CodeInstruction> instructionsList = instructions.ToList();
                List <CodeInstruction> code             = new List <CodeInstruction>();

                int startIdx = 0;
                int endIdx   = matcher.MatchForward(false,
                                                    new CodeMatch(OpCodes.Ldloc_0),
                                                    new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningCostRate)))
                                                    ).Pos;

                if (endIdx == instructionsList.Count)
                {
                    throw new InvalidOperationException("Cannot extract the dysonsphere part of FactorySystem.GameTick because the first indicator isn't present");
                }

                for (int i = startIdx; i < endIdx; i++)
                {
                    code.Add(instructionsList[i]);
                }



                startIdx = matcher.MatchForward(false,
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(FactorySystem), nameof(FactorySystem.ejectorCursor)))
                                                ).Pos;
                if (startIdx == instructionsList.Count)
                {
                    throw new InvalidOperationException("Cannot extract the dysonsphere part of FactorySystem.GameTick because the second indicator isn't present");
                }

                endIdx = matcher.MatchForward(false,
                                              new CodeMatch(OpCodes.Ldloc_0),
                                              new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(GameHistoryData), nameof(GameHistoryData.currentTech)))
                                              ).Pos;
                if (endIdx == instructionsList.Count)
                {
                    throw new InvalidOperationException("Cannot extract the dysonsphere part of FactorySystem.GameTick because the third indicator isn't present");
                }

                Debug.Log($"extracted dysonsphere part of FactorySystem.GameTick from {startIdx} to {endIdx}");
                for (int i = startIdx; i < endIdx; i++)
                {
                    code.Add(instructionsList[i]);
                }

                return(code.AsEnumerable());
            }

            // make compiler happy
            _ = Transpiler(null);
            return;
        }
Ejemplo n.º 5
0
        public static void FactorySystem_RemoveEjectorComponent_Prefix(FactorySystem __instance, int id)
        {
            if (__instance.ejectorPool[id].id != 0)
            {
                var ejector    = __instance.ejectorPool[id];
                var ejectorUID = GetEjectorUID(ejector);

                managedEjectors.Remove(ejectorUID);
            }
        }
Ejemplo n.º 6
0
        public void Import(BinaryReader r)
        {
            r.ReadByte();

            for (int i = 0; i < GameMain.data.factoryCount; i++)
            {
                FactorySystem factory = GameMain.data.factories[i].factorySystem;
                for (int j = 1; j < factory.minerCursor; j++)
                {
                    factory.minerPool[j].insertTarget2 = r.ReadInt32();
                }
            }
        }
Ejemplo n.º 7
0
        static void TakeItemFromMiner(FactorySystem factory, int mid, int itemid, int count)
        {
            if (mid == 0)
            {
                return;
            }
            var ed = factory.minerPool[mid];

            if (ed.id == mid && ed.productId == itemid && ed.productCount >= count)
            {
                factory.minerPool[mid].productCount -= count;
            }
        }
Ejemplo n.º 8
0
        // Save and load miner Component's insertTarget2 field
        public void Export(BinaryWriter w)
        {
            w.Write((byte)0);

            for (int i = 0; i < GameMain.data.factoryCount; i++)
            {
                FactorySystem factory = GameMain.data.factories[i].factorySystem;
                for (int j = 1; j < factory.minerCursor; j++)
                {
                    w.Write(factory.minerPool[j].insertTarget2);
                }
            }
        }
Ejemplo n.º 9
0
        public static void GameTickPatch(FactorySystem __instance, long time, bool isActive)
        {
            var _this           = __instance;
            var assemblerCursor = Traverse.Create(__instance).Field("assemblerCursor").GetValue <int>();

            for (int num17 = 1; num17 < assemblerCursor; num17++)
            {
                var NextId = assemblerComponentEx.GetNextId(__instance.factory.index, num17);
                if (_this.assemblerPool[num17].id == num17 && NextId > 0)
                {
                    assemblerComponentEx.UpdateOutputToNext(__instance.factory.index, num17, _this.assemblerPool);
                }
            }
            return;
        }
Ejemplo n.º 10
0
    public void TestConnectorOneInOneOutBelttoBuilding()
    {
        // Arrange
        int numberOfCases = 2;
        var connectors    = new Connector[numberOfCases];

        connectors[0] = new Connector()
        {
            inputBelts = new List <Belt>()
            {
                GetFullBelt()
            },
            outputBuildings = new List <Building>()
            {
                GetEmptyBuilding()
            }
        };
        connectors[1] = new Connector()
        {
            inputBuildings = new List <Building>()
            {
                GetFullBuilding()
            },
            outputBelts = new List <Belt>()
            {
                GetEmptyBelt()
            }
        };

        // Act
        for (int i = 0; i < numberOfCases; i++)
        {
            FactorySystem.UpdateConnector(connectors[i]);
        }


        // Assert
        Assert.AreEqual(CheckBeltEmptyness(connectors[0].inputBelts[0]), true);
        Assert.AreEqual(GetBuildingInputCount(connectors[0].outputBuildings[0]), 1);
        Assert.AreEqual(GetBuildingOutputCount(connectors[0].outputBuildings[0]), 0);


        Assert.AreEqual(GetBuildingInputCount(connectors[1].inputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingOutputCount(connectors[1].inputBuildings[0]), 4);
        Assert.AreEqual(CheckBeltEmptyness(connectors[1].outputBelts[0]), false);
    }
Ejemplo n.º 11
0
        private static bool SetAssemblerCapacityPatch(FactorySystem __instance, int newCapacity)
        {
            var index = __instance.factory.index;

            if (index > assemblerComponentEx.assemblerNextIds.Length)
            {
                assemblerComponentEx.SetAssemblerCapacity(assemblerComponentEx.assemblerCapacity * 2);
            }
            var assemblerCapacity = Traverse.Create(__instance).Field("assemblerCapacity").GetValue <int>();

            int[] array = assemblerComponentEx.assemblerNextIds[index];
            assemblerComponentEx.assemblerNextIds[index] = new int[newCapacity];
            if (array != null)
            {
                Array.Copy(array, assemblerComponentEx.assemblerNextIds[index], (newCapacity <= assemblerCapacity) ? newCapacity : assemblerCapacity);
            }
            return(true);
        }
Ejemplo n.º 12
0
        public void factorySystemStatUpdate(long time, FactorySystem factorySystem)
        {
            var factory = factorySystem.factory;

            FactoryProductionStat factoryProductionStat = GameMain.statistics.production.factoryStatPool[factory.index];

            int[] productRegister = factoryProductionStat.productRegister;

            for (int i = 1; i < factorySystem.minerCursor; i++)
            {
                if (factorySystem.minerPool[i].id == i)
                {
                    var minerComponent = factorySystem.minerPool[i];
                    var networkId      = factory.powerSystem.consumerPool[minerComponent.pcId].networkId;

                    if (MinerComponent_InternalUpdate(
                            factory,
                            factory.veinPool,
                            factory.powerSystem.netPool[networkId],
                            factory.powerSystem.networkServes[networkId],
                            GameMain.history.miningCostRate,
                            GameMain.history.miningSpeedScale,
                            productRegister,
                            minerComponent))
                    {
                        // Update notificationTimes used to trigger notifications
                        if (notificationTimes.ContainsKey(minerComponent.entityId))
                        {
                            notificationTimes[minerComponent.entityId].lastUpdated = time;
                        }
                        else
                        {
                            // We want to trigger almost immediately, but leave notificationWindowLow for cases where you are actively building and haven't wired up things.
                            notificationTimes[minerComponent.entityId] = new NotificationTiming()
                            {
                                lastNotification = time - notificationWindowHigh + notificationWindowLow,
                                lastUpdated      = time
                            };
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public MiningBase()
        //////public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update1;
            shipComponents          = new ShipComponents();
            LocateAllParts();
            SetupFleetListener();

            log = new Logger(Me.CubeGrid, shipComponents);

            communicationSystems = new CommunicationSystem(log, Me.CubeGrid, shipComponents);
            navigationSystems    = new BasicNavigationSystem(log, Me.CubeGrid, shipComponents);
            factorySystems       = new FactorySystem(log, Me.CubeGrid, shipComponents);
            trackingSystems      = new TrackingSystem(log, Me.CubeGrid, shipComponents, true);
            weaponSystems        = new WeaponSystem(log, Me.CubeGrid, shipComponents);

            operatingOrder.AddLast(new TaskInfo(LocateAllParts));
            operatingOrder.AddLast(new TaskInfo(NavigationCheck));

            operatingOrder.AddLast(new TaskInfo(InternalSystemCheck));
            operatingOrder.AddLast(new TaskInfo(ScanLocalArea));

            operatingOrder.AddLast(new TaskInfo(UpdateTrackedTargets));
            operatingOrder.AddLast(new TaskInfo(UpdateDisplays));

            operatingOrder.AddLast(new TaskInfo(RecieveFleetMessages));
            operatingOrder.AddLast(new TaskInfo(SendPendingMessages));

            operatingOrder.AddLast(new TaskInfo(MaintainAltitude));

            operatingOrder.AddLast(new TaskInfo(IssueOrders));

            //operatingOrder.AddLast(new TaskInfo(RunProductionRoutine));

            maxCameraRange = 5000;
            maxCameraAngle = 80;
            //set new defaults
            hoverHeight             = 400;
            InitialBlockCount       = shipComponents.AllBlocks.Count();
            Runtime.UpdateFrequency = UpdateFrequency.Update1;
        }
    private void InstantiateSystemsManager()
    {
        SystemsManager      = Instantiate(new GameObject());
        SystemsManager.name = "SystemsManager";


        movementSystem       = SystemsManager.AddComponent <MovementSystem>();
        keyboardInputSystem  = SystemsManager.AddComponent <KeyboardInputSystem>();
        mouseInputSystem     = SystemsManager.AddComponent <MouseInputSystem>();
        factorySystem        = SystemsManager.AddComponent <FactorySystem>();
        lSystemSystem        = SystemsManager.AddComponent <LSystemSystem>();
        lSystemFactorySystem = SystemsManager.AddComponent <LSystemFactorySystem>();

        entityPool = SystemsManager.AddComponent <EntityPool>();
        entityPool.InitialiseEntitiesList();


        movementSystem.entityPool       = entityPool;
        keyboardInputSystem.entityPool  = entityPool;
        mouseInputSystem.entityPool     = entityPool;
        factorySystem.entityPool        = entityPool;
        lSystemSystem.entityPool        = entityPool;
        lSystemFactorySystem.entityPool = entityPool;
    }
Ejemplo n.º 15
0
    public void TestBeltUpdateMidSpaceRemovalAndMerge()
    {
        // Arrange
        int numberOfCases = 3;
        var belts         = new Belt[numberOfCases];

        belts[0] = new Belt(new Position(0, 0), new Position(2, 0))
        {
            items = new List <Belt.BeltSegment>()
            {
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 1
                    }
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item().SetEmpty()
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 1
                    }
                },
            }
        };
        belts[1] = new Belt(new Position(0, 0), new Position(5, 0))
        {
            items = new List <Belt.BeltSegment>()
            {
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item().SetEmpty()
                },
                new Belt.BeltSegment()
                {
                    count = 2, item = new Item()
                    {
                        itemId = 2
                    }
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item().SetEmpty()
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 2
                    }
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 1
                    }
                },
            }
        };
        belts[2] = new Belt(new Position(0, 0), new Position(4, 0))
        {
            items = new List <Belt.BeltSegment>()
            {
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 1
                    }
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item().SetEmpty()
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 1
                    }
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item().SetEmpty()
                },
                new Belt.BeltSegment()
                {
                    count = 1, item = new Item()
                    {
                        itemId = 1
                    }
                },
            }
        };

        // Act
        for (int i = 0; i < numberOfCases; i++)
        {
            FactorySystem.UpdateBelt(belts[i]);
        }


        // Assert
        var corrects = new List <Belt.BeltSegment> [numberOfCases];

        corrects[0] = new List <Belt.BeltSegment>()
        {
            new Belt.BeltSegment()
            {
                count = 1, item = new Item().SetEmpty()
            },
            new Belt.BeltSegment()
            {
                count = 2, item = new Item()
                {
                    itemId = 1
                }
            },
        };
        corrects[1] = new List <Belt.BeltSegment>()
        {
            new Belt.BeltSegment()
            {
                count = 2, item = new Item().SetEmpty()
            },
            new Belt.BeltSegment()
            {
                count = 3, item = new Item()
                {
                    itemId = 2
                }
            },
            new Belt.BeltSegment()
            {
                count = 1, item = new Item()
                {
                    itemId = 1
                }
            },
        };
        corrects[2] = new List <Belt.BeltSegment>()
        {
            new Belt.BeltSegment()
            {
                count = 1, item = new Item().SetEmpty()
            },
            new Belt.BeltSegment()
            {
                count = 1, item = new Item()
                {
                    itemId = 1
                }
            },
            new Belt.BeltSegment()
            {
                count = 1, item = new Item().SetEmpty()
            },
            new Belt.BeltSegment()
            {
                count = 2, item = new Item()
                {
                    itemId = 1
                }
            },
        };


        for (int i = 0; i < numberOfCases; i++)
        {
            Assert.IsTrue(BeltSegmentEqualityChecker(belts[i].items, corrects[i]));
        }
    }
Ejemplo n.º 16
0
        public static void FastDeleteEntities(PlanetFactory factory, List <int> targetIds, List <int> edgeIds)
        {
            Player player = GameMain.mainPlayer;

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

            FactorySystem factorySystem = factory.factorySystem;
            CargoTraffic  cargoTraffic  = factory.cargoTraffic;
            PowerSystem   powerSystem   = factory.powerSystem;

            // Close all the build tools, so we don't have to worry about BuildTool.buildPreview
            foreach (BuildTool buildTool in player.controller.actionBuild.tools)
            {
                if (!(buildTool is DragRemoveBuildTool))
                {
                    buildTool._Close();
                }
            }

            powerConRemoval.Clear();

            if (powerConRemoval.Capacity < powerSystem.netCursor)
            {
                powerConRemoval.Capacity = powerSystem.netCursor;
            }

            // Close inspect
            player.controller.actionInspect.InspectNothing();

            for (int i = 0; i < powerSystem.netCursor; i++)
            {
                int maxConsumers = 10;
                if (powerSystem.netPool[i] != null)
                {
                    maxConsumers = powerSystem.netPool[i].consumers.Count;
                }

                powerConRemoval.Add(new HashSet <int>(maxConsumers));
            }

            foreach (int itemId in LDB.items.dataIndices.Keys)
            {
                takeBackCount[itemId] = 0;
                takeBackInc[itemId]   = 0;
            }

            PowerConsumerComponent[] consumerPool = powerSystem.consumerPool;
            InserterComponent[]      inserterPool = factorySystem.inserterPool;
            EntityData[]             entityPool   = factory.entityPool;

            void RemoveConsumerComponent(int id)
            {
                ref PowerConsumerComponent powerCon = ref consumerPool[id];

                if (powerCon.id != 0)
                {
                    if (powerCon.networkId >= powerConRemoval.Count)
                    {
                        //Debug.Log($"Power Net: {powerCon.networkId} is not in the list");
                        return;
                    }

                    if (powerConRemoval[powerCon.networkId].Contains(id))
                    {
                        return;
                    }

                    powerConRemoval[powerCon.networkId].Add(id);
                    powerCon.SetEmpty();
                    powerSystem.consumerRecycle[powerSystem.consumerRecycleCursor] = id;
                    powerSystem.consumerRecycleCursor++;
                }
            }
Ejemplo n.º 17
0
        public static void SyncAssemblerFunctions(FactorySystem factorySystem, StorageComponent package, int assemblerId)
        {
            var _this    = factorySystem;
            int entityId = _this.assemblerPool[assemblerId].entityId;

            if (entityId == 0)
            {
                return;
            }
            int num  = entityId;
            int num2 = 0;

            do
            {
                bool flag;
                int  num3;
                int  num4;
                _this.factory.ReadObjectConn(num, 14, out flag, out num3, out num4);
                num = num3;
                if (num > 0)
                {
                    int assemblerId2 = _this.factory.entityPool[num].assemblerId;
                    if (assemblerId2 > 0 && _this.assemblerPool[assemblerId2].id == assemblerId2)
                    {
                        if (_this.assemblerPool[assemblerId].recipeId > 0)
                        {
                            if (_this.assemblerPool[assemblerId2].recipeId != _this.assemblerPool[assemblerId].recipeId)
                            {
                                _this.TakeBackItems_Assembler(package, assemblerId2);
                                _this.assemblerPool[assemblerId2].SetRecipe(_this.assemblerPool[assemblerId].recipeId, _this.factory.entitySignPool);
                            }
                        }
                        else if (_this.assemblerPool[assemblerId2].recipeId != 0)
                        {
                            _this.TakeBackItems_Assembler(package, assemblerId2);
                            _this.assemblerPool[assemblerId2].SetRecipe(0, _this.factory.entitySignPool);
                        }
                    }
                }
                if (num2 > 256)
                {
                    break;
                }
            }while (num != 0);
            num  = entityId;
            num2 = 0;
            do
            {
                bool flag;
                int  num3;
                int  num4;
                _this.factory.ReadObjectConn(num, 15, out flag, out num3, out num4);
                num = num3;
                if (num > 0)
                {
                    int assemblerId3 = _this.factory.entityPool[num].assemblerId;
                    if (assemblerId3 > 0 && _this.assemblerPool[assemblerId3].id == assemblerId3)
                    {
                        if (_this.assemblerPool[assemblerId].recipeId > 0)
                        {
                            if (_this.assemblerPool[assemblerId3].recipeId != _this.assemblerPool[assemblerId].recipeId)
                            {
                                _this.TakeBackItems_Assembler(package, assemblerId3);
                                _this.assemblerPool[assemblerId3].SetRecipe(_this.assemblerPool[assemblerId].recipeId, _this.factory.entitySignPool);
                            }
                        }
                        else if (_this.assemblerPool[assemblerId3].recipeId != 0)
                        {
                            _this.TakeBackItems_Assembler(package, assemblerId3);
                            _this.assemblerPool[assemblerId3].SetRecipe(0, _this.factory.entitySignPool);
                        }
                    }
                }
                if (num2 > 256)
                {
                    break;
                }
            }while (num != 0);
        }
Ejemplo n.º 18
0
        static void Miner(FactorySystem __instance)
        {
            GameHistoryData history = GameMain.history;



            float miningSpeedScale = history.miningSpeedScale;

            if (miningSpeedScale <= 0)
            {
                return;
            }
            int baseSpeed = (int)(120 / (miningSpeedScale));

            if (baseSpeed <= 0)
            {
                baseSpeed = 1;
            }

            if (frame % baseSpeed != 0)
            {
                return;
            }


            var veinPool = __instance.factory.veinPool;
            Dictionary <int, List <int> > veins = new Dictionary <int, List <int> >();


            if (__instance.minerPool[0].seed == 0)
            {
                var rondom = new System.Random();
                __instance.minerPool[0].seed = (uint)(__instance.planet.id * 100000 + rondom.Next(1, 9999));
            }
            else
            {
                seed = __instance.minerPool[0].seed;
            }



            for (int i = 0; i < veinPool.Length; i++)
            {
                var d = veinPool[i];
                if (d.amount > 0 && d.productId > 0)
                {
                    AddVeinData(veins, d.productId, i);
                }
            }

            float           miningCostRate = 0;
            PlanetTransport transport      = null;

            int[] productRegister = null;

            miningCostRate = history.miningCostRate;
            transport      = __instance.planet.factory.transport;

            FactoryProductionStat factoryProductionStat = GameMain.statistics.production.factoryStatPool[__instance.factory.index];

            bool h = false;

            if (factoryProductionStat != null)
            {
                productRegister = factoryProductionStat.productRegister;
                h = true;
            }


            for (int i = 1; i < transport.stationCursor; i++)
            {
                var sc = transport.stationPool[i];
                if (sc != null && sc.storage != null)
                {
                    for (int j = 0; j < sc.storage.Length; j++)
                    {
                        var da = sc.storage[j];
                        if (da.localLogic == ELogisticStorage.Demand && da.max > da.count)
                        {
                            if (veins.ContainsKey(da.itemId) || da.itemId == __instance.planet.waterItemId)
                            {
                                //当能量不足一半时
                                if (sc.energyMax / 2 > sc.energy)
                                {
                                    //获取倒数第二个物品栏
                                    var lastup = sc.storage[sc.storage.Length - 2];
                                    //如果物品数量大于0
                                    if (lastup.count > 0)
                                    {
                                        //获取物品的能量值
                                        long en = LDB.items.Select(lastup.itemId).HeatValue;
                                        //如果物品的能量大于0
                                        if (en > 0)
                                        {
                                            //获取需要充电的能量
                                            long needen = sc.energyMax - sc.energy;
                                            //计算需要的数量
                                            int needcount = (int)(needen / en);
                                            //如果需要是数量大于有的数量
                                            if (needcount > lastup.count)
                                            {
                                                //将需求数量改为当前数量
                                                needcount = sc.storage[sc.storage.Length - 2].count;
                                            }
                                            //消耗物品
                                            sc.storage[sc.storage.Length - 2].count -= needcount;
                                            //充能
                                            sc.energy += needcount * en;
                                        }
                                    }
                                }
                            }
                            if (veins.ContainsKey(da.itemId))
                            {
                                if (sc.energy >= uesEnergy)
                                {
                                    var vein = veins[da.itemId].First();
                                    if (veinPool[vein].type == EVeinType.Oil)
                                    {
                                        float count = 0;
                                        foreach (int index in veins[da.itemId])
                                        {
                                            if (veinPool.Length > index && veinPool[index].productId > 0)
                                            {
                                                count += veinPool[index].amount / 6000f;
                                            }
                                        }
                                        sc.storage[j].count += (int)count;
                                        if (h)
                                        {
                                            productRegister[da.itemId] += (int)count;
                                        }
                                        sc.energy -= uesEnergy;
                                    }
                                    else
                                    {
                                        int count = 0;
                                        foreach (int index in veins[da.itemId])
                                        {
                                            if (GetMine(veinPool, index, miningCostRate, __instance.planet.factory))
                                            {
                                                count++;
                                            }
                                        }
                                        sc.storage[j].count += count;
                                        if (h)
                                        {
                                            productRegister[da.itemId] += count;
                                        }
                                        sc.energy -= uesEnergy;
                                    }
                                }
                            }
                            else if (da.itemId == __instance.planet.waterItemId)
                            {
                                sc.storage[j].count += waterSpeed;
                                if (h)
                                {
                                    productRegister[da.itemId] += waterSpeed;
                                }
                                sc.energy -= uesEnergy;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
 public static int GetInsertTarget(FactorySystem system, int slotId, int minerId)
 {
     return(GetInsertTarget(system.minerPool[minerId], slotId));
 }
Ejemplo n.º 20
0
    public void TestConnectorOneInOneOutBeltToBelt()
    {
        // Arrange
        int numberOfCases = 4;
        var connectors    = new Connector[numberOfCases];

        connectors[0] = new Connector()
        {
            inputBelts = new List <Belt>()
            {
                GetEmptyBelt()
            },
            outputBelts = new List <Belt>()
            {
                GetEmptyBelt()
            }
        };
        connectors[1] = new Connector()
        {
            inputBelts = new List <Belt>()
            {
                GetFullBelt()
            },
            outputBelts = new List <Belt>()
            {
                GetFullBelt()
            }
        };
        connectors[2] = new Connector()
        {
            inputBelts = new List <Belt>()
            {
                GetFullBelt()
            },
            outputBelts = new List <Belt>()
            {
                GetEmptyBelt()
            }
        };
        connectors[3] = new Connector()
        {
            inputBelts = new List <Belt>()
            {
                GetEmptyBelt()
            },
            outputBelts = new List <Belt>()
            {
                GetFullBelt()
            }
        };

        // Act
        for (int i = 0; i < numberOfCases; i++)
        {
            FactorySystem.UpdateConnector(connectors[i]);
        }


        // Assert
        Assert.IsTrue(CheckBeltEmptyness(connectors[0].inputBelts[0]));
        Assert.IsTrue(CheckBeltEmptyness(connectors[0].outputBelts[0]));

        Assert.IsFalse(CheckBeltEmptyness(connectors[1].inputBelts[0]));
        Assert.IsFalse(CheckBeltEmptyness(connectors[1].outputBelts[0]));

        Assert.IsTrue(CheckBeltEmptyness(connectors[2].inputBelts[0]));
        Assert.IsFalse(CheckBeltEmptyness(connectors[2].outputBelts[0]));

        Assert.IsTrue(CheckBeltEmptyness(connectors[3].inputBelts[0]));
        Assert.IsFalse(CheckBeltEmptyness(connectors[3].outputBelts[0]));
    }
Ejemplo n.º 21
0
    public void TestConnectorOneInOneOutBuildingToBuilding()
    {
        // Arrange
        int numberOfCases = 4;
        var connectors    = new Connector[numberOfCases];

        connectors[0] = new Connector()
        {
            inputBuildings = new List <Building>()
            {
                GetEmptyBuilding()
            },
            outputBuildings = new List <Building>()
            {
                GetEmptyBuilding()
            }
        };
        connectors[1] = new Connector()
        {
            inputBuildings = new List <Building>()
            {
                GetFullBuilding()
            },
            outputBuildings = new List <Building>()
            {
                GetFullBuilding()
            }
        };
        connectors[2] = new Connector()
        {
            inputBuildings = new List <Building>()
            {
                GetFullBuilding()
            },
            outputBuildings = new List <Building>()
            {
                GetEmptyBuilding()
            }
        };
        connectors[3] = new Connector()
        {
            inputBuildings = new List <Building>()
            {
                GetEmptyBuilding()
            },
            outputBuildings = new List <Building>()
            {
                GetFullBuilding()
            }
        };

        // Act
        for (int i = 0; i < numberOfCases; i++)
        {
            FactorySystem.UpdateConnector(connectors[i]);
        }


        // Assert
        Assert.AreEqual(GetBuildingInputCount(connectors[0].inputBuildings[0]), 0);
        Assert.AreEqual(GetBuildingOutputCount(connectors[0].inputBuildings[0]), 0);
        Assert.AreEqual(GetBuildingInputCount(connectors[0].outputBuildings[0]), 0);
        Assert.AreEqual(GetBuildingOutputCount(connectors[0].outputBuildings[0]), 0);

        Assert.AreEqual(GetBuildingInputCount(connectors[1].inputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingOutputCount(connectors[1].inputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingInputCount(connectors[1].outputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingOutputCount(connectors[1].outputBuildings[0]), 5);

        Assert.AreEqual(GetBuildingInputCount(connectors[2].inputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingOutputCount(connectors[2].inputBuildings[0]), 4);
        Assert.AreEqual(GetBuildingInputCount(connectors[2].outputBuildings[0]), 1);
        Assert.AreEqual(GetBuildingOutputCount(connectors[2].outputBuildings[0]), 0);

        Assert.AreEqual(GetBuildingInputCount(connectors[3].inputBuildings[0]), 0);
        Assert.AreEqual(GetBuildingOutputCount(connectors[3].inputBuildings[0]), 0);
        Assert.AreEqual(GetBuildingInputCount(connectors[3].outputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingOutputCount(connectors[3].outputBuildings[0]), 5);


        // Act 2
        FactorySystem.UpdateConnector(connectors[2]);


        // Assert 2
        Assert.AreEqual(GetBuildingInputCount(connectors[2].inputBuildings[0]), 5);
        Assert.AreEqual(GetBuildingOutputCount(connectors[2].inputBuildings[0]), 3);
        Assert.AreEqual(GetBuildingInputCount(connectors[2].outputBuildings[0]), 2);
        Assert.AreEqual(GetBuildingOutputCount(connectors[2].outputBuildings[0]), 0);
    }