/// <summary> /// Gets a map queue entry of the currently joined room /// </summary> /// <param name="mapIndexOffset">The offset of the map index we want to get, relative to the currently played one</param> /// <returns></returns> static MapQueueEntry GetRoomMap(int mapIndexOffset) { if (PhotonNetwork.room == null) { Debug.LogError("Can't get current map if player hasn't joined a room yet."); return(MapQueueEntry.None); } if (PhotonNetwork.room.customProperties == null) { Debug.LogError("Current room doesn't have custom properties. Can't find current map."); return(MapQueueEntry.None); } if (PhotonNetwork.room.customProperties.ContainsKey(RoomProperty.MapQueue) == false) { Debug.LogError("Couldn't find map queue in room properties."); return(MapQueueEntry.None); } if (PhotonNetwork.room.customProperties.ContainsKey(RoomProperty.MapIndex) == false) { Debug.LogError("Couldn't find map index in room properties."); return(MapQueueEntry.None); } string mapQueueString = (string)PhotonNetwork.room.customProperties[RoomProperty.MapQueue]; int mapIndex = (int)PhotonNetwork.room.customProperties[RoomProperty.MapIndex] + mapIndexOffset; return(MapQueue.GetSingleEntryInMapQueue(mapQueueString, mapIndex)); }
/// 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 ); }
/// <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 ); }
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); }
protected void MapQuerierOnMapAdded(object sender, MapEventArgs e) { if (!MapQueue.ContainsKey(e.Map.Id) && !MapCompleted.ContainsKey(e.Map.Id)) { MapQueue.Add(e.Map.Id, e.Map); if (ProgressChanged != null) { ProgressChanged(this, new ProgressChangedEventArgs(MapCompleted.Count * 100 / (MapQueue.Count + MapCompleted.Count), null)); } } }
protected override void OnContainerMapLoaded(INode node) { base.OnContainerMapLoaded(node); CompendiumXmlMap = new CompendiumXmlMap(RootMapId); var mapQuerier = new CompendiumMapQuerier(MapManager, CompendiumXmlMap, SelectedNodes, node); MapQueue.Add(node.Id, node); mapQuerier.QueryCompleted += MapQuerierOnQueryCompleted; mapQuerier.MapAdded += MapQuerierOnMapAdded; mapQuerier.Process(); }
protected void MapQuerierOnQueryCompleted(object sender, MapEventArgs e) { try { if (MapQueue.ContainsKey(e.Map.Id)) { MapQueue.Remove(e.Map.Id); } if (!MapCompleted.ContainsKey(e.Map.Id)) { MapCompleted.Add(e.Map.Id, e.Map); } if (MapQueue.Count == 0) { OnProgressChanged(this, new ProgressChangedEventArgs(100, null)); OnExportCompleted(this, new ExportCompletedEventArgs(OutputFileLocation, UserState, RootMap.Name)); } else { OnProgressChanged(this, new ProgressChangedEventArgs(MapCompleted.Count * 100 / (MapQueue.Count + MapCompleted.Count), null)); var nextMap = MapQueue.Values.FirstOrDefault(); if (nextMap != null) { if (!MapCompleted.ContainsKey(nextMap.Id)) { ReadNextMap(nextMap); } else { var mapArgs = new MapEventArgs { Container = e.Container, Map = nextMap }; MapQuerierOnQueryCompleted(sender, mapArgs); } } else { throw new NullReferenceException("Map in queue is null"); } } } catch (Exception ex) { OnExceptionRaised(sender, "Error occurred when querying map data", ex); } }
/// <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; } }
void DrawCreateRoomButton() { if (GUI.Button(new Rect(40, Screen.height - 80, Screen.width - 80, 40), "Create Room", Styles.DarkButton)) { if (m_ServerName == "") { RoomMenu.ShowPopupMessage("Please enter a name"); } else if (m_MapQueue.Count == 0) { RoomMenu.ShowPopupMessage("Please add a map to the map queue"); } else { ServerOptions.CreateRoom(m_ServerName, MapQueue.ListToString(m_MapQueue)); } } }
/// <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); } }
void CreateSqlMatchmakingServer() { string serverName = ChatHandler.Instance.ChatUsername + "'s Server"; ServerOptions.CreateRoom(serverName, MapQueue.ListToString(m_MatchmakingMapQueue), m_PlayerSkill); }
/// <summary> /// If no suitable room was found through room properties matchmaking, we just create a new one /// </summary> void CreateRoomPropertiesMatchmakingServer() { string serverName = ChatHandler.Instance.ChatUsername + "'s Server"; ServerOptions.CreateRoom(serverName, MapQueue.ListToString(m_MatchmakingMapQueue)); }
void DrawEndOfMatchText() { Team winningTeam = m_Gamemode.GetWinningTeam(); if (winningTeam == Team.Blue) { GUI.color = Color.blue; GUI.Label(new Rect(0, 0, Screen.width, 200), "Blue Team won!", Styles.EndMatchLabel); } else if (winningTeam == Team.Red) { GUI.color = Color.red; GUI.Label(new Rect(0, 0, Screen.width, 200), "Red Team won!", Styles.EndMatchLabel); } else { GUI.color = Color.white; GUI.Label(new Rect(0, 0, Screen.width, 200), "Both Teams are tied!", Styles.EndMatchLabel); } GUI.color = Color.white; GUI.Label(new Rect(0, Screen.height * 0.5f + 140, Screen.width, 50), "Next Map: " + MapQueue.GetNextMap(), Styles.LabelSmallCentered); if (PhotonNetwork.isMasterClient == true && m_Gamemode.GetEndRoundTime() > 2f) { float blinkAlpha = (int)(m_Gamemode.GetEndRoundTime() * 2) % 2; GUI.color = new Color(1f, 1f, 1f, blinkAlpha); GUI.Label(new Rect(0, 0, Screen.width, Screen.height), "Press any key to load the next map.", LabelStyleCentered); } }