Reuse item info for multisells that are maintainEnchantment enabled.
This commit is contained in:
		@@ -291,7 +291,7 @@ public class MultisellData implements IXmlReader
 | 
			
		||||
		do
 | 
			
		||||
		{
 | 
			
		||||
			// send list at least once even if size = 0
 | 
			
		||||
			player.sendPacket(new MultiSellList(list, index));
 | 
			
		||||
			player.sendPacket(new MultiSellList(player, list, index));
 | 
			
		||||
			index += PAGE_SIZE;
 | 
			
		||||
		}
 | 
			
		||||
		while (index < list.getEntries().size());
 | 
			
		||||
 
 | 
			
		||||
@@ -173,7 +173,7 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		final ItemInfo itemEnchantment = list.getItemEnchantment(_entryId - 1); // Entry Id begins from 1. We currently use entry IDs as index pointer.
 | 
			
		||||
		ItemInfo itemEnchantment = list.getItemEnchantment(_entryId - 1); // Entry Id begins from 1. We currently use entry IDs as index pointer.
 | 
			
		||||
		
 | 
			
		||||
		// Validate the requested item with its full stats.
 | 
			
		||||
		//@formatter:off
 | 
			
		||||
@@ -319,7 +319,6 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
			
 | 
			
		||||
			final InventoryUpdate iu = new InventoryUpdate();
 | 
			
		||||
			boolean itemEnchantmentProcessed = (itemEnchantment == null);
 | 
			
		||||
			int enchantLevel = -1;
 | 
			
		||||
			
 | 
			
		||||
			// Take all ingredients
 | 
			
		||||
			for (ItemChanceHolder ingredient : entry.getIngredients())
 | 
			
		||||
@@ -382,9 +381,9 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
					{
 | 
			
		||||
						itemEnchantmentProcessed = true;
 | 
			
		||||
						iu.addItem(destroyedItem);
 | 
			
		||||
						if (enchantLevel < 0) // Will only consider first ingredient enchant.
 | 
			
		||||
						if (itemEnchantmentProcessed && destroyedItem.isEquipable()) // Will only consider first equipable ingredient.
 | 
			
		||||
						{
 | 
			
		||||
							enchantLevel = destroyedItem.getEnchantLevel();
 | 
			
		||||
							itemEnchantment = new ItemInfo(destroyedItem);
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					else
 | 
			
		||||
@@ -403,9 +402,9 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
					{
 | 
			
		||||
						itemEnchantmentProcessed = true;
 | 
			
		||||
						iu.addItem(destroyedItem);
 | 
			
		||||
						if (enchantLevel < 0) // Will only consider first ingredient enchant.
 | 
			
		||||
						if (itemEnchantmentProcessed && destroyedItem.isEquipable()) // Will only consider first equipable ingredient.
 | 
			
		||||
						{
 | 
			
		||||
							enchantLevel = destroyedItem.getEnchantLevel();
 | 
			
		||||
							itemEnchantment = new ItemInfo(destroyedItem);
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					else
 | 
			
		||||
@@ -423,9 +422,9 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
					if (destroyedItem != null)
 | 
			
		||||
					{
 | 
			
		||||
						iu.addItem(destroyedItem);
 | 
			
		||||
						if (enchantLevel < 0) // Will only consider first ingredient enchant.
 | 
			
		||||
						if (itemEnchantmentProcessed && destroyedItem.isEquipable()) // Will only consider first equipable ingredient.
 | 
			
		||||
						{
 | 
			
		||||
							enchantLevel = destroyedItem.getEnchantLevel();
 | 
			
		||||
							itemEnchantment = new ItemInfo(destroyedItem);
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					else
 | 
			
		||||
@@ -544,7 +543,9 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
								addedItem.addSpecialAbility(ensoul, 0, 2, false);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						addedItem.updateDatabase(true);
 | 
			
		||||
						
 | 
			
		||||
						// Mark that we have already upgraded the item.
 | 
			
		||||
						itemEnchantmentProcessed = false;
 | 
			
		||||
					}
 | 
			
		||||
@@ -554,12 +555,6 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
						addedItem.setEnchantLevel(product.getEnchantmentLevel());
 | 
			
		||||
						addedItem.updateDatabase(true);
 | 
			
		||||
					}
 | 
			
		||||
					else if (itemEnchantmentProcessed && list.isMaintainEnchantment() && (enchantLevel > 0) && !addedItem.getItem().isEtcItem())
 | 
			
		||||
					{
 | 
			
		||||
						addedItem.setEnchantLevel(enchantLevel);
 | 
			
		||||
						addedItem.updateDatabase(true);
 | 
			
		||||
						enchantLevel = -1; // Will only enchant first product.
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					if (addedItem.getCount() > 1)
 | 
			
		||||
					{
 | 
			
		||||
@@ -590,7 +585,7 @@ public class MultiSellChoose implements IClientIncomingPacket
 | 
			
		||||
			// Update inventory and weight.
 | 
			
		||||
			player.sendInventoryUpdate(iu);
 | 
			
		||||
			
 | 
			
		||||
			// finally, give the tax to the castle...
 | 
			
		||||
			// Finally, give the tax to the castle.
 | 
			
		||||
			if ((npc != null) && list.isApplyTaxes())
 | 
			
		||||
			{
 | 
			
		||||
				final OptionalLong taxPaid = entry.getIngredients().stream().filter(i -> i.getId() == Inventory.ADENA_ID).mapToLong(i -> Math.round(i.getCount() * list.getIngredientMultiplier() * list.getTaxRate()) * _amount).reduce(Math::multiplyExact);
 | 
			
		||||
 
 | 
			
		||||
@@ -21,21 +21,25 @@ import static org.l2jmobius.gameserver.data.xml.MultisellData.PAGE_SIZE;
 | 
			
		||||
import org.l2jmobius.commons.network.PacketWriter;
 | 
			
		||||
import org.l2jmobius.gameserver.data.ItemTable;
 | 
			
		||||
import org.l2jmobius.gameserver.model.ItemInfo;
 | 
			
		||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
 | 
			
		||||
import org.l2jmobius.gameserver.model.holders.ItemChanceHolder;
 | 
			
		||||
import org.l2jmobius.gameserver.model.holders.MultisellEntryHolder;
 | 
			
		||||
import org.l2jmobius.gameserver.model.holders.PreparedMultisellListHolder;
 | 
			
		||||
import org.l2jmobius.gameserver.model.items.Item;
 | 
			
		||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
 | 
			
		||||
import org.l2jmobius.gameserver.network.OutgoingPackets;
 | 
			
		||||
 | 
			
		||||
public class MultiSellList extends AbstractItemPacket
 | 
			
		||||
{
 | 
			
		||||
	private final PlayerInstance _player;
 | 
			
		||||
	private int _size;
 | 
			
		||||
	private int _index;
 | 
			
		||||
	private final PreparedMultisellListHolder _list;
 | 
			
		||||
	private final boolean _finished;
 | 
			
		||||
	
 | 
			
		||||
	public MultiSellList(PreparedMultisellListHolder list, int index)
 | 
			
		||||
	public MultiSellList(PlayerInstance player, PreparedMultisellListHolder list, int index)
 | 
			
		||||
	{
 | 
			
		||||
		_player = player;
 | 
			
		||||
		_list = list;
 | 
			
		||||
		_index = index;
 | 
			
		||||
		_size = list.getEntries().size() - index;
 | 
			
		||||
@@ -65,8 +69,21 @@ public class MultiSellList extends AbstractItemPacket
 | 
			
		||||
		
 | 
			
		||||
		while (_size-- > 0)
 | 
			
		||||
		{
 | 
			
		||||
			final ItemInfo itemEnchantment = _list.getItemEnchantment(_index);
 | 
			
		||||
			ItemInfo itemEnchantment = _list.getItemEnchantment(_index);
 | 
			
		||||
			final MultisellEntryHolder entry = _list.getEntries().get(_index++);
 | 
			
		||||
			if ((itemEnchantment == null) && _list.isMaintainEnchantment())
 | 
			
		||||
			{
 | 
			
		||||
				SEARCH: for (ItemChanceHolder holder : entry.getIngredients())
 | 
			
		||||
				{
 | 
			
		||||
					final ItemInstance item = _player.getInventory().getItemByItemId(holder.getId());
 | 
			
		||||
					if ((item != null) && item.isEquipable())
 | 
			
		||||
					{
 | 
			
		||||
						itemEnchantment = new ItemInfo(item);
 | 
			
		||||
						break SEARCH;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			packet.writeD(_index); // Entry ID. Start from 1.
 | 
			
		||||
			packet.writeC(entry.isStackable() ? 1 : 0);
 | 
			
		||||
			
 | 
			
		||||
@@ -82,7 +99,7 @@ public class MultiSellList extends AbstractItemPacket
 | 
			
		||||
			for (ItemChanceHolder product : entry.getProducts())
 | 
			
		||||
			{
 | 
			
		||||
				final Item template = ItemTable.getInstance().getTemplate(product.getId());
 | 
			
		||||
				final ItemInfo displayItemEnchantment = (_list.isMaintainEnchantment() && (itemEnchantment != null) && (template != null) && template.getClass().equals(itemEnchantment.getItem().getClass())) ? itemEnchantment : null;
 | 
			
		||||
				final ItemInfo displayItemEnchantment = _list.isMaintainEnchantment() && (itemEnchantment != null) && (template != null) && template.getClass().equals(itemEnchantment.getItem().getClass()) ? itemEnchantment : null;
 | 
			
		||||
				if (template != null)
 | 
			
		||||
				{
 | 
			
		||||
					packet.writeD(template.getDisplayId());
 | 
			
		||||
@@ -106,7 +123,7 @@ public class MultiSellList extends AbstractItemPacket
 | 
			
		||||
			for (ItemChanceHolder ingredient : entry.getIngredients())
 | 
			
		||||
			{
 | 
			
		||||
				final Item template = ItemTable.getInstance().getTemplate(ingredient.getId());
 | 
			
		||||
				final ItemInfo displayItemEnchantment = ((itemEnchantment != null) && (itemEnchantment.getItem().getId() == ingredient.getId())) ? itemEnchantment : null;
 | 
			
		||||
				final ItemInfo displayItemEnchantment = (itemEnchantment != null) && (template != null) && template.getClass().equals(itemEnchantment.getItem().getClass()) ? itemEnchantment : null;
 | 
			
		||||
				if (template != null)
 | 
			
		||||
				{
 | 
			
		||||
					packet.writeD(template.getDisplayId());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user