Exemplo n.º 1
0
  /** Process delayed direction release. */
  synchronized void processDelayedDirectionRelease() {
    if ((directionRelease != null) && directionRelease.hasExpired()) {
      client.removeDirection(directionRelease.getDirection(), directionRelease.isFacing());

      directionRelease = null;
    }
  }
Exemplo n.º 2
0
  /**
   * Check if the user is close enough the parent entity of the slot. If the user is too far away
   * the window should not be opened, and it should be closed if it was already open.
   *
   * @return <code>true</code> if the user is close enough to have the window open, <code>false
   *     </code> otherwise.
   */
  public boolean isCloseEnough() {
    final User user = User.get();

    if ((user != null) && (parent != null)) {
      // null checks are fixes for Bug 1825678:
      // NullPointerException happened
      // after double clicking one
      // monster and a fast double
      // click on another monster

      // Check if the parent is user
      RPObject root = parent.getRPObject().getBaseContainer();
      // We don't want to close our own stuff
      // The root entity may have been removed, but still if it was
      // the user we do not want to close it.
      // User may have been changed by the main thread, so we can not rely
      // on user.getRPObject() being equal to root. (bug #3159058)
      final String type = root.getRPClass().getName();
      if (type.equals("player") && root.has("name")) {
        if (StendhalClient.get().getCharacter().equalsIgnoreCase(root.get("name"))) {
          return true;
        }
      }

      return isCloseEnough(user.getX(), user.getY());
    }

    return true;
  }
Exemplo n.º 3
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());
      }
    }
  }
Exemplo n.º 4
0
  /**
   * Handle direction press actions.
   *
   * @param direction The direction.
   * @param facing If facing only.
   */
  private synchronized void processDirectionPress(final Direction direction, final boolean facing) {
    if (directionRelease != null) {
      if (directionRelease.check(direction, facing)) {
        directionRelease = null;
        return;
      } else {
        /*
         * Flush pending release
         */
        client.removeDirection(directionRelease.getDirection(), directionRelease.isFacing());

        directionRelease = null;
      }
    }

    if (client.addDirection(direction, facing)) {
      // Movement prediction.
      User user = User.get();
      if (user != null) {
        user.predictMovement(direction, facing);
      }
    }
  }
Exemplo n.º 5
0
  /**
   * Handle direction release actions.
   *
   * @param direction The direction.
   * @param facing If facing only.
   */
  private synchronized void processDirectionRelease(
      final Direction direction, final boolean facing) {
    if (directionRelease != null) {
      if (directionRelease.check(direction, facing)) {
        /*
         * Ignore repeats
         */
        return;
      } else {
        /*
         * Flush previous release
         */
        client.removeDirection(directionRelease.getDirection(), directionRelease.isFacing());
      }
    }

    directionRelease = new DelayedDirectionRelease(direction, facing);
  }
Exemplo n.º 6
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;
      }
    }
  }