diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index 9d15cf578bb..cd954b1cdaa 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -18,6 +18,7 @@ package forge.deck; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.collect.Lists; import forge.StaticData; import forge.card.CardDb; @@ -232,8 +233,10 @@ public class Deck extends DeckBase implements Iterable> referenceDeckLoadingMap; - if (deferredSections != null) - referenceDeckLoadingMap = new HashMap<>(deferredSections); + if (deferredSections != null) { + this.validateDeferredSections(); + referenceDeckLoadingMap = new HashMap<>(this.deferredSections); + } else referenceDeckLoadingMap = new HashMap<>(loadedSections); @@ -276,6 +279,56 @@ public class Deck extends DeckBase implements Iterable> s : this.deferredSections.entrySet()) { + final DeckSection deckSection = DeckSection.smartValueOf(s.getKey()); + if (deckSection == null) + continue; + + final List cardsInSection = s.getValue(); + CardPool pool = CardPool.fromCardList(cardsInSection); + if (pool.countDistinct() == 0) + continue; // pool empty, no card has been found! + + // Filter pool by applying DeckSection Validation schema for Card Types (to avoid inconsistencies) + CardPool filteredPool = pool.getFilteredPoolWithCardsCount(new Predicate() { + @Override + public boolean apply(PaperCard input) { + return deckSection.validate(input); + } + }); + + if (filteredPool.countDistinct() != pool.countDistinct()) { // Some cards have been filtered + CardPool blackListPool = pool.getFilteredPoolWithCardsCount(new Predicate() { + @Override + public boolean apply(PaperCard input) { + return !(deckSection.validate(input)); + } + }); + + List> blackList = Lists.newArrayList(blackListPool); + for (Entry entry : blackList) { + PaperCard card = entry.getKey(); + DeckSection cardSection = DeckSection.matchingSection(card); + if (cardSection == null) + continue; // No matching section could be found! + String cardRequest = CardDb.CardRequest.compose(card.getName(), card.getEdition(), card.getArtIndex()); + String poolRequest = String.format("%d %s", entry.getValue(), cardRequest); + List sectionCardList = this.deferredSections.getOrDefault(cardSection.name(), null); + if (sectionCardList == null) + sectionCardList = new ArrayList<>(); + sectionCardList.add(poolRequest); + this.deferredSections.put(cardSection.name(), sectionCardList); + } + } + } + } + private ArrayList getAllCardNamesWithNoSpecifiedEdition(List cardsInSection) { ArrayList cardNamesWithNoEdition = new ArrayList<>(); List> cardRequests = CardPool.processCardList(cardsInSection);