public static void GetDifficultyModifierRange(SimGameDifficulty difficulty) { var diffSettings = new List <SimGameDifficulty.DifficultySetting>(difficulty.GetSettings()); foreach (var setting in diffSettings) { var ordered = setting.Options.OrderBy(x => x.CareerScoreModifier).ToList(); //Mod.Log.Info?.Write($"Sorted options: {setting.Options.First().Name} is first with {setting.Options.First().CareerScoreModifier}, {setting.Options.Last().Name} is last with {setting.Options.Last().CareerScoreModifier}"); ModState.MinDiffModifier += ordered.First().CareerScoreModifier; ModState.MaxDiffModifier += ordered.Last().CareerScoreModifier; } Mod.Log.Info?.Write($"Min Difficulty Modifier: {ModState.MinDiffModifier}. Final Max Difficulty Modifier: {ModState.MaxDiffModifier}"); }
public static float GetCareerModifier(SimGameDifficulty simGameDifficulty) { float ret = 0.0f; foreach (SimGameDifficulty.DifficultySetting difficultySetting in simGameDifficulty.GetSettings()) { if (difficultySetting.Enabled) { int idx = simGameDifficulty.GetCurSettingIndex(difficultySetting.ID); ret += difficultySetting.Options[idx].CareerScoreModifier; } } PersistentMapClient.Logger.Log($"Unclamped Career Modifier is: {ret}"); ret = Mathf.Clamp(ret, 0.01f, 1.5f); PersistentMapClient.Logger.Log($"Clamped Career Modifier is: {ret}"); return(ret); }
static void Postfix(SimGameDifficultySettingsModule __instance, SimGameDifficulty ___cachedDiff, string ___ironManModeId, string ___autoEquipMechsId, string ___mechPartsReqId, string ___skipPrologueId, string ___randomMechId, string ___argoUpgradeCostId, SGDSToggle ___ironManModeToggle, SGDSDropdown ___mechPartsReqDropdown, GameObject ___disabledOverlay, List <SGDSDropdown> ___activeDropdowns, List <SGDSToggle> ___activeToggles, List <SGDSDropdown> ___cachedDropdowns, List <SGDSToggle> ___cachedToggles, SGDSToggle ___togglePrefab, SGDSDropdown ___dropdownPrefab) { var existingStartOnlyVars = new List <string>() { ___ironManModeId, ___autoEquipMechsId, ___mechPartsReqId, ___skipPrologueId, ___randomMechId, ___argoUpgradeCostId }; ___cachedDiff = UnityGameInstance.BattleTechGame.DifficultySettings; var settings = ___cachedDiff.GetSettings(); settings.Sort(delegate(SimGameDifficulty.DifficultySetting a, SimGameDifficulty.DifficultySetting b) { if (a.UIOrder != b.UIOrder) { return(a.UIOrder.CompareTo(b.UIOrder)); } return(a.Name.CompareTo(b.Name)); }); foreach (var setting in settings) { if (setting.Visible) { int curSettingIndex = ___cachedDiff.GetCurSettingIndex(setting.ID); if (setting.StartOnly && existingStartOnlyVars.All(x => x != setting.ID)) { if (!setting.Toggle) { var sourceSettingDropDownGO = ___mechPartsReqDropdown.gameObject; GameObject newDropDownObject = UnityEngine.Object.Instantiate <GameObject>(sourceSettingDropDownGO, sourceSettingDropDownGO.transform.parent); SGDSDropdown newDropDown = newDropDownObject.GetOrAddComponent <SGDSDropdown>(); var dropdown = Traverse.Create(newDropDown).Field("dropdown").GetValue <HBS_Dropdown>(); var dropdownrect = dropdown.gameObject.GetComponent <RectTransform>(); dropdownrect.sizeDelta = new Vector2(170, 40); var dropdownLabel = Traverse.Create(dropdown).Field("m_CaptionText") .GetValue <LocalizableText>(); dropdownLabel.enableWordWrapping = false; if (!ModState.instantiatedDropdowns.Contains(newDropDown)) { ___activeDropdowns.Add(newDropDown); newDropDown.Initialize(__instance, setting, curSettingIndex); newDropDown.gameObject.SetActive(true); ModState.instantiatedDropdowns.Add(newDropDown); } } else if (setting.Toggle) { var sourceDiffToggleGO = ___ironManModeToggle.gameObject; GameObject sourceDiffToggle = UnityEngine.Object.Instantiate <GameObject>(sourceDiffToggleGO, sourceDiffToggleGO.transform.parent); SGDSToggle newToggle = sourceDiffToggle.GetOrAddComponent <SGDSToggle>(); if (!ModState.instantiatedToggles.Contains(newToggle)) { ___activeToggles.Add(newToggle); newToggle.Initialize(__instance, setting, curSettingIndex); newToggle.gameObject.SetActive(true); ModState.instantiatedToggles.Add(newToggle); } } } } } var newDisabledOverlay = UnityEngine.Object.Instantiate <GameObject>(___disabledOverlay, ___disabledOverlay.transform.parent); ___disabledOverlay.SetActive(false); newDisabledOverlay.SetActive(!__instance.CanModifyStartSettings); __instance.UpdateDifficultyScoreBar(); ModState.HaveDiffSettingsInitiated = true; }
static void Prefix(SimGameDifficultySettingsModule __instance, SimGameDifficulty ___cachedDiff, PreGameCareerModeSettingsTotalScoreDescAndBar ___difficultyBarAndMod) { if (ModState.HaveDiffSettingsInitiated) { return; } ___cachedDiff = UnityGameInstance.BattleTechGame.DifficultySettings; if (ModState.MaxDiffModifier == 0f && ModState.MinDiffModifier == 0f) { Helper.DifficultyHelper.GetDifficultyModifierRange(___cachedDiff); } if (__instance.CanModifyStartSettings) { var atlasSkull = GameObject.Find("atlasSkull-image"); var atlasImage = atlasSkull.gameObject.GetComponent <Image>(); var currentModifier = Mathf.Abs(Mathf.Max(0, __instance.CalculateRawScoreMod()) - ModState.MaxDiffModifier); var scaledModifier = Mathf.FloorToInt(currentModifier * 255 / ModState.MaxDiffModifier); atlasImage.color = new Color32(255, (byte)scaledModifier, (byte)scaledModifier, 255); Mod.Log.Info?.Write($"From INITSETTINGS: Atlas values: {atlasImage.color.r}, {atlasImage.color.g}, {atlasImage.color.b}, {atlasImage.color.a}"); } var settings = ___cachedDiff.GetSettings(); settings.Sort(delegate(SimGameDifficulty.DifficultySetting a, SimGameDifficulty.DifficultySetting b) { if (a.UIOrder != b.UIOrder) { return(a.UIOrder.CompareTo(b.UIOrder)); } return(a.Name.CompareTo(b.Name)); }); var startCount = -5; foreach (var setting in settings) { if (setting.Visible && setting.StartOnly && setting.Enabled) { startCount += 1; } } var startYAdjust = startCount / 2; var regularDiffs = GameObject.Find("difficulty_scroll"); var startOnly = GameObject.Find("OBJ_startOnly_settings"); var startRect = startOnly.GetComponent <RectTransform>(); if (startYAdjust > 0) { if (__instance.CanModifyStartSettings) { var barRect = ___difficultyBarAndMod.gameObject.GetComponent <RectTransform>(); var currentbarPos = barRect.position; currentbarPos.x = 700f; currentbarPos.y = 400f; barRect.position = currentbarPos; } else { var barRect = ___difficultyBarAndMod.gameObject.GetComponent <RectTransform>(); var currentbarPos = barRect.position; currentbarPos.y = 820f; barRect.position = currentbarPos; } var currentStartPosition = startRect.position; currentStartPosition.y += Mod.Config.Misc.DifficultyUIScaling.StartOnlyPositionY; startRect.position = currentStartPosition; var currentStartSizeDelta = startRect.sizeDelta; currentStartSizeDelta.y += startYAdjust * Mod.Config.Misc.DifficultyUIScaling.StartOnlyScalar; startRect.sizeDelta = currentStartSizeDelta; var regularRect = regularDiffs.GetComponent <RectTransform>(); var currentRegSizeDelta = regularRect.sizeDelta; currentRegSizeDelta.y -= startYAdjust - 1 * Mod.Config.Misc.DifficultyUIScaling.StartOnlyScalar; regularRect.sizeDelta = currentRegSizeDelta; var currentRegPosition = regularRect.position; currentRegPosition.y += Mod.Config.Misc.DifficultyUIScaling.RegularPositionY; currentRegPosition.y -= (startYAdjust * Mod.Config.Misc.DifficultyUIScaling.StartOnlyPositionY); regularRect.position = currentRegPosition; } var startTransformLayoutGroup = startOnly.GetComponent <RectTransform>().GetComponent <GridLayoutGroup>(); startTransformLayoutGroup.childAlignment = TextAnchor.UpperCenter; startTransformLayoutGroup.cellSize = new Vector2(375, 40); startTransformLayoutGroup.spacing = new Vector2(25, 10); }