Пример #1
0
        public void HandleRoomJoinPacket(Client client, Packet packet)
        {
            C2SRoomJoinPacket roomJoinPacket = new C2SRoomJoinPacket(packet);
            Room room = this.GameHandler.Rooms.Find(r => r.Id == roomJoinPacket.RoomId);

            S2CRoomJoinAnswer roomJoinAnswer = new S2CRoomJoinAnswer(0, 0, 0, 0);

            client.PacketStream.Write(roomJoinAnswer);
            client.ActiveRoom = room;

            S2CRoomInformation roomInformationPacket = new S2CRoomInformation(room);

            client.PacketStream.Write(roomInformationPacket);

            RoomPlayer roomPlayer = new RoomPlayer();

            roomPlayer.Character = client.ActiveCharacter;
            roomPlayer.Position  = 1;
            roomPlayer.Master    = false;
            room.CurrentPlayers.Add(roomPlayer);

            List <Client> clientsInRoom = this.GameHandler.GetClientsInRoom(room.Id);

            foreach (Client roomClient in clientsInRoom)
            {
                S2CRoomPlayerInformation roomPlayerInformationPacket =
                    new S2CRoomPlayerInformation(room.CurrentPlayers);
                roomClient.PacketStream.Write(roomPlayerInformationPacket);
            }
        }
Пример #2
0
        public void HandleRoomCreatePacket(Client client, Packet packet)
        {
            C2SRoomCreatePacket roomCreatePacket = new C2SRoomCreatePacket(packet);

            // Still needs fixes
            Room room = new Room();

            room.Id           = Convert.ToInt16(this.GameHandler.Rooms.Count);
            room.Name         = roomCreatePacket.Name;
            room.GameMode     = 0;
            room.BattleMode   = roomCreatePacket.GameMode;
            room.Level        = client.ActiveCharacter.Level;
            room.LevelRange   = roomCreatePacket.LevelRange;
            room.Map          = 1;
            room.Betting      = false;
            room.BettingCoins = 0;
            room.BettingGold  = 0;
            room.MaxPlayer    = roomCreatePacket.Players;

            RoomPlayer roomPlayer = new RoomPlayer();

            roomPlayer.Character = client.ActiveCharacter;
            roomPlayer.Position  = 0;
            roomPlayer.Master    = true;
            room.CurrentPlayers.Add(roomPlayer);

            this.GameHandler.Rooms.Add(room);

            client.ActiveRoom = room;

            Packet roomCreateAnswerPacket = new Packet(PacketId.S2CRoomCreateAnswer);

            roomCreateAnswerPacket.Write(0);
            client.PacketStream.Write(roomCreateAnswerPacket);

            S2CRoomInformation roomInformationPacket = new S2CRoomInformation(room);

            client.PacketStream.Write(roomInformationPacket);

            S2CRoomPlayerInformation roomPlayerInformationPacket = new S2CRoomPlayerInformation(room.CurrentPlayers);

            client.PacketStream.Write(roomPlayerInformationPacket);

            List <Client>           clientsInLobby       = this.GameHandler.GetClientsInLobby();
            S2CRoomListAnswerPacket roomListAnswerPacket = new S2CRoomListAnswerPacket(this.GameHandler.Rooms);

            foreach (Client c in clientsInLobby)
            {
                c.PacketStream.Write(roomListAnswerPacket);
            }
        }
Пример #3
0
        public void HandleRoomReadyChange(Client client, Packet packet)
        {
            C2SRoomReadyChangePacket roomReadyChangePacket = new C2SRoomReadyChangePacket(packet);

            client.ActiveRoom.CurrentPlayers.Find(rp => rp.Character.CharacterId == client.ActiveCharacter.CharacterId)
            .Ready = Convert.ToBoolean(roomReadyChangePacket.Ready);

            List <Client> clientsInRoom = this.GameHandler.GetClientsInRoom(client.ActiveRoom.Id);

            foreach (Client roomClient in clientsInRoom)
            {
                S2CRoomPlayerInformation roomPlayerInformationPacket =
                    new S2CRoomPlayerInformation(client.ActiveRoom.CurrentPlayers);
                roomClient.PacketStream.Write(roomPlayerInformationPacket);
            }
        }
Пример #4
0
        public void HandleRoomPositionChange(Client client, Packet packet)
        {
            C2SRoomPositionChange roomPositionChangePacket = new C2SRoomPositionChange(packet);
            byte currentPosition = client.ActiveRoom.CurrentPlayers
                                   .Find(rp => rp.Character.CharacterId == client.ActiveCharacter.CharacterId).Position;

            S2CRoomPositionChangeAnswer roomPositionChangeAnswer = new S2CRoomPositionChangeAnswer(0, currentPosition, roomPositionChangePacket.NewPosition);

            client.ActiveRoom.CurrentPlayers
            .Find(rp => rp.Character.CharacterId == client.ActiveCharacter.CharacterId).Position =
                Convert.ToByte(roomPositionChangePacket.NewPosition);
            client.PacketStream.Write(roomPositionChangeAnswer);

            List <Client> clientsInRoom = this.GameHandler.GetClientsInRoom(client.ActiveRoom.Id);

            foreach (Client roomClient in clientsInRoom)
            {
                S2CRoomPlayerInformation roomPlayerInformationPacket =
                    new S2CRoomPlayerInformation(client.ActiveRoom.CurrentPlayers);
                roomClient.PacketStream.Write(roomPlayerInformationPacket);
            }
        }