Example #1
0
        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}");
        }
Example #2
0
        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);
        }
 public static void Prefix(SimGameDifficulty __instance, bool force, SimGameState ___simState, SimGameDifficulty.DifficultySetting setting, int index,
                           Dictionary <string, int> ___difficultyIndices,
                           ref List <SimGameDifficulty.DifficultyConstantValue> __state)
 {
     __state = null;
     if (setting == null)
     {
         return;
     }
     if (!force && ___difficultyIndices[setting.ID] == index)
     {
         return;
     }
     if (index >= setting.Options.Count)
     {
         return;
     }
     if (!setting.Enabled)
     {
         return;
     }
     try
     {
         SimGameDifficulty.DifficultyOption opt = setting.Options[index];
         if (opt.DifficultyConstants != null)
         {
             __state = opt.DifficultyConstants;
             foreach (SimGameDifficulty.DifficultyConstantValue v in opt.DifficultyConstants)
             {
                 if (v.ConstantType.Equals("AdditionalSettings"))
                 {
                     DifficultyOptionsMain.ApplySettings(___simState, setting.ID, v.ConstantName, v.ConstantValue);
                 }
             }
             opt.DifficultyConstants = opt.DifficultyConstants.Where((x) => !x.ConstantType.Equals("AdditionalSettings")).ToList();
         }
     }
     catch (Exception e)
     {
         FileLog.Log(e.ToString());
     }
 }
        static void Postfix(SimGameState __instance, GameInstance game, SimGameDifficulty difficulty)
        {
            DataManager dm          = UnityGameInstance.BattleTechGame.DataManager;
            LoadRequest loadRequest = dm.CreateLoadRequest();

            // Need to load each unique icon
            Mod.Log.Info?.Write("-- Loading HUD icons");

            loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_Aerospace, null);
            loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_MechTech, null);
            loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_MedTech, null);
            loadRequest.AddLoadRequest <SVGAsset>(BattleTechResourceType.SVGAsset, Mod.Config.Icons.CrewPortrait_Vehicle, null);

            loadRequest.ProcessRequests();
            Mod.Log.Info?.Write("--  Done!");

            // Reinitialize state
            ModState.Reset();
            ModState.SimGameState = __instance;
        }
        static bool Prefix(SimGameDifficultySettingsModule __instance, SimGameDifficulty ___cachedDiff,
                           PreGameCareerModeSettingsTotalScoreDescAndBar ___difficultyBarAndMod)
        {
            float num    = __instance.CalculateRawScoreMod();
            bool  active = __instance.ShouldShowDifficultyData();

            ___difficultyBarAndMod.gameObject.SetActive(active);
            ___difficultyBarAndMod.RefreshInfo(num);

            if (__instance.CanModifyStartSettings)
            {
                var atlasSkull      = GameObject.Find("atlasSkull-image");
                var atlasImage      = atlasSkull.gameObject.GetComponent <Image>();
                var currentModifier = Mathf.Abs(Mathf.Max(0, num) - ModState.MaxDiffModifier);
                var scaledModifier  = Mathf.FloorToInt(currentModifier * 255 / ModState.MaxDiffModifier);
                Mod.Log.Info?.Write($"COLOR SCORE MOD THING: real score {num} vs current {currentModifier} vs scaled {scaledModifier}");
                Mod.Log.Info?.Write($"From UPDATEDIFFICULTYSCOREBAR: Atlas values: {atlasImage.color.r}, {atlasImage.color.g}, {atlasImage.color.b}, {atlasImage.color.a}");
                atlasImage.color = new Color32(255, (byte)scaledModifier, (byte)scaledModifier, 255);;
            }

            return(false);
        }
        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);
        }
 static void Postfix(SimGameState __instance, GameInstance game, SimGameDifficulty difficulty)
 {
     ModState.OnSimInit();
 }