コード例 #1
0
 public void ShowWeChat(string roomId)
 {
     this.roomId = roomId;
     GameHelp.SetRoomId(roomIdObj, Convert.ToInt32(roomId));
     // roomIdText.text = $"房间号:{roomId}";
     weChatBtn.gameObject.SetActive(true);
 }
コード例 #2
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            GameHelp.DeleteAllItem(FaceObj);
            FaceObj = null;
        }
コード例 #3
0
        /// <summary>
        /// 改变玩家财富
        /// </summary>
        /// <param name="self"></param>
        /// <param name="huaCount"></param>
        /// <param name="room"></param>
        /// <returns></returns>
        private static async Task ChangeWeath(GameControllerComponent self, int huaCount, Room room)
        {
            int amount = huaCount * self.RoomConfig.Multiples;

            if (huaCount > 0)
            {
                //改变财富
                foreach (var gamer in room.GetAll())
                {
                    //自摸
                    if (room.IsZimo)
                    {
                        if (gamer.UserID == room.huPaiUid)
                        {
                            GameHelp.ChangeGamerGold(room, gamer, amount * 3, self.RoomConfig.Name + "结算");
                            gamer.ChangeGold = amount * 3;
//                            await DBCommonUtil.ChangeWealth(gamer.UserID, 1, amount * 3,self.RoomConfig.Name + "结算");
                            UpdateTask(gamer, amount * 3);
                        }
                        else
                        {
//                            Log.Debug($"玩家:{gamer.UserID} 输了{amount}");
//                            await DBCommonUtil.ChangeWealth(gamer.UserID, 1, -amount, self.RoomConfig.Name + "结算");
                            GameHelp.ChangeGamerGold(room, gamer, -amount, self.RoomConfig.Name + "结算");
                            gamer.ChangeGold = -amount;
                        }
                    }
                    else
                    {
                        if (gamer.UserID == room.huPaiUid)
                        {
//                            await DBCommonUtil.ChangeWealth(gamer.UserID, 1, amount, self.RoomConfig.Name + "结算");
                            GameHelp.ChangeGamerGold(room, gamer, amount, self.RoomConfig.Name + "结算");
                            gamer.ChangeGold = amount;
                            UpdateTask(gamer, amount);
                        }
                        else
                        {
                            if (gamer.UserID == room.fangPaoUid)
                            {
//                                Log.Debug($"玩家:{gamer.UserID} 输了{amount}");
//                                await DBCommonUtil.ChangeWealth(gamer.UserID, 1, -amount, self.RoomConfig.Name + "结算");
                                GameHelp.ChangeGamerGold(room, gamer, -amount, self.RoomConfig.Name + "结算");
                                gamer.ChangeGold = -amount;
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        /// <summary>
        /// 继续游戏
        /// </summary>
        public void ContinueGamer()
        {
            players?.SetActive(false);
            this.changeTableBtn.gameObject.SetActive(true);
            this.readyBtn.gameObject.SetActive(true);
            this.desk.SetActive(false);
            this.trustship.SetActive(false);

            //碰刚按钮隐藏
            this.giveUpBtn.gameObject.SetActive(false);
            this.huBtn.gameObject.SetActive(false);
            this.gangBtn.gameObject.SetActive(false);
            this.pengBtn.gameObject.SetActive(false);

            this.head.GetComponentInParent <RectTransform>().gameObject.SetActive(true);
            players.SetActive(false);
            isTreasureFinish = true;
            treasure.SetActive(false);
            faceCardObj.SetActive(false);
            //剩余牌数
            restText.text = $"";
            GamerComponent gamerComponent = this.GetParent <UI>().GetComponent <GamerComponent>();

            gamerComponent.IsPlayed = false;
            Gamer[] gamers = gamerComponent.GetAll();

            foreach (var gamer in gamers)
            {
                if (gamer == null)
                {
                    continue;
                }
                gamer?.GetComponent <HandCardsComponent>()?.ClearAll();
                gamer?.GetComponent <GamerUIComponent>()?.zhuang.SetActive(false);
                gamer?.RemoveComponent <HandCardsComponent>();
            }

            foreach (var face in FacePanel)
            {
                GameHelp.DeleteAllItem(face.gameObject);
            }
        }
コード例 #6
0
        /// <summary>
        /// 其他人的牌
        /// </summary>
        /// <param name="messageMahjongs"></param>
        public void AddOtherCards(bool isBanker)
        {
            GameHelp.DeleteAllItem(CardBottom);
            this.grabObj = this.CreateCardSprite($"{this.Direction}_back1", this.grabPostionX, this.grabPostionY);

            if (!isBanker)
            {
                //grabObj.SetActive(false);
                grabObj.transform.localScale = Vector3.zero;
            }

            for (int i = 0; i < 13; i++)
            {
                GameObject cardSprite = this.CreateCardSprite($"{Direction}_back1", i * this.postionX, i * this.postionY);
            }

            if (Direction.Equals("left"))
            {
                grabObj.transform.SetAsLastSibling();
            }
        }
コード例 #7
0
        public void AddCards(List <MahjongInfo> mahjongs)
        {
            Logic_NJMJ.getInstance().SortMahjong(mahjongs);
            handCards.Clear();
            ItemCards.Clear();
            GameHelp.DeleteAllItem(CardBottom);

            for (int i = 0; i < mahjongs.Count; i++)
            {
                if (i > 12)
                {
                    AddCard(mahjongs[i], (mahjongs.Count - 1) * postionX + 30, 0, i);
                }
                else
                {
                    AddCard(mahjongs[i], postionX * i, postionY * i, i);
                }
            }

            handCards = mahjongs;
        }
コード例 #8
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;
        }
コード例 #9
0
 public void ChangeGold(int amount)
 {
     Log.Debug("改变财富");
     GameHelp.GoldChange(changeMoney.gameObject, amount);
 }
コード例 #10
0
        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;
        }
コード例 #11
0
        /// <summary>
        /// 给当前玩家发一张不是花牌的牌
        /// </summary>
        /// <param name="room"></param>
        /// <param name="currentGamer"></param>
        /// <returns></returns>
        public static async Task <MahjongInfo> GrabMahjongNoHua(this Room room, Gamer currentGamer)
        {
            GameControllerComponent gameController = room.GetComponent <GameControllerComponent>();
            HandCardsComponent      cardsComponent = currentGamer.GetComponent <HandCardsComponent>();
            var grabMahjong = GrabMahjong(room);

            if (grabMahjong == null)
            {
                Log.Info("没牌流局了");
                await gameController.GameOver(0);

                return(null);
            }
            while (grabMahjong.m_weight >= Consts.MahjongWeight.Hua_HongZhong)
            {
                Actor_GamerBuHua actorGamerBuHua = new Actor_GamerBuHua()
                {
                    Uid    = currentGamer.UserID,
                    weight = grabMahjong.weight
                };
                room.Broadcast(actorGamerBuHua);

                //从手牌中删除花牌
                Log.Info($"{currentGamer.UserID}补花,{grabMahjong.m_weight}");
                cardsComponent.FaceCards.Add(grabMahjong);
                cardsComponent.FaceGangCards.Add(grabMahjong);

                #region 花杠
                int temp = 0;
                foreach (var faceCard in cardsComponent.FaceCards)
                {
                    if (faceCard.m_weight == grabMahjong.m_weight)
                    {
                        temp++;
                    }
                }

                Logic_NJMJ.getInstance().SortMahjong(cardsComponent.FaceCards);
                //春夏秋冬
                for (int i = 0; i < cardsComponent.FaceGangCards.Count - 3; i++)
                {
                    if (cardsComponent.FaceCards[i + 3].m_weight - cardsComponent.FaceCards[i + 2].m_weight == 2 &&
                        cardsComponent.FaceCards[i + 2].m_weight - cardsComponent.FaceCards[i + 1].m_weight == 2 &&
                        cardsComponent.FaceCards[i + 1].m_weight - cardsComponent.FaceCards[i].m_weight == 2)
                    {
                        temp = 4;
                        cardsComponent.FaceGangCards.RemoveAt(i + 3);
                        cardsComponent.FaceGangCards.RemoveAt(i + 2);
                        cardsComponent.FaceGangCards.RemoveAt(i + 1);
                        cardsComponent.FaceGangCards.RemoveAt(i);
                    }
                }

                if (temp == 4)
                {
                    foreach (var _gamer in room.GetAll())
                    {
                        if (_gamer.UserID == currentGamer.UserID)
                        {
                            GameHelp.ChangeGamerGold(room, _gamer, 20 * gameController.RoomConfig.Multiples * 3);
                        }
                        else
                        {
                            GameHelp.ChangeGamerGold(room, _gamer, -20 * gameController.RoomConfig.Multiples);
                        }
                    }

                    room.LastBiXiaHu = true;
                }

                #endregion
                currentGamer.isGangEndBuPai    = false;
                currentGamer.isGetYingHuaBuPai = true;

                grabMahjong = GrabMahjong(room);

                if (grabMahjong == null)
                {
                    Log.Info("没牌流局了");
                    await gameController.GameOver(0);

                    return(null);;
                }
            }

            room.StartTime();
            return(grabMahjong);
        }
コード例 #12
0
        /// <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);
            }
        }
コード例 #13
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;
        }
コード例 #14
0
 public void SetGoldChange(int num)
 {
     GameHelp.ShowPlusGoldChange(changeMoney, num);
 }
コード例 #15
0
        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;
        }
コード例 #16
0
        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;
        }
コード例 #17
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;
        }