Removing promo, foil and tengwar cards from Casual games, unless player owns them.

This commit is contained in:
marcins78@gmail.com
2012-01-16 12:44:50 +00:00
parent dbf2e5e9e8
commit fa7603f623
3 changed files with 55 additions and 22 deletions

View File

@@ -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<String, Integer> getTotalCardCount(List<String> cards) {
Map<String, Integer> counts = new HashMap<String, Integer>();
for (String card : cards)
incrementCardCount(counts, card, 1);
return counts;
}
private static void incrementCardCount(Map<String, Integer> map, String blueprintId, int incrementBy) {
final Integer oldCount = map.get(blueprintId);
if (oldCount == null)

View File

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

View File

@@ -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<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
for (String site : lotroDeck.getSites())
filteredSpecialCardsDeck.addSite(filterCard(site, ownedCollection));
for (Map.Entry<String, Integer> 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<String, Integer> 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<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
for (Map.Entry<String, Integer> 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();