@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); }
@Override protected void runImpl() { if (_items == null) return; final L2PcInstance player = getClient().getActiveChar(); if (player == null) return; if (player.isProcessingTransaction()) { player.sendPacket(SystemMessageId.ALREADY_TRADING); return; } if (player.getActiveEnchantItem() != null) { player.setActiveEnchantItem(null); player.sendPacket(EnchantResult.CANCELLED); player.sendPacket(SystemMessageId.ENCHANT_SCROLL_CANCELLED); } final ItemContainer warehouse = player.getActiveWarehouse(); if (warehouse == null) return; final boolean isPrivate = warehouse instanceof PcWarehouse; final L2Npc manager = player.getCurrentFolkNPC(); if ((manager == null || !manager.isWarehouse() || !manager.canInteract(player)) && !player.isGM()) return; if (!isPrivate && !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) final int fee = _items.length * 30; int currentAdena = player.getAdena(); int slots = 0; for (WarehouseItem i : _items) { ItemInstance item = player.checkItemManipulation(i.getObjectId(), i.getCount()); if (item == null) { _log.warning( "Error depositing a warehouse object for char " + player.getName() + " (validity check)"); return; } // Calculate needed adena and slots if (item.getItemId() == ADENA_ID) currentAdena -= i.getCount(); if (!item.isStackable()) slots += i.getCount(); 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.getName(), fee, manager, false)) { sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA)); return; } // get current tradelist if any if (player.getActiveTradeList() != null) return; // Proceed to the transfer InventoryUpdate playerIU = new InventoryUpdate(); for (WarehouseItem i : _items) { // Check validity of requested item ItemInstance oldItem = player.checkItemManipulation(i.getObjectId(), i.getCount()); if (oldItem == null) { _log.warning( "Error depositing a warehouse object for char " + player.getName() + " (olditem == null)"); return; } if (!oldItem.isDepositable(isPrivate) || !oldItem.isAvailable(player, true, isPrivate)) continue; final ItemInstance newItem = player .getInventory() .transferItem( warehouse.getName(), i.getObjectId(), i.getCount(), warehouse, player, manager); 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); }