Work on merchant.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user