Exemplo n.º 1
0
        /// <summary>
        /// Starts a new game turn.
        /// </summary>
        protected virtual void StartTurn()
        {
            Logger.Log("Start turn for player " + currentPlayerIndex + ".");

            var players = gameState.players;

            // Update the current player and opponents.
            gameState.currentPlayer   = players[currentPlayerIndex];
            gameState.currentOpponent = players.Find(x => x != gameState.currentPlayer);

            gameState.currentPlayer.numTurn += 1;

            // Execute the turn start actions.
            foreach (var action in GameManager.Instance.config.properties.turnStartActions)
            {
                ExecuteGameAction(action);
            }

            // Run any code that needs to be executed at turn start time.
            PerformTurnStartStateInitialization();

            // Let the server handlers know the turn has started.
            for (var i = 0; i < handlers.Count; i++)
            {
                handlers[i].OnStartTurn();
            }

            effectSolver.OnTurnStarted();

            // Send a StartTurn message to all the connected players.
            for (var i = 0; i < players.Count; i++)
            {
                var player = players[i];
                var msg    = new StartTurnMessage();
                msg.recipientNetId             = player.netId;
                msg.isRecipientTheActivePlayer = player == gameState.currentPlayer;
                msg.turn     = currentTurn;
                msg.player   = GetPlayerNetworkState(player);
                msg.opponent = GetOpponentNetworkState(players.Find(x => x != player));
                SafeSendToClient(player, NetworkProtocol.StartTurn, msg);
            }
        }
Exemplo n.º 2
0
        public virtual void OnStartTurn(StartTurnMessage msg)
        {
            if (msg.isRecipientTheActivePlayer)
            {
                isActivePlayer = true;
                CleanupTurnLocalState();

                gameState.currentPlayer   = playerInfo;
                gameState.currentOpponent = opponentInfo;
            }
            else
            {
                gameState.currentPlayer   = opponentInfo;
                gameState.currentOpponent = playerInfo;
            }

            effectSolver.OnTurnStarted();

            LoadPlayerStates(msg.player, msg.opponent);
        }