Exemple #1
0
 public SimpleMechAssembly_InterruptManager_AssembleMechEntry(SimGameState s, MechDef d, MechBayPanel refresh)
 {
     type         = SimGameInterruptManager.InterruptType.GenericPopup;
     this.s       = s;
     this.d       = d;
     this.refresh = refresh;
 }
 public static void PreparePopup(ChassisDef chassisDef, MechBayPanel mechbay, MechBayChassisInfoWidget widget, MechBayChassisUnitElement unitElement)
 {
     mechBay = mechbay;
     ChassisHandler.unitElement = unitElement;
     infoWidget = widget;
     chassis    = chassisDef;
     mech       = ChassisToMech[chassis.Description.Id];
 }
 static void Prefix(MechBayPanel __instance)
 {
     Logger.Debug("OnMechLabClosed Patch Installed");
     if (!__instance.IsSimGame)
     {
         return;
     }
     SortMechLabMechs(__instance.Sim.GetMaxActiveMechs(), __instance.Sim.ActiveMechs, __instance.Sim.ReadyingMechs);
 }
Exemple #4
0
            public static void Postfix(MechBayPanel __instance)
            {
                if (!Core.Settings.RepairRearm)
                {
                    return;
                }

                //Logger.LogDebug("OnRepairAllCancelled");
                //if (__instance.selectedMech.MechDef.MechTags.Contains("XLRP_Armor_Repairing"))
                //    __instance.selectedMech.MechDef.MechTags.Remove("XLRP_Armor_Repairing");
            }
Exemple #5
0
 public static void Postfix(MechBayPanel __instance)
 {
     try
     {
         ActiveMechBayPanel = null;
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
 public static void Postfix(MechBayPanel __instance)
 {
     try
     {
         Global.ActiveMechBayPanel = __instance;
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
Exemple #7
0
        public static void UnStorageOmniMechPopup(SimGameState s, MechDef d, MechBayPanel refresh)
        {
            if (Settings.OmniMechTag == null)
            {
                throw new InvalidOperationException("omnimechs disabled");
            }
            int mechbay = s.GetFirstFreeMechBay();

            if (mechbay < 0)
            {
                return;
            }
            List <MechDef> mechs = GetAllOmniVariants(s, d);
            string         desc  = "Yang: We know the following Omni variants. Which should I build?\n\n";

            foreach (MechDef m in mechs)
            {
                if (!CheckOmniKnown(s, d, m))
                {
                    continue;
                }
                int com = GetNumberOfMechsOwnedOfType(s, m);
                desc += string.Format("[[DM.MechDefs[{3}],{0} {1}]] ({2} Complete)\n", m.Chassis.Description.UIName, m.Chassis.VariantName, com, m.Description.Id);
            }
            GenericPopupBuilder pop = GenericPopupBuilder.Create("Ready Mech?", desc);

            pop.AddButton("-", null, true, null);
            foreach (MechDef m in mechs)
            {
                MechDef var = m; // new var to keep it for lambda
                if (!CheckOmniKnown(s, d, m))
                {
                    continue;
                }
                pop.AddButton(string.Format("{0} {1}", var.Chassis.Description.UIName, var.Chassis.VariantName), delegate
                {
                    Log.Log("ready omni as: " + var.Description.Id);
                    s.ScrapInactiveMech(d.Chassis.Description.Id, false);
                    ReadyMech(s, new MechDef(var, s.GenerateSimGameUID(), false), mechbay);
                    if (refresh != null)
                    {
                        refresh.RefreshData(false);
                        refresh.ViewBays();
                    }
                }, true, null);
            }
            pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
            pop.Render();
        }
Exemple #8
0
        public static void QueryMechAssemblyPopup(SimGameState s, MechDef d, MechBayPanel refresh = null, SimpleMechAssembly_InterruptManager_AssembleMechEntry close = null)
        {
            if (GetNumPartsForAssembly(s, d) < s.Constants.Story.DefaultMechPartMax)
            {
                if (close != null)
                {
                    close.NewClose();
                }
                return;
            }
            IEnumerable <MechDef> ownedMechVariantParts = GetAllAssemblyVariants(s, d)
                                                          .Where(m => s.GetItemCount(
                                                                     m.Description.Id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY) > 0 || CheckOmniKnown(s, d, m));

            int    selectedMechParts    = s.GetItemCount(d.Description.Id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY);
            int    numberOfChassisOwned = GetNumberOfMechsOwnedOfType(s, d);
            string desc = $"Yang: {d.Chassis.YangsThoughts}\n\n";

            IEnumerable <string> additionalVariants = ownedMechVariantParts
                                                      .Where(m => m.Description.Id != d.Description.Id)
                                                      .Select(m =>
            {
                int count = s.GetItemCount(m.Description.Id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY);
                int com   = GetNumberOfMechsOwnedOfType(s, m);
                return($"[[DM.MechDefs[{m.Description.Id}], {m.Chassis.VariantName}]] ({count} Parts/{com} Complete)");
            });

            string selectedMechDisplayTitle = $"[[DM.MechDefs[{d.Description.Id}],{d.Chassis.VariantName}]] ({selectedMechParts} Parts/{numberOfChassisOwned} Complete)";

            if (additionalVariants.Count() > 1)
            {
                desc += $"We can build the {selectedMechDisplayTitle}, " +
                        $"or one of these other variants of the {d.Chassis.Description.UIName}:\n\n";
                desc += string.Join("\n", additionalVariants);
                VariantPopup(desc, s, ownedMechVariantParts, refresh, close);
            }
            else if (additionalVariants.Count() == 1)
            {
                desc += $"We can build the {selectedMechDisplayTitle}, or the\n" +
                        $"{string.Join("", additionalVariants)} variant of the {d.Chassis.Description.UIName}.";
                VariantPopup(desc, s, ownedMechVariantParts, refresh, close);
            }
            else
            {
                desc += $"Should I build the {selectedMechDisplayTitle}?";
                VariantPopup(desc, s, new[] { d }, refresh, close);
            }
        }
Exemple #9
0
        public static void Prefix(MechBayPanel __instance, MechDef selectedMech)
        {
            try
            {
                if (!__instance.IsSimGame)
                {
                    return;
                }

                EnginePersistence.FixSimGameUID(__instance.Sim, selectedMech);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(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 void Prefix(MechBayPanel __instance, MechBayMechUnitElement mechElement)
        {
            try
            {
                if (!__instance.IsSimGame)
                {
                    return;
                }

                if (mechElement == null || mechElement.MechDef == null)
                {
                    return;
                }

                EnginePersistence.FixSimGameUID(__instance.Sim, mechElement.MechDef);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
        static void Prefix(MechBayChassisUnitElement chassisElement, MechBayPanel __instance)
        {
            Logger.Debug("we readying!");
            var chassisDef = chassisElement.ChassisDef;
            var itemCount  = chassisDef.MechPartCount;

            if (itemCount > 0)
            {
                int defaultMechPartMax = this.Constants.Story.DefaultMechPartMax;
                if (itemCount + 1 >= defaultMechPartMax)
                {
                    for (int index = 0; index < defaultMechPartMax - 1; ++index)
                    {
                        this.RemoveItemStat(id, "MECHPART", false);
                    }
                    MechDef mechDef = new MechDef(this.DataManager.MechDefs.Get(id), this.GenerateSimGameUID(), this.Constants.Salvage.EquipMechOnSalvage);
                    this.AddMech(0, mechDef, true, false, true, (string)null);
                    this.interruptQueue.DisplayIfAvailable();
                    this.MessageCenter.PublishMessage((MessageCenterMessage) new SimGameMechAddedMessage(mechDef, true));
                }
                Logger.Debug("hey this is where we put our code to do the buildout");
            }
        }
Exemple #13
0
        public static void ScrapChassis(List <ChassisCount> filteredChassis)
        {
            MechBayPanel mechBayPanel = LazySingletonBehavior <UIManager> .Instance.GetOrCreateUIModule <MechBayPanel>();

            foreach (ChassisCount item in filteredChassis)
            {
                Mod.Log.Debug?.Write($"Scrapping chassis: {item.ChassisDef.Description.Name}");
                for (int i = 0; i < item.ChassisQty; i++)
                {
                    mechBayPanel.Sim.ScrapInactiveMech(item.ChassisDef.Description.Id, pay: true);
                    Mod.Log.Debug?.Write($"  -- scrapped one full mech");
                }

                for (int i = 0; i < item.PartsCount; i++)
                {
                    Mod.Log.Debug?.Write($"  -- scrapped one mech part");
                    mechBayPanel.Sim.ScrapMechPart(item.ChassisDef.Description.Id, 1f, item.ChassisDef.MechPartMax, pay: true);
                }

                mechBayPanel.RefreshData(resetFilters: true);
                mechBayPanel.SelectChassis(null);
            }
        }
        public static void show_all(MechBayPanel __instance)
        {
            var sim = __instance.Sim;

            if (!Control.Instance.Settings.DebugInfo.HasFlag(DInfo.Debug))
            {
                return;
            }


            Control.Instance.LogDebug(DInfo.Debug, "Player Mech:");
            foreach (var mech in sim.ActiveMechs)
            {
                Control.Instance.LogDebug(DInfo.Debug, "-- {0:00}[{3}]:{1}/{2}", mech.Key,
                                          mech.Value.Description.Id, mech.Value.Chassis?.Description.Id, mech.Value.GUID);
            }
            Control.Instance.LogDebug(DInfo.Debug, "Stored Mech:");
            foreach (var mech in sim.GetAllInventoryMechDefs())
            {
                Control.Instance.LogDebug(DInfo.Debug, "-- {0} ", mech.Description.Id);
                //foreach (var tag in mech.ChassisTags)
                //    Control.Instance.LogDebug(DInfo.Debug, "-- -C:{0}", tag );
            }
        }
 private static void ScrapChassis(int num, ChassisDef p1, MechBayChassisInfoWidget widget, MechBayPanel mechBay)
 {
     for (int i = 0; i < num; i++)
     {
         UnityGameInstance.BattleTechGame.Simulation.ScrapInactiveMech(p1.Description.Id, true);
     }
     mechBay.RefreshData(false);
     mechBay.SelectChassis(null);
 }
        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);
        }
Exemple #17
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);
        }
 private static void ScrapParts(int num, ChassisDef mech, MechBayChassisInfoWidget widget, MechBayPanel mechBay)
 {
     for (int i = 0; i < num; i++)
     {
         UnityGameInstance.BattleTechGame.Simulation.ScrapMechPart(mech.Description.Id, 1,
                                                                   UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax, true);
     }
     widget.SetData(mechBay, null);
     mechBay.RefreshData(false);
     mechBay.SelectChassis(null);
 }
Exemple #19
0
        public static void VariantPopup(string desc, SimGameState s, IEnumerable <MechDef> variantsToList, MechBayPanel refresh = null, SimpleMechAssembly_InterruptManager_AssembleMechEntry close = null)
        {
            GenericPopupBuilder pop    = GenericPopupBuilder.Create("Assemble Mech?", desc);
            bool   hasMultipleVariants = variantsToList.Count() > 1;
            string closeButtonText     = hasMultipleVariants ? "-" : "Not now";

            pop.AddButton(closeButtonText, delegate
            {
                if (close != null)
                {
                    close.NewClose();
                }
            }, true, null);


            foreach (MechDef m in variantsToList)
            {
                string buttonText = hasMultipleVariants ? string.Format("{0}", m.Chassis.VariantName) : "Yes";
                pop.AddButton(buttonText, delegate
                {
                    PerformMechAssemblyStorePopup(s, m, refresh, close);
                }, true, null);
            }

            pop.CancelOnEscape();
            pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
            pop.Render();
        }
Exemple #20
0
        public static void PerformMechAssemblyStorePopup(SimGameState s, MechDef d, MechBayPanel refresh, SimpleMechAssembly_InterruptManager_AssembleMechEntry close)
        {
            MechDef toAdd   = PerformMechAssembly(s, d);
            int     mechbay = s.GetFirstFreeMechBay();

            if (mechbay < 0) // no space - direct storage
            {
                StoreMech(s, toAdd);
                Log.Log("no space, direct storage");
                if (refresh != null)
                {
                    refresh.RefreshData(false);
                }
                GenericPopupBuilder pop = GenericPopupBuilder.Create("Mech Assembled",
                                                                     string.Format("Yang: [[DM.MechDefs[{3}],{1} {2}]] finished!\n{0}\n\nWe have no space for a new mech, so it goes into storage.",
                                                                                   d.Chassis.YangsThoughts, d.Chassis.Description.UIName, d.Chassis.VariantName, d.Description.Id));
                pop.AddButton("ok", delegate
                {
                    if (close != null)
                    {
                        close.NewClose();
                    }
                }, true, null);
                pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
                pop.Render();
            }
            else
            {
                GenericPopupBuilder pop = GenericPopupBuilder.Create("Mech Assembled",
                                                                     string.Format("Yang: [[DM.MechDefs[{3}],{1} {2}]] finished!\n{0}\n\nShould I put it into storage, or ready it for combat?",
                                                                                   d.Chassis.YangsThoughts, d.Chassis.Description.UIName, d.Chassis.VariantName, d.Description.Id));
                pop.AddButton("storage", delegate
                {
                    StoreMech(s, toAdd);
                    Log.Log("direct storage");
                    if (refresh != null)
                    {
                        refresh.RefreshData(false);
                    }
                    if (close != null)
                    {
                        close.NewClose();
                    }
                }, true, null);
                pop.AddButton("ready it", delegate
                {
                    if (Settings.AssembledMechsNeedReadying)
                    {
                        ReadyMech(s, toAdd, mechbay);
                    }
                    else
                    {
                        s.AddMech(mechbay, toAdd, true, false, false);
                    }
                    Log.Log("added to bay " + mechbay);
                    if (refresh != null)
                    {
                        refresh.RefreshData(false);
                    }
                    if (close != null)
                    {
                        close.NewClose();
                    }
                }, true, null);
                pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
                pop.Render();
            }
        }
Exemple #21
0
        public static bool Prefix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, MechBayPanel ___mechBay)
        {
            if (___selectedChassis == null)
            {
                return(true);
            }
            int     bay = ___mechBay.Sim.GetFirstFreeMechBay();
            string  id  = ___selectedChassis.Description.Id.Replace("chassisdef", "mechdef");
            MechDef d   = ___mechBay.Sim.DataManager.MechDefs.Get(id);

            if (___selectedChassis.MechPartCount > 0) // this is actually a part that gets assembled
            {
                int p = SimpleMechAssembly_Main.GetNumPartsForAssembly(___mechBay.Sim, d);
                if (p < ___mechBay.Sim.Constants.Story.DefaultMechPartMax)
                {
                    GenericPopupBuilder.Create("Mech Assembly", "Yang: I do not have enough parts to assemble a mech out of it.").AddButton("Cancel", null, true, null)
                    .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                    return(false);
                }
                //SimpleMechAssembly_Main.QueryMechAssemblyPopup(___mechBay.Sim, d, ___mechBay);
                ___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(___mechBay.Sim, d, ___mechBay), true);
                return(false);
            }
            if (___selectedChassis.MechPartCount < ___selectedChassis.MechPartMax)
            {
                return(true);
            }
            if (SimpleMechAssembly_Main.Settings.OmniMechTag == null || !___selectedChassis.ChassisTags.Contains(SimpleMechAssembly_Main.Settings.OmniMechTag))
            {
                return(true);
            }
            if (bay < 0)
            {
                return(true);
            }
            SimpleMechAssembly_Main.UnStorageOmniMechPopup(___mechBay.Sim, d, ___mechBay);
            return(false);
        }
Exemple #22
0
        public static bool ReadyVehicle(MechBayPanel __instance, MechBayChassisUnitElement chassisElement,
                                        ref MechBayChassisUnitElement ___selectedChassis, MechBayRowGroupWidget ___bayGroupWidget)
        {
            try
            {
                var chassisDef = chassisElement.ChassisDef;
                if (!chassisDef.IsVehicle())
                {
                    return(true);
                }

                var id      = chassisElement.ChassisDef.Description.Id;
                var sim     = __instance.Sim;
                int start   = sim.VehicleShift();
                int end     = start + sim.GetMaxActiveMechs();
                int baySlot = -1;
                for (int i = start; i < end; i++)
                {
                    MechDef mech_in_slot = null;
                    if (!sim.ActiveMechs.TryGetValue(i, out mech_in_slot))
                    {
                        sim.ReadyingMechs.TryGetValue(i, out mech_in_slot);
                    }
                    if (mech_in_slot == null)
                    {
                        baySlot = i;
                        break;
                    }
                }

                if (baySlot < 0)
                {
                    Control.Instance.LogDebug(DInfo.General, "No Free vehicle slots for {0}", id);
                    return(false);
                }

                var mid    = ChassisHandler.GetMDefFromCDef(id);
                var sim_id = sim.GenerateSimGameUID();
                var stock  = __instance.DataManager.MechDefs.Get(mid);
                var mech   = new MechDef(chassisDef, sim_id, stock);
                mech.SetInventory(stock.Inventory);


                WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech(
                    string.Format("ReadyMech-{0}", sim_id), Strings.T("Readying 'Mech - {0}", new object[]
                {
                    chassisDef.Description.Name
                }), sim.Constants.Story.MechReadyTime, baySlot, mech, Strings.T(
                        sim.Constants.Story.MechReadiedWorkOrderCompletedText, new object[]
                {
                    chassisDef.Description.Name
                }));

                sim.MechLabQueue.Add(workOrderEntry_ReadyMech);
                sim.ReadyingMechs[baySlot] = mech;
                sim.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech);
                sim.UpdateMechLabWorkQueue(false);
                sim.RemoveItemStat(id, typeof(MechDef), false);

                AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech",
                                                 WwiseManager.GlobalAudioObject, null);


                ___selectedChassis = null;
                __instance.RefreshData(true);
                __instance.ViewBays();
                __instance.SelectMech(___bayGroupWidget.GetMechUnitForSlot(baySlot), true);
            }
            catch (Exception e)
            {
                Control.Instance.LogError(e);
            }

            return(false);
        }
Exemple #23
0
            public static bool Prefix(MechBayPanel __instance, MechBayMechUnitElement mechElement)
            {
                Logger.LogDebug("We are repairing, yes?");
                Logger.Log("We are repairing, yes?");
                if (!Core.Settings.RepairRearm)
                {
                    return(true);
                }

                var     sim     = UnityGameInstance.BattleTechGame.Simulation;
                MechDef mechDef = mechElement.MechDef;
                WorkOrderEntry_MechLab workOrderEntry_MechLab = __instance.Sim.GetWorkOrderEntryForMech(mechDef);
                bool flag = false;

                for (int i = 0; i < mechDef.Inventory.Length; i++)
                {
                    MechComponentRef mechComponentRef = mechDef.Inventory[i];
                    if (mechComponentRef.DamageLevel != ComponentDamageLevel.Functional && mechComponentRef.DamageLevel
                        != ComponentDamageLevel.Installing && !MechValidationRules.MechComponentUnderMaintenance(mechComponentRef, MechValidationLevel.MechLab, workOrderEntry_MechLab))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!mechDef.IsDamaged && !flag)
                {
                    return(false);
                }
                List <ChassisLocations> list = new List <ChassisLocations>();

                __instance.pendingWorkOrderNew = false;
                __instance.pendingWorkOrderEntriesToAdd.Clear();
                if (workOrderEntry_MechLab == null)
                {
                    workOrderEntry_MechLab = new WorkOrderEntry_MechLab(WorkOrderType.MechLabGeneric, "MechLab-BaseWorkOrder", Strings.T("Modify 'Mech - {0}", new object[]
                    {
                        mechDef.Description.Name
                    }), mechDef.GUID, 0, Strings.T(__instance.Sim.Constants.Story.GeneralMechWorkOrderCompletedText, new object[]
                    {
                        mechDef.Description.Name
                    }));
                    workOrderEntry_MechLab.SetMechDef(mechDef);
                    __instance.pendingWorkOrderNew = true;
                }
                __instance.pendingWorkOrder = workOrderEntry_MechLab;
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.Head, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.Head.CurrentInternalStructure < mechDef.Chassis.Head.InternalStructure)
                {
                    list.Add(ChassisLocations.Head);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.CenterTorso, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.CenterTorso.CurrentInternalStructure < mechDef.Chassis.CenterTorso.InternalStructure)
                {
                    list.Add(ChassisLocations.CenterTorso);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.LeftTorso, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.LeftTorso.CurrentInternalStructure < mechDef.Chassis.LeftTorso.InternalStructure)
                {
                    list.Add(ChassisLocations.LeftTorso);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.RightTorso, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.RightTorso.CurrentInternalStructure < mechDef.Chassis.RightTorso.InternalStructure)
                {
                    list.Add(ChassisLocations.RightTorso);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.LeftLeg, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.LeftLeg.CurrentInternalStructure < mechDef.Chassis.LeftLeg.InternalStructure)
                {
                    list.Add(ChassisLocations.LeftLeg);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.RightLeg, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.RightLeg.CurrentInternalStructure < mechDef.Chassis.RightLeg.InternalStructure)
                {
                    list.Add(ChassisLocations.RightLeg);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.LeftArm, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.LeftArm.CurrentInternalStructure < mechDef.Chassis.LeftArm.InternalStructure)
                {
                    list.Add(ChassisLocations.LeftArm);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.RightArm, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.RightArm.CurrentInternalStructure < mechDef.Chassis.RightArm.InternalStructure)
                {
                    list.Add(ChassisLocations.RightArm);
                }
                if (list.Count < 1 && !flag)
                {
                    GenericPopupBuilder.Create("Repair Already Ordered", string.Format("A repair order has already been queued for " +
                                                                                       "{0}", mechDef.Name)).AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                    __instance.OnRepairAllCancelled();
                    return(false);
                }
                int num  = 0;
                int num2 = 0;

                for (int j = 0; j < list.Count; j++)
                {
                    LocationDef        chassisLocationDef = mechDef.GetChassisLocationDef(list[j]);
                    LocationLoadoutDef locationLoadoutDef = mechDef.GetLocationLoadoutDef(list[j]);
                    int structureCount = Mathf.RoundToInt(Mathf.Max(0f, chassisLocationDef.InternalStructure - locationLoadoutDef.CurrentInternalStructure));
                    WorkOrderEntry_RepairMechStructure workOrderEntry_RepairMechStructure = __instance.Sim.CreateMechRepairWorkOrder(mechDef.GUID, list[j], structureCount);
                    __instance.pendingWorkOrderEntriesToAdd.Add(workOrderEntry_RepairMechStructure);
                    num  += workOrderEntry_RepairMechStructure.GetCost();
                    num2 += workOrderEntry_RepairMechStructure.GetCBillCost();
                }
                StringBuilder stringBuilder = new StringBuilder();
                int           num3          = 0;

                for (int k = 0; k < mechDef.Inventory.Length; k++)
                {
                    MechComponentRef mechComponentRef2 = mechDef.Inventory[k];
                    if (string.IsNullOrEmpty(mechComponentRef2.SimGameUID))
                    {
                        mechComponentRef2.SetSimGameUID(__instance.Sim.GenerateSimGameUID());
                    }
                    if (mechComponentRef2.DamageLevel == ComponentDamageLevel.Destroyed)
                    {
                        if (num3 < 1)
                        {
                            stringBuilder.Append("\n\nThe following components have been Destroyed. If you continue with the Repair, " +
                                                 "replacement Components will NOT be installed. If you want to replace them with identical or " +
                                                 "different Components, you must Refit the 'Mech.\n\n");
                        }
                        if (num3 < 5)
                        {
                            stringBuilder.Append(mechComponentRef2.MountedLocation.ToString());
                            stringBuilder.Append(": ");
                            stringBuilder.Append(mechComponentRef2.Def.Description.Name);
                            stringBuilder.Append("\n");
                        }
                        num3++;
                        WorkOrderEntry_InstallComponent workOrderEntry_InstallComponent = sim.CreateComponentInstallWorkOrder(__instance.selectedMech.MechDef.GUID,
                                                                                                                              mechComponentRef2, ChassisLocations.None, mechComponentRef2.MountedLocation);
                        __instance.pendingWorkOrderEntriesToAdd.Insert(0, workOrderEntry_InstallComponent);
                        num  += workOrderEntry_InstallComponent.GetCost();
                        num2 += workOrderEntry_InstallComponent.GetCBillCost();
                    }
                    else if (mechComponentRef2.DamageLevel != ComponentDamageLevel.Functional && mechComponentRef2.DamageLevel != ComponentDamageLevel.Installing)
                    {
                        WorkOrderEntry_RepairComponent workOrderEntry_RepairComponent = __instance.Sim.CreateComponentRepairWorkOrder(mechComponentRef2, true);
                        __instance.pendingWorkOrderEntriesToAdd.Add(workOrderEntry_RepairComponent);
                        num  += workOrderEntry_RepairComponent.GetCost();
                        num2 += workOrderEntry_RepairComponent.GetCBillCost();
                    }
                }

                foreach (var foo in __instance.pendingWorkOrderEntriesToAdd)
                {
                    Logger.LogDebug(foo.ID);
                }
                Logger.LogDebug("Armor Repair Section");
                float armorLoss = 1;
                bool  armorTag  = false;

                foreach (var tag in mechDef.MechTags)
                {
                    Logger.LogDebug(tag);
                    if (tag.StartsWith("XLRPArmor"))
                    {
                        armorTag = true;
                        string[] parsedString = tag.Split('_');
                        armorLoss = float.Parse(parsedString[1]);
                    }
                    Logger.LogDebug(armorLoss.ToString());
                }
                if (armorTag)
                {
                    if (!mechDef.MechTags.Contains("XLRP_Armor_Repairing"))
                    {
                        mechDef.MechTags.Add("XLRP_Armor_Repairing");
                    }
                    int brokenArmor = (int)((1 - armorLoss) * mechDef.MechDefAssignedArmor);
                    int frontArmor  = (int)(mechDef.MechDefAssignedArmor - mechDef.CenterTorso.AssignedRearArmor -
                                            mechDef.LeftTorso.AssignedRearArmor - mechDef.RightTorso.AssignedRearArmor);
                    int rearArmor = (int)(mechDef.CenterTorso.AssignedRearArmor +
                                          mechDef.LeftTorso.AssignedRearArmor + mechDef.RightTorso.AssignedRearArmor);
                    Logger.LogDebug($"brokenAmor: {brokenArmor}, frontArmor: {frontArmor}, rearArmor: {rearArmor}");
                    WorkOrderEntry_ModifyMechArmor subEntry = sim.CreateMechArmorModifyWorkOrder(__instance.selectedMech.MechDef.GUID,
                                                                                                 ChassisLocations.All, brokenArmor, frontArmor, rearArmor);

                    __instance.pendingWorkOrderEntriesToAdd.Add(subEntry);
                    num  += subEntry.GetCost();
                    num2 += subEntry.GetCBillCost();
                }

                num = Mathf.Max(1, Mathf.CeilToInt((float)num / (float)__instance.Sim.MechTechSkill));
                if (num3 > 5)
                {
                    stringBuilder.Append(Strings.T("...\nAnd {0} additional destroyed components.\n", new object[]
                    {
                        num3 - 5
                    }));
                }
                string body = Strings.T("Repairing {0} will cost {1:n0} C-Bills and take {2} Days.{3}\n\nProceed?", new object[]
                {
                    mechDef.Name,
                    num2,
                    num,
                    stringBuilder.ToString()
                });

                GenericPopupBuilder.Create("Repair 'Mech?", body).AddButton("Cancel", new Action(__instance.OnRepairAllCancelled), true, null).
                AddButton("Repair", new Action(__instance.OnRepairAllAccepted), true, null).AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                return(false);
            }
Exemple #24
0
 public static void Postfix(MechBayPanel __instance)
 {
     Main.SetupUI(__instance.GetRepresentation().transform);
 }
        public static bool Prefix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, MechBayPanel ___mechBay)
        {
            if (___selectedChassis == null)
            {
                return(true);
            }
            int     bay = ___mechBay.Sim.GetFirstFreeMechBay();
            MechDef d   = ___selectedChassis.GetMainMechDef(___mechBay.Sim.DataManager);

            if (___selectedChassis.MechPartCount > 0) // this is actually a part that gets assembled
            {
                int p = SimpleMechAssembly_Main.GetNumPartsForAssembly(___mechBay.Sim, d);
                if (p < ___mechBay.Sim.Constants.Story.DefaultMechPartMax)
                {
                    GenericPopupBuilder.Create($"{d.GetMechOmniVehicle()} Assembly", SimpleMechAssembly_Main.GetAssembleNotEnoughPartsText(___mechBay.Sim, d)).AddButton("Cancel", null, true, null)
                    .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                    return(false);
                }
                ___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(___mechBay.Sim, d, delegate
                {
                    ___mechBay.RefreshData(false);
                }), true);
                return(false);
            }
            if (___selectedChassis.MechPartCount < ___selectedChassis.MechPartMax)
            {
                return(true);
            }
            if (___selectedChassis.IsVehicle())
            {
                bay = CUIntegration.GetFirstFreeMechBay(___mechBay.Sim, d);
                if (bay < 0)
                {
                    GenericPopupBuilder.Create("Cannot Ready Vehicle", "There are no available slots in the Vehicle Bay. You must move an active Vehicle into storage before readying this chassis.")
                    .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                }
                else
                {
                    GenericPopupBuilder.Create("Ready Vehicle?", $"It will take {Mathf.CeilToInt(___mechBay.Sim.Constants.Story.MechReadyTime / (float)___mechBay.Sim.MechTechSkill)} day(s) to ready this Vehicle for combat.")
                    .AddButton("Cancel", null, true, null).AddButton("Ready", delegate
                    {
                        if (___mechBay.Sim.ScrapInactiveMech(___selectedChassis.Description.Id, false))
                        {
                            SimpleMechAssembly_Main.ReadyMech(___mechBay.Sim, new MechDef(d, ___mechBay.Sim.GenerateSimGameUID(), true), bay, true);
                            ___mechBay.RefreshData(false);
                            ___mechBay.ViewBays();
                        }
                    }).AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).CancelOnEscape().Render();
                }
                return(false);
            }
            if (!___selectedChassis.IsOmni())
            {
                return(true);
            }
            if (bay < 0)
            {
                return(true);
            }
            ___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_UnStorageOmniEntry(___mechBay.Sim, d, delegate
            {
                ___mechBay.RefreshData(false);
            }));
            return(false);
        }