public void PrintContentsWithSubtype(string lcdName, string containerName, string title, int timer)
        {
            var results = StringifyContainerContent(containerName);

            var containers = GridBlocksHelper.Prefixed(GTS, containerName).GetCargoContainers();

            if (containers.Count == 0)
            {
                results = "Container not found.";
            }

            var items = CargoHelper.GetItemsInInventory(containers[0].GetInventory(0));

            var itemsString = items.Select(item => item.ItemName + "(" + (item.IsOre ? "Ore" : "Ingot") + ")" + " - " + item.Quantity);

            results = String.Join("\n", itemsString);

            //public List<string> GetItemsInInventory(string containerName)
            //{
            //    // Get containers
            //    var containers = GridBlocksHelper.Prefixed(GTS, containerName).GetCargoContainers();
            //    if (containers.Count == 0)
            //        return new List<string> { "Container not found." };

            //    // Get items in inventories
            //    var itemsInDestinyInventory = CargoHelper.GetItemsInInventories(containers);

            //    // Build a string with the items
            //    return itemsInDestinyInventory.Values.Select(item => item.ItemName + " - " + item.Quantity).ToList();
            //}

            PrintResultsOnLcd(lcdName, results, title, timer);
        }
Ejemplo n.º 2
0
        public GridCargo ReadAllCargo()
        {
            var inventoryBlocks = GridBlocksHelper.Get(GTS).GetAllInventoryBlocks();
            var inventories     = inventoryBlocks.SelectMany(t => InventoryHelper.GetInventories(t));

            Items = CargoHelper.GetItemsInInventories(inventories);
            return(this);
        }
Ejemplo n.º 3
0
        public void Sort(string groupName)
        {
            var groupBlocks      = GridBlocksHelper.Get(GTS).GetGroupBlocks(groupName);
            var groupInventories = groupBlocks.SelectMany(t => InventoryHelper.GetInventories(t));
            var groupCargo       = CargoHelper.GetItemsInInventories(groupInventories);

            var oresBlocks       = GridBlocksHelper.Get(GTS).GetGroupBlocks(oresGroup);
            var ingotsBlocks     = GridBlocksHelper.Get(GTS).GetGroupBlocks(ingotsGroup);
            var componentsBlocks = GridBlocksHelper.Get(GTS).GetGroupBlocks(componentsGroup);
        }
Ejemplo n.º 4
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update100;
            H = new Helper(GridTerminalSystem);
            Echo("Lauching script...\n If you add more refineries recompile script");

            // Get needed blocks in grid
            AllRefineries        = H.Grid.GetGroupBlocks(controlledRefineries);
            EmptyCargoInventory  = H.Grid.GetCargoContainers(emptyCargoContainer).First().GetInventory(0);
            ContainerInventories = H.Grid.GetBlocks().Where(t => t is IMyCargoContainer).Select(t => t.GetInventory(0)).ToList();

            // Empty refineries into one cargo container before starting script (that should be handled by some inventory manager script)
            AllRefineries.Select(t => t.GetInventory(0)).Where(t => t.ItemCount > 0).ToList()
            .ForEach(t => CargoHelper.MoveAllCargo(t, EmptyCargoInventory));
        }
        public string StringifyContainerContent(List <IMyTerminalBlock> inventoryBlocks)
        {
            // Get items in inventories
            var inventories             = inventoryBlocks.SelectMany(t => InventoryHelper.GetInventories(t));
            var itemsInDestinyInventory = CargoHelper.GetItemsInInventories(inventories);

            // Build a string with the items
            var itemsString = string.Empty;

            foreach (var item in itemsInDestinyInventory.Values)
            {
                itemsString += item.ItemName + " - " + item.Quantity + "\n";
            }
            return(itemsString);
        }
        public string StringifyContainerContent(string containerName, Dictionary <string, int> componentDesiredQuantities)
        {
            // Get containers
            var containers = GridBlocksHelper.Prefixed(GTS, containerName).GetCargoContainers();

            if (containers.Count == 0)
            {
                return("Container not found.");
            }

            // Get items in inventories
            var inventories             = containers.SelectMany(t => InventoryHelper.GetInventories(t));
            var itemsInDestinyInventory = CargoHelper.GetItemsInInventories(inventories);

            // Build a string with the items
            var itemsString = string.Empty;

            if (componentDesiredQuantities == null || componentDesiredQuantities.Count == 0)
            {
                foreach (var item in itemsInDestinyInventory.Values)
                {
                    itemsString += item.ItemName + " - " + item.Quantity + "\n";
                }
                return(itemsString);
            }

            foreach (var desired in componentDesiredQuantities)
            {
                var quantity = itemsInDestinyInventory.ContainsKey(desired.Key) ? itemsInDestinyInventory[desired.Key].Quantity : 0;
                if (quantity == 0 && desired.Value == 0)
                {
                    continue;
                }
                var percentage = getPercentage(quantity, desired.Value);

                itemsString += desired.Key + " - " + quantity + "(" + percentage + "%) " + (percentage < 100 ? "<=========" : string.Empty) + "\n";
            }

            return(itemsString);
        }
Ejemplo n.º 7
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.º 8
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);
                }
            });
        }