public static void Prefix(ChassisDef __instance)
        {
            try
            {
                if (!Control.settings.HardpointFix.AutoFixChassisDefWeaponHardpointCounts)
                {
                    return;
                }

                if (ChassisDef_RefreshHardpointData_Patch.ChassisDefLocationsLocationsCache.TryGetValue(__instance.Description.Id, out var locations))
                {
                    var adapter = new ChassisDefAdapter(__instance);
                    adapter.Locations = locations;
                }
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
Esempio n. 2
0
        private static void AutoFixSlots(ChassisDef chassisDef)
        {
            var changes = AutoFixerFeature.settings.ChassisDefSlotsChanges;

            if (changes == null)
            {
                return;
            }

            var adapter   = new ChassisDefAdapter(chassisDef);
            var locations = adapter.Locations;

            for (var i = 0; i < locations.Length; i++)
            {
                var location = locations[i].Location;
                foreach (var change in changes.Where(x => x.Location == location).Select(x => x.Change))
                {
                    ModifyInventorySlots(ref locations[i], location, change);
                }
            }

            adapter.refreshLocationReferences();
        }
Esempio n. 3
0
        public static void Postfix(ChassisDef __instance)
        {
            try
            {
                if (!Control.settings.HardpointFix.AutoFixChassisDefWeaponHardpointCounts)
                {
                    return;
                }

                var hardpointDataDef = __instance.HardpointDataDef;
                if (hardpointDataDef == null)
                {
                    return;
                }

                if (ChassisDefLocationsLocationsCache.ContainsKey(__instance.Description.Id))
                {
                    return;
                }

                var hardpointCounts = new Dictionary <ChassisLocations, HardpointCounter>();
                foreach (var hardpointData in hardpointDataDef.HardpointData)
                {
                    var location = VHLUtils.GetLocationByString(hardpointData.location);
                    var counter  = new HardpointCounter(hardpointData.weapons);
                    hardpointCounts[location] = counter;
                }

                var adapter             = new ChassisDefAdapter(__instance);
                var chassisLocationDefs = adapter.Locations;
                for (var i = 0; i < chassisLocationDefs.Length; i++)
                {
                    var            locationDef = chassisLocationDefs[i];
                    HardpointDef[] hardpointDefs;
                    if (hardpointCounts.ContainsKey(locationDef.Location))
                    {
                        var counter = hardpointCounts[locationDef.Location];
                        hardpointDefs = counter.HardpointsDefs;
                    }
                    else
                    {
                        hardpointDefs = new HardpointDef[0];
                    }

                    chassisLocationDefs[i] = new LocationDef(
                        hardpointDefs,
                        locationDef.Location,
                        locationDef.Tonnage,
                        locationDef.InventorySlots,
                        locationDef.MaxArmor,
                        locationDef.MaxRearArmor,
                        locationDef.InternalStructure
                        );
                }

                ChassisDefLocationsLocationsCache[__instance.Description.Id] = chassisLocationDefs;

                adapter.refreshLocationReferences();
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }