コード例 #1
0
        public static MechDef MechDefs(ChassisDef chassisDef, string bedfile)
        {
            var mechdef = new MechDef
            {
                ChassisId   = chassisDef.Description.Id,
                HeraldryId  = null,
                Description = new DefDescription
                {
                    Cost        = chassisDef.Description.Cost,
                    Rarity      = chassisDef.Description.Rarity,
                    Purchasable = chassisDef.Description.Purchasable,
                    UiName      = chassisDef.Description.UiName + " " + chassisDef.VariantName,
                    Id          = chassisDef.Description.Id.Replace("chassisdef", "mechdef"),
                    Name        = chassisDef.Description.Name,
                    Details     = chassisDef.Description.Details,
                    Icon        = chassisDef.Description.Icon
                },
                SimGameMechPartCost = chassisDef.Description.Cost,
                Version             = 1,
                Locations           = new List <MechDefLocation>(),
                Inventory           = new List <Inventory>(),
            };

            string[] filelines         = File.ReadAllLines(bedfile);
            string   armorline         = "";
            string   armortypeline     = "";
            string   sturcturetypeline = "";
            int      internalStructre  = -1;

            foreach (string lines in filelines)
            {
                string newl = Reuse.RemoveSpecialCharacters(lines);
                newl = newl.Replace("\"", "");
                if (newl.Contains("ArmorVals"))
                {
                    armorline = newl;

                    break;
                }
                if (newl.Contains("Armor"))
                {
                    armortypeline = newl;
                }
                if (newl.Contains("Internal"))
                {
                    sturcturetypeline = newl;
                }
            }
            if (!armorline.Contains("ArmorVals"))
            {
                Reuse.EndProgram("FATAL ERROR: Unable to parse ArmorVals from Bedfile");
            }
            string[] armorvaulewords = armorline.Split(',');
            foreach (Location location in Enum.GetValues(typeof(Location)))
            {
                //ArmorVaule to Location  If Array
                int frontarmorvaule = -1;
                int reararmorvaule  = -1;
                if ((int)location == 0)
                {
                    frontarmorvaule = 45;
                }
                else
                {
                    frontarmorvaule = Convert.ToInt32(armorvaulewords[(int)location]) * 5;
                }
                if (((int)location == 3) || ((int)location == 4))
                {
                    reararmorvaule = Convert.ToInt32(armorvaulewords[6]) * 5;
                }
                if ((int)location == 5)
                {
                    reararmorvaule = Convert.ToInt32(armorvaulewords[8]) * 5;
                }
                if (((int)location == 6) || ((int)location == 7))
                {
                    frontarmorvaule = Convert.ToInt32(armorvaulewords[10]) * 5;
                }
                foreach (Location chassislocation in Enum.GetValues(typeof(Location)))
                {
                    if (chassisDef.Locations[(int)chassislocation].Location == location)
                    {
                        internalStructre = chassisDef.Locations[(int)chassislocation].InternalStructure;
                    }
                }
                mechdef.Locations.Add(new MechDefLocation
                {
                    DamageLevel              = DamageLevel.Functional,
                    Location                 = location,
                    CurrentArmor             = frontarmorvaule,
                    CurrentRearArmor         = reararmorvaule,
                    CurrentInternalStructure = internalStructre,
                    AssignedArmor            = frontarmorvaule,
                    AssignedRearArmor        = reararmorvaule,
                });
            }
            string armortype = "";

            if (armortypeline.Contains("Standard"))
            {
                armortype = "emod_armorslots_standard";
            }
            if (armortypeline.Contains("Ferro"))
            {
                armortype = "emod_armorslots_ferrosfibrous";
            }
            mechdef.Inventory.Add(new Inventory
            {
                MountedLocation  = Location.CenterTorso,
                ComponentDefId   = armortype,
                ComponentDefType = ComponentDefType.Upgrade,
                HardpointSlot    = -1,
                DamageLevel      = "Functional",
                PrefabName       = null,
                HasPrefabName    = false,
                SimGameUid       = "",
                Guid             = null
            });
            string sturcturetype = "";

            if (sturcturetypeline.Contains("Standard"))
            {
                sturcturetype = "emod_structureslots_standard";
            }
            if (sturcturetypeline.Contains("Endo"))
            {
                sturcturetype = "emod_structureslots_endosteel";
            }
            mechdef.Inventory.Add(new Inventory
            {
                MountedLocation  = Location.CenterTorso,
                ComponentDefId   = sturcturetype,
                ComponentDefType = ComponentDefType.Upgrade,
                HardpointSlot    = -1,
                DamageLevel      = "Functional",
                PrefabName       = null,
                HasPrefabName    = false,
                SimGameUid       = "",
                Guid             = null
            });
            return(mechdef);
        }
コード例 #2
0
 public static string ToJson(this MechDef self) => JsonConvert.SerializeObject(self, Converter.Settings);