diff --git a/gemp-lotr/db/fix-gold-amount.sql b/gemp-lotr/db/fix-gold-amount.sql new file mode 100644 index 000000000..a53392527 --- /dev/null +++ b/gemp-lotr/db/fix-gold-amount.sql @@ -0,0 +1,26 @@ + +SELECT + HEX(LEFT(c.collection,1)) AS Version + ,CONV(HEX(SUBSTRING(c.collection,2,3)),16,10) AS currency + ,json_extract(extra_info, '$.currency') AS extra_info_currency + , CONV(HEX(SUBSTRING(c.collection,2,3)),16,10) + json_extract(extra_info, '$.currency') AS total + , extra_info + , CONCAT('{"currency":', CONV(HEX(SUBSTRING(c.collection,2,3)),16,10) + json_extract(extra_info, '$.currency'), '}') AS new_extra_info + ,p.id +FROM collection c +INNER JOIN player p + ON c.player_id = p.id +WHERE c.type = 'permanent' + AND p.name = 'Caram'; + + +UPDATE collection +SET extra_info = CONCAT('{"currency":', CONV(HEX(SUBSTRING(collection,2,3)),16,10) + json_extract(extra_info, '$.currency'), '}') +WHERE type = 'permanent' + AND player_id = 31040 + + +-- +-- SELECT * +-- FROM transfer t +-- WHERE player = 'Tunadan' \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/MerchantRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/MerchantRequestHandler.java index dd2185060..387c72e67 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/MerchantRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/MerchantRequestHandler.java @@ -6,7 +6,6 @@ import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.game.*; import com.gempukku.lotro.game.formats.LotroFormatLibrary; -import com.gempukku.lotro.merchant.MerchantException; import com.gempukku.lotro.merchant.MerchantService; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; @@ -60,17 +59,17 @@ public class MerchantRequestHandler extends LotroServerRequestHandler implements private void tradeInFoil(HttpRequest request, ResponseWriter responseWriter) throws Exception { HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request); try { - String participantId = getFormParameterSafely(postDecoder, "participantId"); - String blueprintId = getFormParameterSafely(postDecoder, "blueprintId"); + String participantId = getFormParameterSafely(postDecoder, "participantId"); + String blueprintId = getFormParameterSafely(postDecoder, "blueprintId"); - Player resourceOwner = getResourceOwnerSafely(request, participantId); - try { - _merchantService.tradeForFoil(resourceOwner, blueprintId); - responseWriter.writeXmlResponse(null); - } catch (MerchantException exp) { - _log.error("Error response for " + request.uri(), exp); - responseWriter.writeXmlResponse(marshalException(exp)); - } + Player resourceOwner = getResourceOwnerSafely(request, participantId); + try { + _merchantService.tradeForFoil(resourceOwner, blueprintId); + responseWriter.writeHtmlResponse("OK"); + } catch (Exception exp) { + _log.error("Error response for " + request.uri(), exp); + responseWriter.writeXmlResponse(marshalException(exp)); + } } finally { postDecoder.destroy(); } @@ -79,18 +78,23 @@ public class MerchantRequestHandler extends LotroServerRequestHandler implements private void sell(HttpRequest request, ResponseWriter responseWriter) throws Exception { HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request); try { - String participantId = getFormParameterSafely(postDecoder, "participantId"); - String blueprintId = getFormParameterSafely(postDecoder, "blueprintId"); - int price = Integer.parseInt(getFormParameterSafely(postDecoder, "price")); + String participantId = getFormParameterSafely(postDecoder, "participantId"); + String blueprintId = getFormParameterSafely(postDecoder, "blueprintId"); + int price = Integer.parseInt(getFormParameterSafely(postDecoder, "price")); - Player resourceOwner = getResourceOwnerSafely(request, participantId); - try { - _merchantService.merchantBuysCard(resourceOwner, blueprintId, price); - responseWriter.writeXmlResponse(null); - } catch (MerchantException exp) { - _log.error("Error response for " + request.uri(), exp); - responseWriter.writeXmlResponse(marshalException(exp)); - } + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + Document doc = documentBuilder.newDocument(); + + Player resourceOwner = getResourceOwnerSafely(request, participantId); + try { + _merchantService.merchantBuysCard(resourceOwner, blueprintId, price); + responseWriter.writeHtmlResponse("OK"); + } catch (Exception exp) { + _log.error("Error response for " + request.uri(), exp); + responseWriter.writeXmlResponse(marshalException(exp)); + } } finally { postDecoder.destroy(); } @@ -99,18 +103,24 @@ public class MerchantRequestHandler extends LotroServerRequestHandler implements private void buy(HttpRequest request, ResponseWriter responseWriter) throws Exception { HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request); try { - String participantId = getFormParameterSafely(postDecoder, "participantId"); - String blueprintId = getFormParameterSafely(postDecoder, "blueprintId"); - int price = Integer.parseInt(getFormParameterSafely(postDecoder, "price")); + String participantId = getFormParameterSafely(postDecoder, "participantId"); + String blueprintId = getFormParameterSafely(postDecoder, "blueprintId"); + int price = Integer.parseInt(getFormParameterSafely(postDecoder, "price")); - Player resourceOwner = getResourceOwnerSafely(request, participantId); - try { - _merchantService.merchantSellsCard(resourceOwner, blueprintId, price); - responseWriter.writeXmlResponse(null); - } catch (MerchantException exp) { - _log.error("Error response for " + request.uri(), exp); - responseWriter.writeXmlResponse(marshalException(exp)); - } + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + Document doc = documentBuilder.newDocument(); + + + Player resourceOwner = getResourceOwnerSafely(request, participantId); + try { + _merchantService.merchantSellsCard(resourceOwner, blueprintId, price); + responseWriter.writeHtmlResponse("OK"); + } catch (Exception exp) { + _log.error("Error response for " + request.uri(), exp); + responseWriter.writeXmlResponse(marshalException(exp)); + } } finally { postDecoder.destroy(); } @@ -188,7 +198,7 @@ public class MerchantRequestHandler extends LotroServerRequestHandler implements responseWriter.writeXmlResponse(doc); } - private Document marshalException(MerchantException e) throws ParserConfigurationException { + private Document marshalException(Exception e) throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js index 3ec700253..e37fd1664 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js +++ b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-022/communication.js @@ -362,7 +362,7 @@ var GempLotrCommunication = Class.extend({ price:price}, success:this.deliveryCheck(callback), error:this.errorCheck(errorMap), - dataType:"xml" + dataType:"html" }); }, sellItem:function (blueprintId, price, callback, errorMap) { @@ -376,7 +376,7 @@ var GempLotrCommunication = Class.extend({ price:price}, success:this.deliveryCheck(callback), error:this.errorCheck(errorMap), - dataType:"xml" + dataType:"html" }); }, tradeInFoil:function (blueprintId, callback, errorMap) { @@ -389,7 +389,7 @@ var GempLotrCommunication = Class.extend({ blueprintId:blueprintId}, success:this.deliveryCheck(callback), error:this.errorCheck(errorMap), - dataType:"xml" + dataType:"html" }); }, getCollection:function (collectionType, filter, start, count, callback, errorMap) { 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 4b8269e3f..3701a8980 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 @@ -227,7 +227,7 @@ public class CollectionsManager { String reason = "Trading items"; removeFromPlayerCollection(player, collectionType.getCode(), cardCollectionFromBlueprintId(removeCount, removeBlueprintId), reason); - addToPlayerCollection(player, collectionType.getCode(), cardCollectionFromBlueprintId(removeCount, removeBlueprintId), reason); + addToPlayerCollection(player, collectionType.getCode(), cardCollectionFromBlueprintId(addCount, addBlueprintId), reason); removeCurrencyFromPlayerCollection(reason, player, collectionType, currencyCost); _transferDAO.addTransferFrom(player.getName(), reason, collectionType.getFullName(), currencyCost, cardCollectionFromBlueprintId(removeCount, removeBlueprintId)); 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 f911c7a6c..4be9836a0 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 @@ -139,16 +139,18 @@ public class MerchantService { } public void merchantBuysCard(Player player, String blueprintId, int price) throws MerchantException, SQLException, IOException { + priceCards(player, Collections.singleton(new BasicCardItem(blueprintId))); + Date currentTime = new Date(); Lock lock = _lock.writeLock(); lock.lock(); try { PriceGuarantee guarantee = _priceGuarantees.get(player.getName()); - if (guarantee == null || guarantee.getDate().getTime() + _priceGuaranteeExpire < currentTime.getTime()) - throw new MerchantException("Price guarantee has expired"); +// if (guarantee == null || guarantee.getDate().getTime() + _priceGuaranteeExpire < currentTime.getTime()) +// throw new MerchantException("Price guarantee has expired"); Integer guaranteedPrice = guarantee.getBuyPrices().get(blueprintId); - if (guaranteedPrice == null || price != guaranteedPrice) - throw new MerchantException("Guaranteed price does not match the user asked price"); +// if (guaranteedPrice == null || price != guaranteedPrice) +// throw new MerchantException("Guaranteed price does not match the user asked price"); boolean success = _collectionsManager.sellCardInPlayerCollection(player, _permanentCollection, blueprintId, price); if (!success) @@ -162,16 +164,18 @@ public class MerchantService { } public void merchantSellsCard(Player player, String blueprintId, int price) throws MerchantException, SQLException, IOException { + priceCards(player, Collections.singleton(new BasicCardItem(blueprintId))); + Date currentTime = new Date(); Lock lock = _lock.writeLock(); lock.lock(); try { PriceGuarantee guarantee = _priceGuarantees.get(player.getName()); - if (guarantee == null || guarantee.getDate().getTime() + _priceGuaranteeExpire < currentTime.getTime()) - throw new MerchantException("Price guarantee has expired"); +// if (guarantee == null || guarantee.getDate().getTime() + _priceGuaranteeExpire < currentTime.getTime()) +// throw new MerchantException("Price guarantee has expired"); Integer guaranteedPrice = guarantee.getSellPrices().get(blueprintId); - if (guaranteedPrice == null || price != guaranteedPrice) - throw new MerchantException("Guaranteed price does not match the user asked price"); +// if (guaranteedPrice == null || price != guaranteedPrice) +// throw new MerchantException("Guaranteed price does not match the user asked price"); boolean success = _collectionsManager.buyCardToPlayerCollection(player, _permanentCollection, blueprintId, price); if (!success)