Initial Commit
This commit is contained in:
commit
e9f360305b
1 changed files with 57 additions and 0 deletions
57
iceMonitor.cs
Normal file
57
iceMonitor.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
const int upperThreshold = 25000000;
|
||||
const int lowerThreshold = 1000000;
|
||||
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";
|
||||
Echo($"Current Ice Amount: {iceamount}");
|
||||
Echo($"Collectors are {collectorState}");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue