public static void ParseRooms(string filePath, ContentManager contentManager = null, bool isDLCMap = false) { CultureInfo cultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone(); cultureInfo.NumberFormat.CurrencyDecimalSeparator = "."; XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.IgnoreComments = true; xmlReaderSettings.IgnoreWhitespace = true; XmlReader xmlReader; if (contentManager == null) { xmlReader = XmlReader.Create(filePath, xmlReaderSettings); } else { xmlReader = XmlReader.Create(contentManager.RootDirectory + "\\Levels\\" + filePath + ".xml", xmlReaderSettings); } RoomObj roomObj = null; RoomObj roomObj2 = null; RoomObj roomObj3 = null; RoomObj roomObj4 = null; RoomObj roomObj5 = null; while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (xmlReader.Name == "RoomObject") { roomObj = new RoomObj(); LevelParser.ParseGenericXML(xmlReader, roomObj); if (isDLCMap) { roomObj.IsDLCMap = true; } roomObj2 = (roomObj.Clone() as RoomObj); roomObj3 = (roomObj.Clone() as RoomObj); roomObj4 = (roomObj.Clone() as RoomObj); roomObj5 = (roomObj.Clone() as RoomObj); } if (xmlReader.Name == "GameObject") { xmlReader.MoveToAttribute("Type"); string value = xmlReader.Value; GameObj gameObj = null; string key; switch (key = value) { case "CollHullObj": gameObj = new TerrainObj(0, 0); break; case "DoorObj": gameObj = new DoorObj(roomObj, 0, 0, GameTypes.DoorType.OPEN); break; case "ChestObj": if (xmlReader.MoveToAttribute("Fairy")) { if (bool.Parse(xmlReader.Value)) { gameObj = new FairyChestObj(null); (gameObj as ChestObj).ChestType = 4; } else { gameObj = new ChestObj(null); } } else { gameObj = new ChestObj(null); } break; case "HazardObj": gameObj = new HazardObj(0, 0); break; case "BorderObj": gameObj = new BorderObj(); break; case "EnemyObj": xmlReader.MoveToAttribute("Procedural"); if (!bool.Parse(xmlReader.Value)) { xmlReader.MoveToAttribute("EnemyType"); byte enemyType = byte.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); xmlReader.MoveToAttribute("Difficulty"); GameTypes.EnemyDifficulty difficulty = (GameTypes.EnemyDifficulty)Enum.Parse(typeof(GameTypes.EnemyDifficulty), xmlReader.Value, true); gameObj = EnemyBuilder.BuildEnemy((int)enemyType, null, null, null, difficulty, false); if (xmlReader.MoveToAttribute("Flip") && bool.Parse(xmlReader.Value)) { gameObj.Flip = SpriteEffects.FlipHorizontally; } if (xmlReader.MoveToAttribute("InitialDelay")) { (gameObj as EnemyObj).InitialLogicDelay = float.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); } } else { xmlReader.MoveToAttribute("EnemyType"); string value2 = xmlReader.Value; gameObj = new EnemyTagObj(); (gameObj as EnemyTagObj).EnemyType = value2; } break; case "EnemyOrbObj": { xmlReader.MoveToAttribute("OrbType"); int orbType = int.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); bool flag = false; if (xmlReader.MoveToAttribute("IsWaypoint")) { flag = bool.Parse(xmlReader.Value); } if (flag) { gameObj = new WaypointObj(); (gameObj as WaypointObj).OrbType = orbType; } else { gameObj = new EnemyOrbObj(); (gameObj as EnemyOrbObj).OrbType = orbType; if (xmlReader.MoveToAttribute("ForceFlying")) { (gameObj as EnemyOrbObj).ForceFlying = bool.Parse(xmlReader.Value); } } break; } case "SpriteObj": xmlReader.MoveToAttribute("SpriteName"); if (xmlReader.Value == "LightSource_Sprite") { gameObj = new LightSourceObj(); } else { gameObj = new SpriteObj(xmlReader.Value); } break; case "PhysicsObj": { xmlReader.MoveToAttribute("SpriteName"); gameObj = new PhysicsObj(xmlReader.Value, null); PhysicsObj physicsObj = gameObj as PhysicsObj; physicsObj.CollisionTypeTag = 5; physicsObj.CollidesBottom = false; physicsObj.CollidesLeft = false; physicsObj.CollidesRight = false; break; } case "PhysicsObjContainer": { bool flag2 = false; if (xmlReader.MoveToAttribute("Breakable")) { flag2 = bool.Parse(xmlReader.Value); } xmlReader.MoveToAttribute("SpriteName"); if (flag2) { gameObj = new BreakableObj(xmlReader.Value); } else { gameObj = new PhysicsObjContainer(xmlReader.Value, null); } break; } case "ObjContainer": xmlReader.MoveToAttribute("SpriteName"); gameObj = new ObjContainer(xmlReader.Value); break; case "PlayerStartObj": gameObj = new PlayerStartObj(); break; } LevelParser.ParseGenericXML(xmlReader, gameObj); GameTypes.LevelType levelType = GameTypes.LevelType.NONE; if (xmlReader.MoveToAttribute("LevelType")) { levelType = (GameTypes.LevelType)int.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); } if (levelType == GameTypes.LevelType.CASTLE) { LevelParser.StoreObj(gameObj, roomObj2); LevelParser.StoreSwappedObj(gameObj, GameTypes.LevelType.DUNGEON, roomObj3); LevelParser.StoreSwappedObj(gameObj, GameTypes.LevelType.TOWER, roomObj5); LevelParser.StoreSwappedObj(gameObj, GameTypes.LevelType.GARDEN, roomObj4); SpriteObj spriteObj = gameObj as SpriteObj; if (spriteObj != null && spriteObj.SpriteName == "CastleAssetFrame_Sprite") { spriteObj.ChangeSprite("FramePicture" + CDGMath.RandomInt(1, 16) + "_Sprite"); } } else if (levelType == GameTypes.LevelType.DUNGEON) { LevelParser.StoreObj(gameObj, roomObj3); } else if (levelType == GameTypes.LevelType.TOWER) { LevelParser.StoreObj(gameObj, roomObj5); } else if (levelType == GameTypes.LevelType.GARDEN) { LevelParser.StoreObj(gameObj, roomObj4); } else { LevelParser.StoreObj(gameObj, roomObj2); LevelParser.StoreObj(gameObj, roomObj3); LevelParser.StoreObj(gameObj, roomObj5); LevelParser.StoreObj(gameObj, roomObj4); LevelParser.StoreObj(gameObj, roomObj); } if (LevelEV.RUN_TESTROOM && (levelType == LevelEV.TESTROOM_LEVELTYPE || levelType == GameTypes.LevelType.CASTLE)) { if (levelType == LevelEV.TESTROOM_LEVELTYPE) { LevelParser.StoreObj(gameObj, roomObj); } else if (levelType == GameTypes.LevelType.CASTLE) { LevelParser.StoreSwappedObj(gameObj, LevelEV.TESTROOM_LEVELTYPE, roomObj); } } if (gameObj is PlayerStartObj) { RoomObj expr_65E = roomObj; expr_65E.Name += "DEBUG_ROOM"; } } } else if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "RoomObject") { if (roomObj.X < 10000f && roomObj.Name != "Boss" && roomObj.Name != "ChallengeBoss") { if (!roomObj.Name.Contains("DEBUG_ROOM")) { if (roomObj.AddToCastlePool) { LevelBuilder2.StoreRoom(roomObj2, GameTypes.LevelType.CASTLE); LevelBuilder2.StoreSpecialRoom(roomObj2, GameTypes.LevelType.CASTLE, false); } if (roomObj.AddToDungeonPool) { LevelBuilder2.StoreRoom(roomObj3, GameTypes.LevelType.DUNGEON); LevelBuilder2.StoreSpecialRoom(roomObj3, GameTypes.LevelType.DUNGEON, false); } if (roomObj.AddToGardenPool) { LevelBuilder2.StoreRoom(roomObj4, GameTypes.LevelType.GARDEN); LevelBuilder2.StoreSpecialRoom(roomObj4, GameTypes.LevelType.GARDEN, false); } if (roomObj.AddToTowerPool) { LevelBuilder2.StoreRoom(roomObj5, GameTypes.LevelType.TOWER); LevelBuilder2.StoreSpecialRoom(roomObj5, GameTypes.LevelType.TOWER, false); } } if (roomObj.Name.Contains("DEBUG_ROOM")) { roomObj.Name = roomObj.Name.Replace("DEBUG_ROOM", ""); if (LevelEV.TESTROOM_LEVELTYPE != GameTypes.LevelType.CASTLE) { LevelBuilder2.StoreSpecialRoom(roomObj, GameTypes.LevelType.CASTLE, true); } LevelBuilder2.StoreSpecialRoom(roomObj, LevelEV.TESTROOM_LEVELTYPE, true); } } if (roomObj.X < 10000f && (roomObj.Name == "Boss" || roomObj.Name == "ChallengeBoss")) { LevelBuilder2.StoreSpecialRoom(roomObj, GameTypes.LevelType.CASTLE, false); } } } }
public static void ParseRooms(string filePath, ContentManager contentManager = null, bool isDLCMap = false) { var cultureInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone(); cultureInfo.NumberFormat.CurrencyDecimalSeparator = "."; var xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.IgnoreComments = true; xmlReaderSettings.IgnoreWhitespace = true; XmlReader xmlReader; if (contentManager == null) { xmlReader = XmlReader.Create(filePath, xmlReaderSettings); } else { xmlReader = XmlReader.Create(contentManager.RootDirectory + "\\Levels\\" + filePath + ".xml", xmlReaderSettings); } RoomObj roomObj = null; RoomObj roomObj2 = null; RoomObj roomObj3 = null; RoomObj roomObj4 = null; RoomObj roomObj5 = null; while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (xmlReader.Name == "RoomObject") { roomObj = new RoomObj(); ParseGenericXML(xmlReader, roomObj); if (isDLCMap) { roomObj.IsDLCMap = true; } roomObj2 = (roomObj.Clone() as RoomObj); roomObj3 = (roomObj.Clone() as RoomObj); roomObj4 = (roomObj.Clone() as RoomObj); roomObj5 = (roomObj.Clone() as RoomObj); } if (xmlReader.Name == "GameObject") { xmlReader.MoveToAttribute("Type"); var value = xmlReader.Value; GameObj gameObj = null; string key; switch (key = value) { case "CollHullObj": gameObj = new TerrainObj(0, 0); break; case "DoorObj": gameObj = new DoorObj(roomObj, 0, 0, GameTypes.DoorType.OPEN); break; case "ChestObj": if (xmlReader.MoveToAttribute("Fairy")) { if (bool.Parse(xmlReader.Value)) { gameObj = new FairyChestObj(null); (gameObj as ChestObj).ChestType = 4; } else { gameObj = new ChestObj(null); } } else { gameObj = new ChestObj(null); } break; case "HazardObj": gameObj = new HazardObj(0, 0); break; case "BorderObj": gameObj = new BorderObj(); break; case "EnemyObj": xmlReader.MoveToAttribute("Procedural"); if (!bool.Parse(xmlReader.Value)) { xmlReader.MoveToAttribute("EnemyType"); var enemyType = byte.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); xmlReader.MoveToAttribute("Difficulty"); var difficulty = (GameTypes.EnemyDifficulty) Enum.Parse(typeof(GameTypes.EnemyDifficulty), xmlReader.Value, true); gameObj = EnemyBuilder.BuildEnemy(enemyType, null, null, null, difficulty); if (xmlReader.MoveToAttribute("Flip") && bool.Parse(xmlReader.Value)) { gameObj.Flip = SpriteEffects.FlipHorizontally; } if (xmlReader.MoveToAttribute("InitialDelay")) { (gameObj as EnemyObj).InitialLogicDelay = float.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); } } else { xmlReader.MoveToAttribute("EnemyType"); var value2 = xmlReader.Value; gameObj = new EnemyTagObj(); (gameObj as EnemyTagObj).EnemyType = value2; } break; case "EnemyOrbObj": { xmlReader.MoveToAttribute("OrbType"); var orbType = int.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); var flag = false; if (xmlReader.MoveToAttribute("IsWaypoint")) { flag = bool.Parse(xmlReader.Value); } if (flag) { gameObj = new WaypointObj(); (gameObj as WaypointObj).OrbType = orbType; } else { gameObj = new EnemyOrbObj(); (gameObj as EnemyOrbObj).OrbType = orbType; if (xmlReader.MoveToAttribute("ForceFlying")) { (gameObj as EnemyOrbObj).ForceFlying = bool.Parse(xmlReader.Value); } } break; } case "SpriteObj": xmlReader.MoveToAttribute("SpriteName"); if (xmlReader.Value == "LightSource_Sprite") { gameObj = new LightSourceObj(); } else { gameObj = new SpriteObj(xmlReader.Value); } break; case "PhysicsObj": { xmlReader.MoveToAttribute("SpriteName"); gameObj = new PhysicsObj(xmlReader.Value); var physicsObj = gameObj as PhysicsObj; physicsObj.CollisionTypeTag = 5; physicsObj.CollidesBottom = false; physicsObj.CollidesLeft = false; physicsObj.CollidesRight = false; break; } case "PhysicsObjContainer": { var flag2 = false; if (xmlReader.MoveToAttribute("Breakable")) { flag2 = bool.Parse(xmlReader.Value); } xmlReader.MoveToAttribute("SpriteName"); if (flag2) { gameObj = new BreakableObj(xmlReader.Value); } else { gameObj = new PhysicsObjContainer(xmlReader.Value); } break; } case "ObjContainer": xmlReader.MoveToAttribute("SpriteName"); gameObj = new ObjContainer(xmlReader.Value); break; case "PlayerStartObj": gameObj = new PlayerStartObj(); break; } ParseGenericXML(xmlReader, gameObj); var levelType = GameTypes.LevelType.NONE; if (xmlReader.MoveToAttribute("LevelType")) { levelType = (GameTypes.LevelType) int.Parse(xmlReader.Value, NumberStyles.Any, cultureInfo); } if (levelType == GameTypes.LevelType.CASTLE) { StoreObj(gameObj, roomObj2); StoreSwappedObj(gameObj, GameTypes.LevelType.DUNGEON, roomObj3); StoreSwappedObj(gameObj, GameTypes.LevelType.TOWER, roomObj5); StoreSwappedObj(gameObj, GameTypes.LevelType.GARDEN, roomObj4); var spriteObj = gameObj as SpriteObj; if (spriteObj != null && spriteObj.SpriteName == "CastleAssetFrame_Sprite") { spriteObj.ChangeSprite("FramePicture" + CDGMath.RandomInt(1, 16) + "_Sprite"); } } else if (levelType == GameTypes.LevelType.DUNGEON) { StoreObj(gameObj, roomObj3); } else if (levelType == GameTypes.LevelType.TOWER) { StoreObj(gameObj, roomObj5); } else if (levelType == GameTypes.LevelType.GARDEN) { StoreObj(gameObj, roomObj4); } else { StoreObj(gameObj, roomObj2); StoreObj(gameObj, roomObj3); StoreObj(gameObj, roomObj5); StoreObj(gameObj, roomObj4); StoreObj(gameObj, roomObj); } if (LevelEV.RUN_TESTROOM && (levelType == LevelEV.TESTROOM_LEVELTYPE || levelType == GameTypes.LevelType.CASTLE)) { if (levelType == LevelEV.TESTROOM_LEVELTYPE) { StoreObj(gameObj, roomObj); } else if (levelType == GameTypes.LevelType.CASTLE) { StoreSwappedObj(gameObj, LevelEV.TESTROOM_LEVELTYPE, roomObj); } } if (gameObj is PlayerStartObj) { var expr_65E = roomObj; expr_65E.Name += "DEBUG_ROOM"; } } } else if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "RoomObject") { if (roomObj.X < 10000f && roomObj.Name != "Boss" && roomObj.Name != "ChallengeBoss") { if (!roomObj.Name.Contains("DEBUG_ROOM")) { if (roomObj.AddToCastlePool) { LevelBuilder2.StoreRoom(roomObj2, GameTypes.LevelType.CASTLE); LevelBuilder2.StoreSpecialRoom(roomObj2, GameTypes.LevelType.CASTLE); } if (roomObj.AddToDungeonPool) { LevelBuilder2.StoreRoom(roomObj3, GameTypes.LevelType.DUNGEON); LevelBuilder2.StoreSpecialRoom(roomObj3, GameTypes.LevelType.DUNGEON); } if (roomObj.AddToGardenPool) { LevelBuilder2.StoreRoom(roomObj4, GameTypes.LevelType.GARDEN); LevelBuilder2.StoreSpecialRoom(roomObj4, GameTypes.LevelType.GARDEN); } if (roomObj.AddToTowerPool) { LevelBuilder2.StoreRoom(roomObj5, GameTypes.LevelType.TOWER); LevelBuilder2.StoreSpecialRoom(roomObj5, GameTypes.LevelType.TOWER); } } if (roomObj.Name.Contains("DEBUG_ROOM")) { roomObj.Name = roomObj.Name.Replace("DEBUG_ROOM", ""); if (LevelEV.TESTROOM_LEVELTYPE != GameTypes.LevelType.CASTLE) { LevelBuilder2.StoreSpecialRoom(roomObj, GameTypes.LevelType.CASTLE, true); } LevelBuilder2.StoreSpecialRoom(roomObj, LevelEV.TESTROOM_LEVELTYPE, true); } } if (roomObj.X < 10000f && (roomObj.Name == "Boss" || roomObj.Name == "ChallengeBoss")) { LevelBuilder2.StoreSpecialRoom(roomObj, GameTypes.LevelType.CASTLE); } } } }