Пример #1
0
  public static long removeItem(Playable playable, ItemInstance item, long count, boolean notify) {
    long removed = 0;
    if (playable == null || count < 1) return removed;

    Playable player = playable.getPlayer();
    if (item.getTemplate().isStackable()) {
      if (player.getInventory().destroyItem(item, count)) removed = count;
    } else
      for (long i = 0; i < count; i++) if (player.getInventory().destroyItem(item, 1)) removed++;

    if (removed > 0 && notify)
      player.sendPacket(SystemMessage2.removeItems(item.getItemId(), removed));

    return removed;
  }
Пример #2
0
  /**
   * Добавляет предмет в инвентарь игрока, корректно обрабатывает нестыкуемые вещи
   *
   * @param playable Владелец инвентаря
   * @param itemId ID предмета
   * @param count количество
   */
  public static void addItem(Playable playable, int itemId, long count, boolean notify) {
    if (playable == null || count < 1) return;

    Playable player;
    if (playable.isSummon()) player = playable.getPlayer();
    else player = playable;

    if (itemId > 0) {
      ItemTemplate t = ItemHolder.getInstance().getTemplate(itemId);
      if (t.isStackable()) player.getInventory().addItem(itemId, count);
      else for (long i = 0; i < count; i++) player.getInventory().addItem(itemId, 1);

      if (notify) player.sendPacket(SystemMessage2.obtainItems(itemId, count, 0));
    } else if (itemId == -100 && player.isPlayer()) {
      player.getPlayer().addPcBangPoints((int) count, false);
    } else if (itemId == -200 && player.isPlayer()) {
      if (player.getPlayer().getClan() != null)
        player.getPlayer().getClan().incReputation((int) count, false, "itemFunction");
    } else if (itemId == -300 && player.isPlayer()) {
      player.getPlayer().setFame((int) count + player.getPlayer().getFame(), "itemFunction");
    }
  }