예제 #1
0
        public static void Handle_PlayTogether(ClientConnection Client, PacketReader packet, byte last)
        {
            Account User       = Client.CurrentAccount;
            int     unk        = packet.ReadLEInt32();
            int     roomid     = packet.ReadLEInt32();
            byte    roomkindid = packet.ReadByte();
            int     pwlen      = packet.ReadLEInt32();
            string  pw         = string.Empty;

            if (pwlen > 0)
            {
                pw = packet.ReadBig5StringSafe(pwlen);
            }
            bool isExist = Rooms.NormalRoomList.Exists(rm => rm.ID == roomid);

            if (!isExist)
            {
                Client.SendAsync(new GameRoom_EnterRoomError(User, 0x1, roomkindid, last));
            }
            else
            {
                NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == roomid);
                GameRoomEvent.EnterRoom(Client, room, pw, last);
            }
        }
예제 #2
0
        public static void Handle_EnterRoom(ClientConnection Client, PacketReader reader, byte last)
        {
            Account User   = Client.CurrentAccount;
            int     roomid = reader.ReadLEInt32();
            int     pwlen  = reader.ReadLEInt32();
            string  pw     = string.Empty;

            if (pwlen != 0)
            {
                pw = reader.ReadBig5StringSafe(pwlen);
            }
            if (User.CurrentRoomId != 0)
            {
                GameRoomEvent.DisconnectRoom(User);
            }
            bool isExist = Rooms.NormalRoomList.Exists(rm => rm.ID == roomid);

            if (isExist)
            {
                NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == roomid);
                GameRoomEvent.EnterRoom(Client, room, pw, last);
            }
            else
            {
                Client.SendAsync(new GameRoom_EnterRoomError(User, 0x1, 0x9B, last));
            }
        }
예제 #3
0
        public static void Handle_RandomEnterRoom(ClientConnection Client, PacketReader reader, byte last)
        {
            Account User       = Client.CurrentAccount;
            byte    roomkindid = reader.ReadByte();

            //int empty = reader.ReadLEInt32();

            if (roomkindid == 0x4A)
            {
                bool isExist = Rooms.NormalRoomList.Any(rm => rm.RoomKindID == 0x4A && rm.Players.Count < rm.MaxPlayersCount);
                if (!isExist)
                {
                    NormalRoom room = new NormalRoom();
                    room.setID(Rooms.RoomID);
                    room.setName("Park");
                    room.setPassword("");
                    room.setItemType(1);
                    room.setIsStepOn(true);
                    room.setRoomKindID(0x4A);
                    room.setIsTeamPlay(0);

                    room.Players.Add(User);
                    room.setMaxPlayersCount(30);
                    room.setPosList(30);

                    User.RoomPos = room.PosList.First();
                    room.PosList.Remove(User.RoomPos);
                    room.setRoomMasterIndex(User.RoomPos);

                    User.CurrentRoomId = Rooms.RoomID;
                    User.InGame        = true;

                    Client.SendAsync(new GameRoom_SendRoomInfo(User, room, last));
                    Client.SendAsync(new GameRoom_SendPlayerInfo(User, last));
                    Client.SendAsync(new GameRoom_GetRoomMaster(User, room.RoomMasterIndex, last)); //場主位置

                    Client.SendAsync(new GameRoom_SendRoomMaster(User, room.MapNum, room.RoomMasterIndex, last));

                    Rooms.NormalRoomList.Add(room);
                    Rooms.RoomID += 1;
                }
                else
                {
                    NormalRoom room = Rooms.NormalRoomList.FirstOrDefault(rm => rm.RoomKindID == 0x4A && rm.Players.Count < rm.MaxPlayersCount);
                    User.CurrentRoomId = room.ID;
                    User.InGame        = true;

                    //取得當前第一個位置id
                    User.RoomPos = room.PosList.FirstOrDefault();
                    room.PosList.Remove(User.RoomPos);

                    Client.SendAsync(new GameRoom_Hex(User, "FF5805FFFFFFFF00000000000000000000000000", last));
                    Client.SendAsync(new GameRoom_SendRoomInfo(User, room, last, User.RoomPos));

                    //Send自己info俾其他roomuser
                    foreach (Account roomUser in room.Players)
                    {
                        roomUser.Connection.SendAsync(new GameRoom_SendPlayerInfo(User, last));
                    }

                    room.Players.Add(User);

                    //Send roomuser info俾自己
                    foreach (Account roomUser in room.Players)
                    {
                        Client.SendAsync(new GameRoom_SendPlayerInfo(roomUser, last));
                    }

                    byte roommasterpos = room.RoomMasterIndex; //room.Players.Find(player => player.IsRoomMaster).RoomPos;
                    Client.SendAsync(new GameRoom_GetRoomMaster(User, roommasterpos, last));
                }
            }
            else
            {
                bool isExist = Rooms.NormalRoomList.Any(rm => rm.RoomKindID == roomkindid && rm.Players.Count < rm.MaxPlayersCount && !rm.isPlaying && !rm.HasPassword && !rm.Players.Exists(p => p.Attribute == 3));
                if (!isExist)
                {
                    Client.SendAsync(new GameRoom_EnterRoomError(User, 0xB, roomkindid, last));
                }
                else
                {
                    int        count = Rooms.NormalRoomList.Count(rm => rm.RoomKindID == roomkindid && rm.Players.Count < rm.MaxPlayersCount && !rm.isPlaying && !rm.HasPassword && !rm.Players.Exists(p => p.Attribute == 3));
                    NormalRoom room  = Rooms.NormalRoomList.FindAll(rm => rm.RoomKindID == roomkindid && rm.Players.Count < rm.MaxPlayersCount && !rm.isPlaying && !rm.HasPassword && !rm.Players.Exists(p => p.Attribute == 3))[new Random().Next(count)];
                    GameRoomEvent.EnterRoom(Client, room, string.Empty, last);
                }
            }
        }