if ((whkeeper == null) || !activeChar.isInRange(whkeeper, Creature.INTERACTION_DISTANCE))
{
activeChar.sendPacket(Msg.WAREHOUSE_IS_TOO_FAR);
return;
}
Warehouse warehouse = null;
String logType = null;
if (activeChar.getUsingWarehouseType() == WarehouseType.PRIVATE)
{
warehouse = activeChar.getWarehouse();
logType = Log.WarehouseWithdraw;
}
else if (activeChar.getUsingWarehouseType() == WarehouseType.CLAN)
{
logType = Log.ClanWarehouseWithdraw;
boolean canWithdrawCWH = false;
if (activeChar.getClan() != null)
{
if (((activeChar.getClanPrivileges() & Clan.CP_CL_WAREHOUSE_SEARCH) == Clan.CP_CL_WAREHOUSE_SEARCH) && (Config.ALT_ALLOW_OTHERS_WITHDRAW_FROM_CLAN_WAREHOUSE || activeChar.isClanLeader() || activeChar.getVarB("canWhWithdraw")))
{
canWithdrawCWH = true;
}
}
if (!canWithdrawCWH)
{
return;
}
warehouse = activeChar.getClan().getWarehouse();
}
else if (activeChar.getUsingWarehouseType() == WarehouseType.FREIGHT)
{
warehouse = activeChar.getFreight();
logType = Log.FreightWithdraw;
}
else
{
_log.warn("Error retrieving a warehouse object for char " + activeChar.getName() + " - using warehouse type: " + activeChar.getUsingWarehouseType());
return;
}
PcInventory inventory = activeChar.getInventory();
inventory.writeLock();
warehouse.writeLock();
try
{
long weight = 0;
int slots = 0;
for (int i = 0; i < _count; i++)
{
ItemInstance item = warehouse.getItemByObjectId(_items[i]);
if ((item == null) || (item.getCount() < _itemQ[i]))
{
activeChar.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
return;
}
weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(item.getTemplate().getWeight(), _itemQ[i]));
if (!item.isStackable() || (inventory.getItemByItemId(item.getItemId()) == null))
{
slots++;
}
}
if (!activeChar.getInventory().validateCapacity(slots))
{
activeChar.sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
return;
}
if (!activeChar.getInventory().validateWeight(weight))
{
activeChar.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
return;
}
for (int i = 0; i < _count; i++)
{
ItemInstance item = warehouse.removeItemByObjectId(_items[i], _itemQ[i]);
Log.LogItem(activeChar, logType, item);
activeChar.getInventory().addItem(item);
}
}
catch (ArithmeticException ae)
{
sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
return;
}
finally
{
warehouse.writeUnlock();
inventory.writeUnlock();
}
activeChar.sendChanges();
activeChar.sendPacket(Msg.THE_TRANSACTION_IS_COMPLETE);
}