// Send a list of the end-game rankings to the player. private void sendRankingsMessage(int id) { RankingsMessage message = new RankingsMessage(); // Sort/rank players by score. List <Player> rankings = new List <Player>(); foreach (var player in this._players) { //player.Value.score = 0; //player.Value.score += ((7 - player.Value.placement) * 1000); player.Value.score = (((this._players.Count + 1) - player.Value.placement) * 1000); player.Value.score += (player.Value.kills * 600); rankings.Add(player.Value); } rankings.Sort((p1, p2) => p2.score.CompareTo(p1.score)); // NB! Since we can't send dictionaries as network messages, we must send it as an array. message.rankings = new Player[rankings.Count]; for (int i = 0; i < rankings.Count; i++) { message.rankings[i] = new Player(); message.rankings[i].id = rankings[i].id; message.rankings[i].name = rankings[i].name; message.rankings[i].animal = rankings[i].animal; message.rankings[i].isDead = rankings[i].isDead; message.rankings[i].rank = (i + 1); message.rankings[i].kills = rankings[i].kills; message.rankings[i].score = rankings[i].score; message.rankings[i].win = rankings[i].win; // Only send the scores once from the server. if (id == NetworkServer.serverHostId) { Leaderboard.SaveScore(rankings[i].name, (double)rankings[i].score); } } if (id == NetworkServer.serverHostId) { Leaderboard.SaveStats(this._models[rankings[0].animal]); // DEBUG: Print stats to console for (int i = 0; i < this._models.Length; i++) { Leaderboard.GetStats(this._models[i]); } } NetworkServer.SendToClient(id, (short)NetworkMessageType.MSG_RANKINGS, message); }
// Update the game rankings. private void updateRankings(RankingsMessage message) { if (this.isServer) { this.RpcUpdateRankings(message); } else if (this.isClient) { this.CmdUpdateRankings(message); } }
// Show a list of all the player rankings and stats. private void showRankings(RankingsMessage message) { if (!this.isLocalPlayer || (this._gameOverText == null) || this._ranked) { return; } if (GameInfo.gamemode == "Deathmatch") { this._gameOverText.color = new Color(this._gameOverText.color.r, this._gameOverText.color.g, this._gameOverText.color.b, 1.0f); this._gameOverText.text = ""; } this._ranked = true; this._gameOverText.text += "\nRank\tKills\t\tScore\tName\n"; this._gameOverText.text += "---------------------------------------"; foreach (Player player in message.rankings) { this._gameOverText.text += string.Format("\n#{0}\t\t{1}\t\t\t{2}\t{3}", player.rank, player.kills, player.score, player.name); } StartCoroutine(this.gameOverTimer(15)); }
private void CmdUpdateRankings(RankingsMessage message) { this.RpcUpdateRankings(message); }
private void RpcUpdateRankings(RankingsMessage message) { this.showRankings(message); }