using System; using System.Text; using System.Collections; using System.Collections.Generic; using VRageMath; using VRage.Game; using Sandbox.ModAPI.Interfaces; using Sandbox.ModAPI.Ingame; using Sandbox.Game.EntityComponents; using VRage.Game.Components; using VRage.Collections; using VRage.Game.ObjectBuilders.Definitions; using VRage.Game.ModAPI.Ingame; using SpaceEngineers.Game.ModAPI.Ingame; namespace Tut3 { class Program : MyGridProgram { private const string inDoorName = "inDoor"; private const string outDoorName = "outDoor"; private const string timerName = "timerForClose"; private const string inLightName = "inLight"; private const string outLightName = "outLight"; private const string airVentName = "airVent"; private IMyDoor myDoorOut; private IMyDoor myDoorIn; private IMyTimerBlock myTimerForClose; private IMyLightingBlock myLightIn; private IMyLightingBlock myLightOut; private IMyAirVent myAirVent; List allDoors = new List(); List allTimerBlocks = new List(); List allLightningBlocks = new List(); List allAirVents = new List(); Dictionary nameToCloseOut = new Dictionary(); // Konstruktor, wird beim Programmstart/Neukompilieren ausgeführt public Program() { GridTerminalSystem.GetBlocksOfType(allDoors); GridTerminalSystem.GetBlocksOfType(allTimerBlocks); GridTerminalSystem.GetBlocksOfType(allLightningBlocks); GridTerminalSystem.GetBlocksOfType(allAirVents); } private void LoadAllBlocks(string name) { var doorIn = allDoors.Find(x => x.CustomName == name + inDoorName); var doorOut = allDoors.Find(x => x.CustomName == name + outDoorName); var timerForClose = allTimerBlocks.Find(x => x.CustomName == name + timerName); var lightIn = allLightningBlocks.Find(x => x.CustomName == name + inLightName); var lightOut = allLightningBlocks.Find(x => x.CustomName == name + outLightName); var airVent = allAirVents.Find(x => x.CustomName == name + airVentName); if (!nameToCloseOut.ContainsKey(name)) { nameToCloseOut.Add(name, doorIn.Status == DoorStatus.Closed); } Echo(doorIn.CustomName); Echo(doorOut.CustomName); Echo(timerForClose.CustomName); Echo(lightIn.CustomName); Echo(lightOut.CustomName); if (doorIn == null) { Echo($"{inDoorName} not found"); } if (doorOut == null) { Echo($"{outDoorName} not found"); } if (timerForClose == null) { Echo($"{timerName} not found"); } if (lightIn == null || !(lightIn is IMyLightingBlock)) { Echo($"{inLightName} not found"); } if (lightOut == null || !(lightOut is IMyLightingBlock)) { Echo($"{outLightName} not found"); } if (airVent == null) { Echo($"{airVentName} not found"); } myDoorOut = doorOut; myDoorIn = doorIn; myTimerForClose = timerForClose; myLightIn = lightIn; myLightOut = lightOut; myAirVent = airVent; } // Mit der Funktion Save kann man Werte über die Spielsession hinweg speichern public void Save() { } public void Main(string argument, UpdateType updateType) { string[] args = argument.Split(';'); if(args.Length != 2) { Echo("lengh of args not equals 2"); } string name = args[0]; string command = args[1]; LoadAllBlocks(name); if (command == "close") { if (nameToCloseOut[name]) { myDoorOut.CloseDoor(); myAirVent.ApplyAction("Depressurize_Off"); myLightIn.ApplyAction("OnOff_On"); } else { myDoorIn.CloseDoor(); myAirVent.ApplyAction("Depressurize_On"); myLightOut.ApplyAction("OnOff_On"); } myTimerForClose.StartCountdown(); } else if (command == "open") { if (nameToCloseOut[name]) { myDoorOut.ApplyAction("OnOff_Off"); myDoorIn.ApplyAction("OnOff_On"); myDoorIn.OpenDoor(); nameToCloseOut[name] = false; myLightIn.ApplyAction("OnOff_Off"); } else { myDoorIn.ApplyAction("OnOff_Off"); myDoorOut.ApplyAction("OnOff_On"); myDoorOut.OpenDoor(); nameToCloseOut[name] = true; myLightOut.ApplyAction("OnOff_Off"); } } } } }