player.sendMessage("You can't withdraw items when you are trading.");
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
ItemContainer warehouse = player.getActiveWarehouse();
if(warehouse == null)
return;
L2FolkInstance manager = player.getLastFolkNPC();
if((manager == null || !player.isInsideRadius(manager, L2NpcInstance.INTERACTION_DISTANCE, false, false)) && !player.isGM())
return;
if(warehouse instanceof ClanWarehouse && !player.getAccessLevel().allowTransaction())
{
player.sendMessage("Unsufficient privileges.");
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Alt game - Karma punishment
if(!Config.ALT_GAME_KARMA_PLAYER_CAN_USE_WAREHOUSE && player.getKarma() > 0)
return;
if(Config.ALT_MEMBERS_CAN_WITHDRAW_FROM_CLANWH)
{
if(warehouse instanceof ClanWarehouse && (player.getClanPrivileges() & L2Clan.CP_CL_VIEW_WAREHOUSE) != L2Clan.CP_CL_VIEW_WAREHOUSE)
return;
}
else
{
if(warehouse instanceof ClanWarehouse && !player.isClanLeader())
{
// this msg is for depositing but maybe good to send some msg?
player.sendPacket(new SystemMessage(SystemMessageId.ONLY_CLAN_LEADER_CAN_RETRIEVE_ITEMS_FROM_CLAN_WAREHOUSE));
return;
}
}
int weight = 0;
int slots = 0;
for(int i = 0; i < _count; i++)
{
int objectId = _items[i * 2 + 0];
int count = _items[i * 2 + 1];
// Calculate needed slots
L2ItemInstance item = warehouse.getItemByObjectId(objectId);
if(item == null)
{
continue;
}
weight += count * item.getItem().getWeight();
if(!item.isStackable())
{
slots += count;
}
else if(player.getInventory().getItemByItemId(item.getItemId()) == null)
{
slots++;
}
}
// Item Max Limit Check
if(!player.getInventory().validateCapacity(slots))
{
sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
return;
}
// Like L2OFF enchant window must close
if(player.getActiveEnchantItem() != null)
{
sendPacket(new SystemMessage(SystemMessageId.ENCHANT_SCROLL_CANCELLED));
player.sendPacket(new EnchantResult(0));
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Weight limit Check
if(!player.getInventory().validateWeight(weight))
{
sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
return;
}
// Proceed to the transfer
InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
for(int i = 0; i < _count; i++)
{
int objectId = _items[i * 2 + 0];
int count = _items[i * 2 + 1];
L2ItemInstance oldItem = warehouse.getItemByObjectId(objectId);
if(oldItem == null || oldItem.getCount() < count)
{
player.sendMessage("Can't withdraw requested item" + (count > 1 ? "s" : ""));
}
L2ItemInstance newItem = warehouse.transferItem("Warehouse", objectId, count, player.getInventory(), player, player.getLastFolkNPC());
if(newItem == null)
{
_log.warning("Error withdrawing a warehouse object for char " + player.getName());
continue;
}