Space Engineers

Space Engineers

Fluid Battery
 Denne tråd er blevet fastgjort, så den er sikkert vigtig
Dummy08  [udvikler] 10. mar. 2019 kl. 11:48
Script support
As the game battery class does not allow conveyor connection the fluid battery mod is derived from reactor.

Therefor if you would like to use the battery in scripts you can't directly use the IMyBattery Interface.


/// <summary> /// Extension methode does not work here as the script is embedded as a nested class /// </summary> public static class BatteryExtensions { public static ChargeMode GetChargeMode(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.ChargeMode; var property = entity.GetProperty("ChargeMode"); return property != null ? (ChargeMode)property.Cast<long>().GetValue(entity) : ChargeMode.Auto; } public static void SetChargeMode(IMyFunctionalBlock entity, ChargeMode value) { var battery = entity as IMyBatteryBlock; if (battery != null) { battery.ChargeMode = value; return; } var property = entity.GetProperty("ChargeMode"); if (property != null) property.Cast<long>().SetValue(entity, (long)value); } public static float GetMaxStoredPower(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.MaxStoredPower; var property = entity.GetProperty("MaxStoredPower"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetCurrentStoredPower(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.CurrentStoredPower; var property = entity.GetProperty("CurrentStoredPower"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetMaxInput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.MaxInput; var property = entity.GetProperty("MaxInput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetMaxOutput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.MaxOutput; var property = entity.GetProperty("MaxOutput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetCurrentOutput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.CurrentOutput; var property = entity.GetProperty("CurrentOutput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } public static float GetCurrentInput(IMyFunctionalBlock entity) { var battery = entity as IMyBatteryBlock; if (battery != null) return battery.CurrentInput; var property = entity.GetProperty("CurrentInput"); return property != null ? property.Cast<float>().GetValue(entity) : 0f; } }

Sidst redigeret af Dummy08; 10. mar. 2019 kl. 12:02
< >
Viser 1-1 af 1 kommentarer
Forge 20. apr. 2019 kl. 15:22 
This Helped me a lot, thank you (I just had to make the whole class it not static)
< >
Viser 1-1 af 1 kommentarer
Per side: 1530 50