mirror of
https://github.com/correl/mage.git
synced 2025-01-14 03:00:10 +00:00
Merge pull request #12 from magefree/master
Merge https://github.com/magefree/mage
This commit is contained in:
commit
e772f5ea91
1 changed files with 37 additions and 12 deletions
|
@ -29,10 +29,13 @@ 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> {
|
||||||
|
@ -61,31 +64,53 @@ 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()) {
|
||||||
found = ((SplitCard) input).getLeftHalfCard().getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase()));
|
for (String rule : ((SplitCard) input).getLeftHalfCard().getRules(game)) {
|
||||||
found |= ((SplitCard) input).getRightHalfCard().getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase()));
|
if (rule.toLowerCase().contains(token)) {
|
||||||
|
found = true;
|
||||||
} else {
|
break;
|
||||||
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) {
|
||||||
found |= input.getSubtype(game).stream().anyMatch(s -> s.toString().equalsIgnoreCase(token));
|
for (SubType subType : input.getSubtype(game)) {
|
||||||
found |= input.getSuperType().stream().anyMatch(s -> s.toString().equalsIgnoreCase(token));
|
if (subType.toString().equalsIgnoreCase(token)) {
|
||||||
}
|
found = true;
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for (SuperType superType : input.getSuperType()) {
|
||||||
|
if (superType.toString().equalsIgnoreCase(token)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue