Prevent partial complete Tiny Leaders decks being filtered out

This commit is contained in:
drdev
2015-11-26 17:35:17 +00:00
parent 4b610e9dfd
commit 80bcab72d3
3 changed files with 28 additions and 2 deletions

View File

@@ -344,6 +344,22 @@ public enum DeckFormat {
}; };
} }
public Predicate<Deck> hasLegalCardsPredicate() {
return new Predicate<Deck>() {
@Override
public boolean apply(Deck deck) {
if (cardPoolFilter != null) {
for (final Entry<PaperCard, Integer> cp : deck.getAllCardsInASinglePool()) {
if (!cardPoolFilter.apply(cp.getKey().getRules())) {
return false;
}
}
}
return true;
}
};
}
public Predicate<PaperCard> isLegalCardPredicate() { public Predicate<PaperCard> isLegalCardPredicate() {
return new Predicate<PaperCard>() { return new Predicate<PaperCard>() {
@Override @Override

View File

@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import forge.StaticData; import forge.StaticData;
@@ -351,8 +352,17 @@ public class DeckProxy implements InventoryItem {
} }
public static Iterable<DeckProxy> getAllTinyLeadersDecks() { public static Iterable<DeckProxy> getAllTinyLeadersDecks() {
return getAllTinyLeadersDecks(null);
}
public static Iterable<DeckProxy> getAllTinyLeadersDecks(Predicate<Deck> filter) {
final List<DeckProxy> result = new ArrayList<DeckProxy>(); final List<DeckProxy> result = new ArrayList<DeckProxy>();
addDecksRecursivelly("Tiny Leaders", GameType.TinyLeaders, result, "", FModel.getDecks().getCommander(), DeckFormat.TinyLeaders.isLegalDeckPredicate()); if (filter == null) {
filter = DeckFormat.TinyLeaders.hasLegalCardsPredicate();
}
else {
filter = Predicates.and(DeckFormat.TinyLeaders.hasLegalCardsPredicate(), filter);
}
addDecksRecursivelly("Tiny Leaders", GameType.TinyLeaders, result, "", FModel.getDecks().getCommander(), filter);
return result; return result;
} }

View File

@@ -114,7 +114,7 @@ public class RandomDeckGenerator extends DeckProxy implements Comparable<RandomD
decks = DeckProxy.getAllCommanderDecks(DeckFormat.Commander.isLegalDeckPredicate()); decks = DeckProxy.getAllCommanderDecks(DeckFormat.Commander.isLegalDeckPredicate());
break; break;
case TinyLeaders: case TinyLeaders:
decks = DeckProxy.getAllTinyLeadersDecks(); //already applies isLegal check for TinyLeaders decks = DeckProxy.getAllTinyLeadersDecks(DeckFormat.TinyLeaders.isLegalDeckPredicate());
break; break;
case Archenemy: case Archenemy:
decks = DeckProxy.getAllSchemeDecks(DeckFormat.Archenemy.isLegalDeckPredicate()); decks = DeckProxy.getAllSchemeDecks(DeckFormat.Archenemy.isLegalDeckPredicate());