diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/collection/CollectionsManager.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/collection/CollectionsManager.java index 3b28e3a83..b61a5b4c3 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/collection/CollectionsManager.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/collection/CollectionsManager.java @@ -109,6 +109,25 @@ public class CollectionsManager { addItemsToPlayerCollection(_playerDAO.getPlayer(player), collectionType, items); } + public boolean tradeCards(Player player, CollectionType collectionType, String blueprintId1, int count1, String blueprintId2, int count2) { + _readWriteLock.writeLock().lock(); + try { + final CardCollection playerCollection = getPlayerCollection(player, collectionType.getCode()); + if (playerCollection != null) { + MutableCardCollection mutableCardCollection = new DefaultCardCollection(playerCollection); + if (!mutableCardCollection.removeItem(blueprintId1, count1)) + return false; + mutableCardCollection.addItem(blueprintId2, count2); + + _collectionDAO.setCollectionForPlayer(player.getId(), collectionType.getCode(), mutableCardCollection); + return true; + } + return false; + } finally { + _readWriteLock.writeLock().unlock(); + } + } + public boolean buyCardToPlayerCollection(Player player, CollectionType collectionType, String blueprintId, int currency) { _readWriteLock.writeLock().lock(); try { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/merchant/MerchantService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/merchant/MerchantService.java index 687530037..1ed9ecf20 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/merchant/MerchantService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/merchant/MerchantService.java @@ -115,6 +115,20 @@ public class MerchantService { } } + public void tradeForFoil(Player player, String blueprintId) throws MerchantException { + if (!blueprintId.contains("_") || blueprintId.endsWith("*")) + throw new MerchantException("Unable to trade in this type of item"); + Lock lock = _lock.writeLock(); + lock.lock(); + try { + boolean success = _collectionsManager.tradeCards(player, _permanentCollection, blueprintId, 4, blueprintId + "*", 1); + if (!success) + throw new MerchantException("Unable to remove the required cards from your collection"); + } finally { + lock.unlock(); + } + } + private static class BasicCardItem implements CardItem { private String _blueprintId; diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/MerchantResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/MerchantResource.java index 2642d87ea..3787eb9de 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/MerchantResource.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/MerchantResource.java @@ -111,6 +111,8 @@ public class MerchantResource extends AbstractResource { elem = doc.createElement("pack"); elem.setAttribute("count", String.valueOf(collection.getItemCount(blueprintId))); + if (blueprintId.contains("_") && !blueprintId.endsWith("*") && collection.getItemCount(blueprintId) >= 4) + elem.setAttribute("tradeFoil", "true"); elem.setAttribute("blueprintId", blueprintId); Integer buyPrice = buyPrices.get(blueprintId); if (buyPrice != null)