Ejemplo n.º 1
0
        public override bool AddCommand(Command command)
        {
            int syncturn = command.SyncTurn;

            if (syncturn < 0 || syncturn > MAX_SYNCTURN_INDEX)
            {
                return(false);
            }
            long player_pstid = command.PlayerPstid;

            if (player_pstid == -1)
            {
                if (command.Type != CommandType.SyncTurnDone)
                {
                    return(false);
                }
                syncturn += 1;
                SortedDictionary <long, PlayerTurnState> .Enumerator enumerator = m_turn_state_of_players.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    PlayerTurnState pts = enumerator.Current.Value;
                    if (syncturn > pts.SyncTurn)
                    {
                        pts.SyncTurn = syncturn;
                    }
                }
                if (syncturn > m_top_turn)
                {
                    m_top_turn = syncturn;
                }
                if (syncturn - 1 > m_ready_turn)
                {
                    m_ready_turn = syncturn - 1;
                }
                return(true);
            }
            else
            {
                PlayerTurnState pts;
                if (!m_turn_state_of_players.TryGetValue(player_pstid, out pts))
                {
                    return(false);
                }
                if (command.Type == CommandType.SyncTurnDone)
                {
                    syncturn += 1;
                }
                if (syncturn > pts.SyncTurn)
                {
                    pts.SyncTurn = syncturn;
                    CalculateReadyTurn();
                }
                if (syncturn > m_top_turn)
                {
                    m_top_turn = syncturn;
                }
                return(base.AddCommand(command));
            }
        }
Ejemplo n.º 2
0
        void CalculateReadyTurn()
        {
            int turn = MAX_INT;

            SortedDictionary <long, PlayerTurnState> .Enumerator enumerator = m_turn_state_of_players.GetEnumerator();
            while (enumerator.MoveNext())
            {
                PlayerTurnState pts = enumerator.Current.Value;
                if (pts.Valid && pts.SyncTurn < turn)
                {
                    turn = pts.SyncTurn;
                }
            }
            if (turn == MAX_INT)
            {
                m_ready_turn = -1;
            }
            else
            {
                m_ready_turn = turn - 1;
            }
        }
Ejemplo n.º 3
0
        public override void AddPlayer(long player_pstid)
        {
            PlayerTurnState pts = new PlayerTurnState();

            m_turn_state_of_players[player_pstid] = pts;
        }