|
@ -31,7 +31,6 @@ public class GameManager : MonoBehaviour |
|
|
|
|
|
|
|
|
#endregion Inspector Field
|
|
|
#endregion Inspector Field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Private Variables
|
|
|
#region Private Variables
|
|
|
private Dictionary<int, PlayerData> playerData; |
|
|
private Dictionary<int, PlayerData> playerData; |
|
|
#endregion Private Variables
|
|
|
#endregion Private Variables
|
|
@ -48,22 +47,12 @@ public class GameManager : MonoBehaviour |
|
|
private GameMode gameMode {get { return CurrentGameMode.Value; } } |
|
|
private GameMode gameMode {get { return CurrentGameMode.Value; } } |
|
|
#endregion Read Only
|
|
|
#endregion Read Only
|
|
|
|
|
|
|
|
|
public GameObject levelInfo; |
|
|
|
|
|
public blockSpawn bspawn; |
|
|
|
|
|
|
|
|
|
|
|
#region Unity Functions
|
|
|
#region Unity Functions
|
|
|
public void Awake() |
|
|
|
|
|
{ |
|
|
|
|
|
RegisterHandlers(); |
|
|
|
|
|
SpawnCharacters(); |
|
|
|
|
|
ClientList.ForEach(p => p.ChangeScene("ClientScene")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void Start() |
|
|
private void Start() |
|
|
{ |
|
|
{ |
|
|
StartCoroutine(displayforSeconds(levelInfo, 5.0f)); |
|
|
|
|
|
gameMode.GameStart(playerDataAsArray.ToArray()); |
|
|
|
|
|
StartRound(); |
|
|
|
|
|
|
|
|
//Start Game
|
|
|
|
|
|
StartCoroutine(GameRoutine()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void Update() |
|
|
private void Update() |
|
@ -73,6 +62,12 @@ public class GameManager : MonoBehaviour |
|
|
server.ServerUpdate(); |
|
|
server.ServerUpdate(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable() |
|
|
|
|
|
{ |
|
|
|
|
|
//Let Server know we want to recieve some messages
|
|
|
|
|
|
RegisterHandlers(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void OnDisable() |
|
|
private void OnDisable() |
|
|
{ |
|
|
{ |
|
|
//Let server know to not send messages this way
|
|
|
//Let server know to not send messages this way
|
|
@ -80,6 +75,7 @@ public class GameManager : MonoBehaviour |
|
|
} |
|
|
} |
|
|
#endregion Unity Functions
|
|
|
#endregion Unity Functions
|
|
|
|
|
|
|
|
|
|
|
|
#region Class Functions
|
|
|
private IEnumerator GameRoutine() |
|
|
private IEnumerator GameRoutine() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
@ -105,33 +101,6 @@ public class GameManager : MonoBehaviour |
|
|
gameMode.GameEnd(playerDataAsArray); |
|
|
gameMode.GameEnd(playerDataAsArray); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator displayforSeconds(GameObject display, float time) |
|
|
|
|
|
{ |
|
|
|
|
|
display.SetActive (true); |
|
|
|
|
|
yield return new WaitForSeconds(time); |
|
|
|
|
|
display.SetActive (false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator WaitForPlayerInput() |
|
|
|
|
|
{ |
|
|
|
|
|
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime()); |
|
|
|
|
|
playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); |
|
|
|
|
|
|
|
|
|
|
|
ClientList.ForEach(p => p.ChangeScene("ClientScene")); |
|
|
|
|
|
|
|
|
|
|
|
gameMode.InputStart(playerDataAsArray); |
|
|
|
|
|
yield return new WaitUntil(() => playerData.All(p => p.Value.recievedList)); |
|
|
|
|
|
|
|
|
|
|
|
//reset
|
|
|
|
|
|
playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gameMode.InputEnd(playerDataAsArray); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator RoundRoutine() |
|
|
private IEnumerator RoundRoutine() |
|
|
{ |
|
|
{ |
|
|
//Tell the gamemode that we are starting a round
|
|
|
//Tell the gamemode that we are starting a round
|
|
@ -147,7 +116,7 @@ public class GameManager : MonoBehaviour |
|
|
yield return StartCoroutine(MoveRoutine(player));//Move Player
|
|
|
yield return StartCoroutine(MoveRoutine(player));//Move Player
|
|
|
gameMode.PlayerMoved(player);//LetGameModeKnow
|
|
|
gameMode.PlayerMoved(player);//LetGameModeKnow
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Let Gamemode know all players have moved
|
|
|
//Let Gamemode know all players have moved
|
|
|
gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); |
|
|
gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); |
|
|
playerDataAsArray.ForEach(p => p.client.SendScore()); //Update the players score
|
|
|
playerDataAsArray.ForEach(p => p.client.SendScore()); //Update the players score
|
|
@ -156,7 +125,7 @@ public class GameManager : MonoBehaviour |
|
|
if (gameMode.isGameOver(playerDataAsArray)) |
|
|
if (gameMode.isGameOver(playerDataAsArray)) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Let GameMode know that Round is Over
|
|
|
//Let GameMode know that Round is Over
|
|
|
gameMode.RoundEnd(playerDataAsArray.ToArray()); |
|
|
gameMode.RoundEnd(playerDataAsArray.ToArray()); |
|
|
|
|
|
|
|
@ -166,7 +135,56 @@ public class GameManager : MonoBehaviour |
|
|
player.blockReader.Reset(); |
|
|
player.blockReader.Reset(); |
|
|
player.client.SendInventory(); |
|
|
player.client.SendInventory(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator WaitForPlayerInput() |
|
|
|
|
|
{ |
|
|
|
|
|
//send round length to players
|
|
|
|
|
|
//#TODO make this only happen after first input
|
|
|
|
|
|
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime()); |
|
|
|
|
|
playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); |
|
|
|
|
|
|
|
|
|
|
|
//Send players to input Scene
|
|
|
|
|
|
ClientList.ForEach(p => p.ChangeScene("ClientScene")); |
|
|
|
|
|
|
|
|
|
|
|
//Let gamemode know clients are input-ing
|
|
|
|
|
|
gameMode.InputStart(playerDataAsArray); |
|
|
|
|
|
|
|
|
|
|
|
//wait for all players to
|
|
|
|
|
|
yield return new WaitUntil(() => playerData.All(p => p.Value.recievedList)); |
|
|
|
|
|
|
|
|
|
|
|
//reset
|
|
|
|
|
|
playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list
|
|
|
|
|
|
|
|
|
|
|
|
//Let gamemode know all inputs have been recieved
|
|
|
|
|
|
gameMode.InputEnd(playerDataAsArray); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator MoveRoutine(PlayerData data) |
|
|
|
|
|
{ |
|
|
|
|
|
bool blockFinished = false; |
|
|
|
|
|
float waitTime; |
|
|
|
|
|
|
|
|
|
|
|
//Loop until the current block indicates or the reader indicates it has finished
|
|
|
|
|
|
while (!blockFinished && !data.blockReader.Finished) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
//If the current block hasn't already been removed, remove it from the player inventory
|
|
|
|
|
|
//We need to check if it has already been removed so loops don't eat an entire stack
|
|
|
|
|
|
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved) |
|
|
|
|
|
{ |
|
|
|
|
|
data.client.Inventory.Remove(data.blockReader.CurrentBlock); |
|
|
|
|
|
data.blockReader.CurrentBlock.hasBeenRemoved = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Process the move
|
|
|
|
|
|
blockFinished = data.blockReader.Read(data.character, AnimationTime, out waitTime); |
|
|
|
|
|
|
|
|
|
|
|
//Wait for the animation to finish
|
|
|
|
|
|
yield return new WaitForSeconds(waitTime); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void SpawnCharacters() |
|
|
private void SpawnCharacters() |
|
@ -195,12 +213,12 @@ public class GameManager : MonoBehaviour |
|
|
Block startingBlock = SpawnBlocks[spawnIndex++]; |
|
|
Block startingBlock = SpawnBlocks[spawnIndex++]; |
|
|
newChar.Initialise(startingBlock, client.Inventory, client.characterAnimal); |
|
|
newChar.Initialise(startingBlock, client.Inventory, client.characterAnimal); |
|
|
newChar.transform.forward = startingBlock.SpawnDirection.ToVector(); |
|
|
newChar.transform.forward = startingBlock.SpawnDirection.ToVector(); |
|
|
playerData.Add(client.ID, new PlayerData(newChar,client)); |
|
|
|
|
|
|
|
|
playerData.Add(client.ID, new PlayerData(newChar, client)); |
|
|
newChar.ClientLink = client; |
|
|
newChar.ClientLink = client; |
|
|
client.playerCharacter = newChar; |
|
|
|
|
|
|
|
|
client.playerCharacter = newChar; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
#endregion Class Functions
|
|
|
|
|
|
|
|
|
#region Networking Functions
|
|
|
#region Networking Functions
|
|
|
|
|
|
|
|
@ -238,39 +256,9 @@ public class GameManager : MonoBehaviour |
|
|
//Update player Data with recieved list
|
|
|
//Update player Data with recieved list
|
|
|
playerData[msg.conn.connectionId].blockReader.LogicChain = new List<LogicBlock>(logicMsg.elements); |
|
|
playerData[msg.conn.connectionId].blockReader.LogicChain = new List<LogicBlock>(logicMsg.elements); |
|
|
playerData[msg.conn.connectionId].recievedList = true; |
|
|
playerData[msg.conn.connectionId].recievedList = true; |
|
|
|
|
|
|
|
|
//if we have recieved all moves start round
|
|
|
|
|
|
if (playerData.All(p => p.Value.recievedList)) |
|
|
|
|
|
DoRoundRoutine(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endregion Networking Functions
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator MoveRoutine(PlayerData data) |
|
|
|
|
|
{ |
|
|
|
|
|
bool blockFinished = false; |
|
|
|
|
|
float waitTime; |
|
|
|
|
|
|
|
|
|
|
|
//Loop until the current block indicates or the reader indicates it has finished
|
|
|
|
|
|
while (!blockFinished && !data.blockReader.Finished) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
//If the current block hasn't already been removed, remove it from the player inventory
|
|
|
|
|
|
//We need to check if it has already been removed so loops don't eat an entire stack
|
|
|
|
|
|
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved) |
|
|
|
|
|
{ |
|
|
|
|
|
data.client.Inventory.Remove(data.blockReader.CurrentBlock); |
|
|
|
|
|
data.blockReader.CurrentBlock.hasBeenRemoved = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Process the move
|
|
|
|
|
|
blockFinished = data.blockReader.Read(data.character, AnimationTime,out waitTime); |
|
|
|
|
|
|
|
|
|
|
|
//Wait for the animation to finish
|
|
|
|
|
|
yield return new WaitForSeconds(waitTime); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#endregion Networking Functions
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public class PlayerData |
|
|
public class PlayerData |
|
|