Exemplo n.º 1
0
        /// <summary>
        /// 加入房间Actor
        /// </summary>
        /// <param name="self"></param>
        /// <param name="userId"></param>
        public static async Task BroadGamerEnter(this Room self, long userId)
        {
            List <GamerInfo> gamerInfos  = new List <GamerInfo>();
            long             roomType    = self.GetComponent <GameControllerComponent>().RoomConfig.Id;
            GamerInfo        currentInfo = null;

            for (int i = 0; i < self.GetAll().Length; i++)
            {
                Gamer _gamer = self.GetAll()[i];
                if (_gamer == null)
                {
                    continue;
                }
                GamerInfo gamerInfo = new GamerInfo();
                gamerInfo.UserID    = _gamer.UserID;
                gamerInfo.SeatIndex = self.GetGamerSeat(_gamer.UserID);
                gamerInfo.IsReady   = _gamer.IsReady;

                if (_gamer.playerBaseInfo == null)
                {
                    _gamer.playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(gamerInfo.UserID);
                }

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

                if (gamerInfo.UserID == userId)
                {
                    currentInfo = gamerInfo;
                }

                gamerInfos.Add(gamerInfo);
            }

            foreach (var _gamer in self.GetAll())
            {
                if (_gamer == null || _gamer.isOffline)
                {
                    continue;
                }

                //第一次进入
                if (_gamer.UserID == userId)
                {
                    Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom()
                    {
                        RoomType = (int)roomType,
                        Gamers   = gamerInfos,
                    };

                    if (roomType == 3)
                    {
                        GameControllerComponent gameControllerComponent = self.GetComponent <GameControllerComponent>();
                        actorGamerEnterRoom.RoomId         = gameControllerComponent.RoomConfig.FriendRoomId;
                        actorGamerEnterRoom.MasterUserId   = gameControllerComponent.RoomConfig.MasterUserId;
                        actorGamerEnterRoom.JuCount        = gameControllerComponent.RoomConfig.JuCount;
                        actorGamerEnterRoom.Multiples      = gameControllerComponent.RoomConfig.Multiples;
                        actorGamerEnterRoom.CurrentJuCount = self.CurrentJuCount;
                    }

                    self.GamerBroadcast(_gamer, actorGamerEnterRoom);
                }
                //有人加入
                else
                {
                    Actor_GamerJionRoom actorGamerJionRoom = new Actor_GamerJionRoom()
                    {
                        Gamer = currentInfo
                    };

                    self.GamerBroadcast(_gamer, actorGamerJionRoom);
                }
            }
        }
        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;
        }
        protected override async void Run(ETModel.Session session, Actor_GamerReconnet message)
        {
            try
            {
                Log.Info($"断线重连:");
                SoundsHelp.Instance.IsOpenSound(false);

                GameObject mask = GameObject.Instantiate(CommonUtil.getGameObjByBundle("Image_Desk_Card", "RoomMask"), GameObject.Find("Global/UI/CommonCanvas").transform);

                //进入
                List <GamerInfo> Gamers = new List <GamerInfo>();
                foreach (var item in message.Gamers)
                {
                    GamerInfo gamerInfo = new GamerInfo();
                    gamerInfo.UserID     = item.UserID;
                    gamerInfo.SeatIndex  = item.SeatIndex;
                    gamerInfo.IsReady    = true;
                    gamerInfo.playerInfo = item.playerInfo;
                    Gamers.Add(gamerInfo);

                    //将出的牌加入到手牌中
                    item.handCards.AddRange(item.playCards);

                    foreach (var card in item.pengCards)
                    {
                        item.handCards.Add(card);
                        item.handCards.Add(card);
                    }

                    foreach (var card in item.gangCards)
                    {
                        item.handCards.Add(card);
                        item.handCards.Add(card);
                        item.handCards.Add(card);
                    }

                    Logic_NJMJ.getInstance().SortMahjong(item.handCards);

                    Log.Info($"{item.UserID} 手牌:{item.handCards.Count}");
                }

                Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom()
                {
                    Gamers   = Gamers,
                    RoomType = message.RoomType,
                };
                if (message.RoomType == 3)
                {
                    actorGamerEnterRoom.RoomId       = message.RoomId;
                    actorGamerEnterRoom.MasterUserId = message.MasterUserId;
                    actorGamerEnterRoom.JuCount      = message.JuCount;
                    actorGamerEnterRoom.Multiples    = message.Multiples;
                }
                await Actor_GamerEnterRoomHandler.GamerEnterRoom(actorGamerEnterRoom);

                //开始游戏
                var actorStartGame = new Actor_StartGame();
                actorStartGame.GamerDatas = message.Gamers;
                actorStartGame.restCount  = message.RestCount;
                actorStartGame.RoomType   = message.RoomType;
                if (actorStartGame.RoomType == 3)
                {
                    actorStartGame.CurrentJuCount = message.CurrentJuCount;
                }

                Actor_StartGameHandler.StartGame(actorStartGame, true);

                //碰刚
                foreach (var item in message.Gamers)
                {
                    for (int i = 0; i < item.pengCards.Count; i++)
                    {
                        MahjongInfo          card           = item.pengCards[i];
                        Actor_GamerOperation gamerOperation = new Actor_GamerOperation();
                        gamerOperation.Uid           = item.UserID;
                        gamerOperation.weight        = card.weight;
                        gamerOperation.OperationType = 0;
                        gamerOperation.OperatedUid   = item.OperatedPengUserIds[i];
                        Actor_GamerOperateHandler.GamerOperation(gamerOperation, true);
                    }

                    for (int i = 0; i < item.gangCards.Count; i++)
                    {
                        MahjongInfo          card = item.gangCards[i];
                        long                 operatedGangUserIds = item.OperatedGangUserIds[i];
                        Actor_GamerOperation gamerOperation      = new Actor_GamerOperation();
                        gamerOperation.Uid           = item.UserID;
                        gamerOperation.weight        = card.weight;
                        gamerOperation.OperationType = 1;
                        gamerOperation.OperatedUid   = operatedGangUserIds;

                        if (operatedGangUserIds == 0)
                        {
                            gamerOperation.OperationType = 4;
                        }
                        Actor_GamerOperateHandler.GamerOperation(gamerOperation, true);
                    }
                }

                //打牌
                foreach (var item in message.Gamers)
                {
                    Log.Debug($"{item.UserID} 重连出牌");
                    for (int i = 0; i < item.playCards.Count; i++)
                    {
                        MahjongInfo         card     = item.playCards[i];
                        int                 index    = Logic_NJMJ.getInstance().GetIndex(item.handCards, card);
                        Actor_GamerPlayCard playCard = new Actor_GamerPlayCard();
                        playCard.Uid    = item.UserID;
                        playCard.weight = card.weight;
                        playCard.index  = index;
//                        await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(100);
                        Actor_GamerPlayCardHandler.PlayCard(playCard);
//                        item.handCards.RemoveAt(index);
                    }
                }

                //托管恢复
                UI              uiRoom          = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
                GamerComponent  gamerComponent  = uiRoom.GetComponent <GamerComponent>();
                UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>();
                foreach (var item in message.Gamers)
                {
                    if (item.IsTrusteeship)
                    {
                        if (item.UserID == PlayerInfoComponent.Instance.uid)
                        {
                            uiRoomComponent.ShowTrustship();
                        }
                        else
                        {
                            GamerUIComponent gamerUIComponent = gamerComponent.Get(item.UserID).GetComponent <GamerUIComponent>();
                            gamerUIComponent.ShowTrust();
                        }
                    }
                }

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

                int openSound = PlayerPrefs.GetInt("isOpenSound", 1);
                SoundsHelp.Instance.IsOpenSound(openSound == 1);
                GameObject.Destroy(mask);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }