update cardtextpredicate

This commit is contained in:
igoudt 2017-09-30 00:07:25 +02:00
parent 61f14ea97a
commit 7c34dad8cb

View file

@ -29,13 +29,10 @@ package mage.filter.predicate.other;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.SplitCard; import mage.cards.SplitCard;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.filter.predicate.Predicate; import mage.filter.predicate.Predicate;
import mage.game.Game; import mage.game.Game;
/** /**
*
* @author North * @author North
*/ */
public class CardTextPredicate implements Predicate<Card> { public class CardTextPredicate implements Predicate<Card> {
@ -64,53 +61,31 @@ public class CardTextPredicate implements Predicate<Card> {
//separate by spaces //separate by spaces
String[] tokens = text.toLowerCase().split(" "); String[] tokens = text.toLowerCase().split(" ");
boolean found = false;
for (String token : tokens) { for (String token : tokens) {
boolean found = false;
if (!token.isEmpty()) { if (!token.isEmpty()) {
// then try to find in rules // then try to find in rules
if (inRules) { if (inRules) {
if (input.isSplitCard()) { if (input.isSplitCard()) {
for (String rule : ((SplitCard) input).getLeftHalfCard().getRules(game)) { found = ((SplitCard) input).getLeftHalfCard().getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase()));
if (rule.toLowerCase().contains(token)) { found |= ((SplitCard) input).getRightHalfCard().getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase()));
found = true;
break; } else {
} found = input.getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase()));
}
for (String rule : ((SplitCard) input).getRightHalfCard().getRules(game)) {
if (rule.toLowerCase().contains(token)) {
found = true;
break;
}
}
}
for (String rule : input.getRules(game)) {
if (rule.toLowerCase().contains(token)) {
found = true;
break;
}
} }
} }
if (inTypes) { if (inTypes) {
for (SubType subType : input.getSubtype(game)) { found |= input.getSubtype(game).stream().anyMatch(s -> s.toString().equalsIgnoreCase(token));
if (subType.toString().equalsIgnoreCase(token)) { found |= input.getSuperType().stream().anyMatch(s -> s.toString().equalsIgnoreCase(token));
found = true;
break;
}
}
for (SuperType superType : input.getSuperType()) {
if (superType.toString().equalsIgnoreCase(token)) {
found = true;
break;
}
}
} }
} }
if (!found) { if (found) {
return false; break;
} }
} }
return true; return found;
} }
@Override @Override