public void UpdatePing(int id, String newPing) { //print("updating scores " + id + " " + diffKills); int foundPlayerIndex = FindPlayerIndex(id); if (foundPlayerIndex != -1) { ScoreboardPlayer foundPlayer = scores.GetItem(foundPlayerIndex); foundPlayer.ping = newPing; scores[foundPlayerIndex] = foundPlayer; } }
private IEnumerator GameOver(ScoreboardPlayer winner) { if (gameIsOver == false) { gameIsOver = true; Time.timeScale = 0.25f; text_Header.SetText("winner!"); text_Subheader.textColor = characterSettings.Single(c => c.characterName == winner.player.spriteAnimator.runtimeAnimatorController.name).color; text_Subheader.SetText(winner.player.playerName.ToLower() + "!"); yield return(new WaitForSeconds(2f)); Time.timeScale = 1f; StartCoroutine(StartGame()); } }
public void RemovePlayer(int id) { // Called when player disconnects under any circumstances ScoreboardPlayer findResult = scores.Find(id); print("removing player: " + findResult.name); bool removeResult = scores.Remove(findResult); if (removeResult) { RpcRefreshScoreboard(); } else { print("Could not find player to disconnect, sorry"); } }
public void UpdateScore(int id, int diffKills, int diffAssists, int diffDeaths) { //print("updating scores " + id + " " + diffKills); // TODO update ping on a timer, not just through here string ping = getPing(id); int foundPlayerIndex = FindPlayerIndex(id); if (foundPlayerIndex != -1) { ScoreboardPlayer foundPlayer = scores.GetItem(foundPlayerIndex); foundPlayer.kills += diffKills; foundPlayer.assists += diffAssists; foundPlayer.deaths += diffDeaths; foundPlayer.ping = ping; scores [foundPlayerIndex] = foundPlayer; } }
int IComparer.Compare(object a, object b) { ScoreboardPlayer sa = (ScoreboardPlayer)a; ScoreboardPlayer sb = (ScoreboardPlayer)b; if (sa.kills > sb.kills) { return(-1); } else if (sa.kills < sb.kills) { return(1); } else { // Equals, use assists if (sa.assists > sb.assists) { return(-1); } else if (sa.assists < sb.assists) { return(1); } else { // Equals, use min deaths if (sa.deaths < sb.deaths) { return(-1); } else if (sa.deaths > sb.deaths) { return(1); } else { // Well that's a draw return(0); } } } }
public void OnPlayerDied(PlayerController playerKilled, PlayerController playerKiller, GameObject newCorpse) { // Add the new corpse if (corpses.Count == gameSettings.corpseMax && gameSettings.corpseMax != 0) { Destroy(corpses[0]); corpses.RemoveAt(0); } corpses.Add(newCorpse); ScoreboardPlayer scoreboardPlayerKiller = (playerKiller == null ? null : scoreboard.Single(p => p.player == playerKiller)); ScoreboardPlayer scoreboardPlayerKilled = scoreboard.Single(p => p.player == playerKilled); if (playerKiller == null) { scoreboardPlayerKilled.suicides += 1; } else { scoreboardPlayerKiller.kills += 1; if (gameModeCurrent.playerSettings.lifeStealing == true) { scoreboardPlayerKiller.lives = (int)Mathf.Clamp(scoreboardPlayerKiller.lives + 1, 0, (gameModeCurrent.playerSettings.livesMax != 0 ? gameModeCurrent.playerSettings.livesMax : Mathf.Infinity)); DisplayLives(playerKiller, 1); } } scoreboardPlayerKilled.deaths += 1; scoreboardPlayerKilled.lives = (int)Mathf.Clamp(scoreboardPlayerKilled.lives - 1, 0, Mathf.Infinity); DisplayLives(playerKilled, -1); if (scoreboardPlayerKilled.lives > 0 || gameModeCurrent.playerSettings.livesStarting == 0) { StartCoroutine(RespawnPlayer(playerKilled, gameModeCurrent.playerSettings.respawnTime)); } CheckForGameOver(); }
public void DisplayLives(PlayerController player, int livesIncrement) { if (player.transform.Find("(DynamicMovingText)")) { Destroy(player.transform.Find("(DynamicMovingText)").gameObject); } Vector2 textOffset = new Vector2(0, 0.5f); GameObject newDynamicMovingText = (GameObject)Instantiate(prefab_DynamicMovingText, player.transform.position + (Vector3)textOffset, Quaternion.identity, player.transform); ScoreboardPlayer playerScoreboard = GetPlayerScoreboardInformation(player); newDynamicMovingText.name = "(DynamicMovingText)"; if (livesIncrement == -1) { newDynamicMovingText.GetComponent <DynamicMovingText>().Construct(new string[] { (playerScoreboard.lives + -livesIncrement).ToString(), playerScoreboard.lives.ToString() }, player.transform, new Vector2(0, 1f), characterSettings[player.characterIndex].color); } else { newDynamicMovingText.GetComponent <DynamicMovingText>().Construct(new string[] { (playerScoreboard.lives + -livesIncrement).ToString(), playerScoreboard.lives.ToString() }, player.transform, new Vector2(0, 1f), characterSettings[player.characterIndex].color); } }
// Update is called once per frame void Update() { for (int i = 0; i < Network.connections.Length; i++) { //print("Player " + i + " " + Network.GetAveragePing(Network.connections[i])); } if (!isServer) { return; // All scoreboard processing is handled server side } foreach (PlayerInput p in GameObject.FindObjectsOfType <PlayerInput>()) { if (p.GetPlayerId() == 0) { // Unassigned, we can't do anything here continue; } int foundIndex = FindPlayerIndex(p.GetPlayerId()); PlayerStats ps = p.GetComponent <PlayerStats>(); if (p.gameObject.tag != "Player") { Debug.LogWarning("The player added to the scoreboard does not have the 'Player' tag. Please assign this tag."); } if (foundIndex != -1) { ScoreboardPlayer foundPlayer = scores.GetItem(foundIndex); foundPlayer.name = ps.gameObject.name; foundPlayer.teamIndex = ps.teamIndex; scores[foundIndex] = foundPlayer; } else { print("Adding player with id " + p.GetPlayerId()); scores.Add(new ScoreboardPlayer { name = ps.gameObject.name, teamIndex = ps.teamIndex, classId = ps.classIndex, kills = 0, deaths = 0, assists = 0, id = p.GetPlayerId(), ping = getPing(p.GetPlayerId()), found = true }); } } // If any have not been checked, then kill and try again // TODO OMG F*****G KILL ME bool refresh = false; foreach (ScoreboardItem items in parentGroup.GetComponentsInChildren <ScoreboardItem>()) { if (items.referredItem == null) { scores.Remove(scores.Find(items.id)); refresh = true; } } if (refresh) { RpcRefreshScoreboard(); } }
private void RefreshScoreboard() { ScoreboardPlayer[] tmp = scores.ToArray(); Array.Sort(tmp, (IComparer) new SyncListScoreboardPlayer.ScoreboardPlayerComparer()); // Sort, then put up //foreach (ScoreboardPlayer scoreboardPlayer in tmp) for (int i = 0; i < scores.Count; i++) { ScoreboardPlayer scoreboardPlayer = tmp[i]; Transform foundItem; if ((foundItem = parentGroup.Find(scoreboardPlayer.id.ToString())) == null) { // Make a new UI item foundItem = GameObject.Instantiate(scoreboardItemPrefab, parentGroup).transform; } // Update foundItem.SetSiblingIndex(i); ScoreboardItem scoreboardItem = foundItem.GetComponent <ScoreboardItem>(); scoreboardItem.gameObject.name = scoreboardPlayer.id.ToString(); scoreboardItem.nameText.text = scoreboardPlayer.name; scoreboardItem.score.text = scoreboardPlayer.kills.ToString(); scoreboardItem.assists.text = scoreboardPlayer.assists.ToString(); scoreboardItem.deaths.text = scoreboardPlayer.deaths.ToString(); scoreboardItem.ping.text = scoreboardPlayer.ping; scoreboardItem.id = scoreboardPlayer.id; scoreboardItem.classIcon.sprite = classSpritePrefabHolder[scoreboardPlayer.classId]; Color teamColor = Color.white; // All players are added, including spectators, who are not colored foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player")) { //print(player.name + " " + player.GetComponent<NetworkBehaviour>().isLocalPlayer); BasePlayer basePlayer = player.GetComponent <BasePlayer>(); int playerId = basePlayer.GetComponent <PlayerInput>().GetPlayerId(); if (playerId == scoreboardPlayer.id) { scoreboardItem.referredItem = player; teamColor = basePlayer.GetComponent <PlayerStats>().teamColor; if (player.GetComponent <NetworkBehaviour>().isLocalPlayer) { // Is the local player scoreboardItem.nameText.fontStyle = FontStyle.Bold; // TODO make it a different color, better scoreboardItem.nameText.color = Color.black; } } } foreach (Image image in scoreboardItem.teamImages) { image.color = teamColor; } } foreach (ScoreboardItem scoreboardItem in parentGroup.GetComponentsInChildren <ScoreboardItem>()) { if (!scores.Find(scoreboardItem.id).found || (scoreboardItem.referredItem != null && !scoreboardItem.referredItem.activeInHierarchy)) { // Delete if not found GameObject.Destroy(scoreboardItem.gameObject); } } //print ("Score synclist size: " + scores.Count); }