protected override async Task Run(Gamer gamer, Actor_GamerCancelTrusteeship message)
 {
     Log.Info($"玩家{gamer.UserID}取消托管");
     try
     {
         RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
         Room          room          = roomComponent.Get(gamer.RoomID);
         if (room == null)
         {
             return;
         }
         gamer.IsTrusteeship = false;
         //在自己出牌的时候取消托管
         OrderControllerComponent orderControllerComponent = room.GetComponent <OrderControllerComponent>();
         //当前出牌是自己,并且外面没有碰刚
         Log.Info($"IsNeedWaitOperate:{room.IsNeedWaitOperate}");
         if (orderControllerComponent.CurrentAuthority == gamer.UserID && !room.IsNeedWaitOperate)
         {
             room.StartTime(8);
         }
         room.Broadcast(new Actor_GamerCancelTrusteeship()
         {
             Uid = gamer.UserID
         });
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
     await Task.CompletedTask;
 }
        public static async ETTask DestroyRoom(this RoomComponent self, long id)
        {
            Room room = self.Get(id);

            if (room == null)
            {
                return;
            }

            switch (room.Type)
            {
            case RoomType.Roaming:
            {
                self.RoamingSettingDict.Remove(room.info.RoadSettingId);
                self.RoamingList.Remove(room);
                await self.MemorySync.Delete <Room>(id);
            }
            break;

            case RoomType.Team:
            {
                self.TeamList.Remove(room);
                await self.MemorySync.Delete <Room>(id);
            }
            break;
            }
        }
        protected override async Task Run(Gamer gamer, Actor_GamerCancelRoomDismiss message)
        {
            try
            {
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null || !room.IsFriendRoom || gamer.DismissState != DismissState.None)
                {
                    return;
                }

                gamer.DismissState = DismissState.Cancel;
                room.Broadcast(new Actor_GamerCancelRoomDismiss()
                {
                    UserId = gamer.UserID
                });

                Gamer[] gamers = room.GetAll();

                if (gamers.Count(g => g.DismissState == DismissState.Cancel) == 2)
                {
                    room.roomDismissTokenSource?.Cancel();
                    foreach (var _gamer in gamers)
                    {
                        _gamer.DismissState = DismissState.None;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            await Task.CompletedTask;
        }
Esempio n. 4
0
        protected override async Task Run(Gamer gamer, Actor_GamerCheat message)
        {
            try
            {
                Log.Info("收到作弊:" + JsonHelper.ToJson(message));
                if (string.IsNullOrEmpty(message.Info))
                {
                    return;
                }
                string[]      split         = message.Info.Split(' ');
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);

                HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>();

                if (handCardsComponent == null)
                {
                    handCardsComponent = gamer.AddComponent <HandCardsComponent>();
                }

                if (split.Length == 13)
                {
                    List <MahjongInfo> mahjongInfos = new List <MahjongInfo>();
                    foreach (var item in split)
                    {
                        mahjongInfos.Add(new MahjongInfo()
                        {
                            m_weight = (Consts.MahjongWeight)Convert.ToInt32(item),
                            weight   = (byte)Convert.ToInt32(item)
                        });
                    }

                    handCardsComponent.library = mahjongInfos;
                    Logic_NJMJ.getInstance().SortMahjong(handCardsComponent.library);

                    Actor_GamerCheat actorCheat = new Actor_GamerCheat();
                    actorCheat.handCards = mahjongInfos;

                    room.GamerBroadcast(gamer, actorCheat);
                }
                else if (split.Length == 1)
                {
                    int num = Convert.ToInt32(split[0]);
                    room.NextGrabCard = new MahjongInfo()
                    {
                        m_weight = (Consts.MahjongWeight)num,
                        weight   = (byte)num
                    };
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            await Task.CompletedTask;
        }
Esempio n. 5
0
        public static Room Remove(this RoomComponent self, string id)
        {
            Room room = self.Get(id);

            self.rooms.Remove(id);
            Dictionary <int, Gamer> gamers = room.GetAll();

            foreach (var gamer in gamers.Values)
            {
                self.Remove(gamer.UserID);
            }
            return(room);
        }
        protected override async Task Run(Gamer gamer, Actor_GamerApplyRoomDismiss message)
        {
            try
            {
                Log.Info($"玩家{gamer.UserID}申请解散房间");
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null)
                {
                    return;
                }
                if (!room.IsFriendRoom)
                {
                    return;
                }

                GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>();
                if (room.State == RoomState.Idle)
                {
                    if (gamer.UserID != gameControllerComponent.RoomConfig.MasterUserId)
                    {
                        Log.Warning($"准备阶段只有房主才能解散,房主:{gameControllerComponent.RoomConfig.MasterUserId},gamer:{gamer.UserID}");
                        return;
                    }
                    else
                    {
                        if (room.CurrentJuCount > 0)
                        {
                            return;
                        }
                        room.Broadcast(new Actor_GamerReadyTimeOut()
                        {
                            Message = "房主解散房间"
                        });
                        GameHelp.RoomDispose(room);
                        return;
                    }
                }

                room.Broadcast(new Actor_GamerApplyRoomDismiss());
                room.WaitDismiss(60);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
Esempio n. 7
0
        protected override async Task Run(Gamer gamer, Actor_GamerKickOff message)
        {
            try
            {
                Log.Info($"收到房主{gamer.UserID}踢人 {message.KickedUserId}");
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null || room.State == RoomState.Game || !room.IsFriendRoom)
                {
                    return;
                }

                long masterUserId = room.GetComponent <GameControllerComponent>().RoomConfig.MasterUserId;

                if (masterUserId != gamer.UserID)
                {
                    Log.Error("只有房主才能踢人");
                    return;
                }

                Gamer kickedGamer = room.Get(message.KickedUserId);
                if (kickedGamer == null)
                {
                    return;
                }

                room.GamerBroadcast(kickedGamer, new Actor_GamerReadyTimeOut()
                {
                    Message = "被房主踢出"
                });

                //房间移除玩家
                Log.Info($"{kickedGamer.UserID}被房主踢出,移除玩家");
                room.Remove(kickedGamer.UserID);
                //消息广播给其他人
                room.Broadcast(new Actor_GamerExitRoom()
                {
                    Uid = kickedGamer.UserID
                });
                kickedGamer.Dispose();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
Esempio n. 8
0
 protected override async Task Run(Gamer gamer, Actor_Chat message)
 {
     try
     {
         Log.Debug("收到表情:" + JsonHelper.ToJson(message));
         RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
         Room          room          = roomComponent.Get(gamer.RoomID);
         room.Broadcast(new Actor_Chat {
             ChatType = message.ChatType, Value = message.Value, UId = message.UId
         });
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
     await Task.CompletedTask;
 }
Esempio n. 9
0
        public static void CheckAndDestoryRoom(this RoomComponent roomComponent, long Roomid, long Userid)
        {
            Room room = roomComponent.Get(Roomid);

            if (room == null)
            {
                return;
            }
            if (room.Count <= 1)
            {
                roomComponent.Remove(Roomid);
                room.Dispose();
            }
            else
            {
                room.Delete(Userid);
            }
        }
Esempio n. 10
0
        protected async ETVoid RunAsync(Session session, C2G_EnterRoom message, Action <G2C_EnterRoom> reply)
        {
            G2C_EnterRoom response = new G2C_EnterRoom();

            try
            {
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();

                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                Room room = roomComponent.Get(message.RoomId);

                if (room == null)
                {
                    Log.Error($"不存在房间{message.RoomId}");

                    response.Error = ErrorCode.ERR_RpcFail;
                }

                if (room.Add(player) == null)
                {
                    Log.Error($"房间已满,或者玩家{player.UserDB.GetComponent<UserBaseComponent>().UserName}已经存在房间{room.RoomName}中");

                    response.Error = ErrorCode.ERR_RpcFail;
                }

                room.BroadcastRoomDetailInfo();

                BroadcastMessage.Send_G2C_Rooms();

                await ETTask.CompletedTask;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Esempio n. 11
0
        public static async Task GamerAgreeRoomDismiss(Gamer gamer)
        {
            try
            {
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null || !room.IsFriendRoom || gamer.DismissState != DismissState.None)
                {
                    return;
                }

                gamer.DismissState = DismissState.Agree;
                room.Broadcast(new Actor_GamerAgreeRoomDismiss()
                {
                    UserId = gamer.UserID
                });

                Gamer[] gamers = room.GetAll();

                if (gamers.Count(g => g.DismissState == DismissState.Agree) == 3)
                {
                    room.roomDismissTokenSource?.Cancel();
                    room.Broadcast(new Actor_GamerReadyTimeOut()
                    {
                        Message = "房间已解散"
                    });
                    GameHelp.RoomDispose(room);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            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;
        }
        public static async Task GamerContinue(Gamer gamer)
        {
            try
            {
                Log.Info($"玩家{gamer.UserID}继续游戏");

                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null)
                {
                    return;
                }

                GameControllerComponent  gameControllerComponent  = room.GetComponent <GameControllerComponent>();
                OrderControllerComponent orderControllerComponent = room.GetComponent <OrderControllerComponent>();

                gamer.ReadyTimeOut = 0;
                List <GamerInfo> Gamers = new List <GamerInfo>();
                for (int i = 0; i < room.GetAll().Length; i++)
                {
                    Gamer _gamer = room.GetAll()[i];
                    if (_gamer == null)
                    {
                        continue;
                    }
                    GamerInfo gamerInfo = new GamerInfo();
                    gamerInfo.UserID    = _gamer.UserID;
                    gamerInfo.SeatIndex = room.GetGamerSeat(_gamer.UserID);
                    gamerInfo.IsReady   = _gamer.IsReady;
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(gamerInfo.UserID);

                    //判断金币是否不够
                    if (!room.IsFriendRoom)
                    {
                        if (playerBaseInfo.GoldNum < gameControllerComponent.RoomConfig.MinThreshold)
                        {
                            room.GamerBroadcast(_gamer, new Actor_GamerReadyTimeOut()
                            {
                                Message = "金币不足"
                            });
                            room.Remove(_gamer.UserID);
                            _gamer.Dispose();
                            if (room.Count == 0)
                            {
                                GameHelp.RoomDispose(room);
                                return;
                            }
                            continue;
                        }
                    }

                    PlayerInfo playerInfo = PlayerInfoFactory.Create(playerBaseInfo);
                    gamerInfo.playerInfo = playerInfo;

                    Gamers.Add(gamerInfo);
                }

                Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom()
                {
                    RoomType = (int)gameControllerComponent.RoomConfig.Id,
                    Gamers   = Gamers
                };
                if (room.IsFriendRoom)
                {
                    actorGamerEnterRoom.RoomId         = gameControllerComponent.RoomConfig.FriendRoomId;
                    actorGamerEnterRoom.MasterUserId   = gameControllerComponent.RoomConfig.MasterUserId;
                    actorGamerEnterRoom.JuCount        = gameControllerComponent.RoomConfig.JuCount;
                    actorGamerEnterRoom.Multiples      = gameControllerComponent.RoomConfig.Multiples;
                    actorGamerEnterRoom.CurrentJuCount = room.CurrentJuCount;
                }

                room.Broadcast(actorGamerEnterRoom);

//                if (room.IsFriendRoom)
//                {
                await Actor_GamerReadyHandler.GamerReady(gamer, new Actor_GamerReady()
                {
                });

//                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
Esempio n. 14
0
        protected override async Task Run(Gamer gamer, Actor_GamerExitRoom message)
        {
            try
            {
                Log.Info($"玩家{gamer.UserID}退出房间");
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null)
                {
                    return;
                }

                if (room.State == RoomState.Game)
                {
                    if (gamer.isOffline)
                    {
                        return;
                    }
                    gamer.isOffline = true;
                    //玩家断开添加自动出牌组件
                    //if (gamer.GetComponent<TrusteeshipComponent>() == null)
                    //gamer.AddComponent<TrusteeshipComponent>();
                    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);

                    Log.Info($"玩家{gamer.UserID}断开,切换为自动模式");
                }
                else
                {
                    GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>();

                    //好友房还没开局房主掉线,房间解散
                    if (room.IsFriendRoom && room.State == RoomState.Idle && room.CurrentJuCount == 0)
                    {
                        if (gameControllerComponent.RoomConfig.MasterUserId == gamer.UserID)
                        {
                            room.Broadcast(new Actor_GamerReadyTimeOut()
                            {
                                Message = "房主解散房间"
                            });
                            GameHelp.RoomDispose(room);
                            return;
                        }
                    }
                    //好友房开局后,掉线后不能退出
                    if (room.IsFriendRoom && room.CurrentJuCount > 0 && room.CurrentJuCount < gameControllerComponent.RoomConfig.JuCount)
                    {
                        gamer.isOffline = true;
                        Log.Info($"{gamer.UserID} 好友房开局后,掉线后不能退出");
                        return;
                    }

                    //玩家主动退出 通知gate
                    if (message.IsFromClient)
                    {
                        ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
                        ActorMessageSender          actorMessageSender          = actorMessageSenderComponent.Get(gamer.PlayerID);
                        actorMessageSender.Send(new M2G_Actor_GamerExitRoom());

                        //消息广播给其他人
                        room.Broadcast(new Actor_GamerExitRoom()
                        {
                            Uid = gamer.UserID
                        });
                        //房间移除玩家
                        Log.Info($"{gamer.UserID}主动退出,移除玩家");
                        room.Remove(gamer.UserID);
                    }
                    else     //游戏崩溃
                    {
                        //房间移除玩家
                        Log.Info($"{gamer.UserID}崩溃退出,移除玩家");
                        room.Remove(gamer.UserID);
                        //消息广播给其他人
                        room.Broadcast(new Actor_GamerExitRoom()
                        {
                            Uid = gamer.UserID
                        });
                    }
                    gamer.Dispose();
                    //房间没人就释放
                    if (room.seats.Count == 0)
                    {
                        roomComponent.RemoveRoom(room);
                        room?.Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
        private static async Task ChangeTable(Gamer gamer)
        {
            try
            {
//                Log.Info("收到换桌:" + JsonHelper.ToJson(message));
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          gamerRoom     = roomComponent.Get(gamer.RoomID);
                if (gamerRoom == null || gamerRoom.IsFriendRoom)
                {
                    return;
                }
                if (gamerRoom.State == RoomState.Game)
                {
                    Log.Warning($"玩家{gamer.UserID}打牌过程中不能换桌");
                    return;
                }

                GameControllerComponent gameControllerComponent = gamerRoom.GetComponent <GameControllerComponent>();
                long roomType = gameControllerComponent.RoomConfig.Id;

                Room idleRoom = null;
                //获得空闲的房间
                foreach (var room in roomComponent.idleRooms.Values)
                {
                    if (room.Id != gamerRoom?.Id && room.Count < 4)
                    {
                        GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>();
                        if (controllerComponent.RoomConfig.Id == roomType)
                        {
                            idleRoom = room;
                            break;
                        }
                    }
                }

                if (idleRoom == null)
                {
                    idleRoom = RoomFactory.Create((int)roomType);
                    roomComponent.Add(idleRoom);
                }

                Log.Info($"收到玩家{gamer.UserID}换桌前:" + gamer.RoomID);
                //房间移除玩家
                gamerRoom?.Remove(gamer.UserID);
                //房间没人就释放
                if (gamerRoom?.seats.Count == 0)
                {
                    roomComponent.RemoveRoom(gamerRoom);
                    gamerRoom?.Dispose();
                }

                gamer.IsReady      = false;
                gamer.ReadyTimeOut = 0;
                idleRoom.Add(gamer);
                await idleRoom.BroadGamerEnter(gamer.UserID);

                Log.Info($"收到玩家{gamer.UserID}换桌后:" + gamer.RoomID);

                gamerRoom?.Broadcast(new Actor_GamerExitRoom()
                {
                    Uid = gamer.UserID
                });
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            await Task.CompletedTask;
        }
Esempio n. 16
0
        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;
        }
        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;
        }