Ejemplo n.º 1
0
        protected override List <MapMetadata> Parse()
        {
            MapsList = new List <MapMetadata>();

            // Parse map names
            MapNames = new Dictionary <int, string>();
            PackFileEntry file     = Resources.XmlReader.Files.FirstOrDefault(x => x.Name.StartsWith("string/en/mapname.xml"));
            XmlDocument   document = Resources.XmlReader.GetXmlDocument(file);

            foreach (XmlNode node in document.DocumentElement.ChildNodes)
            {
                int    id   = int.Parse(node.Attributes["id"].Value);
                string name = node.Attributes["name"].Value;
                MapNames[id] = name;
            }

            // Parse every block for each map
            FlatTypeIndex index  = new FlatTypeIndex(Resources.ExportedReader);
            XBlockParser  parser = new XBlockParser(Resources.ExportedReader, index);

            parser.Include(typeof(IMS2CubeProp)); // We only care about cubes here

            parser.Parse(AddMetadata);

            return(MapsList);
        }
        protected override List <MapEntityMetadata> Parse()
        {
            Entities = new List <MapEntityMetadata>();

            // fetch interactID and recipeID relation from xml (can be expanded to parse other xml info)
            InteractRecipeMap = new Dictionary <int, int>();
            foreach (PackFileEntry entry in Resources.XmlReader.Files
                     .Where(entry => Regex.Match(entry.Name, "table/interactobject_mastery").Success))
            {
                XmlDocument document      = Resources.XmlReader.GetXmlDocument(entry);
                XmlNodeList interactNodes = document.SelectNodes("/ms2/interact");

                foreach (XmlNode node in interactNodes)
                {
                    int     interactID    = int.Parse(node.Attributes["id"].Value);
                    XmlNode gatheringNode = node.SelectSingleNode("gathering");
                    int     recipeID      = int.Parse(gatheringNode.Attributes["receipeID"].Value);
                    InteractRecipeMap[interactID] = recipeID;
                }
            }

            // Get mob spawn ID and mob spawn information from xml (can be expanded to parse other xml info)
            SpawnTagMap = new Dictionary <string, Dictionary <int, SpawnMetadata> >();
            foreach (PackFileEntry entry in Resources.XmlReader.Files
                     .Where(entry => Regex.Match(entry.Name, "table/mapspawntag").Success))
            {
                XmlDocument document    = Resources.XmlReader.GetXmlDocument(entry);
                XmlNodeList regionNodes = document.SelectNodes("/ms2/region");

                foreach (XmlNode node in regionNodes)
                {
                    string mapID        = node.Attributes["mapCode"].Value;
                    int    spawnPointID = int.Parse(node.Attributes["spawnPointID"].Value);

                    int      difficulty    = int.Parse(node.Attributes["difficulty"].Value);
                    int      minDifficulty = int.Parse(node.Attributes["difficultyMin"].Value);
                    string[] spawnTags     = node.Attributes["tag"].Value.Split(",").Select(p => p.Trim()).ToArray();
                    if (!int.TryParse(node.Attributes["coolTime"].Value, out int spawnTime))
                    {
                        spawnTime = 0;
                    }

                    if (!int.TryParse(node.Attributes["population"].Value, out int population))
                    {
                        population = 0;
                    }

                    bool isPetSpawn = node.Attributes["petPopulation"] != null &&
                                      int.Parse(node.Attributes["petPopulation"].Value) > 0;

                    SpawnMetadata spawnData = new SpawnMetadata(spawnTags, population, spawnTime, difficulty,
                                                                minDifficulty, isPetSpawn);
                    if (!SpawnTagMap.ContainsKey(mapID))
                    {
                        SpawnTagMap[mapID] = new Dictionary <int, SpawnMetadata>();
                    }

                    SpawnTagMap[mapID][spawnPointID] = spawnData;
                }
            }

            // Iterate over map xblocks
            Maps = new Dictionary <string, string>();
            XBlockParser parser = new XBlockParser(Resources.ExportedReader, new FlatTypeIndex(Resources.ExportedReader));

            parser.Parse(BuildMetadata);

            // Since parsing is done in parallel, sort at the end for deterministic order.
            Entities.Sort((metadata1, metadata2) => metadata1.MapId.CompareTo(metadata2.MapId));
            return(Entities);
        }
Ejemplo n.º 3
0
        protected override List <MapEntityMetadata> Parse()
        {
            // Get InteractObject Types
            InteractTypes = new Dictionary <int, InteractObjectType>();
            foreach (PackFileEntry entry in Resources.XmlReader.Files)
            {
                if (!entry.Name.StartsWith("table/interactobject"))
                {
                    continue;
                }

                XmlDocument document      = Resources.XmlReader.GetXmlDocument(entry);
                XmlNodeList interactNodes = document.GetElementsByTagName("interact");
                foreach (XmlNode node in interactNodes)
                {
                    string locale = node.Attributes["locale"]?.Value ?? "";
                    if (locale != "NA" && locale != "")
                    {
                        continue;
                    }

                    int interactId = int.Parse(node.Attributes["id"].Value);
                    _ = Enum.TryParse(node.Attributes["type"].Value, out InteractObjectType objectType);

                    InteractTypes[interactId] = objectType;
                }
            }

            Entities = new List <MapEntityMetadata>();

            // Get mob spawn ID and mob spawn information from xml (can be expanded to parse other xml info)
            SpawnTagMap = new Dictionary <string, Dictionary <int, SpawnMetadata> >();
            foreach (PackFileEntry entry in Resources.XmlReader.Files.Where(x => x.Name.StartsWith("table/mapspawntag")))
            {
                XmlDocument document    = Resources.XmlReader.GetXmlDocument(entry);
                XmlNodeList regionNodes = document.SelectNodes("/ms2/region");

                foreach (XmlNode node in regionNodes)
                {
                    string mapID        = node.Attributes["mapCode"].Value;
                    int    spawnPointID = int.Parse(node.Attributes["spawnPointID"].Value);

                    int      difficulty    = int.Parse(node.Attributes["difficulty"].Value);
                    int      minDifficulty = int.Parse(node.Attributes["difficultyMin"].Value);
                    string[] spawnTags     = node.Attributes["tag"].Value.Split(",").Select(p => p.Trim()).ToArray();
                    if (!int.TryParse(node.Attributes["coolTime"].Value, out int spawnTime))
                    {
                        spawnTime = 0;
                    }

                    if (!int.TryParse(node.Attributes["population"].Value, out int population))
                    {
                        population = 0;
                    }

                    _ = int.TryParse(node.Attributes["petPopulation"]?.Value, out int petPopulation);
                    bool isPetSpawn = petPopulation > 0;

                    SpawnMetadata spawnData = new SpawnMetadata(spawnTags, population, spawnTime, difficulty, minDifficulty, isPetSpawn);
                    if (!SpawnTagMap.ContainsKey(mapID))
                    {
                        SpawnTagMap[mapID] = new Dictionary <int, SpawnMetadata>();
                    }

                    SpawnTagMap[mapID][spawnPointID] = spawnData;
                }
            }

            // Iterate over map xblocks
            Maps = new Dictionary <string, string>();
            XBlockParser parser = new XBlockParser(Resources.ExportedReader, new FlatTypeIndex(Resources.ExportedReader));

            parser.Parse(BuildMetadata);

            // Since parsing is done in parallel, sort at the end for deterministic order.
            Entities.Sort((metadata1, metadata2) => metadata1.MapId.CompareTo(metadata2.MapId));
            return(Entities);
        }