Ejemplo n.º 1
0
        public void Main(string argument, UpdateType updateSource)
        {
            H.UpdateTimer();

            Echo("Running Ucat's automated refineries" + H.TimerChar);

            // Get ores in inventories
            var ores = ContainerInventories.SelectMany(t => CargoHelper.GetItemsInInventory(t)).Where(t => (t.IsOre && t.ItemName != CargoHelper.ICE) || (t.IsIngot && t.ItemName == CargoHelper.SCRAP)).ToList();

            //Echo("Ores Found:\n" + ores.Select(t => t.ItemName + ": " + t.Quantity.ToIntSafe() + "\n").Aggregate((acc, t) => acc + t));

            // Get most priority ore and quantity for each refinery
            //var itemName = oresPriority.FirstOrDefault(t => ores.Any(r => r.ItemName == t));

            // Get ore with most quantity first
            Echo("Sorting ores by most quantity.\n");
            var max      = ores.Max(r => r.Quantity.RawValue);
            var itemName = ores.FirstOrDefault(t => t.Quantity.RawValue == max)?.ItemName;

            if (itemName == null)
            {
                Echo("\nAll done, nothing to refine");
                return;
            }

            var item    = ores.FirstOrDefault(t => t.ItemName == itemName);
            var divided = (MyFixedPoint)(item.Quantity.RawValue > 1000 ? ((decimal)item.Quantity.RawValue / AllRefineries.Count / 1000000) : 1);


            if (divided.RawValue < 1000000)
            {
                Echo("\nNot worth moving " + item.Quantity.ToIntSafe() + " " + itemName + ".\nWaiting for more...");
                return;
            }

            var refineryOne          = AllRefineries.First();
            var moveOres             = refineryOne.GetInventory(0).CurrentVolume.RawValue < refineryOne.GetInventory(0).MaxVolume.RawValue / 2;
            var emptySecondInventory = refineryOne.GetInventory(1).CurrentVolume.RawValue > refineryOne.GetInventory(1).MaxVolume.RawValue / 2;

            if (moveOres)
            {
                Echo("Moving " + divided.ToIntSafe() + " " + itemName + " into each refinery.");
            }

            AllRefineries.ForEach(t =>
            {
                // Move target quantity into refinery if not full
                if (moveOres)
                {
                    t.GetInventory(0).TransferItemFrom(item.Inventory, item.Item, divided);
                }

                // Empty second inventory
                if (emptySecondInventory)
                {
                    CargoHelper.MoveAllCargo(t.GetInventory(1), EmptyCargoInventory);
                }

                // Turn off refinery when it's empty, on otherwise
                if (t.GetInventory(0).ItemCount == 0)
                {
                    TerminalBlockHelper.TurnOff(t);
                }
                else
                {
                    TerminalBlockHelper.TurnOn(t);
                }
            });
        }
Ejemplo n.º 2
0
        public void Main(string argument, UpdateType updateSource)
        {
            H.UpdateTimer();

            Echo("Running Ucat's automated sifters" + H.TimerChar);

            if (H.TimerChar != "|")
            {
                // Don't run script on every execution
                return;
            }

            // Get gravel in inventories
            var gravel = ContainerInventories.SelectMany(t => CargoHelper.GetItemsInInventory(t)).Where(t => (t.IsIngot && t.ItemName == CargoHelper.STONE)).FirstOrDefault();;

            if (gravel == null)
            {
                Echo("All done, nothing to sift");
                return;
            }

            var divided = (MyFixedPoint)(gravel.Quantity.RawValue > 1000 ? ((decimal)gravel.Quantity.RawValue / AllSifters.Count / 1000000) : 1);

            if (divided.RawValue < 1000000)
            {
                Echo("\nNot worth moving " + gravel.Quantity.ToIntSafe() + " " + " gravel.\nWaiting for more...\n");
                return;
            }

            var sifterOne            = AllSifters.First();
            var moveGravel           = sifterOne.GetInventory(0).CurrentVolume.RawValue < sifterOne.GetInventory(0).MaxVolume.RawValue / 2;
            var emptySecondInventory = sifterOne.GetInventory(1).CurrentVolume.RawValue > sifterOne.GetInventory(1).MaxVolume.RawValue / 2;

            if (moveGravel)
            {
                Echo("Moving gravel into sifters: " + divided.ToIntSafe());
            }

            AllSifters.ForEach(t =>
            {
                // Move target quantity into refinery if not full
                if (moveGravel)
                {
                    t.GetInventory(0).TransferItemFrom(gravel.Inventory, gravel.Item, divided);
                }

                // Empty second inventory if half full
                if (emptySecondInventory)
                {
                    Echo("Emptying");
                    CargoHelper.MoveAllCargo(t.GetInventory(1), EmptyCargoInventory);
                }

                // Turn off sifter when it's empty, on otherwise
                if (t.GetInventory(0).ItemCount == 0)
                {
                    TerminalBlockHelper.TurnOff(t);
                }
                else
                {
                    TerminalBlockHelper.TurnOn(t);
                }
            });
        }