gaming-scripts/Space Engineers/iceMonitoringScript.cs

69 lines
2.2 KiB
C#
Raw Normal View History

2023-04-04 18:55:31 +00:00
/* CUSTOMIZE BEHAVIOR HERE */
2023-03-01 18:04:29 +00:00
2023-03-01 17:59:59 +00:00
const int upperThreshold = 25000000;
const int lowerThreshold = 1000000;
2023-03-01 18:04:29 +00:00
2023-04-04 18:55:31 +00:00
/* DO NOT CHANGE ANYTHING BELOW THIS LINE */
2023-03-01 18:04:29 +00:00
2023-03-01 17:59:59 +00:00
string collectorState = "";
List<IMyCargoContainer> oreContainers = new List<IMyCargoContainer>();
List<MyInventoryItem> Items = new List<MyInventoryItem>();
IMyBlockGroup collectorGroup;
List<IMyCollector> collectors = new List<IMyCollector>();
public Program() {
Runtime.UpdateFrequency = UpdateFrequency.Update100;
}
public void Main(string args) {
collectorGroup = GridTerminalSystem.GetBlockGroupWithName("Collectors");
collectorGroup.GetBlocksOfType(collectors);
int iceamount = getCurrentIceAmount();
collectorState = collectors[0].Enabled ? "Active" : "Inactive";
2023-04-08 12:20:23 +00:00
var msg = string.Format("\n\nIce Manager by Firq\n----------------------------\nCurrent Time: {0}\n----------------------------\nCollectors are {1}\nIce Amount: {2}M",
DateTime.UtcNow.ToLocalTime().ToLongTimeString(), collectorState, Math.Round((iceamount / 1000000.0), 2));
var screen = Me.GetSurface(0);
screen.ContentType = ContentType.TEXT_AND_IMAGE;
screen.Alignment = TextAlignment.CENTER;
screen.WriteText(msg, false);
Echo(msg);
2023-03-01 17:59:59 +00:00
if(iceamount > upperThreshold) {
toggleCollectors(false);
Echo($"Collectors are OFF");
} else if (iceamount < lowerThreshold) {
toggleCollectors(true);
Echo($"Collectors are ON");
}
}
public int getCurrentIceAmount() {
int totalAmount = 0;
GridTerminalSystem.GetBlocksOfType(oreContainers);
foreach (var osc in oreContainers) {
var inventory = osc.GetInventory(0);
Items.Clear();
inventory.GetItems(Items);
foreach (var item in Items) {
string key = item.Type.ToString();
if (key == "MyObjectBuilder_Ore/Ice") {
totalAmount = totalAmount + item.Amount.ToIntSafe();
}
}
}
return totalAmount;
}
public void toggleCollectors(bool targetState) {
if (collectors == null) {
Echo("Group collectors not found");
return;
}
foreach (var collector in collectors) {
collector.Enabled = targetState;
}
}