{
L2ItemInstance[] list = inv.getAllItemsById(ingridientItemId);
// Если энчант имеет значение - то ищем вещи с точно таким энчантом
if(_keepenchant)
{
L2ItemInstance itemToTake = null;
for(L2ItemInstance itm : list)
{
if((itm.getEnchantLevel() == _enchant || itm.getItem().getType2() > 2) && !_items.contains(new ItemData(itm.getItemId(), itm.getCount(), itm)) && !itm.isShadowItem() && !itm.isTemporalItem() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE)
{
itemToTake = itm;
if(itm.getAttributeElement() != L2Item.ATTRIBUTE_NONE)
{
_enchantAttr = itm.getAttributeElement();
_enchantAttrVal = itm.getAttributeElementValue();
}
break;
}
}
if(itemToTake == null)
{
activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
return;
}
if(!checkItem(itemToTake, activeChar))
{
activeChar.sendActionFailed();
return;
}
if(itemToTake.getAugmentation() != null)
{
augmentation = itemToTake.getAugmentation();
}
_items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
}
// Если энчант не обрабатывается берется вещь с наименьшим энчантом
else
{
L2ItemInstance itemToTake = null;
for(L2ItemInstance itm : list)
{
if(!_items.contains(new ItemData(itm.getItemId(), itm.getCount(), itm)) && (itemToTake == null || itm.getEnchantLevel() < itemToTake.getEnchantLevel()) && !itm.isShadowItem() && !itm.isTemporalItem() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE && checkItem(itm, activeChar))
{
itemToTake = itm;
if(itemToTake.getEnchantLevel() == 0)
{
break;
}
}
}
if(itemToTake == null)
{
activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
return;
}
if(itemToTake.getAugmentation() != null)
{
augmentation = itemToTake.getAugmentation();
}
_items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
}
}
}
else if(ingridientItemId == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
{
if(activeChar.getClan() == null)
{
activeChar.sendPacket(Msg.YOU_ARE_NOT_A_CLAN_MEMBER);
return;
}
if(activeChar.getClan().getReputationScore() < total_amount)
{
activeChar.sendPacket(Msg.THE_CLAN_REPUTATION_SCORE_IS_TOO_LOW);
return;
}
if(activeChar.getClan().getLeaderId() != activeChar.getObjectId())
{
activeChar.sendPacket(new SystemMessage(SystemMessage.S1_IS_NOT_A_CLAN_LEADER).addString(activeChar.getName()));
return;
}
_items.add(new ItemData(ingridientItemId, total_amount, null));
}
else if(ingridientItemId == L2Item.ITEM_ID_PC_BANG_POINTS)
{
if(activeChar.getPcBangPoints() < total_amount)
{
activeChar.sendPacket(Msg.YOU_ARE_SHORT_OF_ACCUMULATED_POINTS);
return;
}
_items.add(new ItemData(ingridientItemId, total_amount, null));
}
else if(ingridientItemId == L2Item.ITEM_ID_FAME)
{
if(activeChar.getFame() < total_amount)
{
activeChar.sendPacket(Msg.NOT_ENOUGH_FAME_POINTS);
return;
}
_items.add(new ItemData(ingridientItemId, total_amount, null));
}
else
{
if(ingridientItemId == 57)
{
totalAdenaCost += ingridientItemCount * _amount;
}
L2ItemInstance item = inv.getItemByItemId(ingridientItemId);
if(item == null || item.getCount() < total_amount)
{
activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
return;
}
_items.add(new ItemData(item.getItemId(), total_amount, item));
}
if(activeChar.getAdena() < totalAdenaCost)
{
activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
return;
}
}
for(ItemData id : _items)
{
long count = id.getCount();
if(count > 0)
{
L2ItemInstance item = id.getItem();
if(item != null)
{
activeChar.sendPacket(SystemMessage.removeItems(item.getItemId(), count));
if(logExchange)
{
msgb.append("\t<destroy id=").append(item.getItemId()).append(" oid=").append(item.getObjectId()).append(" count=").append(count).append(">\n");
}
if(item.isEquipped())
{
inv.unEquipItemInSlot(item.getEquipSlot());
}
inv.destroyItem(item, count, true);
}
else if(id.getId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
{
activeChar.getClan().incReputation((int) -count, false, "MultiSell" + _listId);
activeChar.sendPacket(new SystemMessage(SystemMessage.S1_POINTS_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_REPUTATION_SCORE).addNumber(count));
}
else if(id.getId() == L2Item.ITEM_ID_PC_BANG_POINTS)
{
activeChar.setPcBangPoints(activeChar.getPcBangPoints() - (int) count);
activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_ARE_USING_S1_POINT).addNumber(count), new ExPCCafePointInfo(activeChar));
}
else if(id.getId() == L2Item.ITEM_ID_FAME)
{
activeChar.setFame(activeChar.getFame() - (int) count, "MultiSell" + _listId);
activeChar.sendPacket(new SystemMessage(SystemMessage.S2_S1_HAS_DISAPPEARED).addNumber(count).addString("Fame"));
}
}
}
if(tax > 0 && !_notax)
{
if(castle != null)
{
activeChar.sendMessage("Tax: " + tax);
if(merchant != null && merchant.getReflection().getId() == 0)
{
castle.addToTreasury(tax, true, false);
Log.add(castle.getName() + "|" + tax + "|Multisell", "treasury");
}
}
}
for(MultiSellIngredient in : productId)
{
if(in.getItemId() <= 0)
{
if(in.getItemId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
{
activeChar.getClan().incReputation((int) (in.getItemCount() * _amount), false, "MultiSell" + _listId);
activeChar.sendPacket(new SystemMessage(SystemMessage.YOUR_CLAN_HAS_ADDED_1S_POINTS_TO_ITS_CLAN_REPUTATION_SCORE).addNumber(in.getItemCount() * _amount));
}
else if(in.getItemId() == L2Item.ITEM_ID_PC_BANG_POINTS)
{
activeChar.setPcBangPoints(activeChar.getPcBangPoints() + (int) (in.getItemCount() * _amount));
activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_ACQUIRED_S1_PC_BANG_POINT).addNumber(in.getItemCount() * _amount), new ExPCCafePointInfo(activeChar));
}
else if(in.getItemId() == L2Item.ITEM_ID_FAME)
{
activeChar.setFame(activeChar.getFame() + (int) (in.getItemCount() * _amount), "MultiSell" + _listId);
}
}
else if(ItemTable.getInstance().getTemplate(in.getItemId()).isStackable())
{
L2ItemInstance product = ItemTable.getInstance().createItem(in.getItemId());
double total = in.getItemCount() * _amount;
if(total < 0 || total > Long.MAX_VALUE)
{
activeChar.sendActionFailed();
return;
}
product.setCount((long) total);
activeChar.sendPacket(SystemMessage.obtainItems(product));
if(logExchange)
{
msgb.append("\t<add id=").append(product.getItemId()).append(" count=").append(product.getCount()).append(">\n");
}
inv.addItem(product);
}
else
{
for(int i = 0; i < _amount; i++)
{
L2ItemInstance product = inv.addItem(ItemTable.getInstance().createItem(in.getItemId()));
if(_keepenchant)
{
product.setEnchantLevel(_enchant);
if(_enchantAttr != L2Item.ATTRIBUTE_NONE)
{
product.setAttributeElement(_enchantAttr, _enchantAttrVal, true);
}
}
if(in.getElementValue() > 0)
{
product.setAttributeElement(in.getElement(), in.getElementValue(), true);
}
if(augmentation != null && product.isEquipable() && product.canBeEnchanted() && !product.isRaidAccessory())
{
product.setAugmentation(augmentation);
}
if(logExchange)
{
msgb.append("\t<add id=").append(product.getItemId()).append(" oid=").append(product.getObjectId()).append(" count=").append(product.getCount()).append(">\n");
}
activeChar.sendPacket(SystemMessage.obtainItems(product));
}
}
}