Added - deck builder checks collection's content if limited format is selected
This commit is contained in:
@@ -3,6 +3,7 @@ package com.gempukku.lotro.async.handler;
|
||||
import com.gempukku.lotro.async.HttpProcessingException;
|
||||
import com.gempukku.lotro.async.ResponseWriter;
|
||||
import com.gempukku.lotro.chat.MarkdownParser;
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.common.JSONDefs;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.db.DeckDAO;
|
||||
@@ -44,6 +45,7 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
|
||||
private final LotroServer _lotroServer;
|
||||
private final MarkdownParser _markdownParser;
|
||||
private final TableDraftDefinitions _tableDraftDefinitions;
|
||||
private final CollectionsManager _collectionsManager;
|
||||
|
||||
private static final Logger _log = LogManager.getLogger(DeckRequestHandler.class);
|
||||
|
||||
@@ -57,6 +59,7 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
|
||||
_draftLibrary = extractObject(context, SoloDraftDefinitions.class);
|
||||
_markdownParser = extractObject(context, MarkdownParser.class);
|
||||
_tableDraftDefinitions = extractObject(context, TableDraftDefinitions.class);
|
||||
_collectionsManager = extractObject(context, CollectionsManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,10 +144,11 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
|
||||
try {
|
||||
String participantId = getFormParameterSafely(postDecoder, "participantId");
|
||||
String targetFormat = getFormParameterSafely(postDecoder, "targetFormat");
|
||||
String collectionName = getFormParameterSafely(postDecoder, "collectionName");
|
||||
String contents = getFormParameterSafely(postDecoder, "deckContents");
|
||||
|
||||
//check for valid access
|
||||
getResourceOwnerSafely(request, participantId);
|
||||
Player player = getResourceOwnerSafely(request, participantId);
|
||||
|
||||
LotroDeck deck = _lotroServer.createDeckWithValidate("tempDeck", contents, targetFormat, "");
|
||||
if (deck == null)
|
||||
@@ -179,6 +183,47 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
|
||||
LotroDeck deckWithErrata = format.applyErrata(deck);
|
||||
errataValidation = format.validateDeck(deckWithErrata);
|
||||
}
|
||||
|
||||
if (!collectionName.equals("default")) {
|
||||
// Check collection
|
||||
try {
|
||||
CardCollection collection = _collectionsManager.getPlayerCollection(player, collectionName);
|
||||
|
||||
Map<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(deck);
|
||||
|
||||
for (Map.Entry<String, Integer> cardCount : deckCardCounts.entrySet()) {
|
||||
String overtID = cardCount.getKey();
|
||||
String errataID = format.applyErrata(cardCount.getKey());
|
||||
var baseIDs = format.findBaseCards(cardCount.getKey());
|
||||
|
||||
int collectionCount = collection.getItemCount(cardCount.getKey());
|
||||
|
||||
if (!errataID.equals(overtID)) {
|
||||
collection.getItemCount(errataID);
|
||||
}
|
||||
|
||||
var alts = _library.getAllAlternates(cardCount.getKey());
|
||||
if (alts != null) {
|
||||
for (String id : alts) {
|
||||
collectionCount += collection.getItemCount(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (collectionCount < cardCount.getValue()) {
|
||||
String cardName = null;
|
||||
try {
|
||||
cardName = GameUtils.getFullName(_library.getLotroCardBlueprint(cardCount.getKey()));
|
||||
validation.add("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + collectionCount);
|
||||
} catch (CardNotFoundException e) {
|
||||
// Ignore, card player has in a collection, should not disappear
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
validation.add("You don't have cards in the required collection to play in this format");
|
||||
}
|
||||
}
|
||||
|
||||
if(validation.size() == 0) {
|
||||
valid.append("<b>" + format.getName() + "</b>: <font color='green'>Valid</font><br/>");
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ var GempLotrCommunication = Class.extend({
|
||||
dataType:"xml"
|
||||
});
|
||||
},
|
||||
getDeckStats:function (contents, targetFormat, callback, errorMap) {
|
||||
getDeckStats:function (contents, targetFormat, collectionName, callback, errorMap) {
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url:this.url + "/deck/stats",
|
||||
@@ -620,6 +620,7 @@ var GempLotrCommunication = Class.extend({
|
||||
data:{
|
||||
participantId:getUrlParam("participantId"),
|
||||
targetFormat:targetFormat,
|
||||
collectionName:collectionName,
|
||||
deckContents:contents},
|
||||
success:this.deckbuilderDeliveryCheck(callback),
|
||||
error:this.errorCheck(errorMap),
|
||||
|
||||
@@ -336,6 +336,10 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
that.updateDeckStats();
|
||||
}
|
||||
}, this.checkDirtyInterval);
|
||||
|
||||
$("#formatSelect").change(function () {
|
||||
that.deckValidationDirty = true;
|
||||
});
|
||||
|
||||
this.updateFormatOptions();
|
||||
this.comm.forcePackDelivery();
|
||||
@@ -458,7 +462,10 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
for (var i = 0; i < collections.length; i++) {
|
||||
var collection = collections[i];
|
||||
$("#collectionSelect").append("<option value='" + collection.getAttribute("type") + "'>" + collection.getAttribute("name") + "</option>");
|
||||
$("#formatSelect").append("<option value='" + collection.getAttribute("format") + "'>" + collection.getAttribute("name") + "</option>");
|
||||
$("#formatSelect").append(
|
||||
"<option value='" + collection.getAttribute("format") + "' data-type='" + collection.getAttribute("type") + "'>" +
|
||||
collection.getAttribute("name") + "</option>"
|
||||
);
|
||||
}
|
||||
|
||||
$("#collectionSelect").val("default");
|
||||
@@ -1055,11 +1062,13 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
|
||||
updateDeckStats:function () {
|
||||
var that = this;
|
||||
var selectedOption = $("#formatSelect option:selected");
|
||||
var deckContents = this.getDeckContents();
|
||||
if (deckContents != null && deckContents != "")
|
||||
{
|
||||
this.comm.getDeckStats(deckContents,
|
||||
$("#formatSelect").val(),
|
||||
selectedOption.val(), // format
|
||||
selectedOption.data("type"), // collection name
|
||||
function (html)
|
||||
{
|
||||
$("#deckStats").html(html);
|
||||
@@ -1094,6 +1103,7 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
|
||||
var option = $("<option/>")
|
||||
.attr("value", code)
|
||||
.attr("data-type", "default") // default collection for non-limited formats
|
||||
.text(format.name);
|
||||
options[format.order] = option;
|
||||
if(format.order > max) {
|
||||
|
||||
@@ -935,6 +935,7 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
{
|
||||
this.comm.getDeckStats(deckContents,
|
||||
$("#formatSelect").val(),
|
||||
"default", // TODO - collection name for limited formats, now it does not check card availability
|
||||
function (html)
|
||||
{
|
||||
$("#deckStats").html(html);
|
||||
|
||||
Reference in New Issue
Block a user