/// <summary>
        /// 准备开始游戏
        /// </summary>
        /// <param name="self"></param>
        public static void ReadyStartGame(this GameControllerComponent self)
        {
            Room room = self.GetParent <Room>();

            Gamer[] gamers = room.GetAll();

            //房间内有3名玩家且全部准备则开始游戏
            if (room.Count == 3 && gamers.Where(g => g.IsReady).Count() == 3)
            {
                //同步匹配服务器开始游戏
                room.State = RoomState.Game;
                MapHelper.SendMessage(new MP2MH_SyncRoomState_Ntt()
                {
                    RoomID = room.InstanceId, State = room.State
                });

                //初始玩家开始状态
                foreach (var _gamer in gamers)
                {
                    if (_gamer.GetComponent <HandCardsComponent>() == null)
                    {
                        _gamer.AddComponent <HandCardsComponent>();
                    }
                    _gamer.IsReady = false;
                }

                GameControllerComponent gameController = room.GetComponent <GameControllerComponent>();
                //洗牌发牌
                gameController.DealCards();

                List <GamerCardNum> gamersCardNum = new List <GamerCardNum>();
                Array.ForEach(gamers, (g) =>
                {
                    HandCardsComponent handCards = g.GetComponent <HandCardsComponent>();
                    //重置玩家身份
                    handCards.AccessIdentity = Identity.None;
                    //记录玩家手牌数
                    gamersCardNum.Add(new GamerCardNum()
                    {
                        UserID = g.UserID,
                        Num    = g.GetComponent <HandCardsComponent>().GetAll().Length
                    });
                });

                //发送玩家手牌和其他玩家手牌数
                foreach (var _gamer in gamers)
                {
                    ActorMessageSender  actorProxy       = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                    Actor_GameStart_Ntt gameStartMessage = new Actor_GameStart_Ntt();
                    gameStartMessage.HandCards.AddRange(_gamer.GetComponent <HandCardsComponent>().GetAll());
                    gameStartMessage.GamersCardNum.AddRange(gamersCardNum);
                    actorProxy.Send(gameStartMessage);
                }

                //随机先手玩家
                gameController.RandomFirstAuthority();

                Log.Info($"房间{room.InstanceId}开始游戏");
            }
        }
        /// <summary>
        /// 准备开始游戏
        /// </summary>
        /// <param name="self"></param>
        public static void StartGame(this GameControllerComponent self)
        {
            LandlordsRoom room = self.GetParent <LandlordsRoom>();

            Gamer[] gamers = room.gamers;

            //房间内有3名玩家且全部准备则开始游戏
            //if(room.Count == 3 && gamers.Where(g => g.IsReady).Count() == 3){}

            //初始玩家开始状态
            foreach (var _gamer in gamers)
            {
                if (_gamer.GetComponent <HandCardsComponent>() == null)
                {
                    _gamer.AddComponent <HandCardsComponent>();
                }
            }

            GameControllerComponent gameController = room.GetComponent <GameControllerComponent>();

            //洗牌发牌
            gameController.DealCards();

            List <GamerCardNum> gamersCardNum = new List <GamerCardNum>();

            Array.ForEach(gamers, (g) =>
            {
                HandCardsComponent handCards = g.GetComponent <HandCardsComponent>();
                //重置玩家身份
                handCards.AccessIdentity = Identity.None;
                //记录玩家手牌数
                gamersCardNum.Add(new GamerCardNum()
                {
                    UserID = g.UserID,
                    Num    = g.GetComponent <HandCardsComponent>().GetAll().Length
                });
            });

            //发送玩家手牌和其他玩家手牌数
            foreach (var _gamer in gamers)
            {
                ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
                ActorMessageSender          actorProxy          = actorProxyComponent.Get(_gamer.ActorIDofClient);

                actorProxy.Send(new Actor_GameStart_Ntt()
                {
                    HandCards     = To.RepeatedField(_gamer.GetComponent <HandCardsComponent>().GetAll()),
                    GamersCardNum = To.RepeatedField(gamersCardNum)
                });
            }

            //随机先手玩家
            gameController.RandomFirstAuthority();

            Log.Info($"房间{room.Id}开始游戏");
        }
        protected override void Run(Gamer gamer, Actor_GamerGrabLandlordSelect_Ntt message)
        {
            Room room = Game.Scene.GetComponent <RoomComponent>().Get(gamer.RoomID);
            OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
            GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();

            if (orderController.CurrentAuthority == gamer.UserID)
            {
                //保存抢地主状态
                orderController.GamerLandlordState[gamer.UserID] = message.IsGrab;

                if (message.IsGrab)
                {
                    orderController.Biggest   = gamer.UserID;
                    gameController.Multiples *= 2;
                    room.Broadcast(new Actor_SetMultiples_Ntt()
                    {
                        Multiples = gameController.Multiples
                    });
                }

                //转发消息
                Actor_GamerGrabLandlordSelect_Ntt transpond = new Actor_GamerGrabLandlordSelect_Ntt();
                transpond.IsGrab = message.IsGrab;
                transpond.UserID = gamer.UserID;
                room.Broadcast(transpond);

                if (orderController.SelectLordIndex >= room.Count)
                {
                    /*
                     * 地主:√ 农民1:× 农民2:×
                     * 地主:× 农民1:√ 农民2:√
                     * 地主:√ 农民1:√ 农民2:√ 地主:√
                     *
                     * */
                    if (orderController.Biggest == 0)
                    {
                        //没人抢地主则重新发牌
                        gameController.BackToDeck();
                        gameController.DealCards();

                        //发送玩家手牌
                        Gamer[]             gamers        = room.GetAll();
                        List <GamerCardNum> gamersCardNum = new List <GamerCardNum>();
                        Array.ForEach(gamers, _gamer => gamersCardNum.Add(new GamerCardNum()
                        {
                            UserID = _gamer.UserID,
                            Num    = _gamer.GetComponent <HandCardsComponent>().GetAll().Length
                        }));
                        Array.ForEach(gamers, _gamer =>
                        {
                            ActorMessageSender actorProxy    = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                            Actor_GameStart_Ntt actorMessage = new Actor_GameStart_Ntt();
                            actorMessage.HandCards.AddRange(_gamer.GetComponent <HandCardsComponent>().GetAll());
                            actorMessage.GamersCardNum.AddRange(gamersCardNum);
                        });

                        //随机先手玩家
                        gameController.RandomFirstAuthority();
                        return;
                    }
                    else if ((orderController.SelectLordIndex == room.Count &&
                              ((orderController.Biggest != orderController.FirstAuthority.Key && !orderController.FirstAuthority.Value) ||
                               orderController.Biggest == orderController.FirstAuthority.Key)) ||
                             orderController.SelectLordIndex > room.Count)
                    {
                        gameController.CardsOnTable(orderController.Biggest);
                        return;
                    }
                }

                //当所有玩家都抢地主时先手玩家还有一次抢地主的机会
                if (gamer.UserID == orderController.FirstAuthority.Key && message.IsGrab)
                {
                    orderController.FirstAuthority = new KeyValuePair <long, bool>(gamer.UserID, true);
                }

                orderController.Turn();
                orderController.SelectLordIndex++;
                room.Broadcast(new Actor_AuthorityGrabLandlord_Ntt()
                {
                    UserID = orderController.CurrentAuthority
                });
            }
        }
        public static async Task GamerReady(Gamer gamer, Actor_GamerReady message)
        {
            try
            {
                Log.Info($"收到玩家{gamer.UserID}准备");
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);

                if (room == null || gamer == null || gamer.IsReady || room.State == RoomState.Game)
                {
                    return;
                }

                gamer.IsReady = true;
                //消息广播给其他人
                room?.Broadcast(new Actor_GamerReady()
                {
                    Uid = gamer.UserID
                });

                Gamer[] gamers = room.GetAll();
                //房间内有4名玩家且全部准备则开始游戏
                if (room.Count == 4 && gamers.Where(g => g.IsReady).Count() == 4)
                {
                    room.State = RoomState.Game;
                    room.CurrentJuCount++;
                    room.IsGameOver = false;
                    room.RoomDispose();

                    #region 好友房扣钥匙

                    if (room.IsFriendRoom && room.CurrentJuCount == 1)
                    {
                        RoomConfig roomConfig = room.GetComponent <GameControllerComponent>().RoomConfig;
                        await DBCommonUtil.DeleteFriendKey(roomConfig.MasterUserId, roomConfig.KeyCount, "好友房房主扣除钥匙");
                    }
                    #endregion
                    //设置比下胡
                    if (room.LastBiXiaHu)
                    {
                        room.IsBiXiaHu = true;
                    }
                    else
                    {
                        room.IsBiXiaHu = false;
                    }
                    room.LastBiXiaHu = false;


                    if (roomComponent.gameRooms.TryGetValue(room.Id, out var itemRoom))
                    {
                        roomComponent.gameRooms.Remove(room.Id);
                    }

                    roomComponent.gameRooms.Add(room.Id, room);
                    roomComponent.idleRooms.Remove(room.Id);
                    //添加用户
                    room.UserIds.Clear();
                    //初始玩家开始状态
                    foreach (var _gamer in gamers)
                    {
                        room.UserIds.Add(_gamer.UserID);

                        if (_gamer.GetComponent <HandCardsComponent>() == null)
                        {
                            _gamer.AddComponent <HandCardsComponent>();
                        }

                        _gamer.IsReady = false;
                    }

                    Log.Info($"{room.Id}房间开始,玩家:{JsonHelper.ToJson(room.UserIds)}");


                    GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                    DeskComponent            deskComponent   = room.GetComponent <DeskComponent>();

                    Gamer bankerGamer = null;
                    HandCardsComponent bankerHandCards = null;
                    if (room.IsLianZhuang)
                    {
                        if (room.huPaiUid != 0 && room.huPaiUid == room.BankerGamer?.UserID)
                        {
                            bankerGamer              = room.Get(room.huPaiUid);
                            bankerHandCards          = bankerGamer.GetComponent <HandCardsComponent>();
                            bankerHandCards.IsBanker = true;
                            room.BankerGamer         = bankerGamer;
                            //连庄
                            room.LastBiXiaHu = true;
                        }
                        else
                        {
                            int gamerSeat = room.GetGamerSeat(room.BankerGamer.UserID);
                            int currentSeat;
                            if (gamerSeat == 3)
                            {
                                currentSeat = 0;
                            }
                            else
                            {
                                currentSeat = ++gamerSeat;
                            }

                            bankerGamer              = room.gamers[currentSeat];
                            bankerHandCards          = bankerGamer.GetComponent <HandCardsComponent>();
                            bankerHandCards.IsBanker = true;
                            room.BankerGamer         = bankerGamer;
                        }
                    }
                    else
                    {
                        if (room.IsFriendRoom)
                        {
                            GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>();
                            long masterUserId = controllerComponent.RoomConfig.MasterUserId;
                            bankerGamer = room.Get(masterUserId);
                        }
                        else
                        {
                            //随机庄家
                            int number = RandomHelper.RandomNumber(0, 12);
                            int i      = number % 4;
                            bankerGamer = room.gamers[i];
                        }
                        bankerHandCards          = bankerGamer.GetComponent <HandCardsComponent>();
                        bankerHandCards.IsBanker = true;
                        room.BankerGamer         = bankerGamer;
                    }

                    //发牌
                    gameController.DealCards();
                    orderController.Start(bankerGamer.UserID);

                    //去除花牌
                    foreach (var _gamer in gamers)
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                        List <MahjongInfo> handCards          = handCardsComponent.GetAll();

                        for (int j = handCards.Count - 1; j >= 0; j--)
                        {
                            MahjongInfo mahjongInfo = handCards[j];

                            if (mahjongInfo.m_weight >= Consts.MahjongWeight.Hua_HongZhong)
                            {
                                handCards.RemoveAt(j);
                                mahjongInfo.weight = (byte)mahjongInfo.m_weight;
                                handCardsComponent.FaceCards.Add(mahjongInfo);
                                handCardsComponent.FaceGangCards.Add(mahjongInfo);
                            }
                        }

                        //加牌
                        int handCardsCount = handCards.Count;
                        for (int j = 0; j < 13 - handCardsCount; j++)
                        {
                            GetCardNotFace(deskComponent, handCardsComponent);
                        }
                    }

                    //庄家多发一张牌
                    GetCardNotFace(deskComponent, bankerHandCards);

//	                List<MahjongInfo> infos = bankerHandCards.GetAll();
//	                bankerHandCards.library = new List<MahjongInfo>(list);

                    //给客户端传送数据
                    Actor_StartGame actorStartGame = new Actor_StartGame();
                    foreach (var itemGame in gamers)
                    {
                        GamerData          gamerData          = new GamerData();
                        HandCardsComponent handCardsComponent = itemGame.GetComponent <HandCardsComponent>();

                        List <MahjongInfo> mahjongInfos = handCardsComponent.library;
                        foreach (var mahjongInfo in mahjongInfos)
                        {
                            mahjongInfo.weight = (byte)mahjongInfo.m_weight;
                        }

                        gamerData.UserID    = itemGame.UserID;
                        gamerData.handCards = mahjongInfos;
                        gamerData.faceCards = handCardsComponent.FaceCards;
                        if (handCardsComponent.IsBanker)
                        {
                            gamerData.IsBanker = true;
                        }

                        gamerData.SeatIndex     = room.seats[itemGame.UserID];
                        gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(itemGame.UserID);

                        actorStartGame.GamerDatas.Add(gamerData);
                    }

                    actorStartGame.restCount = deskComponent.RestLibrary.Count;
                    GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>();

                    if (room.IsFriendRoom)
                    {
                        actorStartGame.RoomType       = 3;
                        actorStartGame.CurrentJuCount = room.CurrentJuCount;
                    }
                    else
                    {
                        actorStartGame.RoomType = (int)gameControllerComponent.RoomConfig.Id;
                    }
                    //发送消息
                    room.Broadcast(actorStartGame);
//	                Log.Debug("发送开始:" + JsonHelper.ToJson(actorStartGame));

                    //排序
                    var startTime = DateTime.Now;
                    foreach (var _gamer in gamers)
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                        //排序
                        handCardsComponent.Sort();
                        handCardsComponent.GrabCard = handCardsComponent.GetAll()[handCardsComponent.GetAll().Count - 1];
                        //设置玩家在线开始时间
                        _gamer.StartTime = startTime;
                        //await DBCommonUtil.RecordGamerTime(startTime, true, _gamer.UserID);
                    }

                    foreach (var _gamer in room.GetAll())
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();

                        List <MahjongInfo> cards = handCardsComponent.GetAll();

                        if (handCardsComponent.IsBanker)
                        {
                            if (Logic_NJMJ.getInstance().isHuPai(cards))
                            {
                                //ToDo 胡牌
                                Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                                canOperation.Uid           = _gamer.UserID;
                                _gamer.IsCanHu             = true;
                                canOperation.OperationType = 2;
                                room.GamerBroadcast(_gamer, canOperation);
                                _gamer.isGangFaWanPai = true;
                            }
                        }
                        else
                        {
                            //检查听牌
                            List <MahjongInfo> checkTingPaiList = Logic_NJMJ.getInstance().checkTingPaiList(cards);
                            if (checkTingPaiList.Count > 0)
                            {
                                Log.Info($"{_gamer.UserID}听牌:");
                                _gamer.isFaWanPaiTingPai = true;
                            }
                        }
                    }

                    //等客户端掷骰子
                    //是否超时
                    await Game.Scene.GetComponent <TimerComponent>().WaitAsync(10 * 1000);

                    room.StartTime();
                    //扣服务费
                    if (!room.IsFriendRoom)
                    {
                        //不要动画
                        GameHelp.CostServiceCharge(room, false);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
        /// <summary>
        /// 准备开始游戏
        /// </summary>
        /// <param name="self"></param>
        public static async void ReadyStartGame(this GameControllerComponent self)
        {
            Room room = self.GetParent <Room>();

            Gamer[] gamers = room.GetAll();
            if (room.State == RoomState.Game)
            {
                DeckComponent deck = room.GetComponent <DeckComponent>();
                Log.Info($"当前准备的玩家个数:{deck.XJReady}");
                if (deck.XJReady == self.Config.PlayerCount)
                {
                    Log.Info("重新开始游戏");
                    //重置庄
                    foreach (Gamer gamer in gamers)
                    {
                        gamer.IsRobBanker = false;
                        gamer.GetComponent <HandCardsComponent>().Reset();
                    }

                    //重新洗牌
                    self.DealCards();

                    //清理缓存数据
                    deck.Reset();

                    //发送游戏开始
                    room.Broadcast(new Actor_GamerStart_Ntt());

                    await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);

                    //发送手牌
                    foreach (var _gamer in gamers)
                    {
                        ActorMessageSender actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                        actorProxy.Send(new Actor_SendCard_Ntt()
                        {
                            Cards = _gamer.GetComponent <HandCardsComponent>().GetAll()
                        });
                        Log.Info($"{_gamer.UserID}手牌:{_gamer.GetComponent<HandCardsComponent>().ShowAllCard()}");
                    }

                    await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);
                }
            }
            if (room.State == RoomState.Idle)
            {
                if (room.Count == self.Config.PlayerCount && gamers.Count(model => model.IsReady) == self.Config.PlayerCount)
                {
                    room.State = RoomState.Game;
                    //所有玩家准备!!
                    //发送游戏开始
                    room.Broadcast(new Actor_GamerStart_Ntt());

                    await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);

                    self.DealCards();

                    foreach (var _gamer in gamers)
                    {
                        ActorMessageSender actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                        actorProxy.Send(new Actor_SendCard_Ntt()
                        {
                            Cards = _gamer.GetComponent <HandCardsComponent>().GetAll()
                        });
                        Log.Info($"{_gamer.UserID}手牌:{_gamer.GetComponent<HandCardsComponent>().ShowAllCard()}");
                    }

                    await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);

                    Log.Info("可以开始出牌了");
                }
            }
        }
Ejemplo n.º 6
0
        protected override Task Run(Room entity, PlayerReady message)
        {
            Gamer gamer = entity.Get(message.PlayerID);

            if (gamer != null)
            {
                gamer.IsReady = true;

                Gamer[] gamers = entity.GetAll();

                //转发玩家准备消息
                entity.Broadcast(message);
                Log.Info($"玩家{gamer.Id}准备");

                //房间内有3名玩家且全部准备则开始游戏
                if (entity.Count == 3 && gamers.Where(g => g.IsReady).Count() == 3)
                {
                    //同步匹配服务器开始游戏
                    entity.State = RoomState.Game;
                    MapHelper.SendMessage(new SyncRoomState()
                    {
                        RoomID = entity.Id, State = entity.State
                    });

                    //初始玩家开始状态
                    foreach (var _gamer in gamers)
                    {
                        if (_gamer.GetComponent <HandCardsComponent>() == null)
                        {
                            _gamer.AddComponent <HandCardsComponent>();
                        }
                        _gamer.IsReady = false;
                    }

                    GameControllerComponent gameController = entity.GetComponent <GameControllerComponent>();
                    //洗牌发牌
                    gameController.DealCards();

                    Dictionary <long, int> gamerCardsNum = new Dictionary <long, int>();
                    Array.ForEach(gamers, (g) =>
                    {
                        HandCardsComponent handCards = g.GetComponent <HandCardsComponent>();
                        //重置玩家身份
                        handCards.AccessIdentity = Identity.None;
                        //记录玩家手牌数
                        gamerCardsNum.Add(g.Id, handCards.CardsCount);
                    });

                    //发送玩家手牌和其他玩家手牌数
                    foreach (var _gamer in gamers)
                    {
                        ActorProxy actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorProxy();
                        actorProxy.Send(new GameStart()
                        {
                            GamerCards    = _gamer.GetComponent <HandCardsComponent>().GetAll(),
                            GamerCardsNum = gamerCardsNum
                        });
                    }

                    //随机先手玩家
                    gameController.RandomFirstAuthority();

                    Log.Info($"房间{entity.Id}开始游戏");
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 7
0
        protected override async Task Run(Gamer gamer, C2M_GamerGrabLandlordSelect message)
        {
            Room room = Game.Scene.GetComponent <RoomComponent>().Get(gamer.RoomID);
            OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
            GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();

            if (orderController.CurrentAuthority == gamer.UserID)
            {
                //保存抢地主状态
                orderController.GamerLandlordState[gamer.UserID] = message.IsGrab;

                if (message.IsGrab)
                {
                    orderController.Biggest   = gamer.UserID;
                    gameController.Multiples *= 2;
                    room.Broadcast(new M2C_SetMultiples()
                    {
                        Multiples = gameController.Multiples
                    });
                }

                //转发消息
                C2M_GamerGrabLandlordSelect transpond = new C2M_GamerGrabLandlordSelect();
                transpond.IsGrab = message.IsGrab;
                transpond.UserID = gamer.UserID;
                room.Broadcast(transpond);

                if (orderController.SelectLordIndex >= room.Count)
                {
                    /*
                     * 地主:√ 农民1:× 农民2:×
                     * 地主:× 农民1:√ 农民2:√
                     * 地主:√ 农民1:√ 农民2:√ 地主:√
                     *
                     * */
                    if (orderController.Biggest == 0)
                    {
                        //没人抢地主则重新发牌
                        gameController.BackToDeck();
                        gameController.DealCards();

                        //发送玩家手牌
                        Gamer[] gamers = room.GetAll();
                        Dictionary <long, int> gamerCardsNum = new Dictionary <long, int>();
                        Array.ForEach(gamers, _gamer => gamerCardsNum.Add(_gamer.UserID, _gamer.GetComponent <HandCardsComponent>().GetAll().Length));
                        Array.ForEach(gamers, _gamer =>
                        {
                            ActorProxy actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorProxy();
                            actorProxy.Send(new M2C_GameStart()
                            {
                                GamerCards    = _gamer.GetComponent <HandCardsComponent>().GetAll(),
                                GamerCardsNum = gamerCardsNum
                            });
                        });

                        //随机先手玩家
                        gameController.RandomFirstAuthority();
                        return;
                    }
                    else if ((orderController.SelectLordIndex == room.Count &&
                              ((orderController.Biggest != orderController.FirstAuthority.Key && !orderController.FirstAuthority.Value) ||
                               orderController.Biggest == orderController.FirstAuthority.Key)) ||
                             orderController.SelectLordIndex > room.Count)
                    {
                        gameController.CardsOnTable(orderController.Biggest);
                        return;
                    }
                }

                //当所有玩家都抢地主时先手玩家还有一次抢地主的机会
                if (gamer.UserID == orderController.FirstAuthority.Key && message.IsGrab)
                {
                    orderController.FirstAuthority = new KeyValuePair <long, bool>(gamer.UserID, true);
                }

                orderController.Turn(false);
                orderController.SelectLordIndex++;
                room.Broadcast(new M2C_AuthorityGrabLandlord()
                {
                    UserID = orderController.CurrentAuthority
                });
            }
            await Task.CompletedTask;
        }
Ejemplo n.º 8
0
        protected override Task Run(Room entity, GrabLordSelect message)
        {
            OrderControllerComponent orderController = entity.GetComponent <OrderControllerComponent>();
            GameControllerComponent  gameController  = entity.GetComponent <GameControllerComponent>();

            if (orderController.CurrentAuthority == message.PlayerId)
            {
                if (message.IsGrab)
                {
                    orderController.Biggest   = message.PlayerId;
                    gameController.Multiples *= 2;
                    entity.Broadcast(new GameMultiples()
                    {
                        Multiples = gameController.Multiples
                    });
                }

                //转发消息
                entity.Broadcast(message);

                if (orderController.SelectLordIndex >= entity.Count)
                {
                    /*
                     * 地主:√ 农民1:× 农民2:×
                     * 地主:× 农民1:√ 农民2:√
                     * 地主:√ 农民1:√ 农民2:√ 地主2:√
                     *
                     * */
                    if (orderController.Biggest == 0)
                    {
                        //没人抢地主则重新发牌
                        gameController.BackToDeck();
                        gameController.DealCards();

                        //发送玩家手牌
                        Gamer[] gamers = entity.GetAll();
                        Dictionary <long, int> gamerCardsNum = new Dictionary <long, int>();
                        Array.ForEach(gamers, gamer => gamerCardsNum.Add(gamer.Id, gamer.GetComponent <HandCardsComponent>().GetAll().Length));
                        Array.ForEach(gamers, gamer =>
                        {
                            ActorProxy actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorProxy();
                            actorProxy.Send(new GameStart()
                            {
                                GamerCards    = gamer.GetComponent <HandCardsComponent>().GetAll(),
                                GamerCardsNum = gamerCardsNum
                            });
                        });

                        //随机先手玩家
                        gameController.RandomFirstAuthority();
                        return(Task.CompletedTask);
                    }
                    else if ((orderController.SelectLordIndex == entity.Count &&
                              ((orderController.Biggest != orderController.FirstAuthority.Key && !orderController.FirstAuthority.Value) ||
                               orderController.Biggest == orderController.FirstAuthority.Key)) ||
                             orderController.SelectLordIndex > entity.Count)
                    {
                        gameController.CardsOnTable(orderController.Biggest);
                        return(Task.CompletedTask);
                    }
                }

                //当所有玩家都抢地主时先手玩家还有一次抢地主的机会
                if (message.PlayerId == orderController.FirstAuthority.Key && message.IsGrab)
                {
                    orderController.FirstAuthority = new KeyValuePair <long, bool>(message.PlayerId, true);
                }

                orderController.Turn();
                orderController.SelectLordIndex++;
                entity.Broadcast(new SelectAuthority()
                {
                    PlayerId = orderController.CurrentAuthority
                });
            }
            return(Task.CompletedTask);
        }