Exemplo n.º 1
0
  @Override
  protected void runImpl() {
    if (_items == null || _items.isEmpty() || !Config.ALLOW_FREIGHT) return;

    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    // player attempts to send freight to the different account
    if (!player.getAccountChars().containsKey(_objectID)) return;

    final PcFreight freight = player.getDepositedFreight(_objectID);
    player.setActiveWarehouse(freight);

    final ItemContainer warehouse = player.getActiveWarehouse();
    if (warehouse == null) return;

    final L2Npc manager = player.getCurrentFolkNPC();
    if ((manager == null
            || !player.isInsideRadius(manager, L2Npc.INTERACTION_DISTANCE, false, false))
        && !player.isGM()) return;

    if (warehouse instanceof PcFreight && !player.getAccessLevel().allowTransaction()) {
      player.sendMessage("Transactions are disabled for your Access Level.");
      return;
    }

    // Alt game - Karma punishment
    if (!Config.KARMA_PLAYER_CAN_USE_WH && player.getKarma() > 0) return;

    // Freight price from config or normal price per item slot (30)
    int fee = _items.size() * Config.ALT_GAME_FREIGHT_PRICE;
    int currentAdena = player.getAdena();
    int slots = 0;

    for (Item i : _items) {
      int objectId = i.id;
      int count = i.count;

      // Check validity of requested item
      ItemInstance item = player.checkItemManipulation(objectId, count);
      if (item == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (validity check)");
        i.id = 0;
        i.count = 0;
        continue;
      }

      if (!item.isTradable() || item.isQuestItem()) return;

      // Calculate needed adena and slots
      if (item.getItemId() == 57) currentAdena -= count;

      if (!item.isStackable()) slots += count;
      else if (warehouse.getItemByItemId(item.getItemId()) == null) slots++;
    }

    // Item Max Limit Check
    if (!warehouse.validateCapacity(slots)) {
      sendPacket(
          SystemMessage.getSystemMessage(
              SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
      return;
    }

    // Check if enough adena and charge the fee
    if (currentAdena < fee
        || !player.reduceAdena("Warehouse", fee, player.getCurrentFolkNPC(), false)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    // Proceed to the transfer
    InventoryUpdate playerIU = new InventoryUpdate();
    for (Item i : _items) {
      int objectId = i.id;
      int count = i.count;

      // check for an invalid item
      if (objectId == 0 && count == 0) continue;

      ItemInstance oldItem = player.getInventory().getItemByObjectId(objectId);
      if (oldItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (olditem == null)");
        continue;
      }

      if (oldItem.isHeroItem()) continue;

      ItemInstance newItem =
          player
              .getInventory()
              .transferItem(
                  "Warehouse", objectId, count, warehouse, player, player.getCurrentFolkNPC());
      if (newItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (newitem == null)");
        continue;
      }

      if (oldItem.getCount() > 0 && oldItem != newItem) playerIU.addModifiedItem(oldItem);
      else playerIU.addRemovedItem(oldItem);
    }

    // Send updated item list to the player
    player.sendPacket(playerIU);

    // Update current load status on player
    StatusUpdate su = new StatusUpdate(player);
    su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    player.sendPacket(su);
  }
Exemplo n.º 2
0
  @Override
  protected void runImpl() {
    if (_items == null) return;

    L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    L2Object manager = player.getCurrentFolkNPC();
    if (!(manager instanceof L2ManorManagerInstance)) return;

    if (!player.isInsideRadius(manager, L2Npc.INTERACTION_DISTANCE, false, false)) return;

    int castleId = ((L2ManorManagerInstance) manager).getCastle().getCastleId();

    // Calculate summary values
    int slots = 0;
    int weight = 0;

    for (Crop i : _items) {
      if (!i.getCrop()) continue;

      Item template = ItemTable.getInstance().getTemplate(i.getReward());
      weight += i.getCount() * template.getWeight();

      if (!template.isStackable()) slots += i.getCount();
      else if (player.getInventory().getItemByItemId(i.getItemId()) == null) slots++;
    }

    if (!player.getInventory().validateWeight(weight)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    if (!player.getInventory().validateCapacity(slots)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Proceed the purchase
    for (Crop i : _items) {
      if (i.getReward() == 0) continue;

      int fee = i.getFee(castleId); // fee for selling to other manors

      int rewardPrice = ItemTable.getInstance().getTemplate(i.getReward()).getReferencePrice();
      if (rewardPrice == 0) continue;

      int rewardItemCount = i.getPrice() / rewardPrice;
      if (rewardItemCount < 1) {
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1)
                .addItemName(i.getItemId())
                .addItemNumber(i.getCount()));
        continue;
      }

      if (player.getAdena() < fee) {
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1)
                .addItemName(i.getItemId())
                .addItemNumber(i.getCount()));
        player.sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
        continue;
      }

      // check if player have correct items count
      ItemInstance item = player.getInventory().getItemByObjectId(i.getObjectId());
      if (item == null || item.getCount() < i.getCount()) continue;

      // try modify castle crop
      if (!i.setCrop()) continue;

      if (fee > 0 && !player.reduceAdena("Manor", fee, manager, true)) continue;

      if (!player.destroyItem("Manor", i.getObjectId(), i.getCount(), manager, true)) continue;

      player.addItem("Manor", i.getReward(), rewardItemCount, manager, true);
    }
  }