mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
Tests: added check that filter card must not contain controller predicate;
This commit is contained in:
parent
8a7f31b215
commit
69e52815b6
1 changed files with 14 additions and 4 deletions
|
@ -1,10 +1,8 @@
|
|||
package mage.filter;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.filter.predicate.ObjectPlayer;
|
||||
import mage.filter.predicate.ObjectPlayerPredicate;
|
||||
import mage.filter.predicate.ObjectSourcePlayer;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.predicate.*;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -71,6 +69,9 @@ public class FilterCard extends FilterObject<Card> {
|
|||
if (isLockedFilter()) {
|
||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
||||
}
|
||||
|
||||
checkPredicateIsSuitableForCardFilter(predicate);
|
||||
|
||||
extraPredicates.add(predicate);
|
||||
}
|
||||
|
||||
|
@ -86,4 +87,13 @@ public class FilterCard extends FilterObject<Card> {
|
|||
public FilterCard copy() {
|
||||
return new FilterCard(this);
|
||||
}
|
||||
|
||||
public static void checkPredicateIsSuitableForCardFilter(Predicate predicate) {
|
||||
// card filter can't contain controller predicate (only permanents on battlefield have controller)
|
||||
List<Predicate> list = new ArrayList<>();
|
||||
Predicates.collectAllComponents(predicate, list);
|
||||
if (list.stream().anyMatch(p -> p instanceof TargetController.ControllerPredicate)) {
|
||||
throw new IllegalArgumentException("Card filter doesn't support controller predicate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue