Adding possibility of selection packs.
This commit is contained in:
@@ -12,7 +12,7 @@ public interface CardCollection extends OwnershipCheck {
|
||||
|
||||
public static class Item {
|
||||
public enum Type {
|
||||
PACK, CARD
|
||||
PACK, CARD, SELECTION
|
||||
}
|
||||
|
||||
private Type _type;
|
||||
|
||||
@@ -144,13 +144,31 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
_counts.put(itemId, oldCount + count);
|
||||
}
|
||||
|
||||
private boolean hasSelection(String packId, String selection, PacksStorage packsStorage) {
|
||||
for (Item item : packsStorage.openPack(packId)) {
|
||||
if (item.getBlueprintId().equals(selection))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized CardCollection openPack(String packId, PacksStorage packsStorage) {
|
||||
public synchronized CardCollection openPack(String packId, String selection, PacksStorage packsStorage) {
|
||||
Integer count = _counts.get(packId);
|
||||
if (count == null)
|
||||
return null;
|
||||
if (count > 0) {
|
||||
List<Item> packContents = packsStorage.openPack(packId);
|
||||
List<Item> packContents = null;
|
||||
if (selection != null && packId.startsWith("(S)")) {
|
||||
if (hasSelection(packId, selection, packsStorage)) {
|
||||
packContents = new LinkedList<Item>();
|
||||
Item.Type type = selection.contains("_") ? Item.Type.CARD : Item.Type.PACK;
|
||||
packContents.add(new Item(type, 1, selection));
|
||||
}
|
||||
} else {
|
||||
packContents = packsStorage.openPack(packId);
|
||||
}
|
||||
|
||||
if (packContents == null)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@ import com.gempukku.lotro.packs.PacksStorage;
|
||||
public interface MutableCardCollection extends CardCollection {
|
||||
public void addItem(String itemId, int count);
|
||||
|
||||
public CardCollection openPack(String packId, PacksStorage packBox);
|
||||
public CardCollection openPack(String packId, String selection, PacksStorage packBox);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
1x1_1T
|
||||
1x1_13T
|
||||
1x1_14T
|
||||
1x1_30T
|
||||
1x1_50T
|
||||
1x1_72T
|
||||
1x1_83T
|
||||
1x1_89T
|
||||
1x1_96T
|
||||
1x1_114T
|
||||
1x1_127T
|
||||
1x1_165T
|
||||
1x1_231T
|
||||
1x1_237T
|
||||
1x1_256T
|
||||
1x2_52T
|
||||
1x2_102T
|
||||
1x2_105T
|
||||
@@ -7,4 +7,5 @@ MoM - Gimli Starter
|
||||
MoM - Booster
|
||||
RotEL - Boromir Starter
|
||||
RotEL - Legolas Starter
|
||||
RotEL - Booster
|
||||
RotEL - Booster
|
||||
(S)FotR - Tengwar
|
||||
@@ -85,6 +85,14 @@ public class CollectionResource extends AbstractResource {
|
||||
Element pack = doc.createElement("pack");
|
||||
pack.setAttribute("count", String.valueOf(item.getCount()));
|
||||
pack.setAttribute("blueprintId", blueprintId);
|
||||
if (blueprintId.startsWith("(S)")) {
|
||||
List<CardCollection.Item> contents = _packStorage.openPack(blueprintId);
|
||||
StringBuilder contentsStr = new StringBuilder();
|
||||
for (CardCollection.Item content : contents)
|
||||
contentsStr.append(content.getBlueprintId()).append("|");
|
||||
contentsStr.delete(contentsStr.length() - 1, contentsStr.length());
|
||||
pack.setAttribute("contents", contentsStr.toString());
|
||||
}
|
||||
collectionElem.appendChild(pack);
|
||||
}
|
||||
}
|
||||
@@ -144,6 +152,7 @@ public class CollectionResource extends AbstractResource {
|
||||
@PathParam("collectionType") String collectionType,
|
||||
@FormParam("participantId") String participantId,
|
||||
@FormParam("pack") String packId,
|
||||
@FormParam("selection") String selection,
|
||||
@Context HttpServletRequest request,
|
||||
@Context HttpServletResponse response) throws ParserConfigurationException {
|
||||
Player resourceOwner = getResourceOwnerSafely(request, participantId);
|
||||
@@ -154,7 +163,7 @@ public class CollectionResource extends AbstractResource {
|
||||
|
||||
MutableCardCollection modifiableColleciton = (MutableCardCollection) collection;
|
||||
|
||||
CardCollection packContents = modifiableColleciton.openPack(packId, _packStorage);
|
||||
CardCollection packContents = modifiableColleciton.openPack(packId, selection, _packStorage);
|
||||
_deliveryService.addPackage(resourceOwner, getPackageNameByCollectionType(collectionType), packContents);
|
||||
|
||||
if (packContents == null)
|
||||
|
||||
@@ -43,6 +43,7 @@ public class PacksStorageProvider implements Injectable<PacksStorage>, Injectabl
|
||||
packStorage.addPackBox("MoM - Gimli Starter", new FixedPackBox("MoM - Gimli Starter"));
|
||||
packStorage.addPackBox("RotEL - Boromir Starter", new FixedPackBox("RotEL - Boromir Starter"));
|
||||
packStorage.addPackBox("RotEL - Legolas Starter", new FixedPackBox("RotEL - Legolas Starter"));
|
||||
packStorage.addPackBox("(S)FotR - Tengwar", new FixedPackBox("(S)FotR - Tengwar"));
|
||||
|
||||
packStorage.addPackBox("FotR - Booster", new RarityPackBox(1));
|
||||
packStorage.addPackBox("MoM - Booster", new RarityPackBox(2));
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
<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>
|
||||
<script type="text/javascript" src="js/commonUi.js"></script>
|
||||
<script type="text/javascript" src="js/deckBuildingUi.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -313,6 +313,7 @@ body {
|
||||
<script type="text/javascript" src="js/inheritance.js"></script>
|
||||
<script type="text/javascript" src="js/communication.js"></script>
|
||||
<script type="text/javascript" src="js/chat.js"></script>
|
||||
<script type="text/javascript" src="js/commonUi.js"></script>
|
||||
<script type="text/javascript" src="js/gameUi.js"></script>
|
||||
<script type="text/javascript" src="js/gameAnimations.js"></script>
|
||||
<script type="text/javascript" src="js/jCardGroup.js"></script>
|
||||
|
||||
@@ -138,6 +138,7 @@
|
||||
<script type="text/javascript" src="js/common.js"></script>
|
||||
<script type="text/javascript" src="js/logging.js"></script>
|
||||
<script type="text/javascript" src="js/chat.js"></script>
|
||||
<script type="text/javascript" src="js/commonUi.js"></script>
|
||||
<script type="text/javascript" src="js/hallUi.js"></script>
|
||||
<script type="text/javascript" src="js/leagueResultsUi.js"></script>
|
||||
<script type="text/javascript" src="js/communication.js"></script>
|
||||
|
||||
22
gemp-lotr/gemp-lotr-web/src/main/webapp/js/commonUi.js
Normal file
22
gemp-lotr/gemp-lotr-web/src/main/webapp/js/commonUi.js
Normal file
@@ -0,0 +1,22 @@
|
||||
var dialogsSized = new Array();
|
||||
|
||||
function openSizeDialog(dialog) {
|
||||
var sizedDialog = function() {
|
||||
for (var i = 0; i < dialogsSized.length; i++)
|
||||
if (dialogsSized[i] == dialog)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!sizedDialog(dialog)) {
|
||||
var windowWidth = $(window).width();
|
||||
var windowHeight = $(window).height();
|
||||
|
||||
var dialogWidth = windowWidth * 0.8;
|
||||
var dialogHeight = windowHeight * 0.8;
|
||||
|
||||
dialogsSized.push(dialog);
|
||||
dialog.dialog({width: dialogWidth, height: dialogHeight});
|
||||
}
|
||||
dialog.dialog("open");
|
||||
}
|
||||
@@ -197,6 +197,25 @@ var GempLotrCommunication = Class.extend({
|
||||
dataType: "xml"
|
||||
});
|
||||
},
|
||||
openSelectionPack: function(collectionType, pack, selection, callback) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: this.url + "/collection/" + collectionType,
|
||||
cache: false,
|
||||
data: {
|
||||
participantId: getUrlParam("participantId"),
|
||||
pack: pack,
|
||||
selection: selection},
|
||||
success: function(xml, status, request) {
|
||||
var delivery = request.getResponseHeader("Delivery-Service-Package");
|
||||
if (delivery == "true")
|
||||
|
||||
callback(xml);
|
||||
},
|
||||
error: this.failure,
|
||||
dataType: "xml"
|
||||
});
|
||||
},
|
||||
saveDeck: function(deckName, contents, callback) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
||||
@@ -35,6 +35,9 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
checkDirtyInterval: 1000,
|
||||
|
||||
deckListDialog: null,
|
||||
selectionDialog: null,
|
||||
selectionGroup: null,
|
||||
packSelectionId: null,
|
||||
|
||||
init: function() {
|
||||
var that = this;
|
||||
@@ -507,7 +510,7 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
}
|
||||
}
|
||||
|
||||
that.deckListDialog.dialog("open");
|
||||
openSizeDialog(that.deckListDialog);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -540,6 +543,50 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
that.getCollection();
|
||||
});
|
||||
}
|
||||
} else if (selectedCardElem.hasClass("cardToSelect")) {
|
||||
this.comm.openSelectionPack(this.getCollectionType(), this.packSelectionId, selectedCardElem.data("card").blueprintId, function() {
|
||||
that.getCollection();
|
||||
});
|
||||
this.selectionDialog.dialog("close");
|
||||
} else if (selectedCardElem.hasClass("selectionInCollection")) {
|
||||
var selectionDialogResize = function() {
|
||||
var width = that.selectionDialog.width() + 10;
|
||||
var height = that.selectionDialog.height() + 10;
|
||||
that.selectionGroup.setBounds(2, 2, width - 2 * 2, height - 2 * 2);
|
||||
};
|
||||
|
||||
if (this.selectionDialog == null) {
|
||||
this.selectionDialog = $("<div></div>")
|
||||
.dialog({
|
||||
title: "Choose one",
|
||||
autoOpen: false,
|
||||
closeOnEscape: true,
|
||||
resizable: true,
|
||||
width: 400,
|
||||
height: 200,
|
||||
modal: true
|
||||
});
|
||||
|
||||
this.selectionGroup = new NormalCardGroup(this.selectionDialog, function(card) {
|
||||
return true;
|
||||
}, false);
|
||||
|
||||
this.selectionDialog.bind("dialogresize", selectionDialogResize);
|
||||
}
|
||||
this.selectionDialog.html("");
|
||||
var cardData = selectedCardElem.data("card");
|
||||
this.packSelectionId = cardData.blueprintId;
|
||||
var selection = selectedCardElem.data("selection");
|
||||
var blueprintIds = selection.split("|");
|
||||
for (var i = 0; i < blueprintIds.length; i++) {
|
||||
var card = new Card(blueprintIds[i], "selection", "selection" + i, "player");
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil(), false);
|
||||
cardDiv.data("card", card);
|
||||
cardDiv.addClass("cardToSelect");
|
||||
this.selectionDialog.append(cardDiv);
|
||||
}
|
||||
openSizeDialog(that.selectionDialog);
|
||||
selectionDialogResize();
|
||||
} else if (selectedCardElem.hasClass("cardInDeck")) {
|
||||
this.removeCardFromDeck(selectedCardElem);
|
||||
}
|
||||
@@ -889,11 +936,20 @@ var GempLotrDeckBuildingUI = Class.extend({
|
||||
var packElem = packs[i];
|
||||
var blueprintId = packElem.getAttribute("blueprintId");
|
||||
var count = packElem.getAttribute("count");
|
||||
var card = new Card(blueprintId, "pack", "collection" + i, "player");
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil(), true);
|
||||
cardDiv.data("card", card);
|
||||
cardDiv.addClass("packInCollection");
|
||||
if (blueprintId.substr(0, 3) == "(S)") {
|
||||
var card = new Card(blueprintId, "pack", "collection" + i, "player");
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, false, true);
|
||||
cardDiv.data("card", card);
|
||||
cardDiv.data("selection", packElem.getAttribute("contents"));
|
||||
cardDiv.addClass("selectionInCollection");
|
||||
} else {
|
||||
var card = new Card(blueprintId, "pack", "collection" + i, "player");
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, false, true);
|
||||
cardDiv.data("card", card);
|
||||
cardDiv.addClass("packInCollection");
|
||||
}
|
||||
if (this.normalCollectionDiv.is(":visible"))
|
||||
this.normalCollectionDiv.append(cardDiv);
|
||||
else
|
||||
|
||||
@@ -306,7 +306,7 @@ var GempLotrGameUI = Class.extend({
|
||||
$("#discard" + this.getPlayerIndex(this.bottomPlayerId)).addClass("clickable").click(
|
||||
(function(index) {
|
||||
return function() {
|
||||
that.discardPileDialogs[that.bottomPlayerId].dialog("open");
|
||||
openSizeDialog(that.discardPileDialogs[that.bottomPlayerId]);
|
||||
};
|
||||
})(i));
|
||||
|
||||
@@ -314,7 +314,7 @@ var GempLotrGameUI = Class.extend({
|
||||
$("#deadPile" + i).addClass("clickable").click(
|
||||
(function(index) {
|
||||
return function() {
|
||||
that.deadPileDialogs[that.allPlayerIds[index]].dialog("open");
|
||||
openSizeDialog(that.deadPileDialogs[that.allPlayerIds[index]]);
|
||||
};
|
||||
})(i));
|
||||
}
|
||||
@@ -1382,7 +1382,7 @@ var GempLotrGameUI = Class.extend({
|
||||
if (!this.replayMode)
|
||||
processButtons();
|
||||
|
||||
this.cardActionDialog.dialog("open");
|
||||
openSizeDialog(this.cardActionDialog);
|
||||
this.arbitraryDialogResize(false);
|
||||
$('.ui-dialog :button').blur();
|
||||
},
|
||||
@@ -1649,7 +1649,7 @@ var GempLotrGameUI = Class.extend({
|
||||
if (!this.replayMode)
|
||||
processButtons();
|
||||
|
||||
this.cardActionDialog.dialog("open");
|
||||
openSizeDialog(this.cardActionDialog);
|
||||
this.arbitraryDialogResize(false);
|
||||
$('.ui-dialog :button').blur();
|
||||
},
|
||||
|
||||
@@ -90,26 +90,28 @@ var Card = Class.extend({
|
||||
},
|
||||
|
||||
getUrlByBlueprintId: function(blueprintId) {
|
||||
if (blueprintId.substr(0, 3) == "(S)")
|
||||
return "/gemp-lotr/images/boosters/selection.png";
|
||||
if (blueprintId == "FotR - League Starter")
|
||||
return "/gemp-lotr/images/boosters/fotr_league_starter.png";
|
||||
else if (blueprintId == "FotR - Gandalf Starter")
|
||||
if (blueprintId == "FotR - Gandalf Starter")
|
||||
return "/gemp-lotr/images/boosters/fotr_gandalf_starter.png";
|
||||
else if (blueprintId == "FotR - Aragorn Starter")
|
||||
return "/gemp-lotr/images/boosters/fotr_aragorn_starter.png";
|
||||
else if (blueprintId == "FotR - Booster")
|
||||
return "/gemp-lotr/images/boosters/fotr_booster.png";
|
||||
else if (blueprintId == "MoM - Gandalf Starter")
|
||||
return "/gemp-lotr/images/boosters/mom_gandalf_starter.png";
|
||||
else if (blueprintId == "MoM - Gimli Starter")
|
||||
return "/gemp-lotr/images/boosters/mom_gimli_starter.png";
|
||||
else if (blueprintId == "MoM - Booster")
|
||||
return "/gemp-lotr/images/boosters/mom_booster.png";
|
||||
else if (blueprintId == "RotEL - Boromir Starter")
|
||||
return "/gemp-lotr/images/boosters/rotel_boromir_starter.png";
|
||||
else if (blueprintId == "RotEL - Legolas Starter")
|
||||
return "/gemp-lotr/images/boosters/rotel_legolas_starter.png";
|
||||
else if (blueprintId == "RotEL - Booster")
|
||||
return "/gemp-lotr/images/boosters/rotel_booster.png";
|
||||
if (blueprintId == "FotR - Aragorn Starter")
|
||||
return "/gemp-lotr/images/boosters/fotr_aragorn_starter.png";
|
||||
if (blueprintId == "FotR - Booster")
|
||||
return "/gemp-lotr/images/boosters/fotr_booster.png";
|
||||
if (blueprintId == "MoM - Gandalf Starter")
|
||||
return "/gemp-lotr/images/boosters/mom_gandalf_starter.png";
|
||||
if (blueprintId == "MoM - Gimli Starter")
|
||||
return "/gemp-lotr/images/boosters/mom_gimli_starter.png";
|
||||
if (blueprintId == "MoM - Booster")
|
||||
return "/gemp-lotr/images/boosters/mom_booster.png";
|
||||
if (blueprintId == "RotEL - Boromir Starter")
|
||||
return "/gemp-lotr/images/boosters/rotel_boromir_starter.png";
|
||||
if (blueprintId == "RotEL - Legolas Starter")
|
||||
return "/gemp-lotr/images/boosters/rotel_legolas_starter.png";
|
||||
if (blueprintId == "RotEL - Booster")
|
||||
return "/gemp-lotr/images/boosters/rotel_booster.png";
|
||||
|
||||
var separator = blueprintId.indexOf("_");
|
||||
var setNo = parseInt(blueprintId.substr(0, separator));
|
||||
|
||||
Reference in New Issue
Block a user