コード例 #1
0
        /// <summary>
        /// 客户端离开请求的处理
        /// </summary>
        /// <param name="client"></param>
        private void LeaveRoom(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                //不在战斗房间,忽略
                if (fightCache.IsFighting(client.Id) == false)
                {
                    return;
                }

                FightRoom room = fightCache.GetFightRoomByUserId(client.Id);
                room.leaveUserIdList.Add(client.Id);

                DatabaseManager.UpdateCoinCount(client.Id, -(room.bottomStakes * 20));
                room.Broadcase(OpCode.Fight, FightCode.Leave_BRO, client.Id);

                if (room.leaveUserIdList.Count == 1)
                {
                    if (room.giveUpCardUserIdList.Count == 0)
                    {
                        //离开的玩家是本次下注的玩家
                        //这样需转换下一个玩家下注
                        if (room.roundModel.CurrentStakesUserId == client.Id)
                        {
                            //轮换下注TODO
                        }
                    }
                }

                if (room.leaveUserIdList.Count == 2)
                {
                    //TODO
                    return;
                }
                if (room.leaveUserIdList.Count == 3)
                {
                    fightCache.DestoryRoom(room);
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// 客户端比牌的处理
        /// </summary>
        /// <param name="compareClient"></param>
        /// <param name="comparedID"></param>
        private void CompareCard(ClientPeer compareClient, int comparedID)
        {
            SingleExecute.Instance.Exeecute(() => {
                if (fightCache.IsFighting(compareClient.Id) == false)
                {
                    return;
                }

                FightRoom room  = fightCache.GetFightRoomByUserId(compareClient.Id);
                room.stakesSum += room.lastPlayerStakes;
                int stakesSum   = room.UpdatePlayerStakesSum(compareClient.Id, room.lastPlayerStakes);
                int remainCoin  = DatabaseManager.UpdateCoin(compareClient.Id, -room.lastPlayerStakes);
                stakesDto.Change(compareClient.Id, remainCoin, room.lastPlayerStakes, stakesSum, StakesDto.StakesType.Look);
                room.Broadcast(OpCode.Fight, FightCode.PutStakes_BRO, stakesDto);

                // 拿到 3 个玩家的 DTO
                PlayerDto c1Dto = null, c2Dto = null, otherDto = null;
                foreach (var player in room.playerList)
                {
                    if (player.id == compareClient.Id)
                    {
                        c1Dto = player;
                    }
                    else if (player.id == comparedID)
                    {
                        c2Dto = player;
                    }
                    else
                    {
                        otherDto = player;
                    }
                }
                ClientPeer otherClient = DatabaseManager.GetClientPeerByUserId(otherDto.id);
                // 比牌
                CompareCard(room, compareClient, c1Dto, c2Dto, otherClient);
            });
        }
コード例 #3
0
        /// <summary>
        /// 客户端聊天的请求处理
        /// </summary>
        /// <param name="client"></param>
        /// <param name="msg"></param>
        private void Chat(ClientPeer client, string msg)
        {
            SingleExecute.Instance.Exeecute(() => {
                foreach (var matchCache in matchCaches)
                {
                    if (matchCache.IsMatching(client.Id))   // 客户端在匹配房间里
                    {
                        MatchRoom room = matchCache.GetRoom(client.Id);
                        chatDto.Change(client.Id, client.UserName, msg);
                        room.Broadcast(OpCode.Chat, ChatCode.BRO, chatDto);
                    }
                }
                if (fightCache.IsFighting(client.Id) == false)
                {
                    return;
                }

                FightRoom fightRoom = fightCache.GetFightRoomByUserId(client.Id);
                chatDto.Change(client.Id, client.UserName, msg);
                fightRoom.Broadcast(OpCode.Chat, ChatCode.BRO, chatDto);
            });
        }