Пример #1
0
        static void Postfix(SimGameState __instance)
        {
            if (!Core.ModSettings.WarnAboutTrainablePilots)
            {
                return;
            }

            var pilotsToTrain = 0;
            var pilots        = new List <Pilot>(__instance.PilotRoster)
            {
                __instance.Commander
            };

            foreach (var pilot in pilots)
            {
                if (pilot.pilotDef.PilotTags.ContainsAny(PilotFatigueTags))
                {
                    continue;
                }
                var foundTrainable = false;
                var source         = new int[] { pilot.Gunnery, pilot.Tactics, pilot.Guts, pilot.Piloting };
                for (var i = 0; i < source.Length && !foundTrainable; i++)
                {
                    if (source[i] >= Core.ModSettings.PilotSkillLevelForWhichWarningNotNecessary)
                    {
                        continue;
                    }
                    if (pilot.UnspentXP <= __instance.GetLevelCost(source[i] + 1))
                    {
                        continue;
                    }
                    pilotsToTrain++;
                    foundTrainable = true;
                }

                if (foundTrainable)
                {
                    pilotsToTrain++;
                }
            }

            if (pilotsToTrain >= Core.ModSettings.MinimumPilotsNeedingTrainingForWarning)
            {
                __instance
                .GetInterruptQueue()
                .QueuePauseNotification(
                    "MechWarrior Training Required",
                    $"Our MechWarriors are gaining in experience and need your guidance, {__instance.Commander.Callsign}. If you head to the Barracks, you can direct their training.",
                    __instance.GetCrewPortrait(SimGameCrew.Crew_Darius),
                    null,
                    new Action(Core.OnNotificationDismissed),
                    "Continue",
                    null,
                    null);
            }
        }
Пример #2
0
 static bool Prefix(SGTravelManager __instance, SimGameState ___simState)
 {
     try {
         bool              flag       = true;
         Faction           owner      = ___simState.CurSystem.Owner;
         SimGameReputation reputation = ___simState.GetReputation(owner);
         if (reputation <= SimGameReputation.LOATHED)
         {
             flag = false;
         }
         if (flag)
         {
             Action actionArrive = (Action)Delegate.CreateDelegate(typeof(Action), __instance, "OnArrivedAtPlanet");
             Action actionSave   = (Action)Delegate.CreateDelegate(typeof(Action), __instance, "SaveNow");
             ___simState.GetInterruptQueue().QueueTravelPauseNotification("Arrived", Strings.T("We've arrived at {0}.", new object[]
             {
                 ___simState.Starmap.CurPlanet.System.Def.Description.Name
             }), ___simState.GetCrewPortrait(SimGameCrew.Crew_Sumire), "notification_travelcomplete", actionArrive, "Visit Store", actionSave, "Continue");
         }
         else
         {
             Action actionSave = (Action)Delegate.CreateDelegate(typeof(Action), __instance, "SaveNow");
             ___simState.GetInterruptQueue().QueueTravelPauseNotification("Arrived", Strings.T("We've arrived at {0}.", new object[]
             {
                 ___simState.Starmap.CurPlanet.System.Def.Description.Name
             }), ___simState.GetCrewPortrait(SimGameCrew.Crew_Sumire), "notification_travelcomplete", actionSave, "Continue", null, null);
         }
         if (!___simState.TimeMoving)
         {
             ___simState.GetInterruptQueue().DisplayIfAvailable();
         }
         return(false);
     }
     catch (Exception e) {
         Logger.LogError(e);
         return(true);
     }
 }
 private static void ShowLongTomSpecial(SimGameState s)
 {
     s.CompanyTags.Add("bullshark_cac_lt_upgrade");
     s.InterruptQueue.QueuePauseNotification("Yangs Offer",
                                             $"Hey, Boss. We have a Bull Shark and I found a Long Tom on the local market. Give me {SimGameState.GetCBillString(10000000)} and a lot of time, and I replace the Thumper with it.",
                                             s.GetCrewPortrait(SimGameCrew.Crew_Yang), "", () =>
     {
         RemoveBullshark(s);
         AddBullsharkLT(s);
         s.AddFunds(-10000000, null, true, true);
     }, "OK", () =>
     {
         s.CompanyTags.Remove("bullshark_cac_lt_upgrade");
     }, "Cancel");
 }
Пример #4
0
 static bool Prefix(SimGameState __instance, Action continueAction, Action cancelAction)
 {
     try {
         if (__instance.ActiveTravelContract == null)
         {
             return(false);
         }
         string primaryButtonText = Strings.T("Confirm");
         string message           = Strings.T("Commander, we're locked into our existing contract already. We can't take another one without seeing this one through first. We've got enough problems with people shooting us already, let's not add lawyers to the mix.");
         PauseNotification.Show("CONTRACT VIOLATION", message, __instance.GetCrewPortrait(SimGameCrew.Crew_Darius), string.Empty, true, cancelAction, primaryButtonText, null, null);
         return(false);
     }
     catch (Exception e) {
         PersistentMapClient.Logger.LogError(e);
         return(false);
     }
 }
        static bool Prefix(int idx, MechDef mech, bool active, bool forcePlacement, bool displayMechPopup,
                           string mechAddedHeader, SimGameState __instance)
        {
            Logger.Debug("AddMech Prefix Patch Installed");
            if (displayMechPopup)
            {
                if (string.IsNullOrEmpty(mech.GUID))
                {
                    mech.SetGuid(__instance.GenerateSimGameUID());
                }

                var companyStats = Traverse.Create(__instance).Field("companyStats").GetValue <StatCollection>();
                companyStats.ModifyStat <int>("Mission", 0, "COMPANY_MechsAdded", StatCollection.StatOperation.Int_Add, 1, -1, true);
                if (string.IsNullOrEmpty(mechAddedHeader))
                {
                    mechAddedHeader = "'Mech Chassis Complete";
                    int num = (int)WwiseManager.PostEvent <AudioEventList_ui>(AudioEventList_ui.ui_sim_popup_newChassis, WwiseManager.GlobalAudioObject, (AkCallbackManager.EventCallback)null, (object)null);
                }

                mechAddedHeader += ": {0}";

                __instance.GetInterruptQueue().QueuePauseNotification(
                    string.Format(mechAddedHeader, (object)mech.Description.UIName), mech.Chassis.YangsThoughts,
                    __instance.GetCrewPortrait(SimGameCrew.Crew_Yang), "notification_mechreadycomplete", (Action)(() =>
                {
                    int firstFreeMechBay = __instance.GetFirstFreeMechBay();
                    if (firstFreeMechBay >= 0)
                    {
                        __instance.ActiveMechs[firstFreeMechBay] = mech;
                        SortMechLabMechs(__instance.GetMaxActiveMechs(), __instance.ActiveMechs,
                                         __instance.ReadyingMechs);
                    }
                    else
                    {
                        __instance.CreateMechPlacementPopup(mech);
                    }
                }), "Continue", (Action)null, (string)null);
                return(false);
            }

            return(true);
        }
Пример #6
0
 static bool Prefix(SGNavigationScreen __instance)
 {
     try {
         if (Fields.Deployment)
         {
             UIManager    uiManager = (UIManager)AccessTools.Field(typeof(SGNavigationScreen), "uiManager").GetValue(__instance);
             SimGameState simState  = (SimGameState)AccessTools.Field(typeof(SGNavigationScreen), "simState").GetValue(__instance);
             Action       cleanup   = delegate() {
                 uiManager.ResetFader(UIManagerRootType.PopupRoot);
                 simState.Starmap.Screen.AllowInput(true);
             };
             string primaryButtonText = "Break Contract";
             string message           = "WARNING: This action will break your current deployment contract. Your reputation with the employer and the MRB will be negatively affected.";
             PauseNotification.Show("Navigation Change", message, simState.GetCrewPortrait(SimGameCrew.Crew_Sumire), string.Empty, true, delegate {
                 cleanup();
                 Fields.Deployment = false;
                 if (simState.DoesFactionGainReputation(Fields.DeploymentEmployer))
                 {
                     Settings settings = Helper.LoadSettings();
                     ReflectionHelper.InvokePrivateMethode(simState, "SetReputation", new object[] { Fields.DeploymentEmployer, settings.DeploymentBreakRepCost, StatCollection.StatOperation.Int_Add, null });
                     ReflectionHelper.InvokePrivateMethode(simState, "SetReputation", new object[] { Faction.MercenaryReviewBoard, settings.DeploymentBreakMRBRepCost, StatCollection.StatOperation.Int_Add, null });
                     AccessTools.Field(typeof(SimGameState), "activeBreadcrumb").SetValue(simState, null);
                 }
                 simState.Starmap.SetActivePath();
                 simState.SetSimRoomState(DropshipLocation.SHIP);
             }, primaryButtonText, cleanup, "Cancel");
             simState.Starmap.Screen.AllowInput(false);
             uiManager.SetFaderColor(uiManager.UILookAndColorConstants.PopupBackfill, UIManagerFader.FadePosition.FadeInBack, UIManagerRootType.PopupRoot, true);
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception e) {
         Logger.LogError(e);
         return(true);
     }
 }
Пример #7
0
 static bool Prefix(SGContractsWidget __instance)
 {
     try {
         SimGameState Sim = (SimGameState)AccessTools.Property(typeof(SGContractsWidget), "Sim").GetValue(__instance, null);
         if (__instance.SelectedContract.Override.travelOnly && !__instance.SelectedContract.IsPriorityContract && Sim.ActiveMechs.Count < 8)
         {
             string message = "Commander, a deployment is a longer term arrangement with an employer, that may require missions to be done without time between them for repairs. I strongly encourage you to only deploy on this arrangement if we are capable of fielding multiple lances with little or no time for repairs, just in case.";
             PauseNotification.Show("Deployment", message,
                                    Sim.GetCrewPortrait(SimGameCrew.Crew_Darius), string.Empty, true, delegate {
                 __instance.NegotiateContract(__instance.SelectedContract, null);
             }, "Do it anyways", null, "Cancel");
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception e) {
         Logger.LogError(e);
         return(true);
     }
 }
Пример #8
0
 static bool Prefix(SimGameState __instance, SimGameInterruptManager ___interruptQueue)
 {
     try {
         ___interruptQueue.QueuePauseNotification("Difficult Mission", "Careful, Commander. This drop looks like it might require more firepower than that.", __instance.GetCrewPortrait(SimGameCrew.Crew_Darius), string.Empty, new Action(__instance.RoomManager.CmdCenterRoom.lanceConfigBG.LC.ContinueConfirmClicked), "CONFIRM", null, "BACK");
         return(false);
     }
     catch (Exception e) {
         Logger.LogError(e);
         return(true);
     }
 }
Пример #9
0
            public static void Postfix(SimGameState __instance, Contract __state)
            {
                if (ModInit.Settings.SwapUnitsWithAIContractIDs.ContainsKey(__state.Override.ID))
                {
                    if (ModInit.Settings.SwapUnitsWithAIContractIDs[contractID] == "SIMULATOR")
                    {
                        foreach (var kvp in new Dictionary <int, MechDef>(__instance.ActiveMechs))
                        {
                            if (ModState.deployedMechs.Any(x => x.GUID == kvp.Value.GUID))
                            {
                                __instance.ActiveMechs.Remove(kvp.Key);
                                ModInit.modLog.LogMessage($"Removing old {kvp.Value.Name} from MechBay");
                            }
                        }
                        foreach (var deployedMech in ModState.deployedMechs)
                        {
                            Thread.CurrentThread.pushActorDef(deployedMech);
                            __instance.ActiveMechs.Add(__instance.GetFirstFreeMechBay(), deployedMech);
                            Thread.CurrentThread.clearActorDef();

                            ModInit.modLog.LogMessage($"Added replacement {deployedMech.Name}");
                        }
                    }

                    else if (ModInit.Settings.SwapUnitsWithAIContractIDs[contractID] == "RECOVER")
                    {
                        foreach (var kvp in new Dictionary <int, MechDef>(__instance.ActiveMechs))
                        {
                            if (ModState.deployedMechs.Any(x => x.GUID == kvp.Value.GUID))
                            {
                                __instance.ActiveMechs.Remove(kvp.Key);
                                ModInit.modLog.LogMessage($"Removing original {kvp.Value.Name} from MechBay");
                            }
                        }
                        foreach (var recoveredMech in ModState.recoveredMechDefs)
                        {
                            Thread.CurrentThread.pushActorDef(recoveredMech);
                            __instance.ActiveMechs.Add(__instance.GetFirstFreeMechBay(), recoveredMech);
                            Thread.CurrentThread.clearActorDef();
                            ModInit.modLog.LogMessage($"Added replacement damaged {recoveredMech.Name}");
                        }
                    }
                }

                if (ModState.IsSimulatorMission)
                {
                    foreach (var kvp in new Dictionary <int, MechDef>(__instance.ActiveMechs))
                    {
                        if (ModState.deployedMechs.Any(x => x.GUID == kvp.Value.GUID))
                        {
                            __instance.ActiveMechs.Remove(kvp.Key);
                            ModInit.modLog.LogMessage($"Removing old {kvp.Value.Name} from MechBay");
                        }
                    }

                    foreach (var deployedMech in ModState.deployedMechs)
                    {
                        Thread.CurrentThread.pushActorDef(deployedMech);
                        __instance.ActiveMechs.Add(__instance.GetFirstFreeMechBay(), deployedMech);
                        Thread.CurrentThread.clearActorDef();
                        ModInit.modLog.LogMessage($"Added replacement {deployedMech.Name}");
                    }
                }

                if (ModInit.Settings.TrainingContractIDs.ContainsKey(__state.Override.ID))
                {
                    if (ModInit.Settings.TrainingContractIDs[contractID] == "SUCCESS" &&
                        __state.State != Contract.ContractState.Complete)
                    {
                        ModInit.modLog.LogMessage($"Mission was not successful, not restoring mechs.");
                        return;
                    }

                    if (ModInit.Settings.TrainingContractIDs[contractID] == "GOODFAITH" &&
                        !__state.IsGoodFaithEffort &&
                        (__state.State == Contract.ContractState.Failed ||
                         __state.State == Contract.ContractState.Retreated))
                    {
                        ModInit.modLog.LogMessage(
                            $"Mission failed, not restoring mechs.");
                        return;
                    }
                    goto continu;
                }

                if (ModState.DynamicTrainingMissionsDict.ContainsKey(__state.GenerateID()))
                {
                    if (ModState.DynamicTrainingMissionsDict[__state.GenerateID()] == "SUCCESS" &&
                        __state.State != Contract.ContractState.Complete)
                    {
                        ModInit.modLog.LogMessage($"Mission was not successful, not restoring mechs.");
                        return;
                    }

                    if (ModState.DynamicTrainingMissionsDict[__state.GenerateID()] == "GOODFAITH" &&
                        !__state.IsGoodFaithEffort &&
                        (__state.State == Contract.ContractState.Failed ||
                         __state.State == Contract.ContractState.Retreated))
                    {
                        ModInit.modLog.LogMessage(
                            $"Mission failed, not restoring mechs.");
                        return;
                    }
                    goto continu;
                }
                return;

continu:
                foreach (var kvp in new Dictionary <int, MechDef>(__instance.ActiveMechs))
                {
                    if (ModState.deployedMechs.Any(x => x.GUID == kvp.Value.GUID))
                    {
                        __instance.ActiveMechs.Remove(kvp.Key);
                        ModInit.modLog.LogMessage($"Removing old {kvp.Value.Name} from MechBay");
                    }
                }

                foreach (var deployedMech in ModState.deployedMechs)
                {
                    Thread.CurrentThread.pushActorDef(deployedMech);
                    __instance.ActiveMechs.Add(__instance.GetFirstFreeMechBay(), deployedMech);
                    Thread.CurrentThread.clearActorDef();
                    ModInit.modLog.LogMessage($"Added replacement {deployedMech.Name}");
                }

                if (ModInit.Settings.showRestoreNotification && ModState.deployedMechs.Count > 0)
                {
                    Traverse.Create(__instance).Field("interruptQueue").GetValue <SimGameInterruptManager>()
                    .QueuePauseNotification("Mechs Restored",
                                            "As per the terms of the contract, our employer has repaired, replaced, and refitted our damaged and destroyed units. Our pilots are another story, however.",
                                            __instance.GetCrewPortrait(SimGameCrew.Crew_Darius), "", null, "Continue", null, null);
                }

                if (ModState.DynamicTrainingMissionsDict.ContainsKey(__state.GenerateID()))
                {
                    ModState.DynamicTrainingMissionsDict.Remove(__state.GenerateID());
                }
                ModState.IsSimulatorMission = false;
//                ModState.IsTrainingMission = false;
                ModState.AIGetsPlayerMechs = false;
                ModState.PlayerGetsAIMechs = false;
//                ModState.successReq = "";
                ModState.playerMechs                   = new List <ModState.playerMechStore>();
                ModState.AIMechs                       = new List <ModState.playerMechStore>();
                ModState.deployedMechs                 = new List <MechDef>();
                ModState.contractID                    = "";
                ModState.pilotStartingInjuries         = new Dictionary <string, int>();
                ModState.recoveredMechDefs             = new List <MechDef>();
                ModState.runContinueConfirmClickedPost = false;
            }
        // Run after completion of contracts and queue up any orders in the temp queue into the game's Mech Lab queue
        public static void Postfix(SimGameState __instance)
        {
            try
            {
                // If there are any work orders in the temporary queue, prompt the player
                if (Globals.tempMechLabQueue.Count > 0)
                {
                    Logger.LogDebug("Processing temp Mech Lab queue orders.");

                    int    cbills                   = 0;
                    int    techCost                 = 0;
                    int    mechRepairCount          = 0;
                    int    skipMechCount            = 0;
                    string mechRepairCountDisplayed = String.Empty;
                    string skipMechCountDisplayed   = String.Empty;
                    string skipMechMessage          = String.Empty;
                    string finalMessage             = String.Empty;

                    // If player has disabled auto repairing mechs with destroyed components, check for them and remove them from the temp queue before continuing
                    if (!ArmorRepair.ModSettings.AutoRepairMechsWithDestroyedComponents)
                    {
                        for (int index = 0; index < Globals.tempMechLabQueue.Count; index++)
                        {
                            WorkOrderEntry_MechLab order = Globals.tempMechLabQueue[index];

                            Logger.LogDebug("Checking for destroyed components.");
                            bool    destroyedComponents = false;
                            MechDef mech = __instance.GetMechByID(order.MechID);
                            destroyedComponents = Helpers.CheckDestroyedComponents(mech);

                            if (destroyedComponents)
                            {
                                // Remove this work order from the temp mech lab queue if the mech has destroyed components and move to next iteration
                                Logger.LogDebug("Removing " + mech.Name + " order from temp queue due to destroyed components and mod settings.");
                                Globals.tempMechLabQueue.Remove(order);
                                destroyedComponents = false;
                                skipMechCount++;
                                index++;
                            }
                        }
                    }

                    Logger.LogDebug("Temp Queue has " + Globals.tempMechLabQueue.Count + " entries.");

                    // Calculate summary of total repair costs from the temp work order queue
                    for (int index = 0; index < Globals.tempMechLabQueue.Count; index++)
                    {
                        WorkOrderEntry_MechLab order = Globals.tempMechLabQueue[index];
                        MechDef mech = __instance.GetMechByID(order.MechID);
                        Logger.LogDebug("Adding " + mech.Name + " to RepairCount.");
                        cbills   += order.GetCBillCost();
                        techCost += order.GetCost();
                        mechRepairCount++;
                    }

                    mechRepairCount = Mathf.Clamp(mechRepairCount, 0, 4);
                    Logger.LogDebug("Temp Queue has " + Globals.tempMechLabQueue.Count + " work order entries.");

                    // If Yang's Auto Repair prompt is enabled, build a message prompt dialog for the player
                    if (ArmorRepair.ModSettings.EnableAutoRepairPrompt)
                    {
                        // Calculate a friendly techCost of the work order in days, based on number of current mechtechs in the player's game.
                        if (techCost != 0 && __instance.MechTechSkill != 0)
                        {
                            techCost = Mathf.CeilToInt((float)techCost / (float)__instance.MechTechSkill);
                        }
                        else
                        {
                            techCost = 1; // Safety in case of weird div/0
                        }

                        // Generate a quick friendly description of how many mechs were damaged in battle
                        switch (mechRepairCount)
                        {
                        case 0: { Logger.LogDebug("mechRepairCount was 0."); break; }

                        case 1: { mechRepairCountDisplayed = "one of our 'Mechs was"; break; }

                        case 2: { mechRepairCountDisplayed = "a couple of the 'Mechs were"; break; }

                        case 3: { mechRepairCountDisplayed = "three of our 'Mechs were"; break; }

                        case 4: { mechRepairCountDisplayed = "our whole lance was"; break; }
                        }
                        // Generate a friendly description of how many mechs were damaged but had components destroyed
                        switch (skipMechCount)
                        {
                        case 0: { Logger.LogDebug("skipMechCount was 0."); break; }

                        case 1: { skipMechCountDisplayed = "one of the 'Mechs is damaged but has"; break; }

                        case 2: { skipMechCountDisplayed = "two of the 'Mechs are damaged but have"; break; }

                        case 3: { skipMechCountDisplayed = "three of the 'Mechs are damaged but have "; break; }

                        case 4: { skipMechCountDisplayed = "the whole lance is damaged but has"; break; }
                        }

                        // Check if there are any mechs to process
                        if (mechRepairCount > 0 || skipMechCount > 0)
                        {
                            Logger.LogDebug("mechRepairCount is " + mechRepairCount + " skipMechCount is " + skipMechCount);

                            // Setup the notification for mechs with damaged components that we might want to skip
                            if (skipMechCount > 0 && mechRepairCount == 0)
                            {
                                skipMechMessage = String.Format("{0} destroyed components. I'll leave the repairs for you to review.", skipMechCountDisplayed);
                            }
                            else
                            {
                                skipMechMessage = String.Format("{0} destroyed components, so I'll leave those repairs to you.", skipMechCountDisplayed);
                            }

                            Logger.LogDebug("Firing Yang's UI notification.");
                            SimGameInterruptManager notificationQueue = __instance.GetInterruptQueue();

                            // If all of the mechs needing repairs have damaged components and should be skipped from auto-repair, change the message notification structure to make more sense (e.g. just have an OK button)
                            if (skipMechCount > 0 && mechRepairCount == 0)
                            {
                                finalMessage = String.Format(
                                    "Boss, {0} \n\n",
                                    skipMechMessage
                                    );

                                // Queue Notification
                                notificationQueue.QueuePauseNotification(
                                    "'Mech Repairs Needed",
                                    finalMessage,
                                    __instance.GetCrewPortrait(SimGameCrew.Crew_Yang),
                                    string.Empty,
                                    delegate
                                {
                                    Logger.LogDebug("[PROMPT] All damaged mechs had destroyed components and won't be queued for repair.");
                                },
                                    "OK"
                                    );
                            }
                            else
                            {
                                if (skipMechCount > 0)
                                {
                                    finalMessage = String.Format(
                                        "Boss, {0} damaged. It'll cost <color=#DE6729>{1}{2:n0}</color> and {3} days for these repairs. Want my crew to get started?\n\nAlso, {4}\n\n",
                                        mechRepairCountDisplayed,
                                        '¢', cbills.ToString(),
                                        techCost.ToString(),
                                        skipMechMessage
                                        );
                                }
                                else
                                {
                                    finalMessage = String.Format(
                                        "Boss, {0} damaged on the last engagement. It'll cost <color=#DE6729>{1}{2:n0}</color> and {3} days for the repairs.\n\nWant my crew to get started?",
                                        mechRepairCountDisplayed,
                                        '¢', cbills.ToString(),
                                        techCost.ToString()
                                        );
                                }


                                // Queue up Yang's notification
                                notificationQueue.QueuePauseNotification(
                                    "'Mech Repairs Needed",
                                    finalMessage,
                                    __instance.GetCrewPortrait(SimGameCrew.Crew_Yang),
                                    string.Empty,
                                    delegate
                                {
                                    Logger.LogDebug("[PROMPT] Moving work orders from temp queue to Mech Lab queue: " + Globals.tempMechLabQueue.Count + " work orders");
                                    foreach (WorkOrderEntry_MechLab workOrder in Globals.tempMechLabQueue.ToList())
                                    {
                                        Logger.LogInfo("[PROMPT] Moving work order from temp queue to Mech Lab queue: " + workOrder.Description + " - " + workOrder.GetCBillCost());
                                        Helpers.SubmitWorkOrder(__instance, workOrder);
                                        Globals.tempMechLabQueue.Remove(workOrder);
                                    }
                                },
                                    "Yes",
                                    delegate
                                {
                                    Logger.LogInfo("[PROMPT] Discarding work orders from temp queue: " + Globals.tempMechLabQueue.Count + " work orders");
                                    foreach (WorkOrderEntry_MechLab workOrder in Globals.tempMechLabQueue.ToList())
                                    {
                                        Logger.LogInfo("[PROMPT] Discarding work order from temp queue: " + workOrder.Description + " - " + workOrder.GetCBillCost());
                                        Globals.tempMechLabQueue.Remove(workOrder);
                                    }
                                },
                                    "No"
                                    );
                            }
                        }
                    }
                    else // If Auto Repair prompt is not enabled, just proceed with queuing the remaining temp queue work orders and don't notify the player
                    {
                        foreach (WorkOrderEntry_MechLab workOrder in Globals.tempMechLabQueue.ToList())
                        {
                            Logger.LogInfo("[AUTO] Moving work order from temp queue to Mech Lab queue: " + workOrder.Description + " - " + workOrder.GetCBillCost());
                            Helpers.SubmitWorkOrder(__instance, workOrder);
                            Globals.tempMechLabQueue.Remove(workOrder);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.tempMechLabQueue.Clear();
                Logger.LogError(ex);
            }
        }
Пример #11
0
        static void Postfix(SimGameState __instance)
        {
            try {
                Fields.PaymentCall = false;
                if (Fields.Deployment)
                {
                    if (Fields.DeploymentRemainingDays <= 0)
                    {
                        __instance.StopPlayMode();
                        Fields.Deployment = false;
                        SimGameInterruptManager interruptQueue = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(__instance);
                        interruptQueue.QueueGenericPopup("Deployment Over", "Thanks for your services.");
                        Fields.DeploymentContracts = new Dictionary <string, Contract>();
                        __instance.CurSystem.SystemContracts.Clear();
                        __instance.RoomManager.RefreshTimeline();
                        AccessTools.Field(typeof(SimGameState), "activeBreadcrumb").SetValue(__instance, null);
                    }
                    else
                    {
                        Settings      settings      = Helper.LoadSettings();
                        System.Random rand          = new System.Random();
                        int           ChanceDivider = Mathf.Max(1, 2 ^ ((Fields.MissionsDoneCurrentMonth + 1) - Mathf.RoundToInt((__instance.Constants.Finances.QuarterLength * settings.MissionChancePerDay))));
                        if (rand.NextDouble() < settings.MissionChancePerDay / ChanceDivider)
                        {
                            __instance.PauseTimer();
                            __instance.StopPlayMode();

                            SimGameInterruptManager interruptQueue = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(__instance);
                            Contract newcon = Helper.GetNewContract(__instance, Fields.DeploymentDifficulty, Fields.DeploymentEmployer, Fields.DeploymentTarget);
                            newcon.SetInitialReward(0);
                            newcon.Override.salvagePotential = Fields.DeploymentSalvage;
                            newcon.SetNegotiatedValues(Fields.DeploymentNegotiatedPayment, Fields.DeploymentNegotiatedSalvage);
                            newcon.Override.disableNegotations = true;
                            SimGameEventResult  simGameEventResult  = new SimGameEventResult();
                            SimGameResultAction simGameResultAction = new SimGameResultAction();
                            int num2 = 11;
                            simGameResultAction.Type                 = SimGameResultAction.ActionType.System_StartNonProceduralContract;
                            simGameResultAction.value                = newcon.mapName;
                            simGameResultAction.additionalValues     = new string[num2];
                            simGameResultAction.additionalValues[0]  = __instance.CurSystem.ID;
                            simGameResultAction.additionalValues[1]  = newcon.mapPath;
                            simGameResultAction.additionalValues[2]  = newcon.encounterObjectGuid;
                            simGameResultAction.additionalValues[3]  = newcon.Override.ID;
                            simGameResultAction.additionalValues[4]  = (!newcon.Override.useTravelCostPenalty).ToString();
                            simGameResultAction.additionalValues[5]  = Fields.DeploymentEmployer.ToString();
                            simGameResultAction.additionalValues[6]  = Fields.DeploymentTarget.ToString();
                            simGameResultAction.additionalValues[7]  = newcon.Difficulty.ToString();
                            simGameResultAction.additionalValues[8]  = "true";
                            simGameResultAction.additionalValues[9]  = Fields.DeploymentEmployer.ToString();
                            simGameResultAction.additionalValues[10] = newcon.Override.travelSeed.ToString();
                            simGameEventResult.Actions               = new SimGameResultAction[1];
                            simGameEventResult.Actions[0]            = simGameResultAction;
                            newcon.Override.OnContractSuccessResults.Add(simGameEventResult);
                            AccessTools.Field(typeof(SimGameState), "activeBreadcrumb").SetValue(__instance, newcon);
                            Fields.DeploymentContracts.Add(newcon.Name, newcon);
                            Action primaryAction = delegate() {
                                __instance.QueueCompleteBreadcrumbProcess(true);
                            };
                            interruptQueue.QueueTravelPauseNotification("New Mission", "Our Employer has a new mission for us.", __instance.GetCrewPortrait(SimGameCrew.Crew_Darius),
                                                                        string.Empty, new Action(primaryAction), "Proceed", new Action(__instance.OnBreadcrumbWait), "Not Yet");
                        }
                    }
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Пример #12
0
        // Run after completion of contracts and queue up any orders in the temp queue into the game's Mech Lab queue
        public static void Postfix(SimGameState __instance)
        {
            try
            {
                foreach (var mechDef in Core.CombatMechs)
                {
                    if (mechDef.MechDefCurrentStructure < mechDef.MechDefMaxStructure)
                    {
                        continue;
                    }

                    bool componentDamage = false;
                    for (int i = 0; i < mechDef.inventory.Length; i++)
                    {
                        if (mechDef.inventory[i].DamageLevel == ComponentDamageLevel.Destroyed ||
                            mechDef.inventory[i].DamageLevel == ComponentDamageLevel.NonFunctional)
                        {
                            componentDamage = true;
                        }
                    }
                    if (componentDamage)
                    {
                        continue;
                    }

                    var tempWO = Helpers.CreateBaseMechLabOrder(__instance, mechDef);
                    tempWO.AddSubEntry(Repair_ReArm.RepairArmorMechDef(mechDef));
                    Core.tempMechLabQueue.Add(tempWO);
                }


                // If there are any work orders in the temporary queue, prompt the player
                if (Core.tempMechLabQueue.Count > 0)
                {
                    Logger.LogDebug("Processing temp Mech Lab queue orders.");

                    int    cbills                   = 0;
                    int    techCost                 = 0;
                    int    mechRepairCount          = 0;
                    int    skipMechCount            = 0;
                    string mechRepairCountDisplayed = String.Empty;
                    string skipMechCountDisplayed   = String.Empty;
                    string skipMechMessage          = String.Empty;
                    string finalMessage             = String.Empty;

                    //int Counter = Core.tempMechLabQueue.Count;
                    //for (int index = Counter - 1; index < 0; index--)
                    //{
                    //    if (Counter == 0)
                    //        break;

                    //    WorkOrderEntry_MechLab order = Core.tempMechLabQueue[index];

                    //    LogDebug("Checking for destroyed components.");
                    //    bool destroyedComponents = false;
                    //    MechDef mech = __instance.GetMechByID(order.MechID);
                    //    if (mech != null)
                    //        destroyedComponents = Helpers.CheckDestroyedComponents(mech);
                    //    else
                    //        destroyedComponents = true;

                    //    if (destroyedComponents)
                    //    {
                    //        // Remove this work order from the temp mech lab queue if the mech has destroyed components and move to next iteration
                    //        Logger.LogDebug("Removing " + mech.Name + " order from temp queue due to destroyed components and mod settings.");
                    //        Core.tempMechLabQueue.Remove(order);
                    //        destroyedComponents = false;
                    //        skipMechCount++;
                    //    }
                    //}

                    // Calculate summary of total repair costs from the temp work order queue
                    for (int index = 0; index < Core.tempMechLabQueue.Count; index++)
                    {
                        if (Core.tempMechLabQueue.Count == 0)
                        {
                            break;
                        }

                        WorkOrderEntry_MechLab order = Core.tempMechLabQueue[index];
                        MechDef mech = __instance.GetMechByID(order.MechID);
                        LogDebug("Adding " + mech.Name + " to RepairCount.");
                        cbills   += order.GetCBillCost();
                        techCost += order.GetCost();
                        mechRepairCount++;
                    }

                    mechRepairCount = Mathf.Clamp(mechRepairCount, 0, 6);

                    // If Yang's Auto Repair prompt is enabled, build a message prompt dialog for the player
                    if (true)
                    {
                        // Calculate a friendly techCost of the work order in days, based on number of current mechtechs in the player's game.
                        if (techCost != 0 && __instance.MechTechSkill != 0)
                        {
                            techCost = Mathf.CeilToInt((float)techCost / (float)__instance.MechTechSkill);
                        }
                        else
                        {
                            techCost = 1; // Safety in case of weird div/0
                        }

                        // Generate a quick friendly description of how many mechs were damaged in battle
                        switch (mechRepairCount)
                        {
                        case 0: { Logger.LogDebug("mechRepairCount was 0."); break; }

                        case 1: { mechRepairCountDisplayed = "one of our 'Mechs had only its armor"; break; }

                        case 2: { mechRepairCountDisplayed = "a couple of the 'Mechs had only their armor"; break; }

                        case 3: { mechRepairCountDisplayed = "three of our 'Mechs had only their armor"; break; }

                        case 4: { mechRepairCountDisplayed = "an entire lance of ours had only their armor"; break; }

                        case 5: { mechRepairCountDisplayed = "five of our 'Mechs had only their armor"; break; }

                        case 6: { mechRepairCountDisplayed = "every 'Mech we dropped with had only their armor"; break; }
                        }
                        // Generate a friendly description of how many mechs were damaged but had components destroyed
                        switch (skipMechCount)
                        {
                        case 0: { Logger.LogDebug("skipMechCount was 0."); break; }

                        case 1: { skipMechCountDisplayed = "one of the 'Mechs is damaged but has"; break; }

                        case 2: { skipMechCountDisplayed = "two of the 'Mechs are damaged but have"; break; }

                        case 3: { skipMechCountDisplayed = "three of the 'Mechs are damaged but have "; break; }

                        case 4: { skipMechCountDisplayed = "the whole lance is damaged but has"; break; }
                        }

                        // Check if there are any mechs to process
                        if (mechRepairCount > 0 || skipMechCount > 0)
                        {
                            Logger.LogDebug("mechRepairCount is " + mechRepairCount + " skipMechCount is " + skipMechCount);

                            // Setup the notification for mechs with damaged components that we might want to skip
                            if (skipMechCount > 0 && mechRepairCount == 0)
                            {
                                skipMechMessage = String.Format("{0} destroyed components. I'll leave the repairs for you to review.", skipMechCountDisplayed);
                            }
                            else
                            {
                                skipMechMessage = String.Format("{0} destroyed components, so I'll leave those repairs to you.", skipMechCountDisplayed);
                            }

                            Logger.LogDebug("Firing Yang's UI notification.");
                            SimGameInterruptManager notificationQueue = __instance.GetInterruptQueue();

                            // If all of the mechs needing repairs have damaged components and should be skipped from auto-repair, change the message notification structure to make more sense (e.g. just have an OK button)
                            if (skipMechCount > 0 && mechRepairCount == 0)
                            {
                                finalMessage = String.Format(
                                    "Boss, {0} \n\n",
                                    skipMechMessage
                                    );

                                // Queue Notification
                                notificationQueue.QueuePauseNotification(
                                    "'Mech Armor Repairs Needed",
                                    finalMessage,
                                    __instance.GetCrewPortrait(SimGameCrew.Crew_Yang),
                                    string.Empty,
                                    delegate
                                {
                                    Logger.LogDebug("[PROMPT] All damaged mechs had destroyed components and won't be queued for repair.");
                                },
                                    "OK"
                                    );
                            }
                            else
                            {
                                if (skipMechCount > 0)
                                {
                                    finalMessage = String.Format(
                                        "Boss, {0} damaged. It'll cost <color=#DE6729>{1}{2:n0}</color> and {3} days for these repairs. Want my crew to get started?\n\nAlso, {4}\n\n",
                                        mechRepairCountDisplayed,
                                        '¢', cbills.ToString(),
                                        techCost.ToString(),
                                        skipMechMessage
                                        );
                                }
                                else
                                {
                                    finalMessage = String.Format(
                                        "Boss, {0} damaged on the last engagement. It'll cost <color=#DE6729>{1}{2:n0}</color> and {3} days for the repairs.\n\nWant my crew to get started?",
                                        mechRepairCountDisplayed,
                                        '¢', cbills.ToString(),
                                        techCost.ToString()
                                        );
                                }


                                // Queue up Yang's notification
                                notificationQueue.QueuePauseNotification(
                                    "'Mech Armor Repairs Needed",
                                    finalMessage,
                                    __instance.GetCrewPortrait(SimGameCrew.Crew_Yang),
                                    string.Empty,
                                    delegate
                                {
                                    Logger.LogDebug("[PROMPT] Moving work orders from temp queue to Mech Lab queue: " + Core.tempMechLabQueue.Count + " work orders");
                                    foreach (WorkOrderEntry_MechLab workOrder in Core.tempMechLabQueue.ToList())
                                    {
                                        Helpers.SubmitWorkOrder(__instance, workOrder);
                                        Core.tempMechLabQueue.Remove(workOrder);
                                    }
                                },
                                    "Yes",
                                    delegate
                                {
                                    foreach (WorkOrderEntry_MechLab workOrder in Core.tempMechLabQueue.ToList())
                                    {
                                        Core.tempMechLabQueue.Remove(workOrder);
                                    }
                                },
                                    "No"
                                    );
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.tempMechLabQueue.Clear();
                Error(ex);
            }
        }