public static bool Prefix(SimGameState __instance, string id) { __instance.AddItemStat(id, "MECHPART", false); if (SimGameState_ResolveCompleteContract.IsResolving != null) // save added mechs for later completion { if (!SimGameState_ResolveCompleteContract.IsResolving.ContainsKey(id)) { SimGameState_ResolveCompleteContract.IsResolving.Add(id, 0); } SimGameState_ResolveCompleteContract.IsResolving[id]++; } else // no contract -> direct assembly { MechDef d = __instance.DataManager.MechDefs.Get(id); int p = SimpleMechAssembly_Main.GetNumPartsForAssembly(__instance, d); if (p >= __instance.Constants.Story.DefaultMechPartMax) { //SimpleMechAssembly_Main.QueryMechAssemblyPopup(__instance, d, null); __instance.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(__instance, d, null), true); } } return(false); // completely replace }
internal static void OnAddItemStat(SimGameState sim, MechComponentRef mechComponentRef) { if (mechComponentRef == null) { return; } //if (mechComponentRef.DamageLevel == ComponentDamageLevel.Destroyed) //{ // return; //} var engineRef = mechComponentRef.GetEngineRef(); if (engineRef == null) { return; } foreach (var componentDefID in engineRef.GetInternalComponents()) { //Control.mod.Logger.LogDebug("SimGameState.OnAddItemStat extracting componentDefID=" + componentDefID); sim.AddItemStat(componentDefID, typeof(HeatSinkDef), false); } }
internal static bool AddItemStat(SimGameState sim, MechComponentRef mechComponentRef, string id, Type type, bool damaged) { var engineRef = mechComponentRef.GetEngineRef(); if (engineRef == null) { return(true); } sim.AddItemStat(id, type, damaged); foreach (var componentDefID in engineRef.GetInternalComponents()) { sim.AddItemStat(componentDefID, typeof(HeatSinkDef), damaged); } return(false); }
internal static void AddItemStat(this SimGameState sim, string id, Type type, bool damaged) { if (mechComponentRef != null && !EnginePersistence.AddItemStat(sim, mechComponentRef, id, type, damaged)) { return; } sim.AddItemStat(id, type, damaged); }
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 AddItemStat(this SimGameState instance, string id, Type type, bool damaged) { try { // Control.mod.Logger.LogDebug("AddItemStat id=" + id); instance.AddItemStat(id, type, damaged); OnAddItemStat(instance); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
internal static void AddInternalItemsStat(SimGameState sim, MechComponentRef mechComponentRef, string id, Type type, bool damaged) { var engineRef = mechComponentRef.GetEngineCoreRef(); if (engineRef == null) { return; } foreach (var componentDefID in engineRef.GetInternalComponents()) { sim.AddItemStat(componentDefID, typeof(HeatSinkDef), damaged); } }
internal static void AddItemStat(this SimGameState sim, string id, Type type, bool damaged) { try { if (mechComponentRef != null) { EnginePersistence.AddInternalItemsStat(sim, mechComponentRef, id, type, damaged); } mechComponentRef = null; } catch (Exception e) { Control.mod.Logger.LogError(e); } sim.AddItemStat(id, type, damaged); }
public static bool UnreadyVehicle(int baySlot, MechDef def, SimGameState __instance) { if (!def.IsVehicle()) { return(true); } if (def == null || (baySlot > 0 && !__instance.ActiveMechs.ContainsKey(baySlot))) { return(false); } if (__instance.ActiveMechs.ContainsKey(baySlot)) { __instance.ActiveMechs.Remove(baySlot); } __instance.AddItemStat(def.Chassis.Description.Id, def.GetType(), false); return(false); }
/// <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); } } }
public static bool Prefix(SimGameState __instance, string id) { if (Main.Settings.DependsOnArgoUpgrade && !__instance.PurchasedArgoUpgrades.Contains(Main.Settings.ArgoUpgrade)) { return(true); } // this function replaces the function from SimGameState, prefix return false // just add the piece if (id != null) { __instance.AddItemStat(id, "MECHPART", false); } // we're in the middle of resolving a contract, add the piece to contract if (Main.IsResolvingContract) { if (!Main.SalvageFromContract.ContainsKey(id)) { Main.SalvageFromContract[id] = 0; } Main.SalvageFromContract[id]++; return(false); } // TODO: what happens when you buy multiple pieces from the store at once and can build for each? // not in contract, just try to build with what we have if (!__instance.CompanyTags.Contains("SO_Salvaging")) { Main.ExcludedVariantHolder = __instance.DataManager.MechDefs.Get(id); Main.TryBuildMechs(__instance, new Dictionary <string, int> { { id, 1 } }); Main.ConvertCompanyTags(true); } return(false); }
static bool Prefix(string id, SimGameState __instance) { __instance.AddItemStat(id, "MECHPART", false); return(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 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 Add(string param) { SimGameState simGameState = SceneSingletonBehavior <UnityGameInstance> .Instance.Game.Simulation; DataProvider dataProvider = new DataProvider(); if (param == "help") { string help = ""; help += "• This command will add mechs to your inventory"; help += Environment.NewLine; help += "• Params: the variant name of the desired mech"; help += Environment.NewLine; help += "• Example: '/mech warhammer_WHM-6R'"; PopupHelper.Info(help); return; } // Special interests if (param == "bourbon") { foreach (string id in dataProvider.BourbonCustomMechIds) { AddMech(id, true); } return; } if (param == "special") { foreach (string id in dataProvider.SpecialGearMechIds) { AddMech(id, true); } return; } // Shortcut if param already is a proper mechdef if (simGameState.DataManager.MechDefs.Exists(param)) { simGameState.AddMechByID(param, true); return; } // BEN: Note that the CHASSIS.ID is needed for this to function correctly. // Even in SimGameState.AddMech this would be called with a MechDef (which doesn't work) // Currently all calls to SimGameState.AddMech seem to use params that won't get to that place // In SimGameState.UnreadyMech it's called with a MechDef.Chassis.Description.Id and works correctly //string chassisId = simGameState.GetChassisIdFromVariantName(param.ToUpper()); string chassisId = simGameState.GetChassisIdFromVariantName(param); if (chassisId == null) { string message = $"No mech found for variant: {param}"; Logger.Debug($"[Cheater_Mech_Add] {message}"); PopupHelper.Info(message); return; } AddMech(chassisId); // Local helper void AddMech(string id, bool force = false) { string mechId = id.Replace("chassisdef", "mechdef"); if (!force && !dataProvider.MechDefIds.Contains(mechId)) { string message = $"{mechId} is blacklisted."; Logger.Debug($"[Cheater_Mech_Add] {message}"); PopupHelper.Info(message); return; } if (FellOffACargoShip.Settings.AddMechsSilently) { simGameState.AddItemStat(id, typeof(MechDef), false); string message = $"{id} added to inventory."; Logger.Debug($"[Cheater_Mech_Add] {message}"); PopupHelper.Info(message); } else { simGameState.AddMechByID(mechId, true); } } }
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); } }
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 Add(string param) { SimGameState simGameState = SceneSingletonBehavior <UnityGameInstance> .Instance.Game.Simulation; DataProvider dataProvider = new DataProvider(); if (param == "help") { string help = ""; help += "• This command will add components to your inventory"; help += Environment.NewLine; help += "• Params: 'All', 'all' or the id of some component '+' the desired amount"; help += Environment.NewLine; help += "• Example: '/comp Weapon_Gauss_Gauss_0-STOCK+5'"; help += Environment.NewLine; help += "• Example: '/comp Gear_HeatSink_Generic_Double+20'"; help += Environment.NewLine; help += "• Example: '/comp All+10'"; PopupHelper.Info(help); return; } string message = ""; string[] array = param.Split(new char[] { '+' }); if (array.Length != 2) { message = $"Param should be id+number. Type '/comp help' to get some examples."; Logger.Debug($"[Cheater_Reputation_Add] {message}"); PopupHelper.Info(message); return; } string componentDefId = array[0]; int.TryParse(array[1], out int count); if (count <= 0) { message = $"Amount is not a positive number."; Logger.Debug($"[Cheater_Component_Add] {message}"); PopupHelper.Info(message); return; } if (componentDefId == "All" || componentDefId == "all") { // Add Weapons foreach (string id in dataProvider.WeaponDefIds) { int i = 0; while (i < count) { simGameState.AddItemStat(id, typeof(WeaponDef), false); i++; } Logger.Debug($"[Cheater_Component_Add] Added {id}({count}) to inventory."); } // Add upgrades foreach (string id in dataProvider.UpgradeDefIds) { int i = 0; while (i < count) { simGameState.AddItemStat(id, typeof(UpgradeDef), false); i++; } Logger.Debug($"[Cheater_Component_Add] Added {id}({count}) to inventory."); } // Add Heatsinks foreach (string id in dataProvider.HeatSinkDefIds) { int i = 0; while (i < count) { simGameState.AddItemStat(id, typeof(HeatSinkDef), false); i++; } Logger.Debug($"[Cheater_Component_Add] Added {id}({count}) to inventory."); } // Add AmmoBoxes foreach (string id in dataProvider.AmmoBoxDefIds) { int i = 0; while (i < count) { simGameState.AddItemStat(id, typeof(AmmunitionBoxDef), false); i++; } Logger.Debug($"[Cheater_Component_Add] Added {id}({count}) to inventory."); } // Add JumpJets foreach (string id in dataProvider.JumpJetDefIds) { int i = 0; while (i < count) { simGameState.AddItemStat(id, typeof(JumpJetDef), false); i++; } Logger.Debug($"[Cheater_Component_Add] Added {id}({count}) to inventory."); } message = $"Added {count} pieces of all known components to inventory."; Logger.Debug($"[Cheater_Component_Add] {message}"); PopupHelper.Info(message); } else { // Try to find a valid component Type componentType; // Weapon if (dataProvider.WeaponDefIds.Contains(componentDefId)) { componentType = typeof(WeaponDef); } // Upgrade else if (dataProvider.UpgradeDefIds.Contains(componentDefId)) { componentType = typeof(UpgradeDef); } // Heatsink else if (dataProvider.HeatSinkDefIds.Contains(componentDefId)) { componentType = typeof(HeatSinkDef); } // AmmoBox else if (dataProvider.AmmoBoxDefIds.Contains(componentDefId)) { componentType = typeof(AmmunitionBoxDef); } // JumpJet else if (dataProvider.JumpJetDefIds.Contains(componentDefId)) { componentType = typeof(JumpJetDef); } else { message = $"{componentDefId} is unknown or blacklisted."; Logger.Debug($"[Cheater_Component_Add] {message}"); PopupHelper.Info(message); return; } // Add int i = 0; while (i < count) { simGameState.AddItemStat(componentDefId, componentType, false); i++; } message = $"Added {count} pieces of {componentDefId} to inventory."; Logger.Debug($"[Cheater_Component_Add] {message}"); PopupHelper.Info(message); } }
public static bool AddMechPart(SimGameState __instance, string id) { __instance.AddItemStat(id, "MECHPART", false); return(false); }