Exemple #1
0
        protected override void Run(Gamer gamer, Actor_GamerReady_Landlords message)
        {
            LandlordsComponent landordsMatchComponent = Game.Scene.GetComponent <LandlordsComponent>();
            LandlordsRoom      room = landordsMatchComponent.GetWaitingRoom(gamer);

            if (room != null)
            {
                //找到玩家的座位顺序 设置其准备状态为真
                int seatIndex = room.GetGamerSeat(gamer.UserID);
                if (seatIndex >= 0)
                {
                    room.isReadys[seatIndex] = true;
                    //广播通知全房间玩家
                    room.Broadcast(new Actor_GamerReady_Landlords()
                    {
                        UserID = gamer.UserID
                    });
                    //检测开始游戏
                    room.CheckGameStart();
                }
                else
                {
                    Log.Error("玩家不在正确的座位上");
                }
            }
        }
        /// <summary>
        /// 返回玩家是否已准备 玩家不在房间时返回false
        /// </summary>
        /// <param name="self"></param>
        /// <param name="gamer"></param>
        /// <returns></returns>
        public static bool IsGamerReady(this LandlordsRoom self, Gamer gamer)
        {
            int seatIndex = self.GetGamerSeat(gamer.UserID);

            if (seatIndex > 0)
            {
                return(self.isReadys[seatIndex]);
            }
            return(false);
        }
        /// <summary>
        /// 获取房间中的玩家
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Gamer GetGamerFromUserID(this LandlordsRoom self, long id)
        {
            int seatIndex = self.GetGamerSeat(id);

            if (seatIndex >= 0)
            {
                return(self.gamers[seatIndex]);
            }

            return(null);
        }
        /// <summary>
        /// 移除玩家并返回 玩家离开房间
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Gamer Remove(this LandlordsRoom self, long id)
        {
            int seatIndex = self.GetGamerSeat(id);

            if (seatIndex >= 0)
            {
                Gamer gamer = self.gamers[seatIndex];
                self.gamers[seatIndex] = null;
                self.seats.Remove(id);
                return(gamer);
            }

            return(null);
        }