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<float> RoundTimes;
|
|
|
|
public Action GameStartEvent;
|
|
public Action RoundStartEvent;
|
|
public Action AllPlayersMovedEvent;
|
|
public Action RoundEndEvent;
|
|
public Action OnGameOverEvent;
|
|
|
|
private List<float> gameTimes;
|
|
|
|
|
|
protected abstract void OnGameStart(PlayerData[] allPlayers);
|
|
|
|
/// <summary>
|
|
/// Called at the beginning of a new Round
|
|
/// </summary>
|
|
protected abstract void OnRoundStart(PlayerData[] allPlayers);
|
|
|
|
/// <summary>
|
|
/// Called for each player after they finished one move. Even if they didn't move!
|
|
/// </summary>
|
|
/// <param name="character">Character which moved</param>
|
|
/// <param name="client">Client which controls character</param>
|
|
/// <param name="currentBlock">Block which the character finished on</param>
|
|
protected abstract void OnPlayerMoved(Character character, ClientData client, Block currentBlock);
|
|
|
|
/// <summary>
|
|
/// Called once after every player has finished one move
|
|
/// </summary>
|
|
/// <param name="allCharacters">List of all player Info</param>
|
|
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<float>(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)
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|