public static void Prefix(MechDef __instance) { try { var adapter = new MechDefAdapter(__instance); if (adapter.Chassis?.HardpointDataDef == null) { return; } var componentRefs = adapter.Inventory .Where(c => c != null).Select(c => { if (c.DataManager == null) { c.DataManager = adapter.DataManager; } c.RefreshComponentDef(); return(c); }) .Where(c => !c.hasPrefabName) .ToList(); MechHardpointRulesGetComponentPrefabNamePatch.SetupCalculator(adapter.Chassis, componentRefs); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
private static void UndoArmorStructureChanges(Mech mech, MechDef mechDef) { var armorFactor = Mech_get_ArmorMultiplier_Patch.GetFactorForMech(mech); var structureFactor = Mech_get_StructureMultiplier_Patch.GetFactorForMech(mech); var adapter = new MechDefAdapter(mechDef); foreach (var mechLocationDef in adapter.Locations) { if (mechLocationDef.CurrentInternalStructure > 0) { mechLocationDef.CurrentInternalStructure /= structureFactor; var chassisLocationDef = mechDef.Chassis.GetLocationDef(mechLocationDef.Location); if (Mathf.Approximately(mechLocationDef.CurrentInternalStructure, chassisLocationDef.InternalStructure)) { mechLocationDef.CurrentInternalStructure = chassisLocationDef.InternalStructure; } } if (mechLocationDef.CurrentArmor > 0) { mechLocationDef.CurrentArmor /= armorFactor; if (Mathf.Approximately(mechLocationDef.CurrentArmor, mechLocationDef.AssignedArmor)) { mechLocationDef.CurrentArmor = mechLocationDef.AssignedArmor; } } if (mechLocationDef.CurrentRearArmor > 0) { mechLocationDef.CurrentRearArmor /= armorFactor; if (Mathf.Approximately(mechLocationDef.CurrentRearArmor, mechLocationDef.AssignedRearArmor)) { mechLocationDef.CurrentRearArmor = mechLocationDef.AssignedRearArmor; } } } }