Space Engineers

Space Engineers

Fluid Battery
 此主题已被置顶,因此可能具有重要性
Dummy08  [开发者] 2019 年 3 月 10 日 上午 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; } }

最后由 Dummy08 编辑于; 2019 年 3 月 10 日 下午 12:02
< >
正在显示第 1 - 1 条,共 1 条留言
Forge 2019 年 4 月 20 日 下午 3:22 
This Helped me a lot, thank you (I just had to make the whole class it not static)
< >
正在显示第 1 - 1 条,共 1 条留言
每页显示数: 1530 50