Ejemplo n.º 1
0
  /**
   * Удаляет указанные предметы из инвентаря игрока, и обновляет инвентарь
   *
   * @param itemId : id удаляемого предмета
   * @param count : число удаляемых предметов<br>
   *     Если count передать -1, то будут удалены все указанные предметы.
   * @return Количество удаленных предметов
   */
  public long takeItems(int itemId, long count) {
    Player player = getPlayer();
    if (player == null) {
      return 0;
    }

    // Get object item from player's inventory list
    ItemInstance item = player.getInventory().getItemByItemId(itemId);
    if (item == null) {
      return 0;
    }
    // Tests on count value in order not to have negative value
    if ((count < 0) || (count > item.getCount())) {
      count = item.getCount();
    }

    // Destroy the quantity of items wanted
    player.getInventory().destroyItemByItemId(itemId, count);
    // Send message of destruction to client
    player.sendPacket(SystemMessage2.removeItems(itemId, count));

    return count;
  }