mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Making mvn build the project
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -657,7 +657,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>12.0</version>
|
||||
<version>13.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
|
||||
@@ -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<String, CardInSet> setsPrinted = null;
|
||||
Map<String, CardInSet> 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<String> 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<CardRules> IS_KEPT_IN_AI_DECKS = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return !card.isRemovedFromAIDecks;
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isKeptInRandomDecks. */
|
||||
public static final Predicate<CardRules> IS_KEPT_IN_RANDOM_DECKS = new Predicate<CardRules>() {
|
||||
@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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> hasKeyword(final String keyword) {
|
||||
return new Predicate<CardRules>() {
|
||||
@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<CardRules> wasPrintedInSets(final List<String> setCodes) {
|
||||
return new PredicateExistsInSets(setCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Core type.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> isColor(final byte thatColor) {
|
||||
return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
|
||||
}
|
||||
|
||||
public static Predicate<CardRules> 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<CardRules> 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<CardRules> hasAtLeastCntColors(final byte cntColors) {
|
||||
return new LeafColor(LeafColor.ColorOperator.CountColorsGreaterOrEqual, cntColors);
|
||||
}
|
||||
|
||||
private static class LeafString extends PredicateString<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
private final List<String> sets;
|
||||
|
||||
public PredicateExistsInSets(final List<String> 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<CardRules> IS_CREATURE = Predicates.coreType(true, CardCoreType.Creature);
|
||||
|
||||
/** The Constant isArtifact. */
|
||||
public static final Predicate<CardRules> IS_ARTIFACT = Predicates.coreType(true, CardCoreType.Artifact);
|
||||
|
||||
/** The Constant isLand. */
|
||||
public static final Predicate<CardRules> IS_LAND = Predicates.coreType(true, CardCoreType.Land);
|
||||
|
||||
/** The Constant isBasicLand. */
|
||||
public static final Predicate<CardRules> IS_BASIC_LAND = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
return subject.getType().isBasicLand();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isPlaneswalker. */
|
||||
public static final Predicate<CardRules> IS_PLANESWALKER = Predicates.coreType(true,
|
||||
CardCoreType.Planeswalker);
|
||||
|
||||
/** The Constant isInstant. */
|
||||
public static final Predicate<CardRules> IS_INSTANT = Predicates.coreType(true, CardCoreType.Instant);
|
||||
|
||||
/** The Constant isSorcery. */
|
||||
public static final Predicate<CardRules> IS_SORCERY = Predicates.coreType(true, CardCoreType.Sorcery);
|
||||
|
||||
/** The Constant isEnchantment. */
|
||||
public static final Predicate<CardRules> IS_ENCHANTMENT = Predicates.coreType(true,
|
||||
CardCoreType.Enchantment);
|
||||
|
||||
/** The Constant isNonLand. */
|
||||
public static final Predicate<CardRules> IS_NON_LAND = Predicates.coreType(false, CardCoreType.Land);
|
||||
|
||||
/** The Constant isNonCreatureSpell. */
|
||||
public static final Predicate<CardRules> 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<CardRules> 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<CardRules> IS_WHITE = Predicates.isColor(CardColor.WHITE);
|
||||
|
||||
/** The Constant isBlue. */
|
||||
public static final Predicate<CardRules> IS_BLUE = Predicates.isColor(CardColor.BLUE);
|
||||
|
||||
/** The Constant isBlack. */
|
||||
public static final Predicate<CardRules> IS_BLACK = Predicates.isColor(CardColor.BLACK);
|
||||
|
||||
/** The Constant isRed. */
|
||||
public static final Predicate<CardRules> IS_RED = Predicates.isColor(CardColor.RED);
|
||||
|
||||
/** The Constant isGreen. */
|
||||
public static final Predicate<CardRules> IS_GREEN = Predicates.isColor(CardColor.GREEN);
|
||||
|
||||
/** The Constant isColorless. */
|
||||
public static final Predicate<CardRules> IS_COLORLESS = Predicates.hasCntColors((byte) 0);
|
||||
|
||||
/** The Constant isMulticolor. */
|
||||
public static final Predicate<CardRules> IS_MULTICOLOR = Predicates.hasAtLeastCntColors((byte) 2);
|
||||
|
||||
/** The Constant colors. */
|
||||
public static final List<Predicate<CardRules>> COLORS = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardRules> IS_IN_LATEST_SET_COMMON = Predicates.rarityInCardsLatestSet(true,
|
||||
CardRarity.Common);
|
||||
|
||||
/** The Constant isInLatestSetUncommon. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_UNCOMMON = Predicates.rarityInCardsLatestSet(
|
||||
true, CardRarity.Uncommon);
|
||||
|
||||
/** The Constant isInLatestSetRare. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_RARE = Predicates.rarityInCardsLatestSet(true,
|
||||
CardRarity.Rare);
|
||||
|
||||
/** The Constant isInLatestSetMythicRare. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_MYTHIC_RARE = Predicates.rarityInCardsLatestSet(
|
||||
true, CardRarity.MythicRare);
|
||||
|
||||
/** The Constant isInLatestSetSpecial. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_SPECIAL = Predicates.rarityInCardsLatestSet(true,
|
||||
CardRarity.Special);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
572
src/main/java/forge/card/CardRulesPredicates.java
Normal file
572
src/main/java/forge/card/CardRulesPredicates.java
Normal file
@@ -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<CardRules> IS_KEPT_IN_AI_DECKS = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return !card.isRemovedFromAIDecks;
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isKeptInRandomDecks. */
|
||||
public static final Predicate<CardRules> IS_KEPT_IN_RANDOM_DECKS = new Predicate<CardRules>() {
|
||||
@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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> hasKeyword(final String keyword) {
|
||||
return new Predicate<CardRules>() {
|
||||
@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<CardRules> wasPrintedInSets(final List<String> setCodes) {
|
||||
return new PredicateExistsInSets(setCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Core type.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> 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<CardRules> isColor(final byte thatColor) {
|
||||
return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
|
||||
}
|
||||
|
||||
public static Predicate<CardRules> 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<CardRules> 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<CardRules> hasAtLeastCntColors(final byte cntColors) {
|
||||
return new LeafColor(LeafColor.ColorOperator.CountColorsGreaterOrEqual, cntColors);
|
||||
}
|
||||
|
||||
private static class LeafString extends PredicateString<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
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<CardRules> {
|
||||
private final List<String> sets;
|
||||
|
||||
public PredicateExistsInSets(final List<String> 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<CardRules> IS_CREATURE = CardRulesPredicates.coreType(true, CardCoreType.Creature);
|
||||
|
||||
/** The Constant isArtifact. */
|
||||
public static final Predicate<CardRules> IS_ARTIFACT = CardRulesPredicates.coreType(true, CardCoreType.Artifact);
|
||||
|
||||
/** The Constant isLand. */
|
||||
public static final Predicate<CardRules> IS_LAND = CardRulesPredicates.coreType(true, CardCoreType.Land);
|
||||
|
||||
/** The Constant isBasicLand. */
|
||||
public static final Predicate<CardRules> IS_BASIC_LAND = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
return subject.getType().isBasicLand();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isPlaneswalker. */
|
||||
public static final Predicate<CardRules> IS_PLANESWALKER = CardRulesPredicates.coreType(true,
|
||||
CardCoreType.Planeswalker);
|
||||
|
||||
/** The Constant isInstant. */
|
||||
public static final Predicate<CardRules> IS_INSTANT = CardRulesPredicates.coreType(true, CardCoreType.Instant);
|
||||
|
||||
/** The Constant isSorcery. */
|
||||
public static final Predicate<CardRules> IS_SORCERY = CardRulesPredicates.coreType(true, CardCoreType.Sorcery);
|
||||
|
||||
/** The Constant isEnchantment. */
|
||||
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true,
|
||||
CardCoreType.Enchantment);
|
||||
|
||||
/** The Constant isNonLand. */
|
||||
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(false, CardCoreType.Land);
|
||||
|
||||
/** The Constant isNonCreatureSpell. */
|
||||
public static final Predicate<CardRules> IS_CREATURE_OR_LAND = Predicates.or(Presets.IS_CREATURE,Presets.IS_LAND);
|
||||
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = Predicates.not(IS_CREATURE_OR_LAND);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Predicate<CardRules> 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<CardRules> IS_WHITE = CardRulesPredicates.isColor(CardColor.WHITE);
|
||||
|
||||
/** The Constant isBlue. */
|
||||
public static final Predicate<CardRules> IS_BLUE = CardRulesPredicates.isColor(CardColor.BLUE);
|
||||
|
||||
/** The Constant isBlack. */
|
||||
public static final Predicate<CardRules> IS_BLACK = CardRulesPredicates.isColor(CardColor.BLACK);
|
||||
|
||||
/** The Constant isRed. */
|
||||
public static final Predicate<CardRules> IS_RED = CardRulesPredicates.isColor(CardColor.RED);
|
||||
|
||||
/** The Constant isGreen. */
|
||||
public static final Predicate<CardRules> IS_GREEN = CardRulesPredicates.isColor(CardColor.GREEN);
|
||||
|
||||
/** The Constant isColorless. */
|
||||
public static final Predicate<CardRules> IS_COLORLESS = CardRulesPredicates.hasCntColors((byte) 0);
|
||||
|
||||
/** The Constant isMulticolor. */
|
||||
public static final Predicate<CardRules> IS_MULTICOLOR = CardRulesPredicates.hasAtLeastCntColors((byte) 2);
|
||||
|
||||
/** The Constant colors. */
|
||||
public static final List<Predicate<CardRules>> COLORS = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardRules> IS_IN_LATEST_SET_COMMON = CardRulesPredicates.rarityInCardsLatestSet(true,
|
||||
CardRarity.Common);
|
||||
|
||||
/** The Constant isInLatestSetUncommon. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_UNCOMMON = CardRulesPredicates.rarityInCardsLatestSet(
|
||||
true, CardRarity.Uncommon);
|
||||
|
||||
/** The Constant isInLatestSetRare. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_RARE = CardRulesPredicates.rarityInCardsLatestSet(true,
|
||||
CardRarity.Rare);
|
||||
|
||||
/** The Constant isInLatestSetMythicRare. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_MYTHIC_RARE = CardRulesPredicates.rarityInCardsLatestSet(
|
||||
true, CardRarity.MythicRare);
|
||||
|
||||
/** The Constant isInLatestSetSpecial. */
|
||||
public static final Predicate<CardRules> IS_IN_LATEST_SET_SPECIAL = CardRulesPredicates.rarityInCardsLatestSet(true,
|
||||
CardRarity.Special);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class DeckHints {
|
||||
ret = new ArrayList<CardPrinted>();
|
||||
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<CardPrinted>();
|
||||
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<CardPrinted>();
|
||||
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:
|
||||
|
||||
@@ -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<Card>() {
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CardPrinted> cards = selectCardsOfMatchingColorForPlayer(pt);
|
||||
// build subsets based on type
|
||||
|
||||
final Iterable<CardPrinted> creatures = Iterables.filter(cards, Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES));
|
||||
final Iterable<CardPrinted> 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<CardPrinted> preSpells = Predicates.compose(CardRules.Predicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, CardPrinted.FN_GET_RULES);
|
||||
Predicate<CardPrinted> preSpells = Predicates.compose(CardRulesPredicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, CardPrinted.FN_GET_RULES);
|
||||
final Iterable<CardPrinted> 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<CardPrinted> exceptBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
|
||||
Predicate<CardPrinted> exceptBasicLand = Predicates.not(Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
|
||||
|
||||
for (int i = 0; i < 3 && actualSize > targetSize; i++) {
|
||||
Iterable<CardPrinted> matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand);
|
||||
|
||||
@@ -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<CardPrinted> 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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<CardPrinted> pred = Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES);
|
||||
Predicate<CardPrinted> pred = Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES);
|
||||
Iterable<CardPrinted> aiPlayablesView = Iterables.filter(chooseFrom, pred );
|
||||
List<CardPrinted> aiPlayables = Lists.newArrayList(aiPlayablesView);
|
||||
|
||||
|
||||
@@ -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<CardPrinted> playables = Iterables.filter(availableList, Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES));
|
||||
Iterable<CardPrinted> 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<CardPrinted> onColorWalkers = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_PLANESWALKER, CardPrinted.FN_GET_RULES));
|
||||
Iterable<CardPrinted> onColorWalkers = Iterables.filter(colorList, Predicates.compose(CardRulesPredicates.Presets.IS_PLANESWALKER, CardPrinted.FN_GET_RULES));
|
||||
List<CardPrinted> 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<CardPrinted> others = Iterables.filter(aiPlayables, Predicates.compose(CardRules.Predicates.Presets.IS_NON_LAND, CardPrinted.FN_GET_RULES));
|
||||
Iterable<CardPrinted> others = Iterables.filter(aiPlayables, Predicates.compose(CardRulesPredicates.Presets.IS_NON_LAND, CardPrinted.FN_GET_RULES));
|
||||
List<Pair<Double, CardPrinted>> ranked = rankCards(others);
|
||||
for (Pair<Double, CardPrinted> bean : ranked) {
|
||||
if (nCards > 0) {
|
||||
@@ -577,7 +578,7 @@ public class LimitedDeck {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
creatureCosts.put(i, 0);
|
||||
}
|
||||
Predicate<CardPrinted> filter = Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES);
|
||||
Predicate<CardPrinted> 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) {
|
||||
|
||||
@@ -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<CardRules> 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;
|
||||
|
||||
@@ -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 <T extends InventoryItem> void setStats(final ItemPoolView<T> 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()
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<CardPrinted> 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<Predicate<CardPrinted>> subands = new ArrayList<Predicate<CardPrinted>>();
|
||||
|
||||
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<CardPrinted> 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<Predicate<CardPrinted>> subnots = new ArrayList<Predicate<CardPrinted>>();
|
||||
|
||||
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<CardPrinted> pName = Predicates.compose(CardRulesPredicates.name(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES);
|
||||
subnots.add(pName);
|
||||
}
|
||||
if (useType) {
|
||||
final Predicate<CardPrinted> pType = Predicates.compose(CardRulesPredicates.joinedType(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES);
|
||||
subnots.add(pType);
|
||||
}
|
||||
if (useText) {
|
||||
final Predicate<CardPrinted> pRules = Predicates.compose(CardRulesPredicates.rules(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES);
|
||||
subnots.add(pRules);
|
||||
}
|
||||
|
||||
nots.add(Predicates.or(subnots));
|
||||
Predicate<CardPrinted> mavenCompilerIsBugged = Predicates.or(subnots);
|
||||
nots.add(mavenCompilerIsBugged);
|
||||
}
|
||||
|
||||
filterNot = Predicates.not(Predicates.or(nots));
|
||||
Predicate<CardPrinted> iWouldNotWriteThisIfMavenProcessedGenericsCorrectly = Predicates.or(nots);
|
||||
filterNot = Predicates.not(iWouldNotWriteThisIfMavenProcessedGenericsCorrectly);
|
||||
}
|
||||
|
||||
return Predicates.and(filterAnd, filterNot);
|
||||
}
|
||||
|
||||
@@ -401,7 +413,7 @@ public class SFilterUtil {
|
||||
final Predicate<CardPrinted> 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<CardPrinted> 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<CardPrinted> 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<CardPrinted> 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CardPrinted> notBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND,CardPrinted.FN_GET_RULES));
|
||||
Predicate<CardPrinted> notBasicLand = Predicates.not(Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND,CardPrinted.FN_GET_RULES));
|
||||
Iterable<CardPrinted> source = Iterables.filter(CardDb.instance().getAllUniqueCards(), notBasicLand);
|
||||
randomDeck.getMain().addAllFlat(Aggregates.random(source, 15*5));
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<CardPrinted> getRandomBasicLands(final String setCode, final int count) {
|
||||
Predicate<CardPrinted> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Predicate<CardRules>> colorFilters = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardPrinted> 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<CardPrinted> pCommon = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_COMMON);
|
||||
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, pCommon, numCommon, colorFilters));
|
||||
|
||||
final Predicate<CardPrinted> pUncommon = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_UNCOMMON);
|
||||
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, pUncommon, numUncommon, colorFilters));
|
||||
|
||||
int nRares = numRare, nMythics = 0;
|
||||
final Predicate<CardPrinted> filterMythics = Predicates.and(filter,
|
||||
CardPrinted.Predicates.Presets.IS_MYTHIC_RARE);
|
||||
final Predicate<CardPrinted> 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<CardPrinted> 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<CardRules> 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<BoosterGenerator, List<CardPrinted>> openWay = new Function<BoosterGenerator, List<CardPrinted>>() {
|
||||
@@ -257,6 +258,7 @@ public final class BoosterUtils {
|
||||
}
|
||||
};
|
||||
Predicate<CardPrinted> colorPred = Predicates.compose(col, CardPrinted.FN_GET_RULES);
|
||||
return new UnOpenedProduct(openWay, new BoosterGenerator(Predicates.and(rar, colorPred))); // qty))
|
||||
Predicate<CardPrinted> rarAndColor = Predicates.and(rar, colorPred);
|
||||
return new UnOpenedProduct(openWay, new BoosterGenerator(rarAndColor)); // qty))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,9 +101,12 @@ public final class QuestUtilCards {
|
||||
final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES);
|
||||
|
||||
final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
|
||||
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<CardPrinted> predCommons = Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON);
|
||||
newCards.addAll(BoosterUtils.generateDistinctCards(predCommons, nCommon));
|
||||
Predicate<CardPrinted> predUncommons = Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON);
|
||||
newCards.addAll(BoosterUtils.generateDistinctCards(predUncommons, nUncommon));
|
||||
Predicate<CardPrinted> predRareMythics = Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC);
|
||||
newCards.addAll(BoosterUtils.generateDistinctCards(predRareMythics, nRare));
|
||||
|
||||
this.addAllCards(newCards);
|
||||
return newCards;
|
||||
|
||||
Reference in New Issue
Block a user