using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class RankedSplash : MonoBehaviour { public static RankedSplash instance; public int playerCountRequired; public TMP_Text statusTxt; public GameObject controlsUI; public float startTimer = 60; void Start() { instance = this; statusTxt.text = "Waiting for confirmation"; controlsUI.SetActive(false); } bool allConnected= false; string rules = @"1.Last one standing or the first to collect 30 ores wins! 2.Stay in safe zone to survive 3.Safe-Zone gets shrinked in 5 mins 4.Have fun!"; void FixedUpdate() { SpaceshipController[] players = FindObjectsOfType(); // if(AutoConnect.instance.isClient){return;} if(gameObject.activeSelf){ if(startTimer > 0){ startTimer-= Time.deltaTime; if(startTimer <= 10 && players.Length == 0){ MessageDialog.instance.ShowMessage("Error", "Connection to the server timed out"); LoadingScreen.instance.LoadLevel("GameScene"); startTimer = -100; Feedbacks.Send("Ranked Didn't start", "Couldn't Connect to server", $"Ip:{RegionManager.selectedServer.ip}, Port:{AutoConnect.serverPort}", CustomLogger.Debug.loggedText); } if(startTimer <= 10 && players.Length == 1){ Debug.Log("Timed out"); MinigameManager.instance.EnemyForfeit(); players[0].WonRanked(); startTimer = -100; Feedbacks.Send("Ranked Didn't start", "Opponent didnt connect", $"Ip:{RegionManager.selectedServer.ip}, Port:{AutoConnect.serverPort}", CustomLogger.Debug.loggedText); } }else{ if(SceneData.localPlayer.GetComponent().ready){ MinigameManager.instance.EnemyForfeit(); SceneData.localPlayer.GetComponent().WonRanked(); Feedbacks.Send("Ranked Didn't start", "Opponent didnt connect, I was ready", $"Ip:{RegionManager.selectedServer.ip}, Port:{AutoConnect.serverPort}", CustomLogger.Debug.loggedText); } gameObject.SetActive(false); } } if(players.Length >= playerCountRequired){ if(players.Length >= playerCountRequired && players[0].ready && players[1].ready){ //Start the match! gameObject.SetActive(false); controlsUI.SetActive(true); startTimer = -100; } }else if(players.Length == 0){ statusTxt.text = "Waiting for server\nTimeout in " + (startTimer).ToString("n0") + " seconds"; } if(MinigameManager.instance ==null){return;} if(!MinigameManager.instance.RankedGameStarted){ if(!allConnected && players.Length < playerCountRequired){ statusTxt.text = "Waiting for opponents to connect\nTimeout in " + (startTimer).ToString("n0") + " seconds"; }else{ if(!allConnected){ allConnected = true; MessageDialog.instance.ShowQuestion("Confirm", $"Click yes to confirm you understand the rules below.\n{rules}", OnAgree, ()=>{}, onlyYes:true); // OnAgree(); } if(players.Length > 1 && players[0].ready && players[1].ready){ //Start the match! gameObject.SetActive(false); startTimer = -100; }else{ statusTxt.text = "Waiting for players to get ready\nRemaining " + startTimer.ToString("n0") + " seconds"; } } } } void OnAgree(){ SceneData.localPlayer.GetComponent().SetReady(true); } }