diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java index 0392d5331..ee363d375 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java @@ -14,6 +14,7 @@ public class DefaultCardCollection implements MutableCardCollection { public DefaultCardCollection(CardCollection cardCollection) { _counts.putAll(cardCollection.getAll()); + _currency = cardCollection.getCurrency(); } public void addCurrency(int currency) { diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AbstractResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AbstractResource.java index f61213478..f133a7e56 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AbstractResource.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/AbstractResource.java @@ -35,7 +35,7 @@ public abstract class AbstractResource { Integer lastReward = player.getLastLoginReward(); if (lastReward == null) { _playerDao.setLastReward(player, latestMonday); - _collectionManager.addCurrencyToPlayerCollection(player, new CollectionType("permanent", "My cards"), 5000); + _collectionManager.addCurrencyToPlayerCollection(player, new CollectionType("permanent", "My cards"), 20000); } else { if (latestMonday == lastReward) { if (_playerDao.updateLastReward(player, lastReward, latestMonday)) 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 dfad23e0c..bddd3d1c5 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 @@ -114,7 +114,7 @@ public class MerchantResource extends AbstractResource { elem.setAttribute("tradeFoil", "true"); elem.setAttribute("blueprintId", blueprintId); Integer buyPrice = buyPrices.get(blueprintId); - if (buyPrice != null) + if (buyPrice != null && collection.getItemCount(blueprintId) > 0) elem.setAttribute("buyPrice", buyPrice.toString()); Integer sellPrice = sellPrices.get(blueprintId); if (sellPrice != null) @@ -129,9 +129,9 @@ public class MerchantResource extends AbstractResource { @POST @Produces(MediaType.APPLICATION_XML) public Document buyItem( - @QueryParam("participantId") String participantId, - @QueryParam("blueprintId") String blueprintId, - @QueryParam("price") int price, + @FormParam("participantId") String participantId, + @FormParam("blueprintId") String blueprintId, + @FormParam("price") int price, @Context HttpServletRequest request, @Context HttpServletResponse response) throws ParserConfigurationException { Player resourceOwner = getResourceOwnerSafely(request, participantId); @@ -147,9 +147,9 @@ public class MerchantResource extends AbstractResource { @POST @Produces(MediaType.APPLICATION_XML) public Document sellItem( - @QueryParam("participantId") String participantId, - @QueryParam("blueprintId") String blueprintId, - @QueryParam("price") int price, + @FormParam("participantId") String participantId, + @FormParam("blueprintId") String blueprintId, + @FormParam("price") int price, @Context HttpServletRequest request, @Context HttpServletResponse response) throws ParserConfigurationException { Player resourceOwner = getResourceOwnerSafely(request, participantId); @@ -165,8 +165,8 @@ public class MerchantResource extends AbstractResource { @POST @Produces(MediaType.APPLICATION_XML) public Document tradeInFoil( - @QueryParam("participantId") String participantId, - @QueryParam("blueprintId") String blueprintId, + @FormParam("participantId") String participantId, + @FormParam("blueprintId") String blueprintId, @Context HttpServletRequest request, @Context HttpServletResponse response) throws ParserConfigurationException { Player resourceOwner = getResourceOwnerSafely(request, participantId); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/cardFilter.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/cardFilter.js index 93916491a..5e1032adf 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/cardFilter.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/cardFilter.js @@ -358,7 +358,7 @@ var CardFilter = Class.extend({ log(xml); var root = xml.documentElement; - this.clearCollectionFunc(root.tagName); + this.clearCollectionFunc(root); var packs = root.getElementsByTagName("pack"); for (var i = 0; i < packs.length; i++) { diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js index 52c92f6d2..c2ac14b81 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js @@ -179,6 +179,47 @@ var GempLotrCommunication = Class.extend({ dataType: "xml" }); }, + buyItem: function(blueprintId, price, callback) { + $.ajax({ + type: "POST", + url: this.url + "/merchant/buy", + cache: false, + data: { + participantId: getUrlParam("participantId"), + blueprintId: blueprintId, + price: price}, + success: this.deliveryCheck(callback), + error: this.failure, + dataType: "xml" + }); + }, + sellItem: function(blueprintId, price, callback) { + $.ajax({ + type: "POST", + url: this.url + "/merchant/sell", + cache: false, + data: { + participantId: getUrlParam("participantId"), + blueprintId: blueprintId, + price: price}, + success: this.deliveryCheck(callback), + error: this.failure, + dataType: "xml" + }); + }, + tradeInFoil: function(blueprintId, callback) { + $.ajax({ + type: "POST", + url: this.url + "/merchant/tradeFoil", + cache: false, + data: { + participantId: getUrlParam("participantId"), + blueprintId: blueprintId}, + success: this.deliveryCheck(callback), + error: this.failure, + dataType: "xml" + }); + }, getCollection: function(collectionType, filter, start, count, callback) { $.ajax({ type: "GET", diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/merchantUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/merchantUi.js index 4610f601d..0e4662040 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/merchantUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/merchantUi.js @@ -8,6 +8,9 @@ var GempLotrMerchantUI = Class.extend({ cardFilter: null, infoDialog: null, + questionDialog: null, + + currencyCount: null, init: function(cardListElem, cardFilterElem) { var that = this; @@ -18,8 +21,8 @@ var GempLotrMerchantUI = Class.extend({ function(filter, start, count, callback) { that.comm.getMerchant(filter, start, count, callback); }, - function() { - that.clearList(); + function(rootElem) { + that.clearList(rootElem); }, function(elem, type, blueprintId, count) { that.addCardToList(elem, type, blueprintId, count); @@ -43,6 +46,15 @@ var GempLotrMerchantUI = Class.extend({ title: "Card information" }); + this.questionDialog = $("
") + .dialog({ + autoOpen: false, + closeOnEscape: true, + resizable: false, + modal: true, + title: "Merchant operation" + }); + var swipeOptions = { threshold: 20, swipeUp: function (event) { @@ -157,8 +169,9 @@ var GempLotrMerchantUI = Class.extend({ this.infoDialog.dialog("open"); }, - clearList: function() { + clearList: function(rootElem) { $(".card", this.cardsDiv).remove(); + this.currencyCount = rootElem.getAttribute("currency"); }, addCardToList: function(elem, type, blueprintId, count) { @@ -177,15 +190,16 @@ var GempLotrMerchantUI = Class.extend({ }; var cardDiv = null; + var card = null; if (type == "pack") { - var card = new Card(blueprintId, "merchant", "collection", "player"); + card = new Card(blueprintId, "merchant", "collection", "player"); cardDiv = createCardDiv(card.imageUrl, null, false, true, true); cardDiv.data("card", card); cardDiv.data("sizeListeners", sizeListeners); this.cardsDiv.append(cardDiv); } else if (type == "card") { - var card = new Card(blueprintId, "merchant", "collection", "player"); + card = new Card(blueprintId, "merchant", "collection", "player"); cardDiv = createCardDiv(card.imageUrl, null, card.isFoil()); cardDiv.data("card", card); cardDiv.data("sizeListeners", sizeListeners); @@ -193,22 +207,88 @@ var GempLotrMerchantUI = Class.extend({ } if (cardDiv != null) { + var that = this; cardDiv.append("
" + count + "
"); if (buyPrice != null) { - var buyBut = $("
Buy price
" + this.formatPrice(buyPrice) + "
").button(); + var formattedBuyPrice = this.formatPrice(buyPrice); + var buyBut = $("
Sell for
" + formattedBuyPrice + "
").button(); + buyBut.click( + function() { + that.displayMerchantAction(card, "Do you want to sell this item for " + formattedBuyPrice + "?", + function() { + that.comm.sellItem(blueprintId, buyPrice, function() { + that.cardFilter.getCollection(); + }); + }); + }); cardDiv.append(buyBut); } - if (sellPrice != null) { - var sellBut = $("
Sell price
" + this.formatPrice(sellPrice) + "
").button(); + if (sellPrice != null && sellPrice <= this.currencyCount) { + var formattedSellPrice = this.formatPrice(sellPrice); + var sellBut = $("
Buy for
" + this.formatPrice(sellPrice) + "
").button(); + sellBut.click( + function() { + that.displayMerchantAction(card, "Do you want to buy this item for " + formattedSellPrice + "?", + function() { + that.comm.buyItem(blueprintId, sellPrice, function() { + that.cardFilter.getCollection(); + }); + }); + }); cardDiv.append(sellBut); } if (tradeFoil == "true") { var tradeFoilBut = $("
Trade 4 for foil
").button(); + tradeFoilBut.click( + function() { + that.displayMerchantAction(card, "Do you want to trade 4 of this card for a foil version?", + function() { + that.comm.tradeInFoil(blueprintId, function() { + that.cardFilter.getCollection(); + }); + }); + }); cardDiv.append(tradeFoilBut); } } }, + displayMerchantAction: function(card, text, yesFunc) { + var that = this; + this.questionDialog.html(""); + this.questionDialog.html("
"); + var floatCardDiv = $("
"); + floatCardDiv.append(createFullCardDiv(card.imageUrl, card.foil, card.horizontal, card.isPack())); + this.questionDialog.append(floatCardDiv); + var questionDiv = $("
" + text + "
"); + questionDiv.append("
"); + questionDiv.append($("").button().click( + function() { + that.questionDialog.dialog("close"); + yesFunc(); + })); + questionDiv.append($("").button().click( + function() { + that.questionDialog.dialog("close"); + })); + this.questionDialog.append(questionDiv); + + var windowWidth = $(window).width(); + var windowHeight = $(window).height(); + + var horSpace = 230; + var vertSpace = 45; + + if (card.horizontal) { + // 500x360 + this.questionDialog.dialog({width: Math.min(500 + horSpace, windowWidth), height: Math.min(360 + vertSpace, windowHeight)}); + } else { + // 360x500 + this.questionDialog.dialog({width: Math.min(360 + horSpace, windowWidth), height: Math.min(500 + vertSpace, windowHeight)}); + } + this.questionDialog.dialog("open"); + }, + formatPrice: function(price) { return Math.floor(price / 100) + "G " + price % 100 + "S"; },