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);
                }
            }
        }
        /// <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);
                }
            }
        }
        /// <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);
                }
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
        }
        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
                    }
                }
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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 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 });
                        }
                    }
                }
            }
        }
示例#11
0
        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 PerformMechAssemblyStorePopup(SimGameState s, MechDef d, Action onClose)
        {
            WwiseManager.PostEvent(AudioEventList_ui.ui_sim_popup_newChassis, WwiseManager.GlobalAudioObject, null, null);
            MechDef toAdd = PerformMechAssembly(s, d);
            int     mechbay;

            if (toAdd.IsVehicle())
            {
                mechbay = CUIntegration.GetFirstFreeMechBay(s, d); // vehicle bay, +100 or something similar
            }
            else
            {
                mechbay = s.GetFirstFreeMechBay();
            }
            GenericPopupBuilder pop = GenericPopupBuilder.Create($"{d.GetMechOmniVehicle()} Assembled", $"Yang: [[DM.MechDefs[{d.Description.Id}],{d.Chassis.Description.UIName} {d.Chassis.VariantName}]] finished!\n{d.Chassis.YangsThoughts}\n\n");

            pop.AddButton("storage", delegate
            {
                StoreMech(s, toAdd);
                CallMessages(s, toAdd);
                Log.Log("direct storage");
                onClose?.Invoke();
            }, true, null);
            if (mechbay < 0) // no space - direct storage
            {
                pop.Body += $"We have no space for a new {d.GetMechOmniVehicle()}, so it goes into storage.";
            }
            else
            {
                pop.Body += "Should I put it into storage or ready it for combat?";
                pop.AddButton("ready it", delegate
                {
                    if (Settings.AssembledMechsNeedReadying)
                    {
                        ReadyMech(s, toAdd, mechbay);
                        CallMessages(s, toAdd);
                    }
                    else
                    {
                        s.AddMech(mechbay, toAdd, true, false, false);
                        CallMessages(s, toAdd);
                    }
                    Log.Log("added to bay " + mechbay);
                    onClose?.Invoke();
                }, true, null);
            }
            if (s.IsSellingAllowed())
            {
                int cost = toAdd.GetMechSellCost(s);
                pop.Body += $"\n\nDarius: We could also sell it for {SimGameState.GetCBillString(cost)}, although Yang would certanly not like it.";
                pop.AddButton("sell it", delegate
                {
                    s.AddFunds(cost, "Store", true, true);
                    Log.Log("sold for " + cost);
                    s.CompanyStats.ModifyStat("Mission", 0, "COMPANY_MechsAdded", StatCollection.StatOperation.Int_Add, 1, -1, true);
                    CallMessages(s, toAdd);
                    onClose?.Invoke();
                }, true, null);
            }
            pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
            pop.Render();
        }
示例#13
0
        public static void PerformMechAssemblyStorePopup(SimGameState s, MechDef d, MechBayPanel refresh, SimpleMechAssembly_InterruptManager_AssembleMechEntry close)
        {
            MechDef toAdd   = PerformMechAssembly(s, d);
            int     mechbay = s.GetFirstFreeMechBay();

            if (mechbay < 0) // no space - direct storage
            {
                StoreMech(s, toAdd);
                Log.Log("no space, direct storage");
                if (refresh != null)
                {
                    refresh.RefreshData(false);
                }
                GenericPopupBuilder pop = GenericPopupBuilder.Create("Mech Assembled",
                                                                     string.Format("Yang: [[DM.MechDefs[{3}],{1} {2}]] finished!\n{0}\n\nWe have no space for a new mech, so it goes into storage.",
                                                                                   d.Chassis.YangsThoughts, d.Chassis.Description.UIName, d.Chassis.VariantName, d.Description.Id));
                pop.AddButton("ok", delegate
                {
                    if (close != null)
                    {
                        close.NewClose();
                    }
                }, true, null);
                pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
                pop.Render();
            }
            else
            {
                GenericPopupBuilder pop = GenericPopupBuilder.Create("Mech Assembled",
                                                                     string.Format("Yang: [[DM.MechDefs[{3}],{1} {2}]] finished!\n{0}\n\nShould I put it into storage, or ready it for combat?",
                                                                                   d.Chassis.YangsThoughts, d.Chassis.Description.UIName, d.Chassis.VariantName, d.Description.Id));
                pop.AddButton("storage", delegate
                {
                    StoreMech(s, toAdd);
                    Log.Log("direct storage");
                    if (refresh != null)
                    {
                        refresh.RefreshData(false);
                    }
                    if (close != null)
                    {
                        close.NewClose();
                    }
                }, true, null);
                pop.AddButton("ready it", delegate
                {
                    if (Settings.AssembledMechsNeedReadying)
                    {
                        ReadyMech(s, toAdd, mechbay);
                    }
                    else
                    {
                        s.AddMech(mechbay, toAdd, true, false, false);
                    }
                    Log.Log("added to bay " + mechbay);
                    if (refresh != null)
                    {
                        refresh.RefreshData(false);
                    }
                    if (close != null)
                    {
                        close.NewClose();
                    }
                }, true, null);
                pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
                pop.Render();
            }
        }