Delivery is working on deck builder now.
This commit is contained in:
@@ -5,13 +5,13 @@ import com.gempukku.lotro.game.CardCollection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FixedPackBox implements PackBox {
|
||||
private Map<String, Integer> _contents = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> _contents = new LinkedHashMap<String, Integer>();
|
||||
|
||||
public FixedPackBox(String packName) throws IOException {
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(FixedPackBox.class.getResourceAsStream("/" + packName + ".pack")));
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.sun.jersey.spi.resource.Singleton;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
@Path("/delivery")
|
||||
public class DeliveryResource extends AbstractResource {
|
||||
@GET
|
||||
public Document getDelivery(
|
||||
@Context HttpServletRequest request) throws ParserConfigurationException {
|
||||
Player resourceOwner = getResourceOwnerSafely(request, null);
|
||||
Map<String, List<CardCollection.Item>> delivery = _deliveryService.consumePackages(resourceOwner);
|
||||
if (delivery == null)
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
|
||||
Document doc = documentBuilder.newDocument();
|
||||
|
||||
Element deliveryElem = doc.createElement("delivery");
|
||||
for (Map.Entry<String, List<CardCollection.Item>> collectionTypeItems : delivery.entrySet()) {
|
||||
String collectionType = collectionTypeItems.getKey();
|
||||
List<CardCollection.Item> items = collectionTypeItems.getValue();
|
||||
|
||||
Element collectionTypeElem = doc.createElement("collectionType");
|
||||
collectionTypeElem.setAttribute("name", collectionType);
|
||||
for (CardCollection.Item item : items) {
|
||||
String blueprintId = item.getBlueprintId();
|
||||
if (item.getType() == CardCollection.Item.Type.CARD) {
|
||||
Element card = doc.createElement("card");
|
||||
card.setAttribute("count", String.valueOf(item.getCount()));
|
||||
card.setAttribute("blueprintId", blueprintId);
|
||||
collectionTypeElem.appendChild(card);
|
||||
} else {
|
||||
Element pack = doc.createElement("pack");
|
||||
pack.setAttribute("count", String.valueOf(item.getCount()));
|
||||
pack.setAttribute("blueprintId", blueprintId);
|
||||
collectionTypeElem.appendChild(pack);
|
||||
}
|
||||
}
|
||||
deliveryElem.appendChild(collectionTypeElem);
|
||||
}
|
||||
|
||||
doc.appendChild(deliveryElem);
|
||||
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/inheritance.js"></script>
|
||||
<script type="text/javascript" src="js/communication.js"></script>
|
||||
<script type="text/javascript" src="js/deliveryService.js"></script>
|
||||
<script type="text/javascript" src="js/jCardGroup.js"></script>
|
||||
<script type="text/javascript" src="js/jCards.js"></script>
|
||||
<script type="text/javascript" src="js/logging.js"></script>
|
||||
|
||||
@@ -7,6 +7,29 @@ var GempLotrCommunication = Class.extend({
|
||||
this.failure = failure;
|
||||
},
|
||||
|
||||
getDelivery: function(callback) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: this.url + "/delivery",
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId") },
|
||||
success: callback,
|
||||
error: null,
|
||||
dataType: "xml"
|
||||
});
|
||||
},
|
||||
|
||||
deliveryCheck: function(callback) {
|
||||
var that = this;
|
||||
return function(xml, status, request) {
|
||||
var delivery = request.getResponseHeader("Delivery-Service-Package");
|
||||
if (delivery == "true" && window.deliveryService != null)
|
||||
that.getDelivery(window.deliveryService);
|
||||
callback(xml);
|
||||
};
|
||||
},
|
||||
|
||||
getGameHistory: function(start, count, callback) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
@@ -16,7 +39,7 @@ var GempLotrCommunication = Class.extend({
|
||||
start: start,
|
||||
count: count,
|
||||
participantId: getUrlParam("participantId") },
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -29,7 +52,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participanId: getUrlParam("participantId") },
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -40,7 +63,7 @@ var GempLotrCommunication = Class.extend({
|
||||
type: "GET",
|
||||
url: this.url + "/replay/" + replayId,
|
||||
cache: false,
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -51,7 +74,7 @@ var GempLotrCommunication = Class.extend({
|
||||
url: this.url + "/game/" + getUrlParam("gameId"),
|
||||
cache: false,
|
||||
data: { participantId: getUrlParam("participantId") },
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -62,7 +85,7 @@ var GempLotrCommunication = Class.extend({
|
||||
url: this.url + "/game/" + getUrlParam("gameId"),
|
||||
cache: false,
|
||||
data: { participantId: getUrlParam("participantId") },
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -74,7 +97,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: { cardId: cardId,
|
||||
participantId: getUrlParam("participantId") },
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "html"
|
||||
});
|
||||
@@ -88,7 +111,7 @@ var GempLotrCommunication = Class.extend({
|
||||
participantId: getUrlParam("participantId"),
|
||||
decisionId: decisionId,
|
||||
decisionValue: response},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -112,7 +135,7 @@ var GempLotrCommunication = Class.extend({
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
deckName: deckName},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -124,7 +147,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -136,7 +159,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -151,7 +174,7 @@ var GempLotrCommunication = Class.extend({
|
||||
filter: filter,
|
||||
start: start,
|
||||
count: count},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -164,7 +187,12 @@ var GempLotrCommunication = Class.extend({
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
pack: pack},
|
||||
success: callback,
|
||||
success: function(xml, status, request) {
|
||||
var delivery = request.getResponseHeader("Delivery-Service-Package");
|
||||
if (delivery == "true")
|
||||
|
||||
callback(xml);
|
||||
},
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -178,7 +206,7 @@ var GempLotrCommunication = Class.extend({
|
||||
participantId: getUrlParam("participantId"),
|
||||
deckName: deckName,
|
||||
deckContents: contents},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -192,7 +220,7 @@ var GempLotrCommunication = Class.extend({
|
||||
participantId: getUrlParam("participantId"),
|
||||
oldDeckName: oldDeckName,
|
||||
deckName: deckName},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -205,7 +233,7 @@ var GempLotrCommunication = Class.extend({
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
deckName: deckName},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -218,7 +246,7 @@ var GempLotrCommunication = Class.extend({
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
deckContents: contents},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "html"
|
||||
});
|
||||
@@ -230,7 +258,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -242,7 +270,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -255,7 +283,7 @@ var GempLotrCommunication = Class.extend({
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
message: messages},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
traditional: true,
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
@@ -268,7 +296,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -281,7 +309,7 @@ var GempLotrCommunication = Class.extend({
|
||||
data: {
|
||||
deckName: deckName,
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -295,7 +323,7 @@ var GempLotrCommunication = Class.extend({
|
||||
format: format,
|
||||
deckName: deckName,
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
@@ -318,7 +346,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "html"
|
||||
});
|
||||
@@ -332,7 +360,7 @@ var GempLotrCommunication = Class.extend({
|
||||
login: login,
|
||||
password: password,
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "html"
|
||||
});
|
||||
@@ -346,7 +374,7 @@ var GempLotrCommunication = Class.extend({
|
||||
login: login,
|
||||
password: password,
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "html"
|
||||
});
|
||||
@@ -358,7 +386,7 @@ var GempLotrCommunication = Class.extend({
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId")},
|
||||
success: callback,
|
||||
success: this.deliveryCheck(callback),
|
||||
error: this.failure,
|
||||
dataType: "html"
|
||||
});
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
var deliveryDialog = null;
|
||||
var deliveryGroup = null;
|
||||
|
||||
function deliveryService(xml) {
|
||||
log("Delivered a package:");
|
||||
log(xml);
|
||||
|
||||
var root = xml.documentElement;
|
||||
if (root.tagName == "delivery") {
|
||||
|
||||
var deliveryDialogResize = function() {
|
||||
var width = deliveryDialog.width() + 10;
|
||||
var height = deliveryDialog.height() + 10;
|
||||
deliveryGroup.setBounds(2, 2, width - 2 * 2, height - 2 * 2);
|
||||
};
|
||||
|
||||
if (deliveryDialog == null) {
|
||||
deliveryDialog = $("<div></div>").dialog({
|
||||
title: "You've received the following items",
|
||||
autoOpen: false,
|
||||
closeOnEscape: false,
|
||||
resizable: true,
|
||||
width: 400,
|
||||
height: 200
|
||||
});
|
||||
|
||||
deliveryGroup = new NormalCardGroup(deliveryDialog, function(card) {
|
||||
return true;
|
||||
}, false);
|
||||
|
||||
deliveryDialog.bind("dialogresize", deliveryDialogResize);
|
||||
deliveryDialog.bind("dialogclose",
|
||||
function() {
|
||||
deliveryDialog.html("");
|
||||
});
|
||||
}
|
||||
|
||||
var collections = root.getElementsByTagName("collectionType");
|
||||
for (var i = 0; i < collections.length; i++) {
|
||||
var collection = collections[i];
|
||||
|
||||
var packs = collection.getElementsByTagName("pack");
|
||||
for (var j = 0; j < packs.length; j++) {
|
||||
var packElem = packs[j];
|
||||
var blueprintId = packElem.getAttribute("blueprintId");
|
||||
var count = packElem.getAttribute("count");
|
||||
var card = new Card(blueprintId, "delivery", "deliveryPack" + i, "player");
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil(), true);
|
||||
cardDiv.data("card", card);
|
||||
deliveryDialog.append(cardDiv);
|
||||
}
|
||||
|
||||
var cards = collection.getElementsByTagName("card");
|
||||
for (var j = 0; j < cards.length; j++) {
|
||||
var cardElem = cards[j];
|
||||
var blueprintId = cardElem.getAttribute("blueprintId");
|
||||
var count = cardElem.getAttribute("count");
|
||||
var card = new Card(blueprintId, "delivery", "deliveryCard" + i, "player");
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil());
|
||||
cardDiv.data("card", card);
|
||||
deliveryDialog.append(cardDiv);
|
||||
}
|
||||
}
|
||||
|
||||
deliveryDialog.dialog("open");
|
||||
deliveryDialogResize();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user