private void EvaluateRoundWinner(List <PlayerController> roundWinners)
    {
        PlayerController matchWinner = null;

        foreach (PlayerController controller in roundWinners)
        {
            GameState.PlayerMatchStatistics matchStats = Overseer.Instance.PlayerMatchStats[controller.PlayerIndex];
            matchStats.RoundsWon += 1;
            Overseer.Instance.PlayerMatchStats[controller.PlayerIndex] = matchStats;

            if (matchStats.RoundsWon >= Mathf.RoundToInt(RoundCountLimit / 2f))
            {
                if (matchWinner != null)
                {
                    // If we've already declared a winner, the game is a draw since both players have the needed number of wins
                    Overseer.Instance.OnMatchEnd(null);
                    return;
                }
                else
                {
                    matchWinner = controller;
                }
            }
        }

        if (matchWinner != null)
        {
            matchWinner.CharacterStats.OnRoundEnd(true);
            Overseer.Instance.OnMatchEnd(matchWinner);
        }
        else if (RoundCount >= RoundCountLimit)
        {
            Overseer.Instance.OnMatchEnd(null);
        }
        else
        {
            Overseer.Instance.OnRoundEnd(roundWinners);
        }
    }
示例#2
0
    private void CreatePlayerController(int playerIndex, PlayerController.PlayerType playerType)
    {
        GameObject associatedPlayer = PlayerObjects[playerIndex];

        if (associatedPlayer == null)
        {
            Debug.LogWarning("The Associated Player is null. Perhaps no characters were added to the game");
            return;
        }
        GameObject       playerControllerGameObject = new GameObject();
        PlayerController playerController;

        switch (playerType)
        {
        case PlayerController.PlayerType.Local:
            playerController             = playerControllerGameObject.AddComponent <LocalPlayerController>();
            playerController.PlayerIndex = playerIndex;

            break;

        case PlayerController.PlayerType.Remote:
            playerController             = playerControllerGameObject.AddComponent <RemotePlayerController>();
            playerController.PlayerIndex = playerIndex;
            break;

        case PlayerController.PlayerType.AI:
            playerController             = playerControllerGameObject.AddComponent <LocalPlayerController>();
            playerController.PlayerIndex = playerIndex;
            // TO DO : Replace with AI Controller
            break;

        default:
            playerController = playerControllerGameObject.AddComponent <LocalPlayerController>();
            break;
        }

        playerController.CommandInterpreter         = associatedPlayer.GetComponent <CommandInterpreter>();
        playerController.InteractionHandler         = associatedPlayer.GetComponent <CharacterInteractionHandler>();
        playerController.CharacterStats             = associatedPlayer.GetComponent <CharacterStats>();
        playerController.CharacterStats.PlayerIndex = playerIndex;

        if (IsNetworkedMode && playerType == PlayerController.PlayerType.Local)
        {
            playerController.gameObject.AddComponent <NetworkInputHandler>();
        }

        playerControllerGameObject.transform.parent = this.gameObject.transform;
        playerControllerGameObject.name             = PlayerControllerString + (playerIndex + 1);

        if (Players.Count > playerIndex + 1)
        {
            Players[playerIndex] = playerController;
        }
        else
        {
            Players.Add(playerController);
            PlayerMatchStatistics stats = new PlayerMatchStatistics();
            stats.PlayerIndex = playerIndex;
            PlayerMatchStats.Add(stats);
        }
    }