예제 #1
0
  /**
   * Check if the tile needs to be hidden because the player is inside a cave or a house or
   * something like this.
   *
   * @param tile the tile that is checked
   * @param key the location key of the checked tile
   * @return <code>true</code> in case the tile was handled
   */
  @SuppressWarnings("nls")
  private boolean checkHidden(final MapTile tile, final long key) {
    final Location playerLoc = World.getPlayer().getLocation();
    final Location tileLoc = tile.getLocation();

    if ((playerLoc == null) || (tileLoc == null)) {
      // something is very wrong. Put this entry back into the unchecked
      // list and try it again later.
      reportUnchecked(key);
      return true;
    }

    /*
     * And now we start with the inside check. In case the tile is below the
     * level of the player its never hidden for sure.
     */
    if (tileLoc.getScZ() <= playerLoc.getScZ()) {
      if (tile.isHidden()) {
        tile.setHidden(false);
        addAllBelow(tileLoc, playerLoc.getScZ() - 2);
        addAllNeighbours(tileLoc);
      }
      return true;
    }

    /*
     * Now generate the index in the list of inside states and check if the
     * tile is on a level that is hidden or not. If the tile is on such a
     * level it does not mean for sure that it really needs to be hidden.
     */
    final int insideIndex = tileLoc.getScZ() - playerLoc.getScZ() - 1;

    if ((insideIndex < 0) || (insideIndex > 1)) {
      LOGGER.warn("Invalid inside index: " + insideIndex);
      return true;
    }

    /*
     * Tile is not on a inside level. In case its hidden, show it again.
     */
    if (!insideStates[insideIndex]) {
      if (tile.isHidden()) {
        tile.setHidden(false);
        addAllBelow(tileLoc, playerLoc.getScZ() - 2);
        addAllAbove(tileLoc, playerLoc.getScZ() + 2);
        addAllNeighbours(tileLoc);
      }
      return true;
    }

    /*
     * Now check if the tile is directly above the player. In this case it
     * needs to be hidden.
     */
    if ((tileLoc.getScX() == playerLoc.getScX())
        && (tileLoc.getScY() == playerLoc.getScY())
        && (tileLoc.getScZ() > playerLoc.getScZ())
        && !tile.isHidden()) {
      tile.setHidden(true);
      addAllBelow(tileLoc, playerLoc.getScZ() - 2);
      addAllAbove(tileLoc, playerLoc.getScZ() + 2);
      addAllNeighbours(tileLoc);
      return true;
    }

    if (!tile.isHidden() && searchHiddenNeighbour(tileLoc)) {
      tile.setHidden(true);
      addAllBelow(tileLoc, playerLoc.getScZ() - 2);
      addAllAbove(tileLoc, playerLoc.getScZ() + 2);
      addAllNeighbours(tileLoc);
      return true;
    }

    return false;
  }