using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Networking.Server; public abstract class GameMode : ScriptableObject { [SerializeField] [Tooltip("Scene to load which contains Gamemode UI")] private string GameModeScene; [SerializeField] [Tooltip("Round Times are acessed from the top down")] private List RoundTimes; public Action GameStartEvent; public Action RoundStartEvent; public Action AllPlayersMovedEvent; public Action RoundEndEvent; public Action OnGameOverEvent; private List gameTimes; protected abstract void OnGameStart(PlayerData[] allPlayers); /// /// Called at the beginning of a new Round /// protected abstract void OnRoundStart(PlayerData[] allPlayers); /// /// Called for each player after they finished one move. Even if they didn't move! /// /// Character which moved /// Client which controls character /// Block which the character finished on protected abstract void OnPlayerMoved(Character character, ClientData client, Block currentBlock); /// /// Called once after every player has finished one move /// /// List of all player Info protected abstract void OnAllPlayersMoved(PlayerData[] allPlayers); public abstract bool isGameOver(PlayerData[] allPlayers); protected abstract void OnRoundEnd(PlayerData[] allPlayers); protected abstract void OnGameOver(PlayerData[] allPlayers); public float GetRoundTime() { float retVal = gameTimes[0]; if (gameTimes.Count > 1) gameTimes.RemoveAt(0); return retVal; } public void PreGameStart() { } public void GameStart(PlayerData[] allPlayers) { gameTimes = new List(RoundTimes); if (!String.IsNullOrEmpty(GameModeScene)) UnityEngine.SceneManagement.SceneManager.LoadScene(GameModeScene,UnityEngine.SceneManagement.LoadSceneMode.Additive); for(int i = 0; i < allPlayers.Length; i++) { allPlayers[i].client.SceneScore = 0; } OnGameStart(allPlayers); } public void InputStart(PlayerData[] AllPlayers) { } public void InputEnd(PlayerData[] AllPlayers) { } public void RoundStart(PlayerData[] allPlayers) { OnRoundStart(allPlayers); RoundStartEvent?.Invoke(); } public void AllPlayersMoved(PlayerData[] allPlayers) { OnAllPlayersMoved(allPlayers); AllPlayersMovedEvent?.Invoke(); } public void PlayerMoved(PlayerData player) { OnPlayerMoved(player.character, player.client, player.character.CurrentBlock); } public void RoundEnd(PlayerData[] allPlayers) { OnRoundEnd(allPlayers); RoundEndEvent?.Invoke(); } public void GameEnd(PlayerData[] allPlayers) { OnGameOver(allPlayers); OnGameOverEvent?.Invoke(); } } /* --- Calls we need --- * * PreGameSetup(); - //Called once before the game actually starts * GameStart(PlayerData[] AllPlayers); //Called once after players have Spawned * * OnInputStart(PlayerData[] AllPlayers) //Called when players enter input mode * OnRecievedPlayerInput(PlayerData Player) //Called when a specific player has sent their input * OnInputEnd(PlayerData[] AllPlayers) //Called when player input mode has finished * * OnRoundStart(PlayerData[] AllPlayers) //Just before Players start moving * * ------- Start Round Loop ------- * * OnPlayerMoved(PlayerData player) //Called after each player moves * IsGameOver(PlayerData[] AllPlayers) //Called after each player moves * * AllPlayersMoved(PlayerData[] AllPlayers) //Called after all players have moved * EnvironmentTurn() //Also called after all players have moved but should be kept specialised to environment stuff * IsGameOver(PlayerData[] AllPlayers) //We need to check if the environment terminated the game * * --------- End Game Loop --------- * * OnRoundEnd(PlayerData[] AllPlayers) //Called after movements are made * IsGameOver(PlayerData[] AllPlayers) //This needs to be checked again * * GameEnd(PlayerData[] AllPlayers) * * * * * */