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;
public Action RoundStartEvent;
public Action AllPlayersMovedEvent;
public Action RoundEndEvent;
public Action OnGameOverEvent;
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 OnPlayerFinishedMove(Character character, ClientData client, Block currentBlock);
///
/// Called once after every player has finished one move
///
/// List of all player Info
protected abstract void OnAllPlayersFinishedMove(PlayerData[] allPlayers);
public abstract bool isGameOver(PlayerData[] allPlayers);
protected abstract void OnRoundEnd(PlayerData[] allPlayers);
protected abstract void OnGameOver(PlayerData[] allPlayers);
public void GameStart(PlayerData[] allPlayers)
{
if (!String.IsNullOrEmpty(GameModeScene))
UnityEngine.SceneManagement.SceneManager.LoadScene(GameModeScene,UnityEngine.SceneManagement.LoadSceneMode.Additive);
OnGameStart(allPlayers);
}
public void RoundStart(PlayerData[] allPlayers)
{
OnRoundStart(allPlayers);
RoundStartEvent?.Invoke();
}
public void FinishedMove(PlayerData[] allPlayers)
{
foreach (PlayerData player in allPlayers)
OnPlayerFinishedMove(player.character, player.client, player.character.CurrentBlock);
OnAllPlayersFinishedMove(allPlayers);
AllPlayersMovedEvent?.Invoke();
}
public void RoundEnd(PlayerData[] allPlayers)
{
OnRoundEnd(allPlayers);
RoundEndEvent?.Invoke();
}
public void GameOver(PlayerData[] allPlayers)
{
OnGameOver(allPlayers);
OnGameOverEvent?.Invoke();
}
}