public void AddRoom(int _roomId, int _maxPlayers, int _currentPlayers, string _roomName, bool _isPrivate)
    {
        //Instantiates Room Prefab
        GameObject _roomPrefab      = Instantiate(roomPrefab, transform.position, Quaternion.identity, roomContainer.transform);
        RoomPrefab roomPrefabScript = _roomPrefab.GetComponent <RoomPrefab>();

        //Values
        roomPrefabScript.roomId   = _roomId;
        roomPrefabScript.roomName = _roomName;

        roomPrefabScript.currentPlayers = _currentPlayers;
        roomPrefabScript.maxPlayers     = _maxPlayers;
        roomPrefabScript.isPrivate      = _isPrivate;

        //Adds to List
        roomList.Add(_roomPrefab);


        Debug.Log($"Room Created:\n" +
                  $"Room Id: {_roomId}\n" +
                  $"Max Players: {_maxPlayers}\n" +
                  $"Current Players: {_currentPlayers}\n" +
                  $"RoomName: {_roomName}"
                  );
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        string sceneName = SceneManager.GetActiveScene().name;

        if (sceneName == "AbandonRoom")
        {
            Instantiate(RoomPrefab.getPrefab("AbandonRoom"));
        }
    }
Beispiel #3
0
    public void SpawnMap(RoomPrefab nextRoomPrefab)
    {
        var lastTileBounds = GetComponent <SpriteRenderer>().sprite.bounds;

        Instantiate(nextRoomPrefab,
                    new Vector2(transform.position.x + lastTileBounds.size.x * transform.localScale.x,
                                0),
                    transform.rotation
                    );
    }
Beispiel #4
0
    // Use this for initialization
    IEnumerator Start()
    {
        officeList = new MyRooms();
        personList = new Personnel();
        list       = new List <GameObject>();
        string  url  = "http://localhost:5000/room/";
        WWWForm form = new WWWForm();

        form.AddField("username", "asd");
        form.AddField("password", "asd");
        var headers = form.headers;

        byte[] rawData = form.data;
        headers["Authorization"] = "kLVHntU5YCsQku6GPf1Ehz9cPJ4lwO7krUOgICtSOefIiJ2QGZkbrlXiAXPH";

        using (WWW www = new WWW(url, rawData, headers)) {
            yield return(www);

            if (www.error == null)
            {
                officeList = JsonUtility.FromJson <MyRooms>(www.text);

                foreach (MyRoomData room in officeList.rooms)
                {
                    GameObject newOffice = (GameObject)GameObject.Instantiate(officePrefab);
                    newOffice.transform.SetParent(contentPanel, false);

                    RoomPrefab prefab = newOffice.GetComponent <RoomPrefab>();
                    prefab.Setup(room);
                    list.Add(newOffice);
                }
            }
            else
            {
                Debug.Log("ERROR: " + www.error);
            }
        }

        url = "http://localhost:5000/personnel/";
        using (WWW www = new WWW(url, rawData, headers)) {
            yield return(www);

            if (www.error == null)
            {
                personList = JsonUtility.FromJson <Personnel>(www.text);
                navScript.GetPersonnelList(this.personList);
            }
            else
            {
                Debug.Log("ERROR: " + www.error);
            }
        }
    }
Beispiel #5
0
    private void InstantiateRoomOutline(Vector3 position)
    {
        bool up    = Physics2D.OverlapCircle(position + new Vector3(0f, _yOffset, 0f), 0.2f, _roomLayer);
        bool down  = Physics2D.OverlapCircle(position + new Vector3(0f, -_yOffset, 0f), 0.2f, _roomLayer);
        bool right = Physics2D.OverlapCircle(position + new Vector3(_xOffset, 0f, 0f), 0.2f, _roomLayer);
        bool left  = Physics2D.OverlapCircle(position + new Vector3(-_xOffset, 0f, 0f), 0.2f, _roomLayer);

        RoomPrefab roomPrefab = PickRoom(up, down, right, left);

        if (roomPrefab != null)
        {
            GameObject room = Instantiate(roomPrefab.OutlinePrefab, position, transform.rotation, transform);
            room.transform.parent = _roomSlot.transform;
            _generateOutline.Add(room);
        }
    }
Beispiel #6
0
 /// <summary>
 /// Frankie's Prefab Script
 /// </summary>
 // Use this for initialization
 void Start()
 {
     RoomPrefab.LoadAll("Prefabs");
 }
Beispiel #7
0
    private bool generateSidePaths(List <RoomPrefab> mainPath, List <RoomPrefab> sidePath, string lastExit, int[] position)
    {
        // Figure out which entrance the next room has to have to connect with the previous room
        bool          roomSet       = false;                            // becomes true when the room is safe to use
        List <string> roomsNotToUse = new List <string>();              // a list of all the rooms that we have tried that did not work

        if (noRoomRepeats)
        {
            foreach (RoomPrefab rp in mainPath)
            {
                roomsNotToUse.Add(rp.prefabName);
            }
        }

        string lookingFor = "";

        switch (lastExit)
        {
        case "N":
            lookingFor = "S";
            position[1]++;
            break;

        case "W":
            lookingFor = "E";
            position[0]--;
            break;

        case "E":
            lookingFor = "W";
            position[0]++;
            break;

        case "S":
            lookingFor = "N";
            position[1]--;
            break;
        }

        Debug.Log(position [0] + " " + position [1]);

        while (!roomSet)
        {
            // Look through all room prefabs and select all of the rooms that can connect with the previous one that haven't been used yet
            List <string> potentialRooms = new List <string>();
            foreach (FileInfo f in info)
            {
                if (roomsNotToUse.Contains(f.Name))
                {
                    continue;
                }

                string fileName = f.Name.Substring(0, f.Name.Length - 7);                 // remove ".prefab"
                string e        = fileName.Substring(f.Name.LastIndexOf("_") + 1);        // get exit directions string

                bool willOverlap = false;
                foreach (RoomPrefab rp in mainPath)
                {
                    if (rp.position[0] == position[0] && rp.position[1] == position[1])
                    {
                        willOverlap = true;
                        break;
                    }
                }
                if (willOverlap)
                {
                    roomsNotToUse.Add(f.Name);
                    continue;
                }

                if (sidePath.Count == 0 && !fileName.Contains("_H_"))
                {
                    roomsNotToUse.Add(f.Name);
                    continue;
                }
                else if (sidePath.Count == 1 && !fileName.Contains("_T_"))
                {
                    roomsNotToUse.Add(f.Name);
                    continue;
                }

                // If we got here, the room is good to use
                potentialRooms.Add(fileName);
            }

            // If no rooms work for branching from this one, then we have to scrap this one
            if (potentialRooms.Count == 0)
            {
                // If we have a room to go back to, scrap this room and continue generation from the previous one
                if (sidePath.Count > 0)
                {
                    sidePath.RemoveAt(sidePath.Count - 1);
                    return(false);
                }
                // Otherwise, we are at the starter room, and generation has failed for all possible room combos, so we give up :(
                else
                {
                    break;
                }
            }
            else
            {
                Debug.Log("found potential");
            }

            // Select one of these rooms at random and create the room
            int       idx      = Random.Range(0, potentialRooms.Count);
            string    roomName = potentialRooms[idx];
            string    thisExit = roomName.Substring(roomName.LastIndexOf("_") + 1);
            Direction exitDir  = Direction.NONE;
            if (lookingFor != "")
            {
                thisExit = thisExit.Replace(lookingFor, "");
            }
            switch (thisExit)
            {
            case "N":
                exitDir = Direction.NORTH;
                break;

            case "W":
                exitDir = Direction.WEST;
                break;

            case "E":
                exitDir = Direction.EAST;
                break;

            case "S":
                exitDir = Direction.SOUTH;
                break;
            }
            string type = "_H_";
            if (sidePath.Count > 0)
            {
                type = "_T_";
            }
            RoomPrefab newRoom = new RoomPrefab(roomName + ".prefab", position, exitDir, type);
            sidePath.Add(newRoom);
            roomsNotToUse.Add(roomName + ".prefab");
            // If we have all rooms of the dungeon, return a success
            if (sidePath.Count == 2)
            {
                return(true);
            }
            // Set up generation of the next room if not done

            roomSet = generateSidePaths(mainPath, sidePath, thisExit, position);
        }
        return(false);
    }
Beispiel #8
0
    private List <RoomPrefab> setupSidePaths(List <RoomPrefab> rooms)
    {
        List <RoomPrefab> sideRooms = new List <RoomPrefab>();

        // Get a list of all rooms that can be used for branching
        List <string> potentialRooms = new List <string>();

        foreach (FileInfo f in info)
        {
            string fileName = f.Name.Substring(0, f.Name.Length - 7);               // remove ".prefab"
            string e        = fileName.Substring(f.Name.LastIndexOf("_") + 1);      // get exit directions string

            if (e.Length >= 3)
            {
                potentialRooms.Add(fileName);
            }
        }

        // Pick a random room from the dungeon aside from the start and boss room to replace with a branching room
        int roomToBranch = Random.Range(1, rooms.Count - 1);
        int i            = roomToBranch;

        do
        {
            // Figure out which branching rooms could be used for replacing this room
            string        pName       = rooms[i].prefabName.Substring(0, rooms[i].prefabName.Length - 7);
            string        se          = pName.Substring(pName.LastIndexOf("_") + 1);            // room to replace entrances
            List <string> roomChoices = new List <string>();

            foreach (string roomName in potentialRooms)
            {
                string pe = roomName.Substring(roomName.LastIndexOf("_") + 1);                  // branching room entrances

                // Make sure that the branching room has the same two entrances that the room it's replacing does
                if (pe.Contains(se[0].ToString()) && pe.Contains(se[1].ToString()))
                {
                    roomChoices.Add(roomName);
                }
            }

            bool   success    = false;
            string branchName = "";

            Debug.Log(rooms[i].position[0] + " " + rooms[i].position[1]);
            Debug.Log("\n");

            foreach (string roomName in roomChoices)
            {
                string pe = roomName.Substring(roomName.LastIndexOf("_") + 1);
                pe = pe.Replace(se[0].ToString(), "");
                pe = pe.Replace(se[1].ToString(), "");

                foreach (char e in pe)
                {
                    if (generateSidePaths(rooms, sideRooms, e.ToString(), rooms[i].position))
                    {
                        branchName = roomName + ".prefab";
                        success    = true;
                        break;
                    }
                }

                if (success)
                {
                    break;
                }
            }

            if (success)
            {
                Debug.Log("work");
                rooms[i] = new RoomPrefab(branchName, rooms[i].position, rooms[i].exit, rooms[i].type);
                break;
            }
            else
            {
                break;
            }

            // Continue on to the next room in the range of 1 thru rooms.Count - 2
            i = i == rooms.Count - 2 ? 1 : i + 1;
        } while (i != roomToBranch);

        // Take the created side path and add it to the dungeon


        return(sideRooms);
    }
Beispiel #9
0
    private bool generateRoom(List <RoomPrefab> rooms, Dictionary <string, int> numRoomTypes)
    {
        // Figure out which entrance the next room has to have to connect with the previous room
        string lookingFor = "";

        if (rooms.Count > 0)
        {
            switch (rooms[rooms.Count - 1].exit)
            {
            case Direction.NORTH:
                lookingFor = "S";
                break;

            case Direction.WEST:
                lookingFor = "E";
                break;

            case Direction.EAST:
                lookingFor = "W";
                break;

            case Direction.SOUTH:
                lookingFor = "N";
                break;
            }
        }

        bool          roomSet       = false;                            // becomes true when the room is safe to use
        List <string> roomsNotToUse = new List <string>();              // a list of all the rooms that we have tried that did not work

        // Continue trying to pick a room until either a suitable one is found or all options are exhausted, upon which we scrap this room and back out to the previous one
        while (!roomSet)
        {
            // Look through all room prefabs and select all of the rooms that can connect with the previous one that haven't been used yet
            int[]         nextRoomPos    = new int[2];
            List <string> potentialRooms = new List <string>();
            foreach (FileInfo f in info)
            {
                if (roomsNotToUse.Contains(f.Name))
                {
                    continue;
                }

                string fileName = f.Name.Substring(0, f.Name.Length - 7);                 // remove ".prefab"
                string e        = fileName.Substring(f.Name.LastIndexOf("_") + 1);        // get exit directions string

                // Make sure that this room won't overlap with any existing rooms
                if (rooms.Count > 0)
                {
                    nextRoomPos[0] = rooms[rooms.Count - 1].position[0];
                    nextRoomPos[1] = rooms[rooms.Count - 1].position[1];

                    switch (rooms[rooms.Count - 1].exit)
                    {
                    case Direction.NORTH:
                        lookingFor = "S";
                        nextRoomPos[1]++;
                        break;

                    case Direction.WEST:
                        lookingFor = "E";
                        nextRoomPos[0]--;
                        break;

                    case Direction.EAST:
                        lookingFor = "W";
                        nextRoomPos[0]++;
                        break;

                    case Direction.SOUTH:
                        lookingFor = "N";
                        nextRoomPos[1]--;
                        break;
                    }

                    bool willOverlap = false;
                    foreach (RoomPrefab rp in rooms)
                    {
                        if (rp.position[0] == nextRoomPos[0] && rp.position[1] == nextRoomPos[1])
                        {
                            willOverlap = true;
                            break;
                        }
                    }
                    if (willOverlap)
                    {
                        roomsNotToUse.Add(f.Name);
                        continue;
                    }
                }

                // First room
                if (rooms.Count == 0)
                {
                    // first room must be starter type
                    if (fileName.Contains("_S_"))
                    {
                        potentialRooms.Add(fileName);
                    }
                }
                // Final room
                else if (rooms.Count == numRooms - 1)
                {
                    // makes sure the final room is a boss room
                    if (fileName.Contains("_B_") && e.Contains(lookingFor))
                    {
                        potentialRooms.Add(fileName);
                    }
                }
                // Middle rooms
                else
                {
                    // Room must have the required entrance to connect with the previous room and must have another exit in addition to that
                    if (e.Contains(lookingFor) && e.Length == 2)
                    {
                        if (noRoomRepeats)                              // don't include rooms we have used previously
                        {
                            bool foundRepeat = false;

                            foreach (RoomPrefab rp in rooms)
                            {
                                if (rp.prefabName == f.Name)
                                {
                                    foundRepeat = true;
                                    break;
                                }
                            }

                            if (foundRepeat)
                            {
                                roomsNotToUse.Add(f.Name);
                                continue;
                            }
                        }

                        if (roomBalance)                                        // carry out various actions to balance the room selection
                        {
                            if (fileName.Contains(rooms[rooms.Count - 1].type)) // don't do the same type of room twice in a row
                            {
                                roomsNotToUse.Add(f.Name);
                                continue;
                            }

                            if (fileName.Contains("_H_") && numRoomTypes["_H_"] == goalHordeRooms)
                            {
                                roomsNotToUse.Add(f.Name);
                                continue;
                            }
                            if (fileName.Contains("_P_") && numRoomTypes["_P_"] == goalPuzzleRooms)
                            {
                                roomsNotToUse.Add(f.Name);
                                continue;
                            }
                            if (fileName.Contains("_R_") && numRoomTypes["_R_"] == goalReactionRooms)
                            {
                                roomsNotToUse.Add(f.Name);
                                continue;
                            }
                        }

                        // If a puzzle or reaction room, make sure that we are using the right entrance to the room
                        // (the required entrance will be the first character in e)
                        if (fileName.Contains("_P_") || fileName.Contains("_R_"))
                        {
                            if (e[0].ToString() != lookingFor)
                            {
                                roomsNotToUse.Add(f.Name);
                                continue;
                            }
                        }

                        // If we made it through the optional checks, then go ahead and add the room
                        potentialRooms.Add(fileName);
                    }
                }
            }
            // If no rooms work for branching from this one, then we have to scrap this one
            if (potentialRooms.Count == 0)
            {
                // If we have a room to go back to, scrap this room and continue generation from the previous one
                if (rooms.Count > 0)
                {
                    rooms.RemoveAt(rooms.Count - 1);
                    return(false);
                }
                // Otherwise, we are at the starter room, and generation has failed for all possible room combos, so we give up :(
                else
                {
                    break;
                }
            }
            // Select one of these rooms at random and create the room
            int       idx      = Random.Range(0, potentialRooms.Count);
            string    roomName = potentialRooms[idx];
            string    thisExit = roomName.Substring(roomName.LastIndexOf("_") + 1);
            Direction exitDir  = Direction.NONE;
            if (lookingFor != "")
            {
                thisExit = thisExit.Replace(lookingFor, "");                    // currently only supports rooms with 2 entrances
            }
            switch (thisExit)
            {
            case "N":
                exitDir = Direction.NORTH;
                break;

            case "W":
                exitDir = Direction.WEST;
                break;

            case "E":
                exitDir = Direction.EAST;
                break;

            case "S":
                exitDir = Direction.SOUTH;
                break;
            }
            string type = "_S_";
            if (roomName.Contains("_H_"))
            {
                type = "_H_";
            }
            else if (roomName.Contains("_P_"))
            {
                type = "_P_";
            }
            else if (roomName.Contains("_B_"))
            {
                type = "_B_";
            }
            else if (roomName.Contains("_T_"))
            {
                type = "_T_";
            }
            else if (roomName.Contains("_R_"))
            {
                type = "_R_";
            }
            Dictionary <string, int> newNumRoomTypes = new Dictionary <string, int>(numRoomTypes);
            newNumRoomTypes[type]++;
            RoomPrefab newRoom = new RoomPrefab(roomName + ".prefab", nextRoomPos, exitDir, type);
            rooms.Add(newRoom);
            roomsNotToUse.Add(roomName + ".prefab");
            // If we have all rooms of the dungeon, return a success
            if (rooms.Count == numRooms)
            {
                return(true);
            }
            // Set up generation of the next room if not done
            roomSet = generateRoom(rooms, newNumRoomTypes);
        }
        return(true);
    }