public static void SimGameState__OnDefsLoadComplete_Postfix(SimGameState __instance) { if (UnitAppearanceDateMorphFeature.AppearanceDatesAdjusted == true) { Logger.Debug($"Appearance dates have already been adjusted."); return; } if (Myself.Settings.SetAppearanceDatesForMechsLackingSuch) { Logger.Debug($"Setting appearance dates for mechs lacking..."); var mechAppearanceData = CoreMod.CoreModSingleton.MechAppearanceData; var mechsSansAppearanceDates = __instance.DataManager.MechDefs .Where(pair => !pair.Value.MinAppearanceDate.HasValue) .Select(pair => pair.Value); mechsSansAppearanceDates //.AsParallel() //.ForAll .ToList() .ForEach (mechDef => { Logger.Trace($"Mech [{mechDef.Description.UIName}] lacks an appearance date, attempting to set it..."); var mechModelEntry = mechAppearanceData.FirstOrDefault(model => model.Name.Trim('"') == mechDef.Description.UIName); DateTime?appearanceDate = null; if (mechModelEntry != null) { appearanceDate = new DateTime(mechModelEntry.Year, 1, 1); } appearanceDate = mechDef.MinAppearanceDate ?? appearanceDate; Logger.Trace($"Setting appearance date for [{mechDef.Description.UIName}] to [{appearanceDate}]."); var traverse = Traverse.Create(mechDef).Property("MinAppearanceDate"); traverse.SetValue(appearanceDate); }); } Logger.Debug("Dynamically adjusting appearance dates..."); var appearanceFactor = AppearanceUtils.CalculateAppearanceDateFactor(__instance.GetCampaignStartDate(), Myself.Settings.CompressionFactorControlDate, Myself.Settings.CompressionFactorTargetDate, Logger); __instance.DataManager.MechDefs .Where(pair => pair.Value.MinAppearanceDate.HasValue) .Select(pair => pair.Value) .ToList() .ForEach //.AsParallel() //.ForAll (mechDef => { Logger.Trace($"Calculating new appearance date for [{mechDef.Description.Id}]..."); var appearanceDate = mechDef.MinAppearanceDate; var newAppearanceDate = AppearanceUtils.CalculateCompressedAppearanceDate(__instance.GetCampaignStartDate(), appearanceDate.Value, appearanceFactor, Logger); Logger.Trace($"Setting appearance date for [{mechDef.Description.Id}] to [{newAppearanceDate}] from [{appearanceDate}]..."); // mechDef.MinAppearanceDate = newAppearanceDate; var traverse = Traverse.Create(mechDef).Property("MinAppearanceDate"); traverse.SetValue(newAppearanceDate); }); UnitAppearanceDateMorphFeature.AppearanceDatesAdjusted = true; }