From 8bd42e3aa725eb351279e7c870f01ae4668aff41 Mon Sep 17 00:00:00 2001 From: ClairePeta Date: Wed, 28 Aug 2019 13:19:15 +1000 Subject: [PATCH] Character lives displayed inplace of score, removed scenescore as not being used added line so character and client lives update tested with one client --- Assets/Scenes/Client Scenes/ClientScene.unity | 4 +-- .../GameMode/ColorGameMode/ColorGameMode.cs | 6 +---- .../ColorGameMode/RacetrackGameMode.cs | 5 ++-- .../GameMode/ColorGameMode/ScoreDisplay.cs | 4 +-- Assets/Scripts/GameMode/GameMode.cs | 2 +- Assets/Scripts/Managers/GameManager.cs | 3 ++- .../Scripts/Networking/Client/ClientObject.cs | 21 ++++++++++----- .../Core/Protocols/LogicProtocols.cs | 7 ++--- .../Scripts/Networking/Server/ClientList.cs | 18 ++++++------- Assets/Scripts/PortalSetup.cs | 4 +-- Assets/Scripts/UI/LeadPlayerUI.cs | 4 +-- Assets/Scripts/UI/NetworkedUIManager.cs | 10 ++----- Assets/Scripts/blockSpawn.cs | 8 +++--- Assets/Scripts/portalTesting.cs | 27 ------------------- 14 files changed, 47 insertions(+), 76 deletions(-) diff --git a/Assets/Scenes/Client Scenes/ClientScene.unity b/Assets/Scenes/Client Scenes/ClientScene.unity index f1544c3..859ecb9 100644 --- a/Assets/Scenes/Client Scenes/ClientScene.unity +++ b/Assets/Scenes/Client Scenes/ClientScene.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d7258afade2696f1f0e60c62feee99dad86bdbf347b9fc27b33b5adb1fa5343a -size 38163 +oid sha256:84240e58ab2849433e76c59c022a3e864b4001184f0a8159450e06dfeb4bae36 +size 38360 diff --git a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs index 5f71c3c..7a07b56 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs @@ -136,11 +136,6 @@ public class ColorGameMode : GameMode * It's not needed from move to move, so we clear it */ player.character.justMoved = false; - - if (BlocksOwned.ContainsKey(player.client)) - player.client.SceneScore = BlocksOwned[player.client].Count; - else - player.client.SceneScore = 0; } } @@ -179,6 +174,7 @@ public class ColorGameMode : GameMode if (character.inPit) { character.lives -= 1; + character.ClientLink.Lives = character.lives; } Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); diff --git a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs index 274a16b..76a5a13 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs @@ -137,10 +137,10 @@ public class RacetrackGameMode : GameMode */ player.character.justMoved = false; - if (BlocksOwned.ContainsKey(player.client)) + /* if (BlocksOwned.ContainsKey(player.client)) player.client.SceneScore = BlocksOwned[player.client].Count; else - player.client.SceneScore = 0; + player.client.SceneScore = 0;*/ } } @@ -179,6 +179,7 @@ public class RacetrackGameMode : GameMode if (character.inPit) { character.lives -= 1; + character.ClientLink.Lives = character.lives; } Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); diff --git a/Assets/Scripts/GameMode/ColorGameMode/ScoreDisplay.cs b/Assets/Scripts/GameMode/ColorGameMode/ScoreDisplay.cs index 36b017c..e67a75b 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/ScoreDisplay.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/ScoreDisplay.cs @@ -35,12 +35,12 @@ public class ScoreDisplay : MonoBehaviour public void levelComplete() { ConnectedClients = clientDataList.ConnectedClients; - ConnectedClients.Sort((a, b) => b.SceneScore.CompareTo(a.SceneScore)); + ConnectedClients.Sort((a, b) => b.Lives.CompareTo(a.Lives)); for (int i = 0; i < ConnectedClients.Count; i++) { players[i].GetComponent().text = ConnectedClients[i].Name; - scores[i].GetComponent().text = ConnectedClients[i].SceneScore.ToString(); + scores[i].GetComponent().text = ConnectedClients[i].Lives.ToString(); } int assignedPoints = 3; for (int i = 0; i < ConnectedClients.Count; i++) diff --git a/Assets/Scripts/GameMode/GameMode.cs b/Assets/Scripts/GameMode/GameMode.cs index 519a0e4..a8e3902 100644 --- a/Assets/Scripts/GameMode/GameMode.cs +++ b/Assets/Scripts/GameMode/GameMode.cs @@ -117,7 +117,7 @@ public abstract class GameMode : ScriptableObject for (int i = 0; i < allPlayers.Length; i++) { - allPlayers[i].client.SceneScore = 0; + allPlayers[i].client.Lives = 3; } OnGameStart(allPlayers); GameStartEvent?.Invoke(); diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 0fd86d9..bfdd420 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -84,6 +84,7 @@ public class GameManager : MonoBehaviour //Spawn Characters and tell let the GameMode do anything with the characters it might want SpawnCharacters(); + playerDataAsArray.ForEach(p => p.client.SendLives()); gameMode.GameStart(playerDataAsArray); //Loop until the GameMode lets us know the game is over @@ -119,7 +120,7 @@ public class GameManager : MonoBehaviour //Let Gamemode know all players have moved gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); - playerDataAsArray.ForEach(p => p.client.SendScore()); //Update the players score + playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score //if Game is over break out of loop if (gameMode.isGameOver(playerDataAsArray)) diff --git a/Assets/Scripts/Networking/Client/ClientObject.cs b/Assets/Scripts/Networking/Client/ClientObject.cs index 7bd20ad..950d4ec 100644 --- a/Assets/Scripts/Networking/Client/ClientObject.cs +++ b/Assets/Scripts/Networking/Client/ClientObject.cs @@ -49,19 +49,21 @@ namespace Networking.Client [Tooltip("Current Score in Round")] public float RoundScore; + [SerializeField] + [Tooltip("Remaining Lives")] + public float RemainingLives; + [SerializeField] [Tooltip("A list of all connected clients")] public ConnectedClients ConnectedClients; #endregion Inspector Fields - #region ReadOnly Variables public NetworkClient client { get; private set; } public bool isConnected { get { return client != null && client.isConnected; } } #endregion ReadOnly Variables - public void Connect(string serverAddress,int port) { Debug.Log("Connecting to server: " + serverAddress + ", " + port); @@ -81,6 +83,7 @@ namespace Networking.Client client.RegisterHandler(MsgType.Disconnect, OnDisconnect); client.RegisterHandler(LogicProtocols.SendRoundTime, UpdateTime); client.RegisterHandler(LogicProtocols.SendScore, UpdateScore); + client.RegisterHandler(LogicProtocols.SendLives, UpdateLives); } public void Stop() @@ -97,7 +100,6 @@ namespace Networking.Client this.PlayerColor = PlayerColor; } - public void RecieveInventory(NetworkMessage msg) { Debug.Log("Recieving Inventory"); @@ -132,8 +134,7 @@ namespace Networking.Client if (!msg.TryRead(out floatMsg)) return; - RoundTime = floatMsg.Float; - + RoundTime = floatMsg.Float; } public void UpdateScore(NetworkMessage msg) @@ -144,6 +145,14 @@ namespace Networking.Client RoundScore = floatMsg.Float; } - } + public void UpdateLives(NetworkMessage msg) + { + LogicProtocols.FloatMsg floatMsg; + if (!msg.TryRead(out floatMsg)) + return; + + RemainingLives = floatMsg.Float; + } + } } diff --git a/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs b/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs index 20aebe3..b7227ec 100644 --- a/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs +++ b/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs @@ -12,7 +12,8 @@ namespace Networking public const short SendInventory = 201; public const short SendRoundTime = 202; public const short SendNotification = 203; - public const short SendScore = 204; + public const short SendScore = 205; + public const short SendLives = 204; public class LogicMsg : MessageBase @@ -100,10 +101,6 @@ namespace Networking bagItems[i].isInfinit = reader.ReadBoolean(); } } - - - - } public class FloatMsg : MessageBase diff --git a/Assets/Scripts/Networking/Server/ClientList.cs b/Assets/Scripts/Networking/Server/ClientList.cs index cc5d879..3b7a06c 100644 --- a/Assets/Scripts/Networking/Server/ClientList.cs +++ b/Assets/Scripts/Networking/Server/ClientList.cs @@ -157,7 +157,7 @@ namespace Networking.Server newClient.conn.Send(LoginProtocols.LoginSuccess, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal)); OnClientsChange.Invoke(ConnectedClients); newClient.SendInventory(); - newClient.SendScore(); + newClient.SendLives(); newClient.ChangeScene("WaitScene"); @@ -209,15 +209,15 @@ namespace Networking.Server /// public int Score; - /// - /// Clients character animal - needed for instantiation - /// - public string characterAnimal = "Bear"; + /// + /// Clients Current Lives + /// + public int Lives; /// - /// Clients number of collected items - for colelction level + /// Clients character animal - needed for instantiation /// - public int SceneScore = 0; + public string characterAnimal = "Bear"; /// /// Network connection ID @@ -242,9 +242,9 @@ namespace Networking.Server conn.SendByChannel(LogicProtocols.SendInventory, new LogicProtocols.InventoryMsg(Inventory), TransportConfigure.ReliableFragmented); } - public void SendScore() + public void SendLives() { - conn.Send(LogicProtocols.SendScore, new LogicProtocols.FloatMsg(SceneScore)); + conn.Send(LogicProtocols.SendLives, new LogicProtocols.FloatMsg(Lives)); } public void ChangeScene(string scene, bool Additive = false) diff --git a/Assets/Scripts/PortalSetup.cs b/Assets/Scripts/PortalSetup.cs index 6219927..7e8b78b 100644 --- a/Assets/Scripts/PortalSetup.cs +++ b/Assets/Scripts/PortalSetup.cs @@ -51,10 +51,10 @@ public class PortalSetup : MonoBehaviour void Update() { - if (!collectedFive && (ConnectedClients[0].SceneScore >= collectAmount || ConnectedClients[1].SceneScore >= collectAmount || ConnectedClients[2].SceneScore >= collectAmount || ConnectedClients[3].SceneScore >= collectAmount)){ + /*if (!collectedFive && (ConnectedClients[0].SceneScore >= collectAmount || ConnectedClients[1].SceneScore >= collectAmount || ConnectedClients[2].SceneScore >= collectAmount || ConnectedClients[3].SceneScore >= collectAmount)){ collectedFive = true; StartCoroutine (ColorChange ()); - } + }*/ } private void Awake () diff --git a/Assets/Scripts/UI/LeadPlayerUI.cs b/Assets/Scripts/UI/LeadPlayerUI.cs index 713f9f2..a3a134a 100644 --- a/Assets/Scripts/UI/LeadPlayerUI.cs +++ b/Assets/Scripts/UI/LeadPlayerUI.cs @@ -35,8 +35,8 @@ public class LeadPlayerUI : MonoBehaviour ColorImage.gameObject.SetActive(true); } - ClientData lead = Clients.maxBy(p => p.SceneScore); - ScoreText.text = lead.SceneScore.ToString(); + ClientData lead = Clients.maxBy(p => p.Lives); + ScoreText.text = lead.Lives.ToString(); ColorImage.color = lead.Color; } diff --git a/Assets/Scripts/UI/NetworkedUIManager.cs b/Assets/Scripts/UI/NetworkedUIManager.cs index 22bfc49..8ab447d 100644 --- a/Assets/Scripts/UI/NetworkedUIManager.cs +++ b/Assets/Scripts/UI/NetworkedUIManager.cs @@ -14,7 +14,7 @@ public class NetworkedUIManager : PlayerUIManager [SerializeField] private RectTransform Title; [SerializeField] - private TMPro.TextMeshProUGUI ScoreText; + private TMPro.TextMeshProUGUI LivesText; [Header("Debug")] [SerializeField] @@ -31,12 +31,10 @@ public class NetworkedUIManager : PlayerUIManager TrayUI.SetBlockReader(reader); StartTime = Time.time; ShowPosition.y -= Title.rect.height; - ScoreText.text = "Score: " + Client.RoundScore; + LivesText.text = "Lives: " + Client.RemainingLives; OnClick_Show(); } - - private void Update() { if (!isTimePaused) @@ -67,8 +65,4 @@ public class NetworkedUIManager : PlayerUIManager else TimeText.color = Color.black; } - - - - } diff --git a/Assets/Scripts/blockSpawn.cs b/Assets/Scripts/blockSpawn.cs index c5a4890..6556d01 100644 --- a/Assets/Scripts/blockSpawn.cs +++ b/Assets/Scripts/blockSpawn.cs @@ -37,14 +37,14 @@ public class blockSpawn : MonoBehaviour private void getPlayerScores() { - ConnectedClients.Sort((b, a) => a.SceneScore.CompareTo(b.SceneScore)); + ConnectedClients.Sort((b, a) => a.Lives.CompareTo(b.Lives)); int totalScores = 0; - scoreDifference = ConnectedClients[0].SceneScore + ConnectedClients[ConnectedClients.Count-1].SceneScore; + scoreDifference = ConnectedClients[0].Lives + ConnectedClients[ConnectedClients.Count-1].Lives; //Debug.Log("score difference " + scoreDifference); for(int i = 0; i < ConnectedClients.Count; i++) { - totalScores += ConnectedClients[i].SceneScore; + totalScores += ConnectedClients[i].Lives; } average = totalScores / ConnectedClients.Count; //Debug.Log("score average " + average); @@ -140,7 +140,7 @@ public class blockSpawn : MonoBehaviour float[] difAvg = new float[clients.Length]; for (int i = 0; i < clients.Length; i++) { - difAvg[i] = clients[i].SceneScore - average; + difAvg[i] = clients[i].Lives - average; } float[] ratio = new float[clients.Length]; diff --git a/Assets/Scripts/portalTesting.cs b/Assets/Scripts/portalTesting.cs index cfe6879..ec99cb6 100644 --- a/Assets/Scripts/portalTesting.cs +++ b/Assets/Scripts/portalTesting.cs @@ -18,33 +18,6 @@ public class portalTesting : MonoBehaviour // Update is called once per frame void Update() { - if(Input.GetKeyDown(KeyCode.A)){ - ConnectedClients[0].SceneScore++; - if(ConnectedClients[0].SceneScore >= 5){ - ps.validIndex.Add(0); - } - } - if(Input.GetKeyDown(KeyCode.B)){ - ConnectedClients[1].SceneScore++; - if(ConnectedClients[1].SceneScore >= 5){ - ps.validIndex.Add(1); - } - } - if(Input.GetKeyDown(KeyCode.C)){ - ConnectedClients[2].SceneScore++; - if(ConnectedClients[2].SceneScore >= 5){ - ps.validIndex.Add(2); - } - } - if(Input.GetKeyDown(KeyCode.D)){ - ConnectedClients[3].SceneScore++; - if(ConnectedClients[3].SceneScore >= 5){ - ps.validIndex.Add(3); - } - } - - - }