/// <summary> /// 发牌 /// </summary> /// <param name="self"></param> public static void DealCards(this GameControllerComponent self) { if (self == null) { Log.Error("当前为null:GameControllerComponent.DealCards"); return; } temp.Clear(); Room room = self.GetParent <Room>(); Gamer[] gamers = room.GetAll(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); foreach (var gamer in gamers) { HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); //发牌前有拍了 if (handCardsComponent.GetAll().Count > 0) { // Log.Debug("发牌前有牌了:" + handCardsComponent.GetAll().Count); temp.Add(null); } else { // Log.Debug("发牌前没有拍"); temp.Add(handCardsComponent.GetAll()); } } Logic_NJMJ.getInstance().FaMahjong(temp, deskComponent.RestLibrary); foreach (var card in deskComponent.RestLibrary) { card.weight = (byte)card.m_weight; } }
/// <summary> /// 发牌(不包括花牌) /// </summary> /// <param name="deskComponent"></param> /// <param name="handCardsComponent"></param> private static void GetCardNotFace(DeskComponent deskComponent, HandCardsComponent handCardsComponent) { while (true) { int cardIndex = RandomHelper.RandomNumber(0, deskComponent.RestLibrary.Count); MahjongInfo grabMahjong = deskComponent.RestLibrary[cardIndex]; deskComponent.RestLibrary.RemoveAt(cardIndex); //花牌 if (grabMahjong.m_weight >= Consts.MahjongWeight.Hua_HongZhong) { handCardsComponent.FaceCards.Add(grabMahjong); handCardsComponent.FaceGangCards.Add(grabMahjong); } else { handCardsComponent.GetAll().Add(grabMahjong); break; } } }
protected override async void Run(Session session, G2M_PlayerEnterRoom message, Action <M2G_PlayerEnterRoom> reply) { M2G_PlayerEnterRoom response = new M2G_PlayerEnterRoom(); //Log.Info("G2M_GamerEnterRoomHandler" + JsonHelper.ToJson(message)); try { RoomComponent roomCompnent = Game.Scene.GetComponent <RoomComponent>(); Gamer gamer = null; Room room = null; foreach (var _room in roomCompnent.rooms.Values) { room = _room; gamer = room.Get(message.UserId); if (gamer != null) { Log.Info("找到房间:" + _room.Id); break; } } //断线重连 if (gamer != null) { //在空闲房间内 if (room.State == RoomState.Idle) { response.Message = "已经进入房间"; response.Error = ErrorCode.ERR_Common; Log.Error("玩家多次进入空闲房间"); room.Remove(gamer.UserID); reply(response); return; } DeskComponent deskComponent = room.GetComponent <DeskComponent>(); //重新更新actor gamer.PlayerID = message.PlayerId; gamer.GetComponent <UnitGateComponent>().GateSessionActorId = message.SessionId; //短线重连 Actor_GamerReconnet reconnet = new Actor_GamerReconnet(); foreach (var _gamer in room.GetAll()) { if (_gamer == null) { Log.Error($"断线重连后玩家为空"); continue; } GamerData gamerData = new GamerData(); HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); if (handCardsComponent == null) { Log.Error($"{_gamer.UserID}断线重连后玩家的手牌为空,移除玩家"); continue; // room.Remove(_gamer.UserID); // //房间没人就释放 // if (room.seats.Count == 0) // { // roomCompnent.RemoveRoom(room); // room.Dispose(); // } // return; } List <MahjongInfo> handCards = handCardsComponent.GetAll(); gamerData.handCards = handCards; gamerData.faceCards = handCardsComponent.FaceCards; gamerData.playCards = handCardsComponent.PlayCards; //添加碰刚的uid foreach (var pengOrBar in handCardsComponent.PengOrBars) { //碰 if (pengOrBar.OperateType == OperateType.Peng) { gamerData.pengCards.Add(new MahjongInfo() { weight = (byte)pengOrBar.Weight }); gamerData.OperatedPengUserIds.Add(pengOrBar.UserId); } //杠 else { gamerData.gangCards.Add(new MahjongInfo() { weight = (byte)pengOrBar.Weight }); gamerData.OperatedGangUserIds.Add(pengOrBar.UserId); } } gamerData.IsBanker = handCardsComponent.IsBanker; gamerData.UserID = _gamer.UserID; gamerData.SeatIndex = room.GetGamerSeat(_gamer.UserID); gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(_gamer.UserID); gamerData.IsTrusteeship = gamer.IsTrusteeship; PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(_gamer.UserID); PlayerInfo playerInfo = PlayerInfoFactory.Create(playerBaseInfo); gamerData.playerInfo = playerInfo; reconnet.Gamers.Add(gamerData); } reconnet.RestCount = deskComponent.RestLibrary.Count; reconnet.RoomType = (int)room.GetComponent <GameControllerComponent>().RoomConfig.Id; if (room.IsFriendRoom) { GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); reconnet.RoomId = gameControllerComponent.RoomConfig.FriendRoomId; reconnet.MasterUserId = gameControllerComponent.RoomConfig.MasterUserId; reconnet.JuCount = gameControllerComponent.RoomConfig.JuCount; reconnet.Multiples = gameControllerComponent.RoomConfig.Multiples; reconnet.CurrentJuCount = room.CurrentJuCount; } room.GamerReconnect(gamer, reconnet); gamer.isOffline = false; gamer.RemoveComponent <TrusteeshipComponent>(); Log.Info($"玩家{message.UserId}断线重连"); gamer.StartTime = DateTime.Now; } else { Log.Info($"{message.UserId}进入房间"); gamer = await GamerFactory.Create(message.PlayerId, message.UserId); await gamer.AddComponent <MailBoxComponent>().AddLocation(); gamer.AddComponent <UnitGateComponent, long>(message.SessionId); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); //获得空闲的房间 Room idleRoom; if (message.RoomType == 3) { idleRoom = roomComponent.GetFriendRoomById(message.RoomId); if (idleRoom == null) { response.Error = ErrorCode.ERR_Common; response.Message = "房间号不存在"; reply(response); return; } if (idleRoom.Count == 4) { response.Error = ErrorCode.ERR_Common; response.Message = "房间人数已满"; reply(response); return; } } else { idleRoom = roomComponent.GetIdleRoomById(message.RoomType); if (idleRoom == null) { idleRoom = RoomFactory.Create(message.RoomType); roomComponent.Add(idleRoom); } } idleRoom.Add(gamer); await idleRoom.BroadGamerEnter(gamer.UserID); } response.GameId = gamer.Id; reply(response); if (message.RoomType == 3) { await Actor_GamerReadyHandler.GamerReady(gamer, new Actor_GamerReady() { }); } } catch (Exception e) { ReplyError(response, e, reply); } await Task.CompletedTask; }
public static async Task GamerReady(Gamer gamer, Actor_GamerReady message) { try { Log.Info($"收到玩家{gamer.UserID}准备"); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null || gamer == null || gamer.IsReady || room.State == RoomState.Game) { return; } gamer.IsReady = true; //消息广播给其他人 room?.Broadcast(new Actor_GamerReady() { Uid = gamer.UserID }); Gamer[] gamers = room.GetAll(); //房间内有4名玩家且全部准备则开始游戏 if (room.Count == 4 && gamers.Where(g => g.IsReady).Count() == 4) { room.State = RoomState.Game; room.CurrentJuCount++; room.IsGameOver = false; room.RoomDispose(); #region 好友房扣钥匙 if (room.IsFriendRoom && room.CurrentJuCount == 1) { RoomConfig roomConfig = room.GetComponent <GameControllerComponent>().RoomConfig; await DBCommonUtil.DeleteFriendKey(roomConfig.MasterUserId, roomConfig.KeyCount, "好友房房主扣除钥匙"); } #endregion //设置比下胡 if (room.LastBiXiaHu) { room.IsBiXiaHu = true; } else { room.IsBiXiaHu = false; } room.LastBiXiaHu = false; if (roomComponent.gameRooms.TryGetValue(room.Id, out var itemRoom)) { roomComponent.gameRooms.Remove(room.Id); } roomComponent.gameRooms.Add(room.Id, room); roomComponent.idleRooms.Remove(room.Id); //添加用户 room.UserIds.Clear(); //初始玩家开始状态 foreach (var _gamer in gamers) { room.UserIds.Add(_gamer.UserID); if (_gamer.GetComponent <HandCardsComponent>() == null) { _gamer.AddComponent <HandCardsComponent>(); } _gamer.IsReady = false; } Log.Info($"{room.Id}房间开始,玩家:{JsonHelper.ToJson(room.UserIds)}"); GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); Gamer bankerGamer = null; HandCardsComponent bankerHandCards = null; if (room.IsLianZhuang) { if (room.huPaiUid != 0 && room.huPaiUid == room.BankerGamer?.UserID) { bankerGamer = room.Get(room.huPaiUid); bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; //连庄 room.LastBiXiaHu = true; } else { int gamerSeat = room.GetGamerSeat(room.BankerGamer.UserID); int currentSeat; if (gamerSeat == 3) { currentSeat = 0; } else { currentSeat = ++gamerSeat; } bankerGamer = room.gamers[currentSeat]; bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; } } else { if (room.IsFriendRoom) { GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>(); long masterUserId = controllerComponent.RoomConfig.MasterUserId; bankerGamer = room.Get(masterUserId); } else { //随机庄家 int number = RandomHelper.RandomNumber(0, 12); int i = number % 4; bankerGamer = room.gamers[i]; } bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; } //发牌 gameController.DealCards(); orderController.Start(bankerGamer.UserID); //去除花牌 foreach (var _gamer in gamers) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> handCards = handCardsComponent.GetAll(); for (int j = handCards.Count - 1; j >= 0; j--) { MahjongInfo mahjongInfo = handCards[j]; if (mahjongInfo.m_weight >= Consts.MahjongWeight.Hua_HongZhong) { handCards.RemoveAt(j); mahjongInfo.weight = (byte)mahjongInfo.m_weight; handCardsComponent.FaceCards.Add(mahjongInfo); handCardsComponent.FaceGangCards.Add(mahjongInfo); } } //加牌 int handCardsCount = handCards.Count; for (int j = 0; j < 13 - handCardsCount; j++) { GetCardNotFace(deskComponent, handCardsComponent); } } //庄家多发一张牌 GetCardNotFace(deskComponent, bankerHandCards); // List<MahjongInfo> infos = bankerHandCards.GetAll(); // bankerHandCards.library = new List<MahjongInfo>(list); //给客户端传送数据 Actor_StartGame actorStartGame = new Actor_StartGame(); foreach (var itemGame in gamers) { GamerData gamerData = new GamerData(); HandCardsComponent handCardsComponent = itemGame.GetComponent <HandCardsComponent>(); List <MahjongInfo> mahjongInfos = handCardsComponent.library; foreach (var mahjongInfo in mahjongInfos) { mahjongInfo.weight = (byte)mahjongInfo.m_weight; } gamerData.UserID = itemGame.UserID; gamerData.handCards = mahjongInfos; gamerData.faceCards = handCardsComponent.FaceCards; if (handCardsComponent.IsBanker) { gamerData.IsBanker = true; } gamerData.SeatIndex = room.seats[itemGame.UserID]; gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(itemGame.UserID); actorStartGame.GamerDatas.Add(gamerData); } actorStartGame.restCount = deskComponent.RestLibrary.Count; GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); if (room.IsFriendRoom) { actorStartGame.RoomType = 3; actorStartGame.CurrentJuCount = room.CurrentJuCount; } else { actorStartGame.RoomType = (int)gameControllerComponent.RoomConfig.Id; } //发送消息 room.Broadcast(actorStartGame); // Log.Debug("发送开始:" + JsonHelper.ToJson(actorStartGame)); //排序 var startTime = DateTime.Now; foreach (var _gamer in gamers) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); //排序 handCardsComponent.Sort(); handCardsComponent.GrabCard = handCardsComponent.GetAll()[handCardsComponent.GetAll().Count - 1]; //设置玩家在线开始时间 _gamer.StartTime = startTime; //await DBCommonUtil.RecordGamerTime(startTime, true, _gamer.UserID); } foreach (var _gamer in room.GetAll()) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> cards = handCardsComponent.GetAll(); if (handCardsComponent.IsBanker) { if (Logic_NJMJ.getInstance().isHuPai(cards)) { //ToDo 胡牌 Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; _gamer.IsCanHu = true; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); _gamer.isGangFaWanPai = true; } } else { //检查听牌 List <MahjongInfo> checkTingPaiList = Logic_NJMJ.getInstance().checkTingPaiList(cards); if (checkTingPaiList.Count > 0) { Log.Info($"{_gamer.UserID}听牌:"); _gamer.isFaWanPaiTingPai = true; } } } //等客户端掷骰子 //是否超时 await Game.Scene.GetComponent <TimerComponent>().WaitAsync(10 * 1000); room.StartTime(); //扣服务费 if (!room.IsFriendRoom) { //不要动画 GameHelp.CostServiceCharge(room, false); } } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
/// <summary> /// 抓牌 /// </summary> /// <param name="room"></param> /// <returns></returns> public static MahjongInfo GrabMahjong(this Room room) { try { OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); var currentGamer = room.Get(orderController.CurrentAuthority); HandCardsComponent cardsComponent = currentGamer.GetComponent <HandCardsComponent>(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); if (deskComponent.RestLibrary.Count == 0) { Log.Info("没牌了"); return(null); } MahjongInfo grabMahjong; if (room.NextGrabCard != null) { grabMahjong = new MahjongInfo() { m_weight = room.NextGrabCard.m_weight, weight = room.NextGrabCard.weight }; room.NextGrabCard = null; Log.Debug("发作弊牌:" + grabMahjong.m_weight); } else { int number = RandomHelper.RandomNumber(0, deskComponent.RestLibrary.Count); grabMahjong = deskComponent.RestLibrary[number]; deskComponent.RestLibrary.RemoveAt(number); Log.Info($"{currentGamer.UserID}发牌:" + grabMahjong.m_weight); } //花牌返回 if (grabMahjong.m_weight >= Consts.MahjongWeight.Hua_HongZhong) { return(grabMahjong); } //发牌 cardsComponent.AddCard(grabMahjong); room.my_lastMahjong = grabMahjong; cardsComponent.GrabCard = grabMahjong; Logic_NJMJ.getInstance().SortMahjong(cardsComponent.GetAll()); //发送抓牌消息 ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Gamer _gamer in room.gamers) { if (_gamer == null || _gamer.isOffline) { continue; } UnitGateComponent unitGateComponent = _gamer?.GetComponent <UnitGateComponent>(); Actor_GamerGrabCard actorGamerGrabCard; if (_gamer.UserID == orderController.CurrentAuthority) { actorGamerGrabCard = new Actor_GamerGrabCard() { Uid = currentGamer.UserID, weight = (int)grabMahjong.m_weight }; } else { actorGamerGrabCard = new Actor_GamerGrabCard() { Uid = currentGamer.UserID, }; } actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(actorGamerGrabCard); } //发完牌判断是否胡牌 foreach (Gamer _gamer in room.gamers) { if (_gamer == null || _gamer.isOffline) { continue; } if (_gamer.UserID == orderController.CurrentAuthority) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); //判断胡牌 if (Logic_NJMJ.getInstance().isHuPai(handCardsComponent.GetAll())) { _gamer.huPaiNeedData.my_lastMahjong = room.my_lastMahjong; _gamer.huPaiNeedData.restMahjongCount = deskComponent.RestLibrary.Count; _gamer.huPaiNeedData.isSelfZhuaPai = orderController.CurrentAuthority == _gamer.UserID; _gamer.huPaiNeedData.isZhuangJia = handCardsComponent.IsBanker; _gamer.huPaiNeedData.isGetYingHuaBuPai = _gamer.isGetYingHuaBuPai; _gamer.huPaiNeedData.isGangEndBuPai = _gamer.isGangEndBuPai; _gamer.huPaiNeedData.isGangFaWanPai = _gamer.isGangFaWanPai; _gamer.huPaiNeedData.isFaWanPaiTingPai = _gamer.isFaWanPaiTingPai; _gamer.huPaiNeedData.my_yingHuaList = handCardsComponent.FaceCards; _gamer.huPaiNeedData.my_gangList = handCardsComponent.GangCards; _gamer.huPaiNeedData.my_pengList = handCardsComponent.PengCards; List <List <MahjongInfo> > tempList = new List <List <MahjongInfo> >(); for (int i = 0; i < room.GetAll().Length; i++) { if (_gamer.UserID == room.GetAll()[i].UserID) { continue; } tempList.Add(room.GetAll()[i].GetComponent <HandCardsComponent>().PengCards); } _gamer.huPaiNeedData.other1_pengList = tempList[0]; _gamer.huPaiNeedData.other2_pengList = tempList[1]; _gamer.huPaiNeedData.other3_pengList = tempList[2]; List <Consts.HuPaiType> huPaiTypes = Logic_NJMJ.getInstance().getHuPaiType(handCardsComponent.GetAll(), _gamer.huPaiNeedData); Log.Info(JsonHelper.ToJson(_gamer.huPaiNeedData)); Log.Info(JsonHelper.ToJson(huPaiTypes)); if (huPaiTypes.Count > 0) { //判断小胡,4个花以上才能胡 if (huPaiTypes[0] == Consts.HuPaiType.Normal) { if (handCardsComponent.PengGangCards.Count > 0 || handCardsComponent.PengCards.Count > 0) { if (handCardsComponent.FaceCards.Count >= 4) { _gamer.IsCanHu = true; Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); } } } else { _gamer.IsCanHu = true; Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); } } } //暗杠 if (Logic_NJMJ.getInstance().IsAnGang(handCardsComponent.GetAll(), out var weight)) { _gamer.IsCanGang = true; Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; canOperation.OperationType = 4; room.GamerBroadcast(_gamer, canOperation); } //碰杠 else if (Logic_NJMJ.getInstance().IsPengGang(handCardsComponent.PengCards, handCardsComponent.GetAll(), out var weight2)) { _gamer.IsCanGang = true; Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; canOperation.OperationType = 5; room.GamerBroadcast(_gamer, canOperation); } } } return(grabMahjong); } catch (Exception e) { Log.Error(e); return(null); } }
/// <summary> /// 胡牌 /// </summary> /// <param name="gamer"></param> /// <param name="room"></param> /// <param name="mahjongInfos"></param> /// <param name="b"></param> private static int HuPai(Gamer gamer, Room room, List <MahjongInfo> mahjongInfos, bool isZimo) { room.IsZimo = isZimo; room.huPaiUid = gamer.UserID; if (!isZimo) { gamer.isGangEndBuPai = false; gamer.isGetYingHuaBuPai = false; } int huaCount = 0; DeskComponent deskComponent = room.GetComponent <DeskComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); Actor_GamerHuPai actorGamerHuPai = new Actor_GamerHuPai(); actorGamerHuPai.Uid = gamer.UserID; HuPaiNeedData huPaiNeedData = new HuPaiNeedData(); huPaiNeedData.my_lastMahjong = room.my_lastMahjong; huPaiNeedData.restMahjongCount = deskComponent.RestLibrary.Count; huPaiNeedData.isSelfZhuaPai = orderController.CurrentAuthority == gamer.UserID; huPaiNeedData.isZhuangJia = handCards.IsBanker; huPaiNeedData.isGetYingHuaBuPai = gamer.isGetYingHuaBuPai; huPaiNeedData.isGangEndBuPai = gamer.isGangEndBuPai; huPaiNeedData.isGangFaWanPai = gamer.isGangFaWanPai; huPaiNeedData.isFaWanPaiTingPai = gamer.isFaWanPaiTingPai; huPaiNeedData.my_yingHuaList = handCards.FaceCards; huPaiNeedData.my_gangList = handCards.GangCards; huPaiNeedData.my_pengList = handCards.PengCards; List <List <MahjongInfo> > temp = new List <List <MahjongInfo> >(); foreach (var _gamer in room.GetAll()) { _gamer.RemoveComponent <TrusteeshipComponent>(); if (_gamer.UserID == gamer.UserID) { continue; } HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); temp.Add(handCardsComponent.PengCards); //设置其他人的牌 GamerData gamerData = new GamerData(); gamerData.handCards = handCardsComponent.GetAll(); gamerData.UserID = _gamer.UserID; actorGamerHuPai.GamerDatas.Add(gamerData); } huPaiNeedData.other1_pengList = temp[0]; huPaiNeedData.other2_pengList = temp[1]; huPaiNeedData.other3_pengList = temp[2]; //比下胡 // if (room.IsLianZhuang) // { // if (room.BankerGamer.UserID == room.huPaiUid) // { // room.LiangZhuangCount++; // actorGamerHuPai.BixiaHuCount = room.LiangZhuangCount * 10; // } // } if (room.IsBiXiaHu) { actorGamerHuPai.BixiaHuCount = 20; } List <Consts.HuPaiType> huPaiTypes = Logic_NJMJ.getInstance().getHuPaiType(mahjongInfos, huPaiNeedData); foreach (var huPaiType in huPaiTypes) { if (huPaiType != Consts.HuPaiType.Normal) { room.LastBiXiaHu = true; } } //自摸 actorGamerHuPai.IsZiMo = isZimo; if (!isZimo) { actorGamerHuPai.FangPaoUid = orderController.CurrentAuthority; room.Get(orderController.CurrentAuthority).isFangPao = true; } else { gamer.isZimo = true; } //硬花 actorGamerHuPai.YingHuaCount = handCards.FaceCards.Count; //硬花 huaCount += handCards.FaceCards.Count; //软花 foreach (var pengorbar in handCards.PengOrBars) { //东南西北风 碰牌 if (pengorbar.OperateType == OperateType.Peng) { if (pengorbar.Weight >= 31 && pengorbar.Weight <= 37) { actorGamerHuPai.RuanHuaCount += 1; } } else { if (pengorbar.BarType == BarType.DarkBar) { //风牌暗杠 if (pengorbar.Weight >= 31 && pengorbar.Weight <= 37) { actorGamerHuPai.RuanHuaCount += 3; } //万条筒暗杠 else { actorGamerHuPai.RuanHuaCount += 2; } } else { //风牌明杠 if (pengorbar.Weight >= 31 && pengorbar.Weight <= 37) { actorGamerHuPai.RuanHuaCount += 2; } //万条筒明杠 else { actorGamerHuPai.RuanHuaCount += 1; } } } } int fengKeHuaShu = Logic_NJMJ.getInstance().getFengKeHuaShu(mahjongInfos); //将碰刚将入手牌 foreach (var pengorbar in handCards.PengOrBars) { if (pengorbar.OperateType == OperateType.Peng) { for (int i = 0; i < 3; i++) { mahjongInfos.Add(new MahjongInfo() { m_weight = (Consts.MahjongWeight)pengorbar.Weight, weight = (byte)pengorbar.Weight }); } } else { for (int i = 0; i < 4; i++) { mahjongInfos.Add(new MahjongInfo() { m_weight = (Consts.MahjongWeight)pengorbar.Weight, weight = (byte)pengorbar.Weight }); } } } int queYiMenHuaShu = Logic_NJMJ.getInstance().getQueYiMenHuaShu(mahjongInfos); actorGamerHuPai.RuanHuaCount += queYiMenHuaShu; actorGamerHuPai.RuanHuaCount += fengKeHuaShu; huaCount += actorGamerHuPai.RuanHuaCount; //胡牌类型 foreach (var type in huPaiTypes) { actorGamerHuPai.HuPaiTypes.Add((int)type); } room.Broadcast(actorGamerHuPai); room.IsGameOver = true; gamer.IsCanHu = false; gamer.IsWinner = true; foreach (var item in huPaiTypes) { Log.Info("有人胡牌:" + item.ToString()); } Log.Info("huPaiNeedData:" + JsonHelper.ToJson(huPaiNeedData)); //设置胡牌的花数 for (int j = 0; j < huPaiTypes.Count; j++) { Consts.HuPaiType huPaiType = (Consts.HuPaiType)huPaiTypes[j]; int count; Logic_NJMJ.getInstance().HuPaiHuaCount.TryGetValue(huPaiType, out count); //胡牌花 huaCount += count; } //基数 huaCount += 20; huaCount += actorGamerHuPai.BixiaHuCount; huaCount *= 2; return(huaCount); }
protected override async Task Run(Gamer gamer, Actor_GamerOperation message) { try { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); room.IsOperate = true; room.IsPlayingCard = false; room.IsNeedWaitOperate = false; if (room.IsGameOver) { return; } DeskComponent deskComponent = room.GetComponent <DeskComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); Gamer currentGamer = room.Get(orderController.CurrentAuthority); HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); if (handCards == null) { return; } List <MahjongInfo> mahjongInfos = handCards.GetAll(); Log.Info($"玩家{gamer.UserID}碰或刚{message.OperationType},当前出牌:{deskComponent.CurrentCard.m_weight}"); //胡牌 int huaCount = 0; if (message.OperationType == 2) { //自摸 bool isFinish = false; if (orderController.CurrentAuthority == gamer.UserID) { if (Logic_NJMJ.getInstance().isHuPai(mahjongInfos)) { huaCount = HuPai(gamer, room, mahjongInfos, true); room.huPaiUid = gamer.UserID; isFinish = true; } } //放炮 else { if (room.CanHu(deskComponent.CurrentCard, mahjongInfos)) { List <MahjongInfo> temp = new List <MahjongInfo>(mahjongInfos); temp.Add(deskComponent.CurrentCard); huaCount = HuPai(gamer, room, temp, false); isFinish = true; room.huPaiUid = gamer.UserID; room.fangPaoUid = orderController.CurrentAuthority; } } if (isFinish) { //游戏结束结算 await gameController.GameOver(huaCount); } gamer.IsCanHu = false; gamer.IsCanPeng = false; gamer.IsCanGang = false; } //放弃 else if (message.OperationType == 3) { Log.Debug("放弃:" + gamer.UserID); gamer.IsCanHu = false; gamer.IsCanPeng = false; gamer.IsCanGang = false; if (orderController.CurrentAuthority == gamer.UserID) { //room.tokenSource.Cancel(); } else { room.tokenSource.Cancel(); Log.Info($"{gamer.UserID}取消,发牌"); room.GamerGrabCard(); } } else { Actor_GamerOperation gamerOperation = new Actor_GamerOperation(); gamerOperation.Uid = gamer.UserID; gamerOperation.weight = deskComponent.CurrentCard.weight; //有没有人胡牌 while (true) { if (!GetCanHu(room, gamer)) { break; } await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000); } //游戏结束 if (room.IsGameOver) { Log.Warning("游戏结束不能碰刚"); return; } // 碰 if (message.OperationType == 0) { if (Logic_NJMJ.getInstance().isCanPeng(deskComponent.CurrentCard, mahjongInfos)) { room.tokenSource.Cancel(); //Log.Info("11111"); gamerOperation.OperationType = 0; gamerOperation.OperatedUid = deskComponent.CurrentAuthority; room.Broadcast(gamerOperation); //更新手牌 for (int i = 0; i < 2; i++) { int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, deskComponent.CurrentCard); mahjongInfos.RemoveAt(index); } //Log.Info("222222"); handCards.PengCards.Add(deskComponent.CurrentCard); currentGamer.GetComponent <HandCardsComponent>().PlayCards.Remove(deskComponent.CurrentCard); //添加碰的人 PengOrBar pengOrBar = ComponentFactory.Create <PengOrBar>(); pengOrBar.OperateType = OperateType.Peng; pengOrBar.Weight = deskComponent.CurrentCard.weight; pengOrBar.UserId = deskComponent.CurrentAuthority; pengOrBar.BarType = BarType.None; handCards.PengOrBars.Add(pengOrBar); Log.Debug("PengOrBars:" + handCards.PengOrBars.Count); //碰完当前玩家出牌 orderController.CurrentAuthority = gamer.UserID; room.StartTime(); } } // 杠 else { HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); gamerOperation.OperationType = message.OperationType; bool isSuccess = false; //明杠 if (Logic_NJMJ.getInstance().isCanGang(deskComponent.CurrentCard, mahjongInfos)) { isSuccess = true; //更新手牌 for (int i = 0; i < 3; i++) { int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, deskComponent.CurrentCard); mahjongInfos.RemoveAt(index); } handCards.GangCards.Add(deskComponent.CurrentCard); currentGamer.GetComponent <HandCardsComponent>().PlayCards.Remove(deskComponent.CurrentCard); //杠扣钱 GameHelp.ChangeGamerGold(room, gamer, 20 * gameController.RoomConfig.Multiples); GameHelp.ChangeGamerGold(room, currentGamer, -20 * gameController.RoomConfig.Multiples); //添加明杠 gamerOperation.OperatedUid = deskComponent.CurrentAuthority; PengOrBar pengOrBar = ComponentFactory.Create <PengOrBar>(); pengOrBar.OperateType = OperateType.Bar; pengOrBar.Weight = deskComponent.CurrentCard.weight; pengOrBar.UserId = deskComponent.CurrentAuthority; pengOrBar.BarType = BarType.LightBar; handCards.PengOrBars.Add(pengOrBar); } //暗杠 else if (Logic_NJMJ.getInstance().IsAnGang(handCardsComponent.GetAll(), out var weight)) { isSuccess = true; gamerOperation.weight = (int)weight; gamerOperation.OperationType = 4; MahjongInfo info = new MahjongInfo() { weight = (byte)weight, m_weight = (Consts.MahjongWeight)weight }; //更新手牌 for (int i = 0; i < 4; i++) { int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, info); mahjongInfos.RemoveAt(index); } handCards.GangCards.Add(info); //杠扣钱 foreach (var _gamer in room.GetAll()) { if (_gamer.UserID == gamer.UserID) { GameHelp.ChangeGamerGold(room, _gamer, 10 * gameController.RoomConfig.Multiples * 3); } else { GameHelp.ChangeGamerGold(room, _gamer, -10 * gameController.RoomConfig.Multiples); } } //添加暗杠 gamerOperation.OperatedUid = 0; PengOrBar pengOrBar = ComponentFactory.Create <PengOrBar>(); pengOrBar.OperateType = OperateType.Bar; pengOrBar.Weight = (int)weight; pengOrBar.UserId = 0; pengOrBar.BarType = BarType.DarkBar; handCards.PengOrBars.Add(pengOrBar); } //碰杠 else if (Logic_NJMJ.getInstance().IsPengGang(handCardsComponent.PengCards, handCardsComponent.GetAll(), out var weight1)) { isSuccess = true; gamerOperation.weight = weight1; gamerOperation.OperationType = 5; MahjongInfo info = new MahjongInfo() { weight = (byte)weight1, m_weight = (Consts.MahjongWeight)weight1 }; //更新手牌 for (int i = 0; i < 1; i++) { int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, info); mahjongInfos.RemoveAt(index); } handCardsComponent.PengCards.Remove(info); handCards.GangCards.Add(info); handCards.PengGangCards.Add(info); //添加碰杠 PengOrBar pengOrBar = null; foreach (var item in handCardsComponent.PengOrBars) { if (item.Weight == weight1 && item.OperateType == OperateType.Peng) { pengOrBar = item; } } if (pengOrBar == null) { Log.Error("碰刚的牌没有碰过"); return; } pengOrBar.OperateType = OperateType.Bar; pengOrBar.BarType = BarType.PengBar; gamerOperation.OperatedUid = pengOrBar.UserId; //杠扣钱 foreach (var _gamer in room.GetAll()) { if (_gamer.UserID == gamer.UserID) { GameHelp.ChangeGamerGold(room, _gamer, 20 * gameController.RoomConfig.Multiples); } else if (_gamer.UserID == pengOrBar.UserId) { GameHelp.ChangeGamerGold(room, _gamer, -20 * gameController.RoomConfig.Multiples); } } } if (isSuccess) { room.Broadcast(gamerOperation); //杠完之后不能 gamer.isFaWanPaiTingPai = false; gamer.isGangEndBuPai = true; gamer.isGetYingHuaBuPai = false; //杠完后是本人出牌 orderController.CurrentAuthority = gamer.UserID; //杠完之后抓牌 await room.GrabMahjongNoHua(gamer); #region 比下胡 累计2个暗杠或3个明杠(同一个玩家) int lightCount = handCards.PengOrBars.Count(c => c.BarType == BarType.LightBar); int darkCount = handCards.PengOrBars.Count(c => c.BarType == BarType.DarkBar); if (lightCount >= 3 || darkCount >= 2) { room.LastBiXiaHu = true; } #endregion } else { Log.Debug("不能杠"); } } } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
/// <summary> /// 游戏结束 /// </summary> /// <param name="self"></param> /// <param name="huaCount"></param> public static async Task GameOver(this GameControllerComponent self, int huaCount) { RoomComponent roomComponent = null; Room room = null; try { room = self.GetParent <Room>(); room.IsGameOver = true; room.tokenSource.Cancel(); roomComponent = Game.Scene.GetComponent <RoomComponent>(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>(); deskComponent.RestLibrary.Clear(); if (huaCount == 0) { //没牌 room.huPaiUid = 0; room.fangPaoUid = 0; room.LiangZhuangCount = 0; room.Broadcast(new Actor_GameFlow()); //流局 room.LastBiXiaHu = true; } await ChangeWeath(self, huaCount, room); if (room.huPaiUid != 0) { await DBCommonUtil.RecordWeekRankLog(room.huPaiUid, 0, 1); } Log.Info( $"当前{room.CurrentJuCount}局,改变了{room.GetAll()[0].ChangeGold},{room.GetAll()[1].ChangeGold},{room.GetAll()[2].ChangeGold},{room.GetAll()[3].ChangeGold}"); //更新任务 List <Task> tasks = new List <Task>(); Task updateTask = UpdateTask(room); Task updateChengjiu = UpdateChengjiu(room); Task updatePlayerInfo = UpdatePlayerInfo(room, huaCount); //记录对局 Task logGame = DBCommonUtil.Log_Game( controllerComponent.RoomConfig.Name, room.GetAll()[0].UserID, room.GetAll()[1].UserID, room.GetAll()[2].UserID, room.GetAll()[3].UserID, room.huPaiUid, self.RoomConfig.FriendRoomId, room.GetAll()[0].UserID + ";" + room.GetAll()[0].playerBaseInfo.Name + ";" + room.GetAll()[0].ChangeGold, room.GetAll()[1].UserID + ";" + room.GetAll()[1].playerBaseInfo.Name + ";" + room.GetAll()[1].ChangeGold, room.GetAll()[2].UserID + ";" + room.GetAll()[2].playerBaseInfo.Name + ";" + room.GetAll()[2].ChangeGold, room.GetAll()[3].UserID + ";" + room.GetAll()[3].playerBaseInfo.Name + ";" + room.GetAll()[3].ChangeGold ); tasks.Add(updateTask); tasks.Add(updateChengjiu); tasks.Add(updatePlayerInfo); tasks.Add(logGame); await Task.WhenAll(tasks); //设置在线时长 foreach (var gamer in room.GetAll()) { //在线 if (!gamer.isOffline) { gamer.EndTime = DateTime.Now; TimeSpan span = gamer.EndTime - gamer.StartTime; int totalSeconds = (int)span.TotalSeconds; //await DBCommonUtil.RecordGamerTime(gamer.EndTime, false, gamer.UserID); await DBCommonUtil.RecordGamerInfo(gamer.UserID, totalSeconds); } } foreach (var gamer in room.GetAll()) { if (gamer == null) { continue; } gamer.RemoveComponent <HandCardsComponent>(); gamer.IsReady = false; gamer.ReadyTimeOut = 0; gamer.isGangFaWanPai = false; gamer.isFaWanPaiTingPai = false; gamer.isGangEndBuPai = false; gamer.isGetYingHuaBuPai = false; gamer.IsCanPeng = false; gamer.IsCanGang = false; gamer.IsCanHu = false; gamer.IsWinner = false; gamer.IsTrusteeship = false; gamer.ChangeGold = 0; //离线踢出 if (gamer.isOffline && !room.IsFriendRoom) { Log.Info($"玩家{gamer.UserID}结束游戏后离线踢出,移除玩家"); room.Remove(gamer.UserID); gamer.isOffline = !gamer.isOffline; } } #region 好友房设置 if (room.IsFriendRoom) { //打完啦。可以解散了 if (room.CurrentJuCount == self.RoomConfig.JuCount) { //等待结算界面结束 await Game.Scene.GetComponent <TimerComponent>().WaitAsync(5000); Log.Debug("好友房间打完了"); room.Broadcast(new Actor_GamerReadyTimeOut() { Message = "房间解散" }); GameHelp.RoomDispose(room); return; } else { Log.Debug("还没打完"); room.StartReady(); } } #endregion room.State = RoomState.Idle; room.IsLianZhuang = true; //游戏房间进入准备房间 roomComponent.gameRooms.Remove(room.Id); roomComponent.idleRooms.Add(room.Id, room); //房间没人就释放 if (room.seats.Count == 0) { Log.Info($"房间释放:{room.Id}"); roomComponent.RemoveRoom(room); room?.Dispose(); } } catch (Exception e) { Log.Error("房间结算:" + e); //游戏房间进入准备房间 roomComponent?.gameRooms.Remove(room.Id); roomComponent?.idleRooms.Add(room.Id, room); } }
public static async Task PlayCard(Gamer gamer, Actor_GamerPlayCard message) { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null || room.IsGameOver) { return; } try { MahjongInfo mahjongInfo = new MahjongInfo() { weight = (byte)message.weight, m_weight = (Consts.MahjongWeight)message.weight }; //加锁 if (room.IsPlayingCard) { Log.Warning("当前正在出牌,不能再出牌了"); return; } room.IsPlayingCard = true; GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); if (handCardsComponent == null) { return; } List <MahjongInfo> mahjongInfos = handCardsComponent.GetAll(); if (orderController.CurrentAuthority != gamer.UserID) { Log.Warning("没有轮到当前玩家出牌:" + gamer.UserID); Log.Warning("当前出牌玩家:" + orderController.CurrentAuthority); room.IsPlayingCard = false; return; } int index = -1; for (int i = 0; i < mahjongInfos.Count; i++) { if (mahjongInfos[i].m_weight == mahjongInfo.m_weight) { index = i; break; } } if (index >= 0) { //停止倒计时 room?.tokenSource?.Cancel(); Log.Info($"玩家{gamer.UserID}出牌:" + mahjongInfo.m_weight); //当前出的牌 deskComponent.CurrentCard = mahjongInfo; deskComponent.CurrentAuthority = gamer.UserID; handCardsComponent.PlayCards.Add(mahjongInfo); mahjongInfos.RemoveAt(index); room.my_lastMahjong = mahjongInfo; Actor_GamerPlayCard actorGamerPlayCard = new Actor_GamerPlayCard() { weight = message.weight, Uid = gamer.UserID, index = message.index }; room.Broadcast(actorGamerPlayCard); gamer.IsCanHu = false; gamer.IsCanPeng = false; gamer.IsCanGang = false; #region 4个人连续出同样的牌,第一个出牌的人立即支付其他三人 List <MahjongInfo> list = new List <MahjongInfo>(); foreach (var _gamer in room.GetAll()) { HandCardsComponent cardsComponent = _gamer.GetComponent <HandCardsComponent>(); if (cardsComponent.PlayCards.Count > 0) { list.Add(cardsComponent.PlayCards[cardsComponent.PlayCards.Count - 1]); } } if (list.Count == 4) { bool flag = true; for (int i = 1; i < list.Count; i++) { if (list[0].m_weight != list[i].m_weight) { flag = false; break; } } if (flag) { Gamer nextGamer = orderController.FindNextGamer(gamer.UserID); //罚分 foreach (var _gamer in room.GetAll()) { if (_gamer.UserID == nextGamer.UserID) { GameHelp.ChangeGamerGold(room, _gamer, -10 * gameController.RoomConfig.Multiples * 3); } else { GameHelp.ChangeGamerGold(room, _gamer, 10 * gameController.RoomConfig.Multiples); } room.GamerBroadcast(_gamer, new Actor_ShowAnimType() { Type = 3, Count = 0 }); } room.LastBiXiaHu = true; } } #endregion #region 一个人出4张一样的牌 //4个人出一样的牌 int temp = 0; foreach (var playCard in handCardsComponent.PlayCards) { if (playCard.m_weight == mahjongInfo.m_weight) { temp++; } } if (temp == 4) { //罚分 foreach (var _gamer in room.GetAll()) { if (_gamer.UserID == gamer.UserID) { GameHelp.ChangeGamerGold(room, _gamer, -10 * gameController.RoomConfig.Multiples * 3); } else { GameHelp.ChangeGamerGold(room, _gamer, 10 * gameController.RoomConfig.Multiples); } room.GamerBroadcast(_gamer, new Actor_ShowAnimType() { Type = 3, Count = 0 }); } room.LastBiXiaHu = true; } #endregion #region 一人前四次出牌打出东南西北(不必按顺序),则其他每名玩家立即支付给该玩家 if (handCardsComponent.PlayCards.Count == 4) { int Feng_Dong = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Dong); int Feng_Nan = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Nan); int Feng_Xi = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Xi); int Feng_Bei = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Bei); if (Feng_Dong == 1 && Feng_Nan == 1 && Feng_Xi == 1 && Feng_Bei == 1) { //四连风 foreach (var _gamer in room.GetAll()) { if (_gamer.UserID == gamer.UserID) { GameHelp.ChangeGamerGold(room, _gamer, 5 * gameController.RoomConfig.Multiples * 3); } else { GameHelp.ChangeGamerGold(room, _gamer, -5 * gameController.RoomConfig.Multiples); } room.GamerBroadcast(_gamer, new Actor_ShowAnimType() { Type = 2, Count = 0 }); } } } #endregion #region 等待客户端有没有人碰杠胡 //等待客户端有没有人碰 bool isNeedWait = false; foreach (var _gamer in room.GetAll()) { if (_gamer == null) { continue; } if (_gamer.UserID == gamer.UserID) { continue; } HandCardsComponent currentCards = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> cards = _gamer.GetComponent <HandCardsComponent>().GetAll(); if (Logic_NJMJ.getInstance().isCanPeng(mahjongInfo, cards)) { Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; _gamer.IsCanPeng = true; isNeedWait = true; canOperation.OperationType = 0; //Log.Info($"{_gamer.UserID}可碰:"+JsonHelper.ToJson(canOperation)); room.GamerBroadcast(_gamer, canOperation); } //明杠 if (Logic_NJMJ.getInstance().isCanGang(mahjongInfo, cards)) { Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; _gamer.IsCanGang = true; isNeedWait = true; canOperation.OperationType = 1; //Log.Info($"{_gamer.UserID}可杠" + JsonHelper.ToJson(canOperation)); room.GamerBroadcast(_gamer, canOperation); } if (room.CanHu(mahjongInfo, cards)) { _gamer.huPaiNeedData.my_lastMahjong = room.my_lastMahjong; _gamer.huPaiNeedData.restMahjongCount = deskComponent.RestLibrary.Count; _gamer.huPaiNeedData.isSelfZhuaPai = orderController.CurrentAuthority == _gamer.UserID; _gamer.huPaiNeedData.isZhuangJia = currentCards.IsBanker; _gamer.huPaiNeedData.isGetYingHuaBuPai = _gamer.isGetYingHuaBuPai; _gamer.huPaiNeedData.isGangEndBuPai = _gamer.isGangEndBuPai; _gamer.huPaiNeedData.isGangFaWanPai = _gamer.isGangFaWanPai; _gamer.huPaiNeedData.isFaWanPaiTingPai = _gamer.isFaWanPaiTingPai; _gamer.huPaiNeedData.my_yingHuaList = currentCards.FaceCards; _gamer.huPaiNeedData.my_gangList = currentCards.GangCards; _gamer.huPaiNeedData.my_pengList = currentCards.PengCards; List <List <MahjongInfo> > tempList = new List <List <MahjongInfo> >(); for (int i = 0; i < room.GetAll().Length; i++) { if (_gamer.UserID == room.GetAll()[i].UserID) { continue; } tempList.Add(room.GetAll()[i].GetComponent <HandCardsComponent>().PengCards); } _gamer.huPaiNeedData.other1_pengList = tempList[0]; _gamer.huPaiNeedData.other2_pengList = tempList[1]; _gamer.huPaiNeedData.other3_pengList = tempList[2]; List <MahjongInfo> infos = new List <MahjongInfo>(cards); infos.Add(mahjongInfo); List <Consts.HuPaiType> huPaiTypes = Logic_NJMJ.getInstance().getHuPaiType(infos, _gamer.huPaiNeedData); Log.Info(JsonHelper.ToJson(_gamer.huPaiNeedData)); Log.Info(JsonHelper.ToJson(huPaiTypes)); if (huPaiTypes.Count > 0) { //判断小胡,4个花以上才能胡 if (huPaiTypes[0] == Consts.HuPaiType.Normal) { if (currentCards.PengGangCards.Count > 0 || currentCards.PengCards.Count > 0) { if (currentCards.FaceCards.Count >= 4) { _gamer.IsCanHu = true; isNeedWait = true; Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); } } } else { _gamer.IsCanHu = true; isNeedWait = true; Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); } } } } #endregion if (isNeedWait) { room.IsNeedWaitOperate = true; room.StartOperateTime(); } //没人可以操作就直接发牌 else { room.IsNeedWaitOperate = false; //发牌 room.GamerGrabCard(); room.IsPlayingCard = false; } } else { Log.Warning("玩家出牌不存在:" + message.weight); room.IsPlayingCard = false; } } catch (Exception e) { Log.Error(e); room.IsPlayingCard = false; } await Task.CompletedTask; }