public static bool IsCrossAssemblyExcluded(this MechDef d) { if (!Settings.UseOnlyCCAssemblyOptions) { if (Settings.CrossAssemblyExcludedMechs.Contains(d.Description.Id)) { return(true); } if (d.Chassis.ChassisTags.Contains("chassis_ExcludeCrossAssembly")) { return(true); } } if (d.IsVehicle()) { VehicleChassisDef vd = d.Chassis.GetVehicleChassisDefFromFakeVehicle(); if (vd == null) { return(false); } IVAssemblyVariant vv = CCIntegration.GetCCVehicleAssemblyVariant(vd); if (vv == null) { return(false); } return(vv.Exclude); } IAssemblyVariant v = CCIntegration.GetCCAssemblyVariant(d.Chassis); if (v != null) { return(v.Exclude); } return(false); }
public static bool IsVariantKnown(SimGameState s, MechDef d) { if (!Settings.UseOnlyCCAssemblyOptions) { if (d.Chassis.ChassisTags.Contains("chassis_KnownOmniVariant")) { return(true); } } IAssemblyVariant v = CCIntegration.GetCCAssemblyVariant(d.Chassis); if (v != null) { if (v.KnownOmniVariant) { return(true); } } foreach (KeyValuePair <int, MechDef> a in s.ActiveMechs) { if (d.ChassisID == a.Value.ChassisID) { return(true); } } foreach (KeyValuePair <int, MechDef> a in s.ReadyingMechs) { if (d.ChassisID == a.Value.ChassisID) { return(true); } } string id = s.GetItemStatID(d.Description.Id, "MECHPART"); if (s.CompanyStats.ContainsStatistic(id)) { return(true); } id = s.GetItemStatID(d.Chassis.Description, d.GetType()); if (s.CompanyStats.ContainsStatistic(id)) { return(true); } return(false); }
public static MechDef GetSalvageRedirect(SimGameState s, MechDef m) { if (!SimpleMechAssembly_Main.Settings.UseOnlyCCAssemblyOptions) { if (SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageMechPartSalvageRedirect.TryGetValue(m.Description.Id, out string red)) { if (s.DataManager.MechDefs.TryGet(red, out MechDef n) && n != null) { SimpleMechAssembly_Main.Log.Log($"mechpart salvage redirection (settings): {m.Description.Id}->{red}"); return(n); } } string c = m.MechTags.FirstOrDefault((x) => x.StartsWith("mech_MechPartSalvageRedirect_")); if (c != null) { c = c.Replace("mech_MechPartSalvageRedirect_", ""); if (s.DataManager.MechDefs.TryGet(c, out MechDef n) && n != null) { SimpleMechAssembly_Main.Log.Log($"mechpart salvage redirection (tag): {m.Description.Id}->{c}"); return(n); } } } IAssemblyVariant v = CCIntegration.GetCCAssemblyVariant(m.Chassis); if (v != null && v.Lootable != null) { if (s.DataManager.MechDefs.TryGet(v.Lootable, out MechDef o)) { SimpleMechAssembly_Main.Log.Log($"mechpart salvage redirection (lootable): {m.Description.Id}->{v.Lootable}"); return(o); } } if (!SimpleMechAssembly_Main.Settings.AllowNonMainVariants && !m.IsMechDefMain()) { MechDef ma = m.Chassis.GetMainMechDef(s.DataManager); if (ma != null) { SimpleMechAssembly_Main.Log.Log($"mechpart salvage redirection (main): {m.Description.Id}->{ma.Description.Id}"); return(ma); } } return(m); }
public static void FinishedLoading() { CCIntegration.LoadDelegates(); CUIntegration.LoadDelegates(); }
public static void Postfix(Contract __instance, List <UnitResult> enemyMechs, List <VehicleDef> enemyVehicles, List <UnitResult> lostUnits, ref List <SalvageDef> ___finalPotentialSalvage) { ILog log = SimpleMechAssembly_Main.Log; if (__instance.BattleTechGame.Simulation == null) { log.LogError("trying to generarte salvage without a simgame"); return; } SimGameState s = __instance.BattleTechGame.Simulation; ___finalPotentialSalvage = new List <SalvageDef>(); __instance.SetSalvagedChassis(new List <SalvageDef>()); __instance.SetLostMechs(new List <MechDef>()); __instance.SetSalvageResults(new List <SalvageDef>()); foreach (UnitResult u in lostUnits) { log.Log($"player mech {u.mech.Description.Name} was lost"); if (u.mech.GetLocationLoadoutDef(ChassisLocations.CenterTorso).CurrentInternalStructure > 0f) { log.Log("ct not desytroyed, auto recovery"); u.mechLost = false; } else if (!IsPlayerMech(u.mech, s)) { log.Log("contract added player mech, auto recovery"); u.mechLost = false; } else if (s.NetworkRandom.Float(0f, 1f) <= s.Constants.Salvage.DestroyedMechRecoveryChance) { log.Log("recovery roll succeeded"); u.mechLost = false; } else { log.Log("recovery roll failed, unit goes into salvage pool"); u.mechLost = true; GenerateSalvageForMech(__instance, u, s, ___finalPotentialSalvage); } } foreach (UnitResult u in enemyMechs) { if (!(u.pilot.IsIncapacitated || u.pilot.HasEjected || u.mech.IsDestroyed || u.mech.Inventory.Any((x) => x.Def != null && x.Def.CriticalComponent && x.DamageLevel == ComponentDamageLevel.Destroyed) || CCIntegration.MechDefIsDead(u.mech))) { log.Log($"skipping salvage for mech {u.mech.Description.UIName} {u.mech.Chassis.VariantName}, cause its not dead"); continue; } GenerateSalvageForMech(__instance, u, s, ___finalPotentialSalvage); } foreach (Vehicle v in __instance.BattleTechGame.Combat.AllEnemies.OfType <Vehicle>().Where(t => t.IsDead)) { GenerateSalvageForVehicle(__instance, v, s, ___finalPotentialSalvage); } if (SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageTurretComponentSalvageChance > 0) { foreach (Turret t in __instance.BattleTechGame.Combat.AllEnemies.OfType <Turret>().Where(t => t.IsDead)) { log.Log($"generating salvage for turret {t.TurretDef.Description.Name}"); foreach (TurretComponentRef r in t.TurretDef.Inventory) { float rand = s.NetworkRandom.Float(0f, 1f); if (rand < SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageTurretComponentSalvageChance) { log.Log($"added salvage {r.Def.Description.Id} ({rand}<{SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageTurretComponentSalvageChance})"); AddUpgradeToSalvage(__instance, r.Def, s, ___finalPotentialSalvage); } else { log.Log($"missed salvage {r.Def.Description.Id} ({rand}>={SimpleMechAssembly_Main.Settings.StructurePointBasedSalvageTurretComponentSalvageChance})"); } } } } int salvagepotential = __instance.SalvagePotential; float schanc = s.Constants.Salvage.VictorySalvageChance; float mlos = s.Constants.Salvage.VictorySalvageLostPerMechDestroyed; if (__instance.State == Contract.ContractState.Failed) { schanc = s.Constants.Salvage.DefeatSalvageChance; mlos = s.Constants.Salvage.DefeatSalvageLostPerMechDestroyed; } else if (__instance.State == Contract.ContractState.Retreated) { schanc = s.Constants.Salvage.RetreatSalvageChance; mlos = s.Constants.Salvage.RetreatSalvageLostPerMechDestroyed; } float mod = schanc; float persalpot = salvagepotential * __instance.PercentageContractSalvage; if (salvagepotential > 0) { persalpot += s.Constants.Finances.ContractFloorSalvageBonus; } mod = Mathf.Max(0f, schanc - mlos * lostUnits.Count); __instance.SetFinalSalvageCount(Mathf.FloorToInt(persalpot * mod)); __instance.SetFinalPrioritySalvageCount(Math.Min(8, Mathf.FloorToInt(__instance.FinalSalvageCount * s.Constants.Salvage.PrioritySalvageModifier))); }
public static bool IsCrossAssemblyOverrideEnabled(MechDef a, MechDef b, string va, string vb) { if (!Settings.UseOnlyCCAssemblyOptions) { if (a.Chassis.ChassisTags.Contains($"chassis_CrossAssemblyAllowedWith_{vb}")) { return(true); } if (b.Chassis.ChassisTags.Contains($"chassis_CrossAssemblyAllowedWith_{va}")) { return(true); } if (a.Chassis.ChassisTags.Contains($"chassis_CrossAssemblyAllowedWith_{b.Chassis.VariantName}")) { return(true); } if (b.Chassis.ChassisTags.Contains($"chassis_CrossAssemblyAllowedWith_{a.Chassis.VariantName}")) { return(true); } if (a.Chassis.ChassisTags.Contains($"chassis_CrossAssemblyAllowedWith_{b.Description.Id}")) { return(true); } if (b.Chassis.ChassisTags.Contains($"chassis_CrossAssemblyAllowedWith_{a.Description.Id}")) { return(true); } } IAssemblyVariant av = CCIntegration.GetCCAssemblyVariant(a.Chassis); if (av != null && av.AssemblyAllowedWith != null) { if (av.AssemblyAllowedWith.Contains(vb)) { return(true); } if (av.AssemblyAllowedWith.Contains(b.Chassis.VariantName)) { return(true); } if (av.AssemblyAllowedWith.Contains(b.Description.Id)) { return(true); } } IAssemblyVariant bv = CCIntegration.GetCCAssemblyVariant(b.Chassis); if (bv != null && bv.AssemblyAllowedWith != null) { if (bv.AssemblyAllowedWith.Contains(va)) { return(true); } if (bv.AssemblyAllowedWith.Contains(a.Chassis.VariantName)) { return(true); } if (bv.AssemblyAllowedWith.Contains(a.Description.Id)) { return(true); } } return(false); }