Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java b/java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java
- index eadf661..dc45840 100644
- --- a/java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java
- +++ b/java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java
- @@ -335,31 +335,58 @@
- /**
- * Adjust TradeItem according his status in inventory
- - * @param item : ItemInstance to be adjusten
- + * @param item : ItemInstance to be adjusted
- + * @param list
- + * @return
- */
- - public void adjustAvailableItem(TradeItem item)
- + public TradeItem adjustAvailableItem(TradeItem item, List<TradeItem> list)
- {
- - // For all ItemInstance with same item id.
- - for (ItemInstance adjItem : getItemsByItemId(item.getItem().getItemId()))
- + for(ItemInstance adjItem : _items)
- {
- - // If enchant level is different, bypass.
- - if (adjItem.getEnchantLevel() != item.getEnchant())
- - continue;
- -
- - // If item isn't equipable, or equipable but not equiped it is a success.
- - if (!adjItem.isEquipable() || (adjItem.isEquipable() && !adjItem.isEquipped()))
- + if (adjItem.isStackable())
- {
- - item.setObjectId(adjItem.getObjectId());
- - item.setEnchant(adjItem.getEnchantLevel());
- -
- - if (adjItem.getCount() < item.getCount())
- - item.setCount(adjItem.getCount());
- -
- - return;
- + if (adjItem.getItemId() == item.getItem().getItemId() && (adjItem.getEnchantLevel() == item.getEnchant()))
- + {
- + item.setObjectId(adjItem.getObjectId());
- + if (adjItem.getCount() < item.getCount())
- + item.setCount(adjItem.getCount());
- + else
- + {
- + item.setCount(item.getCount());
- + }
- + return item;
- + }
- + }
- + else
- + {
- + if (adjItem.getItemId() == item.getItem().getItemId() && (adjItem.getEnchantLevel() == item.getEnchant()))
- + {
- + boolean found = false;
- + for (TradeItem actual:list)
- + {
- + if (actual.getObjectId() == adjItem.getObjectId())
- + {
- + found = true;
- + break;
- + }
- + }
- + if (found)
- + {
- + continue;
- + }
- + item.setObjectId(adjItem.getObjectId());
- + if (adjItem.getCount() < item.getCount())
- + item.setCount(adjItem.getCount());
- + else
- + {
- + item.setCount(item.getCount());
- + }
- + return item;
- + }
- }
- }
- - // None item matched conditions ; return as invalid count.
- item.setCount(0);
- + return item;
- }
- /**
- diff --git a/java/net/sf/l2j/gameserver/model/trade/TradeList.java b/java/net/sf/l2j/gameserver/model/trade/TradeList.java
- index 0fe29fd..c494222 100644
- --- a/java/net/sf/l2j/gameserver/model/trade/TradeList.java
- +++ b/java/net/sf/l2j/gameserver/model/trade/TradeList.java
- @@ -22,7 +22,6 @@
- public class TradeList extends CopyOnWriteArrayList<TradeItem>
- {
- private static final long serialVersionUID = 1L;
- -
- private final Player _owner;
- private Player _partner;
- @@ -87,35 +86,39 @@
- {
- return _locked;
- }
- -
- /**
- - * @param inventory : The {@link PcInventory} to test.
- - * @return A cloned {@link List} of this {@link TradeList} adjusted to {@link PcInventory} available items.
- + * Returns the list of items in inventory available for transaction
- + * @param inventory The inventory to make checks on.
- + * @return ItemInstance : items in inventory
- */
- public List<TradeItem> getAvailableItems(PcInventory inventory)
- {
- - final List<TradeItem> list = new ArrayList<>(this);
- - list.forEach(ti -> inventory.adjustAvailableItem(ti));
- + List<TradeItem> list = new ArrayList<>();
- + for (TradeItem item : this)
- + {
- + item = new TradeItem(item, item.getCount(), item.getPrice());
- + list.add(inventory.adjustAvailableItem(item,list));
- + }
- return list;
- }
- /**
- - * Create a {@link TradeItem} based on an existing {@link ItemInstance}.
- - * @param item : The {@link ItemInstance} to test.
- - * @return A {@link TradeItem} based on {@link ItemInstance}.
- + * Adjust available item from Inventory by the one in this list
- + * @param item : ItemInstance to be adjusted
- + * @return TradeItem representing adjusted item
- */
- public TradeItem adjustAvailableItem(ItemInstance item)
- {
- if (item.isStackable())
- {
- - for (TradeItem tradeItem : this)
- + for (TradeItem exclItem : this)
- {
- - if (tradeItem.getItem().getItemId() == item.getItemId())
- + if (exclItem.getItem().getItemId() == item.getItemId() && (exclItem.getEnchant() == item.getEnchantLevel()))
- {
- - if (item.getCount() <= tradeItem.getCount())
- + if (item.getCount() <= exclItem.getCount())
- return null;
- -
- - return new TradeItem(item, item.getCount() - tradeItem.getCount(), item.getReferencePrice());
- +
- + return new TradeItem(item, item.getCount() - exclItem.getCount(), item.getReferencePrice());
- }
- }
- }
- @@ -123,129 +126,130 @@
- }
- /**
- - * Create a {@link TradeItem} based on an existing {@link ItemInstance}, and add it to this {@link TradeList}.
- - * @param objectId : The {@link WorldObject} objectId to test.
- - * @param count : The amount of newly formed {@link TradeItem}.
- - * @param price : The price of newly formed {@link TradeItem}.
- - * @return A {@link TradeItem} based on {@link ItemInstance}, which is itself retrieved from its objectId from {@link World#getObject(int)}.
- + * Add item to TradeList
- + * @param objectId : int
- + * @param count : int
- + * @param price : int
- + * @return
- */
- public synchronized TradeItem addItem(int objectId, int count, int price)
- {
- if (isLocked())
- return null;
- -
- - final WorldObject object = World.getInstance().getObject(objectId);
- - if (!(object instanceof ItemInstance))
- +
- + WorldObject o = World.getInstance().getObject(objectId);
- + if (!(o instanceof ItemInstance))
- return null;
- -
- - final ItemInstance item = (ItemInstance) object;
- -
- +
- + ItemInstance item = (ItemInstance) o;
- +
- if (!item.isTradable() || item.isQuestItem())
- return null;
- -
- +
- if (count <= 0 || count > item.getCount())
- return null;
- -
- +
- if (!item.isStackable() && count > 1)
- return null;
- -
- +
- if ((Integer.MAX_VALUE / count) < price)
- return null;
- -
- +
- for (TradeItem checkitem : this)
- {
- if (checkitem.getObjectId() == objectId)
- return null;
- }
- -
- - final TradeItem tradeItem = new TradeItem(item, count, price);
- - add(tradeItem);
- -
- - // If Player has already confirmed this trade, invalidate the confirmation.
- +
- + TradeItem tradeItem = new TradeItem(item, count, price);
- + this.add(tradeItem);
- +
- + // If Player has already confirmed this trade, invalidate the confirmation
- invalidateConfirmation();
- -
- return tradeItem;
- }
- /**
- - * Create a {@link TradeItem} based on itemId, and add it to this {@link TradeList}.
- - * @param itemId : The itemId of newly formed {@link TradeItem}.
- - * @param count : The amount of newly formed {@link TradeItem}.
- - * @param price : The price of newly formed {@link TradeItem}.
- - * @param enchant : The enchant value of newly formed {@link TradeItem}.
- - * @return A {@link TradeItem} based on itemId.
- + * Add item to TradeList
- + * @param itemId : int
- + * @param count : int
- + * @param price : int
- + * @param enchant
- + * @return
- */
- public synchronized TradeItem addItemByItemId(int itemId, int count, int price, int enchant)
- {
- if (isLocked())
- return null;
- -
- - final Item item = ItemData.getInstance().getTemplate(itemId);
- +
- + Item item = ItemData.getInstance().getTemplate(itemId);
- if (item == null)
- return null;
- -
- +
- if (!item.isTradable() || item.isQuestItem())
- return null;
- -
- +
- if (!item.isStackable() && count > 1)
- return null;
- -
- +
- if ((Integer.MAX_VALUE / count) < price)
- return null;
- -
- - final TradeItem tradeItem = new TradeItem(item, count, price, enchant);
- - add(tradeItem);
- -
- - // If Player has already confirmed this trade, invalidate the confirmation.
- +
- + TradeItem tradeItem = new TradeItem(item, count, price, enchant);
- + tradeItem.setEnchant(enchant);
- + this.add(tradeItem);
- +
- + // If Player has already confirmed this trade, invalidate the confirmation
- invalidateConfirmation();
- -
- return tradeItem;
- }
- /**
- - * Remove or decrease amount of a {@link TradeItem} from this {@link TradeList}, by either its objectId or itemId.
- - * @param objectId : The objectId to test.
- - * @param itemId : The itemId ot test.
- - * @param count : The amount to remove.
- + * Remove item from TradeList
- + * @param objectId : int
- + * @param itemId : int
- + * @param count : int
- + * @return
- */
- - public synchronized void removeItem(int objectId, int itemId, int count)
- + public synchronized TradeItem removeItem(int objectId, int itemId, int count)
- {
- if (isLocked())
- - return;
- -
- + return null;
- +
- for (TradeItem tradeItem : this)
- {
- if (tradeItem.getObjectId() == objectId || tradeItem.getItem().getItemId() == itemId)
- {
- - // If Partner has already confirmed this trade, invalidate the confirmation.
- + // If Partner has already confirmed this trade, invalidate the confirmation
- if (_partner != null)
- {
- TradeList partnerList = _partner.getActiveTradeList();
- if (partnerList == null)
- - break;
- -
- + return null;
- +
- partnerList.invalidateConfirmation();
- }
- -
- - // Reduce item count or complete item.
- +
- + // Reduce item count or complete item
- if (count != -1 && tradeItem.getCount() > count)
- tradeItem.setCount(tradeItem.getCount() - count);
- else
- - remove(tradeItem);
- -
- - break;
- + this.remove(tradeItem);
- +
- + return tradeItem;
- }
- }
- + return null;
- }
- /**
- - * Update {@link TradeItem}s from this {@link TradeList} according to their quantity in owner inventory.
- + * Update items in TradeList according their quantity in owner inventory
- */
- public synchronized void updateItems()
- {
- for (TradeItem tradeItem : this)
- {
- - final ItemInstance item = _owner.getInventory().getItemByObjectId(tradeItem.getObjectId());
- + ItemInstance item = _owner.getInventory().getItemByObjectId(tradeItem.getObjectId());
- if (item == null || tradeItem.getCount() < 1)
- removeItem(tradeItem.getObjectId(), -1, -1);
- else if (item.getCount() < tradeItem.getCount())
- @@ -265,7 +269,6 @@
- public synchronized void clear()
- {
- super.clear();
- -
- _locked = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement