internal static int Vanila(MechDef mech) { if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { return(1); } if (mech.IsLocationDestroyed(ChassisLocations.LeftLeg) && mech.IsLocationDestroyed(ChassisLocations.RightLeg)) { return(2); } return(3); }
private static void AddMechToSalvage(MechDef mech, ContractHelper contract, SimGameState simgame, SimGameConstants constants, bool can_upgrade) { Control.LogDebug($"-- Salvaging {mech.Name}"); int numparts = Control.GetNumParts(mech); try { Control.LogDebug($"--- Adding {numparts} parts"); contract.AddMechPartsToPotentialSalvage(constants, mech, numparts); } catch (Exception e) { Control.LogError("Error in adding parts", e); } try { foreach (var component in mech.Inventory.Where(item => !mech.IsLocationDestroyed(item.MountedLocation) && item.DamageLevel != ComponentDamageLevel.Destroyed)) { contract.AddComponentToPotentialSalvage(component.Def, ComponentDamageLevel.Functional, can_upgrade); } } catch (Exception e) { Control.LogError("Error in adding component", e); } }
public static int GetMechPartCountForSalvage(MechDef m, Pilot p) { if (m.IsLocationDestroyed(ChassisLocations.CenterTorso)) { return(1); } if (m.IsLocationDestroyed(ChassisLocations.LeftLeg) && m.IsLocationDestroyed(ChassisLocations.RightLeg)) { return(2); } if (p.IsIncapacitated || m.IsLocationDestroyed(ChassisLocations.Head)) { return(3); } return(0); }
internal static int VanilaAdjusted(MechDef mech) { int n = UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax; { if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { return((int)(n * Control.Settings.VACTDestroyedMod)); } if (mech.IsLocationDestroyed(ChassisLocations.LeftLeg) && mech.IsLocationDestroyed(ChassisLocations.RightLeg)) { return((int)(n * Control.Settings.VABLDestroyedMod)); } return(n); } }
internal static int PartDestroyed(MechDef mech) { if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { return(Control.Settings.CenterTorsoDestroyedParts); } float total = Control.Settings.SalvageArmWeight * 2 + Control.Settings.SalvageHeadWeight + Control.Settings.SalvageLegWeight * 2 + Control.Settings.SalvageTorsoWeight * 2 + 1; float val = total; val -= mech.IsLocationDestroyed(ChassisLocations.Head) ? Control.Settings.SalvageHeadWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftTorso) ? Control.Settings.SalvageTorsoWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.RightTorso) ? Control.Settings.SalvageTorsoWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftLeg) ? Control.Settings.SalvageLegWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.RightLeg) ? Control.Settings.SalvageLegWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftArm) ? Control.Settings.SalvageArmWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftLeg) ? Control.Settings.SalvageArmWeight : 0; var constants = UnityGameInstance.BattleTechGame.Simulation.Constants; int numparts = (int)(constants.Story.DefaultMechPartMax * val / total + 0.5f); if (numparts <= 0) { numparts = 1; } if (numparts > constants.Story.DefaultMechPartMax) { numparts = constants.Story.DefaultMechPartMax; } return(numparts); }
static bool Prefix(Contract __instance, List <UnitResult> enemyMechs, List <VehicleDef> enemyVehicles, List <UnitResult> lostUnits, bool logResults = false) { try { Settings settings = Helper.LoadSettings(); if (__instance.BattleTechGame.Simulation == null) { return(false); } ReflectionHelper.SetPrivateField(__instance, "finalPotentialSalvage", new List <SalvageDef>()); ReflectionHelper.InvokePrivateMethode(__instance, "set_SalvagedChassis", new object[] { new List <SalvageDef>() }); ReflectionHelper.InvokePrivateMethode(__instance, "set_LostMechs", new object[] { new List <MechDef>() }); ReflectionHelper.InvokePrivateMethode(__instance, "set_SalvageResults", new object[] { new List <SalvageDef>() }); SimGameState simulation = __instance.BattleTechGame.Simulation; SimGameConstants constants = simulation.Constants; for (int i = 0; i < lostUnits.Count; i++) { MechDef mech = lostUnits[i].mech; Pilot pilot = lostUnits[i].pilot; float num = simulation.NetworkRandom.Float(0f, 1f); float ejectRecoveryBonus = 0; float incapacitatedRecoveryBonus = 0; bool notDestroyed = !mech.IsLocationDestroyed(ChassisLocations.CenterTorso) && !mech.IsLocationDestroyed(ChassisLocations.Head) && (!mech.IsLocationDestroyed(ChassisLocations.LeftLeg) && !mech.IsLocationDestroyed(ChassisLocations.RightLeg)); if (pilot.HasEjected) { ejectRecoveryBonus = settings.ejectRecoveryBonus; } else if (mech.IsLocationDestroyed(ChassisLocations.Head) || (pilot.IsIncapacitated && notDestroyed)) { incapacitatedRecoveryBonus = settings.incapacitatedRecoveryBonus; } bool flag = num <= constants.Salvage.DestroyedMechRecoveryChance + ejectRecoveryBonus + incapacitatedRecoveryBonus; // keep mech if the roll is good enough, or if CT + head + legs are intact and the pilot isn't incapacitated if (flag || (notDestroyed && !pilot.IsIncapacitated)) { lostUnits[i].mechLost = false; } else { lostUnits[i].mechLost = true; float mechparts = simulation.Constants.Story.DefaultMechPartMax; if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { mechparts = settings.centerTorsoSalvageValue; } else { if (mech.IsLocationDestroyed(ChassisLocations.LeftArm)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } if (mech.IsLocationDestroyed(ChassisLocations.RightArm)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } if (mech.IsLocationDestroyed(ChassisLocations.LeftLeg)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } if (mech.IsLocationDestroyed(ChassisLocations.RightLeg)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } } SalvageDef def = (SalvageDef)ReflectionHelper.InvokePrivateMethode(__instance, "CreateMechPart", new object[] { constants, mech }); if (settings.ownMechsForFree) { for (int s = 0; s < Mathf.RoundToInt(mechparts); s++) { __instance.SalvageResults.Add(def); } } else { List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage"); ReflectionHelper.InvokePrivateMethode(__instance, "CreateAndAddMechPart", new object[] { constants, mech, Mathf.RoundToInt(mechparts), finalPotentialSalvage }); } if (settings.ownMechsForFree) { foreach (MechComponentRef mechComponentRef in mech.Inventory) { if (!mech.IsLocationDestroyed(mechComponentRef.MountedLocation) && mechComponentRef.DamageLevel != ComponentDamageLevel.Destroyed) { ReflectionHelper.InvokePrivateMethode(__instance, "AddToFinalSalvage", new object[] { new SalvageDef { MechComponentDef = mechComponentRef.Def, Description = new DescriptionDef(mechComponentRef.Def.Description), RewardID = __instance.GenerateRewardUID(), Type = SalvageDef.SalvageType.COMPONENT, ComponentType = mechComponentRef.Def.ComponentType, Damaged = false, Count = 1 } }); } } } else { foreach (MechComponentRef mechComponentRef in mech.Inventory) { if (!mech.IsLocationDestroyed(mechComponentRef.MountedLocation) && mechComponentRef.DamageLevel != ComponentDamageLevel.Destroyed) { List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage"); ReflectionHelper.InvokePrivateMethode(__instance, "AddMechComponentToSalvage", new object[] { finalPotentialSalvage, mechComponentRef.Def, ComponentDamageLevel.Functional, false, constants, simulation.NetworkRandom, true }); } } } } } int k = 0; while (k < enemyMechs.Count) { MechDef mech2 = enemyMechs[k].mech; Pilot pilot = enemyMechs[k].pilot; SalvageDef salvageDef = null; bool flag2 = false; bool flag3 = false; List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage"); if (pilot.IsIncapacitated || mech2.IsDestroyed || mech2.Inventory.Any(cref => cref.Def != null && cref.Def.CriticalComponent && cref.DamageLevel == ComponentDamageLevel.Destroyed)) { float mechparts = simulation.Constants.Story.DefaultMechPartMax; if (mech2.IsLocationDestroyed(ChassisLocations.CenterTorso)) { mechparts = settings.centerTorsoSalvageValue; } else { if (mech2.IsLocationDestroyed(ChassisLocations.LeftArm)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } if (mech2.IsLocationDestroyed(ChassisLocations.RightArm)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } if (mech2.IsLocationDestroyed(ChassisLocations.LeftLeg)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } if (mech2.IsLocationDestroyed(ChassisLocations.RightLeg)) { mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5); } } ReflectionHelper.InvokePrivateMethode(__instance, "CreateAndAddMechPart", new object[] { constants, mech2, Mathf.RoundToInt(mechparts), finalPotentialSalvage }); goto IL_2E4; } IL_4AB: k++; continue; IL_2E4: foreach (MechComponentRef mechComponentRef2 in mech2.Inventory) { if (!mech2.IsLocationDestroyed(mechComponentRef2.MountedLocation) && mechComponentRef2.DamageLevel != ComponentDamageLevel.Destroyed) { ReflectionHelper.InvokePrivateMethode(__instance, "AddMechComponentToSalvage", new object[] { finalPotentialSalvage, mechComponentRef2.Def, ComponentDamageLevel.Functional, false, constants, simulation.NetworkRandom, true }); } } if (flag3) { salvageDef = new SalvageDef(); salvageDef.Type = SalvageDef.SalvageType.CHASSIS; salvageDef.Description = new DescriptionDef(mech2.Chassis.Description); salvageDef.Count = 1; IEnumerator enumerator = Enum.GetValues(typeof(ChassisLocations)).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; ChassisLocations chassisLocations = (ChassisLocations)obj; if (chassisLocations != ChassisLocations.None && chassisLocations != ChassisLocations.All && chassisLocations != ChassisLocations.Arms && chassisLocations != ChassisLocations.Legs && chassisLocations != ChassisLocations.Torso && chassisLocations != ChassisLocations.MainBody) { salvageDef.ChassisLocations.Add(chassisLocations); salvageDef.ChassisStructure.Add(mech2.GetLocationLoadoutDef(chassisLocations).CurrentInternalStructure); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } if (flag2) { for (int m = 0; m < salvageDef.ChassisLocations.Count; m++) { List <float> chassisStructure; int index; (chassisStructure = salvageDef.ChassisStructure)[index = m] = chassisStructure[index] / 2f; } } salvageDef.Weight = constants.Salvage.DefaultChassisWeight; __instance.SalvagedChassis.Add(salvageDef); goto IL_4AB; } goto IL_4AB; } for (int n = 0; n < enemyVehicles.Count; n++) { VehicleDef vehicleDef = enemyVehicles[n]; List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage"); foreach (VehicleComponentRef vehicleComponentRef in vehicleDef.Inventory) { ReflectionHelper.InvokePrivateMethode(__instance, "AddMechComponentToSalvage", new object[] { finalPotentialSalvage, vehicleComponentRef.Def, ComponentDamageLevel.Functional, false, constants, simulation.NetworkRandom, true }); } } int num2 = __instance.SalvagePotential; float num3 = constants.Salvage.VictorySalvageChance; float num4 = constants.Salvage.VictorySalvageLostPerMechDestroyed; if (__instance.State == Contract.ContractState.Failed) { num3 = constants.Salvage.DefeatSalvageChance; num4 = constants.Salvage.DefeatSalvageLostPerMechDestroyed; } else if (__instance.State == Contract.ContractState.Retreated) { num3 = constants.Salvage.RetreatSalvageChance; num4 = constants.Salvage.RetreatSalvageLostPerMechDestroyed; } float num5 = num3; float num6 = (float)num2 * __instance.PercentageContractSalvage; if (num2 > 0) { num6 += (float)constants.Finances.ContractFloorSalvageBonus; } num3 = Mathf.Max(0f, num5 - num4 * (float)lostUnits.Count); int num7 = Mathf.FloorToInt(num6 * num3); if (num2 > 0) { num2 += constants.Finances.ContractFloorSalvageBonus; } ReflectionHelper.InvokePrivateMethode(__instance, "set_FinalSalvageCount", new object[] { num7 }); ReflectionHelper.InvokePrivateMethode(__instance, "set_FinalPrioritySalvageCount", new object[] { Mathf.FloorToInt((float)num7 * constants.Salvage.PrioritySalvageModifier) }); return(false); } catch (Exception e) { Logger.LogError(e); return(false); } }
static void Postfix(Contract __instance, List <UnitResult> enemyMechs, List <VehicleDef> enemyVehicles, List <UnitResult> lostUnits, bool logResults = false) { Logger.LogLine("Postfix Start"); Settings settings = CompanyMechSalvage.LoadSettings(); Logger.LogLine("Settings Loaded"); SimGameState simulation = __instance.BattleTechGame.Simulation; SimGameConstants constants = simulation.Constants; float roll = simulation.NetworkRandom.Float(0f, 1f); Logger.LogLine("Rolled: " + roll); bool recovered = roll <= settings.RecoveryChance; if (!recovered) { Logger.LogLine("Mech not recovered"); for (int i = 0; i < lostUnits.Count; i++) { MechDef mech = lostUnits[i].mech; if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { Logger.LogLine("CT destroyed"); lostUnits[i].mechLost = true; SalvageDef def = CompanyMechSalvage.CreateMechPart(__instance, constants, mech); __instance.SalvageResults.Add(def); foreach (MechComponentRef mechComponentRef in mech.Inventory) { if (!mech.IsLocationDestroyed(mechComponentRef.MountedLocation) && mechComponentRef.DamageLevel != ComponentDamageLevel.Destroyed) { __instance.SalvageResults.Add(new SalvageDef { MechComponentDef = mechComponentRef.Def, Description = new DescriptionDef(mechComponentRef.Def.Description), RewardID = __instance.GenerateRewardUID(), Type = SalvageDef.SalvageType.COMPONENT, ComponentType = mechComponentRef.Def.ComponentType, Damaged = false, Count = 1 }); } } } else if ((mech.IsLocationDestroyed(ChassisLocations.LeftLeg) && mech.IsLocationDestroyed(ChassisLocations.RightLeg)) || (mech.IsLocationDestroyed(ChassisLocations.Head) && settings.DestroyedWithHead)) { Logger.LogLine("Legs or Head destroyed"); lostUnits[i].mechLost = true; SalvageDef def = CompanyMechSalvage.CreateMechPart(__instance, constants, mech); __instance.SalvageResults.Add(def); __instance.SalvageResults.Add(def); foreach (MechComponentRef mechComponentRef in mech.Inventory) { if (!mech.IsLocationDestroyed(mechComponentRef.MountedLocation) && mechComponentRef.DamageLevel != ComponentDamageLevel.Destroyed) { __instance.SalvageResults.Add(new SalvageDef { MechComponentDef = mechComponentRef.Def, Description = new DescriptionDef(mechComponentRef.Def.Description), RewardID = __instance.GenerateRewardUID(), Type = SalvageDef.SalvageType.COMPONENT, ComponentType = mechComponentRef.Def.ComponentType, Damaged = false, Count = 1 }); } } } Logger.LogLine("Salvage created"); } } }
public static bool IsLocationDestroyed(this MechDef mechDef, ChassisLocations location) { lastMechDef = mechDef; return(mechDef.IsLocationDestroyed(location)); }
private static void AddMechToSalvage(MechDef mech, ContractHelper contract, SimGameState simgame, SimGameConstants constants, List <SalvageDef> salvage) { Control.LogDebug(DType.SalvageProccess, $"-- Salvaging {mech.Name}"); int numparts = 0; if (Control.Settings.OverrideMechPartCalculation) { if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { numparts = Control.Settings.CenterTorsoDestroyedParts; } else { float total = Control.Settings.SalvageArmWeight * 2 + Control.Settings.SalvageHeadWeight + Control.Settings.SalvageLegWeight * 2 + Control.Settings.SalvageTorsoWeight * 2 + 1; float val = total; val -= mech.IsLocationDestroyed(ChassisLocations.Head) ? Control.Settings.SalvageHeadWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftTorso) ? Control.Settings.SalvageTorsoWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.RightTorso) ? Control.Settings.SalvageTorsoWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftLeg) ? Control.Settings.SalvageLegWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.RightLeg) ? Control.Settings.SalvageLegWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftArm) ? Control.Settings.SalvageArmWeight : 0; val -= mech.IsLocationDestroyed(ChassisLocations.LeftLeg) ? Control.Settings.SalvageArmWeight : 0; numparts = (int)(constants.Story.DefaultMechPartMax * val / total + 0.5f); if (numparts <= 0) { numparts = 1; } if (numparts > constants.Story.DefaultMechPartMax) { numparts = constants.Story.DefaultMechPartMax; } } } else { numparts = 3; if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { numparts = 1; } else if (mech.IsLocationDestroyed(ChassisLocations.LeftLeg) && mech.IsLocationDestroyed(ChassisLocations.RightLeg)) { numparts = 2; } } try { Control.LogDebug(DType.SalvageProccess, $"--- Adding {numparts} parts"); contract.CreateAndAddMechPart(constants, mech, numparts, salvage); } catch (Exception e) { Control.LogError("Error in adding parts", e); } try { if (Control.Settings.NoLootCTDestroyed && mech.IsLocationDestroyed(ChassisLocations.CenterTorso)) { Control.LogDebug(DType.SalvageProccess, $"--- CT Destroyed - no component loot"); } else { foreach (var component in mech.Inventory.Where(item => !mech.IsLocationDestroyed(item.MountedLocation) && item.DamageLevel != ComponentDamageLevel.Destroyed)) { Control.LogDebug(DType.SalvageProccess, $"--- Adding {component.ComponentDefID}"); contract.AddMechComponentToSalvage(salvage, component.Def, ComponentDamageLevel.Functional, false, constants, simgame.NetworkRandom, true); } } } catch (Exception e) { Control.LogError("Error in adding component", e); } }
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(Contract __instance, List <UnitResult> enemyMechs, ref List <SalvageDef> ___finalPotentialSalvage, DataManager ___dataManager) { try { // Only for opportunity contracts if (__instance.IsOpportunityMission()) { Logger.Debug($"[Contract_GenerateSalvage_POSTFIX] Checking BLACKLISTED overrides for contract {__instance.Override.ID}"); SimGameState simGameState = __instance.BattleTechGame.Simulation; SimGameConstants simGameConstants = simGameState.Constants; foreach (UnitResult unitResult in enemyMechs) { MechDef mech = unitResult.mech; Pilot pilot = unitResult.pilot; // Component handling needs to be before evaluating MechParts as there the MechDef is probably normalized if (mech.MechTags.Contains("WHITELIST_COMPONENTS")) { Logger.Debug($"[Contract_GenerateSalvage_POSTFIX] MechDef of {mech.Name} has WHITELIST_COMPONENTS tag. Manually adding blacklisted components to salvage."); foreach (MechComponentRef mechComponentRef in mech.Inventory) { // Skip if destroyed or in a destroyed location if (mech.IsLocationDestroyed(mechComponentRef.MountedLocation) || mechComponentRef.DamageLevel == ComponentDamageLevel.Destroyed) { continue; } if (mechComponentRef.Def.ComponentTags.Contains("BLACKLISTED")) { Logger.Debug($"[Contract_GenerateSalvage_PREFIX] mechComponentRef.Def {mechComponentRef.Def.Description.Id} has BLACKLISTED tag. Adding to salvage."); SalvageDef salvageDef = Utilities.CreateComponent(simGameConstants, __instance, mechComponentRef.Def); ___finalPotentialSalvage.Add(salvageDef); } } } // MechParts if (mech.MechTags.Contains("BLACKLISTED") || mech.Chassis.ChassisTags.Contains("BLACKLISTED")) { Logger.Debug($"[Contract_GenerateSalvage_POSTFIX] MechDef or ChassisDef of {mech.Name} has BLACKLISTED tag. Checking for override flags."); if (mech.MechTags.Contains("WHITELIST_PARTS")) { Logger.Debug($"[Contract_GenerateSalvage_POSTFIX] MechDef of {mech.Name} has WHITELIST_PARTS tag. Manually adding MechParts to salvage."); // Needs to work on original MechDef so has to be called before a possible normalization int numberOfParts = Utilities.GetMechPartCountForSalvage(mech, pilot); // Normalize MechDef string stockMechDefId = mech.ChassisID.Replace("chassisdef", "mechdef"); if (mech.Description.Id != stockMechDefId) { Logger.Debug($"[Contract_GenerateSalvage_POSTFIX] Normalizing {mech.Description.Id} to {stockMechDefId}"); mech = ___dataManager.MechDefs.Get(stockMechDefId); } // Add MechParts to Salvage for (int i = 0; i < numberOfParts; i++) { SalvageDef salvageDef = Utilities.CreateMechPart(simGameConstants, __instance, mech); ___finalPotentialSalvage.Add(salvageDef); } } } } } } catch (Exception e) { Logger.Error(e); } }
private static void BrokeMech(MechDef new_mech, SimGameState sim) { try { Control.LogDebug($"-- broke parts"); var rnd = new Random(); float LimbChance = Control.Settings.RepairMechLimbsChance; float CompFChance = Control.Settings.RepairComponentsFunctionalThreshold; float CompNFChance = Control.Settings.RepairComponentsNonFunctionalThreshold; if (Control.Settings.RepairChanceByTP) { var basetp = Control.Settings.BaseTP; var limbtp = Control.Settings.LimbChancePerTp; var comptp = Control.Settings.ComponentChancePerTp; if (Control.Settings.BrokeByTag != null && Control.Settings.BrokeByTag.Length > 1) { int numb = 0; int numl = 0; int numc = 0; int sumb = 0; float suml = 0; float sumc = 0; foreach (var info in Control.Settings.BrokeByTag) { if (new_mech.MechTags.Contains(info.tag) || new_mech.Chassis.ChassisTags.Contains(info.tag)) { #if CCDEBUG string logstr = info.tag; #endif if (info.BaseTp > 0) { sumb += info.BaseTp; numb += 1; #if CCDEBUG logstr += $" base:{info.BaseTp}"; #endif } if (info.Limb > 0) { suml += info.Limb; numl += 1; #if CCDEBUG logstr += $" limb:{info.Limb:0.000}"; #endif } if (info.Component > 0) { sumc += info.Component; numc += 1; #if CCDEBUG logstr += $" comp:{info.Component:0.000}"; #endif } #if CCDEBUG Control.LogDebug(logstr); #endif } } if (numb > 0) { basetp = sumb / numb; } if (numl > 0) { limbtp = suml / numl; } if (numc > 0) { comptp = sumc / numc; } Control.LogDebug($"totals: base:{basetp}, limb:{limbtp:0.000}, component:{comptp:0.000}"); var tp = sim.MechTechSkill - basetp; var ltp = Mathf.Clamp(tp * limbtp, -Control.Settings.RepairTPMaxEffect, Control.Settings.RepairTPMaxEffect); var ctp = Mathf.Clamp(tp * comptp, -Control.Settings.RepairTPMaxEffect, Control.Settings.RepairTPMaxEffect); Control.LogDebug($"LeftTP: {tp} limb_change = {ltp:0.000} comp_change = {ctp * comptp:0.000}"); LimbChance = Mathf.Clamp(LimbChance + ltp, Control.Settings.LimbMinChance, Control.Settings.LimbMaxChance); CompFChance = Mathf.Clamp(CompFChance + ctp, Control.Settings.ComponentMinChance, Control.Settings.ComponentMaxChance); CompNFChance = Mathf.Clamp(CompNFChance + ctp, CompFChance, Control.Settings.ComponentMaxChance); } } Control.LogDebug($"--- RepairMechLimbsChance: {LimbChance}, RepairMechLimbs: {Control.Settings.RepairMechLimbs} "); float roll = 0; //hd roll = (float)rnd.NextDouble(); Control.LogDebug($"--- HeadRepaired: {Control.Settings.HeadRepaired}, roll: {roll} "); if (!Control.Settings.HeadRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.Head.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.Head.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //ct roll = (float)rnd.NextDouble(); Control.LogDebug($"--- CentralTorsoRepaired: {Control.Settings.CentralTorsoRepaired}, roll: {roll} "); if (!Control.Settings.CentralTorsoRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.CenterTorso.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.CenterTorso.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //rt roll = (float)rnd.NextDouble(); Control.LogDebug($"--- RightTorsoRepaired: {Control.Settings.RightTorsoRepaired}, roll: {roll} "); if (!Control.Settings.RightTorsoRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.RightTorso.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.RightTorso.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //lt roll = (float)rnd.NextDouble(); Control.LogDebug($"--- LeftTorsoRepaired: {Control.Settings.LeftTorsoRepaired}, roll: {roll} "); if (!Control.Settings.LeftTorsoRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.LeftTorso.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.LeftTorso.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //ra roll = (float)rnd.NextDouble(); Control.LogDebug($"--- RightArmRepaired: {Control.Settings.RightArmRepaired}, roll: {roll} "); if (!Control.Settings.RightArmRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.RightArm.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.RightArm.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //la roll = (float)rnd.NextDouble(); Control.LogDebug($"--- LeftArmRepaired: {Control.Settings.LeftArmRepaired}, roll: {roll} "); if (!Control.Settings.LeftArmRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.LeftArm.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.LeftArm.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //rl roll = (float)rnd.NextDouble(); Control.LogDebug($"--- RightLegRepaired: {Control.Settings.RightLegRepaired}, roll: {roll} "); if (!Control.Settings.RightLegRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.RightLeg.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.RightLeg.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } //ll Control.LogDebug($"--- LeftLegRepaired: {Control.Settings.LeftLegRepaired}, roll: {roll} "); roll = (float)rnd.NextDouble(); if (!Control.Settings.LeftLegRepaired && (!Control.Settings.RepairMechLimbs || roll > LimbChance)) { new_mech.LeftLeg.CurrentInternalStructure = 0f; } else if (Control.Settings.RandomStructureOnRepairedLimbs) { new_mech.LeftLeg.CurrentInternalStructure *= Math.Min(Control.Settings.MinStructure, (float)rnd.NextDouble()); } Control.LogDebug($"-- broke equipment"); foreach (var cref in new_mech.Inventory) { if (new_mech.IsLocationDestroyed(cref.MountedLocation)) { Control.LogDebug($"---- {cref.ComponentDefID} - location destroyed"); cref.DamageLevel = ComponentDamageLevel.Destroyed; } else if (Control.Settings.RepairMechComponents) { roll = (float)rnd.NextDouble(); if (roll < CompFChance) { Control.LogDebug( $"---- {cref.ComponentDefID} - {roll} vs {CompFChance} - repaired "); cref.DamageLevel = ComponentDamageLevel.Functional; } else if (roll < CompNFChance) { Control.LogDebug( $"---- {cref.ComponentDefID} - {roll} vs {CompNFChance} - broken "); cref.DamageLevel = ComponentDamageLevel.NonFunctional; } else { Control.LogDebug( $"---- {cref.ComponentDefID} - {roll} vs {CompNFChance} - fubar "); cref.DamageLevel = ComponentDamageLevel.Destroyed; } } } } catch (Exception e) { Control.LogError($"ERROR in BrokeParts", e); throw; } }