コード例 #1
0
        public static void Postfix(MechBayMechInfoWidget __instance, MechDef ___selectedMech,
                                   GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, HBSTooltip ___initiativeTooltip)
        {
            if (___initiativeObj == null || ___initiativeText == null)
            {
                return;
            }

            //SkillBasedInit.Logger.Log($"MechBayMechInfoWidget::SetInitiative::post - disabling text");
            if (___selectedMech == null)
            {
                ___initiativeObj.SetActive(true);
                ___initiativeText.SetText("-");
            }
            else
            {
                List <string> details = new List <string>();

                // Static initiative from tonnage
                float tonnage    = ___selectedMech.Chassis.Tonnage;
                int   tonnageMod = UnitHelper.GetTonnageModifier(tonnage);
                details.Add($"Tonnage Base: {tonnageMod}");

                // Any modifiers that come from the chassis/mech/vehicle defs
                int componentsMod = UnitHelper.GetNormalizedComponentModifier(___selectedMech);
                if (componentsMod > 0)
                {
                    details.Add($"<space=2em><color=#00FF00>{componentsMod:+0} components</color>");
                }
                else if (componentsMod < 0)
                {
                    details.Add($"<space=2em><color=#FF0000>{componentsMod:0} components </color>");
                }

                // Modifier from the engine
                int engineMod = UnitHelper.GetEngineModifier(___selectedMech);
                if (engineMod > 0)
                {
                    details.Add($"<space=2em><color=#00FF00>{engineMod:+0} engine</color>");
                }
                else if (engineMod < 0)
                {
                    details.Add($"<space=2em><color=#FF0000>{engineMod:0} engine</color>");
                }

                // --- Badge ---
                ___initiativeObj.SetActive(true);
                ___initiativeText.SetText($"{tonnageMod + componentsMod + engineMod}");

                // --- Tooltip ---
                int maxInit = Math.Max(tonnageMod + componentsMod + engineMod, Mod.MinPhase);
                details.Add($"Expected Phase: <b>{maxInit}</b> ");

                string             tooltipTitle   = $"{___selectedMech.Name}";
                string             tooltipText    = String.Join("\n", details.ToArray());
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
        }
コード例 #2
0
 public static void Postfix(MechBayMechInfoWidget __instance, MechDef ___selectedMech, HBS_InputField ___mechNameInput)
 {
     if (__instance != null && MechNamesHelper.HasUiName(___selectedMech))
     {
         ___mechNameInput.SetText(___selectedMech.Description.UIName);
     }
 }
コード例 #3
0
 static void Postfix(MechBayMechInfoWidget __instance)
 {
     ModBase.Sim = __instance.sim;
     if (ModBase.combatConstants == null)
     {
         ModBase.combatConstants = CombatGameConstants.CreateFromSaved(UnityGameInstance.BattleTechGame);
     }
 }
コード例 #4
0
ファイル: StockMech.cs プロジェクト: mad2342/LittleThings
        // This method duplicates functionality of MechLabStockInfoPopup.StockMechDefLoaded
        static void OverrideStockMechDefLoaded(this MechLabStockInfoPopup __instance, string id, MechDef def)
        {
            Logger.Debug("[MechLabStockInfoPopup.OverrideStockMechDefLoaded] called.");

            MechDef ___stockMechDef = Traverse.Create(__instance).Field("stockMechDef").GetValue <MechDef>();
            MechBayMechInfoWidget ___mechInfoWidget  = Traverse.Create(__instance).Field("mechInfoWidget").GetValue <MechBayMechInfoWidget>();
            DataManager           ___dataManager     = Traverse.Create(__instance).Field("dataManager").GetValue <DataManager>();
            LocalizableText       ___descriptionText = Traverse.Create(__instance).Field("descriptionText").GetValue <LocalizableText>();

            ___stockMechDef = def;
            ___mechInfoWidget.SetData(___stockMechDef, ___dataManager);
            ___descriptionText.SetText(___stockMechDef.Description.Details, Array.Empty <object>());
        }
コード例 #5
0
        // pass in a bunch of ___ variables so we can get access to private members of MechBayMechInfoObject.
        // And we'll return false so that the original function doesn't get called.
        public static bool Prefix(MechBayMechInfoWidget __instance, MechDef ___selectedMech,
                                  GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, HBSTooltip ___initiativeTooltip)
        {
            if (___initiativeObj == null || ___initiativeText == null)
            {
                return(false);
            }
            if (___selectedMech == null)
            {
                ___initiativeObj.SetActive(false);
                return(false);
            }

            ___initiativeObj.SetActive(true);
            int num = 1;             // default to assault phase

            float f_walkSpeed = ___selectedMech.Chassis.MovementCapDef.MaxWalkDistance;

            if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseSpecialMinSpeed)
            {
                num = 5;                  //special phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseLightMinSpeed)
            {
                num = 4;                  //light phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseMediumMinSpeed)
            {
                num = 3;                  //medium phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseHeavyMinSpeed)
            {
                num = 2;                  //heavy phase
            }

            ___initiativeText.SetText($"{num}");
            if (___initiativeTooltip != null)
            {
                // build the tooltip.  Going to use the mech's name and tell where its speed puts it, initiative-wise.
                string             tooltipTitle   = $"{___selectedMech.Name}";
                string             tooltipText    = "A max walking speed of " + $"{f_walkSpeed}" + "m per turn means this mech moves in initiative phase " + $"{num}" + ".";
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
            return(false);
        }
        public static bool SetHardpoints(MechBayMechInfoWidget __instance, LocalizableText ___jumpjetHardpointText,
                                         LocalizableText ___ballisticHardpointText, MechDef ___selectedMech)
        {
            try
            {
                var hardpoints = __instance.GetComponent <UIModuleHPHandler>();
                if (hardpoints == null)
                {
                    hardpoints = __instance.gameObject.AddComponent <UIModuleHPHandler>();
                    hardpoints.Init(__instance, ___ballisticHardpointText.gameObject,
                                    ___jumpjetHardpointText.gameObject, new Vector2(-5, -58));
                }

                var usage = ___selectedMech.GetHardpointUsage();
                hardpoints.SetData(usage);
                hardpoints.SetJJ(___selectedMech.GetJJCountByMechDef(), ___selectedMech.GetJJMaxByMechDef());
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
            return(false);
        }
コード例 #7
0
 static void Postfix(MechBayMechInfoWidget __instance)
 {
     ModBase.Sim         = __instance.sim;
     ModBase.mechBay     = (MechBayPanel)ReflectionHelper.GetPrivateField(__instance, "mechBay");
     ModBase.currentMech = (MechDef)ReflectionHelper.GetPrivateField(__instance, "selectedMech");
 }
コード例 #8
0
        public static void Postfix(MechBayMechInfoWidget __instance, MechDef ___selectedMech,
                                   GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, HBSTooltip ___initiativeTooltip)
        {
            Mod.Log.Trace?.Write("MBMIW:SI:post - entered.");

            if (___initiativeObj == null || ___initiativeText == null)
            {
                return;
            }

            if (___selectedMech == null)
            {
                ___initiativeObj.SetActive(true);
                ___initiativeText.SetText("-");
            }
            else
            {
                List <string> details = new List <string>();

                // Static initiative from tonnage

                int initPhase    = PhaseHelper.TonnageToPhase((int)Math.Ceiling(___selectedMech.Chassis.Tonnage));
                int initLabelVal = (Mod.MaxPhase + 1) - initPhase;
                details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_BASE], new object[] { initLabelVal }).ToString());

                // Any bonuses from equipment
                int    componentBonus = UnitHelper.GetNormalizedComponentModifier(___selectedMech);
                string componentColor = "FFFFFF";
                if (componentBonus > 0)
                {
                    componentColor = "00FF00";
                }
                if (componentBonus < 0)
                {
                    componentColor = "FF0000";
                }
                details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENT], new object[] { componentColor, componentBonus }).ToString());
                Mod.Log.Debug?.Write($"Component bonus is: {componentBonus}");

                // No Lance bonus
                // No Pilot bonus

                // --- Badge ---
                int summaryInitLabel = initLabelVal + componentBonus;
                if (summaryInitLabel > Mod.MaxPhase)
                {
                    summaryInitLabel = Mod.MaxPhase;
                }
                else if (summaryInitLabel < Mod.MinPhase)
                {
                    summaryInitLabel = Mod.MinPhase;
                }

                ___initiativeObj.SetActive(true);
                ___initiativeText.SetText($"{summaryInitLabel}");

                // --- Tooltip ---
                string             tooltipTitle   = $"{___selectedMech.Name}";
                string             detailsS       = String.Join("\n", details.ToArray());
                string             tooltipText    = new Text(Mod.Config.LocalizedText[ModConfig.LT_MB_TT_SUMMARY], new object[] { detailsS, summaryInitLabel }).ToString();
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
        }