/// <summary> /// Create and place and DungeonRooms and Corridors from the generated dungeons. /// </summary> /// <param name="dungeon">The dungeon that was just generated.</param> /// <param name="levelNumber">The number of the level.</param> /// <param name="timer">The current used DungeonTimer.</param> /// <returns></returns> public IEnumerator CreateRooms(Dungeon dungeon, int levelNumber, DungeonConfig config, DungeonTimer timer) { List <DungeonRoom> dungeonRooms = new List <DungeonRoom>(); DungeonDict.Instance.ResetRooms(dungeon.Rooms.Length + dungeon.Corridors.Length); GameObject prefabDoorLR = RegionDict.Instance.PrefabDoorLR; GameObject prefabDoorUD = RegionDict.Instance.PrefabDoorUD; // Create DungeonRooms for (int i = 0; i < dungeon.Rooms.Length; i++) { GameObject dungeonRoomObject = Instantiate(DungeonCreator.Instance.PrefabDungeonRoom); dungeonRoomObject.transform.parent = DungeonCreator.Instance.RoomsContainer; DungeonRoom dungeonRoom = SetRoomType(dungeon.Rooms[i], dungeonRoomObject, levelNumber, config); // set room id dungeonRoom.id = i; DungeonDict.Instance.Register(dungeonRoom); SetRoomBorder(dungeon, i, dungeonRoom); SetRoomObjects(dungeon.Rooms[i], dungeonRoomObject, dungeonRoom); SetDoors(dungeon, prefabDoorLR, prefabDoorUD, i, dungeonRoomObject, dungeonRoom); dungeonRooms.Add(dungeonRoom); dungeonRoom.OnFullyCreated(); if (timer.ShouldWait()) { yield return(timer.Wait(0.9f + ((i * 1.0f / dungeon.Rooms.Length) * 0.05f))); } } // Create corridors. for (int i = 0; i < dungeon.Corridors.Length; i++) { Corridor corridor = dungeon.Corridors[i]; GameObject corridorObject = new GameObject("Corridor_" + i); corridorObject.transform.parent = DungeonCreator.Instance.CorridorContainer; CorridorRoom corridorRoom = corridorObject.AddComponent <CorridorRoom>(); corridorRoom.id = dungeon.Rooms.Length + i; corridorRoom.walkableTiles = corridor.GetWalkableTiles(); corridorRoom.direction = corridor.Size.y == 3; SetCorridorBorder(corridor, corridorRoom); DungeonDict.Instance.Register(corridorRoom); } }
/// <summary> /// Generates specific values for the DungeonType. /// </summary> /// <param name="room">The current room.</param> /// <param name="dungeonRoomObject">The gameobject to which the room should be generate don.</param> /// <param name="levelNumber">The number of the level.</param> /// <returns>The fully generated DungeonRoom.</returns> private DungeonRoom SetRoomType(Room room, GameObject dungeonRoomObject, int levelNumber, DungeonConfig config) { switch (room.Type) { case RoomType.Start: StartRoom startRoom = dungeonRoomObject.AddComponent <StartRoom>(); if (Player.LocalPlayer.isServer && levelNumber == 0) { startRoom.SpawnItems(RegionDict.Instance.StartingRoomPickables, DungeonCreator.Instance.TilePositionToWorldPosition(room.Position + (room.Layout.Size / 2))); } return(startRoom); case RoomType.Combat: CombatRoom combatRoom = dungeonRoomObject.AddComponent <CombatRoom>(); combatRoom.ThreatLevel = room.TileCount; combatRoom.enemiesToSpawn = new EnemyObject[combatRoom.ThreatLevel / 48]; for (int j = 0; j < combatRoom.enemiesToSpawn.Length; j++) { combatRoom.enemiesToSpawn[j] = RandomUtil.Element(RegionDict.Instance.EnemiesToSpawn); } return(combatRoom); case RoomType.Loot: LootRoom lootRoom = dungeonRoomObject.AddComponent <LootRoom>(); lootRoom.pickables = new Pickable[room.TileCount / 48]; for (int j = 0; j < lootRoom.pickables.Length; j++) { lootRoom.pickables[j] = RandomUtil.Element(RegionDict.Instance.LootingRoomPickables); } return(lootRoom); case RoomType.Shop: ShopRoom shopRoom = dungeonRoomObject.AddComponent <ShopRoom>(); const int numItems = 4; shopRoom.shopItems = new Pickable[numItems]; shopRoom.locations = new Vector2[numItems]; // TODO: Replace Pickabledict with dungeon config shop pickables. for (int j = 0; j < numItems; j++) { int rnd = Random.Range(0, config.shopItems.Length); shopRoom.shopItems[j] = config.shopItems[rnd]; shopRoom.locations[j] = room.Position + new Vector2Int((int)room.GameObjects[j + 4].Position.x, (int)room.GameObjects[j + 4].Position.y); } shopRoom.SpawnItems(); return(shopRoom); case RoomType.Boss: BossRoom bossRoom = dungeonRoomObject.AddComponent <BossRoom>(); bossRoom.bossObjects = new BossObject[] { RandomUtil.Element(RegionDict.Instance.BossesToSpawn) }; DungeonDict.Instance.SetBossRoom(bossRoom); return(bossRoom); case RoomType.Empty: EmptyRoom emptyRoom = dungeonRoomObject.AddComponent <EmptyRoom>(); return(emptyRoom); default: throw new System.Exception("Unknown room type! (" + room.Type + ")"); } }