Ejemplo n.º 1
0
        /// <summary>
        /// Make this user join a channel
        /// </summary>
        /// <param name="id">Id of channel to join</param>
        /// <returns>Empty task</returns>
        public async Task JoinChannelAsync(uint id)
        {
            var builder = new UserState.Builder
            {
                Session   = this.Id,
                Actor     = this.Client.ClientUser.Id,
                ChannelId = id,
            };

            await this.Client.SendMessageWithResponseAsync <UserState>(builder, builder.Build().Equals).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        private void DelegateOnCancelMatchCallback(Object obj)
        {
            ResponseMsg msg = obj as ResponseMsg;

            if (msg.ErrorCode == RpcErrorCodeEnum.Ok)
            {
                UserState.Builder userStateBuilder = AppValues.UserInfoBuilder.UserState.ToBuilder();
                userStateBuilder.SetActionState(UserActionStateEnum.ActionNone);
                AppValues.UserInfoBuilder.SetUserState(userStateBuilder);

                RefreshUiForUserState();
            }
            else
            {
                string tips = string.Format("取消匹配失败,errorCode = {0}", msg.ErrorCode);
                MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 3
0
        private void DelegateOnMatchResultPushCallback(Object obj)
        {
            ResponseMsg     msg             = obj as ResponseMsg;
            MatchResultPush matchResultPush = MatchResultPush.ParseFrom(msg.ProtoData);

            if (matchResultPush.IsSuccess == false)
            {
                MessageBox.Show(this, "匹配失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                UserState.Builder userStateBuilder = AppValues.UserInfoBuilder.UserState.ToBuilder();
                userStateBuilder.SetActionState(UserActionStateEnum.Playing);
                userStateBuilder.SetBattleType(matchResultPush.BattleType);
                userStateBuilder.SetBattleId(matchResultPush.BattleId);
                AppValues.UserInfoBuilder.SetUserState(userStateBuilder);

                RefreshUiForUserState();

                // 请求获取战场信息
                GetBattleInfoRequest.Builder builder = GetBattleInfoRequest.CreateBuilder();
                WebSocketManager.SendMessage(RpcNameEnum.GetBattleInfo, builder.Build().ToByteArray(), OnGetBattleInfoCallback);
            }
        }
Ejemplo n.º 4
0
        private void doOneEvent(EventMsg eventMsg)
        {
            AppValues.LastEventNum = eventMsg.EventNum;
            switch (eventMsg.EventType)
            {
            case EventTypeEnum.EventTypeStartTurn:
            {
                AppValues.CurrentTurnInfo = eventMsg.StartTurnEvent.CurrentTurnInfo;
                RefreshUiForCurrentTurnInfo();
                break;
            }

            case EventTypeEnum.EventTypeEndTurn:
            {
                break;
            }

            case EventTypeEnum.EventTypePlacePieces:
            {
                PlacePiecesEvent placePiecesEvent = eventMsg.PlacePiecesEvent;
                int value = 0;
                if (placePiecesEvent.UserId == AppValues.BattleUserBriefInfos[0].UserId)
                {
                    value = 1;
                }
                else
                {
                    value = 2;
                }
                AppValues.CellInfos[placePiecesEvent.Index] = value;
                RefreshUiForOneCell(placePiecesEvent.Index);
                break;
            }

            case EventTypeEnum.EventTypeGameOver:
            {
                GameOverEvent gameOverEvent = eventMsg.GameOverEvent;
                if (gameOverEvent.WinnerUserId == 0)
                {
                    MessageBox.Show(this, "对战结束,平局了", "对战结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    string tips = string.Format("对战结束,您{0}了!\n结束原因为:{1}", gameOverEvent.WinnerUserId == AppValues.UserInfoBuilder.UserId ? "赢" : "输", gameOverEvent.GameOverReason);
                    MessageBox.Show(this, tips, "对战结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                AppValues.CellInfos.Clear();
                AppValues.CurrentTurnInfo = null;
                UserState.Builder userStateBuilder = AppValues.UserInfoBuilder.UserState.ToBuilder();
                userStateBuilder.SetActionState(UserActionStateEnum.ActionNone);
                userStateBuilder.ClearBattleType();
                userStateBuilder.ClearBattleId();
                AppValues.UserInfoBuilder.SetUserState(userStateBuilder);
                RefreshUiForUserState();

                break;
            }

            default:
            {
                MessageBox.Show(this, "doOneEvent中收到未支持的EventType = " + eventMsg.EventType, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            }
        }