Ejemplo n.º 1
0
        public void Handle(ConnectionPacket packet, PacketSession peerSession)
        {
            if (packet.Connected)
            {
                // 로그인한 유저 객체 만들고 각 객체 상황 전달한다.
                var playerObject = _context.NewGameObject(ObjectType.Player);
                peerSession.Send(playerObject.ToLoginPacket());

                foreach (var each in _context.GameObjects.Select(e => e.ToSpawnPacket()))
                {
                    peerSession.Send(each);
                }

                foreach (var each in _context.GameObjects.Select(e => e.ToMovePacket()))
                {
                    peerSession.Send(each);
                }

                // 다른 유저들에게 해당 유저가 접속했다는 사실을 알려준다.
                _context.BroadcastPacket(playerObject.ToSpawnPacket(), peerSession);

                _context.AddPlayer(playerObject, peerSession);
            }
            else
            {
                var logoutObject = _context.RemovePlayer(peerSession);

                // 다른 유저들에게 유저가 나갔다는 사실을 알려준다.
                if (logoutObject != null)
                {
                    _context.BroadcastPacket(logoutObject.ToDespawnPacket(), peerSession);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: FormGame.cs Proyecto: lacti/Lz
        private void FormGame_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (_player == null || !_connected)
            {
                return;
            }

            if (_selectEnemyMode)
            {
                SelectTargetAndExecuteSkill(e.KeyCode);
                return;
            }

            var direction = DirectionType.None;

            switch (e.KeyCode)
            {
            case Keys.Down:
                direction = DirectionType.Down;
                break;

            case Keys.Left:
                direction = DirectionType.Left;
                break;

            case Keys.Right:
                direction = DirectionType.Right;
                break;

            case Keys.Up:
                direction = DirectionType.Up;
                break;

            case Keys.Space:
                _attackTarget = SelectNextTarget(DirectionType.Right);
                if (_attackTarget != null)
                {
                    _selectEnemyMode = true;
                }
                break;

            case Keys.Enter:
                if (textChat.Visible)
                {
                    textChat.Enabled = false;
                    textChat.Visible = false;
                }
                else
                {
                    textChat.Enabled = true;
                    textChat.Visible = true;
                    textChat.Focus();
                }
                break;
            }

            if (direction != DirectionType.None)
            {
                if (_player.Move(direction))
                {
                    _session.Send(new MovePacket
                    {
                        ObjectId     = _player.ObjectId,
                        CurrentPoint = _player.Position,
                        State        = MoveStateType.Moving,
                        Direction    = _player.Direction
                    });
                }
            }
        }