public void Load(int rdungeonNum, int floorNum)
        {
            using (XmlReader reader = XmlReader.Create(Paths.DataPath + "RDungeon\\" + rdungeonNum.ToString() + "\\" + floorNum + ".xml")) {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "Algorithm": {
                            Algorithm = reader.ReadString().ToInt();
                            LoadAlgorithmSettings();
                            break;
                        }

                        case "FloorSettings": {
                            XmlReader settingsReader = reader.ReadSubtree();
                            while (settingsReader.Read())
                            {
                                if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name))
                                {
                                    FloorSettings[settingsReader.Name] = settingsReader.ReadString().ToInt();
                                }
                            }
                            break;
                        }

                        case "TileLayers": {
                            XmlReader settingsReader = reader.ReadSubtree();
                            while (settingsReader.Read())
                            {
                                if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name))
                                {
                                    string settingName = settingsReader.Name;
                                    if (settingsReader.Read())
                                    {
                                        List <Maps.TileAnim> layerList = new List <Maps.TileAnim>();
                                        while (settingsReader.Read())
                                        {
                                            int tileNumX  = settingsReader.ReadElementString("TextureX").ToInt();
                                            int tileNumY  = settingsReader.ReadElementString("TextureY").ToInt();
                                            int tileSheet = settingsReader.ReadElementString("Sheet").ToInt();
                                            layerList.Add(new Maps.TileAnim(new Maps.Loc2D(tileNumX, tileNumY), tileSheet));
                                        }
                                        TileLayers[settingName] = layerList;
                                    }
                                }
                            }
                            break;
                        }

                        case "TileData": {
                            XmlReader settingsReader = reader.ReadSubtree();
                            while (settingsReader.Read())
                            {
                                if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name))
                                {
                                    string settingName = settingsReader.Name;
                                    if (settingsReader.Read())
                                    {
                                        List <Maps.TileData> tileDataList = new List <Maps.TileData>();
                                        while (settingsReader.Read())
                                        {
                                            Enums.TileType type       = settingsReader.ReadString().ToEnum <Enums.TileType>();
                                            int            data1      = settingsReader.ReadElementString("Data1").ToInt();
                                            int            data2      = settingsReader.ReadElementString("Data2").ToInt();
                                            int            data3      = settingsReader.ReadElementString("Data3").ToInt();
                                            string         tileString = settingsReader.ReadElementString("String");
                                            tileDataList.Add(new Maps.TileData(type, data1, data2, data3, tileString, "", ""));
                                        }
                                        TileData[settingName] = tileDataList;
                                    }
                                }
                            }
                            break;
                        }

                        case "Weather": {
                            FloorWeather.Add(reader.ReadString().ToEnum <Enums.Weather>(), reader.ReadString().ToInt());
                            break;
                        }

                        case "Darkness": {
                            Darkness = reader.ReadString().ToInt();
                            break;
                        }

                        case "Music": {
                            Music = reader.ReadString();
                            break;
                        }

                        case "NpcSpawnTime": {
                            NpcSpawnTime = reader.ReadString().ToInt();
                            break;
                        }

                        case "NpcMin": {
                            NpcMin = reader.ReadString().ToInt();
                            break;
                        }

                        case "NpcMax": {
                            NpcMax = reader.ReadString().ToInt();
                            break;
                        }

                        case "Items": {
                            XmlReader settingsReader = reader.ReadSubtree();
                            while (settingsReader.Read())
                            {
                                if (settingsReader.IsStartElement())
                                {
                                    string settingName = settingsReader.Name;
                                    settingsReader.Read();
                                    if (settingsReader.Read())
                                    {
                                        List <Tuple <ItemPreset, int> > itemList = new List <Tuple <ItemPreset, int> >();
                                        while (settingsReader.Read())
                                        {
                                            if (settingsReader.IsStartElement() && settingsReader.Name == "Element")
                                            {
                                                settingsReader.Read();
                                                ItemPreset preset = new ItemPreset();
                                                preset.ItemNum   = settingsReader.ReadElementString("ItemNum").ToInt();
                                                preset.MinAmount = settingsReader.ReadElementString("MinAmount").ToInt();
                                                preset.MaxAmount = settingsReader.ReadElementString("MaxAmount").ToInt();
                                                int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt();
                                                preset.StickyRate = settingsReader.ReadElementString("StickyRate").ToInt();
                                                preset.Tag        = settingsReader.ReadElementString("Tag");
                                                preset.Hidden     = settingsReader.ReadElementString("Hidden").ToBool();
                                                preset.OnGround   = settingsReader.ReadElementString("Ground").ToBool();
                                                preset.OnWater    = settingsReader.ReadElementString("Water").ToBool();
                                                preset.OnWall     = settingsReader.ReadElementString("Wall").ToBool();
                                                itemList.Add(new Tuple <ItemPreset, int>(preset, appearanceRate));
                                            }
                                        }
                                        Items[settingName] = itemList;
                                    }
                                }
                            }
                            break;
                        }

                        case "Npcs": {
                            XmlReader settingsReader = reader.ReadSubtree();
                            while (settingsReader.Read())
                            {
                                if (settingsReader.IsStartElement())
                                {
                                    string settingName = settingsReader.Name;
                                    settingsReader.Read();
                                    if (settingsReader.Read())
                                    {
                                        List <Tuple <NpcPreset, int> > npcList = new List <Tuple <NpcPreset, int> >();
                                        while (settingsReader.Read())
                                        {
                                            if (settingsReader.IsStartElement() && settingsReader.Name == "Element")
                                            {
                                                settingsReader.Read();
                                                NpcPreset preset = new NpcPreset();
                                                preset.NpcNum   = settingsReader.ReadElementString("NpcNum").ToInt();
                                                preset.SpawnX   = settingsReader.ReadElementString("SpawnX").ToInt();
                                                preset.SpawnY   = settingsReader.ReadElementString("SpawnY").ToInt();
                                                preset.MinLevel = settingsReader.ReadElementString("MinLevel").ToInt();
                                                preset.MaxLevel = settingsReader.ReadElementString("MaxLevel").ToInt();
                                                int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt();
                                                npcList.Add(new Tuple <NpcPreset, int>(preset, appearanceRate));
                                            }
                                        }
                                        Npcs[settingName] = npcList;
                                    }
                                }
                            }
                            break;
                        }

                        case "Rooms": {
                            XmlReader settingsReader = reader.ReadSubtree();
                            while (settingsReader.Read())
                            {
                                if (settingsReader.IsStartElement())
                                {
                                    string settingName = settingsReader.Name;
                                    settingsReader.Read();
                                    if (settingsReader.Read())
                                    {
                                        List <Tuple <int, int> > roomList = new List <Tuple <int, int> >();
                                        while (settingsReader.Read())
                                        {
                                            if (settingsReader.IsStartElement() && settingsReader.Name == "Element")
                                            {
                                                settingsReader.Read();
                                                int num            = settingsReader.ReadElementString("RoomNum").ToInt();
                                                int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt();
                                                roomList.Add(new Tuple <int, int>(num, appearanceRate));
                                            }
                                        }
                                        Rooms[settingName] = roomList;
                                    }
                                }
                            }
                            break;
                        }
                        }
                    }
                }
            }
        }
Example #2
0
 public void Load(int rdungeonNum, int floorNum)
 {
     using (XmlReader reader = XmlReader.Create(Paths.DataPath + "RDungeon\\" + rdungeonNum.ToString() + "\\" + floorNum + ".xml")) {
         while (reader.Read()) {
             if (reader.IsStartElement()) {
                 switch (reader.Name) {
                     case "Algorithm": {
                             Algorithm = reader.ReadString().ToInt();
                             LoadAlgorithmSettings();
                             break;
                         }
                     case "FloorSettings": {
                             XmlReader settingsReader = reader.ReadSubtree();
                             while (settingsReader.Read()) {
                                 if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name)) {
                                     FloorSettings[settingsReader.Name] = settingsReader.ReadString().ToInt();
                                 }
                             }
                             break;
                         }
                     case "TileLayers": {
                             XmlReader settingsReader = reader.ReadSubtree();
                             while (settingsReader.Read()) {
                                 if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name)) {
                                     string settingName = settingsReader.Name;
                                     if (settingsReader.Read()) {
                                         List<Maps.TileAnim> layerList = new List<Maps.TileAnim>();
                                         while (settingsReader.Read())
                                         {
                                             int tileNumX = settingsReader.ReadElementString("TextureX").ToInt();
                                             int tileNumY = settingsReader.ReadElementString("TextureY").ToInt();
                                             int tileSheet = settingsReader.ReadElementString("Sheet").ToInt();
                                             layerList.Add(new Maps.TileAnim(new Maps.Loc2D(tileNumX, tileNumY), tileSheet));
                                         }
                                         TileLayers[settingName] = layerList;
                                     }
                                 }
                             }
                             break;
                         }
                     case "TileData": {
                             XmlReader settingsReader = reader.ReadSubtree();
                             while (settingsReader.Read()) {
                                 if (settingsReader.IsStartElement() && FloorSettings.ContainsKey(settingsReader.Name)) {
                                     string settingName = settingsReader.Name;
                                     if (settingsReader.Read()) {
                                         List<Maps.TileData> tileDataList = new List<Maps.TileData>();
                                         while (settingsReader.Read()) {
                                             Enums.TileType type = settingsReader.ReadString().ToEnum<Enums.TileType>();
                                             int data1 = settingsReader.ReadElementString("Data1").ToInt();
                                             int data2 = settingsReader.ReadElementString("Data2").ToInt();
                                             int data3 = settingsReader.ReadElementString("Data3").ToInt();
                                             string tileString = settingsReader.ReadElementString("String");
                                             tileDataList.Add(new Maps.TileData(type, data1, data2, data3, tileString, "", ""));
                                         }
                                         TileData[settingName] = tileDataList;
                                     }
                                 }
                             }
                             break;
                         }
                     case "Weather": {
                         FloorWeather.Add(reader.ReadString().ToEnum<Enums.Weather>(), reader.ReadString().ToInt());
                             break;
                         }
                     case "Darkness": {
                             Darkness = reader.ReadString().ToInt();
                             break;
                         }
                     case "Music": {
                             Music = reader.ReadString();
                             break;
                         }
                     case "NpcSpawnTime": {
                             NpcSpawnTime = reader.ReadString().ToInt();
                             break;
                         }
                     case "NpcMin": {
                             NpcMin = reader.ReadString().ToInt();
                             break;
                         }
                     case "NpcMax": {
                             NpcMax = reader.ReadString().ToInt();
                             break;
                         }
                     case "Items": {
                             XmlReader settingsReader = reader.ReadSubtree();
                             while (settingsReader.Read()) {
                                 if (settingsReader.IsStartElement()) {
                                     string settingName = settingsReader.Name;
                                     settingsReader.Read();
                                     if (settingsReader.Read()) {
                                         List<Tuple<ItemPreset, int>> itemList = new List<Tuple<ItemPreset, int>>();
                                         while (settingsReader.Read()) {
                                             if (settingsReader.IsStartElement() && settingsReader.Name == "Element") {
                                                 settingsReader.Read();
                                                 ItemPreset preset = new ItemPreset();
                                                 preset.ItemNum = settingsReader.ReadElementString("ItemNum").ToInt();
                                                 preset.MinAmount = settingsReader.ReadElementString("MinAmount").ToInt();
                                                 preset.MaxAmount = settingsReader.ReadElementString("MaxAmount").ToInt();
                                                 int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt();
                                                 preset.StickyRate = settingsReader.ReadElementString("StickyRate").ToInt();
                                                 preset.Tag = settingsReader.ReadElementString("Tag");
                                                 preset.Hidden = settingsReader.ReadElementString("Hidden").ToBool();
                                                 preset.OnGround = settingsReader.ReadElementString("Ground").ToBool();
                                                 preset.OnWater = settingsReader.ReadElementString("Water").ToBool();
                                                 preset.OnWall = settingsReader.ReadElementString("Wall").ToBool();
                                                 itemList.Add(new Tuple<ItemPreset, int>(preset, appearanceRate));
                                             }
                                         }
                                         Items[settingName] = itemList;
                                     }
                                 }
                             }
                             break;
                         }
                     case "Npcs": {
                             XmlReader settingsReader = reader.ReadSubtree();
                             while (settingsReader.Read()) {
                                 if (settingsReader.IsStartElement()) {
                                     string settingName = settingsReader.Name;
                                     settingsReader.Read();
                                     if (settingsReader.Read()) {
                                         List<Tuple<NpcPreset, int>> npcList = new List<Tuple<NpcPreset, int>>();
                                         while (settingsReader.Read()) {
                                             if (settingsReader.IsStartElement() && settingsReader.Name == "Element") {
                                                 settingsReader.Read();
                                                 NpcPreset preset = new NpcPreset();
                                                 preset.NpcNum = settingsReader.ReadElementString("NpcNum").ToInt();
                                                 preset.SpawnX = settingsReader.ReadElementString("SpawnX").ToInt();
                                                 preset.SpawnY = settingsReader.ReadElementString("SpawnY").ToInt();
                                                 preset.MinLevel = settingsReader.ReadElementString("MinLevel").ToInt();
                                                 preset.MaxLevel = settingsReader.ReadElementString("MaxLevel").ToInt();
                                                 int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt();
                                                 npcList.Add(new Tuple<NpcPreset, int>(preset, appearanceRate));
                                             }
                                         }
                                         Npcs[settingName] = npcList;
                                     }
                                 }
                             }
                             break;
                         }
                     case "Rooms": {
                             XmlReader settingsReader = reader.ReadSubtree();
                             while (settingsReader.Read()) {
                                 if (settingsReader.IsStartElement()) {
                                     string settingName = settingsReader.Name;
                                     settingsReader.Read();
                                     if (settingsReader.Read()) {
                                         List<Tuple<int, int>> roomList = new List<Tuple<int, int>>();
                                         while (settingsReader.Read()) {
                                             if (settingsReader.IsStartElement() && settingsReader.Name == "Element") {
                                                 settingsReader.Read();
                                                 int num = settingsReader.ReadElementString("RoomNum").ToInt();
                                                 int appearanceRate = settingsReader.ReadElementString("AppearanceRate").ToInt();
                                                 roomList.Add(new Tuple<int, int>(num, appearanceRate));
                                             }
                                         }
                                         Rooms[settingName] = roomList;
                                     }
                                 }
                             }
                             break;
                         }
                 }
             }
         }
     }
 }