Fixed foil trade-ins not working. Fixed merchant operations requiring 2 invocations. Fixed various merchant console errors. Added script for handling ad-hoc gold adjustments

This commit is contained in:
Christian 'ketura' McCarty
2022-11-03 20:34:58 -05:00
parent fa31908375
commit cde04dee37
5 changed files with 86 additions and 46 deletions

View File

@@ -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'

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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));

View File

@@ -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)