public static int GetEngineModifier(AbstractActor actor) { int engineMod = 0; if (actor.GetTags().Contains("unit_powerarmor")) { Mod.Log.Debug($" Actor:{actor.DisplayName}_{actor.GetPilot().Name} is PowerArmor, skipping engine bonus."); } else { MechComponent mainEngineComponent = actor?.allComponents?.FirstOrDefault(c => c?.componentDef?.GetComponent <EngineCoreDef>() != null); if (mainEngineComponent != null) { EngineCoreDef engine = mainEngineComponent?.componentDef?.GetComponent <EngineCoreDef>(); float tonnage = GetUnitTonnage(actor); engineMod = CalculateEngineModifier(tonnage, engine.Rating); Mod.Log.Debug($" Actor:{actor.DisplayName}_{actor.GetPilot().Name} with engine rating: {engine?.Rating} has engineMod:{engineMod}"); } else { Mod.Log.Info($" Actor:{actor.DisplayName}_{actor.GetPilot().Name} has no engine - is this expected?"); } } return(engineMod); }
private static void AutoFixChassisDef(ChassisDef chassisDef) { if (AutoFixerFeature.settings.ChassisDefInitialTonnage) { SetOriginalInitialTonnage(chassisDef); var tonnage = chassisDef.Tonnage * AutoFixerFeature.settings.ChassisDefInitialToTotalTonnageFactor; var info = typeof(ChassisDef).GetProperty("InitialTonnage"); var value = Convert.ChangeType(tonnage, info.PropertyType); info.SetValue(chassisDef, value, null); Control.mod.Logger.LogDebug($"set InitialTonnage={tonnage}"); } if (AutoFixerFeature.settings.ChassisDefMaxJumpjets) { var coreDef = new EngineCoreDef { Rating = AutoFixerFeature.settings.ChassisDefMaxJumpjetsRating }; var maxCount = Mathf.Min( AutoFixerFeature.settings.ChassisDefMaxJumpjetsCount, coreDef.GetMovement(chassisDef.Tonnage).JumpJetCount ); var info = typeof(ChassisDef).GetProperty("MaxJumpjets"); var value = Convert.ChangeType(maxCount, info.PropertyType); info.SetValue(chassisDef, value, null); Control.mod.Logger.LogDebug($"set MaxJumpjets={maxCount}"); } }
public static int GetEngineModifier(MechDef mechDef) { int engineMod = 0; // var mainEngineComponent = actor?.allComponents?.FirstOrDefault(c => c?.componentDef?.GetComponent<EngineCoreDef>() != null); MechComponentRef engineRef = mechDef.Inventory.FirstOrDefault(mcr => mcr?.GetComponent <EngineCoreDef>() != null); Mod.Log.Debug($"MechDef:{mechDef.Name} has engineComponent:{engineRef}?"); if (engineRef != null) { EngineCoreDef engine = engineRef.Def.GetComponent <EngineCoreDef>(); float tonnage = mechDef.Chassis.Tonnage; engineMod = CalculateEngineModifier(tonnage, engine.Rating); } return(engineMod); }