int amount = 0;
int x = 0;
int y = 0;
List<SystemMessage> sysmsgs = new FastList<SystemMessage>();
SystemMessage msg = null;
for(TradeItem buyerItem : buyerslist)
{
for(x=0 ; x < sellerslist.size(); x++)//find in sellerslist
{
temp2 = sellerslist.get(x);
if (temp2.getItemId() == buyerItem.getItemId())
{
sellerItem = sellerInv.getItemByItemId(buyerItem.getItemId());
break;
}
}
if (sellerItem !=null)
{
if (buyerItem.getCount()> temp2.getCount())
{
amount = temp2.getCount();
}
if (buyerItem.getCount()> sellerItem.getCount())
{
amount = sellerItem.getCount();
}
else
{
amount = buyerItem.getCount();
}
if (buyerItem.getCount() > Integer.MAX_VALUE / buyerItem.getOwnersPrice())
{
_log.warning("Integer Overflow on Cost. Possible Exploit attempt between "+buyer.getName()+" and "+seller.getName()+".");
return;
}
//int cost = amount * buyerItem.getOwnersPrice();
enchantLevel = sellerItem.getEnchantLevel();
sellerItem = sellerInv.destroyItem("", sellerItem.getObjectId(),amount, null, null);
// buyer.reduceAdena(cost);
// seller.addAdena(cost);
newitem = itemTable.createItem("L2TradeList", sellerItem.getItemId(), amount, buyer, seller);
newitem.setEnchantLevel(enchantLevel);
temp = buyerInv.addItem("", newitem, null, null);
if (amount == 1)//system msg stuff
{
msg = new SystemMessage(SystemMessageId.S1_PURCHASED_S2);
msg.addString(buyer.getName());
msg.addItemName(sellerItem.getItemId());
sysmsgs.add(msg);
msg = new SystemMessage(SystemMessageId.S1_PURCHASED_S2);
msg.addString("You");
msg.addItemName(sellerItem.getItemId());
sysmsgs.add(msg);
}
else
{
msg = new SystemMessage(SystemMessageId.S1_PURCHASED_S3_S2_S);
msg.addString(buyer.getName());
msg.addItemName(sellerItem.getItemId());
msg.addNumber(amount);
sysmsgs.add(msg);
msg = new SystemMessage(SystemMessageId.S1_PURCHASED_S3_S2_S);
msg.addString("You");
msg.addItemName(sellerItem.getItemId());
msg.addNumber(amount);
sysmsgs.add(msg);
}
if(temp2.getCount() == buyerItem.getCount())
{
sellerslist.remove(temp2);