Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion forge-core/src/main/java/forge/card/CardFacePredicates.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public boolean test(ICardFace input) {
} else if (!input.getType().hasStringType(k[0])) {
return false;
}

if (k.length > 1) {
for (final String m : k[1].split("\\+")) {
if (m.contains("ManaCost")) {
Expand All @@ -102,7 +103,32 @@ public boolean test(ICardFace input) {
}
} else if (m.contains("cmcEQ")) {
int i = Integer.parseInt(m.substring(5));
if (!hasCMC(input, i)) return false;
if (!hasCMC(input, i)) {
return false;
}
} else if (m.contains("White") ||
m.contains("Blue") ||
m.contains("Black") ||
m.contains("Red") ||
m.contains("Green")) {
boolean mustHave = !m.startsWith("non");
final String colorName = m.substring(mustHave ? 0 : 3);

if (mustHave != hasColor(input, colorName)) {
return false;
}
} else if (m.contains("Colorless")) {
boolean mustBe = !m.startsWith("non");

if (mustBe != input.getColor().isColorless()) {
return false;
}
} else if (m.contains("MultiColor")) {
boolean mustBe = !m.startsWith("non");

if (mustBe != input.getColor().isMulticolor()) {
return false;
}
} else if (!hasProperty(input, m)) {
return false;
}
Expand All @@ -127,6 +153,10 @@ static protected boolean hasCMC(ICardFace input, final int value) {
return cost != null && cost.getCMC() == value;
}

static protected boolean hasColor(ICardFace input, final String colorName) {
int desiredColor = MagicColor.fromName(colorName);
return input.getColor().hasAnyColor(desiredColor);
}
}

public static Predicate<ICardFace> valid(final String val) {
Expand Down