}
@Override
protected void runImpl()
{
L2PcInstance player = getClient().getActiveChar();
if (player == null)
return;
if (!player.getAccessLevel().allowTransaction())
{
player.sendMessage("Transactions are disable for your Access Level");
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (player.isTradeDisabled())
{
player.sendMessage("Trade are disable here. Try in another place.");
player.sendPacket(new PrivateStoreManageListBuy(player));
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (player.isCastingNow() || player.isCastingPotionNow() || player.isMovementDisabled() || player.inObserverMode() || player.getActiveEnchantItem() != null)
{
player.sendMessage("You cannot start store now..");
player.sendPacket(new PrivateStoreManageListBuy(player));
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (player.isInsideZone(L2Character.ZONE_NOSTORE))
{
player.sendPacket(new PrivateStoreManageListBuy(player));
player.sendMessage("Trade are disable here. Try in another place.");
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
TradeList tradeList = player.getBuyList();
tradeList.clear();
int cost = 0;
for (int i = 0; i < _count; i++)
{
int itemId = _items[i * 4 + 0];
int count = _items[i * 4 + 1];
int price = _items[i * 4 + 2];
int enchant = _items[i * 4 + 3];
tradeList.addItemByItemId(itemId, count, price, enchant);
cost += count * price;
if (cost > Integer.MAX_VALUE)
{
player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
player.sendPacket(new PrivateStoreManageListBuy(player));
return;
}
}
if (_count <= 0)
{
player.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
player.broadcastUserInfo();
return;
}
if (player.isProcessingTransaction())
{
player.sendMessage("Store mode are disable while trading.");
player.sendPacket(new PrivateStoreManageListBuy(player));
return;
}
// Check maximum number of allowed slots for pvt shops
if (_count > player.GetPrivateBuyStoreLimit())
{
player.sendPacket(new PrivateStoreManageListBuy(player));
player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
return;
}
// Check for available funds
if (Config.SELL_BY_ITEM)
{
if (cost > player.getItemCount(Config.SELL_ITEM, -1) || cost <= 0)
{
player.sendPacket(new PrivateStoreManageListBuy(player));
player.sendPacket(new SystemMessage(SystemMessageId.THE_PURCHASE_PRICE_IS_HIGHER_THAN_MONEY));
return;
}
}
else
{
if (cost > player.getAdena() || cost <= 0)
{
player.sendPacket(new PrivateStoreManageListBuy(player));
player.sendPacket(new SystemMessage(SystemMessageId.THE_PURCHASE_PRICE_IS_HIGHER_THAN_MONEY));
return;
}
}
player.sitDown();
player.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_BUY);
player.broadcastUserInfo();
player.broadcastPacket(new PrivateStoreMsgBuy(player));
}