public static bool FixGetMechdef(ref ShopDefItem itemDef, Shop shop, bool isBulkAdd, bool isSelling, IMechLabDropTarget targetWidget, MechLabInventoryWidget_ListView ___inventoryWidget, bool ___isInBuyingState, SimGameState ___simState, SG_Shop_Screen __instance) { if (itemDef.Type == ShopItemType.Mech && !___isInBuyingState) { var dataManager = ___simState.DataManager; string guid8 = itemDef.GUID; if (dataManager.ChassisDefs.Exists(guid8)) { ChassisDef chassisDef = dataManager.ChassisDefs.Get(guid8); string newGUID = ___simState.GenerateSimGameUID(); var id = ChassisHandler.GetMDefFromCDef(guid8); MechDef stockMech = dataManager.MechDefs.Get(id); MechDef mechDef3 = new MechDef(chassisDef, newGUID, stockMech); mechDef3.Refresh(); if (mechDef3 != null) { InventoryDataObject_ShopFullMech inventoryDataObject_ShopFullMech2 = new InventoryDataObject_ShopFullMech(); inventoryDataObject_ShopFullMech2.Init(mechDef3, itemDef, shop, ___simState, dataManager, targetWidget, itemDef.Count, isSelling, new UnityAction <InventoryItemElement>(__instance.OnItemSelected)); ___inventoryWidget.AddItemToInventory(inventoryDataObject_ShopFullMech2, isBulkAdd); inventoryDataObject_ShopFullMech2.SetItemDraggable(false); } } return(false); } return(true); }
public static MechComponentRef[] ClearInventory(MechDef source_mech, SimGameState state) { Control.LogDebug(DType.ClearInventory, "Clearing Inventory"); var list = source_mech.Inventory.ToList(); var changes = new Queue <IChange>(); foreach (var mechComponentRef in list.Where(i => !i.IsFixed)) { changes.Enqueue(new Change_Remove(mechComponentRef, mechComponentRef.MountedLocation)); } var inv_state = new InventoryOperationState(changes, source_mech); inv_state.DoChanges(); var to_apply = inv_state.GetResults(); foreach (var invChange in to_apply) { invChange.ApplyToInventory(source_mech, list); } Control.LogDebug(DType.ClearInventory, $"- setting guids"); foreach (var item in list) { if (string.IsNullOrEmpty(item.SimGameUID)) { item.SetSimGameUID(state.GenerateSimGameUID()); } Control.LogDebug(DType.ClearInventory, $"-- {item.ComponentDefID} - {item.SimGameUID}"); } return(list.ToArray()); }
public static MechDef PerformMechAssembly(SimGameState s, MechDef d) { Log.Log("mech assembly: " + d.Description.Id); IEnumerable <MechDef> mechs = GetAllAssemblyVariants(s, d); int requiredParts = s.Constants.Story.DefaultMechPartMax; requiredParts -= MechAssemblyRemoveParts(s, d, requiredParts, 0); // use all base variant parts if (requiredParts > 0) { foreach (MechDef v in mechs) { requiredParts -= MechAssemblyRemoveParts(s, v, requiredParts, 1); // try to leave 1 part of each variant } } if (requiredParts > 0) { foreach (MechDef v in mechs) { requiredParts -= MechAssemblyRemoveParts(s, v, requiredParts, 0); // use last part of variant } } if (requiredParts > 0) { throw new InvalidOperationException("not enough parts! your parts are now lost!"); // should never happen, we checked before if we have enough } return(new MechDef(d, s.GenerateSimGameUID(), d.IsVehicle() || s.Constants.Salvage.EquipMechOnSalvage)); }
internal static void FixSimGameUID(SimGameState sim, MechComponentRef componentRef) { if (sim == null) { return; } var engineRef = componentRef.GetEngineCoreRef(); if (engineRef == null) { return; } //Control.mod.Logger.LogDebug($"mechDef={Global.ActiveMechDef?.Name}"); if (engineRef.UUID != null) { //Control.mod.Logger.LogDebug($"engineRef.GetNewSimGameUID={engineRef.GetNewSimGameUID()}"); return; } engineRef.UUID = sim.GenerateSimGameUID(); componentRef.SetSimGameUID(engineRef.GetNewSimGameUID()); //Control.mod.Logger.LogDebug($"componentRef.SimGameUID={componentRef.SimGameUID}"); }
public static MechComponentRef[] ClearInventory(MechDef source, SimGameState state) { Control.LogDebug(DType.ClearInventory, "Clearing Inventory"); var list = source.Inventory.ToList(); var result_list = list.Where(i => i.IsFixed).ToList(); for (int i = list.Count - 1; i >= 0; i--) { Control.LogDebug(DType.ClearInventory, $"- {list[i].ComponentDefID} - {(list[i].Def == null ? "NULL" : list[i].SimGameUID)}"); if (list[i].Def == null) { list[i].RefreshComponentDef(); list[i].SetSimGameUID(state.GenerateSimGameUID()); } if (list[i].IsFixed) { Control.LogDebug(DType.ClearInventory, "-- fixed - skipping"); continue; } foreach (var clear in list[i].GetComponents <IClearInventory>()) { clear.ClearInventory(source, result_list, state, list[i]); } } foreach (var clearInventoryDelegate in Validator.clear_inventory) { clearInventoryDelegate(source, result_list, state); } foreach (var item in result_list) { if (string.IsNullOrEmpty(item.SimGameUID)) { item.SetSimGameUID(state.GenerateSimGameUID()); } Control.LogDebug(DType.ClearInventory, $"- {item.ComponentDefID} - {item.SimGameUID}"); } return(result_list.ToArray()); }
private static void Postfix(ref SimGameState __instance, ref string mechSimGameUID, ref ChassisLocations location, ref int structureCount, ref WorkOrderEntry_RepairMechStructure __result) { try { float mechTonnageModifier = 1f; // Original method code, this is still needed to work out zero structure modifiers string id = string.Format("MechLab - RepairMech - {0}", __instance.GenerateSimGameUID()); bool flag = false; float num = 1f; float num2 = 1f; foreach (MechDef mechDef in __instance.ActiveMechs.Values) { if (mechDef.GUID == mechSimGameUID) { // If ScaleStructureCostByTonnage is enabled, make the mech tonnage work as a percentage tech cost reduction (95 tons = 0.95 or "95%" of the cost, 50 tons = 0.05 or "50%" of the cost etc) if (ArmorRepair.ModSettings.ScaleStructureCostByTonnage) { mechTonnageModifier = mechDef.Chassis.Tonnage * 0.01f; } if (mechDef.GetChassisLocationDef(location).InternalStructure == (float)structureCount) { flag = true; } break; } } if (flag) { num = __instance.Constants.MechLab.ZeroStructureCBillModifier; num2 = __instance.Constants.MechLab.ZeroStructureTechPointModifier; } int techCost = Mathf.CeilToInt((__instance.Constants.MechLab.StructureRepairTechPoints * (float)structureCount * num2) * mechTonnageModifier); int cbillCost = Mathf.CeilToInt((float)((__instance.Constants.MechLab.StructureRepairCost * structureCount) * num) * mechTonnageModifier); Logger.LogDebug("Structure WO Subentry Costing:"); Logger.LogDebug("***************************************"); Logger.LogDebug("location: " + location.ToString()); Logger.LogDebug("structureCount: " + structureCount); Logger.LogDebug("mechTonnageModifier: " + mechTonnageModifier); Logger.LogDebug("techCost: " + techCost); Logger.LogDebug("cBill cost: " + cbillCost); Logger.LogDebug("***************************************"); __result = new WorkOrderEntry_RepairMechStructure(id, string.Format("Repair 'Mech - {0}", location.ToString()), mechSimGameUID, techCost, location, structureCount, cbillCost, string.Empty); } catch (Exception ex) { Logger.LogError(ex); } }
internal static MechComponentRef CreateMechComponentRef(string id, SimGameState sim, DataManager dataManager) { var def = dataManager.GetObjectOfType <HeatSinkDef>(id, BattleTechResourceType.HeatSinkDef); var @ref = new MechComponentRef(def.Description.Id, sim.GenerateSimGameUID(), def.ComponentType, ChassisLocations.None); @ref.DataManager = dataManager; @ref.SetComponentDef(def); return(@ref); }
public static MechComponentRef CreateRef(string id, ComponentType type, DataManager datamanager, SimGameState state) { var component_ref = new MechComponentRef(id, string.Empty, type, ChassisLocations.None); component_ref.DataManager = datamanager; component_ref.RefreshComponentDef(); if (state != null) { component_ref.SetSimGameUID(state.GenerateSimGameUID()); } return(component_ref); }
public void ClearInventory(MechDef mech, List <MechComponentRef> result, SimGameState state, MechComponentRef source) { var ref_item = new MechComponentRef(ComponentDefId, state.GenerateSimGameUID(), source.ComponentDefType, Location == ChassisLocations.None ? source.MountedLocation : Location, isFixed: true) { DataManager = state.DataManager }; ref_item.RefreshComponentDef(); result.Add(ref_item); Control.LogDebug(DType.ClearInventory, $"-- Replace with {ref_item.ComponentDefID} - {ref_item.SimGameUID}"); }
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(); }
internal static void FixSimGameUID(SimGameState sim, MechComponentRef componentRef) { var engineRef = componentRef.GetEngineCoreRef(null); if (engineRef == null) { return; } if (engineRef.UUID != null) { return; } engineRef.UUID = sim.GenerateSimGameUID(); componentRef.SetSimGameUID(engineRef.GetNewSimGameUID()); }
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(); }
private static void Postfix(ref SimGameState __instance, ref string mechSimGameUID, ref ChassisLocations location, ref int armorDiff, ref int frontArmor, ref int rearArmor, ref WorkOrderEntry_ModifyMechArmor __result) { string id = string.Format("MechLab - ModifyArmor - {0}", __instance.GenerateSimGameUID()); try { float mechTonnageModifier = 1f; int techCost = 0; int cbillCost = 0; foreach (MechDef mechDef in __instance.ActiveMechs.Values) { if (mechDef.GUID == mechSimGameUID) { // If ScaleArmorCostByTonnage is enabled, make the mech tonnage work as a percentage tech cost reduction (95 tons = 0.95 or "95%" of the cost, 50 tons = 0.05 or "50%" of the cost etc) if (ArmorRepair.ModSettings.ScaleArmorCostByTonnage) { mechTonnageModifier = mechDef.Chassis.Tonnage * 0.01f; } float locationTechCost = ((armorDiff * mechTonnageModifier) * __instance.Constants.MechLab.ArmorInstallTechPoints); float locationCbillCost = ((armorDiff * mechTonnageModifier) * __instance.Constants.MechLab.ArmorInstallCost); techCost = Mathf.CeilToInt(locationTechCost); cbillCost = Mathf.CeilToInt(locationCbillCost); Logger.LogDebug("Armor WO SubEntry Costing: "); Logger.LogDebug("***************************************"); Logger.LogDebug("location: " + location.ToString()); Logger.LogDebug("armorDifference: " + armorDiff); Logger.LogDebug("mechTonnage: " + mechDef.Chassis.Tonnage); Logger.LogDebug("mechTonnageModifier: " + mechTonnageModifier); Logger.LogDebug("techCost: " + techCost); Logger.LogDebug("cbillCost: " + cbillCost); Logger.LogDebug("***************************************"); } } __result = new WorkOrderEntry_ModifyMechArmor(id, string.Format("Modify Armor - {0}", location.ToString()), mechSimGameUID, techCost, location, frontArmor, rearArmor, cbillCost, string.Empty); } catch (Exception ex) { Logger.LogError(ex); } }
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); }
/// <summary> /// Easter Egg. If the ancestral mech is a FLEA, and the setting is enabled, then infest the ship... /// </summary> /// <param name="simGame"></param> private static void Infestation(SimGameState simGame) { // Open bays 0-11, the extra 2 drop spots, and command consoles to match (assumes BT:R) simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_structure1")); simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_mechBay2")); simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_JunkyardLeopard")); simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_DropSlot")); simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_DropSlot1")); simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_PilotSlot")); simGame.AddArgoUpgrade(simGame.DataManager.ShipUpgradeDefs.Get("argoUpgrade_PilotSlot1")); simGame.ApplyArgoUpgrades(); List <MechDef> lance = new List <MechDef>(); var fle4 = simGame.DataManager.MechDefs.Get("mechdef_flea_FLE-4"); var fle15 = simGame.DataManager.MechDefs.Get("mechdef_flea_FLE-15"); var fle4rv = simGame.DataManager.MechDefs.Get("mechdef_flea_FLE-4-RV"); var fle15rv = simGame.DataManager.MechDefs.Get("mechdef_flea_FLE-15-RV"); lance.Add(fle4); lance.Add(fle4); lance.Add(fle4); lance.Add(fle4); lance.Add(fle4rv); lance.Add(fle4rv); lance.Add(fle15); lance.Add(fle15); lance.Add(fle15); lance.Add(fle15); lance.Add(fle15rv); lance.Add(fle15rv); //ApplyLance(simGame, lance); // For some reason, bays 6-11 still aren't marked as available at this point // ... but manually forcing the mechs into those bays seems to work fine. for (int i = 0; i < lance.Count; ++i) { var mech = new MechDef(lance[i], simGame.GenerateSimGameUID()); Logger.Log($"\tAdding {mech.ChassisID} to bay {i}"); simGame.AddMech(i, mech, true, true, 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); } } }
private static void Postfix(ref SimGameState __instance, ref string mechSimGameUID, ref ChassisLocations location, ref int armorDiff, ref int frontArmor, ref int rearArmor, ref WorkOrderEntry_ModifyMechArmor __result) { string id = string.Format("MechLab - ModifyArmor - {0}", __instance.GenerateSimGameUID()); try { float mechTonnageModifier = 1f; int techCost = 0; int cbillCost = 0; foreach (MechDef mechDef in __instance.ActiveMechs.Values) { if (mechDef.GUID == mechSimGameUID) { ArmorRepairFactor armor = null; MechComponentRef armoritem = null; foreach (var item in mechDef.Inventory) { if (item.IsCategory(ArmorRepair.ModSettings.ArmorCategory)) { armor = item.GetComponent <ArmorRepairFactor>(); armoritem = item; break; } } Logger.LogDebug("Armor WO SubEntry Costing: "); Logger.LogDebug("***************************************"); Logger.LogDebug(" location: " + location.ToString()); Logger.LogDebug(" armorDifference: " + armorDiff); Logger.LogDebug(" mechTonnage: " + mechDef.Chassis.Tonnage); Logger.LogDebug(" mechTonnageModifier: " + mechTonnageModifier); if (armor != null) { Logger.LogDebug($" ArmorRepair mods tp:{armor.ArmorTPCost:0.00} cb:{armor.ArmorCBCost:0.00}"); } float atpcost = armor?.ArmorTPCost ?? 1; float acbcost = armor?.ArmorCBCost ?? 1; if (ArmorRepair.ModSettings.RepairCostByTag != null && ArmorRepair.ModSettings.RepairCostByTag.Length > 0) { foreach (var cost in ArmorRepair.ModSettings.RepairCostByTag) { if (mechDef.Chassis.ChassisTags.Contains(cost.Tag)) { Logger.LogDebug($" Chassis {cost.Tag} mods tp:{cost.ArmorTPCost:0.00} cb:{cost.ArmorCBCost:0.00}"); atpcost *= cost.ArmorTPCost; acbcost *= cost.ArmorCBCost; } if (armoritem != null && armoritem.Def.ComponentTags.Contains(cost.Tag)) { Logger.LogDebug($" {armoritem.ComponentDefID} {cost.Tag} mods tp:{cost.ArmorTPCost:0.00} cb:{cost.ArmorCBCost:0.00}"); atpcost *= cost.ArmorTPCost; acbcost *= cost.ArmorCBCost; } } } // If ScaleArmorCostByTonnage is enabled, make the mech tonnage work as a percentage tech cost reduction (95 tons = 0.95 or "95%" of the cost, 50 tons = 0.05 or "50%" of the cost etc) if (ArmorRepair.ModSettings.ScaleArmorCostByTonnage) { mechTonnageModifier = mechDef.Chassis.Tonnage * 0.01f; } float locationTechCost = ((armorDiff * mechTonnageModifier) * __instance.Constants.MechLab.ArmorInstallTechPoints) * atpcost; float locationCbillCost = ((armorDiff * mechTonnageModifier) * __instance.Constants.MechLab.ArmorInstallCost) * acbcost; techCost = Mathf.CeilToInt(locationTechCost); cbillCost = Mathf.CeilToInt(locationCbillCost); Logger.LogDebug($" tpmod: {atpcost:0.000}"); Logger.LogDebug($" cbmod: {acbcost:0.000}"); Logger.LogDebug(" techCost: " + techCost); Logger.LogDebug(" cbillCost: " + cbillCost); Logger.LogDebug("***************************************"); } } __result = new WorkOrderEntry_ModifyMechArmor(id, string.Format("Modify Armor - {0}", location.ToString()), mechSimGameUID, techCost, location, frontArmor, rearArmor, cbillCost, string.Empty); } catch (Exception ex) { Logger.LogError(ex); } }
private static bool Prefix(SimGameState __instance, string id) { try { __instance.AddItemStat(id, "MECHPART", false); Settings settings = Helper.Settings; Dictionary <MechDef, int> possibleMechs = new Dictionary <MechDef, int>(); MechDef currentVariant = __instance.DataManager.MechDefs.Get(id); int itemCount = 0; if (settings.AssembleVariants && !settings.VariantExceptions.Contains(id)) { foreach (KeyValuePair <string, MechDef> pair in __instance.DataManager.MechDefs) { if (pair.Value.Chassis.PrefabIdentifier.Equals(currentVariant.Chassis.PrefabIdentifier) && !settings.VariantExceptions.Contains(pair.Value.Description.Id) && pair.Value.Chassis.Tonnage.Equals(__instance.DataManager.MechDefs.Get(id).Chassis.Tonnage)) { int numberOfParts = __instance.GetItemCount(pair.Value.Description.Id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY); if (numberOfParts > 0) { itemCount += numberOfParts; possibleMechs.Add(new MechDef(pair.Value, __instance.GenerateSimGameUID()), numberOfParts); } } } } else { itemCount = __instance.GetItemCount(id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY); } int defaultMechPartMax = __instance.GetMechPartsRequired(currentVariant); if (itemCount >= defaultMechPartMax) { MechDef mechDef = null; List <KeyValuePair <MechDef, int> > mechlist = possibleMechs.ToList(); mechlist = possibleMechs.OrderByDescending(o => o.Value).ToList(); if (settings.AssembleVariants && !settings.VariantExceptions.Contains(id)) { if (settings.AssembleMostParts) { // This is the list of mechs which have the most parts // (there could be more than one if the parts are equal) // Don't include the variant which we've just found a part for. List <MechDef> topMechList = new List <MechDef>(); if (mechlist[0].Key.ChassisID != currentVariant.ChassisID) { topMechList.Add(mechlist[0].Key); } for (int mechlistI = 1; mechlistI < mechlist.Count && mechlist[mechlistI - 1].Value == mechlist[mechlistI].Value; ++mechlistI) { MechDef mechToAdd = mechlist[mechlistI].Key; if (mechToAdd.ChassisID != currentVariant.ChassisID) { topMechList.Add(mechlist[mechlistI].Key); } } // Now if the most parts list is empty, choose the current variant. // If it has one element, choose it // (we prefer the variant which we have previously had the parts for, all else being equal) // if there's more than one variant, choose one from this list randomly. // // This approach gives the commander some control over what variant will be assembled. // For example, if the commander has 3 of one variant and 2 of another and the parts required is 6, // they can be sure that the first variant will be constructed once they get another part // no matter what it is. // So commanders can sell parts if they choose to manipulate this. switch (topMechList.Count) { case 0: mechDef = currentVariant; break; case 1: mechDef = topMechList[0]; break; default: Random rand = new Random(); int roll = (int)rand.NextDouble() * topMechList.Count; mechDef = topMechList[Math.Min(roll, topMechList.Count - 1)]; break; } } else { Random rand = new Random(); int numberOfDifferentVariants = mechlist.Count; double roll = rand.NextDouble(); double currentTotal = 0; foreach (KeyValuePair <MechDef, int> mech in mechlist) { currentTotal += (double)mech.Value / (double)defaultMechPartMax; if (roll <= currentTotal) { mechDef = mech.Key; break; } } } int j = 0; int i = 0; int currentPart = 1; while (i < defaultMechPartMax) { if (currentPart > mechlist[j].Value) { j++; currentPart = 1; } ReflectionHelper.InvokePrivateMethode(__instance, "RemoveItemStat", new object[] { mechlist[j].Key.Description.Id, "MECHPART", false }); currentPart++; i++; } } else { for (int i = 0; i < defaultMechPartMax; i++) { ReflectionHelper.InvokePrivateMethode(__instance, "RemoveItemStat", new object[] { id, "MECHPART", false }); } mechDef = new MechDef(__instance.DataManager.MechDefs.Get(id), __instance.GenerateSimGameUID()); } Random rng = new Random(); if (!settings.HeadRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.Head.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.Head.CurrentInternalStructure = Math.Max(1f, mechDef.Head.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.LeftArmRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.LeftArm.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.LeftArm.CurrentInternalStructure = Math.Max(1f, mechDef.LeftArm.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.RightArmRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.RightArm.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.RightArm.CurrentInternalStructure = Math.Max(1f, mechDef.RightArm.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.LeftLegRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.LeftLeg.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.LeftLeg.CurrentInternalStructure = Math.Max(1f, mechDef.LeftLeg.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.RightLegRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.RightLeg.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.RightLeg.CurrentInternalStructure = Math.Max(1f, mechDef.RightLeg.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.CentralTorsoRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.CenterTorso.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.CenterTorso.CurrentInternalStructure = Math.Max(1f, mechDef.CenterTorso.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.RightTorsoRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.RightTorso.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.RightTorso.CurrentInternalStructure = Math.Max(1f, mechDef.RightTorso.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.LeftTorsoRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.LeftTorso.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.LeftTorso.CurrentInternalStructure = Math.Max(1f, mechDef.LeftTorso.CurrentInternalStructure * (float)rng.NextDouble()); } // each component is checked and destroyed if the settings are set that way // if RepairMechComponents is true it will variably make components either functional, nonfunctional, or destroyed based on settings foreach (MechComponentRef mechComponent in mechDef.Inventory) { if (!settings.RepairMechComponents || mechDef.IsLocationDestroyed(mechComponent.MountedLocation)) { mechComponent.DamageLevel = ComponentDamageLevel.Destroyed; continue; } if (settings.RepairMechComponents) { double repairRoll = rng.NextDouble(); if (repairRoll <= settings.RepairComponentsFunctionalThreshold) { mechComponent.DamageLevel = ComponentDamageLevel.Functional; } else if (repairRoll <= settings.RepairComponentsNonFunctionalThreshold) { mechComponent.DamageLevel = ComponentDamageLevel.NonFunctional; } else { mechComponent.DamageLevel = ComponentDamageLevel.Destroyed; } } } __instance.AddMech(0, mechDef, true, false, true, null); SimGameInterruptManager interrupt = (SimGameInterruptManager)ReflectionHelper.GetPrivateField(__instance, "interruptQueue"); interrupt.DisplayIfAvailable(); __instance.MessageCenter.PublishMessage(new SimGameMechAddedMessage(mechDef, defaultMechPartMax, true)); } return(false); } catch (Exception e) { Logger.LogError(e); return(true); } }
public static void Postfix(SimGameState __instance) { if (RngStart.Settings.NumberRandomRonin + RngStart.Settings.NumberProceduralPilots + RngStart.Settings.NumberRoninFromList > 0) { while (__instance.PilotRoster.Count > 0) { __instance.PilotRoster.RemoveAt(0); } List <PilotDef> list = new List <PilotDef>(); if (RngStart.Settings.StartingRonin != null) { var RoninRandomizer = new List <string>(); RoninRandomizer.AddRange(GetRandomSubList(RngStart.Settings.StartingRonin, RngStart.Settings.NumberRoninFromList)); foreach (var roninID in RoninRandomizer) { var pilotDef = __instance.DataManager.PilotDefs.Get(roninID); // add directly to roster, don't want to get duplicate ronin from random ronin if (pilotDef != null) { __instance.AddPilotToRoster(pilotDef, true); } } } if (RngStart.Settings.NumberRandomRonin > 0) { List <PilotDef> list2 = new List <PilotDef>(__instance.RoninPilots); for (int m = list2.Count - 1; m >= 0; m--) { for (int n = 0; n < __instance.PilotRoster.Count; n++) { if (list2[m].Description.Id == __instance.PilotRoster[n].Description.Id) { list2.RemoveAt(m); break; } } } list2.RNGShuffle <PilotDef>(); for (int i = 0; i < RngStart.Settings.NumberRandomRonin; i++) { list.Add(list2[i]); } } if (RngStart.Settings.NumberProceduralPilots > 0) { List <PilotDef> list3; List <PilotDef> collection = __instance.PilotGenerator.GeneratePilots(RngStart.Settings.NumberProceduralPilots, 1, 0f, out list3); list.AddRange(collection); } foreach (PilotDef def in list) { __instance.AddPilotToRoster(def, true); } } //Logger.Debug($"Starting lance creation {RngStart.Settings.MinimumStartingWeight} - {RngStart.Settings.MaximumStartingWeight} tons"); // mechs if (RngStart.Settings.UseRandomMechs) { var AncestralMechDef = new MechDef(__instance.DataManager.MechDefs.Get(__instance.ActiveMechs[0].Description.Id), __instance.GenerateSimGameUID()); bool RemoveAncestralMech = RngStart.Settings.RemoveAncestralMech; if (AncestralMechDef.Description.Id == "mechdef_centurion_TARGETDUMMY") { RemoveAncestralMech = true; } var lance = new List <MechDef>(); float currentLanceWeight = 0; var baySlot = 1; // clear the initial lance for (var i = 1; i < 6; i++) { __instance.ActiveMechs.Remove(i); } // memoize dictionary of tonnages since we may be looping a lot //Logger.Debug($"Memoizing"); var mechTonnages = new Dictionary <string, float>(); foreach (var kvp in __instance.DataManager.ChassisDefs) { if (kvp.Key.Contains("DUMMY") && !kvp.Key.Contains("CUSTOM")) { // just in case someone calls their mech DUMMY continue; } if (kvp.Key.Contains("CUSTOM") || kvp.Key.Contains("DUMMY")) { continue; } if (RngStart.Settings.MaximumMechWeight != 100) { if (kvp.Value.Tonnage > RngStart.Settings.MaximumMechWeight || kvp.Value.Tonnage < 20) { continue; } } // passed checks, add to Dictionary mechTonnages.Add(kvp.Key, kvp.Value.Tonnage); } bool firstrun = true; for (int xloop = 0; xloop < RngStart.Settings.Loops; xloop++) { int LanceCounter = 1; if (!RngStart.Settings.FullRandomMode) { // remove ancestral mech if specified if (RemoveAncestralMech && firstrun) { __instance.ActiveMechs.Remove(0); } currentLanceWeight = 0; while (currentLanceWeight < RngStart.Settings.MinimumStartingWeight || currentLanceWeight > RngStart.Settings.MaximumStartingWeight) { if (RemoveAncestralMech == true) { currentLanceWeight = 0; baySlot = 0; } else { currentLanceWeight = AncestralMechDef.Chassis.Tonnage; baySlot = 1; } if (!firstrun) { for (var i = baySlot; i < 6; i++) { __instance.ActiveMechs.Remove(i); } } //It's not a BUG, it's a FEATURE. LanceCounter++; if (LanceCounter > RngStart.Settings.SpiderLoops) { MechDef mechDefSpider = new MechDef(__instance.DataManager.MechDefs.Get("mechdef_spider_SDR-5V"), __instance.GenerateSimGameUID(), true); lance.Add(mechDefSpider); // worry about sorting later for (int j = baySlot; j < 6; j++) { __instance.AddMech(j, mechDefSpider, true, true, false, null); } break; } var legacyLance = new List <string>(); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.AssaultMechsPossible, RngStart.Settings.NumberAssaultMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.HeavyMechsPossible, RngStart.Settings.NumberHeavyMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.MediumMechsPossible, RngStart.Settings.NumberMediumMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.LightMechsPossible, RngStart.Settings.NumberLightMechs)); // check to see if we're on the last mechbay and if we have more mechs to add // if so, store the mech at index 5 before next iteration. for (int j = 0; j < legacyLance.Count; j++) { Logger.Debug($"Build Lance"); MechDef mechDef2 = new MechDef(__instance.DataManager.MechDefs.Get(legacyLance[j]), __instance.GenerateSimGameUID(), true); __instance.AddMech(baySlot, mechDef2, true, true, false, null); if (baySlot == 5 && j + 1 < legacyLance.Count) { __instance.UnreadyMech(5, mechDef2); } else { baySlot++; } currentLanceWeight += (int)mechDef2.Chassis.Tonnage; } firstrun = false; if (currentLanceWeight >= RngStart.Settings.MinimumStartingWeight && currentLanceWeight <= RngStart.Settings.MaximumStartingWeight) { Logger.Debug($"Classic Mode"); for (int y = 0; y < __instance.ActiveMechs.Count(); y++) { Logger.Debug($"{__instance.ActiveMechs[y].Description.Id}"); } } else { Logger.Debug($"Illegal Lance"); } } } else // G new mode { //Logger.Debug($"New mode"); // cap the lance tonnage int minLanceSize = RngStart.Settings.MinimumLanceSize; float maxWeight = RngStart.Settings.MaximumStartingWeight; float maxLanceSize = 6; bool firstTargetRun = false; __instance.ActiveMechs.Remove(0); if (RemoveAncestralMech == true) { baySlot = 0; currentLanceWeight = 0; if (AncestralMechDef.Description.Id == "mechdef_centurion_TARGETDUMMY" && RngStart.Settings.IgnoreAncestralMech == true) { maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; firstTargetRun = true; minLanceSize = minLanceSize + 1; } } else if ((!RemoveAncestralMech && RngStart.Settings.IgnoreAncestralMech)) { lance.Add(AncestralMechDef); currentLanceWeight = 0; maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; } else { baySlot = 1; lance.Add(AncestralMechDef); currentLanceWeight = AncestralMechDef.Chassis.Tonnage; } bool dupe = false; bool excluded = false; bool blacklisted = false; bool TargetDummy = false; while (minLanceSize > lance.Count || currentLanceWeight < RngStart.Settings.MinimumStartingWeight) { #region Def listing loops //Logger.Debug($"In while loop"); //foreach (var mech in __instance.DataManager.MechDefs) //{ // Logger.Debug($"K:{mech.Key} V:{mech.Value}"); //} //foreach (var chasis in __instance.DataManager.ChassisDefs) //{ // Logger.Debug($"K:{chasis.Key}"); //} #endregion // build lance collection from dictionary for speed var randomMech = mechTonnages.ElementAt(rng.Next(0, mechTonnages.Count)); var mechString = randomMech.Key.Replace("chassisdef", "mechdef"); // getting chassisdefs so renaming the key to match mechdefs Id //var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); //It's not a BUG, it's a FEATURE. if (LanceCounter > RngStart.Settings.SpiderLoops) { MechDef mechDefSpider = new MechDef(__instance.DataManager.MechDefs.Get("mechdef_spider_SDR-5V"), __instance.GenerateSimGameUID(), true); lance.Add(mechDefSpider); // worry about sorting later for (int j = baySlot; j < 6; j++) { __instance.AddMech(j, mechDefSpider, true, true, false, null); } break; } if (mechDef.MechTags.Contains("BLACKLISTED")) { currentLanceWeight = 0; blacklisted = true; //Logger.Debug($"Blacklisted! {mechDef.Name}"); } //Logger.Debug($"TestMech {mechDef.Name}"); foreach (var mechID in RngStart.Settings.ExcludedMechs) { if (mechID == mechDef.Description.Id) { currentLanceWeight = 0; excluded = true; //Logger.Debug($"Excluded! {mechDef.Name}"); } } if (!RngStart.Settings.AllowDuplicateChassis) { foreach (var mech in lance) { if (mech.Name == mechDef.Name) { currentLanceWeight = 0; dupe = true; //Logger.Debug($"SAME SAME! {mech.Name}\t\t{mechDef.Name}"); } } } // does the mech fit into the lance? if (TargetDummy) { TargetDummy = false; } else { currentLanceWeight = currentLanceWeight + mechDef.Chassis.Tonnage; } if (RngStart.Settings.MaximumStartingWeight >= currentLanceWeight) { lance.Add(mechDef); //Logger.Debug($"Adding mech {mechString} {mechDef.Chassis.Tonnage} tons"); //if (currentLanceWeight > RngStart.Settings.MinimumStartingWeight + mechDef.Chassis.Tonnage) //Logger.Debug($"Minimum lance tonnage met: done"); //Logger.Debug($"current: {currentLanceWeight} tons. " + // $"tonnage remaining: {RngStart.Settings.MaximumStartingWeight - currentLanceWeight}. " + // $"before lower limit hit: {Math.Max(0, RngStart.Settings.MinimumStartingWeight - currentLanceWeight)}"); } // invalid lance, reset if (currentLanceWeight > RngStart.Settings.MaximumStartingWeight || lance.Count > maxLanceSize || dupe || blacklisted || excluded || firstTargetRun) { //Logger.Debug($"Clearing invalid lance"); currentLanceWeight = 0; lance.Clear(); dupe = false; blacklisted = false; excluded = false; firstTargetRun = false; LanceCounter++; if (RemoveAncestralMech == true) { baySlot = 0; currentLanceWeight = 0; maxLanceSize = RngStart.Settings.MaximumLanceSize; if (AncestralMechDef.Description.Id == "mechdef_centurion_TARGETDUMMY" && RngStart.Settings.IgnoreAncestralMech == true) { maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; TargetDummy = true; } } else if (!RemoveAncestralMech && RngStart.Settings.IgnoreAncestralMech) { maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; currentLanceWeight = 0; lance.Add(AncestralMechDef); baySlot = 1; } else { maxLanceSize = RngStart.Settings.MaximumLanceSize; currentLanceWeight = AncestralMechDef.Chassis.Tonnage; lance.Add(AncestralMechDef); baySlot = 1; } continue; } //Logger.Debug($"Done a loop"); } Logger.Debug($"New mode"); Logger.Debug($"Starting lance instantiation"); float tonnagechecker = 0; for (int x = 0; x < lance.Count; x++) { Logger.Debug($"x is {x} and lance[x] is {lance[x].Name}"); __instance.AddMech(x, lance[x], true, true, false); tonnagechecker = tonnagechecker + lance[x].Chassis.Tonnage; } Logger.Debug($"{tonnagechecker}"); float Maxtonnagedifference = tonnagechecker - RngStart.Settings.MaximumStartingWeight; float Mintonnagedifference = tonnagechecker - RngStart.Settings.MinimumStartingWeight; Logger.Debug($"Over tonnage Maximum amount: {Maxtonnagedifference}"); Logger.Debug($"Over tonnage Minimum amount: {Mintonnagedifference}"); lance.Clear(); // valid lance created } } } }
public static void Postfix(SimGameState __instance) { if (RngStart.Settings.NumberRandomRonin + RngStart.Settings.NumberProceduralPilots > 0) { // clear roster while (__instance.PilotRoster.Count > 0) { __instance.PilotRoster.RemoveAt(0); } // pilotgenerator seems to give me the same exact results for ronin // every time, and can push out duplicates, which is odd? // just do our own thing var pilots = new List <PilotDef>(); // add our guarenteed starting ronin foreach (var roninID in RngStart.Settings.StartingRonin) { var pilotDef = __instance.DataManager.PilotDefs.Get(roninID); // add directly to roster, don't want to get duplicate ronin from random ronin if (pilotDef != null) { __instance.AddPilotToRoster(pilotDef, true); } } pilots.AddRange(GetRandomSubList(__instance.RoninPilots, RngStart.Settings.NumberRandomRonin)); // pilot generator works fine for non-ronin =/ if (RngStart.Settings.NumberProceduralPilots > 0) { pilots.AddRange(__instance.PilotGenerator.GeneratePilots(RngStart.Settings.NumberProceduralPilots, 1, 0, out _)); } // actually add the pilots to the SimGameState foreach (var pilotDef in pilots) { __instance.AddPilotToRoster(pilotDef, true); } } // mechs if (RngStart.Settings.NumberLightMechs + RngStart.Settings.NumberMediumMechs + RngStart.Settings.NumberHeavyMechs + RngStart.Settings.NumberAssaultMechs > 0) { var baySlot = 1; var mechIds = new List <string>(); // clear the initial lance for (var i = 1; i < __instance.Constants.Story.StartingLance.Length + 1; i++) { __instance.ActiveMechs.Remove(i); } // remove ancestral mech if specified if (RngStart.Settings.RemoveAncestralMech) { __instance.ActiveMechs.Remove(0); baySlot = 0; } // add the random mechs to mechIds mechIds.AddRange(GetRandomSubList(RngStart.Settings.AssaultMechsPossible, RngStart.Settings.NumberAssaultMechs)); mechIds.AddRange(GetRandomSubList(RngStart.Settings.HeavyMechsPossible, RngStart.Settings.NumberHeavyMechs)); mechIds.AddRange(GetRandomSubList(RngStart.Settings.MediumMechsPossible, RngStart.Settings.NumberMediumMechs)); mechIds.AddRange(GetRandomSubList(RngStart.Settings.LightMechsPossible, RngStart.Settings.NumberLightMechs)); // actually add the mechs to the game for (var i = 0; i < mechIds.Count; i++) { var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechIds[i]), __instance.GenerateSimGameUID()); __instance.AddMech(baySlot, mechDef, true, true, false); // check to see if we're on the last mechbay and if we have more mechs to add // if so, store the mech at index 5 before next iteration. if (baySlot == 5 && i + 1 < mechIds.Count) { __instance.UnreadyMech(5, mechDef); } else { baySlot++; } } } }
public static void Postfix(SimGameState __instance) { if (RngStart.Settings.NumberRandomRonin + RngStart.Settings.NumberProceduralPilots + RngStart.Settings.NumberRoninFromList > 0) { RandomizeRonin(__instance); } Logger.Debug($"Starting lance creation {RngStart.Settings.MinimumStartingWeight} - {RngStart.Settings.MaximumStartingWeight} tons"); // mechs if (RngStart.Settings.UseRandomMechs) { // memoize dictionary of tonnages since we may be looping a lot Logger.Debug($"Memoizing"); var AncestralMechDef = __instance.Constants.CareerMode.StartingPlayerMech; var lance = new List <string>(); //var lance = new List<MechDef>(); float currentLanceWeight = 0; var mechTonnages = new Dictionary <string, float>(); Logger.Debug($"A"); var startDate = __instance.GetCampaignStartDate(); //Trim the lists. foreach (var kvp in __instance.DataManager.ChassisDefs) { var mechDefId = kvp.Key.Replace("chassisdef", "mechdef"); if (!__instance.DataManager.Exists(BattleTechResourceType.MechDef, mechDefId)) { continue; } var minAppearanceDate = __instance.DataManager.MechDefs.Get(mechDefId).MinAppearanceDate; if (minAppearanceDate.HasValue && minAppearanceDate > startDate) { continue; } if (kvp.Key.Contains("DUMMY") && !kvp.Key.Contains("CUSTOM")) { // just in case someone calls their mech DUMMY continue; } if (kvp.Key.Contains("CUSTOM") || kvp.Key.Contains("DUMMY")) { continue; } if (RngStart.Settings.MaximumMechWeight != 100) { if (kvp.Value.Tonnage > RngStart.Settings.MaximumMechWeight || kvp.Value.Tonnage < 20) { continue; } } // passed checks, add to Dictionary mechTonnages.Add(kvp.Key, kvp.Value.Tonnage); } Logger.Debug($"B"); for (int xloop = 0; xloop < RngStart.Settings.Loops; xloop++) { Logger.Debug($"C"); int minLanceSize = RngStart.Settings.MinimumLanceSize; float maxWeight = RngStart.Settings.MaximumStartingWeight; float maxLanceSize = RngStart.Settings.MaximumLanceSize; bool firstTargetRun = false; var randomStarterMech = mechTonnages.ElementAt(rng.Next(0, mechTonnages.Count)); var StartermechString = randomStarterMech.Key.Replace("chassisdef", "mechdef"); var StarterMechTonnage = randomStarterMech.Value; Logger.Debug($"D"); Logger.Debug(StartermechString); Logger.Debug(AncestralMechDef); if (AncestralMechDef == "mechdef_centurion_TARGETDUMMY") { lance.Add(StartermechString); currentLanceWeight = randomStarterMech.Value; } else { lance.Add(AncestralMechDef); StartermechString = AncestralMechDef; Logger.Debug("Here, right?"); currentLanceWeight = __instance.DataManager.MechDefs.Get(AncestralMechDef).Chassis.Tonnage; StarterMechTonnage = currentLanceWeight; } Logger.Debug($"E"); int LanceCounter = 1; // cap the lance tonnage //__instance.ActiveMechs.Remove(0); bool dupe = false; bool excluded = false; bool blacklisted = false; int RVMechCount = 0; int MediumMechCount = 0; int GhettoCount = 0; int expandedWeight = 0; while (minLanceSize > lance.Count || currentLanceWeight < (RngStart.Settings.MinimumStartingWeight - expandedWeight)) { Logger.Debug($"F"); #region Def listing loops //Logger.Debug($"In while loop"); //foreach (var mech in __instance.DataManager.MechDefs) //{ // Logger.Debug($"K:{mech.Key} V:{mech.Value}"); //} //foreach (var chasis in __instance.DataManager.ChassisDefs) //{ // Logger.Debug($"K:{chasis.Key}"); //} #endregion // build lance collection from dictionary for speed var randomMech = mechTonnages.ElementAt(rng.Next(0, mechTonnages.Count)); var mechString = randomMech.Key.Replace("chassisdef", "mechdef"); // getting chassisdefs so renaming the key to match mechdefs Id var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); //It's not a BUG, it's a FEATURE. if (LanceCounter > RngStart.Settings.SpiderLoops) { MechDef mechDefSpider = new MechDef(__instance.DataManager.MechDefs.Get("mechdef_spider_SDR-5V"), __instance.GenerateSimGameUID(), true); lance.Add(mechDefSpider.Description.Id); // worry about sorting later Traverse.Create(__instance).Method("AddMechs", new Type[] { typeof(List <string>) }).GetValue(lance); //for (int j = baySlot; j < 6; j++) //{ // __instance.AddMech(j, mechDefSpider, true, true, false, null); //} break; } Logger.Debug($"G"); if (mechDef.MechTags.Contains("BLACKLISTED")) { currentLanceWeight = 0; blacklisted = true; //Logger.Debug($"Blacklisted! {mechDef.Name}"); } Logger.Debug($"TestMech {mechDef.Name}"); foreach (var mechID in RngStart.Settings.ExcludedMechs) { if (mechID == mechDef.Description.Id) { currentLanceWeight = 0; excluded = true; Logger.Debug($"Excluded! {mechDef.Name}"); } } if (!RngStart.Settings.AllowDuplicateChassis) { foreach (var mech in lance) { Logger.Debug("Mech Chassis Comparer"); Logger.Debug(mech.Substring(0, 12) + ":" + mechDef.Description.Id.Substring(0, 12)); if (mech.Substring(0, 12) == mechDef.Description.Id.Substring(0, 12)) { currentLanceWeight = 0; dupe = true; Logger.Debug($"SAME SAME!"); } } } if (mechDef.Description.UIName.Contains("-RV") && RngStart.Settings.LimitRVMechs) { RVMechCount++; } if (mechDef.Chassis.weightClass == WeightClass.MEDIUM && RngStart.Settings.ForceSingleMedium) { MediumMechCount++; } if (mechDef.Chassis.Tonnage == 20) { GhettoCount++; } // does the mech fit into the lance? currentLanceWeight = currentLanceWeight + mechDef.Chassis.Tonnage; if (RngStart.Settings.MaximumStartingWeight >= currentLanceWeight) { lance.Add(mechDef.Description.Id); Logger.Debug($"Adding mech {mechString} {mechDef.Chassis.Tonnage} tons"); if (currentLanceWeight > RngStart.Settings.MinimumStartingWeight + mechDef.Chassis.Tonnage) { Logger.Debug($"Minimum lance tonnage met: done"); } Logger.Debug($"current: {currentLanceWeight} tons. " + $"tonnage remaining: {RngStart.Settings.MaximumStartingWeight - currentLanceWeight}. " + $"before lower limit hit: {Math.Max(0, RngStart.Settings.MinimumStartingWeight - currentLanceWeight)}"); } // invalid lance, reset if (currentLanceWeight > (RngStart.Settings.MaximumStartingWeight + expandedWeight) || lance.Count > maxLanceSize || dupe || blacklisted || excluded || firstTargetRun || RVMechCount > 1 || (lance.Count >= minLanceSize && MediumMechCount != 1) || GhettoCount > 1) { Logger.Debug($"Clearing invalid lance"); currentLanceWeight = StarterMechTonnage; lance.Clear(); lance.Add(StartermechString); dupe = false; blacklisted = false; excluded = false; firstTargetRun = false; RVMechCount = 0; LanceCounter++; if (StarterMechTonnage > 35) { MediumMechCount = 1; } else { MediumMechCount = 0; } GhettoCount = 0; if (xloop > RngStart.Settings.Loops / 2) { expandedWeight = 5; } continue; } Logger.Debug($"Done a loop"); } Logger.Debug($"New mode"); Logger.Debug($"Starting lance instantiation"); float tonnagechecker = 0; Traverse.Create(__instance).Method("AddMechs", new Type[] { typeof(List <string>) }).GetValue(lance); Logger.Debug($"{tonnagechecker}"); float Maxtonnagedifference = currentLanceWeight - RngStart.Settings.MaximumStartingWeight; float Mintonnagedifference = currentLanceWeight - RngStart.Settings.MinimumStartingWeight; Logger.Debug($"Over tonnage Maximum amount: {Maxtonnagedifference}"); Logger.Debug($"Over tonnage Minimum amount: {Mintonnagedifference}"); lance.Clear(); // valid lance created } } }
static void Postfix(SimGameState __instance, string id) { try { __instance.AddItemStat(id, "MECHPART", false); Settings settings = Helper.LoadSettings(); Dictionary <MechDef, int> possibleMechs = new Dictionary <MechDef, int>(); int itemCount = 0; if (settings.AssembleVariants && !settings.VariantExceptions.Contains(id)) { foreach (KeyValuePair <string, MechDef> pair in __instance.DataManager.MechDefs) { if (pair.Value.Chassis.PrefabIdentifier.Equals(__instance.DataManager.MechDefs.Get(id).Chassis.PrefabIdentifier) && !settings.VariantExceptions.Contains(pair.Value.Description.Id) && pair.Value.Chassis.Tonnage.Equals(__instance.DataManager.MechDefs.Get(id).Chassis.Tonnage)) { int numberOfParts = __instance.GetItemCount(pair.Value.Description.Id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY); if (numberOfParts > 0) { itemCount += numberOfParts; possibleMechs.Add(new MechDef(pair.Value, __instance.GenerateSimGameUID()), numberOfParts); } } } } else { itemCount = __instance.GetItemCount(id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY); } int defaultMechPartMax = __instance.Constants.Story.DefaultMechPartMax; if (itemCount >= defaultMechPartMax) { MechDef mechDef = null; List <KeyValuePair <MechDef, int> > mechlist = possibleMechs.ToList(); mechlist = possibleMechs.OrderByDescending(o => o.Value).ToList(); if (settings.AssembleVariants && !settings.VariantExceptions.Contains(id)) { if (settings.AssembleMostParts) { mechDef = mechlist[0].Key; } else { Random rand = new Random(); int numberOfDifferentVariants = mechlist.Count; double roll = rand.NextDouble(); double currentTotal = 0; foreach (KeyValuePair <MechDef, int> mech in mechlist) { currentTotal += (double)mech.Value / (double)defaultMechPartMax; if (roll <= currentTotal) { mechDef = mech.Key; break; } } } int j = 0; int i = 0; int currentPart = 1; while (i < defaultMechPartMax) { if (currentPart > mechlist[j].Value) { j++; currentPart = 1; } ReflectionHelper.InvokePrivateMethode(__instance, "RemoveItemStat", new object[] { mechlist[j].Key.Description.Id, "MECHPART", false }); currentPart++; i++; } } else { for (int i = 0; i < defaultMechPartMax; i++) { ReflectionHelper.InvokePrivateMethode(__instance, "RemoveItemStat", new object[] { id, "MECHPART", false }); } mechDef = new MechDef(__instance.DataManager.MechDefs.Get(id), __instance.GenerateSimGameUID()); } Random rng = new Random(); if (!settings.HeadRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.Head.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.Head.CurrentInternalStructure = Math.Max(1f, mechDef.Head.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.LeftArmRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.LeftArm.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.LeftArm.CurrentInternalStructure = Math.Max(1f, mechDef.LeftArm.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.RightArmRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.RightArm.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.RightArm.CurrentInternalStructure = Math.Max(1f, mechDef.RightArm.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.LeftLegRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.LeftLeg.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.LeftLeg.CurrentInternalStructure = Math.Max(1f, mechDef.LeftLeg.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.RightLegRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.RightLeg.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.RightLeg.CurrentInternalStructure = Math.Max(1f, mechDef.RightLeg.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.CentralTorsoRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.CenterTorso.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.CenterTorso.CurrentInternalStructure = Math.Max(1f, mechDef.CenterTorso.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.RightTorsoRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.RightTorso.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.RightTorso.CurrentInternalStructure = Math.Max(1f, mechDef.RightTorso.CurrentInternalStructure * (float)rng.NextDouble()); } if (!settings.LeftTorsoRepaired && (!settings.RepairMechLimbs || rng.NextDouble() > settings.RepairMechLimbsChance)) { mechDef.LeftTorso.CurrentInternalStructure = 0f; } else if (settings.RandomStructureOnRepairedLimbs) { mechDef.LeftTorso.CurrentInternalStructure = Math.Max(1f, mechDef.LeftTorso.CurrentInternalStructure * (float)rng.NextDouble()); } // each component is checked and destroyed if the settings are set that way // if RepairMechComponents is true it will variably make components either functional, nonfunctional, or destroyed based on settings foreach (MechComponentRef mechComponent in mechDef.Inventory) { if (!settings.RepairMechComponents || mechDef.IsLocationDestroyed(mechComponent.MountedLocation)) { mechComponent.DamageLevel = ComponentDamageLevel.Destroyed; continue; } if (settings.RepairMechComponents) { double repairRoll = rng.NextDouble(); if (repairRoll <= settings.RepairComponentsFunctionalThreshold) { mechComponent.DamageLevel = ComponentDamageLevel.Functional; } else if (repairRoll <= settings.RepairComponentsNonFunctionalThreshold) { mechComponent.DamageLevel = ComponentDamageLevel.NonFunctional; } else { mechComponent.DamageLevel = ComponentDamageLevel.Destroyed; } } } __instance.AddMech(0, mechDef, true, false, true, null); SimGameInterruptManager interrupt = (SimGameInterruptManager)ReflectionHelper.GetPrivateField(__instance, "interruptQueue"); interrupt.DisplayIfAvailable(); __instance.MessageCenter.PublishMessage(new SimGameMechAddedMessage(mechDef, true)); } } catch (Exception e) { Logger.LogError(e); } }
private static void Postfix(ref SimGameState __instance, ref string mechSimGameUID, ref ChassisLocations location, ref int structureCount, ref WorkOrderEntry_RepairMechStructure __result) { try { float mechTonnageModifier = 1f; // Original method code, this is still needed to work out zero structure modifiers string id = string.Format("MechLab - RepairMech - {0}", __instance.GenerateSimGameUID()); bool is_repaired = false; float cbmod = 1f; float tpmod = 1f; foreach (MechDef mechDef in __instance.ActiveMechs.Values) { if (mechDef.GUID == mechSimGameUID) { if (mechDef.GetChassisLocationDef(location).InternalStructure == (float)structureCount) { is_repaired = true; break; } Logger.LogDebug("Structure WO Subentry Costing:"); Logger.LogDebug("***************************************"); Logger.LogDebug(" location: " + location.ToString()); Logger.LogDebug(" structureCount: " + structureCount); Logger.LogDebug(" mechTonnageModifier: " + mechTonnageModifier); // If ScaleStructureCostByTonnage is enabled, make the mech tonnage work as a percentage tech cost reduction (95 tons = 0.95 or "95%" of the cost, 50 tons = 0.05 or "50%" of the cost etc) if (ArmorRepair.ModSettings.ScaleStructureCostByTonnage) { mechTonnageModifier = mechDef.Chassis.Tonnage * 0.01f; } StructureRepairFactor str = null; MechComponentRef structitem = null; foreach (var item in mechDef.Inventory) { if (item.IsCategory(ArmorRepair.ModSettings.StructureCategory)) { str = item.GetComponent <StructureRepairFactor>(); structitem = item; break; } } if (str != null) { Logger.LogDebug($" StructRepair mods tp:{str.StructureTPCost:0.00} cb:{str.StructureCBCost:0.00}"); } tpmod *= str?.StructureTPCost ?? 1; cbmod *= str?.StructureTPCost ?? 1; if (ArmorRepair.ModSettings.RepairCostByTag != null && ArmorRepair.ModSettings.RepairCostByTag.Length > 0) { foreach (var cost in ArmorRepair.ModSettings.RepairCostByTag) { if (mechDef.Chassis.ChassisTags.Contains(cost.Tag)) { Logger.LogDebug($" Chassis {cost.Tag} mods tp:{cost.StructureTPCost:0.00} cb:{cost.StructureCBCost:0.00}"); tpmod *= cost.StructureTPCost; cbmod *= cost.StructureCBCost; } if (structitem != null && structitem.Def.ComponentTags.Contains(cost.Tag)) { Logger.LogDebug($" {structitem.ComponentDefID} {cost.Tag} mods tp:{cost.StructureTPCost:0.00} cb:{cost.StructureCBCost:0.00}"); tpmod *= cost.StructureTPCost; cbmod *= cost.StructureCBCost; } } } break; } } if (is_repaired) { cbmod = __instance.Constants.MechLab.ZeroStructureCBillModifier; tpmod = __instance.Constants.MechLab.ZeroStructureTechPointModifier; } int techCost = Mathf.CeilToInt((__instance.Constants.MechLab.StructureRepairTechPoints * (float)structureCount * tpmod) * mechTonnageModifier); int cbillCost = Mathf.CeilToInt((float)((__instance.Constants.MechLab.StructureRepairCost * structureCount) * cbmod) * mechTonnageModifier); Logger.LogDebug($" tpmod: {tpmod:0.000}"); Logger.LogDebug($" cbmod: {cbmod:0.000}"); Logger.LogDebug(" techCost: " + techCost); Logger.LogDebug(" cBill cost: " + cbillCost); Logger.LogDebug("***************************************"); __result = new WorkOrderEntry_RepairMechStructure(id, string.Format("Repair 'Mech - {0}", location.ToString()), mechSimGameUID, techCost, location, structureCount, cbillCost, string.Empty); } catch (Exception ex) { Logger.LogError(ex); } }
public static void MyMethod(SimGameState simulation) { if (Cheats.cSettings.cheatStart) { Logger.Debug($"Welcome You Cheater!"); if (Cheats.cSettings.cheatArgo) { for (int i = 0; i < Cheats.cSettings.cheatArgoUpgrades.Count; i++) { simulation.AddArgoUpgrade(simulation.DataManager.ShipUpgradeDefs.Get(Cheats.cSettings.cheatArgoUpgrades[i])); Logger.Debug($"Upgrade Added: {Cheats.cSettings.cheatArgoUpgrades[i]}"); } } if (Cheats.cSettings.cheatPilots) { Logger.Debug($"Number of Pilots: {simulation.PilotRoster.Count}"); foreach (var pilot in simulation.PilotRoster) { Logger.Debug($"Pilot: {pilot.Name}"); pilot.AddExperience(0, "Cheat XP", Cheats.cSettings.iCheatXP); Logger.Debug($"XP Added: {Cheats.cSettings.iCheatXP}"); } simulation.Constants.Story.CommanderStartingExperience += Cheats.cSettings.iCheatXP; } if (Cheats.cSettings.cheatMoney) { simulation.Constants.Story.StartingCBills += Cheats.cSettings.iCheatMoney; Logger.Debug($"CBills Added: {Cheats.cSettings.iCheatMoney}"); } if (Cheats.cSettings.cheatLance) { //__instance.Constants.Progression.PilotingSkills.Add() var tempLance = new List <MechDef>(); Logger.Debug($"Readying Mechs: {simulation.ReadyingMechs.Count}"); for (int k = 0; k < simulation.ReadyingMechs.Count; k++) { Logger.Debug($"Readying Mechs: {simulation.ReadyingMechs[k].Description.Id}"); tempLance.Add(simulation.ReadyingMechs[k]); } Logger.Debug($"Active Mechs: {simulation.ActiveMechs.Count}"); for (int j = 0; j < simulation.ActiveMechs.Count; j++) { Logger.Debug($"Active Mech: {simulation.ActiveMechs[j].Description.Id}"); tempLance.Add(simulation.ActiveMechs[j]); } Logger.Debug($"Store Mechs"); for (int l = 0; l < tempLance.Count; l++) { Logger.Debug($"Storing Mech: {tempLance[l]}"); simulation.UnreadyMech(l, tempLance[l]); } for (int i = 0; i < Cheats.cSettings.cheatAddMechs.Count; i++) { Logger.Debug($"Add Cheat Mechs"); var curMechDef = new MechDef(simulation.DataManager.MechDefs.Get(Cheats.cSettings.cheatAddMechs[i]), simulation.GenerateSimGameUID()); simulation.AddMech(i, curMechDef, true, true, false); Logger.Debug($"Adding... {curMechDef.Description.Id}"); } } if (Cheats.cSettings.cheatRep) { Random RNG = new Random(); if (Cheats.cSettings.cheatLocalRep) { foreach (KeyValuePair <Faction, FactionDef> pair in simulation.FactionsDict) { int randVal = RNG.Next(Cheats.cSettings.iMinRepVal, Cheats.cSettings.iMaxRepVal); AccessTools.Method(typeof(SimGameState), "SetReputation").Invoke(simulation, new object[] { pair.Key, randVal, StatCollection.StatOperation.Set, null }); } } if (Cheats.cSettings.cheatAllRep) { foreach (KeyValuePair <Faction, FactionDef> pair in simulation.FactionsDict) { int iVal = Cheats.cSettings.iAllRepVal; AccessTools.Method(typeof(SimGameState), "SetReputation").Invoke(simulation, new object[] { pair.Key, iVal, StatCollection.StatOperation.Int_Add, null }); } } } } }
static void Postfix(SimGameState __instance, string id) { try { Settings settings = Helper.LoadSettings(); int itemCount = __instance.GetItemCount(id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY); int defaultMechPartMax = __instance.Constants.Story.DefaultMechPartMax; if (itemCount + 1 >= defaultMechPartMax) { for (int i = 0; i < defaultMechPartMax - 1; i++) { ReflectionHelper.InvokePrivateMethode(__instance, "RemoveItemStat", new object[] { id, "MECHPART", false }); } MechDef mechDef = new MechDef(__instance.DataManager.MechDefs.Get(id), __instance.GenerateSimGameUID()); if (!settings.HeadRepaired) { mechDef.Head.CurrentInternalStructure = 0f; } if (!settings.LeftArmRepaired) { mechDef.LeftArm.CurrentInternalStructure = 0f; } if (!settings.RightArmRepaired) { mechDef.RightArm.CurrentInternalStructure = 0f; } if (!settings.LeftLegRepaired) { mechDef.LeftLeg.CurrentInternalStructure = 0f; } if (!settings.RightLegRepaired) { mechDef.RightLeg.CurrentInternalStructure = 0f; } if (!settings.CentralTorsoRepaired) { mechDef.CenterTorso.CurrentInternalStructure = 0f; } if (!settings.RightTorsoRepaired) { mechDef.RightTorso.CurrentInternalStructure = 0f; } if (!settings.LeftTorsoRepaired) { mechDef.LeftTorso.CurrentInternalStructure = 0f; } foreach (MechComponentRef comp in mechDef.Inventory) { if (mechDef.IsLocationDestroyed(comp.MountedLocation) || settings.NoItems) { comp.DamageLevel = ComponentDamageLevel.Destroyed; } } __instance.AddMech(0, mechDef, true, false, true, null); SimGameInterruptManager interrupt = (SimGameInterruptManager)ReflectionHelper.GetPrivateField(__instance, "interruptQueue"); interrupt.DisplayIfAvailable(); __instance.MessageCenter.PublishMessage(new SimGameMechAddedMessage(mechDef, true)); } else { __instance.AddItemStat(id, "MECHPART", false); } } catch (Exception e) { Logger.LogError(e); } }
public static void Postfix(SimGameState __instance) { if (RngStart.Settings.NumberRandomRonin + RngStart.Settings.NumberProceduralPilots + RngStart.Settings.NumberRoninFromList > 0) { while (__instance.PilotRoster.Count > 0) { __instance.PilotRoster.RemoveAt(0); } List <PilotDef> list = new List <PilotDef>(); if (RngStart.Settings.StartingRonin != null) { var RoninRandomizer = new List <string>(); RoninRandomizer.AddRange(GetRandomSubList(RngStart.Settings.StartingRonin, RngStart.Settings.NumberRoninFromList)); foreach (var roninID in RoninRandomizer) { var pilotDef = __instance.DataManager.PilotDefs.Get(roninID); // add directly to roster, don't want to get duplicate ronin from random ronin if (pilotDef != null) { __instance.AddPilotToRoster(pilotDef, true); } } } if (RngStart.Settings.NumberRandomRonin > 0) { List <PilotDef> list2 = new List <PilotDef>(__instance.RoninPilots); for (int m = list2.Count - 1; m >= 0; m--) { for (int n = 0; n < __instance.PilotRoster.Count; n++) { if (list2[m].Description.Id == __instance.PilotRoster[n].Description.Id) { list2.RemoveAt(m); break; } } } list2.RNGShuffle <PilotDef>(); for (int i = 0; i < RngStart.Settings.NumberRandomRonin; i++) { list.Add(list2[i]); } } if (RngStart.Settings.NumberProceduralPilots > 0) { List <PilotDef> list3; List <PilotDef> collection = __instance.PilotGenerator.GeneratePilots(RngStart.Settings.NumberProceduralPilots, 1, 0f, out list3); list.AddRange(collection); } foreach (PilotDef def in list) { __instance.AddPilotToRoster(def, true); } } //Logger.Debug($"Starting lance creation {RngStart.Settings.MinimumStartingWeight} - {RngStart.Settings.MaximumStartingWeight} tons"); // mechs if (!RngStart.Settings.TagRandomLance) { var AncestralMechDef = new MechDef(__instance.DataManager.MechDefs.Get(__instance.ActiveMechs[0].Description.Id), __instance.GenerateSimGameUID()); bool RemoveAncestralMech = RngStart.Settings.RemoveAncestralMech; if (AncestralMechDef.Description.Id == "mechdef_centurion_TARGETDUMMY") { RemoveAncestralMech = true; } var lance = new List <MechDef>(); float currentLanceWeight = 0; var baySlot = 1; // clear the initial lance for (var i = 1; i < 6; i++) { __instance.ActiveMechs.Remove(i); } // memoize dictionary of tonnages since we may be looping a lot //Logger.Debug($"Memoizing"); var mechTonnages = new Dictionary <string, float>(); foreach (var kvp in __instance.DataManager.ChassisDefs) { if (kvp.Key.Contains("DUMMY") && !kvp.Key.Contains("CUSTOM")) { // just in case someone calls their mech DUMMY continue; } if (kvp.Key.Contains("CUSTOM") || kvp.Key.Contains("DUMMY")) { continue; } if (RngStart.Settings.MaximumMechWeight != 100) { if (kvp.Value.Tonnage > RngStart.Settings.LegacyMaxMechWeight || kvp.Value.Tonnage < RngStart.Settings.LegacyMinMechWeight) { continue; } } // passed checks, add to Dictionary mechTonnages.Add(kvp.Key, kvp.Value.Tonnage); } bool firstrun = true; for (int xloop = 0; xloop < RngStart.Settings.Loops; xloop++) { int LanceCounter = 1; if (!RngStart.Settings.NotRandomMode) { // remove ancestral mech if specified if (RemoveAncestralMech && firstrun) { //Logger.Debug($"Lance Size(Legacy1): {lance.Count}"); __instance.ActiveMechs.Remove(0); //Logger.Debug($"Lance Size(Legacy2): {lance.Count}"); } while (currentLanceWeight < RngStart.Settings.LegacyMinStartingWeight || currentLanceWeight > RngStart.Settings.LegacyMaxStartingWeight) { if (!firstrun) { for (var i = baySlot; i < 6; i++) { __instance.ActiveMechs.Remove(i); } currentLanceWeight = 0; } if (RemoveAncestralMech == true) { baySlot = 0; } else { currentLanceWeight = AncestralMechDef.Chassis.Tonnage; baySlot = 1; } //It's not a BUG, it's a FEATURE. LanceCounter++; if (LanceCounter > RngStart.Settings.SpiderLoops) { MechDef mechDefSpider = new MechDef(__instance.DataManager.MechDefs.Get("mechdef_spider_SDR-5V"), __instance.GenerateSimGameUID(), true); lance.Add(mechDefSpider); // worry about sorting later for (int j = baySlot; j < 6; j++) { __instance.AddMech(j, mechDefSpider, true, true, false, null); } break; } var legacyLance = new List <string>(); for (int i = 0; i < RngStart.Settings.startTypes.Count; i++) { foreach (var planet in RngStart.Settings.startTypeOptions[i]) { if (planet == __instance.Constants.Story.StartingTargetSystem) { if (RngStart.Settings.startTypes[i] == "InnerSphere") { legacyLance.AddRange(GetRandomSubList(RngStart.Settings.innerAssaultMechsPossible, RngStart.Settings.innerNumberAssaultMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.innerHeavyMechsPossible, RngStart.Settings.innerNumberHeavyMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.innerMediumMechsPossible, RngStart.Settings.innerNumberMediumMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.innerLightMechsPossible, RngStart.Settings.innerNumberLightMechs)); } if (RngStart.Settings.startTypes[i] == "Periphery") { legacyLance.AddRange(GetRandomSubList(RngStart.Settings.periAssaultMechsPossible, RngStart.Settings.periNumberAssaultMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.periHeavyMechsPossible, RngStart.Settings.periNumberHeavyMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.periMediumMechsPossible, RngStart.Settings.periNumberMediumMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.periLightMechsPossible, RngStart.Settings.periNumberLightMechs)); } if (RngStart.Settings.startTypes[i] == "DeepPeriphery") { legacyLance.AddRange(GetRandomSubList(RngStart.Settings.deepAssaultMechsPossible, RngStart.Settings.deepNumberAssaultMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.deepHeavyMechsPossible, RngStart.Settings.deepNumberHeavyMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.deepMediumMechsPossible, RngStart.Settings.deepNumberMediumMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.deepLightMechsPossible, RngStart.Settings.deepNumberLightMechs)); } if (RngStart.Settings.startTypes[i] == "Clan") { legacyLance.AddRange(GetRandomSubList(RngStart.Settings.clanAssaultMechsPossible, RngStart.Settings.clanNumberAssaultMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.clanHeavyMechsPossible, RngStart.Settings.clanNumberHeavyMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.clanMediumMechsPossible, RngStart.Settings.clanNumberMediumMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.clanLightMechsPossible, RngStart.Settings.clanNumberLightMechs)); } if (RngStart.Settings.startTypes[i] == "Pirates") { legacyLance.AddRange(GetRandomSubList(RngStart.Settings.pirateAssaultMechsPossible, RngStart.Settings.pirateNumberAssaultMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.pirateHeavyMechsPossible, RngStart.Settings.pirateNumberHeavyMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.pirateMediumMechsPossible, RngStart.Settings.pirateNumberMediumMechs)); legacyLance.AddRange(GetRandomSubList(RngStart.Settings.pirateLightMechsPossible, RngStart.Settings.pirateNumberLightMechs)); } } } } // check to see if we're on the last mechbay and if we have more mechs to add // if so, store the mech at index 5 before next iteration. for (int j = 0; j < legacyLance.Count; j++) { Logger.Debug($"Build Lance"); MechDef mechDef2 = new MechDef(__instance.DataManager.MechDefs.Get(legacyLance[j]), __instance.GenerateSimGameUID(), true); __instance.AddMech(baySlot, mechDef2, true, true, false, null); if (baySlot == 5 && j + 1 < legacyLance.Count) { __instance.UnreadyMech(5, mechDef2); } else { baySlot++; } currentLanceWeight += (int)mechDef2.Chassis.Tonnage; } firstrun = false; if (currentLanceWeight >= RngStart.Settings.MinimumStartingWeight && currentLanceWeight <= RngStart.Settings.MaximumStartingWeight) { Logger.Debug($"Classic Mode"); for (int y = 0; y < __instance.ActiveMechs.Count(); y++) { Logger.Debug($"Mech {y}: {__instance.ActiveMechs[y].Description.Id}"); } } else { Logger.Debug($"Illegal Lance"); Logger.Debug($"Weight: {currentLanceWeight}"); } } } else // G new mode { //Logger.Debug($"New mode"); // cap the lance tonnage int minLanceSize = RngStart.Settings.MinimumLanceSize; float maxWeight = RngStart.Settings.MaximumStartingWeight; float maxLanceSize = 6; //bool firstTargetRun = true; currentLanceWeight = 0; if (RemoveAncestralMech == true) { baySlot = 0; if (RngStart.Settings.IgnoreAncestralMech) { maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; minLanceSize = minLanceSize + 1; } } else if ((!RemoveAncestralMech && RngStart.Settings.IgnoreAncestralMech)) { lance.Add(AncestralMechDef); maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; } else { baySlot = 1; lance.Add(AncestralMechDef); currentLanceWeight += AncestralMechDef.Chassis.Tonnage; Logger.Debug($"Weight w/Ancestral: {currentLanceWeight}"); } bool dupe = false; bool excluded = false; bool blacklisted = false; bool TargetDummy = false; while (minLanceSize > lance.Count || currentLanceWeight < RngStart.Settings.MinimumStartingWeight) { #region Def listing loops //Logger.Debug($"In while loop"); //foreach (var mech in __instance.DataManager.MechDefs) //{ // Logger.Debug($"K:{mech.Key} V:{mech.Value}"); //} //foreach (var chasis in __instance.DataManager.ChassisDefs) //{ // Logger.Debug($"K:{chasis.Key}"); //} #endregion // build lance collection from dictionary for speed var randomMech = mechTonnages.ElementAt(rng.Next(0, mechTonnages.Count)); var mechString = randomMech.Key.Replace("chassisdef", "mechdef"); // getting chassisdefs so renaming the key to match mechdefs Id //var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); //It's not a BUG, it's a FEATURE. if (LanceCounter > RngStart.Settings.SpiderLoops) { MechDef mechDefSpider = new MechDef(__instance.DataManager.MechDefs.Get("mechdef_spider_SDR-5V"), __instance.GenerateSimGameUID(), true); lance.Add(mechDefSpider); // worry about sorting later for (int j = baySlot; j < 6; j++) { __instance.AddMech(j, mechDefSpider, true, true, false, null); } break; } /*for (int i = 0; i < mechDef.MechTags.Count; i++) * { * Logger.Debug($"MechTags: {mechDef.MechTags[i]}"); * }*/ if (mechDef.MechTags.Contains("BLACKLISTED")) { blacklisted = true; Logger.Debug($"Blacklisted! {mechDef.Name}"); } if (!RngStart.Settings.AllowDuplicateChassis) { foreach (var mech in lance) { if (mech.Name == mechDef.Name) { dupe = true; Logger.Debug($"SAME SAME! {mech.Name}\t\t{mechDef.Name}"); } } } // does the mech fit into the lance? if (TargetDummy) { TargetDummy = false; } else { //currentLanceWeight = currentLanceWeight + mechDef.Chassis.Tonnage; } if (!blacklisted && !dupe && !excluded) { Logger.Debug($"Lance Count-1: {lance.Count}"); lance.Add(mechDef); currentLanceWeight += mechDef.Chassis.Tonnage; Logger.Debug($"Lance Count-2: {lance.Count}"); Logger.Debug($"Adding mech {mechString} {mechDef.Chassis.Tonnage} tons"); } else { blacklisted = false; dupe = false; excluded = false; } Logger.Debug($"Lance Counter: {LanceCounter}"); LanceCounter++; //if (currentLanceWeight > RngStart.Settings.MinimumStartingWeight + mechDef.Chassis.Tonnage) //Logger.Debug($"Minimum lance tonnage met: done"); //Logger.Debug($"current: {currentLanceWeight} tons. " + // $"tonnage remaining: {RngStart.Settings.MaximumStartingWeight - currentLanceWeight}. " + // $"before lower limit hit: {Math.Max(0, RngStart.Settings.MinimumStartingWeight - currentLanceWeight)}"); // invalid lance, reset if (lance.Count >= maxLanceSize && currentLanceWeight < RngStart.Settings.MinimumStartingWeight) { Logger.Debug($"Weight: {currentLanceWeight}"); Logger.Debug($"Lance Count-1: {lance.Count}"); var lightest = lance[0]; for (int i = 0; i < lance.Count; i++) { if (lightest.Chassis.Tonnage > lance[i].Chassis.Tonnage) { Logger.Debug($"Mech: {lance[i].Name}"); Logger.Debug($"Weight: {lance[i].Chassis.Tonnage}"); lightest = lance[i]; } } lance.Remove(lightest); currentLanceWeight -= lightest.Chassis.Tonnage; } if (lance.Count < minLanceSize && currentLanceWeight > RngStart.Settings.MaximumStartingWeight) { Logger.Debug($"Weight: {currentLanceWeight}"); Logger.Debug($"Lance Count-1: {lance.Count}"); var heaviest = lance[0]; for (int i = 0; i < lance.Count; i++) { if (heaviest.Chassis.Tonnage < lance[i].Chassis.Tonnage) { Logger.Debug($"Mech: {lance[i].Name}"); Logger.Debug($"Weight: {lance[i].Chassis.Tonnage}"); heaviest = lance[i]; } } lance.Remove(heaviest); currentLanceWeight -= heaviest.Chassis.Tonnage; } } Logger.Debug($"New mode"); Logger.Debug($"Starting lance instantiation"); float tonnagechecker = 0; for (int x = 0; x < lance.Count; x++) { Logger.Debug($"x is {x} and lance[x] is {lance[x].Name}"); __instance.AddMech(x, lance[x], true, true, false); tonnagechecker = tonnagechecker + lance[x].Chassis.Tonnage; } Logger.Debug($"{tonnagechecker}"); float Maxtonnagedifference = tonnagechecker - RngStart.Settings.MaximumStartingWeight; float Mintonnagedifference = tonnagechecker - RngStart.Settings.MinimumStartingWeight; Logger.Debug($"Over tonnage Maximum amount: {Maxtonnagedifference}"); Logger.Debug($"Over tonnage Minimum amount: {Mintonnagedifference}"); lance.Clear(); // valid lance created } } } else { //Find Starting Mech and if Starting Mech is used var AncestralMechDef = new MechDef(__instance.DataManager.MechDefs.Get(__instance.ActiveMechs[0].Description.Id), __instance.GenerateSimGameUID()); bool RemoveAncestralMech = RngStart.Settings.RemoveAncestralMech; if (AncestralMechDef.Description.Id == "mechdef_centurion_TARGETDUMMY") { RemoveAncestralMech = true; } var lance = new List <MechDef>(); float currentLanceWeight = 0; var baySlot = 1; // clear the initial lance for (var i = 1; i < 6; i++) { __instance.ActiveMechs.Remove(i); } // memoize dictionary of tonnages since we may be looping a lot //Logger.Debug($"Memoizing"); var mechTonnages = new Dictionary <string, float>(); foreach (var kvp in __instance.DataManager.ChassisDefs) { if (kvp.Key.Contains("DUMMY") && !kvp.Key.Contains("CUSTOM")) { // just in case someone calls their mech DUMMY continue; } if (kvp.Key.Contains("CUSTOM") || kvp.Key.Contains("DUMMY")) { continue; } if (RngStart.Settings.MaximumMechWeight != 100) { //AccessTools.Method(typeof(SimGameState), "SetReputation").Invoke(__instance, new object[] { Values to give }); if (kvp.Value.Tonnage > RngStart.Settings.MaximumMechWeight || kvp.Value.Tonnage < RngStart.Settings.MinimumMechWeight) { continue; } } // passed checks, add to Dictionary mechTonnages.Add(kvp.Key, kvp.Value.Tonnage); } Logger.Debug($"TagRandom Mode"); // cap the lance tonnage int minLanceSize = RngStart.Settings.MinimumLanceSize; float maxWeight = RngStart.Settings.MaximumStartingWeight; float maxLanceSize = 6; //bool firstTargetRun = true; currentLanceWeight = 0; if (RemoveAncestralMech == true) { baySlot = 0; if (RngStart.Settings.IgnoreAncestralMech) { maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; minLanceSize = minLanceSize + 1; } } else if ((!RemoveAncestralMech && RngStart.Settings.IgnoreAncestralMech)) { lance.Add(AncestralMechDef); maxLanceSize = RngStart.Settings.MaximumLanceSize + 1; } else { baySlot = 1; lance.Add(AncestralMechDef); currentLanceWeight += AncestralMechDef.Chassis.Tonnage; Logger.Debug($"Weight w/Ancestral: {currentLanceWeight}"); } /* * // build lance collection from dictionary for speed * var randomMech = mechTonnages.ElementAt(rng.Next(0, mechTonnages.Count)); * var mechString = randomMech.Key.Replace("chassisdef", "mechdef"); * // getting chassisdefs so renaming the key to match mechdefs Id * //var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); * var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); */ /*for (int j = 0; j < mechTonnages.Count; j++) * { * var currentMech = mechTonnages.ElementAt(j); * var currentMechString = currentMech.Key.Replace("chassisdef", "mechdef"); * var currentMechDef = new MechDef(__instance.DataManager.MechDefs.Get(currentMechString), __instance.GenerateSimGameUID()); * * Logger.Debug($"Mech ID: {currentMechDef.Description.Id}"); * for (int k = 0; k < currentMechDef.MechTags.Count; k++) * { * Logger.Debug($"Tag-{k}: {currentMechDef.MechTags[k]}"); * } * * }*/ bool bNoTag = false; bool bDupe = false; bool bExcluded = false; bool bBlacklisted = false; while (minLanceSize > lance.Count || currentLanceWeight < RngStart.Settings.MinimumStartingWeight) { Logger.Debug($"Begin Mech Finder Loop"); // build lance collection from dictionary for speed var randomMech = mechTonnages.ElementAt(rng.Next(0, mechTonnages.Count)); var mechString = randomMech.Key.Replace("chassisdef", "mechdef"); // getting chassisdefs so renaming the key to match mechdefs Id //var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechString), __instance.GenerateSimGameUID()); foreach (var mechID in RngStart.Settings.ExcludedMechs) { if (mechID == mechDef.Description.Id) { bExcluded = true; Logger.Debug($"Excluded! {mechDef.Description.Id}"); } } if (mechDef.MechTags.Contains("BLACKLISTED")) { bBlacklisted = true; Logger.Debug($"Blacklisted! {mechDef.Name}"); } if (!RngStart.Settings.AllowDuplicateChassis) { foreach (var mech in lance) { if (mech.Name == mechDef.Name) { bDupe = true; Logger.Debug($"SAME SAME! {mech.Name}\t\t{mechDef.Name}"); } } } if (!bBlacklisted && !bDupe && !bExcluded) { Logger.Debug($"Starting Planet: {__instance.Constants.Story.StartingTargetSystem}"); for (int iStart = 0; iStart < RngStart.Settings.startSystemList.Count; iStart++) { if (__instance.Constants.Story.StartingTargetSystem == RngStart.Settings.startSystemList[iStart]) { for (int iTag = 0; iTag < mechDef.MechTags.Count; iTag++) { foreach (var mechTag in RngStart.Settings.AllowedTags[iStart]) { if (mechTag == mechDef.MechTags[iTag]) { Logger.Debug($"INCLUDED!"); Logger.Debug($"Included Tag: {mechDef.MechTags[iTag]}"); Logger.Debug($"Included Mech:{mechDef.Description.Id}"); bNoTag = false; goto endTagCheck; } else { bNoTag = true; } } Logger.Debug($" "); Logger.Debug($"{RngStart.Settings.startSystemList[iStart]} Start!"); Logger.Debug($"Invalid Tag!"); Logger.Debug($"Mech Tag: {mechDef.MechTags[iTag]}"); Logger.Debug($" "); } endTagCheck: if (!bNoTag) { Logger.Debug($"Lance Count-1: {lance.Count}"); lance.Add(mechDef); currentLanceWeight += mechDef.Chassis.Tonnage; Logger.Debug($"Lance Count-2: {lance.Count}"); Logger.Debug($"Adding mech {mechString} {mechDef.Chassis.Tonnage} tons"); } else { bBlacklisted = false; bDupe = false; bExcluded = false; bNoTag = false; } } } } else { bBlacklisted = false; bDupe = false; bExcluded = false; bNoTag = false; } if (lance.Count >= maxLanceSize && currentLanceWeight < RngStart.Settings.MinimumStartingWeight) { Logger.Debug($"Under-Weight: {currentLanceWeight}"); Logger.Debug($"Lance Count: {lance.Count}"); var lightest = lance[1]; for (int i = 1; i < lance.Count; i++) { if (lightest.Chassis.Tonnage > lance[i].Chassis.Tonnage) { Logger.Debug($"Mech: {lance[i].Name}"); Logger.Debug($"Weight: {lance[i].Chassis.Tonnage}"); lightest = lance[i]; } } lance.Remove(lightest); currentLanceWeight -= lightest.Chassis.Tonnage; } if (lance.Count < minLanceSize && currentLanceWeight > RngStart.Settings.MaximumStartingWeight) { Logger.Debug($"Over-Weight: {currentLanceWeight}"); Logger.Debug($"Lance Count-1: {lance.Count}"); var heaviest = lance[1]; for (int i = 1; i < lance.Count; i++) { if (heaviest.Chassis.Tonnage < lance[i].Chassis.Tonnage) { Logger.Debug($"Mech: {lance[i].Name}"); Logger.Debug($"Weight: {lance[i].Chassis.Tonnage}"); heaviest = lance[i]; } } lance.Remove(heaviest); currentLanceWeight -= heaviest.Chassis.Tonnage; } } float tonnagechecker = 0; for (int x = 0; x < lance.Count; x++) { Logger.Debug($"x is {x} and lance[x] is {lance[x].Name}"); __instance.AddMech(x, lance[x], true, true, false); tonnagechecker = tonnagechecker + lance[x].Chassis.Tonnage; } Logger.Debug($"{tonnagechecker}"); float Maxtonnagedifference = tonnagechecker - RngStart.Settings.MaximumStartingWeight; float Mintonnagedifference = tonnagechecker - RngStart.Settings.MinimumStartingWeight; Logger.Debug($"Over tonnage Maximum amount: {Maxtonnagedifference}"); Logger.Debug($"Over tonnage Minimum amount: {Mintonnagedifference}"); lance.Clear(); } //Cheats.MyMethod(__instance); }