Esempio n. 1
0
        protected override async ETTask Run(Gamer gamer, Actor_GamerPlayCard_Req message, Action <Actor_GamerPlayCard_Back> reply)
        {
            Actor_GamerPlayCard_Back response = new Actor_GamerPlayCard_Back();

            try
            {
                LandlordsRoom room = Game.Scene.GetComponent <LandlordsComponent>().GetGamingRoom(gamer);

                GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                DeskCardsCacheComponent  deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();
                OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();

                //检测是否符合出牌规则
                if (CardHelper.PopEnable(To.Array(message.Cards), out CardsType type))
                {
                    //当前出牌牌型是否比牌桌上牌型的权重更大
                    bool isWeightGreater = CardHelper.GetWeight(To.Array(message.Cards), type) > deskCardsCache.GetTotalWeight();
                    //当前出牌牌型是否和牌桌上牌型的数量一样
                    bool isSameCardsNum = message.Cards.Count == deskCardsCache.GetAll().Length;
                    //当前出牌玩家是否是上局最大出牌者
                    bool isBiggest = orderController.Biggest == orderController.CurrentAuthority;
                    //当前牌桌牌型是否是顺子
                    bool isStraight = deskCardsCache.Rule == CardsType.Straight || deskCardsCache.Rule == CardsType.DoubleStraight || deskCardsCache.Rule == CardsType.TripleStraight;
                    //当前出牌牌型是否和牌桌上牌型一样
                    bool isSameCardsType = type == deskCardsCache.Rule;

                    if (isBiggest ||                                                          //先手出牌玩家
                        type == CardsType.JokerBoom ||                                        //王炸
                        type == CardsType.Boom && isWeightGreater ||                          //更大的炸弹
                        isSameCardsType && isStraight && isSameCardsNum && isWeightGreater || //更大的顺子
                        isSameCardsType && isWeightGreater)                                   //更大的同类型牌
                    {
                        if (type == CardsType.JokerBoom)
                        {
                            //王炸翻4倍
                            gameController.Multiples *= 4;
                            room.Broadcast(new Actor_SetMultiples_Ntt()
                            {
                                Multiples = gameController.Multiples
                            });
                        }
                        else if (type == CardsType.Boom)
                        {
                            //炸弹翻2倍
                            gameController.Multiples *= 2;
                            room.Broadcast(new Actor_SetMultiples_Ntt()
                            {
                                Multiples = gameController.Multiples
                            });
                        }
                    }
                    else
                    {
                        response.Error = ErrorCode.ERR_PlayCardError;
                        reply(response);
                        return;
                    }
                }
                else
                {
                    response.Error = ErrorCode.ERR_PlayCardError;
                    reply(response);
                    return;
                }

                //如果符合将牌从手牌移到出牌缓存区
                deskCardsCache.Clear();
                deskCardsCache.Rule = type;
                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                foreach (var card in message.Cards)
                {
                    handCards.PopCard(card);
                    deskCardsCache.AddCard(card);
                }

                reply(response);

                //转发玩家出牌消息
                room.Broadcast(new Actor_GamerPlayCard_Ntt()
                {
                    UserID = gamer.UserID, Cards = message.Cards
                });

                //游戏控制器继续游戏
                gameController.Continue(gamer);

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Esempio n. 2
0
        protected override async ETTask Run(Session session, CreateNewCharacter_C2G request, CharacterMessage_G2C response, Action reply)
        {
            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = MMOErrorCode.ERR_UserNotOnline;
                    reply();
                    return;
                }

                // 限制最多可创建多少角色处理
                int max = request.Max;
                if (max == 0)
                {
                    max = 100;
                }
                if (request.Index > max)
                {
                    response.Error = MMOErrorCode.ERR_CannotCreateMoreCharacter;
                    reply();
                    return;
                }

                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                //获取玩家对象
                User user = session.GetComponent <SessionUserComponent>().User;

                //获取玩家所在大区编号
                UserInfo userInfo = await dbProxy.Query <UserInfo>(user.UserId);

                int GateAppId = RealmHelper.GetGateAppIdFromUserId(userInfo.Id);
                userInfo.LastPlay = request.Index;

                //检查角色名是否可用
                //会得到全部大区的同名角色 需遍历排除
                List <ComponentWithId> result = await dbProxy.Query <Character>($"{{Name:'{request.Name}'}}");

                foreach (var a in result)
                {
                    if (RealmHelper.GetGateAppIdFromUserId(((Character)a).UserId) == GateAppId)
                    {
                        //出现同名角色
                        response.Error = MMOErrorCode.ERR_CreateNewCharacter;
                        reply();
                        return;
                    }
                }

                //新建角色数据
                Character character = ComponentFactory.Create <Character, string, long>(request.Name, userInfo.Id);
                character.Race   = request.Race;
                character.Class  = request.Class;
                character.Name   = request.Name;
                character.Level  = 1;
                character.Map    = 1001;
                character.Region = 03;
                character.X      = request.X;
                character.Y      = request.Y;
                character.Z      = request.Z;
                character.Money  = 0;
                character.Mail   = 0;
                character.Index  = request.Index;

                //构建同样的返回数据,减少前端再查询一次此角色数据
                response.Character = GateHelper.CharacterInfoByData(character, false);

                //新角色默认装备
                List <Component> equipInfo = await dbProxy.Query2 <GlobalInfo>($"{{Type:'{request.Class}Equip'}}");

                foreach (GlobalInfo row in equipInfo)
                {
                    character.Equipments          = row.Equipments;
                    response.Character.Equipments = To.RepeatedField <EquipInfo>(row.Equipments);
                }

                //存储数据
                await dbProxy.Save(character);

                await dbProxy.Save(userInfo);

                reply();
                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Esempio n. 3
0
        protected override async void Run(Gamer gamer, Actor_GamerGrabLandlordSelect_Ntt message)
        {
            LandlordsRoom               room                = Game.Scene.GetComponent <LandlordsComponent>().GetGamingRoom(gamer);
            OrderControllerComponent    orderController     = room.GetComponent <OrderControllerComponent>();
            GameControllerComponent     gameController      = room.GetComponent <GameControllerComponent>();
            ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

            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.gamers;
                        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 = actorProxyComponent.Get(_gamer.ActorIDofClient);
                            actorProxy.Send(new Actor_GameStart_Ntt()
                            {
                                HandCards     = To.RepeatedField(_gamer.GetComponent <HandCardsComponent>().GetAll()),
                                GamersCardNum = To.RepeatedField(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
                });
            }
            await Task.CompletedTask;
        }