private ExplorableSection PlaceRoom(ExplorableSection.RoomType connectingType, GameObject exitToConnectTo)
    {
        GameObject        connectableRoom           = null;
        ExplorableSection connectableRoomExplorable = null;
        List <int>        roomIdxToAttempt          = GetRandomRoomIdx(connectingType);

        for (int i = 0; i < roomIdxToAttempt.Count; i++)
        {
            connectableRoom           = instantiatedRooms[connectingType][roomIdxToAttempt[i]];
            connectableRoomExplorable = connectableRoom.GetComponent <ExplorableSection>();
            connectableRoomExplorable.AttachToExit(exitToConnectTo);
            ReplenishRoomPool(connectableRoom, connectingType, roomIdxToAttempt[i]);

            if (DoesRoomOverlap(connectableRoom))
            {
                Destroy(connectableRoom);
                connectableRoom           = null;
                connectableRoomExplorable = null;
            }
            else
            {
                createdRooms.Add(connectableRoom);
                break;
            }
        }
        return(connectableRoomExplorable);
    }
 private void FindAllLootableContainers()
 {
     for (int i = 0; i < districtRooms.Count; i++)
     {
         ExplorableSection explorableSection = districtRooms[i].GetComponent <ExplorableSection>();
         for (int j = 0; j < explorableSection.LootableContainers.Length; j++)
         {
             lootableContainers.Add(explorableSection.LootableContainers[j].GetComponent <LootableContainer>());
         }
     }
 }
 private void CreateRoomBuildingPool()
 {
     createdRoomToRoomIdx = new Dictionary <GameObject, int>();
     instantiatedRooms    = new Dictionary <ExplorableSection.RoomType, List <GameObject> >();
     for (int i = 0; i < rooms.Length; i++)
     {
         GameObject        newRoom = Instantiate(rooms[i], transform.position, Quaternion.identity);
         ExplorableSection newRoomExplorableSection = newRoom.GetComponent <ExplorableSection>();
         if (!instantiatedRooms.ContainsKey(newRoomExplorableSection.SectionRoomType))
         {
             instantiatedRooms[newRoomExplorableSection.SectionRoomType] = new List <GameObject>();
         }
         instantiatedRooms[newRoomExplorableSection.SectionRoomType].Add(newRoom);
         createdRoomToRoomIdx[newRoom] = i;
     }
 }
    public List <GameObject> BuildRooms()
    {
        // playerStartPoint is the side of the room that the player starts in, currently it should only support
        // east or west (as that is what the hallway is by default). Later this should be changed to allow the starting
        // room type to be rotated as the game call for it
        ExplorableSection currentRoomExplorable = startingRoom.GetComponent <ExplorableSection>();
        List <GameObject> pendingExits          = new List <GameObject>();

        for (int i = 0; i < currentRoomExplorable.Exits.Length; i++)
        {
            if (currentRoomExplorable.Exits[i] != playerStartPoint)
            {
                pendingExits.Add(currentRoomExplorable.Exits[i]);
            }
        }

        createdRooms.Add(startingRoom);

        for (int i = 0; i < buildIterations; i++)
        {
            List <GameObject> newExits = new List <GameObject>();
            for (int j = 0; j < pendingExits.Count; j++)
            {
                ExplorableSectionExit      sectionExit    = pendingExits[j].GetComponent <ExplorableSectionExit>();
                ExplorableSection.RoomType connectingType = sectionExit.ConnectableRoomTypes[Random.Range(0, sectionExit.ConnectableRoomTypes.Length)];
                currentRoomExplorable = PlaceRoom(connectingType, pendingExits[j]);
                if (currentRoomExplorable != null)
                {
                    for (int k = 0; k < currentRoomExplorable.Exits.Length; k++)
                    {
                        if (currentRoomExplorable.RoomAttachedExitLocation != currentRoomExplorable.Exits[k])
                        {
                            newExits.Add(currentRoomExplorable.Exits[k]);
                        }
                    }
                }
            }
            pendingExits = newExits;
        }
        RemoveRoomBuildingPool();
        return(createdRooms);
    }