/// <summary> /// Sorts the scores. /// </summary> void SortScores() { int currentPlace = 1; int currentPlayerCount = scoringTable.Count; scoresThisRound = currentPlayerCount; foreach (ScoringInformation playerScore in scoringTable.Values) { if (playerScore.score > 99) AchievementChecker("99Percent"); foreach (ScoringInformation rivalScore in scoringTable.Values) { if (playerScore == rivalScore) continue; if (playerScore.score == rivalScore.score) { float chance = UnityEngine.Random.Range(-0.001f, 0.001f); playerScore.score += chance; } if (playerScore.score < rivalScore.score) currentPlace++; } playerScore.place = currentPlace; currentScores[playerScore.place - 1] = playerScore; if (playerScore.place < 1) AchievementChecker("25Losses"); // For Sending RPC to other players scoreArraySorted[currentPlace - 1] = playerScore.score; keyArraySorted[currentPlace - 1] = playerScore.name + playerScore.ID.ToString(); sortedIDs[currentPlace - 1] = playerScore.ID; currentPlace = 1; } if (currentPlayerCount < 4) { for (int i = currentPlayerCount; i < 4; i++) { currentScores[i] = new ScoringInformation(); sortedIDs[i] = -1; } } Debug.Log("Sending SendScoreList"); photonView.RPC("SendScoreList", PhotonTargets.All, scoreArraySorted, keyArraySorted); }
void OnEnable() { // TODO: Should I have put this as scoringTable.add? i don't think so. for (int i = 0; i < 4; i++) { currentScores.Add(new ScoringInformation()); } currentState = PlayingState.SYNCING; ScoringInformation myInformation = new ScoringInformation(); myInformation.name = PhotonNetwork.player.name; myInformation.ID = PhotonNetwork.player.ID; myInformation.player = PhotonNetwork.player; string myKey = myInformation.name + myInformation.ID.ToString(); scoringTable.Add(myKey, myInformation); sorted = true; ResetLabels(); }
void SendScoreToHost(float inScore, int playerID, string playerName) { Debug.Log("SendScoreToHost"); string key = playerName + playerID.ToString(); ScoringInformation info = null; // Adds new info if player doesn't exist in score yet. if(!scoringTable.TryGetValue(key, out info)) { CleanTable(); info = new ScoringInformation(); info.name = playerName; info.ID = playerID; info.score = 0; info.place = 5; foreach (PhotonPlayer p in PhotonNetwork.playerList) { if (p.ID == playerID) info.player = p; } scoringTable.Add(key, info); photonView.RPC("NewScoreInformation", PhotonTargets.Others, key, playerID); Debug.Log("Sending NewScoreInformation - SendScoreToHost"); } info.score = inScore; }
void NewScoreInformation(string key, int ID) { Debug.Log("NewScoreInformation"); if (ID == PhotonNetwork.player.ID) return; ScoringInformation info = new ScoringInformation(); CleanTable(); info = new ScoringInformation(); foreach (PhotonPlayer p in PhotonNetwork.playerList) { if (p.ID == ID) { info.name = p.name; info.player = p; } } info.ID = ID; info.score = 0; info.place = 5; Debug.Log("Adding " + key + " to table"); scoringTable.Add(key, info); }