예제 #1
0
  @Override
  public void keyReleased(final KeyEvent e) {
    final int keyCode = e.getKeyCode();

    /* Ignore if the key is not found in the pressedStateKeys list. */
    if (client.keyIsPressed(keyCode)) {
      /* Remove keyCode from pressedStateKeys list. */
      client.onKeyReleased(keyCode);

      switch (keyCode) {
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_DOWN:
          /*
           * Ctrl means face, otherwise move
           */
          processDirectionRelease(keyCodeToDirection(e.getKeyCode()), e.isControlDown());
      }
    }
  }
예제 #2
0
  @Override
  public void keyPressed(final KeyEvent e) {
    final int keyCode = e.getKeyCode();

    /* Ignore if the key is already pressed down. */
    if (!client.keyIsPressed(keyCode)) {
      /* Add keyCode to pressedStateKeys list. */
      client.onKeyPressed(keyCode);

      if (e.isShiftDown()) {
        /*
         * We are going to use shift to move to previous/next line of text
         * with arrows so we just ignore the keys if shift is pressed.
         */
        return;
      }

      switch (keyCode) {
        case KeyEvent.VK_R:
          if (e.isControlDown()) {
            /*
             * Ctrl+R Remove text bubbles
             */
            screen.clearTexts();
          }
          break;

        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_DOWN:
          /*
           * Ctrl means face, otherwise move. Alt turns on auto-walk.
           */
          final Direction direction = keyCodeToDirection(e.getKeyCode());

          /* TODO: Remove MOTION condition when auto-walk testing is
           * finished.
           *
           * Check if the player is currently using auto-walk or the Alt
           * key is pressed.
           */
          User user = User.get();
          if ((user.getRPObject().has(AUTOWALK) || e.isAltDown()) && Testing.MOVEMENT) {
            /* Face direction pressed and toggle auto-walk. */
            this.processAutoWalk(direction, user);
          } else {
            if (e.isAltGraphDown()) {
              if (System.currentTimeMillis() - lastAction > 1000) {
                final EntityView<?> view =
                    screen.getEntityViewAt(
                        user.getX() + direction.getdx(), user.getY() + direction.getdy());

                if (view != null) {
                  final IEntity entity = view.getEntity();
                  if (!entity.equals(user)) {
                    view.onAction();
                    lastAction = System.currentTimeMillis();
                  }
                }
              }
            }

            this.processDirectionPress(direction, e.isControlDown());
          }
          break;
        case KeyEvent.VK_0:
        case KeyEvent.VK_1:
        case KeyEvent.VK_2:
        case KeyEvent.VK_3:
        case KeyEvent.VK_4:
        case KeyEvent.VK_5:
        case KeyEvent.VK_6:
        case KeyEvent.VK_7:
        case KeyEvent.VK_8:
        case KeyEvent.VK_9:
          switchToSpellCastingState(e);
          break;
      }
    }
  }