diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/CollectionUtils.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/CollectionUtils.java index 97cb93302..9a5d3d1c2 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/CollectionUtils.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/CollectionUtils.java @@ -3,6 +3,7 @@ package com.gempukku.lotro.game; import com.gempukku.lotro.logic.vo.LotroDeck; import java.util.HashMap; +import java.util.List; import java.util.Map; public class CollectionUtils { @@ -21,6 +22,13 @@ public class CollectionUtils { return counts; } + public static Map getTotalCardCount(List cards) { + Map counts = new HashMap(); + for (String card : cards) + incrementCardCount(counts, card, 1); + return counts; + } + private static void incrementCardCount(Map map, String blueprintId, int incrementBy) { final Integer oldCount = map.get(blueprintId); if (oldCount == null) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java index b93e41dfe..97fb89451 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java @@ -58,12 +58,14 @@ public class LotroServer extends AbstractServer { for (int j = 1; j <= cardCounts[i]; j++) { String blueprintId = i + "_" + j; try { - LotroCardBlueprint cardBlueprint = _lotroCardBlueprintLibrary.getLotroCardBlueprint(blueprintId); - CardType cardType = cardBlueprint.getCardType(); - if (cardType == CardType.SITE || cardType == CardType.THE_ONE_RING) - _defaultCollection.addItem(blueprintId, 1); - else - _defaultCollection.addItem(blueprintId, 4); + if (_lotroCardBlueprintLibrary.getBaseBlueprintId(blueprintId).equals(blueprintId)) { + LotroCardBlueprint cardBlueprint = _lotroCardBlueprintLibrary.getLotroCardBlueprint(blueprintId); + CardType cardType = cardBlueprint.getCardType(); + if (cardType == CardType.SITE || cardType == CardType.THE_ONE_RING) + _defaultCollection.addItem(blueprintId, 1); + else + _defaultCollection.addItem(blueprintId, 4); + } } catch (IllegalArgumentException exp) { } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java index 1eac6eb0a..1fafbbabf 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java @@ -238,33 +238,56 @@ public class HallServer extends AbstractServer { } // Now check if player owns all the cards - OwnershipCheck ownershipCheck; if (collectionType.getCode().equals("default")) { - // Merging player-owned cards in collection with the default one (containing all basic cards) CardCollection ownedCollection = _collectionsManager.getPlayerCollection(player, "permanent"); - if (ownedCollection != null) - ownershipCheck = new MergedOwnershipCheck(_lotroServer.getDefaultCollection(), ownedCollection); - else - ownershipCheck = _lotroServer.getDefaultCollection(); - } else - ownershipCheck = _collectionsManager.getPlayerCollection(player, collectionType.getCode()); - if (ownershipCheck == null) - throw new HallException("You don't have cards in the required collection to play in this format"); + LotroDeck filteredSpecialCardsDeck = new LotroDeck(); + filteredSpecialCardsDeck.setRing(filterCard(lotroDeck.getRing(), ownedCollection)); + filteredSpecialCardsDeck.setRingBearer(filterCard(lotroDeck.getRingBearer(), ownedCollection)); - Map deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck); + for (String site : lotroDeck.getSites()) + filteredSpecialCardsDeck.addSite(filterCard(site, ownedCollection)); - for (Map.Entry cardCount : deckCardCounts.entrySet()) { - final int collectionCount = ownershipCheck.getItemCount(cardCount.getKey()); - if (collectionCount < cardCount.getValue()) { - String cardName = _library.getLotroCardBlueprint(cardCount.getKey()).getName(); - throw new HallException("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + collectionCount); + for (Map.Entry cardCount : CollectionUtils.getTotalCardCount(lotroDeck.getAdventureCards()).entrySet()) { + String blueprintId = cardCount.getKey(); + int count = cardCount.getValue(); + + int owned = 0; + if (ownedCollection != null) + owned = ownedCollection.getItemCount(blueprintId); + + for (int i = 0; i < owned; i++) + filteredSpecialCardsDeck.addCard(blueprintId); + for (int i = 0; i < (count - owned); i++) + filteredSpecialCardsDeck.addCard(_library.getBaseBlueprintId(blueprintId)); + } + + lotroDeck = filteredSpecialCardsDeck; + } else { + CardCollection collection = _collectionsManager.getPlayerCollection(player, collectionType.getCode()); + if (collection == null) + throw new HallException("You don't have cards in the required collection to play in this format"); + + Map deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck); + + for (Map.Entry cardCount : deckCardCounts.entrySet()) { + final int collectionCount = collection.getItemCount(cardCount.getKey()); + if (collectionCount < cardCount.getValue()) { + String cardName = _library.getLotroCardBlueprint(cardCount.getKey()).getName(); + throw new HallException("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + collectionCount); + } } } return lotroDeck; } + private String filterCard(String blueprintId, CardCollection ownedCollection) { + if (ownedCollection == null || ownedCollection.getItemCount(blueprintId) == 0) + return _library.getBaseBlueprintId(blueprintId); + return blueprintId; + } + private String getTournamentName(AwaitingTable table) { String tournamentName = "Casual"; final League league = table.getLeague();