|
|
@ -31,7 +31,6 @@ public class GameManager : MonoBehaviour |
|
|
|
|
|
|
|
#endregion Inspector Field
|
|
|
|
|
|
|
|
|
|
|
|
#region Private Variables
|
|
|
|
private Dictionary<int, PlayerData> playerData; |
|
|
|
#endregion Private Variables
|
|
|
@ -48,22 +47,12 @@ public class GameManager : MonoBehaviour |
|
|
|
private GameMode gameMode {get { return CurrentGameMode.Value; } } |
|
|
|
#endregion Read Only
|
|
|
|
|
|
|
|
public GameObject levelInfo; |
|
|
|
public blockSpawn bspawn; |
|
|
|
|
|
|
|
#region Unity Functions
|
|
|
|
public void Awake() |
|
|
|
{ |
|
|
|
RegisterHandlers(); |
|
|
|
SpawnCharacters(); |
|
|
|
ClientList.ForEach(p => p.ChangeScene("ClientScene")); |
|
|
|
} |
|
|
|
|
|
|
|
private void Start() |
|
|
|
{ |
|
|
|
StartCoroutine(displayforSeconds(levelInfo, 5.0f)); |
|
|
|
gameMode.GameStart(playerDataAsArray.ToArray()); |
|
|
|
StartRound(); |
|
|
|
//Start Game
|
|
|
|
StartCoroutine(GameRoutine()); |
|
|
|
} |
|
|
|
|
|
|
|
private void Update() |
|
|
@ -73,6 +62,12 @@ public class GameManager : MonoBehaviour |
|
|
|
server.ServerUpdate(); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnEnable() |
|
|
|
{ |
|
|
|
//Let Server know we want to recieve some messages
|
|
|
|
RegisterHandlers(); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnDisable() |
|
|
|
{ |
|
|
|
//Let server know to not send messages this way
|
|
|
@ -80,6 +75,7 @@ public class GameManager : MonoBehaviour |
|
|
|
} |
|
|
|
#endregion Unity Functions
|
|
|
|
|
|
|
|
#region Class Functions
|
|
|
|
private IEnumerator GameRoutine() |
|
|
|
{ |
|
|
|
|
|
|
@ -105,33 +101,6 @@ public class GameManager : MonoBehaviour |
|
|
|
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() |
|
|
|
{ |
|
|
|
//Tell the gamemode that we are starting a round
|
|
|
@ -147,7 +116,7 @@ public class GameManager : MonoBehaviour |
|
|
|
yield return StartCoroutine(MoveRoutine(player));//Move Player
|
|
|
|
gameMode.PlayerMoved(player);//LetGameModeKnow
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Let Gamemode know all players have moved
|
|
|
|
gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); |
|
|
|
playerDataAsArray.ForEach(p => p.client.SendScore()); //Update the players score
|
|
|
@ -156,7 +125,7 @@ public class GameManager : MonoBehaviour |
|
|
|
if (gameMode.isGameOver(playerDataAsArray)) |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Let GameMode know that Round is Over
|
|
|
|
gameMode.RoundEnd(playerDataAsArray.ToArray()); |
|
|
|
|
|
|
@ -166,7 +135,56 @@ public class GameManager : MonoBehaviour |
|
|
|
player.blockReader.Reset(); |
|
|
|
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() |
|
|
@ -195,12 +213,12 @@ public class GameManager : MonoBehaviour |
|
|
|
Block startingBlock = SpawnBlocks[spawnIndex++]; |
|
|
|
newChar.Initialise(startingBlock, client.Inventory, client.characterAnimal); |
|
|
|
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; |
|
|
|
client.playerCharacter = newChar; |
|
|
|
client.playerCharacter = newChar; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion Class Functions
|
|
|
|
|
|
|
|
#region Networking Functions
|
|
|
|
|
|
|
@ -238,39 +256,9 @@ public class GameManager : MonoBehaviour |
|
|
|
//Update player Data with recieved list
|
|
|
|
playerData[msg.conn.connectionId].blockReader.LogicChain = new List<LogicBlock>(logicMsg.elements); |
|
|
|
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 |
|
|
|