Exemplo n.º 1
0
        public static void SetColor(MechBayChassisUnitElement __instance, Image ___mechImage, TextMeshProUGUI ___partsText, TextMeshProUGUI ___partsLabelText,
                                    ChassisDef chassisDef, DataManager dataManager, int partsCount, int partsMax, int chassisQuantity)
        {
            try
            {
                if (partsCount != 0)
                {
                    ___partsLabelText.SetText("Parts");
                    ___partsText.SetText($"{partsCount} / {partsMax}");

                    if (partsCount >= partsMax)
                    {
                        ___mechImage.color = Control.Settings.color_ready;
                    }
                    else
                    {
                        int min  = ChassisHandler.GetInfo(chassisDef.Description.Id).MinParts;
                        var list = ChassisHandler.GetCompatible(chassisDef.Description.Id);
                        if (list == null)
                        {
                            ___mechImage.color = Control.Settings.color_exclude;
                        }
                        else if (list.Sum(i => ChassisHandler.GetCount(i.Description.Id)) >= partsMax && chassisDef.MechPartCount >= min)
                        {
                            ___mechImage.color = Control.Settings.color_variant;
                        }
                        else
                        {
                            ___mechImage.color = Control.Settings.color_notready;
                        }
                    }
                }
                else
                {
                    ___mechImage.color = Control.Settings.color_stored;
                }

                var go = __instance.transform.Find("Representation/contents/storage_OverlayBars");

                var mech = ChassisHandler.GetMech(chassisDef.Description.Id);

                if (Control.Settings.BGColors != null && Control.Settings.BGColors.Length > 0)
                {
                    foreach (var color in Control.Settings.BGColors)
                    {
                        if (mech.MechTags.Contains(color.Tag))
                        {
                            var tracker = go.GetComponent <UIColorRefTracker>();
                            tracker.SetUIColor(UIColor.Custom);
                            tracker.OverrideWithColor(color.color);
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Control.LogDebug("Error while get mechdef for " + chassisDef.Description.Id);
            }
        }
 public static void ModifyOptions(SimGameEventDef evt, SGEventPanel __instance,
                                  TextMeshProUGUI ___eventDescription,
                                  DataManager ___dm, RectTransform ___optionParent, List <SGEventOption> ___optionsList)
 {
     try
     {
         Control.LogDebug("Started Event: " + evt.Description.Id);
         if (evt.Description.Id != "CustomSalvageAssemblyEvent")
         {
             return;
         }
         ChassisHandler.MakeOptions(___eventDescription, __instance, ___dm, ___optionParent, ___optionsList);
     }
     catch (Exception e)
     {
         Control.LogError("ModifyOptions error", e);
     }
 }
        private static void SplitToParts(ChassisDef chassisDef, int min, int max, MechBayPanel mechBay)
        {
            int k = mechBay.Sim.NetworkRandom.Int(min, max + 1);

            UnityGameInstance.BattleTechGame.Simulation.ScrapInactiveMech(chassisDef.Description.Id, false);
            var mech = ChassisHandler.GetMech(chassisDef.Description.Id);

            for (int i = 0; i < k; i++)
            {
                mechBay.Sim.AddMechPart(mech.Description.Id);
            }
            mechBay.RefreshData(false);
            mechBay.SelectChassis(null);

            GenericPopupBuilder.Create($"Scraped {mech.Description.UIName}.",
                                       $"We manage to get <color=#20ff20>{k}</color> parts from {mech.Description.UIName} chassis")
            .AddButton("Ok", null, true, null)
            .CancelOnEscape().AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
        }
        public static bool OnReadyClicked(ChassisDef ___selectedChassis, MechBayPanel ___mechBay
                                          , MechBayChassisUnitElement ___chassisElement, MechBayChassisInfoWidget __instance)
        {
            if (___selectedChassis == null)
            {
                return(false);
            }

            var mech = ChassisHandler.GetMech(___selectedChassis.Description.Id);
            var name = new Text(mech.Description.UIName).ToString();

            if (___selectedChassis.MechPartMax == 0)
            {
                int value = Mathf.RoundToInt((float)___selectedChassis.Description.Cost *
                                             ___mechBay.Sim.Constants.Finances.MechScrapModifier);

                if (Control.Settings.AllowScrapToParts)
                {
                    int max = ___mechBay.Sim.Constants.Story.DefaultMechPartMax;
                    int n1  = Mathf.Clamp(Mathf.RoundToInt(max * Control.Settings.MinScrapParts), 1, max);
                    int n2  = Mathf.Clamp(Mathf.RoundToInt(max * Control.Settings.MaxScrapParts), 1, max);


                    GenericPopupBuilder.Create($"Scrap {name}?",
                                               $"Do you want scrap this chassis and sale spare parts for <color=#F79B26FF>{SimGameState.GetCBillString(value)}</color> or scrap and keep parts ({n1}-{n2} parts)")
                    .AddButton("Cancel", null, true, null)
                    .AddButton("Keep Parts", () => SplitToParts(___selectedChassis, n1, n2, ___mechBay), true, null)
                    .AddButton("Sale", () => ScrapChassis(1, ___selectedChassis, __instance, ___mechBay), true,
                               null)
                    .CancelOnEscape()
                    .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true)
                    .Render();
                }
                else
                {
                    GenericPopupBuilder.Create($"Scrap {name}?",
                                               $"Are you sure you want to scrap this 'Mech Chassis? It will be removed permanently from your inventory.\n\nSCRAP VALUE: < color =#F79B26FF>{SimGameState.GetCBillString(value)}</color>")
                    .AddButton("Cancel", null, true, null)
                    .AddButton("scrap", () => ScrapChassis(1, ___selectedChassis, __instance, ___mechBay), true,
                               null)
                    .CancelOnEscape()
                    .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true)
                    .Render();
                }
            }
            else
            {
                int num   = ___selectedChassis.MechPartCount;
                int value = Mathf.RoundToInt((float)___selectedChassis.Description.Cost * ___mechBay.Sim.Constants.Finances.MechScrapModifier) / ___selectedChassis.MechPartMax;

                if (num == 1)
                {
                    GenericPopupBuilder.Create($"Scrap {name} part?",
                                               $"Are you sure you want to scrap this 'Mech part? It will be removed permanently from your inventory.\n\nSCRAP VALUE: <color=#F79B26FF>{SimGameState.GetCBillString(value)}</color>")
                    .AddButton("Cancel", null, true, null)
                    .AddButton("Scrap", () => ScrapParts(1, ___selectedChassis, __instance, ___mechBay), true, null)

                    .CancelOnEscape().AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                }
                else
                {
                    var popup = LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>(string.Empty);

                    var shopdef = new ShopDefItem(mech.Description.Id, ShopItemType.MechPart, 1, num, true, false, value);
                    popup.SetData(___mechBay.Sim, shopdef, name + " parts", num, value, (n) => ScrapParts(n, ___selectedChassis, __instance, ___mechBay));
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public static bool OnReadyClicked(ChassisDef ___selectedChassis, MechBayPanel ___mechBay
                                          , MechBayChassisUnitElement ___chassisElement, MechBayChassisInfoWidget __instance)
        {
            if (!Control.Settings.AssemblyVariants)
            {
                return(true);
            }

            if (___selectedChassis == null)
            {
                return(false);
            }

            if (___mechBay.Sim.GetFirstFreeMechBay() < 0)
            {
                GenericPopupBuilder.Create("Cannot Ready 'Mech", "There are no available slots in the 'Mech Bay. You must move an active 'Mech into storage before readying this chassis.").AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                return(false);
            }

            ChassisHandler.PreparePopup(___selectedChassis, ___mechBay, __instance, ___chassisElement);

            if (___selectedChassis.MechPartCount == 0)
            {
                int num2 = Mathf.CeilToInt((float)___mechBay.Sim.Constants.Story.MechReadyTime /
                                           (float)___mechBay.Sim.MechTechSkill);

                GenericPopupBuilder.Create("Ready 'Mech?",
                                           $"It will take {num2} day(s) to ready this BattleMech chassis for combat.")
                .AddButton("Cancel", null, true, null)
                .AddButton("Ready", ChassisHandler.OnChassisReady, true, null)
                .AddFader(
                    new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants
                                    .PopupBackfill), 0f, true)
                .CancelOnEscape()
                .Render();
                return(false);
            }

            if (___selectedChassis.MechPartCount >= ___selectedChassis.MechPartMax)
            {
                GenericPopupBuilder.Create("Assembly 'Mech?",
                                           $"It will take {___selectedChassis.MechPartMax} parts from storage.")
                .AddButton("Cancel", null, true, null)
                .AddButton("Ready", ChassisHandler.OnPartsAssembly, true, null)
                .AddFader(
                    new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants
                                    .PopupBackfill), 0f, true)
                .CancelOnEscape()
                .Render();
                return(false);
            }

            if (!Control.Settings.AssemblyVariants)
            {
                return(true);
            }


            ChassisHandler.StartDialog();

            return(false);
        }
Exemplo n.º 6
0
        public static void AddVariantsToDescriptions(
            MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis,
            TextMeshProUGUI ___mechDetails, HBSTooltip ___chassisStorageTooltip,
            GameObject ___readyBtnObj, GameObject ___partsCountObj, TextMeshProUGUI ___partsCountText)
        {
            if (___selectedChassis == null)
            {
                return;
            }

            if (!Control.Settings.AssemblyVariants)
            {
                return;
            }


            var list = ChassisHandler.GetCompatible(___selectedChassis.Description.Id);

            if (___selectedChassis.MechPartCount != 0)
            {
                int min = ChassisHandler.GetInfo(___selectedChassis.Description.Id).MinParts;

                if (___selectedChassis.MechPartCount >= ___selectedChassis.MechPartMax)
                {
                    ___readyBtnObj.SetActive(true);
                    ___partsCountObj.SetActive(false);
                    ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Enough parts to assemble: Press Ready to move to a Bay"));
                }
                else
                {
                    if (list == null || ___selectedChassis.MechPartCount < min || list.Sum(i => ChassisHandler.GetCount(i.Description.Id)) < ___selectedChassis.MechPartMax)
                    {
                        ___readyBtnObj.SetActive(false);
                        ___partsCountObj.SetActive(true);
                        ___partsCountText.SetText($"{___selectedChassis.MechPartCount} / {___selectedChassis.MechPartMax}");
                        ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject($"Chassis still needs at least {min} base and total {___selectedChassis.MechPartMax} compatible parts to be completed"));
                    }
                    else
                    {
                        ___readyBtnObj.SetActive(true);
                        ___partsCountObj.SetActive(false);
                        ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Chassis can by assembled using other parts: Press Ready to move to a Bay"));
                    }
                }
            }
            else
            {
                ___readyBtnObj.SetActive(true);
                ___partsCountObj.SetActive(false);
                ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Chassis in storage: Press Ready to move to a Bay"));
            }

            string add = "";

            if (list == null)
            {
                add = $"\n<color=#FFFF00>Special mech: cannot be assembled using other variants</color>";
            }
            else if (list.Count > 1)
            {
                add = $"\n<color=#32CD32>Compatible with owned variants:";

                if (list.Count > Control.Settings.MaxVariantsInDescription + 1)
                {
                    int showed = 0;
                    foreach (var mechDef in list)
                    {
                        if (mechDef.ChassisID == ___selectedChassis.Description.Id)
                        {
                            continue;
                        }
                        add    += "\n" + new Text(mechDef.Description.UIName).ToString();
                        showed += 1;
                        if (showed == Control.Settings.MaxVariantsInDescription - 1)
                        {
                            break;
                        }
                    }

                    add += $"\n and {Control.Settings.MaxVariantsInDescription - showed} other variants</color>";
                }
                else
                {
                    foreach (var mechDef in list)
                    {
                        if (mechDef.ChassisID == ___selectedChassis.Description.Id)
                        {
                            continue;
                        }
                        add += "\n" + new Text(mechDef.Description.UIName).ToString();
                    }

                    add += "</color>";
                }
            }

            ___mechDetails.SetText(___mechDetails.text + add);
        }
Exemplo n.º 7
0
        public static bool GetAllChassis(bool showMechParts, ref List <ChassisDef> __result, SimGameState __instance)
        {
            __result = new List <ChassisDef>();
            ChassisHandler.ClearParts();
            List <string> allInventoryStrings = __instance.GetAllInventoryStrings();

            foreach (string text in allInventoryStrings)
            {
                int count = __instance.CompanyStats.GetValue <int>(text);
                if (count >= 1)
                {
                    string[] array = text.Split(new char[]
                    {
                        '.'
                    });
                    if (array[1] != "MECHPART")
                    {
                        BattleTechResourceType battleTechResourceType =
                            (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), array[1]);
                        if (battleTechResourceType == BattleTechResourceType.MechDef)
                        {
                            var cdef = array[2];
                            var mdef = array[2].Replace("chassisdef", "mechdef");

                            if (__instance.DataManager.Exists(BattleTechResourceType.ChassisDef, cdef) &&
                                __instance.DataManager.Exists(BattleTechResourceType.MechDef, mdef))
                            {
                                var mech = __instance.DataManager.MechDefs.Get(mdef);
                                __result.Add(mech.Chassis);
                                ChassisHandler.RegisterMechDef(mech);
                            }
                            else
                            {
                                Control.LogError($"ERROR: {cdef}/{mdef} not found");
                            }
                        }
                    }
                    else
                    {
                        if (__instance.DataManager.Exists(BattleTechResourceType.MechDef, array[2]))
                        {
                            var mdef = __instance.DataManager.MechDefs.Get(array[2]);
                            if (showMechParts)
                            {
                                var chassisDef = new ChassisDef(mdef.Chassis)
                                {
                                    DataManager = __instance.DataManager
                                };
                                chassisDef.Refresh();
                                chassisDef.MechPartCount = count;
                                chassisDef.MechPartMax   = __instance.Constants.Story.DefaultMechPartMax;
                                __result.Add(chassisDef);
                            }
                            ChassisHandler.RegisterMechDef(mdef, count);
                        }
                        else
                        {
                            Control.LogError($"ERROR: {array[2]} not found");
                            if (show)
                            {
                                Control.LogError($"AllMechDefs:");
                                foreach (var pair in __instance.DataManager.MechDefs)
                                {
                                    Control.LogError($"-- {pair.Key}: {(pair.Value == null ? "null" : "exist")}");
                                }

                                show = false;
                            }
                        }
                    }
                }
            }

            //ChassisHandler.ShowInfo();
            return(false);
        }