Пример #1
0
        protected override async Task Run(Gamer entity, Actor_RobBanker_Ntt message)
        {
            Room          room = RoomHelp.GetRoom(entity.RoomID);
            DeckComponent deck = room.GetComponent <DeckComponent>();

            deck.AddRobBankGamer(message.ChairId, message.BankerNumber);
            if (deck.IsRobBankerAll())
            {
                //如果所有人都抢庄结束
                ushort ChairId = deck.GetBanker();
                room.Broadcast(new Actor_RobBankerResult_Ntt()
                {
                    ChairId = message.ChairId, BankerNumber = message.BankerNumber
                });
                room.Broadcast(new Actor_SelectBanker_Ntt()
                {
                    ChairId = ChairId
                });
                //指定庄
                room.Get(ChairId).IsRobBanker = true;
            }
            else
            {
                //如果还没有抢庄完
                room.Broadcast(new Actor_RobBankerResult_Ntt()
                {
                    ChairId = message.ChairId, BankerNumber = message.BankerNumber
                });
            }
            Log.Debug($"玩家:{message.ChairId},抢庄倍数:{message.BankerNumber},当前抢庄玩家人数:{deck.RobBankerDic.Count}");


            await Task.CompletedTask;
        }
Пример #2
0
        protected override async Task Run(Gamer entity, Actor_GamerBet_Ntt message)
        {
            Room          room = RoomHelp.GetRoom(entity.RoomID);
            DeckComponent deck = room.GetComponent <DeckComponent>();

            deck.AddBetGamer(message.ChairId, message.BetNumber);
            room.Broadcast(new Actor_BetResult_Ntt()
            {
                ChairId = message.ChairId, BetNumber = message.BetNumber
            });
            if (deck.IsBetAll())
            {
                //开始摊牌
                room.Broadcast(new Actor_StartShowHand_Ntt());
            }

            await Task.CompletedTask;
        }
Пример #3
0
        protected override async Task Run(Gamer gamer, Actor_GamerReady_Ntt message)
        {
            gamer.IsReady = true;

            Room room = RoomHelp.GetRoom(gamer.RoomID);
            Actor_GamerReady_Ntt transpond = new Actor_GamerReady_Ntt();

            transpond.ChairId = gamer.uChairID;
            room.Broadcast(transpond);
            Log.Info($"玩家{gamer.uChairID}准备");
            if (room.State == RoomState.Game)
            {
                room.GetComponent <DeckComponent>().XJReady += 1;
            }



            //检查是否所有玩家准备
            room.GetComponent <GameControllerComponent>().ReadyStartGame();
            await Task.CompletedTask;
        }
        protected override async Task Run(Gamer entity, Actor_ShowHandCard_Ntt message)
        {
            Room room = RoomHelp.GetRoom(entity.RoomID);

            DeckComponent deck = room.GetComponent <DeckComponent>();

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

            //排序
            byte CardType = handCardsComponent.Sort();

            //得到排序后的手牌
            byte[] HandCards = handCardsComponent.GetAll();
            //记录
            deck.AddShowCardGamer(entity.uChairID, HandCards);

            room.Broadcast(new Actor_ShowHandResult_Ntt()
            {
                ChairId = entity.uChairID, Cards = HandCards, CardType = CardType
            });

            if (deck.IsShowCardAll())
            {
                //如果所有玩家都摊牌了
                Log.Info("所有玩家都摊牌了");
                //判断牌最大的玩家
                Gamer[] gamers = room.GetAll();
                //找到庄
                Gamer BankerGamer    = gamers.Single(model => model.IsRobBanker);
                byte  BankerCardType = BankerGamer.GetComponent <HandCardsComponent>().CardType;

                //找到比庄大的玩家
                var MoreTranBanker = gamers.Where(model => model.GetComponent <HandCardsComponent>().CardType > BankerCardType);

                //找到比庄小的玩家
                var LessTranBanker = gamers.Where(model => model.GetComponent <HandCardsComponent>().CardType < BankerCardType);
                int AllMultiple    = 0;
                //赢的玩家处理
                foreach (Gamer gamer in MoreTranBanker)
                {
                    int Multiple = 0;
                    Multiple = gamer.GetComponent <HandCardsComponent>().CardTypeMultiple *
                               deck.GetOrderPlayerBet_Bet(gamer.uChairID) *
                               deck.GetOrderPlayerBet_RobBanker(gamer.uChairID);
                    gamer.SingleMultiple = Multiple;
                    gamer.AllMultiple   += Multiple;
                    AllMultiple         -= Multiple;
                }
                //输的玩家处理
                foreach (Gamer gamer in LessTranBanker)
                {
                    int Multiple = 0;
                    Multiple = BankerGamer.GetComponent <HandCardsComponent>().CardTypeMultiple *
                               deck.GetOrderPlayerBet_Bet(gamer.uChairID) *
                               deck.GetOrderPlayerBet_RobBanker(gamer.uChairID);
                    gamer.SingleMultiple = -Multiple;
                    gamer.AllMultiple   += -Multiple;
                    AllMultiple         += Multiple;
                }
                //庄的得分
                BankerGamer.SingleMultiple = AllMultiple;
                BankerGamer.AllMultiple   += AllMultiple;

                List <XJResultInfo> ResultList = new List <XJResultInfo>();
                foreach (Gamer gamer in gamers)
                {
                    XJResultInfo result = new XJResultInfo();
                    result.ChairId  = gamer.uChairID;
                    result.AllScore = gamer.AllMultiple;
                    result.XJScore  = gamer.SingleMultiple;
                    ResultList.Add(result);
                }

                room.Broadcast(new Actor_XJGameResult_Ntt()
                {
                    XJResult = ResultList
                });
                //foreach (Gamer gamer in MoreTranBanker)
                //{
                //    gamer.GetComponent<HandCardsComponent>().CardTypeMultiplp
                //}
            }
            await Task.CompletedTask;
        }
Пример #5
0
        public override async void Destroy(SessionUserComponent self)
        {
            try
            {
                //释放User对象时将User对象从管理组件中移除
                Game.Scene.GetComponent <UserComponent>()?.Remove(self.User.UserID);

                StartConfigComponent        config = Game.Scene.GetComponent <StartConfigComponent>();
                ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

                //从房间移除掉线的玩家
                //TODO  后续做断线重连需要重新改

                //移除在房间的玩家
                if (self.User.ActorID != 0)
                {
                    ActorMessageSender actorProxy = actorProxyComponent.Get(self.User.ActorID);
                    await actorProxy.Call(new Actor_PlayerExitRoom_Req()
                    {
                        UserID = self.User.UserID
                    });
                }

                Room room = RoomHelp.GetRoom(self.User.RoomID);
                if (room?.State == RoomState.Idle)
                {
                    if (room.Count == 0)
                    {
                        room.Dispose();
                    }
                }

                //正在匹配中发送玩家退出匹配请求
                //if (self.User.IsMatching)
                //{
                //    IPEndPoint matchIPEndPoint = config.MatchConfig.GetComponent<InnerConfig>().IPEndPoint;
                //    Session matchSession = Game.Scene.GetComponent<NetInnerComponent>().Get(matchIPEndPoint);
                //    await matchSession.Call(new G2M_PlayerExitMatch_Req() { UserID = self.User.UserID });
                //}

                //正在游戏中发送玩家退出房间请求
                //if (self.User.ActorID != 0)
                //{
                //    ActorMessageSender actorProxy = actorProxyComponent.Get(self.User.ActorID);
                //    await actorProxy.Call(new Actor_PlayerExitRoom_Req() { UserID = self.User.UserID });
                //}

                //向登录服务器发送玩家下线消息
                IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session    realmSession    = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);
                await realmSession.Call(new G2R_PlayerOffline_Req()
                {
                    UserID = self.User.UserID
                });

                self.User.Dispose();
                self.User = null;
            }
            catch (System.Exception e)
            {
                Log.Trace(e.ToString());
            }
        }