예제 #1
0
    public static void LoadCreatures()
    {
        loadedCreatures = new List<Creature>();
        uniqueAttributes = new List<string>();

        using (XmlReader reader = XmlReader.Create("Assets/CreatureList.xml"))
        {
            Component component = new Component(Component.Type.Bell);

            Creature currentCreature = new Creature();
            reader.ReadToFollowing("Creature");
            while (!reader.EOF)
            {
                reader.Read();
                if (reader.NodeType != XmlNodeType.EndElement)
                    switch (reader.Name)
                    {
                        case "Creature":
                            currentCreature = new Creature();
                            break;
                        case "Title":
                            currentCreature.Title = reader.ReadInnerXml();
                            break;
                        case "Type":
                            currentCreature.Type = reader.ReadInnerXml();
                            break;
                        case "Attribute":
                            string attr = reader.ReadInnerXml();
                            currentCreature.Attributes.Add(attr);
                            if (!uniqueAttributes.Contains(attr))
                                uniqueAttributes.Add(attr);
                            break;
                        case "Name":
                            currentCreature.Names.Add(reader.ReadInnerXml());
                            break;
                        case "Bells":
                            component = new Component(Component.Type.Bell);
                            break;
                        case "Bell":
                            component.addData(byte.Parse(reader.ReadInnerXml()));
                            break;
                        case "Effigy":
                            component = new Component(Component.Type.Effigy);
                            break;
                        case "Cut":
                            component.addData(byte.Parse(reader.ReadInnerXml()));
                            break;
                        case "Incantation":
                            currentCreature.RequiredComponents.Add(new Component(reader.ReadInnerXml().ToUpper()));
                            break;
                        case "Potion":
                            component = new Component(Component.Type.Potion);
                            break;
                        case "Material":
                            component.addData(byte.Parse(reader.ReadInnerXml()));
                            break;
                        case "Rune":
                            component = new Component(Component.Type.Rune);
                            break;
                        case "Point":
                            component.addData(byte.Parse(reader.ReadInnerXml()));
                            break;
                    }
                else
                    switch (reader.Name)
                    {
                        case "Creature":
                            loadedCreatures.Add(currentCreature);
                            break;
                        case "Bells":
                        case "Effigy":
                        case "Potion":
                        case "Rune":
                            currentCreature.RequiredComponents.Add(component);
                            break;
                    }
            }
        }
    }