using Sandbox.Game.EntityComponents; using Sandbox.ModAPI.Ingame; using Sandbox.ModAPI.Interfaces; using SpaceEngineers.Game.ModAPI.Ingame; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System; using VRage.Collections; using VRage.Game.Components; using VRage.Game.ModAPI.Ingame; using VRage.Game.ModAPI.Ingame.Utilities; using VRage.Game.ObjectBuilders.Definitions; using VRage.Game; using VRageMath; namespace IngameScript { partial class Program : MyGridProgram { private Dictionary getComponentList() { Dictionary list = new Dictionary(); list.Add("BulletproofGlass", 1000); list.Add("Computer", 1000); list.Add("Construction", 2000); list.Add("Detector", 200); list.Add("Display", 1000); list.Add("Explosives", 0); list.Add("Girder", 1000); list.Add("GravityGenerator", 200); list.Add("InteriorPlate", 2000); list.Add("LargeTube", 1000); list.Add("Medical", 200); list.Add("MetalGrid", 1000); list.Add("Motor", 2000); list.Add("PowerCell", 200); list.Add("RadioCommunication", 200); list.Add("Reactor", 200); list.Add("SmallTube", 2000); list.Add("SolarCell", 200); list.Add("SteelPlate", 4000); list.Add("Superconductor", 200); list.Add("Thrust", 200); list.Add("Canvas", 200); return list; } public Program() { } public void Save() { } public void Main(string argument, UpdateType updateSource) { List textPanels = new List(); GridTerminalSystem.GetBlocksOfType(textPanels, x => x.DisplayNameText.Contains("quota")); List terminalBlocks = new List(); GridTerminalSystem.GetBlocks(terminalBlocks); var componentList = getComponentList(); Dictionary componentTotals = new Dictionary(); foreach (var terminalBlock in terminalBlocks) { if (terminalBlock.HasInventory) { //terminalBlock.InventoryCount; for (int i = 0; i < terminalBlock.InventoryCount; i++) { var myInventory = terminalBlock.GetInventory(i); if (myInventory != null) { List myInventoryItems = new List(); myInventory.GetItems(myInventoryItems); foreach (var item in myInventoryItems) { //string itemName = item.Content.SubtypeId.ToString(); string itemName = item.Type.SubtypeId.ToString(); if (componentList.ContainsKey(itemName)) { if (componentTotals.ContainsKey(itemName)) componentTotals[itemName] += (int)item.Amount; else componentTotals[itemName] = (int)item.Amount; } } } } } } List assemblers = new List(); GridTerminalSystem.GetBlocksOfType(assemblers, x => !x.DisplayNameText.Contains("~")); foreach (var assembler in assemblers) { List productionItems = new List(); assembler.GetQueue(productionItems); foreach (var component in componentList) { int amount = component.Value; if (componentTotals.ContainsKey(component.Key)) amount -= componentTotals[component.Key]; amount = amount > 100 ? 100 : amount; if (amount > 0) { string blueprintName = getBlueprintName(component.Key); if (!productionItems.Exists(x => x.BlueprintId.ToString() == blueprintName)) { MyDefinitionId blueprint = MyDefinitionId.Parse(blueprintName); assembler.AddQueueItem(blueprint, (decimal)amount); } } } /*if (productionItems.Count > 1 && !assembler.IsProducing) { var item = productionItems[0]; assembler.RemoveQueueItem(0, item.Amount); assembler.AddQueueItem(item.BlueprintId, item.Amount); }*/ } foreach (var textPanel in textPanels) { textPanel.Font = "Monospace"; textPanel.FontSize = 0.8f; textPanel.WritePublicText("", false); foreach (var componentTotal in componentTotals.OrderBy(x => x.Key)) { textPanel.WritePublicText(componentTotal.Key + " : " + componentTotal.Value.ToString() + "\n", true); } textPanel.ShowPublicTextOnScreen(); } } private string getBlueprintName(string name) { string prefix = "MyObjectBuilder_BlueprintDefinition/"; switch (name) { case "BulletproofGlass": return prefix + name; case "Computer": return prefix + name + "Component"; case "Construction": return prefix + name + "Component"; case "Detector": return prefix + name + "Component"; case "Display": return prefix + name; case "Explosives": return prefix + name + "Component"; case "Girder": return prefix + name + "Component"; case "GravityGenerator": return prefix + name + "Component"; case "InteriorPlate": return prefix + name; case "LargeTube": return prefix + name; case "Medical": return prefix + name + "Component"; case "MetalGrid": return prefix + name; case "Motor": return prefix + name + "Component"; case "PowerCell": return prefix + name; case "RadioCommunication": return prefix + name + "Component"; case "Reactor": return prefix + name + "Component"; case "SmallTube": return prefix + name; case "SolarCell": return prefix + name; case "SteelPlate": return prefix + name; case "Superconductor": return prefix + name; case "Thrust": return prefix + name + "Component"; case "Canvas": return prefix + name; default: return ""; } } } }