Beispiel #1
0
  /**
   * Handles an interaction with this ground item
   *
   * @param player The player interacting with the object
   * @param option The option selected
   * @return True if the interaction was successful, false otherwise
   */
  public boolean interact(Player player, OptionButton option) {
    if (owner != null && owner.getUserHash() != player.getUserHash()) {
      logger.warn(
          "Player "
              + player.getName()
              + " attempted to interact with item "
              + this.getId()
              + ", which is currently only visible to "
              + owner.getName());
      return true;
    }
    if (OptionButton.SIX.equals(option)) {
      this.examine(player);
      return true;
    }
    ScriptEventType eventType;
    switch (option) {
      case ONE:
        eventType = ScriptEventType.OPOBJ1;
        break;
      case TWO:
        eventType = ScriptEventType.OPOBJ2;
        break;
      case THREE:
        eventType = ScriptEventType.OPOBJ3;
        break;
      case FOUR:
        eventType = ScriptEventType.OPOBJ4;
        break;
      case FIVE:
        eventType = ScriptEventType.OPOBJ5;
        break;
      default:
        eventType = null;
        break;
    }
    ScriptManager scripts = Virtue.getInstance().getScripts();
    if (eventType != null && scripts.hasBinding(eventType, this.getId())) {
      Map<String, Object> args = new HashMap<>();
      args.put("player", player);
      args.put("item", this);
      args.put("coords", tile);
      scripts.invokeScriptChecked(eventType, this.getId(), args);
      return true;
    }

    if (OptionButton.THREE.equals(option)
        && "Take".equalsIgnoreCase(this.getType().op[2])) { // Take
      if (player.getInvs().getContainer(ContainerState.BACKPACK).freeSlots() > 0) {
        Region region = World.getInstance().getRegions().getRegionByID(tile.getRegionID());
        if (region != null) {
          GroundItem oldItem = region.removeItem(tile, this.getId());
          if (oldItem != null) {
            player.getInvs().addBackpackItem(new Item(oldItem));
            return true;
          }
        }
      }
    }
    return false;
  }