Пример #1
0
    void SetUpTableData(bool _isGetAll, SubServerDetail _serverDetail, MessageReceiving _messageReceiving, int _error, System.Action _onSuccess = null, System.Action <int> _onError = null)
    {
        if (_messageReceiving != null)
        {
            bool _checkCase = _messageReceiving.readBoolean();
            if (_checkCase)
            {
                long       _versionRoom = _messageReceiving.readLong();
                RoomDetail _roomDetail  = null;
                for (int i = 0; i < _serverDetail.listRoomDetail.Count; i++)
                {
                    if (_serverDetail.listRoomDetail[i].gameId == DataManager.instance.miniGameData.currentMiniGameDetail.myInfo.gameId)
                    {
                        _roomDetail = _serverDetail.listRoomDetail[i];
                        break;
                    }
                }
                if (_roomDetail == null)
                {
                                        #if TEST
                    Debug.LogError("_roomDetail is null: " + DataManager.instance.miniGameData.currentMiniGameDetail.myInfo.gameType.ToString());
                                        #endif
                }
                else
                {
                    _roomDetail.versionRoom = _versionRoom;
                }
                // if(_roomDetail.myOriginalDetail != null){
                //  _roomDetail.myOriginalDetail.versionServer = _versionServer;
                // }

                TableData _tableData       = new TableData();
                string    _gameNameRecieve = _messageReceiving.readString();
                short     _maxNumberTable  = _messageReceiving.readShort();
                _tableData.numberPlaying = _messageReceiving.readInt();                 //số người đang chơi
                _tableData.maxViewer     = _messageReceiving.readByte();
                _tableData.maxPlayer     = _messageReceiving.readByte();
                short _numberTableGet = _messageReceiving.readShort();
                // GAMEID_UNO|59|0|8|4|20
                // Debug.Log(_gameNameRecieve + "|" + _maxNumberTable + "|" + _tableData.numberPlaying + "|" + _tableData.maxViewer + "|" + _tableData.maxPlayer + "|" + _numberTableGet);
                List <TableDetail> _listTableDetail = new List <TableDetail>();
                for (int i = 0; i < _numberTableGet; i++)
                {
                    TableDetail _tableDetail = new TableDetail();
                    _tableDetail.tableId      = _messageReceiving.readShort();
                    _tableDetail.isLockByPass = _messageReceiving.readBoolean();
                    _tableDetail.status       = _messageReceiving.readByte();
                    _tableDetail.bet          = _messageReceiving.readLong();
                    _tableDetail.countViewer  = _messageReceiving.readByte();
                    _tableDetail.countPlaying = _messageReceiving.readByte();
                    _listTableDetail.Add(_tableDetail);
                }

                if (DataManager.instance.miniGameData.currentMiniGameDetail.myInfo.versionFeature < _versionRoom)
                {
                    _serverDetail.beingError = false;
                    if (currentState == State.Show)
                    {
                        if (_onError != null)
                        {
                            _onError(-98);                             // RoomOutOfDate
                        }
                    }
                }
                else
                {
                    if (_isGetAll)
                    {
                        List <TableDetail> _tableDetailCollection = new List <TableDetail>();
                        for (int i = 0; i < _listTableDetail.Count; i++)
                        {
                            if (_tableData.CanTableBeEnable(_listTableDetail[i]))
                            {
                                _tableDetailCollection.Add(_listTableDetail[i]);
                                if (_tableDetailCollection.Count >= numTableDefault)
                                {
                                    break;
                                }
                            }
                        }
                        _tableData.listTableDetail = _tableDetailCollection;
                    }
                    else
                    {
                        _tableData.listTableDetail = _listTableDetail;
                    }
                    DataManager.instance.miniGameData.currentMiniGameDetail.tableData = _tableData;
                    _serverDetail.beingError = false;
                    if (currentState == State.Show)
                    {
                        panelListTable.InitDataAgain();
                        if (_onSuccess != null)
                        {
                            _onSuccess();
                        }
                    }
                }
            }
            else
            {
                                #if TEST
                Debug.LogError("Lỗi sever trả về rỗng");
                                #endif
                _serverDetail.beingError = true;
                _serverDetail.countConnectionError++;
                if (currentState == State.Show)
                {
                    if (_onError != null)
                    {
                        _onError(-99);                         // RoomIsNotAvailable
                    }
                }
            }
        }
        else
        {
                        #if TEST
            Debug.LogError("Room is not available");
                        #endif
            _serverDetail.beingError = true;
            _serverDetail.countConnectionError++;
            if (currentState == State.Show)
            {
                if (_onError != null)
                {
                    _onError(_error);
                }
            }
        }
    }