private static void RandomizeMechs(SimGameState simGame) { Main.HBSLog.Log("Randomizing mechs, removing old mechs"); // clear the initial lance for (var i = 1; i < simGame.Constants.Story.StartingLance.Length + 1; i++) { simGame.ActiveMechs.Remove(i); } // remove ancestral mech if specified if (Main.Settings.RemoveAncestralMech) { Main.HBSLog.Log("\tRemoving ancestral mech"); simGame.ActiveMechs.Remove(0); } // add the random mechs to mechIds var mechIds = new List <string>(); mechIds.AddRange(GetRandomSubList(Main.Settings.AssaultMechsPossible, Main.Settings.NumberAssaultMechs)); mechIds.AddRange(GetRandomSubList(Main.Settings.HeavyMechsPossible, Main.Settings.NumberHeavyMechs)); mechIds.AddRange(GetRandomSubList(Main.Settings.MediumMechsPossible, Main.Settings.NumberMediumMechs)); mechIds.AddRange(GetRandomSubList(Main.Settings.LightMechsPossible, Main.Settings.NumberLightMechs)); // remove mechIDs that don't have a valid mechDef var numInvalid = mechIds.RemoveAll(id => !simGame.DataManager.MechDefs.Exists(id)); if (numInvalid > 0) { Main.HBSLog.LogWarning($"\tREMOVED {numInvalid} INVALID MECHS! Check mod.json for misspellings"); } // actually add the mechs to the game foreach (var mechID in mechIds) { var baySlot = simGame.GetFirstFreeMechBay(); var mechDef = new MechDef(simGame.DataManager.MechDefs.Get(mechID), simGame.GenerateSimGameUID()); if (baySlot >= 0) { Main.HBSLog.Log($"\tAdding {mechID} to bay {baySlot}"); simGame.AddMech(baySlot, mechDef, true, true, false); } else { Main.HBSLog.Log($"\tAdding {mechID} to storage, bays are full"); simGame.AddItemStat(mechDef.Chassis.Description.Id, mechDef.GetType(), false); } } }
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(); }
public static void UnStorageOmniMechPopup(SimGameState s, MechDef d, Action onClose) { if (Settings.OmniMechTag == null) { onClose?.Invoke(); throw new InvalidOperationException("omnimechs disabled"); } int mechbay = s.GetFirstFreeMechBay(); if (mechbay < 0) { onClose?.Invoke(); return; } IEnumerable <MechDef> mechs = GetAllOmniVariants(s, d); string desc = "Yang: We know the following Omni variants. What should I ready this 'Mech as?\n\n"; GenericPopupBuilder pop = GenericPopupBuilder.Create("Ready 'Mech?", desc); pop.AddButton("nothing", onClose, true, null); foreach (MechDef m in mechs) { MechDef var = m; // new var to keep it for lambda if (!CheckOmniKnown(s, d, m)) { if (Settings.ShowAllVariantsInPopup) { pop.Body += $"unknown: [[DM.MechDefs[{m.Description.Id}],{m.Chassis.Description.UIName} {m.Chassis.VariantName}]]\n"; } continue; } pop.AddButton($"{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); onClose?.Invoke(); }, true, null); int com = GetNumberOfMechsOwnedOfType(s, m); int cost = m.GetMechSellCost(s); pop.Body += $"[[DM.MechDefs[{m.Description.Id}],{m.Chassis.Description.UIName} {m.Chassis.VariantName}]] ({com} Complete) ({SimGameState.GetCBillString(cost)})\n"; } pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true); pop.Render(); }
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); }
/// <summary> /// Adds a lance to the player's roster (possibly to storage if space is insufficient) /// </summary> /// <param name="simGame"></param> /// <param name="lance"></param> private static void ApplyLance(SimGameState simGame, List <MechDef> lance) { // actually add the mechs to the game, in descending order of tonnage foreach (var mechDef in lance.OrderBy(mech => - mech.Chassis.Tonnage)) { // pick a slot, and generate the mechdef a UID var baySlot = simGame.GetFirstFreeMechBay(); var concreteMech = new MechDef(mechDef, simGame.GenerateSimGameUID()); if (baySlot >= 0) { Logger.Log($"\tAdding {concreteMech.ChassisID} to bay {baySlot}"); simGame.AddMech(baySlot, concreteMech, true, true, false); } else { Logger.Log($"\tAdding {concreteMech.ChassisID} to storage, bays are full"); simGame.AddItemStat(concreteMech.Chassis.Description.Id, concreteMech.GetType(), false); } } }
private static void AddBullsharkLT(SimGameState s) { MechDef d = s.DataManager.MechDefs.Get("mechdef_bullshark_BSK-LT"); d = new MechDef(d, s.GenerateSimGameUID(), true); d.SetInventory(d.Inventory.Where((x) => x.IsFixed || x.ComponentDefID.Equals("Ammo_AmmunitionBox_Generic_LongTom")).ToArray()); int baySlot = s.GetFirstFreeMechBay(); int mechReadyTime = 625000; // about 50 days WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech(string.Format("ReadyMech-{0}", d.GUID), string.Format("Readying 'Mech - {0}", new object[] { d.Chassis.Description.Name }), mechReadyTime, baySlot, d, string.Format(s.Constants.Story.MechReadiedWorkOrderCompletedText, new object[] { d.Chassis.Description.Name })); s.MechLabQueue.Add(workOrderEntry_ReadyMech); s.ReadyingMechs[baySlot] = d; s.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech); s.UpdateMechLabWorkQueue(false); AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech", WwiseManager.GlobalAudioObject, null); }
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; }
private static void RandomizeMechs(SimGameState simGame) { Main.HBSLog.Log("Randomizing mechs, removing old mechs"); // clear the initial lance for (var i = 1; i < simGame.Constants.Story.StartingLance.Length + 1; i++) { simGame.ActiveMechs.Remove(i); } // remove ancestral mech if specified if (Main.Settings.RemoveAncestralMech) { Main.HBSLog.Log("\tRemoving ancestral mech"); simGame.ActiveMechs.Remove(0); } List <string> possibleMechs; if (Main.Settings.UseWhitelist) { possibleMechs = new List <string>(Main.Settings.Whitelist); // remove items on whitelist that aren't in the datamanager possibleMechs.FindAll(id => !simGame.DataManager.MechDefs.Exists(id)) .Do(id => Main.HBSLog.LogWarning($"\tInvalid MechDef '{id}'. Will remove from possibilities")); possibleMechs.RemoveAll(id => !simGame.DataManager.MechDefs.Exists(id)); } else { possibleMechs = new List <string>(simGame.DataManager.MechDefs.Keys); // remove mechs with tags possibleMechs.FindAll(id => simGame.DataManager.MechDefs.Get(id).MechTags.Contains("BLACKLISTED")) .Do(id => Main.HBSLog.Log($"\tRemoving blacklisted (by tag) MechDef '{id}' from possibilities")); possibleMechs.RemoveAll(id => simGame.DataManager.MechDefs.Get(id).MechTags.Contains("BLACKLISTED")); // remove mechs from blacklist in settings var intersect = possibleMechs.Intersect(Main.Settings.Blacklist).ToArray(); foreach (var id in intersect) { Main.HBSLog.Log($"\tRemoving blacklisted (by settings) MechDef '{id}' from possibilities"); possibleMechs.Remove(id); } } // sort possible mechs into buckets var assault = new List <string>(possibleMechs .FindAll(id => simGame.DataManager.MechDefs.Get(id).Chassis.weightClass == WeightClass.ASSAULT)); var heavy = new List <string>(possibleMechs .FindAll(id => simGame.DataManager.MechDefs.Get(id).Chassis.weightClass == WeightClass.HEAVY)); var medium = new List <string>(possibleMechs .FindAll(id => simGame.DataManager.MechDefs.Get(id).Chassis.weightClass == WeightClass.MEDIUM)); var light = new List <string>(possibleMechs .FindAll(id => simGame.DataManager.MechDefs.Get(id).Chassis.weightClass == WeightClass.LIGHT)); // add the random mechs to mechIds var mechIds = new List <string>(); mechIds.AddRange(GetRandomSubList(assault, Main.Settings.NumberAssaultMechs)); mechIds.AddRange(GetRandomSubList(heavy, Main.Settings.NumberHeavyMechs)); mechIds.AddRange(GetRandomSubList(medium, Main.Settings.NumberMediumMechs)); mechIds.AddRange(GetRandomSubList(light, Main.Settings.NumberLightMechs)); // actually add the mechs to the game foreach (var mechID in mechIds) { var baySlot = simGame.GetFirstFreeMechBay(); var mechDef = new MechDef(simGame.DataManager.MechDefs.Get(mechID), simGame.GenerateSimGameUID()); if (baySlot >= 0) { Main.HBSLog.Log($"\tAdding {mechID} to bay {baySlot}"); simGame.AddMech(baySlot, mechDef, true, true, false); } else { Main.HBSLog.Log($"\tAdding {mechID} to storage, bays are full"); simGame.AddItemStat(mechDef.Chassis.Description.Id, mechDef.GetType(), false); } } }
public static void PerformMechAssemblyStorePopup(SimGameState s, MechDef d, Action onClose) { WwiseManager.PostEvent(AudioEventList_ui.ui_sim_popup_newChassis, WwiseManager.GlobalAudioObject, null, null); MechDef toAdd = PerformMechAssembly(s, d); int mechbay; if (toAdd.IsVehicle()) { mechbay = CUIntegration.GetFirstFreeMechBay(s, d); // vehicle bay, +100 or something similar } else { mechbay = s.GetFirstFreeMechBay(); } GenericPopupBuilder pop = GenericPopupBuilder.Create($"{d.GetMechOmniVehicle()} Assembled", $"Yang: [[DM.MechDefs[{d.Description.Id}],{d.Chassis.Description.UIName} {d.Chassis.VariantName}]] finished!\n{d.Chassis.YangsThoughts}\n\n"); pop.AddButton("storage", delegate { StoreMech(s, toAdd); CallMessages(s, toAdd); Log.Log("direct storage"); onClose?.Invoke(); }, true, null); if (mechbay < 0) // no space - direct storage { pop.Body += $"We have no space for a new {d.GetMechOmniVehicle()}, so it goes into storage."; } else { pop.Body += "Should I put it into storage or ready it for combat?"; pop.AddButton("ready it", delegate { if (Settings.AssembledMechsNeedReadying) { ReadyMech(s, toAdd, mechbay); CallMessages(s, toAdd); } else { s.AddMech(mechbay, toAdd, true, false, false); CallMessages(s, toAdd); } Log.Log("added to bay " + mechbay); onClose?.Invoke(); }, true, null); } if (s.IsSellingAllowed()) { int cost = toAdd.GetMechSellCost(s); pop.Body += $"\n\nDarius: We could also sell it for {SimGameState.GetCBillString(cost)}, although Yang would certanly not like it."; pop.AddButton("sell it", delegate { s.AddFunds(cost, "Store", true, true); Log.Log("sold for " + cost); s.CompanyStats.ModifyStat("Mission", 0, "COMPANY_MechsAdded", StatCollection.StatOperation.Int_Add, 1, -1, true); CallMessages(s, toAdd); onClose?.Invoke(); }, true, null); } pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true); pop.Render(); }
public static void Postfix(SimGameState __instance) { if (HasBullShark(__instance) && !__instance.CompanyTags.Contains("bullshark_cac_lt_upgrade") && __instance.GetFirstFreeMechBay() >= 0 && __instance.Funds > 10000000 && __instance.NetworkRandom.Int(0, 100) < 10) { ShowLongTomSpecial(__instance); } }
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(); } }