diff --git a/.gitattributes b/.gitattributes
index 63c2f255778..63def2517d3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -12217,6 +12217,7 @@ src/main/java/forge/card/CardManaCost.java -text
src/main/java/forge/card/CardRarity.java -text
src/main/java/forge/card/CardRuleCharacteristics.java -text
src/main/java/forge/card/CardRules.java -text
+src/main/java/forge/card/CardRulesPredicates.java -text
src/main/java/forge/card/CardRulesReader.java svneol=native#text/plain
src/main/java/forge/card/CardSuperType.java -text
src/main/java/forge/card/CardType.java -text
diff --git a/pom.xml b/pom.xml
index 15ed6a881e6..b33c70f0b9d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -657,7 +657,7 @@
com.google.guava
guava
- 12.0
+ 13.0.1
com.thoughtworks.xstream
diff --git a/src/main/java/forge/card/CardRules.java b/src/main/java/forge/card/CardRules.java
index f0b16af702b..efbbfa7ed89 100644
--- a/src/main/java/forge/card/CardRules.java
+++ b/src/main/java/forge/card/CardRules.java
@@ -25,11 +25,8 @@ import java.util.Set;
import org.apache.commons.lang3.StringUtils;
-import com.google.common.base.Predicate;
-import forge.util.ComparableOp;
-import forge.util.PredicateString;
/**
@@ -50,10 +47,10 @@ public final class CardRules {
private String loyalty = null;
- private Map setsPrinted = null;
+ Map setsPrinted = null;
- private boolean isRemovedFromAIDecks = false;
- private boolean isRemovedFromRandomDecks = false;
+ boolean isRemovedFromAIDecks = false;
+ boolean isRemovedFromRandomDecks = false;
private final CardRules slavePart;
@@ -389,568 +386,6 @@ public final class CardRules {
public List getKeywords() {
return characteristics.getKeywords();
}
-
- /**
- * Filtering conditions specific for CardRules class, defined here along
- * with some presets.
- */
- public abstract static class Predicates {
-
- /** The Constant isKeptInAiDecks. */
- public static final Predicate IS_KEPT_IN_AI_DECKS = new Predicate() {
- @Override
- public boolean apply(final CardRules card) {
- return !card.isRemovedFromAIDecks;
- }
- };
-
- /** The Constant isKeptInRandomDecks. */
- public static final Predicate IS_KEPT_IN_RANDOM_DECKS = new Predicate() {
- @Override
- public boolean apply(final CardRules card) {
- return !card.isRemovedFromRandomDecks;
- }
- };
-
- // Static builder methods - they choose concrete implementation by
- // themselves
- /**
- * Cmc.
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate cmc(final ComparableOp op, final int what) {
- return new LeafNumber(LeafNumber.CardField.CMC, op, what);
- }
-
- /**
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate power(final ComparableOp op, final int what) {
- return new LeafNumber(LeafNumber.CardField.POWER, op, what);
- }
-
- /**
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate toughness(final ComparableOp op, final int what) {
- return new LeafNumber(LeafNumber.CardField.TOUGHNESS, op, what);
- }
-
- // P/T
- /**
- * Rules.
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate rules(final PredicateString.StringOp op, final String what) {
- return new LeafString(LeafString.CardField.RULES, op, what);
- }
-
- /**
- * Name.
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate name(final PredicateString.StringOp op, final String what) {
- return new LeafString(LeafString.CardField.NAME, op, what);
- }
-
- /**
- * Sub type.
- *
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate subType(final String what) {
- return new LeafString(LeafString.CardField.SUBTYPE, PredicateString.StringOp.CONTAINS, what);
- }
-
- /**
- * Sub type.
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate subType(final PredicateString.StringOp op, final String what) {
- return new LeafString(LeafString.CardField.SUBTYPE, op, what);
- }
-
- /**
- * Joined type.
- *
- * @param op
- * the op
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate joinedType(final PredicateString.StringOp op, final String what) {
- return new LeafString(LeafString.CardField.JOINED_TYPE, op, what);
- }
-
- /**
- * Has Keyword.
- *
- * @param keyword
- * the keyword
- * @return the predicate
- */
- public static Predicate hasKeyword(final String keyword) {
- return new Predicate() {
- @Override
- public boolean apply(final CardRules card) {
- return card.getKeywords().contains(keyword);
- }
- };
- }
-
- /**
- * Was printed in sets.
- *
- * @param setCodes
- * the set codes
- * @return the predicate
- */
- public static Predicate wasPrintedInSets(final List setCodes) {
- return new PredicateExistsInSets(setCodes);
- }
-
- /**
- * Core type.
- *
- * @param isEqual
- * the is equal
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate coreType(final boolean isEqual, final String what) {
- try {
- return Predicates.coreType(isEqual, Enum.valueOf(CardCoreType.class, what));
- } catch (final Exception e) {
- return com.google.common.base.Predicates.alwaysFalse();
- }
- }
-
- /**
- * Core type.
- *
- * @param isEqual
- * the is equal
- * @param type
- * the type
- * @return the predicate
- */
- public static Predicate coreType(final boolean isEqual, final CardCoreType type) {
- return new PredicateCoreType(type, isEqual);
- }
-
- /**
- * Super type.
- *
- * @param isEqual
- * the is equal
- * @param what
- * the what
- * @return the predicate
- */
- public static Predicate superType(final boolean isEqual, final String what) {
- try {
- return Predicates.superType(isEqual, Enum.valueOf(CardSuperType.class, what));
- } catch (final Exception e) {
- return com.google.common.base.Predicates.alwaysFalse();
- }
- }
-
- /**
- * Super type.
- *
- * @param isEqual
- * the is equal
- * @param type
- * the type
- * @return the predicate
- */
- public static Predicate superType(final boolean isEqual, final CardSuperType type) {
- return new PredicateSuperType(type, isEqual);
- }
-
- /**
- * Rarity in cards latest set.
- *
- * @param isEqual
- * the is equal
- * @param value
- * the value
- * @return the predicate
- */
- public static Predicate rarityInCardsLatestSet(final boolean isEqual, final CardRarity value) {
- return new PredicateLastesSetRarity(value, isEqual);
- }
-
- /**
- * Checks for color.
- *
- * @param thatColor
- * the that color
- * @return the predicate
- */
- public static Predicate hasColor(final byte thatColor) {
- return new LeafColor(LeafColor.ColorOperator.HasAllOf, thatColor);
- }
-
- /**
- * Checks if is color.
- *
- * @param thatColor
- * the that color
- * @return the predicate
- */
- public static Predicate isColor(final byte thatColor) {
- return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
- }
-
- public static Predicate isMonoColor(final byte thatColor) {
- return new LeafColor(LeafColor.ColorOperator.Equals, thatColor);
- }
-
- /**
- * Checks for cnt colors.
- *
- * @param cntColors
- * the cnt colors
- * @return the predicate
- */
- public static Predicate hasCntColors(final byte cntColors) {
- return new LeafColor(LeafColor.ColorOperator.CountColors, cntColors);
- }
-
- /**
- * Checks for at least cnt colors.
- *
- * @param cntColors
- * the cnt colors
- * @return the predicate
- */
- public static Predicate hasAtLeastCntColors(final byte cntColors) {
- return new LeafColor(LeafColor.ColorOperator.CountColorsGreaterOrEqual, cntColors);
- }
-
- private static class LeafString extends PredicateString {
- public enum CardField {
- RULES, NAME, SUBTYPE, JOINED_TYPE
- }
-
- private final String operand;
- private final CardField field;
-
- @Override
- public boolean apply(final CardRules card) {
- boolean shouldContain;
- switch (this.field) {
- case NAME:
- return this.op(card.getName(), this.operand);
- case SUBTYPE:
- shouldContain = (this.getOperator() == StringOp.CONTAINS)
- || (this.getOperator() == StringOp.EQUALS);
- return shouldContain == card.getType().subTypeContains(this.operand);
- case RULES:
- shouldContain = (this.getOperator() == StringOp.CONTAINS)
- || (this.getOperator() == StringOp.EQUALS);
- return shouldContain == card.rulesContain(this.operand);
- case JOINED_TYPE:
- return this.op(card.getType().toString(), this.operand);
- default:
- return false;
- }
- }
-
- public LeafString(final CardField field, final StringOp operator, final String operand) {
- super(operator);
- this.field = field;
- this.operand = operand;
- }
- }
-
- private static class LeafColor implements Predicate {
- public enum ColorOperator {
- CountColors, CountColorsGreaterOrEqual, HasAnyOf, HasAllOf, Equals
- }
-
- private final ColorOperator op;
- private final byte color;
-
- public LeafColor(final ColorOperator operator, final byte thatColor) {
- this.op = operator;
- this.color = thatColor;
- }
-
- @Override
- public boolean apply(final CardRules subject) {
- switch (this.op) {
- case CountColors:
- return subject.getColor().countColors() == this.color;
- case CountColorsGreaterOrEqual:
- return subject.getColor().countColors() >= this.color;
- case Equals:
- return subject.getColor().isEqual(this.color);
- case HasAllOf:
- return subject.getColor().hasAllColors(this.color);
- case HasAnyOf:
- return subject.getColor().hasAnyColor(this.color);
- default:
- return false;
- }
- }
- }
-
- private static class LeafNumber implements Predicate {
- protected enum CardField {
- CMC, POWER, TOUGHNESS,
- }
-
- private final CardField field;
- private final ComparableOp operator;
- private final int operand;
-
- public LeafNumber(final CardField field, final ComparableOp op, final int what) {
- this.field = field;
- this.operand = what;
- this.operator = op;
- }
-
- @Override
- public boolean apply(final CardRules card) {
- int value;
- switch (this.field) {
- case CMC:
- return this.op(card.getManaCost().getCMC(), this.operand);
- case POWER:
- value = card.getIntPower();
- return value >= 0 ? this.op(value, this.operand) : false;
- case TOUGHNESS:
- value = card.getIntToughness();
- return value >= 0 ? this.op(value, this.operand) : false;
- default:
- return false;
- }
- }
-
- private boolean op(final int op1, final int op2) {
- switch (this.operator) {
- case EQUALS:
- return op1 == op2;
- case GREATER_THAN:
- return op1 > op2;
- case GT_OR_EQUAL:
- return op1 >= op2;
- case LESS_THAN:
- return op1 < op2;
- case LT_OR_EQUAL:
- return op1 <= op2;
- case NOT_EQUALS:
- return op1 != op2;
- default:
- return false;
- }
- }
- }
-
- private static class PredicateCoreType implements Predicate {
- private final CardCoreType operand;
- private final boolean shouldBeEqual;
-
- @Override
- public boolean apply(final CardRules card) {
- return this.shouldBeEqual == card.getType().typeContains(this.operand);
- }
-
- public PredicateCoreType(final CardCoreType type, final boolean wantEqual) {
- this.operand = type;
- this.shouldBeEqual = wantEqual;
- }
- }
-
- private static class PredicateSuperType implements Predicate {
- private final CardSuperType operand;
- private final boolean shouldBeEqual;
-
- @Override
- public boolean apply(final CardRules card) {
- return this.shouldBeEqual == card.getType().superTypeContains(this.operand);
- }
-
- public PredicateSuperType(final CardSuperType type, final boolean wantEqual) {
- this.operand = type;
- this.shouldBeEqual = wantEqual;
- }
- }
-
- private static class PredicateLastesSetRarity implements Predicate {
- private final CardRarity operand;
- private final boolean shouldBeEqual;
-
- @Override
- public boolean apply(final CardRules card) {
- return card.getRarityFromLatestSet().equals(this.operand) == this.shouldBeEqual;
- }
-
- public PredicateLastesSetRarity(final CardRarity type, final boolean wantEqual) {
- this.operand = type;
- this.shouldBeEqual = wantEqual;
- }
- }
-
- private static class PredicateExistsInSets implements Predicate {
- private final List sets;
-
- public PredicateExistsInSets(final List wantSets) {
- this.sets = wantSets; // maybe should make a copy here?
- }
-
- @Override
- public boolean apply(final CardRules subject) {
- for (final String s : this.sets) {
- if (subject.setsPrinted.containsKey(s)) {
- return true;
- }
- }
- return false;
- }
- }
-
- /**
- * The Class Presets.
- */
- public static class Presets {
-
- /** The Constant isCreature. */
- public static final Predicate IS_CREATURE = Predicates.coreType(true, CardCoreType.Creature);
-
- /** The Constant isArtifact. */
- public static final Predicate IS_ARTIFACT = Predicates.coreType(true, CardCoreType.Artifact);
-
- /** The Constant isLand. */
- public static final Predicate IS_LAND = Predicates.coreType(true, CardCoreType.Land);
-
- /** The Constant isBasicLand. */
- public static final Predicate IS_BASIC_LAND = new Predicate() {
- @Override
- public boolean apply(final CardRules subject) {
- return subject.getType().isBasicLand();
- }
- };
-
- /** The Constant isPlaneswalker. */
- public static final Predicate IS_PLANESWALKER = Predicates.coreType(true,
- CardCoreType.Planeswalker);
-
- /** The Constant isInstant. */
- public static final Predicate IS_INSTANT = Predicates.coreType(true, CardCoreType.Instant);
-
- /** The Constant isSorcery. */
- public static final Predicate IS_SORCERY = Predicates.coreType(true, CardCoreType.Sorcery);
-
- /** The Constant isEnchantment. */
- public static final Predicate IS_ENCHANTMENT = Predicates.coreType(true,
- CardCoreType.Enchantment);
-
- /** The Constant isNonLand. */
- public static final Predicate IS_NON_LAND = Predicates.coreType(false, CardCoreType.Land);
-
- /** The Constant isNonCreatureSpell. */
- public static final Predicate IS_NON_CREATURE_SPELL =
- com.google.common.base.Predicates.not(com.google.common.base.Predicates.or(Presets.IS_CREATURE,Presets.IS_LAND));
-
- @SuppressWarnings("unchecked")
- public static final Predicate IS_NONCREATURE_SPELL_FOR_GENERATOR =
- com.google.common.base.Predicates.or(
- Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT,
- com.google.common.base.Predicates.and(Presets.IS_ARTIFACT, com.google.common.base.Predicates.not(Presets.IS_CREATURE))
- );
-
- /** The Constant isWhite. */
- public static final Predicate IS_WHITE = Predicates.isColor(CardColor.WHITE);
-
- /** The Constant isBlue. */
- public static final Predicate IS_BLUE = Predicates.isColor(CardColor.BLUE);
-
- /** The Constant isBlack. */
- public static final Predicate IS_BLACK = Predicates.isColor(CardColor.BLACK);
-
- /** The Constant isRed. */
- public static final Predicate IS_RED = Predicates.isColor(CardColor.RED);
-
- /** The Constant isGreen. */
- public static final Predicate IS_GREEN = Predicates.isColor(CardColor.GREEN);
-
- /** The Constant isColorless. */
- public static final Predicate IS_COLORLESS = Predicates.hasCntColors((byte) 0);
-
- /** The Constant isMulticolor. */
- public static final Predicate IS_MULTICOLOR = Predicates.hasAtLeastCntColors((byte) 2);
-
- /** The Constant colors. */
- public static final List> COLORS = new ArrayList>();
- static {
- Presets.COLORS.add(Presets.IS_WHITE);
- Presets.COLORS.add(Presets.IS_BLUE);
- Presets.COLORS.add(Presets.IS_BLACK);
- Presets.COLORS.add(Presets.IS_RED);
- Presets.COLORS.add(Presets.IS_GREEN);
- Presets.COLORS.add(Presets.IS_COLORLESS);
- }
-
- // Think twice before using these, since rarity is a prop of printed
- // card.
- /** The Constant isInLatestSetCommon. */
- public static final Predicate IS_IN_LATEST_SET_COMMON = Predicates.rarityInCardsLatestSet(true,
- CardRarity.Common);
-
- /** The Constant isInLatestSetUncommon. */
- public static final Predicate IS_IN_LATEST_SET_UNCOMMON = Predicates.rarityInCardsLatestSet(
- true, CardRarity.Uncommon);
-
- /** The Constant isInLatestSetRare. */
- public static final Predicate IS_IN_LATEST_SET_RARE = Predicates.rarityInCardsLatestSet(true,
- CardRarity.Rare);
-
- /** The Constant isInLatestSetMythicRare. */
- public static final Predicate IS_IN_LATEST_SET_MYTHIC_RARE = Predicates.rarityInCardsLatestSet(
- true, CardRarity.MythicRare);
-
- /** The Constant isInLatestSetSpecial. */
- public static final Predicate IS_IN_LATEST_SET_SPECIAL = Predicates.rarityInCardsLatestSet(true,
- CardRarity.Special);
- }
- }
}
diff --git a/src/main/java/forge/card/CardRulesPredicates.java b/src/main/java/forge/card/CardRulesPredicates.java
new file mode 100644
index 00000000000..f71b95c8a2c
--- /dev/null
+++ b/src/main/java/forge/card/CardRulesPredicates.java
@@ -0,0 +1,572 @@
+package forge.card;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+
+import forge.util.ComparableOp;
+import forge.util.PredicateString;
+
+/**
+ * Filtering conditions specific for CardRules class, defined here along
+ * with some presets.
+ */
+public final class CardRulesPredicates {
+
+ /** The Constant isKeptInAiDecks. */
+ public static final Predicate IS_KEPT_IN_AI_DECKS = new Predicate() {
+ @Override
+ public boolean apply(final CardRules card) {
+ return !card.isRemovedFromAIDecks;
+ }
+ };
+
+ /** The Constant isKeptInRandomDecks. */
+ public static final Predicate IS_KEPT_IN_RANDOM_DECKS = new Predicate() {
+ @Override
+ public boolean apply(final CardRules card) {
+ return !card.isRemovedFromRandomDecks;
+ }
+ };
+
+ // Static builder methods - they choose concrete implementation by
+ // themselves
+ /**
+ * Cmc.
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate cmc(final ComparableOp op, final int what) {
+ return new LeafNumber(LeafNumber.CardField.CMC, op, what);
+ }
+
+ /**
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate power(final ComparableOp op, final int what) {
+ return new LeafNumber(LeafNumber.CardField.POWER, op, what);
+ }
+
+ /**
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate toughness(final ComparableOp op, final int what) {
+ return new LeafNumber(LeafNumber.CardField.TOUGHNESS, op, what);
+ }
+
+ // P/T
+ /**
+ * Rules.
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate rules(final PredicateString.StringOp op, final String what) {
+ return new LeafString(LeafString.CardField.RULES, op, what);
+ }
+
+ /**
+ * Name.
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate name(final PredicateString.StringOp op, final String what) {
+ return new LeafString(LeafString.CardField.NAME, op, what);
+ }
+
+ /**
+ * Sub type.
+ *
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate subType(final String what) {
+ return new LeafString(LeafString.CardField.SUBTYPE, PredicateString.StringOp.CONTAINS, what);
+ }
+
+ /**
+ * Sub type.
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate subType(final PredicateString.StringOp op, final String what) {
+ return new LeafString(LeafString.CardField.SUBTYPE, op, what);
+ }
+
+ /**
+ * Joined type.
+ *
+ * @param op
+ * the op
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate joinedType(final PredicateString.StringOp op, final String what) {
+ return new LeafString(LeafString.CardField.JOINED_TYPE, op, what);
+ }
+
+ /**
+ * Has Keyword.
+ *
+ * @param keyword
+ * the keyword
+ * @return the predicate
+ */
+ public static Predicate hasKeyword(final String keyword) {
+ return new Predicate() {
+ @Override
+ public boolean apply(final CardRules card) {
+ return card.getKeywords().contains(keyword);
+ }
+ };
+ }
+
+ /**
+ * Was printed in sets.
+ *
+ * @param setCodes
+ * the set codes
+ * @return the predicate
+ */
+ public static Predicate wasPrintedInSets(final List setCodes) {
+ return new PredicateExistsInSets(setCodes);
+ }
+
+ /**
+ * Core type.
+ *
+ * @param isEqual
+ * the is equal
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate coreType(final boolean isEqual, final String what) {
+ try {
+ return CardRulesPredicates.coreType(isEqual, Enum.valueOf(CardCoreType.class, what));
+ } catch (final Exception e) {
+ return com.google.common.base.Predicates.alwaysFalse();
+ }
+ }
+
+ /**
+ * Core type.
+ *
+ * @param isEqual
+ * the is equal
+ * @param type
+ * the type
+ * @return the predicate
+ */
+ public static Predicate coreType(final boolean isEqual, final CardCoreType type) {
+ return new PredicateCoreType(type, isEqual);
+ }
+
+ /**
+ * Super type.
+ *
+ * @param isEqual
+ * the is equal
+ * @param what
+ * the what
+ * @return the predicate
+ */
+ public static Predicate superType(final boolean isEqual, final String what) {
+ try {
+ return CardRulesPredicates.superType(isEqual, Enum.valueOf(CardSuperType.class, what));
+ } catch (final Exception e) {
+ return com.google.common.base.Predicates.alwaysFalse();
+ }
+ }
+
+ /**
+ * Super type.
+ *
+ * @param isEqual
+ * the is equal
+ * @param type
+ * the type
+ * @return the predicate
+ */
+ public static Predicate superType(final boolean isEqual, final CardSuperType type) {
+ return new PredicateSuperType(type, isEqual);
+ }
+
+ /**
+ * Rarity in cards latest set.
+ *
+ * @param isEqual
+ * the is equal
+ * @param value
+ * the value
+ * @return the predicate
+ */
+ public static Predicate rarityInCardsLatestSet(final boolean isEqual, final CardRarity value) {
+ return new PredicateLastesSetRarity(value, isEqual);
+ }
+
+ /**
+ * Checks for color.
+ *
+ * @param thatColor
+ * the that color
+ * @return the predicate
+ */
+ public static Predicate hasColor(final byte thatColor) {
+ return new LeafColor(LeafColor.ColorOperator.HasAllOf, thatColor);
+ }
+
+ /**
+ * Checks if is color.
+ *
+ * @param thatColor
+ * the that color
+ * @return the predicate
+ */
+ public static Predicate isColor(final byte thatColor) {
+ return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
+ }
+
+ public static Predicate isMonoColor(final byte thatColor) {
+ return new LeafColor(LeafColor.ColorOperator.Equals, thatColor);
+ }
+
+ /**
+ * Checks for cnt colors.
+ *
+ * @param cntColors
+ * the cnt colors
+ * @return the predicate
+ */
+ public static Predicate hasCntColors(final byte cntColors) {
+ return new LeafColor(LeafColor.ColorOperator.CountColors, cntColors);
+ }
+
+ /**
+ * Checks for at least cnt colors.
+ *
+ * @param cntColors
+ * the cnt colors
+ * @return the predicate
+ */
+ public static Predicate hasAtLeastCntColors(final byte cntColors) {
+ return new LeafColor(LeafColor.ColorOperator.CountColorsGreaterOrEqual, cntColors);
+ }
+
+ private static class LeafString extends PredicateString {
+ public enum CardField {
+ RULES, NAME, SUBTYPE, JOINED_TYPE
+ }
+
+ private final String operand;
+ private final LeafString.CardField field;
+
+ @Override
+ public boolean apply(final CardRules card) {
+ boolean shouldContain;
+ switch (this.field) {
+ case NAME:
+ return this.op(card.getName(), this.operand);
+ case SUBTYPE:
+ shouldContain = (this.getOperator() == StringOp.CONTAINS)
+ || (this.getOperator() == StringOp.EQUALS);
+ return shouldContain == card.getType().subTypeContains(this.operand);
+ case RULES:
+ shouldContain = (this.getOperator() == StringOp.CONTAINS)
+ || (this.getOperator() == StringOp.EQUALS);
+ return shouldContain == card.rulesContain(this.operand);
+ case JOINED_TYPE:
+ return this.op(card.getType().toString(), this.operand);
+ default:
+ return false;
+ }
+ }
+
+ public LeafString(final LeafString.CardField field, final StringOp operator, final String operand) {
+ super(operator);
+ this.field = field;
+ this.operand = operand;
+ }
+ }
+
+ private static class LeafColor implements Predicate {
+ public enum ColorOperator {
+ CountColors, CountColorsGreaterOrEqual, HasAnyOf, HasAllOf, Equals
+ }
+
+ private final LeafColor.ColorOperator op;
+ private final byte color;
+
+ public LeafColor(final LeafColor.ColorOperator operator, final byte thatColor) {
+ this.op = operator;
+ this.color = thatColor;
+ }
+
+ @Override
+ public boolean apply(final CardRules subject) {
+ switch (this.op) {
+ case CountColors:
+ return subject.getColor().countColors() == this.color;
+ case CountColorsGreaterOrEqual:
+ return subject.getColor().countColors() >= this.color;
+ case Equals:
+ return subject.getColor().isEqual(this.color);
+ case HasAllOf:
+ return subject.getColor().hasAllColors(this.color);
+ case HasAnyOf:
+ return subject.getColor().hasAnyColor(this.color);
+ default:
+ return false;
+ }
+ }
+ }
+
+ private static class LeafNumber implements Predicate {
+ protected enum CardField {
+ CMC, POWER, TOUGHNESS,
+ }
+
+ private final LeafNumber.CardField field;
+ private final ComparableOp operator;
+ private final int operand;
+
+ public LeafNumber(final LeafNumber.CardField field, final ComparableOp op, final int what) {
+ this.field = field;
+ this.operand = what;
+ this.operator = op;
+ }
+
+ @Override
+ public boolean apply(final CardRules card) {
+ int value;
+ switch (this.field) {
+ case CMC:
+ return this.op(card.getManaCost().getCMC(), this.operand);
+ case POWER:
+ value = card.getIntPower();
+ return value >= 0 ? this.op(value, this.operand) : false;
+ case TOUGHNESS:
+ value = card.getIntToughness();
+ return value >= 0 ? this.op(value, this.operand) : false;
+ default:
+ return false;
+ }
+ }
+
+ private boolean op(final int op1, final int op2) {
+ switch (this.operator) {
+ case EQUALS:
+ return op1 == op2;
+ case GREATER_THAN:
+ return op1 > op2;
+ case GT_OR_EQUAL:
+ return op1 >= op2;
+ case LESS_THAN:
+ return op1 < op2;
+ case LT_OR_EQUAL:
+ return op1 <= op2;
+ case NOT_EQUALS:
+ return op1 != op2;
+ default:
+ return false;
+ }
+ }
+ }
+
+ private static class PredicateCoreType implements Predicate {
+ private final CardCoreType operand;
+ private final boolean shouldBeEqual;
+
+ @Override
+ public boolean apply(final CardRules card) {
+ return this.shouldBeEqual == card.getType().typeContains(this.operand);
+ }
+
+ public PredicateCoreType(final CardCoreType type, final boolean wantEqual) {
+ this.operand = type;
+ this.shouldBeEqual = wantEqual;
+ }
+ }
+
+ private static class PredicateSuperType implements Predicate {
+ private final CardSuperType operand;
+ private final boolean shouldBeEqual;
+
+ @Override
+ public boolean apply(final CardRules card) {
+ return this.shouldBeEqual == card.getType().superTypeContains(this.operand);
+ }
+
+ public PredicateSuperType(final CardSuperType type, final boolean wantEqual) {
+ this.operand = type;
+ this.shouldBeEqual = wantEqual;
+ }
+ }
+
+ private static class PredicateLastesSetRarity implements Predicate {
+ private final CardRarity operand;
+ private final boolean shouldBeEqual;
+
+ @Override
+ public boolean apply(final CardRules card) {
+ return card.getRarityFromLatestSet().equals(this.operand) == this.shouldBeEqual;
+ }
+
+ public PredicateLastesSetRarity(final CardRarity type, final boolean wantEqual) {
+ this.operand = type;
+ this.shouldBeEqual = wantEqual;
+ }
+ }
+
+ private static class PredicateExistsInSets implements Predicate {
+ private final List sets;
+
+ public PredicateExistsInSets(final List wantSets) {
+ this.sets = wantSets; // maybe should make a copy here?
+ }
+
+ @Override
+ public boolean apply(final CardRules subject) {
+ for (final String s : this.sets) {
+ if (subject.setsPrinted.containsKey(s)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ /**
+ * The Class Presets.
+ */
+ public static class Presets {
+
+ /** The Constant isCreature. */
+ public static final Predicate IS_CREATURE = CardRulesPredicates.coreType(true, CardCoreType.Creature);
+
+ /** The Constant isArtifact. */
+ public static final Predicate IS_ARTIFACT = CardRulesPredicates.coreType(true, CardCoreType.Artifact);
+
+ /** The Constant isLand. */
+ public static final Predicate IS_LAND = CardRulesPredicates.coreType(true, CardCoreType.Land);
+
+ /** The Constant isBasicLand. */
+ public static final Predicate IS_BASIC_LAND = new Predicate() {
+ @Override
+ public boolean apply(final CardRules subject) {
+ return subject.getType().isBasicLand();
+ }
+ };
+
+ /** The Constant isPlaneswalker. */
+ public static final Predicate IS_PLANESWALKER = CardRulesPredicates.coreType(true,
+ CardCoreType.Planeswalker);
+
+ /** The Constant isInstant. */
+ public static final Predicate IS_INSTANT = CardRulesPredicates.coreType(true, CardCoreType.Instant);
+
+ /** The Constant isSorcery. */
+ public static final Predicate IS_SORCERY = CardRulesPredicates.coreType(true, CardCoreType.Sorcery);
+
+ /** The Constant isEnchantment. */
+ public static final Predicate IS_ENCHANTMENT = CardRulesPredicates.coreType(true,
+ CardCoreType.Enchantment);
+
+ /** The Constant isNonLand. */
+ public static final Predicate IS_NON_LAND = CardRulesPredicates.coreType(false, CardCoreType.Land);
+
+ /** The Constant isNonCreatureSpell. */
+ public static final Predicate IS_CREATURE_OR_LAND = Predicates.or(Presets.IS_CREATURE,Presets.IS_LAND);
+ public static final Predicate IS_NON_CREATURE_SPELL = Predicates.not(IS_CREATURE_OR_LAND);
+
+ @SuppressWarnings("unchecked")
+ public static final Predicate IS_NONCREATURE_SPELL_FOR_GENERATOR =
+ com.google.common.base.Predicates.or(
+ Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT,
+ Predicates.and(Presets.IS_ARTIFACT, Predicates.not(Presets.IS_CREATURE))
+ );
+
+ /** The Constant isWhite. */
+ public static final Predicate IS_WHITE = CardRulesPredicates.isColor(CardColor.WHITE);
+
+ /** The Constant isBlue. */
+ public static final Predicate IS_BLUE = CardRulesPredicates.isColor(CardColor.BLUE);
+
+ /** The Constant isBlack. */
+ public static final Predicate IS_BLACK = CardRulesPredicates.isColor(CardColor.BLACK);
+
+ /** The Constant isRed. */
+ public static final Predicate IS_RED = CardRulesPredicates.isColor(CardColor.RED);
+
+ /** The Constant isGreen. */
+ public static final Predicate IS_GREEN = CardRulesPredicates.isColor(CardColor.GREEN);
+
+ /** The Constant isColorless. */
+ public static final Predicate IS_COLORLESS = CardRulesPredicates.hasCntColors((byte) 0);
+
+ /** The Constant isMulticolor. */
+ public static final Predicate IS_MULTICOLOR = CardRulesPredicates.hasAtLeastCntColors((byte) 2);
+
+ /** The Constant colors. */
+ public static final List> COLORS = new ArrayList>();
+ static {
+ Presets.COLORS.add(Presets.IS_WHITE);
+ Presets.COLORS.add(Presets.IS_BLUE);
+ Presets.COLORS.add(Presets.IS_BLACK);
+ Presets.COLORS.add(Presets.IS_RED);
+ Presets.COLORS.add(Presets.IS_GREEN);
+ Presets.COLORS.add(Presets.IS_COLORLESS);
+ }
+
+ // Think twice before using these, since rarity is a prop of printed
+ // card.
+ /** The Constant isInLatestSetCommon. */
+ public static final Predicate IS_IN_LATEST_SET_COMMON = CardRulesPredicates.rarityInCardsLatestSet(true,
+ CardRarity.Common);
+
+ /** The Constant isInLatestSetUncommon. */
+ public static final Predicate IS_IN_LATEST_SET_UNCOMMON = CardRulesPredicates.rarityInCardsLatestSet(
+ true, CardRarity.Uncommon);
+
+ /** The Constant isInLatestSetRare. */
+ public static final Predicate IS_IN_LATEST_SET_RARE = CardRulesPredicates.rarityInCardsLatestSet(true,
+ CardRarity.Rare);
+
+ /** The Constant isInLatestSetMythicRare. */
+ public static final Predicate IS_IN_LATEST_SET_MYTHIC_RARE = CardRulesPredicates.rarityInCardsLatestSet(
+ true, CardRarity.MythicRare);
+
+ /** The Constant isInLatestSetSpecial. */
+ public static final Predicate IS_IN_LATEST_SET_SPECIAL = CardRulesPredicates.rarityInCardsLatestSet(true,
+ CardRarity.Special);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/forge/card/DeckHints.java b/src/main/java/forge/card/DeckHints.java
index 25b07d6144e..2e47372f1ee 100644
--- a/src/main/java/forge/card/DeckHints.java
+++ b/src/main/java/forge/card/DeckHints.java
@@ -77,7 +77,7 @@ public class DeckHints {
ret = new ArrayList();
String[] types = filterParam.split("\\|");
for (String type : types) {
- addMatchingItems(ret, cardList, CardRules.Predicates.subType(type), CardPrinted.FN_GET_RULES);
+ addMatchingItems(ret, cardList, CardRulesPredicates.subType(type), CardPrinted.FN_GET_RULES);
}
break;
case COLOR:
@@ -85,21 +85,21 @@ public class DeckHints {
String[] colors = filterParam.split("\\|");
for (String color : colors) {
CardColor cc = CardColor.fromNames(color);
- addMatchingItems(ret, cardList, CardRules.Predicates.isColor(cc.getColor()), CardPrinted.FN_GET_RULES);
+ addMatchingItems(ret, cardList, CardRulesPredicates.isColor(cc.getColor()), CardPrinted.FN_GET_RULES);
}
break;
case KEYWORD:
ret = new ArrayList();
String[] keywords = filterParam.split("\\|");
for (String keyword : keywords) {
- addMatchingItems(ret, cardList, CardRules.Predicates.hasKeyword(keyword), CardPrinted.FN_GET_RULES);
+ addMatchingItems(ret, cardList, CardRulesPredicates.hasKeyword(keyword), CardPrinted.FN_GET_RULES);
}
break;
case NAME:
ret = new ArrayList();
String[] names = filterParam.split("\\|");
for (String name : names) {
- addMatchingItems(ret, cardList, CardRules.Predicates.name(StringOp.EQUALS, name), CardPrinted.FN_GET_RULES);
+ addMatchingItems(ret, cardList, CardRulesPredicates.name(StringOp.EQUALS, name), CardPrinted.FN_GET_RULES);
}
break;
default:
diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java
index a0e8e7f53c5..2bc889f2d7a 100644
--- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java
+++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java
@@ -2709,14 +2709,7 @@ public class CardFactoryUtil {
final String validDevoured = l[0].split(" ")[1];
final Card csource = c;
CardList cl = c.getDevoured();
-
- cl = cl.filter(new Predicate() {
- @Override
- public boolean apply(final Card cdev) {
- return cdev.isValid(validDevoured.split(","), csource.getController(), csource);
- }
- });
-
+ cl = cl.getValidCards(validDevoured.split(","), csource.getController(), csource);
return CardFactoryUtil.doXMath(cl.size(), m, c);
}
diff --git a/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java b/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java
index d83f5cf13ce..5785d516d90 100644
--- a/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java
+++ b/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java
@@ -31,6 +31,7 @@ import com.google.common.collect.Iterables;
import forge.Constant;
import forge.Singletons;
import forge.card.CardColor;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
import forge.game.player.PlayerType;
@@ -86,12 +87,12 @@ public abstract class GenerateColoredDeckBase {
final Iterable cards = selectCardsOfMatchingColorForPlayer(pt);
// build subsets based on type
- final Iterable creatures = Iterables.filter(cards, Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES));
+ final Iterable creatures = Iterables.filter(cards, Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES));
final int creatCnt = (int) (getCreatPercentage() * size);
tmpDeck.append("Creature Count:").append(creatCnt).append("\n");
addCmcAdjusted(creatures, creatCnt, cmcLevels, cmcAmounts);
- Predicate preSpells = Predicates.compose(CardRules.Predicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, CardPrinted.FN_GET_RULES);
+ Predicate preSpells = Predicates.compose(CardRulesPredicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, CardPrinted.FN_GET_RULES);
final Iterable spells = Iterables.filter(cards, preSpells);
final int spellCnt = (int) (getSpellPercentage() * size);
tmpDeck.append("Spell Count:").append(spellCnt).append("\n");
@@ -179,7 +180,7 @@ public abstract class GenerateColoredDeckBase {
addSome(diff, tDeck.toFlatList());
} else if (actualSize > targetSize) {
- Predicate exceptBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
+ Predicate exceptBasicLand = Predicates.not(Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
for (int i = 0; i < 3 && actualSize > targetSize; i++) {
Iterable matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand);
diff --git a/src/main/java/forge/game/GameFormat.java b/src/main/java/forge/game/GameFormat.java
index 75f098b7ae7..fcbe20c0acf 100644
--- a/src/main/java/forge/game/GameFormat.java
+++ b/src/main/java/forge/game/GameFormat.java
@@ -24,7 +24,7 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-import forge.card.CardRules;
+import forge.card.CardRulesPredicates;
import forge.item.CardPrinted;
@@ -71,7 +71,7 @@ public final class GameFormat {
final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
if ( this.allowedSetCodes == null || this.allowedSetCodes.isEmpty() )
return banNames;
- return Predicates.and(banNames, Predicates.compose(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.FN_GET_RULES));
+ return Predicates.and(banNames, Predicates.compose(CardRulesPredicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.FN_GET_RULES));
}
/**
diff --git a/src/main/java/forge/game/limited/BoosterDraftAI.java b/src/main/java/forge/game/limited/BoosterDraftAI.java
index ae48e2991b3..998fee97726 100644
--- a/src/main/java/forge/game/limited/BoosterDraftAI.java
+++ b/src/main/java/forge/game/limited/BoosterDraftAI.java
@@ -30,6 +30,7 @@ import com.google.common.collect.Lists;
import forge.Constant;
import forge.card.CardColor;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.deck.Deck;
import forge.deck.generate.GenerateDeckUtil;
@@ -79,7 +80,7 @@ public class BoosterDraftAI {
CardPrinted pickedCard = null;
- Predicate pred = Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES);
+ Predicate pred = Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES);
Iterable aiPlayablesView = Iterables.filter(chooseFrom, pred );
List aiPlayables = Lists.newArrayList(aiPlayablesView);
diff --git a/src/main/java/forge/game/limited/LimitedDeck.java b/src/main/java/forge/game/limited/LimitedDeck.java
index 6afaa6a93c3..e13bec62722 100644
--- a/src/main/java/forge/game/limited/LimitedDeck.java
+++ b/src/main/java/forge/game/limited/LimitedDeck.java
@@ -20,6 +20,7 @@ import com.google.common.collect.Lists;
import forge.Constant;
import forge.card.CardColor;
import forge.card.CardManaCost;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.card.DeckHints;
import forge.card.mana.ManaCostShard;
@@ -68,7 +69,7 @@ public class LimitedDeck {
this.colors = pClrs.getCardColors();
// removeUnplayables();
- Iterable playables = Iterables.filter(availableList, Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES));
+ Iterable playables = Iterables.filter(availableList, Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES));
this.aiPlayables = Lists.newArrayList(playables);
this.availableList.removeAll(getAiPlayables());
@@ -99,14 +100,14 @@ public class LimitedDeck {
// -1. Prepare
hasColor = Predicates.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors), GenerateDeckUtil.COLORLESS_CARDS);
colorList = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES));
- onColorCreatures = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES));
- onColorNonCreatures = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL, CardPrinted.FN_GET_RULES));
+ onColorCreatures = Iterables.filter(colorList, Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES));
+ onColorNonCreatures = Iterables.filter(colorList, Predicates.compose(CardRulesPredicates.Presets.IS_NON_CREATURE_SPELL, CardPrinted.FN_GET_RULES));
// Guava iterables do not copy the collection contents, instead they act as filters and
// iterate over _source_ collection each time. So even if aiPlayable has changed,
// there is no need to create a new iterable.
// 0. Add any planeswalkers
- Iterable onColorWalkers = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_PLANESWALKER, CardPrinted.FN_GET_RULES));
+ Iterable onColorWalkers = Iterables.filter(colorList, Predicates.compose(CardRulesPredicates.Presets.IS_PLANESWALKER, CardPrinted.FN_GET_RULES));
List walkers = Lists.newArrayList(onColorWalkers);
deckList.addAll(walkers);
aiPlayables.removeAll(walkers);
@@ -402,7 +403,7 @@ public class LimitedDeck {
* @param nCards
*/
private void addRandomCards(int nCards) {
- Iterable others = Iterables.filter(aiPlayables, Predicates.compose(CardRules.Predicates.Presets.IS_NON_LAND, CardPrinted.FN_GET_RULES));
+ Iterable others = Iterables.filter(aiPlayables, Predicates.compose(CardRulesPredicates.Presets.IS_NON_LAND, CardPrinted.FN_GET_RULES));
List> ranked = rankCards(others);
for (Pair bean : ranked) {
if (nCards > 0) {
@@ -577,7 +578,7 @@ public class LimitedDeck {
for (int i = 1; i < 7; i++) {
creatureCosts.put(i, 0);
}
- Predicate filter = Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES);
+ Predicate filter = Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES);
for (CardPrinted creature : Iterables.filter(deckList, filter)) {
int cmc = creature.getCard().getManaCost().getCMC();
if (cmc < 1) {
diff --git a/src/main/java/forge/game/limited/SealedDeck.java b/src/main/java/forge/game/limited/SealedDeck.java
index 2b56d61eb92..d209fe488e8 100644
--- a/src/main/java/forge/game/limited/SealedDeck.java
+++ b/src/main/java/forge/game/limited/SealedDeck.java
@@ -12,6 +12,7 @@ import com.google.common.collect.Iterables;
import forge.Constant;
import forge.Constant.Color;
import forge.card.CardColor;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.item.CardPrinted;
import forge.util.MyRandom;
@@ -52,11 +53,11 @@ public class SealedDeck extends LimitedDeck {
Iterable rules = Iterables.transform(colorChooserList, CardPrinted.FN_GET_RULES);
- int white = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_WHITE));
- int blue = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_BLUE));
- int black = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_BLACK));
- int red = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_RED));
- int green = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_GREEN));
+ int white = Iterables.size(Iterables.filter(rules, CardRulesPredicates.Presets.IS_WHITE));
+ int blue = Iterables.size(Iterables.filter(rules, CardRulesPredicates.Presets.IS_BLUE));
+ int black = Iterables.size(Iterables.filter(rules, CardRulesPredicates.Presets.IS_BLACK));
+ int red = Iterables.size(Iterables.filter(rules, CardRulesPredicates.Presets.IS_RED));
+ int green = Iterables.size(Iterables.filter(rules, CardRulesPredicates.Presets.IS_GREEN));
final int[] colorCounts = { white, blue, black, red, green };
final String[] colors = Constant.Color.ONLY_COLORS;
diff --git a/src/main/java/forge/gui/deckeditor/SEditorUtil.java b/src/main/java/forge/gui/deckeditor/SEditorUtil.java
index c442353ebb4..62cf33dcc37 100644
--- a/src/main/java/forge/gui/deckeditor/SEditorUtil.java
+++ b/src/main/java/forge/gui/deckeditor/SEditorUtil.java
@@ -8,6 +8,7 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.gui.deckeditor.views.ITableContainer;
import forge.gui.deckeditor.views.VCardCatalog;
@@ -101,19 +102,19 @@ public final class SEditorUtil {
public static void setStats(final ItemPoolView deck, final ITableContainer view) {
view.getLblTotal().setText(String.valueOf(deck.countAll()));
- setLabelTextSum(view.getLblCreature(), deck, CardRules.Predicates.Presets.IS_CREATURE);
- setLabelTextSum(view.getLblLand(), deck, CardRules.Predicates.Presets.IS_LAND);
- setLabelTextSum(view.getLblEnchantment(), deck, CardRules.Predicates.Presets.IS_ENCHANTMENT);
- setLabelTextSum(view.getLblArtifact(), deck, CardRules.Predicates.Presets.IS_ARTIFACT);
- setLabelTextSum(view.getLblInstant(), deck, CardRules.Predicates.Presets.IS_INSTANT);
- setLabelTextSum(view.getLblSorcery(), deck, CardRules.Predicates.Presets.IS_SORCERY);
- setLabelTextSum(view.getLblPlaneswalker(), deck, CardRules.Predicates.Presets.IS_PLANESWALKER);
- setLabelTextSum(view.getLblColorless(), deck, CardRules.Predicates.Presets.IS_COLORLESS);
- setLabelTextSum(view.getLblBlack(), deck, CardRules.Predicates.Presets.IS_BLACK);
- setLabelTextSum(view.getLblBlue(), deck, CardRules.Predicates.Presets.IS_BLUE);
- setLabelTextSum(view.getLblGreen(), deck, CardRules.Predicates.Presets.IS_GREEN);
- setLabelTextSum(view.getLblRed(), deck, CardRules.Predicates.Presets.IS_RED);
- setLabelTextSum(view.getLblWhite(), deck, CardRules.Predicates.Presets.IS_WHITE);
+ setLabelTextSum(view.getLblCreature(), deck, CardRulesPredicates.Presets.IS_CREATURE);
+ setLabelTextSum(view.getLblLand(), deck, CardRulesPredicates.Presets.IS_LAND);
+ setLabelTextSum(view.getLblEnchantment(), deck, CardRulesPredicates.Presets.IS_ENCHANTMENT);
+ setLabelTextSum(view.getLblArtifact(), deck, CardRulesPredicates.Presets.IS_ARTIFACT);
+ setLabelTextSum(view.getLblInstant(), deck, CardRulesPredicates.Presets.IS_INSTANT);
+ setLabelTextSum(view.getLblSorcery(), deck, CardRulesPredicates.Presets.IS_SORCERY);
+ setLabelTextSum(view.getLblPlaneswalker(), deck, CardRulesPredicates.Presets.IS_PLANESWALKER);
+ setLabelTextSum(view.getLblColorless(), deck, CardRulesPredicates.Presets.IS_COLORLESS);
+ setLabelTextSum(view.getLblBlack(), deck, CardRulesPredicates.Presets.IS_BLACK);
+ setLabelTextSum(view.getLblBlue(), deck, CardRulesPredicates.Presets.IS_BLUE);
+ setLabelTextSum(view.getLblGreen(), deck, CardRulesPredicates.Presets.IS_GREEN);
+ setLabelTextSum(view.getLblRed(), deck, CardRulesPredicates.Presets.IS_RED);
+ setLabelTextSum(view.getLblWhite(), deck, CardRulesPredicates.Presets.IS_WHITE);
} // getStats()
/**
diff --git a/src/main/java/forge/gui/deckeditor/SFilterUtil.java b/src/main/java/forge/gui/deckeditor/SFilterUtil.java
index 8c03a56345c..23d2323d83f 100644
--- a/src/main/java/forge/gui/deckeditor/SFilterUtil.java
+++ b/src/main/java/forge/gui/deckeditor/SFilterUtil.java
@@ -20,6 +20,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import forge.card.CardEdition;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.game.GameFormat;
import forge.gui.WrapLayout;
@@ -186,22 +187,22 @@ public class SFilterUtil {
JCheckBox chbTemp;
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.BLACK)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_BLACK); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_BLACK); }
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.BLUE)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_BLUE); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_BLUE); }
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.GREEN)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_GREEN); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_GREEN); }
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.RED)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_RED); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_RED); }
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.WHITE)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_WHITE); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_WHITE); }
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.COLORLESS)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_COLORLESS); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_COLORLESS); }
// Multi-colored needs special XOR treatment, since "not multi" when OR-ed
// with any other of its colors except colorless, will return true.
@@ -212,7 +213,7 @@ public class SFilterUtil {
preMulti = Predicates.alwaysTrue();
}
else {
- preMulti = Predicates.compose(CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES);
+ preMulti = Predicates.compose(CardRulesPredicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES);
}
final Predicate preColors = Predicates.compose(Predicates.or(ors), CardPrinted.FN_GET_RULES);
@@ -229,7 +230,7 @@ public class SFilterUtil {
}
if (allEmptyExceptMulti) {
- return Predicates.compose(CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES);
+ return Predicates.compose(CardRulesPredicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES);
}
else {
return Predicates.and(preColors, preMulti);
@@ -271,25 +272,25 @@ public class SFilterUtil {
JCheckBox chbTemp;
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.ARTIFACT)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_ARTIFACT); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_ARTIFACT); }
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.CREATURE)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_CREATURE); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_CREATURE); }
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.ENCHANTMENT)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_ENCHANTMENT); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_ENCHANTMENT); }
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.INSTANT)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_INSTANT); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_INSTANT); }
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.LAND)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_LAND); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_LAND); }
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.PLANESWALKER)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_PLANESWALKER); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_PLANESWALKER); }
chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.SORCERY)).getCheckBox();
- if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_SORCERY); }
+ if (chbTemp.isSelected()) { ors.add(CardRulesPredicates.Presets.IS_SORCERY); }
return Predicates.compose(Predicates.or(ors), CardPrinted.FN_GET_RULES);
}
@@ -323,14 +324,15 @@ public class SFilterUtil {
for (final String s : splitContains) {
final List> subands = new ArrayList>();
- if (useName) { subands.add(Predicates.compose(CardRules.Predicates.name(
+ if (useName) { subands.add(Predicates.compose(CardRulesPredicates.name(
StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); }
- if (useType) { subands.add(Predicates.compose(CardRules.Predicates.joinedType(
+ if (useType) { subands.add(Predicates.compose(CardRulesPredicates.joinedType(
StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); }
- if (useText) { subands.add(Predicates.compose(CardRules.Predicates.rules(
+ if (useText) { subands.add(Predicates.compose(CardRulesPredicates.rules(
StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); }
- ands.add(Predicates.or(subands));
+ Predicate mvnMustDie = Predicates.or(subands);
+ ands.add(mvnMustDie);
}
filterAnd = Predicates.and(ands);
@@ -347,16 +349,26 @@ public class SFilterUtil {
for (final String s : splitWithout) {
final List> subnots = new ArrayList>();
- if (useName) { subnots.add(Predicates.compose(CardRules.Predicates.name(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); }
- if (useType) { subnots.add(Predicates.compose(CardRules.Predicates.joinedType(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); }
- if (useText) { subnots.add(Predicates.compose(CardRules.Predicates.rules(StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); }
+ if (useName) {
+ final Predicate pName = Predicates.compose(CardRulesPredicates.name(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES);
+ subnots.add(pName);
+ }
+ if (useType) {
+ final Predicate pType = Predicates.compose(CardRulesPredicates.joinedType(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES);
+ subnots.add(pType);
+ }
+ if (useText) {
+ final Predicate pRules = Predicates.compose(CardRulesPredicates.rules(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES);
+ subnots.add(pRules);
+ }
- nots.add(Predicates.or(subnots));
+ Predicate mavenCompilerIsBugged = Predicates.or(subnots);
+ nots.add(mavenCompilerIsBugged);
}
- filterNot = Predicates.not(Predicates.or(nots));
+ Predicate iWouldNotWriteThisIfMavenProcessedGenericsCorrectly = Predicates.or(nots);
+ filterNot = Predicates.not(iWouldNotWriteThisIfMavenProcessedGenericsCorrectly);
}
-
return Predicates.and(filterAnd, filterNot);
}
@@ -401,7 +413,7 @@ public class SFilterUtil {
final Predicate preNotCreature;
if (plow == -1) {
preNotCreature = Predicates.not(
- Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE,
+ Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE,
CardPrinted.FN_GET_RULES));
}
// Otherwise, if 0 or higher is selected, cards without power
@@ -411,9 +423,9 @@ public class SFilterUtil {
}
final Predicate prePowerTemp = Predicates.and(
- Predicates.compose(CardRules.Predicates.power(
+ Predicates.compose(CardRulesPredicates.power(
ComparableOp.GT_OR_EQUAL, plow), CardPrinted.FN_GET_RULES),
- Predicates.compose(CardRules.Predicates.power(
+ Predicates.compose(CardRulesPredicates.power(
ComparableOp.LT_OR_EQUAL, phigh), CardPrinted.FN_GET_RULES));
prePower = Predicates.or(preNotCreature, prePowerTemp);
@@ -429,7 +441,7 @@ public class SFilterUtil {
final Predicate preNotCreature;
if (tlow == -1) {
preNotCreature = Predicates.not(
- Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE,
+ Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE,
CardPrinted.FN_GET_RULES));
}
// Otherwise, if 0 or higher is selected, cards without toughness
@@ -439,9 +451,9 @@ public class SFilterUtil {
}
final Predicate preToughnessTemp = Predicates.and(
- Predicates.compose(CardRules.Predicates.toughness(
+ Predicates.compose(CardRulesPredicates.toughness(
ComparableOp.GT_OR_EQUAL, tlow), CardPrinted.FN_GET_RULES),
- Predicates.compose(CardRules.Predicates.toughness(
+ Predicates.compose(CardRulesPredicates.toughness(
ComparableOp.LT_OR_EQUAL, thigh), CardPrinted.FN_GET_RULES));
preToughness = Predicates.or(preNotCreature, preToughnessTemp);
@@ -453,9 +465,9 @@ public class SFilterUtil {
if (clow > chigh) { preCMC = Predicates.alwaysFalse(); }
else {
preCMC = Predicates.and(
- Predicates.compose(CardRules.Predicates.cmc(
+ Predicates.compose(CardRulesPredicates.cmc(
ComparableOp.GT_OR_EQUAL, clow), CardPrinted.FN_GET_RULES),
- Predicates.compose(CardRules.Predicates.cmc(
+ Predicates.compose(CardRulesPredicates.cmc(
ComparableOp.LT_OR_EQUAL, chigh), CardPrinted.FN_GET_RULES));
}
diff --git a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java
index a0e904cc4c3..0fe8be0fbb9 100644
--- a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java
+++ b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java
@@ -5,7 +5,7 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import forge.Command;
-import forge.card.CardRules;
+import forge.card.CardRulesPredicates;
import forge.deck.Deck;
import forge.deck.DeckBase;
import forge.deck.generate.Generate2ColorDeck;
@@ -80,7 +80,7 @@ public enum CDeckgen implements ICDoc {
final Deck randomDeck = new Deck();
- Predicate notBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND,CardPrinted.FN_GET_RULES));
+ Predicate notBasicLand = Predicates.not(Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND,CardPrinted.FN_GET_RULES));
Iterable source = Iterables.filter(CardDb.instance().getAllUniqueCards(), notBasicLand);
randomDeck.getMain().addAllFlat(Aggregates.random(source, 15*5));
diff --git a/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java b/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java
index 9c480da6317..a02fa793e19 100644
--- a/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java
+++ b/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java
@@ -10,6 +10,7 @@ import com.google.common.collect.Iterables;
import forge.Command;
import forge.card.CardColor;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.deck.DeckBase;
import forge.gui.deckeditor.CDeckEditorUI;
@@ -81,21 +82,21 @@ public enum CStatistics implements ICDoc {
if (total == 0) { total = 1; }
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblCreature(), deck, CardRules.Predicates.Presets.IS_CREATURE, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblLand(), deck, CardRules.Predicates.Presets.IS_LAND, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblEnchantment(), deck, CardRules.Predicates.Presets.IS_ENCHANTMENT, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblArtifact(), deck, CardRules.Predicates.Presets.IS_ARTIFACT, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblInstant(), deck, CardRules.Predicates.Presets.IS_INSTANT, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblSorcery(), deck, CardRules.Predicates.Presets.IS_SORCERY, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker(), deck, CardRules.Predicates.Presets.IS_PLANESWALKER, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblCreature(), deck, CardRulesPredicates.Presets.IS_CREATURE, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblLand(), deck, CardRulesPredicates.Presets.IS_LAND, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblEnchantment(), deck, CardRulesPredicates.Presets.IS_ENCHANTMENT, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblArtifact(), deck, CardRulesPredicates.Presets.IS_ARTIFACT, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblInstant(), deck, CardRulesPredicates.Presets.IS_INSTANT, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblSorcery(), deck, CardRulesPredicates.Presets.IS_SORCERY, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker(), deck, CardRulesPredicates.Presets.IS_PLANESWALKER, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblMulti(), deck, CardRules.Predicates.Presets.IS_MULTICOLOR, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblColorless(), deck, CardRules.Predicates.Presets.IS_COLORLESS, total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlack(), deck, CardRules.Predicates.isMonoColor(CardColor.BLACK), total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlue(), deck, CardRules.Predicates.isMonoColor(CardColor.BLUE), total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblGreen(), deck, CardRules.Predicates.isMonoColor(CardColor.GREEN), total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblRed(), deck, CardRules.Predicates.isMonoColor(CardColor.RED), total );
- setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblWhite(), deck, CardRules.Predicates.isMonoColor(CardColor.WHITE), total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblMulti(), deck, CardRulesPredicates.Presets.IS_MULTICOLOR, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblColorless(), deck, CardRulesPredicates.Presets.IS_COLORLESS, total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlack(), deck, CardRulesPredicates.isMonoColor(CardColor.BLACK), total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlue(), deck, CardRulesPredicates.isMonoColor(CardColor.BLUE), total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblGreen(), deck, CardRulesPredicates.isMonoColor(CardColor.GREEN), total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblRed(), deck, CardRulesPredicates.isMonoColor(CardColor.RED), total );
+ setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblWhite(), deck, CardRulesPredicates.isMonoColor(CardColor.WHITE), total );
int cmc0 = 0, cmc1 = 0, cmc2 = 0, cmc3 = 0, cmc4 = 0, cmc5 = 0, cmc6 = 0;
int tmc = 0;
diff --git a/src/main/java/forge/item/OpenablePack.java b/src/main/java/forge/item/OpenablePack.java
index 8dbcf274de5..e970e38d4d6 100644
--- a/src/main/java/forge/item/OpenablePack.java
+++ b/src/main/java/forge/item/OpenablePack.java
@@ -25,7 +25,7 @@ import com.google.common.collect.Iterables;
import forge.card.BoosterData;
import forge.card.BoosterGenerator;
-import forge.card.CardRules;
+import forge.card.CardRulesPredicates;
import forge.util.Aggregates;
/**
@@ -174,7 +174,7 @@ public abstract class OpenablePack implements InventoryItemFromSet {
protected List getRandomBasicLands(final String setCode, final int count) {
Predicate cardsRule = Predicates.and(
CardPrinted.Predicates.printedInSets(setCode),
- Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
+ Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
return Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), cardsRule), count);
}
diff --git a/src/main/java/forge/quest/BoosterUtils.java b/src/main/java/forge/quest/BoosterUtils.java
index 496282c67ab..6bfad8c0808 100644
--- a/src/main/java/forge/quest/BoosterUtils.java
+++ b/src/main/java/forge/quest/BoosterUtils.java
@@ -29,6 +29,7 @@ import com.google.common.collect.Iterables;
import forge.card.BoosterGenerator;
+import forge.card.CardRulesPredicates;
import forge.card.CardRules;
import forge.card.UnOpenedProduct;
import forge.item.CardDb;
@@ -69,30 +70,30 @@ public final class BoosterUtils {
// There should be 1 Multicolor card for every 4 cards in a single color
final List> colorFilters = new ArrayList>();
- colorFilters.add(CardRules.Predicates.Presets.IS_MULTICOLOR);
+ colorFilters.add(CardRulesPredicates.Presets.IS_MULTICOLOR);
for (int i = 0; i < 4; i++) {
if (i != 2) {
- colorFilters.add(CardRules.Predicates.Presets.IS_COLORLESS);
+ colorFilters.add(CardRulesPredicates.Presets.IS_COLORLESS);
}
- colorFilters.add(CardRules.Predicates.Presets.IS_WHITE);
- colorFilters.add(CardRules.Predicates.Presets.IS_RED);
- colorFilters.add(CardRules.Predicates.Presets.IS_BLUE);
- colorFilters.add(CardRules.Predicates.Presets.IS_BLACK);
- colorFilters.add(CardRules.Predicates.Presets.IS_GREEN);
+ colorFilters.add(CardRulesPredicates.Presets.IS_WHITE);
+ colorFilters.add(CardRulesPredicates.Presets.IS_RED);
+ colorFilters.add(CardRulesPredicates.Presets.IS_BLUE);
+ colorFilters.add(CardRulesPredicates.Presets.IS_BLACK);
+ colorFilters.add(CardRulesPredicates.Presets.IS_GREEN);
}
final Iterable cardpool = CardDb.instance().getAllUniqueCards();
- cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
- Predicates.and(filter, CardPrinted.Predicates.Presets.IS_COMMON), numCommon, colorFilters));
- cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
- Predicates.and(filter, CardPrinted.Predicates.Presets.IS_UNCOMMON), numUncommon, colorFilters));
+ final Predicate pCommon = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_COMMON);
+ cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, pCommon, numCommon, colorFilters));
+
+ final Predicate pUncommon = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_UNCOMMON);
+ cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, pUncommon, numUncommon, colorFilters));
int nRares = numRare, nMythics = 0;
- final Predicate filterMythics = Predicates.and(filter,
- CardPrinted.Predicates.Presets.IS_MYTHIC_RARE);
+ final Predicate filterMythics = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_MYTHIC_RARE);
final boolean haveMythics = Iterables.any(cardpool, filterMythics);
for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) {
if (MyRandom.getRandom().nextInt(10) < 1) {
@@ -102,8 +103,8 @@ public final class BoosterUtils {
}
}
- cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
- Predicates.and(filter, CardPrinted.Predicates.Presets.IS_RARE), nRares, colorFilters));
+ final Predicate pRare = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_RARE);
+ cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, pRare, nRares, colorFilters));
if (nMythics > 0) {
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters));
}
@@ -235,19 +236,19 @@ public final class BoosterUtils {
// Determine color ("random" defaults to null color)
Predicate col = Predicates.alwaysTrue();
if (temp[1].equalsIgnoreCase("black")) {
- col = CardRules.Predicates.Presets.IS_BLACK;
+ col = CardRulesPredicates.Presets.IS_BLACK;
} else if (temp[1].equalsIgnoreCase("blue")) {
- col = CardRules.Predicates.Presets.IS_BLUE;
+ col = CardRulesPredicates.Presets.IS_BLUE;
} else if (temp[1].equalsIgnoreCase("colorless")) {
- col = CardRules.Predicates.Presets.IS_COLORLESS;
+ col = CardRulesPredicates.Presets.IS_COLORLESS;
} else if (temp[1].equalsIgnoreCase("green")) {
- col = CardRules.Predicates.Presets.IS_GREEN;
+ col = CardRulesPredicates.Presets.IS_GREEN;
} else if (temp[1].equalsIgnoreCase("multicolor")) {
- col = CardRules.Predicates.Presets.IS_MULTICOLOR;
+ col = CardRulesPredicates.Presets.IS_MULTICOLOR;
} else if (temp[1].equalsIgnoreCase("red")) {
- col = CardRules.Predicates.Presets.IS_RED;
+ col = CardRulesPredicates.Presets.IS_RED;
} else if (temp[1].equalsIgnoreCase("white")) {
- col = CardRules.Predicates.Presets.IS_WHITE;
+ col = CardRulesPredicates.Presets.IS_WHITE;
}
Function> openWay = new Function>() {
@@ -257,6 +258,7 @@ public final class BoosterUtils {
}
};
Predicate colorPred = Predicates.compose(col, CardPrinted.FN_GET_RULES);
- return new UnOpenedProduct(openWay, new BoosterGenerator(Predicates.and(rar, colorPred))); // qty))
+ Predicate rarAndColor = Predicates.and(rar, colorPred);
+ return new UnOpenedProduct(openWay, new BoosterGenerator(rarAndColor)); // qty))
}
}
diff --git a/src/main/java/forge/quest/QuestUtilCards.java b/src/main/java/forge/quest/QuestUtilCards.java
index 70a302e08f2..07dcd8bab61 100644
--- a/src/main/java/forge/quest/QuestUtilCards.java
+++ b/src/main/java/forge/quest/QuestUtilCards.java
@@ -101,9 +101,12 @@ public final class QuestUtilCards {
final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES);
final ArrayList newCards = new ArrayList();
- newCards.addAll(BoosterUtils.generateDistinctCards(Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON), nCommon));
- newCards.addAll(BoosterUtils.generateDistinctCards(Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON), nUncommon));
- newCards.addAll(BoosterUtils.generateDistinctCards(Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC), nRare));
+ Predicate predCommons = Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON);
+ newCards.addAll(BoosterUtils.generateDistinctCards(predCommons, nCommon));
+ Predicate predUncommons = Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON);
+ newCards.addAll(BoosterUtils.generateDistinctCards(predUncommons, nUncommon));
+ Predicate predRareMythics = Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC);
+ newCards.addAll(BoosterUtils.generateDistinctCards(predRareMythics, nRare));
this.addAllCards(newCards);
return newCards;