예제 #1
0
        public static void Initialize()
        {
            XmlDocument doc = new XmlDocument();

            string[] xmlFilesArray = Directory.GetFiles(@"data\xml\npcs\");
            try
            {
                StatsSet set = new StatsSet();

                foreach (string i in xmlFilesArray)
                {
                    doc.Load(i);

                    XmlNodeList nodes = doc.DocumentElement?.SelectNodes("/list/npc");

                    if (nodes == null)
                    {
                        continue;
                    }

                    foreach (XmlNode node in nodes)
                    {
                        XmlElement ownerElement = node.Attributes?[0].OwnerElement;
                        if (ownerElement != null && node.Attributes != null && ownerElement.Name == "npc")
                        {
                            XmlNamedNodeMap attrs = node.Attributes;

                            int npcId      = int.Parse(attrs.GetNamedItem("id").Value);
                            int templateId = attrs.GetNamedItem("idTemplate") == null ? npcId : int.Parse(attrs.GetNamedItem("idTemplate").Value);

                            set.Set("id", npcId);
                            set.Set("idTemplate", templateId);
                            set.Set("name", attrs.GetNamedItem("name").Value);
                            set.Set("title", attrs.GetNamedItem("title").Value);

                            foreach (XmlNode innerData in node.ChildNodes)
                            {
                                if (innerData.Attributes["name"] != null && innerData.Attributes["val"] != null)
                                {
                                    string value = innerData.Attributes["val"].Value;
                                    string name  = innerData.Attributes["name"].Value;

                                    set.Set(name, value);
                                }
                            }

                            _npcs.Add(npcId, new NpcTemplate(set));
                        }
                        set.Clear();
                    }
                }

                Log.Info($"Loaded {_npcs.Count} npcs.");
            }
            catch (Exception e)
            {
                Log.Error(e, "Error parsing NPC templates: ");
            }
        }
예제 #2
0
        public void Test()
        {
            Dictionary <int, NpcTemplate> _npcs = new Dictionary <int, NpcTemplate>();
            XmlDocument doc = new XmlDocument();

            string[] xmlFilesArray = Directory.GetFiles(@"data\xml\npcs\");
            try
            {
                StatsSet set = new StatsSet();
                //StatsSet petSet = new StatsSet();

                foreach (string i in xmlFilesArray)
                {
                    doc.Load(i);

                    XmlNodeList nodes = doc.DocumentElement?.SelectNodes("/list/npc");

                    if (nodes == null)
                    {
                        continue;
                    }

                    foreach (XmlNode node in nodes)
                    {
                        XmlElement ownerElement = node.Attributes?[0].OwnerElement;
                        if ((ownerElement != null) && (node.Attributes != null) && "npc".Equals(ownerElement.Name))
                        {
                            XmlNamedNodeMap attrs = node.Attributes;

                            int npcId      = int.Parse(attrs.GetNamedItem("id").Value);
                            int templateId = attrs.GetNamedItem("idTemplate") == null ? npcId : int.Parse(attrs.GetNamedItem("idTemplate").Value);

                            set.Set("id", npcId);
                            set.Set("idTemplate", templateId);
                            set.Set("name", attrs.GetNamedItem("name").Value);
                            set.Set("title", attrs.GetNamedItem("title").Value);

                            _npcs.Add(npcId, new NpcTemplate(set));
                        }
                        set.Clear();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"MapRegionTest Error: {e.Message}");
                //_log.log(Level.SEVERE, "NpcTable: Error parsing NPC templates : ", e);
            }
        }