public static void setOriginal(this MechDef def, string json)
 {
     if (originals.TryGetValue(def.GetType(), out Dictionary <string, string> origs) == false)
     {
         origs = new Dictionary <string, string>();
         originals.Add(def.GetType(), origs);
     }
     if (origs.ContainsKey(def.Description.Id))
     {
         origs[def.Description.Id] = json;
     }
     else
     {
         origs.Add(def.Description.Id, json);
     }
 }
示例#2
0
        public static bool IsVariantKnown(SimGameState s, MechDef d)
        {
            foreach (KeyValuePair <int, MechDef> a in s.ActiveMechs)
            {
                if (d.ChassisID == a.Value.ChassisID)
                {
                    return(true);
                }
            }
            foreach (KeyValuePair <int, MechDef> a in s.ReadyingMechs)
            {
                if (d.ChassisID == a.Value.ChassisID)
                {
                    return(true);
                }
            }
            Traverse c = Traverse.Create(s);

            object[] args = new object[] { d.Chassis.Description.Id, "MECHPART" };
            string   id   = c.Method("GetItemStatID", args).GetValue <string>(args);

            if (s.CompanyStats.ContainsStatistic(id))
            {
                return(true);
            }
            args[1] = d.GetType();
            id      = c.Method("GetItemStatID", args).GetValue <string>(args);
            if (s.CompanyStats.ContainsStatistic(id))
            {
                return(true);
            }
            return(false);
        }
 public static string getOriginal(this MechDef def)
 {
     if (originals.TryGetValue(def.GetType(), out Dictionary <string, string> origs) == false)
     {
         return(def.ToJSON());
     }
     if (origs.TryGetValue(def.Description.Id, out string result) == false)
     {
         return(def.ToJSON());
     }
     return(result);
 }
        private static void RandomizeMechs(SimGameState simGame)
        {
            Main.HBSLog.Log("Randomizing mechs, removing old mechs");

            // clear the initial lance
            for (var i = 1; i < simGame.Constants.Story.StartingLance.Length + 1; i++)
            {
                simGame.ActiveMechs.Remove(i);
            }

            // remove ancestral mech if specified
            if (Main.Settings.RemoveAncestralMech)
            {
                Main.HBSLog.Log("\tRemoving ancestral mech");
                simGame.ActiveMechs.Remove(0);
            }

            // add the random mechs to mechIds
            var mechIds = new List <string>();

            mechIds.AddRange(GetRandomSubList(Main.Settings.AssaultMechsPossible, Main.Settings.NumberAssaultMechs));
            mechIds.AddRange(GetRandomSubList(Main.Settings.HeavyMechsPossible, Main.Settings.NumberHeavyMechs));
            mechIds.AddRange(GetRandomSubList(Main.Settings.MediumMechsPossible, Main.Settings.NumberMediumMechs));
            mechIds.AddRange(GetRandomSubList(Main.Settings.LightMechsPossible, Main.Settings.NumberLightMechs));

            // remove mechIDs that don't have a valid mechDef
            var numInvalid = mechIds.RemoveAll(id => !simGame.DataManager.MechDefs.Exists(id));

            if (numInvalid > 0)
            {
                Main.HBSLog.LogWarning($"\tREMOVED {numInvalid} INVALID MECHS! Check mod.json for misspellings");
            }

            // actually add the mechs to the game
            foreach (var mechID in mechIds)
            {
                var baySlot = simGame.GetFirstFreeMechBay();
                var mechDef = new MechDef(simGame.DataManager.MechDefs.Get(mechID), simGame.GenerateSimGameUID());

                if (baySlot >= 0)
                {
                    Main.HBSLog.Log($"\tAdding {mechID} to bay {baySlot}");
                    simGame.AddMech(baySlot, mechDef, true, true, false);
                }
                else
                {
                    Main.HBSLog.Log($"\tAdding {mechID} to storage, bays are full");
                    simGame.AddItemStat(mechDef.Chassis.Description.Id, mechDef.GetType(), false);
                }
            }
        }
        public static bool IsVariantKnown(SimGameState s, MechDef d)
        {
            if (!Settings.UseOnlyCCAssemblyOptions)
            {
                if (d.Chassis.ChassisTags.Contains("chassis_KnownOmniVariant"))
                {
                    return(true);
                }
            }
            IAssemblyVariant v = CCIntegration.GetCCAssemblyVariant(d.Chassis);

            if (v != null)
            {
                if (v.KnownOmniVariant)
                {
                    return(true);
                }
            }
            foreach (KeyValuePair <int, MechDef> a in s.ActiveMechs)
            {
                if (d.ChassisID == a.Value.ChassisID)
                {
                    return(true);
                }
            }
            foreach (KeyValuePair <int, MechDef> a in s.ReadyingMechs)
            {
                if (d.ChassisID == a.Value.ChassisID)
                {
                    return(true);
                }
            }
            string id = s.GetItemStatID(d.Description.Id, "MECHPART");

            if (s.CompanyStats.ContainsStatistic(id))
            {
                return(true);
            }
            id = s.GetItemStatID(d.Chassis.Description, d.GetType());
            if (s.CompanyStats.ContainsStatistic(id))
            {
                return(true);
            }
            return(false);
        }
        public static bool UnreadyVehicle(int baySlot, MechDef def, SimGameState __instance)
        {
            if (!def.IsVehicle())
            {
                return(true);
            }
            if (def == null || (baySlot > 0 && !__instance.ActiveMechs.ContainsKey(baySlot)))
            {
                return(false);
            }


            if (__instance.ActiveMechs.ContainsKey(baySlot))
            {
                __instance.ActiveMechs.Remove(baySlot);
            }

            __instance.AddItemStat(def.Chassis.Description.Id, def.GetType(), false);
            return(false);
        }
        public static int GetNumberOfMechsOwnedOfType(SimGameState s, MechDef m)
        {
            int com = s.GetItemCount(m.Chassis.Description.Id, m.GetType(), SimGameState.ItemCountType.UNDAMAGED_ONLY);

            foreach (KeyValuePair <int, MechDef> a in s.ActiveMechs)
            {
                if (m.ChassisID == a.Value.ChassisID)
                {
                    com++;
                }
            }
            foreach (KeyValuePair <int, MechDef> a in s.ReadyingMechs)
            {
                if (m.ChassisID == a.Value.ChassisID)
                {
                    com++;
                }
            }
            return(com);
        }
        /// <summary>
        /// Adds a lance to the player's roster (possibly to storage if space is insufficient)
        /// </summary>
        /// <param name="simGame"></param>
        /// <param name="lance"></param>
        private static void ApplyLance(SimGameState simGame, List <MechDef> lance)
        {
            // actually add the mechs to the game, in descending order of tonnage
            foreach (var mechDef in lance.OrderBy(mech => - mech.Chassis.Tonnage))
            {
                // pick a slot, and generate the mechdef a UID
                var baySlot      = simGame.GetFirstFreeMechBay();
                var concreteMech = new MechDef(mechDef, simGame.GenerateSimGameUID());

                if (baySlot >= 0)
                {
                    Logger.Log($"\tAdding {concreteMech.ChassisID} to bay {baySlot}");
                    simGame.AddMech(baySlot, concreteMech, true, true, false);
                }
                else
                {
                    Logger.Log($"\tAdding {concreteMech.ChassisID} to storage, bays are full");
                    simGame.AddItemStat(concreteMech.Chassis.Description.Id, concreteMech.GetType(), false);
                }
            }
        }
        private static void 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);
                }
            }
        }