public void Chat(ClientPeer client, int type) { SingleExecute.Instance.Execute(() => { if (!user.IsOnLine(client)) { return; } int userId = user.GetId(client); //匹配场景 if (match.IsMatching(userId)) { MatchRoom mr = match.GetRoom(userId); ChatDto dto = new ChatDto(userId, type); mr.Brocast(OpCode.CHAT, ChatCode.CHAT_SRES, dto); } else if (fight.IsFighting(userId)) { //战斗场景 FightRoom mr = fight.GetRoom(userId); ChatDto dto = new ChatDto(userId, type); //fight.(OpCode.CHAT, ChatCode.CHAT_SRES, dto); Brocast(mr, OpCode.CHAT, ChatCode.CHAT_SRES, dto); } }); }
/// <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); } }); }
/// <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); } }); }
/// <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); }); }
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); } }
/// <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); }); }
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); } }
/// <summary> /// 用户离开 /// </summary> /// <param name="client"></param> private void leave(ClientPeer client) { SingleExecute.Instance.Execute( () => { if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); if (fightCache.IsFighting(userId) == false) { return; } FightRoom room = fightCache.GetRoomByUId(userId); //就算中途退出的人 room.LeaveUIdList.Add(userId); //给逃跑玩家添加逃跑场次 for (int i = 0; i < room.LeaveUIdList.Count; i++) { UserModel um = userCache.GetModelById(room.LeaveUIdList[i]); um.RunCount++; foreach (var player in room.PlayerList) { if (player.UserId == room.LeaveUIdList[i]) { um.Been -= 500; } } um.Exp += 0; userCache.Update(um); } brocast(room, OpCode.FIGHT, FightCode.LEAVE_BRO, null); fightCache.Destroy(room); } ); }
/// <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); } }); }
/// <summary> /// 玩家退出房间或者掉线 /// FIXME 本局结束之后也要退出房间//不能扣除豆子 计划加入一个room 的结束flag 如果退出的时候战斗已经结束就return/同时房间人数减少1 /// </summary> /// <param name="client"></param> private void ExitRoom(ClientPeer client) { SingleExecute.Instance.Execute(() => { if (!user.IsOnLine(client)) { //不在线 return; } int userId = user.GetId(client); if (!fight.IsFighting(userId)) { return; } var room = fight.GetRoom(userId); int count = room.ExitRoom(userId); //FIXME 如果当前我正在操作 //如果自己正在抢地主 让下家抢地主 //当前自己正在操作 //if (room.round.currentUserId == userId) //{ // //出牌者是自己 // if (room.round.currentBiggsetId == userId) // { // //出一张当前手里最小的牌 // var cards = room.GetPlayerCards(userId); // CardDto smallCard = null; // foreach (var item in cards) // { // if (item.weight <= smallCard.weight) // { // smallCard = item; // } // } // ChuPai(client,new ChuPaiDto(userId,new List<CardDto>() { smallCard})); // } // else //出牌者不是自己 // { // //游戏已经开始? // if (room.isFighting) // { // BuChu(client); // } // else //还在抢地主? // { // //Qiang_Landlord(client, false); // Brocast(room, OpCode.FIGHT, FightCode.BUQIANG_LANDLORD_BRO, userId,client); // int count1 = room.BuQiang();//在这里重置了id // if (count1 == 3)//重新开始 // { // Brocast(room, OpCode.FIGHT, FightCode.BACKTOFIGHT_BRO, null,client);//让第一个人抢地主 // return; // } // //将下轮 该谁抢地主的id广播给客户端 // Turn(room, FightCode.QIANG_TURN_BRO); // } // } //} //如果自己正在出牌 让下家出牌 //给逃跑玩家结算 var beens = room.multiple * 1000; var userModel = user.GetModelById(userId); userModel.runCount++; //userModel.loseCount++; 游戏结束的会结算2 userModel.beens -= beens * 3;//逃跑的人减3倍 user.Update(userModel); //把这个id从fightCache中移除 因为这个id跟 roomId绑定了 fight.uIdRidDic.Remove(userId); //离线的不要发啦。都离线了还发个鬼 Brocast(room, OpCode.FIGHT, FightCode.LEAVE_BRO, userId, client); if (count == 3) { fight.Destroy(room); } }); }