public static void OnPartsAssembly()
 {
     try
     {
         Control.LogDebug($"-- remove parts");
         RemoveMechPart(mech.Description.Id, chassis.MechPartMax);
         infoWidget.SetData(mechBay, null);
         Control.LogDebug($"-- making mech");
         MakeMech(mechBay.Sim);
         Control.LogDebug($"-- refresh mechlab");
         mechBay.RefreshData(false);
     }
     catch (Exception e)
     {
         Control.LogError("Error in Complete Mech", e);
     }
 }
 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);
 }
 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);
 }
Beispiel #4
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();
        }
        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();
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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();
            }
        }
        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);
        }