/// Below OnJoinedRoom() is as used in the Tutorial/Videos but commented out.
    /// Below that, is a more up to date variant, using PhotonNetwork.LoadLevel() on the Master Client.

    ///// <summary>
    ///// Called when we successfully joined a room. It is also called if we created the room.
    ///// </summary>
    //void OnJoinedRoom()
    //{
    //    //Pause the message queue. While unity is loading a new level, updates from Photon are skipped.
    //    //So we have to tell Photon to wait until we resume the queue again after the level is loaded. See MultiplayerConnector.OnLevelWasLoaded
    //    PhotonNetwork.isMessageQueueRunning = false;

    //    MapQueueEntry currentMap = MapQueue.GetCurrentMap();

    //    Debug.Log( "OnJoinedRoom. Loading map: " + currentMap );

    //    if( currentMap.Equals( MapQueueEntry.None ) )
    //    {
    //        PhotonNetwork.LeaveRoom();
    //        return;
    //    }

    //    Application.LoadLevel( currentMap.Name );

    //    ChatHandler.Instance.SetOnlineStatus(
    //        ExitGames.Client.Photon.Chat.ChatUserStatus.Playing,
    //        PhotonNetwork.room.name
    //    );
    //}

    /// <summary>
    /// Called when we successfully joined a room. It is also called if we created the room.
    /// </summary>
    void OnJoinedRoom()
    {
        if (PhotonNetwork.isMasterClient)
        {
            MapQueueEntry currentMap = MapQueue.GetCurrentMap();

            Debug.Log("OnJoinedRoom. Loading map: " + currentMap);

            if (currentMap.Equals(MapQueueEntry.None))
            {
                PhotonNetwork.LeaveRoom();
                return;
            }

            //Pause the message queue. While unity is loading a new level, updates from Photon are skipped.
            //So we have to tell Photon to wait until we resume the queue again after the level is loaded. See MultiplayerConnector.OnLevelWasLoaded
            //PhotonNetwork.isMessageQueueRunning = false;

            // PhotonNetwork.LoadLevel will internally handle isMessageQueueRunning.
            // It will also load the correct scene on all clients automatically, so this call is only needed by the Master Client.
            PhotonNetwork.LoadLevel("main");

            //PhotonNetwork.player.CustomProperties;
//            PhotonNetwork.LoadLevel(currentMap.Name);
        }
        else
        {
            Debug.Log("OnJoinedRoom. LoadedLevel: " + SceneManager.GetActiveScene().name);
        }

        ChatHandler.Instance.SetOnlineStatus(
            ExitGames.Client.Photon.Chat.ChatUserStatus.Playing,
            PhotonNetwork.room.Name
            );
    }
Beispiel #2
0
    public static void CreateRoom(string name, string mapQueueString, int skillLevel = 5)
    {
        MapQueueEntry firstMap = MapQueue.GetSingleEntryInMapQueue(mapQueueString, 0);

        RoomOptions roomOptions = new RoomOptions();

        roomOptions.MaxPlayers = 8;

        roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
        roomOptions.CustomRoomProperties.Add(RoomProperty.MapQueue, mapQueueString);
        roomOptions.CustomRoomProperties.Add(RoomProperty.MapIndex, 0);
        roomOptions.CustomRoomProperties.Add(RoomProperty.RedScore, 0);
        roomOptions.CustomRoomProperties.Add(RoomProperty.BlueScore, 0);
        roomOptions.CustomRoomProperties.Add(RoomProperty.Map, firstMap.Name);
        roomOptions.CustomRoomProperties.Add(RoomProperty.Mode, (int)firstMap.Mode);
        Debug.Log(firstMap.Mode);
        roomOptions.CustomRoomProperties.Add(RoomProperty.SkillLevel, skillLevel);

        roomOptions.CustomRoomPropertiesForLobby = new string[] {
            RoomProperty.Map,
            RoomProperty.Mode,
            RoomProperty.SkillLevel,
        };

        PhotonNetwork.JoinOrCreateRoom(name, roomOptions, MultiplayerConnector.Lobby);
    }
Beispiel #3
0
    /// <summary>
    /// Gets all the necessary data that is needed to load the next map and stores
    /// the information in the rooms custom properties
    /// </summary>
    protected void LoadNextMap()
    {
        //MapQueue has a quick access function that retrieves the next map from the custom properties
        MapQueueEntry map = MapQueue.GetNextMap();

        //We also have to calculate what the index of the next map is, so everybody knows where
        //we are in the map queue
        int currentMapIndex = (int)PhotonNetwork.room.CustomProperties[RoomProperty.MapIndex];

        //The map queue simply loops when all maps have been played
        int nextMapIndex = (currentMapIndex + 1) % MapQueue.GetCurrentMapQueueLength();

        //Store all the information in a photon hashtable that are needed for the next map
        ExitGames.Client.Photon.Hashtable newProperties = new ExitGames.Client.Photon.Hashtable();
        newProperties.Add(RoomProperty.BlueScore, 0);
        newProperties.Add(RoomProperty.RedScore, 0);
        newProperties.Add(RoomProperty.MapIndex, nextMapIndex);
        newProperties.Add(RoomProperty.Map, map.Name);
        Debug.Log("LOOK AT MEEEEEEEEEEEEE");
        Debug.Log(map.Mode);
        newProperties.Add(RoomProperty.Mode, map.Mode);

        //And store this information in the rooms custom properties
        PhotonNetwork.room.SetCustomProperties(newProperties);

        //Then load the next map. PhotonNetwork.LoadLevel automatically sends the LoadLevel event
        //to all other clients so that everybody joins the next map. This only has to be called on
        //the master client
        PhotonNetwork.LoadLevel("main");
        //PhotonNetwork.LoadLevel( map.Name );
    }
    void AddMapToQueue(string map, Gamemode mode)
    {
        MapQueueEntry newEntry = new MapQueueEntry
        {
            Name = map,
            Mode = mode,
        };

        m_MapQueue.Add(newEntry);
    }
    public override bool Equals(object obj)
    {
        if (obj is MapQueueEntry)
        {
            MapQueueEntry otherEntry = (MapQueueEntry)obj;

            return(Name == otherEntry.Name && Mode == otherEntry.Mode);
        }

        return(false);
    }
Beispiel #6
0
	void AddMapToQueue(string map, Gamemode mode)
	{
		MapQueueEntry newEntry = new MapQueueEntry
		{
			Name = map,
			Mode = mode,
		};

		m_MapQueue.Add( newEntry );
		UpdateGamesList();
	}
Beispiel #7
0
    /// <summary>
    /// Convert a single map queue entry string to a MapQueueEntry object
    /// </summary>
    /// <param name="mapQueueEntryString">The map queue entry string.</param>
    /// <returns></returns>
    public static MapQueueEntry StringToEntry(string mapQueueEntryString)
    {
        string[] mapData = mapQueueEntryString.Split('#');

        MapQueueEntry queueEntry = new MapQueueEntry
        {
            Name = mapData[0],
            Mode = (Gamemode)(int.Parse(mapData[1]))
        };

        return(queueEntry);
    }
Beispiel #8
0
	/// <summary>
	/// Convert a single map queue entry string to a MapQueueEntry object
	/// </summary>
	/// <param name="mapQueueEntryString">The map queue entry string.</param>
	/// <returns></returns>
	public static MapQueueEntry StringToEntry( string mapQueueEntryString )
	{
		string[] mapData = mapQueueEntryString.Split( '#' );

		MapQueueEntry queueEntry = new MapQueueEntry
		{
			Name = mapData[ 0 ],
			Mode = (Gamemode)( int.Parse( mapData[ 1 ] ) )
		};

		return queueEntry;
	}
Beispiel #9
0
    /// <summary>
    /// This function checks the current room for it's custom properties to see which game mode
    /// is currently being played
    /// </summary>
    void FindCurrentMapMode()
    {
        //Check if we are actually connected to a room
        if (PhotonNetwork.room == null)
        {
            return;
        }

        MapQueueEntry map = MapQueue.GetCurrentMap();

        if (map.Equals(MapQueueEntry.None) == false)
        {
            SelectedGamemode = map.Mode;
        }
    }
Beispiel #10
0
    /// <summary>
    /// Convert a map queue string back into a list
    /// </summary>
    /// <param name="mapQueueString">The map queue string.</param>
    /// <returns></returns>
    public static List <MapQueueEntry> StringToList(string mapQueueString)
    {
        List <MapQueueEntry> mapQueue = new List <MapQueueEntry>();

        //First, split the big string into it's entry segments
        string[] mapSegments = mapQueueString.Split('~');

        for (int i = 0; i < mapSegments.Length; ++i)
        {
            //And then convert each segment into a map queue entry
            MapQueueEntry newQueueEntry = StringToEntry(mapSegments[i]);

            mapQueue.Add(newQueueEntry);
        }

        return(mapQueue);
    }
Beispiel #11
0
    void MakeRoomPropertiesMatchmakingJoinAttempt()
    {
        if (m_JoinAttempt < m_MatchmakingMapQueue.Count)
        {
            MapQueueEntry searchForMap = m_MatchmakingMapQueue[m_JoinAttempt];

            ExitGames.Client.Photon.Hashtable expectedProperties = new ExitGames.Client.Photon.Hashtable();
            expectedProperties.Add(RoomProperty.Map, searchForMap.Name);
            expectedProperties.Add(RoomProperty.Mode, searchForMap.Mode);

            PhotonNetwork.JoinRandomRoom(expectedProperties, 0);

            m_JoinAttempt++;
        }
        else
        {
            CreateRoomPropertiesMatchmakingServer();
        }
    }
    void DrawMapQueueList()
    {
        GUILayout.BeginArea(new Rect(510, 220, 390, Screen.height - 340));
        {
            for (int i = 0; i < m_MapQueue.Count; ++i)
            {
                MapQueueEntry entry = m_MapQueue[i];

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(entry.Name + " [" + GetGamemodeShortform(entry.Mode) + "]", Styles.LabelSmall);
                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("X", Styles.DarkButtonActive, GUILayout.Width(60)) == true)
                    {
                        m_MapQueue.RemoveAt(i);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
        GUILayout.EndArea();
    }
Beispiel #13
0
    /// <summary>
    /// This function creates 8 dummy rooms with random properties
    /// </summary>
    void CreateTestDummyRoomInfos()
    {
        m_TestDummyRoomInfos = new RoomInfo[8];
        string[] serverNames = new string[] { "Team Watery Server", "24/7 Deathmatch", "BestClanEver - Beginners only", "ESL Server 1", "ESL Server 2", "Sky Arena Developers",
                                              "Test Server", "Yay my first server" };

        for (int i = 0; i < m_TestDummyRoomInfos.Length; ++i)
        {
            int    mapIndex       = Random.Range(0, 4);
            string mapQueueString = "City#0~Greenlands#1~City#2~Greenlands#0~City#1~Greenlands#2";

            MapQueueEntry currentMap = MapQueue.GetSingleEntryInMapQueue(mapQueueString, mapIndex);

            ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
            properties.Add(GamePropertyKey.MaxPlayers, (byte)8);
            properties.Add(GamePropertyKey.PlayerCount, (byte)Random.Range(0, 8));
            properties.Add(RoomProperty.MapIndex, mapIndex);
            properties.Add(RoomProperty.MapQueue, mapQueueString);
            properties.Add(RoomProperty.Map, currentMap.Name);
            properties.Add(RoomProperty.Mode, (int)currentMap.Mode);

            m_TestDummyRoomInfos[i] = new RoomInfo(serverNames[i], properties);
        }
    }
Beispiel #14
0
 /// <summary>
 /// Convert a single MapQueueEntry to a string representation
 /// </summary>
 /// <param name="entry">The entry.</param>
 /// <returns></returns>
 public static string EntryToString(MapQueueEntry entry)
 {
     return(entry.Name + "#" + (int)entry.Mode);
 }
Beispiel #15
0
	/// <summary>
	/// Convert a single MapQueueEntry to a string representation
	/// </summary>
	/// <param name="entry">The entry.</param>
	/// <returns></returns>
	public static string EntryToString( MapQueueEntry entry )
	{
		return entry.Name + "#" + (int)entry.Mode;
	}