コード例 #1
0
ファイル: FightHandler.cs プロジェクト: hjj0416/DouDiZhu
        /// <summary>
        /// 用户离开
        /// </summary>
        /// <param name="client"></param>
        private void leave(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (fightCache.IsFighting(userId) == false)
                {
                    return;
                }
                FightRoom fightRoom = fightCache.GetRoomByUId(userId);

                //中途退出
                fightRoom.LeaveUIdList.Add(userId);
                Brocast(fightRoom, OpCode.FIGHT, FightCode.LEAVE_BRO, userId);

                if (fightRoom.LeaveUIdList.Count == 3)
                {
                    //给逃跑玩家添加逃跑场次
                    for (int i = 0; i < fightRoom.LeaveUIdList.Count; i++)
                    {
                        UserModel um = userCache.GetModelById(fightRoom.LeaveUIdList[i]);
                        um.RunCount++;
                        um.Been -= fightRoom.Multiple * 1000 * 3;
                        um.Exp  += 0;
                        userCache.Update(um);
                    }
                    //销毁缓存层的房间数据
                    fightCache.Destroy(fightRoom);
                }
            });
        }
コード例 #2
0
        private void grabLandlord(ClientPeer client, bool result)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId          = userCache.GetId(client);
                FightRoom fightRoom = fightCache.GetRoomByUId(userId);

                if (result == true)
                {
                    fightRoom.SetLandlord(userId);
                    //send message to all client who was landlord
                    GrabDto dto = new GrabDto(userId, fightRoom.TableCardList, fightRoom.getUserCards(userId));
                    Broadcast(fightRoom, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BROADCAST, dto);

                    //enter deal phase
                    Broadcast(fightRoom, OpCode.FIGHT, FightCode.TURN_DEAL_BROADCAST, userId);
                }
                else
                {
                    //don't grab
                    int nextUserId = fightRoom.GetNextUserId(userId);
                    Broadcast(fightRoom, OpCode.FIGHT, FightCode.TURN_GRAB_BROADCAST, nextUserId);
                }
            });
        }
コード例 #3
0
        /// <summary>
        /// 翻倍处理
        /// </summary>
        /// <param name="client"></param>
        /// <param name="multi"></param>
        private void multi(ClientPeer client, int multi)
        {
            int       userId = userCache.GetId(client);
            FightRoom room   = fightCache.GetRoomByUId(userId);

            room.AddInMulti(userId, multi);
            if (room.multiDict.Count == 2)
            {
                room.isMulti = false;
            }
            if (room.isMulti == false)
            {
                foreach (var player in room.PlayerList)
                {
                    if (player.Identity == Identity.LANDLORD)
                    {
                        brocast(room, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, player.UserId);
                    }
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// 用户离开
 /// </summary>
 /// <param name="client"></param>
 private void Leave(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (UserCache.IsOnline(client) == false)
         {
             socketMsg.State = null;
             Console.WriteLine("当前用户不在线,不能从房间中剔除!");
             return;
         }
         int userId = UserCache.GetClientUserId(client);
         if (FightCache.IsFighting(userId) == false)
         {
             return;
         }
         FightRoom room = FightCache.GetRoomByUId(userId);
         //中途退出房间的玩家
         room.LeaveUIdList.Add(userId);
         //
         socketMsg.SubCode = FightCode.Leave_Bro;
         socketMsg.value   = userId;
         BroCast(room, socketMsg);
         //当前房间玩家是否都退出
         if (room.LeaveUIdList.Count == 3)
         {
             for (int i = 0; i < room.LeaveUIdList.Count; i++)
             {
                 UserCharacterInfo user = UserCache.GetUserInfo(room.LeaveUIdList[i]);
                 user.RunCount++;
                 user.Been -= (room.Multiple * 1000) * 3;
                 user.Exp  += 0;
                 UserCache.Update(user);
             }
             FightCache.Destroy(room);
         }
     });
 }
コード例 #5
0
ファイル: ChatHandler.cs プロジェクト: hjj0416/DouDiZhu
        private void chatRequest(ClientPeer client, int chatType)
        {
            if (userCache.IsOnline(client) == false)
            {
                return;
            }
            int     userId  = userCache.GetId(client);
            ChatDto chatDto = new ChatDto(userId, chatType);

            if (matchCache.IsMatching(userId))
            {
                MatchRoom mRoom = matchCache.GetRoom(userId);
                mRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto);
                Console.WriteLine("快捷喊话:" + chatDto.ChatType);
            }
            else if (fightCache.IsFighting(userId))
            {
                FightRoom fightRoom = fightCache.GetRoomByUId(userId);
                fightRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto);
                Console.WriteLine("快捷喊话:" + chatDto.ChatType);
            }
        }
コード例 #6
0
        private void chatRequest(ClientPeer client, int chatType)
        {
            if (userCache.IsOnline(client) == false)
            {
                return;
            }
            int userId = userCache.GetId(client);
            //获取发送者的id userId
            //发送
            ChatDto dto = new ChatDto(userId, chatType);

            //广播给房间内的玩家
            if (matchCache.IsMatching(userId))
            {
                MatchRoom mRoom = matchCache.GetRoom(userId);
                mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto);
            }
            if (fightCache.IsFighting(userId))
            {
                FightRoom fRoom = fightCache.GetRoomByUId(userId);
                fRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto, client);
            }
        }