示例#1
0
        public virtual void OnStartGame(StartGameMessage msg)
        {
            gameStarted  = true;
            playerIndex  = msg.playerIndex;
            turnDuration = msg.turnDuration;

            effectSolver = new EffectSolver(gameState, msg.rngSeed);
            effectSolver.SetTriggers(playerInfo);
            effectSolver.SetTriggers(opponentInfo);

            LoadPlayerStates(msg.player, msg.opponent);
        }
示例#2
0
        /// <summary>
        /// Starts the multiplayer game. This is automatically called when the appropriate number of players
        /// have joined a room.
        /// </summary>
        public virtual void StartGame()
        {
            Logger.Log("Game has started.");

            // Start with turn 1.
            currentTurn = 1;

            var players = gameState.players;

            // Create an array with all the player nicknames.
            var playerNicknames = new List <string>(players.Count);

            foreach (var player in players)
            {
                playerNicknames.Add(player.nickname);
            }

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

            var rngSeed = System.Environment.TickCount;

            effectSolver = new EffectSolver(gameState, rngSeed);

            foreach (var player in players)
            {
                effectSolver.SetTriggers(player);
                foreach (var zone in player.zones)
                {
                    foreach (var card in zone.Value.cards)
                    {
                        effectSolver.SetDestroyConditions(card);
                        effectSolver.SetTriggers(card);
                    }
                }
            }

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

            // Send a StartGame message to all the connected players.
            for (var i = 0; i < players.Count; i++)
            {
                var player = players[i];
                var msg    = new StartGameMessage();
                msg.recipientNetId = player.netId;
                msg.playerIndex    = i;
                msg.turnDuration   = turnDuration;
                msg.nicknames      = playerNicknames.ToArray();
                msg.player         = GetPlayerNetworkState(player);
                msg.opponent       = GetOpponentNetworkState(players.Find(x => x != player));
                msg.rngSeed        = rngSeed;
                SafeSendToClient(player, NetworkProtocol.StartGame, msg);
            }

            // Start running the turn sequence coroutine.
            turnCoroutine = StartCoroutine(RunTurn());
        }