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();
                MechHardpointRules_GetComponentPrefabName_Patch.SetupCalculator(adapter.Chassis, componentRefs);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
Esempio n. 2
0
        private static void UndoArmorStructureChanges(Mech mech, MechDef mechDef)
        {
            var armorFactor     = ArmorStructureChangesFeature.GetArmorFactorForMech(mech);
            var structureFactor = ArmorStructureChangesFeature.GetStructureFactorForMech(mech);

            var adapter = new MechDefAdapter(mechDef);

            foreach (var mechLocationDef in adapter.Locations)
            {
                var chassisLocationDef = mechDef.Chassis.GetLocationDef(mechLocationDef.Location);

                mechLocationDef.CurrentInternalStructure = ReverseFactor(structureFactor, mechLocationDef.CurrentInternalStructure, chassisLocationDef.InternalStructure);
                mechLocationDef.CurrentArmor             = ReverseFactor(armorFactor, mechLocationDef.CurrentArmor, mechLocationDef.AssignedArmor);
                mechLocationDef.CurrentRearArmor         = ReverseFactor(armorFactor, mechLocationDef.CurrentRearArmor, mechLocationDef.AssignedRearArmor);
            }
        }