예제 #1
0
  /**
   * Adds item to inventory
   *
   * @param process : String Identifier of process triggering this action
   * @param itemId : int Item Identifier of the item to be added
   * @param count : int Quantity of items to be added
   * @param actor : L2PcInstance Player requesting the item add
   * @param reference : Object Object referencing current action like NPC selling item or previous
   *     item in transformation
   * @return L2ItemInstance corresponding to the new item or the updated item in inventory
   */
  public L2ItemInstance addItem(
      String process, int itemId, long count, L2PcInstance actor, Object reference) {
    L2ItemInstance item = getItemByItemId(itemId);

    // If stackable item is found in inventory just add to current quantity
    if (item != null && item.isStackable()) {
      item.changeCount(process, count, actor, reference);
      item.setLastChange(L2ItemInstance.MODIFIED);
      // Updates database
      if (itemId == 57 && count < 10000 * Config.RATE_DROP_ITEMS_ID.get(57)) {
        // Small adena changes won't be saved to database all the time
        if (GameTimeController.getGameTicks() % 5 == 0) item.updateDatabase();
      } else item.updateDatabase();
    }
    // If item hasn't be found in inventory, create new one
    else {
      for (int i = 0; i < count; i++) {
        L2Item template = ItemTable.getInstance().getTemplate(itemId);
        if (template == null) {
          _log.log(
              Level.WARNING,
              (actor != null ? "[" + actor.getName() + "] " : "") + "Invalid ItemId requested: ",
              itemId);
          return null;
        }

        item =
            ItemTable.getInstance()
                .createItem(process, itemId, template.isStackable() ? count : 1, actor, reference);
        item.setOwnerId(getOwnerId());
        item.setLocation(getBaseLocation());
        item.setLastChange(L2ItemInstance.ADDED);

        // Add item in inventory
        addItem(item);
        // Updates database
        item.updateDatabase();

        // If stackable, end loop as entire count is included in 1 instance of item
        if (template.isStackable() || !Config.MULTIPLE_ITEM_DROP) break;
      }
    }

    refreshWeight();
    return item;
  }
예제 #2
0
  /**
   * Adds item to inventory
   *
   * @param process : String Identifier of process triggering this action
   * @param item : L2ItemInstance to be added
   * @param actor : L2PcInstance Player requesting the item add
   * @param reference : Object Object referencing current action like NPC selling item or previous
   *     item in transformation
   * @return L2ItemInstance corresponding to the new item or the updated item in inventory
   */
  public L2ItemInstance addItem(
      String process, L2ItemInstance item, L2PcInstance actor, Object reference) {
    L2ItemInstance olditem = getItemByItemId(item.getItemId());

    // If stackable item is found in inventory just add to current quantity
    if (olditem != null && olditem.isStackable()) {
      long count = item.getCount();
      olditem.changeCount(process, count, actor, reference);
      olditem.setLastChange(L2ItemInstance.MODIFIED);

      // And destroys the item
      ItemTable.getInstance().destroyItem(process, item, actor, reference);
      item.updateDatabase();
      item = olditem;

      // Updates database
      if (item.getItemId() == 57 && count < 10000 * Config.RATE_DROP_ITEMS_ID.get(57)) {
        // Small adena changes won't be saved to database all the time
        if (GameTimeController.getGameTicks() % 5 == 0) item.updateDatabase();
      } else item.updateDatabase();
    }
    // If item hasn't be found in inventory, create new one
    else {
      item.setOwnerId(process, getOwnerId(), actor, reference);
      item.setLocation(getBaseLocation());
      item.setLastChange((L2ItemInstance.ADDED));

      // Add item in inventory
      addItem(item);

      // Updates database
      item.updateDatabase();
    }

    refreshWeight();
    return item;
  }