You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.4 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Networking.Server;
  6. public abstract class GameMode : ScriptableObject
  7. {
  8. [SerializeField]
  9. [Tooltip("Scene to load which contains Gamemode UI")]
  10. private string GameModeScene;
  11. [SerializeField]
  12. [Tooltip("Round Times are acessed from the top down")]
  13. private List<float> RoundTimes;
  14. public Action GameStartEvent;
  15. public Action RoundStartEvent;
  16. public Action AllPlayersMovedEvent;
  17. public Action RoundEndEvent;
  18. public Action OnGameOverEvent;
  19. private List<float> gameTimes;
  20. protected abstract void OnGameStart(PlayerData[] allPlayers);
  21. /// <summary>
  22. /// Called at the beginning of a new Round
  23. /// </summary>
  24. protected abstract void OnRoundStart(PlayerData[] allPlayers);
  25. /// <summary>
  26. /// Called for each player after they finished one move. Even if they didn't move!
  27. /// </summary>
  28. /// <param name="character">Character which moved</param>
  29. /// <param name="client">Client which controls character</param>
  30. /// <param name="currentBlock">Block which the character finished on</param>
  31. protected abstract void OnPlayerMoved(Character character, ClientData client, Block currentBlock);
  32. /// <summary>
  33. /// Called once after every player has finished one move
  34. /// </summary>
  35. /// <param name="allCharacters">List of all player Info</param>
  36. protected abstract void OnAllPlayersMoved(PlayerData[] allPlayers);
  37. public abstract bool isGameOver(PlayerData[] allPlayers);
  38. protected abstract void OnRoundEnd(PlayerData[] allPlayers);
  39. protected abstract void OnGameOver(PlayerData[] allPlayers);
  40. public float GetRoundTime()
  41. {
  42. float retVal = gameTimes[0];
  43. if (gameTimes.Count > 1)
  44. gameTimes.RemoveAt(0);
  45. return retVal;
  46. }
  47. public void PreGameStart()
  48. {
  49. }
  50. public void GameStart(PlayerData[] allPlayers)
  51. {
  52. gameTimes = new List<float>(RoundTimes);
  53. if (!String.IsNullOrEmpty(GameModeScene))
  54. UnityEngine.SceneManagement.SceneManager.LoadScene(GameModeScene,UnityEngine.SceneManagement.LoadSceneMode.Additive);
  55. for(int i = 0; i < allPlayers.Length; i++)
  56. {
  57. allPlayers[i].client.SceneScore = 0;
  58. }
  59. OnGameStart(allPlayers);
  60. }
  61. public void InputStart(PlayerData[] AllPlayers)
  62. {
  63. }
  64. public void InputEnd(PlayerData[] AllPlayers)
  65. {
  66. }
  67. public void RoundStart(PlayerData[] allPlayers)
  68. {
  69. OnRoundStart(allPlayers);
  70. RoundStartEvent?.Invoke();
  71. }
  72. public void AllPlayersMoved(PlayerData[] allPlayers)
  73. {
  74. OnAllPlayersMoved(allPlayers);
  75. AllPlayersMovedEvent?.Invoke();
  76. }
  77. public void PlayerMoved(PlayerData player)
  78. {
  79. OnPlayerMoved(player.character, player.client, player.character.CurrentBlock);
  80. }
  81. public void RoundEnd(PlayerData[] allPlayers)
  82. {
  83. OnRoundEnd(allPlayers);
  84. RoundEndEvent?.Invoke();
  85. }
  86. public void GameEnd(PlayerData[] allPlayers)
  87. {
  88. OnGameOver(allPlayers);
  89. OnGameOverEvent?.Invoke();
  90. }
  91. }
  92. /* --- Calls we need ---
  93. *
  94. * PreGameSetup(); - //Called once before the game actually starts
  95. * GameStart(PlayerData[] AllPlayers); //Called once after players have Spawned
  96. *
  97. * OnInputStart(PlayerData[] AllPlayers) //Called when players enter input mode
  98. * OnRecievedPlayerInput(PlayerData Player) //Called when a specific player has sent their input
  99. * OnInputEnd(PlayerData[] AllPlayers) //Called when player input mode has finished
  100. *
  101. * OnRoundStart(PlayerData[] AllPlayers) //Just before Players start moving
  102. *
  103. * ------- Start Round Loop -------
  104. *
  105. * OnPlayerMoved(PlayerData player) //Called after each player moves
  106. * IsGameOver(PlayerData[] AllPlayers) //Called after each player moves
  107. *
  108. * AllPlayersMoved(PlayerData[] AllPlayers) //Called after all players have moved
  109. * EnvironmentTurn() //Also called after all players have moved but should be kept specialised to environment stuff
  110. * IsGameOver(PlayerData[] AllPlayers) //We need to check if the environment terminated the game
  111. *
  112. * --------- End Game Loop ---------
  113. *
  114. * OnRoundEnd(PlayerData[] AllPlayers) //Called after movements are made
  115. * IsGameOver(PlayerData[] AllPlayers) //This needs to be checked again
  116. *
  117. * GameEnd(PlayerData[] AllPlayers)
  118. *
  119. *
  120. *
  121. *
  122. *
  123. */