// Max players private void SetupMaxPlayerSelector(int i_StadiumId) { SelectorData selectorData = new SelectorData(); tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(i_StadiumId); if (stadiumData != null) { int minPlayers = 2 * stadiumData.onlineTeamSize.min; int maxPlayers = 2 * stadiumData.onlineTeamSize.max; int localPartySize; PhotonUtils.TryGetPlayerCustomProperty <int>(PhotonNetwork.player, PhotonPropertyKey.s_PlayerCustomPropertyKey_LocalPartySize, out localPartySize); for (int numPlayers = minPlayers; numPlayers <= maxPlayers; numPlayers += 2) { if (numPlayers <= localPartySize) { continue; } SelectorItem selectorItem = new SelectorItem(numPlayers, numPlayers.ToString(), "", null); selectorData.AddItem(selectorItem); } } if (viewInstance != null) { viewInstance.SetMaxPlayersSelectorData(selectorData); } RefreshMaxPlayers(); }
private void Synchronization_Update() { if (PhotonNetwork.room == null) { RPC_Setup(0); return; } if (!PhotonNetwork.isMasterClient) { return; } int totalPlayers = PhotonNetwork.room.PlayerCount; // Wait for players. if (m_Synchronization_WaitingForPlayers) { int playersJoined = 0; PhotonPlayer[] photonPlayers = PhotonNetwork.playerList; if (photonPlayers != null) { for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Length; ++photonPlayerIndex) { PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex]; if (photonPlayer == null) { continue; } bool playerJoined; if (PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_PlayerJoined_PropertyKey, out playerJoined)) { if (playerJoined) { ++playersJoined; } } } } if (playersJoined == totalPlayers) { m_Synchronization_WaitingForPlayers = false; int seed = (m_ForcedSeed >= 0) ? m_ForcedSeed : Random.Range(0, int.MaxValue); m_PhotonView.RPC("RPC_Setup", PhotonTargets.AllViaServer, (int)seed); } } }
private void CheckRoomPing() { int currentPing = 0; PhotonPlayer[] photonPlayers = PhotonNetwork.playerList; if (photonPlayers != null) { if (photonPlayers.Length > 0) { for (int index = 0; index < photonPlayers.Length; ++index) { PhotonPlayer photonPlayer = photonPlayers[index]; if (photonPlayer == null) { continue; } int playerPing; PhotonUtils.TryGetPlayerCustomProperty <int>(PhotonPropertyKey.s_PlayerCustomPropertyKey_Ping, out playerPing); currentPing += playerPing; } currentPing /= photonPlayers.Length; } } int diff = currentPing - m_LastRoomPing; int absDiff = Mathf.Abs(diff); if (diff < 0) { if (absDiff > m_RoomFallingThreshold) { WriteRoomProperty(currentPing); } } else { if (diff > 0) { if (absDiff > m_RoomRisingThreshold) { WriteRoomProperty(currentPing); } } } m_LastRoomPing = currentPing; }
// Game mode private void SetupGameModeSelector() { SelectorData selectorData = new SelectorData(); List <int> gameModesKeys = tnGameData.GetGameModesKeysMain(); if (gameModesKeys != null) { for (int gameModeIndex = 0; gameModeIndex < gameModesKeys.Count; ++gameModeIndex) { int gameModeId = gameModesKeys[gameModeIndex]; if (Hash.IsNullOrEmpty(gameModeId)) { continue; } tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId); if (gameModeData == null) { continue; } if (!gameModeData.hidden) { IntRange teamSizeRange = gameModeData.onlinePlayersPerTeamRange; int localPartySize; PhotonUtils.TryGetPlayerCustomProperty <int>(PhotonPropertyKey.s_PlayerCustomPropertyKey_LocalPartySize, out localPartySize); bool teamSizeInvalid = (localPartySize >= teamSizeRange.max * 2); if (!teamSizeInvalid) { SelectorItem selectorItem = new SelectorItem(gameModeId, gameModeData.name, "", null); selectorData.AddItem(selectorItem); } } } } if (viewInstance != null) { viewInstance.SetGameModeSelectorData(selectorData); } }
public static bool CheckPropertyOnAllPlayers <T>(object i_Key, T i_Value) { Room room = PhotonNetwork.room; if (room == null) { return(false); } PhotonPlayer[] photonPlayers = PhotonNetwork.playerList; if (photonPlayers != null) { for (int index = 0; index < photonPlayers.Length; ++index) { PhotonPlayer photonPlayer = photonPlayers[index]; if (photonPlayer == null) { continue; } T propertyValue; if (PhotonUtils.TryGetPlayerCustomProperty <T>(photonPlayer, i_Key, out propertyValue)) { if (propertyValue.Equals(i_Value)) { return(false); } } else { return(false); } } } return(true); }
private void WaitForRematch_Update() { if (m_WaitForRematch_Success || m_WaitForRematch_Failed) { return; } if (m_PlayerDisconnectedAfterGameFinished || m_WaitForRematch_Failed) { if (m_WaitForRematch_QuitDialogOpened) { return; } // Set flag. m_WaitForRematch_QuitDialogOpened = true; // Clear all groups. ClearAllGroups(); // Clear Match controller UI. if (m_MatchController != null) { m_MatchController.ClearUI(); } // Open dialog. ShowDialog("MATCH OVER", "You will be returned to the main menu.", On_WaitForRematch_QuitDialogCallback); return; } // Sync time. if (!m_GameFinishedTimeSynced) { UpdateGameFinishedStartTime(); } // Update timer. double time = m_TimeForRematch; double startTime; if (PhotonUtils.TryGetRoomCustomProperty <double>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTime, out startTime)) { m_GameFinishedTimeSynced = true; double elapsedTime = PhotonNetwork.time - startTime; time = m_TimeForRematch - elapsedTime; } time = Math.Max(time, 0.0); if (m_EndGamePanel != null) { m_EndGamePanel.SetTimer((float)time); } // Check rematch. int totalVotes = 0; int rematchVotes = 0; int playerCount = 0; PhotonPlayer[] photonPlayers = PhotonNetwork.playerList; if (photonPlayers != null) { playerCount = photonPlayers.Length; for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Length; ++photonPlayerIndex) { PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex]; if (photonPlayer == null) { continue; } bool voted; PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_RematchVoted_PropertyKey, out voted); if (voted) { ++totalVotes; bool vote; PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_RematchVote_PropertyKey, out vote); rematchVotes += (vote) ? 1 : 0; } } } if (m_EndGamePanel != null) { m_EndGamePanel.SetReadyPlayers(rematchVotes, playerCount); } if (playerCount > 1) { if (rematchVotes == playerCount) { m_WaitForRematch_Success = true; ProceedTo(tnMultiplayerGameState.RestartGame); } else { if (totalVotes == playerCount) { m_WaitForRematch_Failed = true; } } } else { m_WaitForRematch_Failed = true; } }
// Stadium private void SetupStadiumSelector(int i_GameModeId) { SelectorData selectorData = new SelectorData(); List <int> stadiumKeys = tnGameData.GetStadiumsKeysMain(); if (stadiumKeys == null) { return; } tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(i_GameModeId); for (int stadiumIndex = 0; stadiumIndex < stadiumKeys.Count; ++stadiumIndex) { int stadiumId = stadiumKeys[stadiumIndex]; tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId); if (stadiumData == null) { continue; } if (stadiumData.hiddenOnline) { continue; } bool excludedByTag = false; if (gameModeData != null) { for (int excluderTagIndex = 0; excluderTagIndex < gameModeData.fieldsExcludersTagsCount; ++excluderTagIndex) { int excluderTag = gameModeData.GetFieldExcluderTag(excluderTagIndex); if (Hash.IsNullOrEmpty(excluderTag)) { continue; } excludedByTag |= stadiumData.HasTag(excluderTag); } } IntRange teamSizeRange = stadiumData.onlineTeamSize; int localPartySize; PhotonUtils.TryGetPlayerCustomProperty <int>(PhotonNetwork.player, PhotonPropertyKey.s_PlayerCustomPropertyKey_LocalPartySize, out localPartySize); bool teamSizeInvalid = (localPartySize >= teamSizeRange.max * 2); bool locked = excludedByTag || teamSizeInvalid; SelectorItem selectorItem = new SelectorItem(stadiumId, stadiumData.name, stadiumData.description, stadiumData.icon, locked, String.Empty); selectorData.AddItem(selectorItem); } if (viewInstance != null) { viewInstance.SetStadiumSelectorData(selectorData); } SelectFirstUnlockedStadium(); }