mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
Merge 141d78a158 into acc180d1d4
This commit is contained in:
commit
b49b580ac4
24 changed files with 392 additions and 411 deletions
|
|
@ -10,7 +10,6 @@ import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
|
||||||
import mage.filter.common.FilterSpellOrPermanent;
|
import mage.filter.common.FilterSpellOrPermanent;
|
||||||
import mage.target.common.TargetCreatureOrPlaneswalker;
|
import mage.target.common.TargetCreatureOrPlaneswalker;
|
||||||
import mage.target.common.TargetSpellOrPermanent;
|
import mage.target.common.TargetSpellOrPermanent;
|
||||||
|
|
@ -26,7 +25,7 @@ public final class BrutalExpulsion extends CardImpl {
|
||||||
private static final FilterSpellOrPermanent filter = new FilterSpellOrPermanent("spell or creature");
|
private static final FilterSpellOrPermanent filter = new FilterSpellOrPermanent("spell or creature");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
filter.setPermanentFilter(new FilterCreaturePermanent());
|
filter.getPermanentFilter().add(CardType.CREATURE.getPredicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrutalExpulsion(UUID ownerId, CardSetInfo setInfo) {
|
public BrutalExpulsion(UUID ownerId, CardSetInfo setInfo) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
package mage.cards.c;
|
package mage.cards.c;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
|
@ -13,16 +12,17 @@ import mage.cards.SplitCard;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.SpellAbilityType;
|
import mage.constants.SpellAbilityType;
|
||||||
import mage.filter.common.FilterNonlandPermanent;
|
|
||||||
import mage.filter.common.FilterSpellOrPermanent;
|
import mage.filter.common.FilterSpellOrPermanent;
|
||||||
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.common.TargetSpellOrPermanent;
|
import mage.target.common.TargetSpellOrPermanent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author fireshoes
|
* @author fireshoes
|
||||||
*/
|
*/
|
||||||
public final class CommitMemory extends SplitCard {
|
public final class CommitMemory extends SplitCard {
|
||||||
|
|
@ -30,7 +30,7 @@ public final class CommitMemory extends SplitCard {
|
||||||
private static final FilterSpellOrPermanent filter = new FilterSpellOrPermanent("spell or nonland permanent");
|
private static final FilterSpellOrPermanent filter = new FilterSpellOrPermanent("spell or nonland permanent");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
filter.setPermanentFilter(new FilterNonlandPermanent());
|
filter.getPermanentFilter().add(Predicates.not(CardType.LAND.getPredicate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommitMemory(UUID ownerId, CardSetInfo setInfo) {
|
public CommitMemory(UUID ownerId, CardSetInfo setInfo) {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
|
|
||||||
package mage.cards.u;
|
package mage.cards.u;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.abilities.effects.common.ReturnToHandTargetEffect;
|
import mage.abilities.effects.common.ReturnToHandTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
|
||||||
import mage.filter.common.FilterSpellOrPermanent;
|
import mage.filter.common.FilterSpellOrPermanent;
|
||||||
import mage.target.common.TargetSpellOrPermanent;
|
import mage.target.common.TargetSpellOrPermanent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author fireshoes
|
* @author fireshoes
|
||||||
*/
|
*/
|
||||||
public final class Unsubstantiate extends CardImpl {
|
public final class Unsubstantiate extends CardImpl {
|
||||||
|
|
@ -19,11 +18,11 @@ public final class Unsubstantiate extends CardImpl {
|
||||||
private static final FilterSpellOrPermanent filter = new FilterSpellOrPermanent("spell or creature");
|
private static final FilterSpellOrPermanent filter = new FilterSpellOrPermanent("spell or creature");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
filter.setPermanentFilter(new FilterCreaturePermanent());
|
filter.getPermanentFilter().add(CardType.CREATURE.getPredicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Unsubstantiate(UUID ownerId, CardSetInfo setInfo) {
|
public Unsubstantiate(UUID ownerId, CardSetInfo setInfo) {
|
||||||
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{U}");
|
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}");
|
||||||
|
|
||||||
// Return target spell or creature to its owner's hand.
|
// Return target spell or creature to its owner's hand.
|
||||||
this.getSpellAbility().addTarget(new TargetSpellOrPermanent(1, 1, filter, false));
|
this.getSpellAbility().addTarget(new TargetSpellOrPermanent(1, 1, filter, false));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
import mage.filter.predicate.Predicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.util.Copyable;
|
import mage.util.Copyable;
|
||||||
|
|
@ -7,6 +9,7 @@ import mage.util.Copyable;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <E>
|
* @param <E>
|
||||||
|
|
@ -21,8 +24,25 @@ public interface Filter<E> extends Serializable, Copyable<Filter<E>> {
|
||||||
|
|
||||||
boolean match(E o, Game game);
|
boolean match(E o, Game game);
|
||||||
|
|
||||||
|
boolean match(E object, UUID sourceControllerId, Ability source, Game game);
|
||||||
|
|
||||||
Filter<E> add(Predicate<? super E> predicate);
|
Filter<E> add(Predicate<? super E> predicate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure on setting a new Filter that you overwrite this method
|
||||||
|
* and call Predicates.makeSurePredicateCompatibleWithFilter
|
||||||
|
* to check that the filter is able to process objects
|
||||||
|
* of the right kind. Helps with checks the Compiler can't do
|
||||||
|
* due to ObjectSourcePlayer casting in the this.match(4 arguments).
|
||||||
|
* <p>
|
||||||
|
* (method should then call this.addExtra(predicate) after verify checks)
|
||||||
|
*/
|
||||||
|
Filter<E> add(ObjectSourcePlayerPredicate predicate);
|
||||||
|
|
||||||
|
// TODO: if someone can find a way to not have to add this
|
||||||
|
// Compiler was confused between overloads
|
||||||
|
void addExtra(ObjectSourcePlayerPredicate predicate);
|
||||||
|
|
||||||
boolean checkObjectClass(Object object);
|
boolean checkObjectClass(Object object);
|
||||||
|
|
||||||
String getMessage();
|
String getMessage();
|
||||||
|
|
@ -31,13 +51,13 @@ public interface Filter<E> extends Serializable, Copyable<Filter<E>> {
|
||||||
|
|
||||||
Filter<E> copy();
|
Filter<E> copy();
|
||||||
|
|
||||||
public boolean isLockedFilter();
|
boolean isLockedFilter();
|
||||||
|
|
||||||
public void setLockedFilter(boolean lockedFilter);
|
void setLockedFilter(boolean lockedFilter);
|
||||||
|
|
||||||
List<Predicate<? super E>> getPredicates();
|
List<Predicate<? super E>> getPredicates();
|
||||||
|
|
||||||
default List<Predicate> getExtraPredicates() {
|
default List<ObjectSourcePlayerPredicate<E>> getExtraPredicates() {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ package mage.filter;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.AbilityType;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
import mage.filter.predicate.Predicate;
|
||||||
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.stack.StackObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author North
|
* @author North
|
||||||
*/
|
*/
|
||||||
public class FilterAbility extends FilterImpl<Ability> {
|
public class FilterAbility extends FilterImpl<Ability> {
|
||||||
|
|
@ -38,6 +40,14 @@ public class FilterAbility extends FilterImpl<Ability> {
|
||||||
return new AbilityTypePredicate(type);
|
return new AbilityTypePredicate(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FilterAbility add(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
// Verify Checks
|
||||||
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Ability.class, StackObject.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkObjectClass(Object object) {
|
public boolean checkObjectClass(Object object) {
|
||||||
return object instanceof Ability;
|
return object instanceof Ability;
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,14 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.constants.TargetController;
|
import mage.constants.TargetController;
|
||||||
import mage.filter.predicate.ObjectSourcePlayer;
|
|
||||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
import mage.filter.predicate.Predicate;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Works with cards only. For objects like commanders you must override your canTarget method.
|
* Works with cards only. For objects like commanders you must override your canTarget method.
|
||||||
|
|
@ -23,7 +19,6 @@ import java.util.UUID;
|
||||||
public class FilterCard extends FilterObject<Card> {
|
public class FilterCard extends FilterObject<Card> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
protected final List<ObjectSourcePlayerPredicate<Card>> extraPredicates = new ArrayList<>();
|
|
||||||
|
|
||||||
public FilterCard() {
|
public FilterCard() {
|
||||||
super("card");
|
super("card");
|
||||||
|
|
@ -46,48 +41,6 @@ public class FilterCard extends FilterObject<Card> {
|
||||||
|
|
||||||
protected FilterCard(final FilterCard filter) {
|
protected FilterCard(final FilterCard filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.extraPredicates.addAll(filter.extraPredicates);
|
|
||||||
}
|
|
||||||
|
|
||||||
//20130711 708.6c
|
|
||||||
/* If anything performs a comparison involving multiple characteristics or
|
|
||||||
* values of one or more split cards in any zone other than the stack or
|
|
||||||
* involving multiple characteristics or values of one or more fused split
|
|
||||||
* spells, each characteristic or value is compared separately. If each of
|
|
||||||
* the individual comparisons would return a “yes” answer, the whole
|
|
||||||
* comparison returns a “yes” answer. The individual comparisons may involve
|
|
||||||
* different halves of the same split card.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean match(Card card, Game game) {
|
|
||||||
if (card == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super.match(card, game);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean match(Card card, UUID playerId, Ability source, Game game) {
|
|
||||||
if (!this.match(card, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ObjectSourcePlayer<Card> osp = new ObjectSourcePlayer<>(card, playerId, source);
|
|
||||||
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void add(ObjectSourcePlayerPredicate predicate) {
|
|
||||||
if (isLockedFilter()) {
|
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify check
|
|
||||||
checkPredicateIsSuitableForCardFilter(predicate);
|
|
||||||
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Card.class);
|
|
||||||
|
|
||||||
extraPredicates.add(predicate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPredicates() {
|
|
||||||
return !predicates.isEmpty() || !extraPredicates.isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -95,13 +48,8 @@ public class FilterCard extends FilterObject<Card> {
|
||||||
return new FilterCard(this);
|
return new FilterCard(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Predicate> getExtraPredicates() {
|
|
||||||
return new ArrayList<>(extraPredicates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void checkPredicateIsSuitableForCardFilter(Predicate predicate) {
|
public static void checkPredicateIsSuitableForCardFilter(Predicate predicate) {
|
||||||
// card filter can't contain controller predicate (only permanents on battlefield have controller)
|
// card filter can't contain controller predicate (only permanents on battlefield and StackObjects have controller)
|
||||||
List<Predicate> list = new ArrayList<>();
|
List<Predicate> list = new ArrayList<>();
|
||||||
Predicates.collectAllComponents(predicate, list);
|
Predicates.collectAllComponents(predicate, list);
|
||||||
if (list.stream().anyMatch(TargetController.ControllerPredicate.class::isInstance)) {
|
if (list.stream().anyMatch(TargetController.ControllerPredicate.class::isInstance)) {
|
||||||
|
|
@ -109,8 +57,26 @@ public class FilterCard extends FilterObject<Card> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FilterCard withMessage(String message) {
|
public FilterCard withMessage(String message) {
|
||||||
this.setMessage(message);
|
this.setMessage(message);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FilterCard add(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
// verify checks
|
||||||
|
checkPredicateIsSuitableForCardFilter(predicate);
|
||||||
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Card.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkObjectClass(Object object) {
|
||||||
|
// TODO: investigate if we can/should exclude Permanent here.
|
||||||
|
// as it does extend Card (if so do cleanup the
|
||||||
|
// MultiFilterImpl that match Permanent and Card/Spell)
|
||||||
|
return object instanceof Card;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayer;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
import mage.filter.predicate.Predicate;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <E>
|
* @param <E>
|
||||||
|
|
@ -14,7 +18,8 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public abstract class FilterImpl<E> implements Filter<E> {
|
public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
|
|
||||||
protected List<Predicate<? super E>> predicates = new ArrayList<>();
|
private List<Predicate<? super E>> predicates = new ArrayList<>();
|
||||||
|
private List<ObjectSourcePlayerPredicate<E>> extraPredicates = new ArrayList<>();
|
||||||
protected String message;
|
protected String message;
|
||||||
protected boolean lockedFilter; // Helps to prevent "accidentally" modifying the StaticFilters objects
|
protected boolean lockedFilter; // Helps to prevent "accidentally" modifying the StaticFilters objects
|
||||||
|
|
||||||
|
|
@ -29,6 +34,7 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
protected FilterImpl(final FilterImpl<E> filter) {
|
protected FilterImpl(final FilterImpl<E> filter) {
|
||||||
this.message = filter.message;
|
this.message = filter.message;
|
||||||
this.predicates = new ArrayList<>(filter.predicates);
|
this.predicates = new ArrayList<>(filter.predicates);
|
||||||
|
this.extraPredicates = new ArrayList<>(filter.extraPredicates);
|
||||||
this.lockedFilter = false;// After copying a filter it's allowed to modify
|
this.lockedFilter = false;// After copying a filter it's allowed to modify
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,14 +47,27 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Filter<E> add(Predicate<? super E> predicate) {
|
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
if (isLockedFilter()) {
|
if (!this.match(object, game)) {
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
return false;
|
||||||
}
|
}
|
||||||
|
ObjectSourcePlayer osp = new ObjectSourcePlayer<>(object, sourceControllerId, source);
|
||||||
|
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Filter<E> add(Predicate<? super E> predicate) {
|
||||||
|
checkUnlockedFilter();
|
||||||
predicates.add(predicate);
|
predicates.add(predicate);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void addExtra(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
checkUnlockedFilter();
|
||||||
|
extraPredicates.add(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
|
|
@ -56,10 +75,14 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setMessage(String message) {
|
public final void setMessage(String message) {
|
||||||
|
checkUnlockedFilter();
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkUnlockedFilter() {
|
||||||
if (isLockedFilter()) {
|
if (isLockedFilter()) {
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
throw new UnsupportedOperationException("You may not modify a locked filter");
|
||||||
}
|
}
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -80,4 +103,12 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
public List<Predicate<? super E>> getPredicates() {
|
public List<Predicate<? super E>> getPredicates() {
|
||||||
return predicates;
|
return predicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ObjectSourcePlayerPredicate<E>> getExtraPredicates() {
|
||||||
|
return new ArrayList<>(extraPredicates);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPredicates() {
|
||||||
|
return !predicates.isEmpty() || !extraPredicates.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
package mage.filter;
|
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.game.Game;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param <E>
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
|
||||||
*/
|
|
||||||
public interface FilterInPlay<E> extends Filter<E> {
|
|
||||||
|
|
||||||
boolean match(E o, UUID playerId, Ability source, Game game);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
FilterInPlay<E> copy();
|
|
||||||
}
|
|
||||||
|
|
@ -7,6 +7,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO: Not really a Filter. Should be renamed?
|
||||||
|
*
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
*/
|
*/
|
||||||
public class FilterMana implements Serializable {
|
public class FilterMana implements Serializable {
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,17 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
|
import mage.filter.predicate.Predicates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* // TODO: migrate all FilterObject to more specific ones, then remove this class?
|
||||||
*
|
*
|
||||||
* @author North
|
|
||||||
* @param <E>
|
* @param <E>
|
||||||
|
* @author North
|
||||||
*/
|
*/
|
||||||
public class FilterObject<E extends MageObject> extends FilterImpl<E> {
|
public class FilterObject<E extends MageObject> extends FilterImpl<E> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public FilterObject<E> copy() {
|
|
||||||
return new FilterObject<>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkObjectClass(Object object) {
|
|
||||||
return object instanceof MageObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterObject(String name) {
|
public FilterObject(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
@ -27,4 +20,22 @@ public class FilterObject<E extends MageObject> extends FilterImpl<E> {
|
||||||
protected FilterObject(final FilterObject<E> filter) {
|
protected FilterObject(final FilterObject<E> filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FilterObject<E> copy() {
|
||||||
|
return new FilterObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FilterObject<E> add(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
// verify checks
|
||||||
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, MageObject.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkObjectClass(Object object) {
|
||||||
|
return object instanceof MageObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,18 @@ package mage.filter;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.filter.predicate.ObjectSourcePlayer;
|
|
||||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author North
|
* @author North
|
||||||
*/
|
*/
|
||||||
public class FilterPermanent extends FilterObject<Permanent> implements FilterInPlay<Permanent> {
|
public class FilterPermanent extends FilterObject<Permanent> {
|
||||||
|
|
||||||
protected final List<ObjectSourcePlayerPredicate<Permanent>> extraPredicates = new ArrayList<>();
|
|
||||||
|
|
||||||
public FilterPermanent() {
|
public FilterPermanent() {
|
||||||
super("permanent");
|
super("permanent");
|
||||||
|
|
@ -43,32 +37,6 @@ public class FilterPermanent extends FilterObject<Permanent> implements FilterIn
|
||||||
|
|
||||||
protected FilterPermanent(final FilterPermanent filter) {
|
protected FilterPermanent(final FilterPermanent filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.extraPredicates.addAll(filter.extraPredicates);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkObjectClass(Object object) {
|
|
||||||
return object instanceof Permanent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean match(Permanent permanent, UUID playerId, Ability source, Game game) {
|
|
||||||
if (!this.match(permanent, game) || !permanent.isPhasedIn()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ObjectSourcePlayer<Permanent> osp = new ObjectSourcePlayer<>(permanent, playerId, source);
|
|
||||||
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void add(ObjectSourcePlayerPredicate predicate) {
|
|
||||||
if (isLockedFilter()) {
|
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify check
|
|
||||||
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Permanent.class);
|
|
||||||
|
|
||||||
extraPredicates.add(predicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -77,7 +45,31 @@ public class FilterPermanent extends FilterObject<Permanent> implements FilterIn
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Predicate> getExtraPredicates() {
|
public FilterPermanent add(ObjectSourcePlayerPredicate predicate) {
|
||||||
return new ArrayList<>(extraPredicates);
|
// verify checks
|
||||||
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Permanent.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(Permanent permanent, Game game) {
|
||||||
|
// TODO: if we can trust the target/checks using FilterPermanent to filter out Phased out permanent,
|
||||||
|
// this overload would be no longer necessary.
|
||||||
|
return super.match(permanent, game)
|
||||||
|
&& permanent.isPhasedIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(Permanent permanent, UUID sourceControllerId, Ability source, Game game) {
|
||||||
|
// TODO: if we can trust the target/checks using FilterPermanent to filter out Phased out permanent,
|
||||||
|
// this overload would be no longer necessary.
|
||||||
|
return super.match(permanent, sourceControllerId, source, game)
|
||||||
|
&& permanent.isPhasedIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkObjectClass(Object object) {
|
||||||
|
return object instanceof Permanent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,15 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.filter.predicate.ObjectSourcePlayer;
|
|
||||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
* @author North
|
* @author North
|
||||||
*/
|
*/
|
||||||
public class FilterPlayer extends FilterImpl<Player> {
|
public class FilterPlayer extends FilterImpl<Player> {
|
||||||
|
|
||||||
protected final List<ObjectSourcePlayerPredicate<Player>> extraPredicates = new ArrayList<>();
|
|
||||||
|
|
||||||
public FilterPlayer() {
|
public FilterPlayer() {
|
||||||
this("player");
|
this("player");
|
||||||
}
|
}
|
||||||
|
|
@ -30,32 +20,6 @@ public class FilterPlayer extends FilterImpl<Player> {
|
||||||
|
|
||||||
protected FilterPlayer(final FilterPlayer filter) {
|
protected FilterPlayer(final FilterPlayer filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.extraPredicates.addAll(filter.extraPredicates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterPlayer add(ObjectSourcePlayerPredicate predicate) {
|
|
||||||
if (isLockedFilter()) {
|
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify check
|
|
||||||
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Player.class);
|
|
||||||
|
|
||||||
extraPredicates.add(predicate);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkObjectClass(Object object) {
|
|
||||||
return object instanceof Player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean match(Player checkPlayer, UUID sourceControllerId, Ability source, Game game) {
|
|
||||||
if (!this.match(checkPlayer, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ObjectSourcePlayer<Player> osp = new ObjectSourcePlayer<>(checkPlayer, sourceControllerId, source);
|
|
||||||
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -64,7 +28,15 @@ public class FilterPlayer extends FilterImpl<Player> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Predicate> getExtraPredicates() {
|
public FilterPlayer add(ObjectSourcePlayerPredicate predicate) {
|
||||||
return new ArrayList<>(extraPredicates);
|
// verify checks
|
||||||
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Player.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkObjectClass(Object object) {
|
||||||
|
return object instanceof Player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,18 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.filter.predicate.ObjectSourcePlayer;
|
|
||||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.command.CommandObject;
|
import mage.game.command.CommandObject;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Susucr
|
* @author Susucr
|
||||||
*/
|
*/
|
||||||
public class FilterSource extends FilterObject<MageObject> {
|
public class FilterSource extends FilterObject<MageObject> {
|
||||||
|
|
||||||
protected final List<ObjectSourcePlayerPredicate<MageObject>> extraPredicates = new ArrayList<>();
|
|
||||||
|
|
||||||
public FilterSource() {
|
public FilterSource() {
|
||||||
super("source");
|
super("source");
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +24,6 @@ public class FilterSource extends FilterObject<MageObject> {
|
||||||
|
|
||||||
private FilterSource(final FilterSource filter) {
|
private FilterSource(final FilterSource filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.extraPredicates.addAll(filter.extraPredicates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -42,15 +31,12 @@ public class FilterSource extends FilterObject<MageObject> {
|
||||||
return new FilterSource(this);
|
return new FilterSource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public FilterSource add(ObjectSourcePlayerPredicate predicate) {
|
public FilterSource add(ObjectSourcePlayerPredicate predicate) {
|
||||||
if (isLockedFilter()) {
|
// verify checks
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
// A source can be a lot of different things, so a variety of predicates can be fed here
|
||||||
}
|
|
||||||
|
|
||||||
// verify check -- make sure predicates work with all 3 Class that could be a Source
|
|
||||||
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Permanent.class, Card.class, StackObject.class, CommandObject.class);
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, Permanent.class, Card.class, StackObject.class, CommandObject.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
extraPredicates.add(predicate);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,17 +47,4 @@ public class FilterSource extends FilterObject<MageObject> {
|
||||||
|| object instanceof StackObject
|
|| object instanceof StackObject
|
||||||
|| object instanceof CommandObject;
|
|| object instanceof CommandObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
|
|
||||||
if (!this.match(object, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ObjectSourcePlayer<MageObject> osp = new ObjectSourcePlayer<>(object, sourceControllerId, source);
|
|
||||||
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Predicate> getExtraPredicates() {
|
|
||||||
return new ArrayList<>(extraPredicates);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
|
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import java.util.UUID;
|
import mage.cards.Card;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.game.stack.StackObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author North, Quercitron
|
* @author North, Quercitron
|
||||||
|
|
@ -26,11 +22,9 @@ public class FilterSpell extends FilterStackObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(StackObject stackObject, UUID playerId, Ability source, Game game) {
|
public boolean checkObjectClass(Object object) {
|
||||||
if (!(stackObject instanceof Spell)) {
|
return object instanceof Spell
|
||||||
return false;
|
|| object instanceof Card; // TODO: investigate. Is sometimes used for checking a spell's characteristic before cast
|
||||||
}
|
|
||||||
return super.match(stackObject, playerId, source, game);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,16 @@
|
||||||
package mage.filter;
|
package mage.filter;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.filter.predicate.ObjectSourcePlayer;
|
|
||||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicate;
|
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author North
|
* @author North
|
||||||
*/
|
*/
|
||||||
public class FilterStackObject extends FilterObject<StackObject> {
|
public class FilterStackObject extends FilterObject<StackObject> {
|
||||||
|
|
||||||
protected final List<ObjectSourcePlayerPredicate<StackObject>> extraPredicates = new ArrayList<>();
|
|
||||||
|
|
||||||
public FilterStackObject() {
|
public FilterStackObject() {
|
||||||
this("spell or ability");
|
this("spell or ability");
|
||||||
|
|
@ -31,27 +22,6 @@ public class FilterStackObject extends FilterObject<StackObject> {
|
||||||
|
|
||||||
protected FilterStackObject(final FilterStackObject filter) {
|
protected FilterStackObject(final FilterStackObject filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.extraPredicates.addAll(filter.extraPredicates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean match(StackObject stackObject, UUID playerId, Ability source, Game game) {
|
|
||||||
if (!this.match(stackObject, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ObjectSourcePlayer<StackObject> osp = new ObjectSourcePlayer<>(stackObject, playerId, source);
|
|
||||||
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void add(ObjectSourcePlayerPredicate predicate) {
|
|
||||||
if (isLockedFilter()) {
|
|
||||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify check
|
|
||||||
// Spell implements Card interface, so it can use some default predicates like owner
|
|
||||||
Predicates.makeSurePredicateCompatibleWithFilter(predicate, StackObject.class, Spell.class, Card.class);
|
|
||||||
|
|
||||||
extraPredicates.add(predicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -60,7 +30,17 @@ public class FilterStackObject extends FilterObject<StackObject> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Predicate> getExtraPredicates() {
|
public final FilterStackObject add(ObjectSourcePlayerPredicate predicate) {
|
||||||
return new ArrayList<>(extraPredicates);
|
// verify checks
|
||||||
|
// Spell implements Card interface, so it can use some default predicates like owner
|
||||||
|
Predicates.makeSurePredicateCompatibleWithFilter(predicate, StackObject.class, Spell.class, Card.class);
|
||||||
|
this.addExtra(predicate);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkObjectClass(Object object) {
|
||||||
|
return object instanceof StackObject
|
||||||
|
|| object instanceof Card; // TODO: investigate. Is sometimes used for checking a spell's characteristic before cast
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
133
Mage/src/main/java/mage/filter/MultiFilterImpl.java
Normal file
133
Mage/src/main/java/mage/filter/MultiFilterImpl.java
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
package mage.filter;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
|
import mage.filter.predicate.Predicate;
|
||||||
|
import mage.game.Game;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a Filter out of multiple inner filters.
|
||||||
|
* If making a multi filter out of filterA and filterB,
|
||||||
|
* any object match the multi filter if it either match
|
||||||
|
* filterA or match filterB.
|
||||||
|
*
|
||||||
|
* @author Susucr
|
||||||
|
*/
|
||||||
|
public abstract class MultiFilterImpl<E> implements Filter<E> {
|
||||||
|
|
||||||
|
protected List<Filter<? extends E>> innerFilters = new ArrayList<>();
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract MultiFilterImpl<E> copy();
|
||||||
|
|
||||||
|
protected MultiFilterImpl(String name, Filter<? extends E>... filters) {
|
||||||
|
this.message = name;
|
||||||
|
if (filters.length < 2) {
|
||||||
|
throw new IllegalArgumentException("Wrong code usage: MultiFilterImpl should have at least 2 inner filters");
|
||||||
|
}
|
||||||
|
this.innerFilters.addAll(
|
||||||
|
Arrays.stream(filters)
|
||||||
|
.map(f -> f.copy())
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MultiFilterImpl(final MultiFilterImpl<E> filter) {
|
||||||
|
this.message = filter.message;
|
||||||
|
for (Filter<? extends E> innerFilter : filter.innerFilters) {
|
||||||
|
this.innerFilters.add(innerFilter.copy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(E object, Game game) {
|
||||||
|
return innerFilters
|
||||||
|
.stream()
|
||||||
|
.anyMatch((Filter filter) -> filter.checkObjectClass(object) && filter.match(object, game));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
|
return innerFilters
|
||||||
|
.stream()
|
||||||
|
.anyMatch((Filter filter) -> filter.checkObjectClass(object) && filter.match(object, sourceControllerId, source, game));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultiFilterImpl<E> add(Predicate<? super E> predicate) {
|
||||||
|
innerFilters.forEach((Filter filter) -> filter.add(predicate));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultiFilterImpl<E> add(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
innerFilters.forEach((Filter filter) -> filter.add(predicate));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addExtra(ObjectSourcePlayerPredicate predicate) {
|
||||||
|
innerFilters.forEach((Filter filter) -> filter.addExtra(predicate));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkObjectClass(Object object) {
|
||||||
|
return innerFilters
|
||||||
|
.stream()
|
||||||
|
.anyMatch((Filter filter) -> filter.checkObjectClass(object));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void setMessage(String message) {
|
||||||
|
if (isLockedFilter()) {
|
||||||
|
throw new UnsupportedOperationException("You may not modify a locked filter");
|
||||||
|
}
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLockedFilter() {
|
||||||
|
return innerFilters.stream().anyMatch((Filter filter) -> filter.isLockedFilter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLockedFilter(boolean lockedFilter) {
|
||||||
|
innerFilters.forEach((Filter filter) -> filter.setLockedFilter(lockedFilter));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Predicate<? super E>> getPredicates() {
|
||||||
|
List<Predicate<? super E>> predicates = new ArrayList<>();
|
||||||
|
for (Filter<? extends E> filter : innerFilters) {
|
||||||
|
for (Predicate predicate : filter.getPredicates()) {
|
||||||
|
predicates.add(predicate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return predicates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ObjectSourcePlayerPredicate<E>> getExtraPredicates() {
|
||||||
|
List<ObjectSourcePlayerPredicate<E>> predicates = new ArrayList<>();
|
||||||
|
for (Filter<? extends E> filter : innerFilters) {
|
||||||
|
for (ObjectSourcePlayerPredicate predicate : filter.getExtraPredicates()) {
|
||||||
|
predicates.add(predicate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return predicates;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ public class FilterAnyTarget extends FilterPermanentOrPlayer {
|
||||||
|
|
||||||
public FilterAnyTarget(String name) {
|
public FilterAnyTarget(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
this.permanentFilter.add(Predicates.or(
|
this.getPermanentFilter().add(Predicates.or(
|
||||||
CardType.CREATURE.getPredicate(),
|
CardType.CREATURE.getPredicate(),
|
||||||
CardType.PLANESWALKER.getPredicate(),
|
CardType.PLANESWALKER.getPredicate(),
|
||||||
CardType.BATTLE.getPredicate()
|
CardType.BATTLE.getPredicate()
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ public class FilterCreaturePlayerOrPlaneswalker extends FilterPermanentOrPlayer
|
||||||
|
|
||||||
public FilterCreaturePlayerOrPlaneswalker(String name) {
|
public FilterCreaturePlayerOrPlaneswalker(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
this.permanentFilter.add(Predicates.or(
|
this.getPermanentFilter().add(Predicates.or(
|
||||||
CardType.CREATURE.getPredicate(),
|
CardType.CREATURE.getPredicate(),
|
||||||
CardType.PLANESWALKER.getPredicate()
|
CardType.PLANESWALKER.getPredicate()
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package mage.filter.common;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.filter.predicate.other.PlayerIdPredicate;
|
import mage.filter.predicate.other.PlayerIdPredicate;
|
||||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
|
||||||
import mage.filter.predicate.permanent.PermanentIdPredicate;
|
import mage.filter.predicate.permanent.PermanentIdPredicate;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -17,17 +16,17 @@ public class FilterDefender extends FilterPermanentOrPlayer {
|
||||||
|
|
||||||
public FilterDefender(Set<UUID> defenders) {
|
public FilterDefender(Set<UUID> defenders) {
|
||||||
super("player, planeswalker, or battle to attack");
|
super("player, planeswalker, or battle to attack");
|
||||||
this.permanentFilter.add(Predicates.or(
|
this.getPermanentFilter().add(Predicates.or(
|
||||||
CardType.PLANESWALKER.getPredicate(),
|
CardType.PLANESWALKER.getPredicate(),
|
||||||
CardType.BATTLE.getPredicate()
|
CardType.BATTLE.getPredicate()
|
||||||
));
|
));
|
||||||
this.permanentFilter.add(Predicates.or(
|
this.getPermanentFilter().add(Predicates.or(
|
||||||
defenders
|
defenders
|
||||||
.stream()
|
.stream()
|
||||||
.map(PermanentIdPredicate::new)
|
.map(PermanentIdPredicate::new)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
));
|
));
|
||||||
this.playerFilter.add(Predicates.or(
|
this.getPlayerFilter().add(Predicates.or(
|
||||||
defenders
|
defenders
|
||||||
.stream()
|
.stream()
|
||||||
.map(PlayerIdPredicate::new)
|
.map(PlayerIdPredicate::new)
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,14 @@
|
||||||
package mage.filter.common;
|
package mage.filter.common;
|
||||||
|
|
||||||
import mage.MageItem;
|
import mage.MageItem;
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.filter.FilterImpl;
|
|
||||||
import mage.filter.FilterInPlay;
|
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.FilterPlayer;
|
import mage.filter.FilterPlayer;
|
||||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
import mage.filter.MultiFilterImpl;
|
||||||
import mage.filter.predicate.Predicate;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
import mage.players.Player;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
*/
|
*/
|
||||||
public class FilterPermanentOrPlayer extends FilterImpl<MageItem> implements FilterInPlay<MageItem> {
|
public class FilterPermanentOrPlayer extends MultiFilterImpl<MageItem> {
|
||||||
|
|
||||||
protected final FilterPermanent permanentFilter;
|
|
||||||
protected final FilterPlayer playerFilter;
|
|
||||||
|
|
||||||
public FilterPermanentOrPlayer() {
|
public FilterPermanentOrPlayer() {
|
||||||
this("player or permanent");
|
this("player or permanent");
|
||||||
|
|
@ -31,52 +19,11 @@ public class FilterPermanentOrPlayer extends FilterImpl<MageItem> implements Fil
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterPermanentOrPlayer(String name, FilterPermanent permanentFilter, FilterPlayer playerFilter) {
|
public FilterPermanentOrPlayer(String name, FilterPermanent permanentFilter, FilterPlayer playerFilter) {
|
||||||
super(name);
|
super(name, permanentFilter, playerFilter);
|
||||||
this.permanentFilter = permanentFilter;
|
|
||||||
this.playerFilter = playerFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FilterPermanentOrPlayer(final FilterPermanentOrPlayer filter) {
|
protected FilterPermanentOrPlayer(final FilterPermanentOrPlayer filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.permanentFilter = filter.permanentFilter.copy();
|
|
||||||
this.playerFilter = filter.playerFilter.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkObjectClass(Object object) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean match(MageItem o, Game game) {
|
|
||||||
if (super.match(o, game)) {
|
|
||||||
if (o instanceof Player) {
|
|
||||||
return playerFilter.match((Player) o, game);
|
|
||||||
} else if (o instanceof Permanent) {
|
|
||||||
return permanentFilter.match((Permanent) o, game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean match(MageItem o, UUID playerId, Ability source, Game game) {
|
|
||||||
if (super.match(o, game)) { // process predicates
|
|
||||||
if (o instanceof Player) {
|
|
||||||
return playerFilter.match((Player) o, playerId, source, game);
|
|
||||||
} else if (o instanceof Permanent) {
|
|
||||||
return permanentFilter.match((Permanent) o, playerId, source, game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterPermanent getPermanentFilter() {
|
|
||||||
return this.permanentFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterPlayer getPlayerFilter() {
|
|
||||||
return this.playerFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -84,4 +31,12 @@ public class FilterPermanentOrPlayer extends FilterImpl<MageItem> implements Fil
|
||||||
return new FilterPermanentOrPlayer(this);
|
return new FilterPermanentOrPlayer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FilterPermanent getPermanentFilter() {
|
||||||
|
return (FilterPermanent) this.innerFilters.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilterPlayer getPlayerFilter() {
|
||||||
|
return (FilterPlayer) this.innerFilters.get(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,89 +1,74 @@
|
||||||
package mage.filter.common;
|
package mage.filter.common;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.keyword.SuspendAbility;
|
import mage.abilities.keyword.SuspendAbility;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.FilterCard;
|
||||||
import mage.filter.FilterImpl;
|
|
||||||
import mage.filter.FilterInPlay;
|
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
|
import mage.filter.MultiFilterImpl;
|
||||||
import mage.filter.predicate.mageobject.AbilityPredicate;
|
import mage.filter.predicate.mageobject.AbilityPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author emerald000
|
* @author emerald000
|
||||||
*/
|
*/
|
||||||
public class FilterPermanentOrSuspendedCard extends FilterImpl<MageObject> implements FilterInPlay<MageObject> {
|
public class FilterPermanentOrSuspendedCard extends MultiFilterImpl<MageObject> {
|
||||||
|
|
||||||
protected FilterCard cardFilter;
|
|
||||||
protected FilterPermanent permanentFilter;
|
|
||||||
|
|
||||||
public FilterPermanentOrSuspendedCard() {
|
public FilterPermanentOrSuspendedCard() {
|
||||||
this("permanent or suspended card");
|
this("permanent or suspended card");
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterPermanentOrSuspendedCard(String name) {
|
public FilterPermanentOrSuspendedCard(String name) {
|
||||||
super(name);
|
super(name, new FilterPermanent(), new FilterCard());
|
||||||
permanentFilter = new FilterPermanent();
|
this.getCardFilter().add(new AbilityPredicate(SuspendAbility.class));
|
||||||
cardFilter = new FilterCard();
|
this.getCardFilter().add(CounterType.TIME.getPredicate());
|
||||||
cardFilter.add(new AbilityPredicate(SuspendAbility.class));
|
|
||||||
cardFilter.add(CounterType.TIME.getPredicate());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FilterPermanentOrSuspendedCard(final FilterPermanentOrSuspendedCard filter) {
|
protected FilterPermanentOrSuspendedCard(final FilterPermanentOrSuspendedCard filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.permanentFilter = filter.permanentFilter.copy();
|
|
||||||
this.cardFilter = filter.cardFilter.copy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkObjectClass(Object object) {
|
public boolean match(MageObject object, Game game) {
|
||||||
return object instanceof MageObject;
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
}
|
// so a Permanent could get filtered by the FilterCard
|
||||||
|
if (object instanceof Permanent) {
|
||||||
@Override
|
return getPermanentFilter().match((Permanent) object, game);
|
||||||
public boolean match(MageObject o, Game game) {
|
} else if (object instanceof Card) {
|
||||||
if (o instanceof Permanent) {
|
return getCardFilter().match((Card) object, game);
|
||||||
return permanentFilter.match((Permanent) o, game);
|
} else {
|
||||||
} else if (o instanceof Card) {
|
|
||||||
return cardFilter.match((Card) o, game);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(MageObject o, UUID playerId, Ability source, Game game) {
|
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
if (o instanceof Permanent) {
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
return permanentFilter.match((Permanent) o, playerId, source, game);
|
// so a Permanent could get filtered by the FilterCard
|
||||||
} else if (o instanceof Card) {
|
if (object instanceof Permanent) {
|
||||||
return cardFilter.match((Card) o, playerId, source, game);
|
return getPermanentFilter().match((Permanent) object, sourceControllerId, source, game);
|
||||||
}
|
} else if (object instanceof Card) {
|
||||||
|
return getCardFilter().match((Card) object, sourceControllerId, source, game);
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterPermanent getPermanentFilter() {
|
|
||||||
return this.permanentFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterCard getCardFilter() {
|
|
||||||
return this.cardFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermanentFilter(FilterPermanent permanentFilter) {
|
|
||||||
this.permanentFilter = permanentFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCardFilter(FilterCard cardFilter) {
|
|
||||||
this.cardFilter = cardFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FilterPermanentOrSuspendedCard copy() {
|
public FilterPermanentOrSuspendedCard copy() {
|
||||||
return new FilterPermanentOrSuspendedCard(this);
|
return new FilterPermanentOrSuspendedCard(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FilterPermanent getPermanentFilter() {
|
||||||
|
return (FilterPermanent) this.innerFilters.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilterCard getCardFilter() {
|
||||||
|
return (FilterCard) this.innerFilters.get(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@ package mage.filter.common;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.filter.FilterImpl;
|
|
||||||
import mage.filter.FilterInPlay;
|
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.FilterSpell;
|
import mage.filter.FilterSpell;
|
||||||
|
import mage.filter.MultiFilterImpl;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
|
|
@ -15,73 +14,45 @@ import java.util.UUID;
|
||||||
/**
|
/**
|
||||||
* @author LevelX
|
* @author LevelX
|
||||||
*/
|
*/
|
||||||
public class FilterSpellOrPermanent extends FilterImpl<MageObject> implements FilterInPlay<MageObject> {
|
public class FilterSpellOrPermanent extends MultiFilterImpl<MageObject> {
|
||||||
|
|
||||||
protected FilterPermanent permanentFilter;
|
|
||||||
protected FilterSpell spellFilter;
|
|
||||||
|
|
||||||
public FilterSpellOrPermanent() {
|
public FilterSpellOrPermanent() {
|
||||||
this("spell or permanent");
|
this("spell or permanent");
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterSpellOrPermanent(String name) {
|
public FilterSpellOrPermanent(String name) {
|
||||||
super(name);
|
super(name, new FilterPermanent(), new FilterSpell());
|
||||||
permanentFilter = new FilterPermanent();
|
|
||||||
spellFilter = new FilterSpell();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FilterSpellOrPermanent(final FilterSpellOrPermanent filter) {
|
protected FilterSpellOrPermanent(final FilterSpellOrPermanent filter) {
|
||||||
super(filter);
|
super(filter);
|
||||||
this.permanentFilter = filter.permanentFilter.copy();
|
|
||||||
this.spellFilter = filter.spellFilter.copy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkObjectClass(Object object) {
|
|
||||||
return object instanceof MageObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(MageObject o, Game game) {
|
public boolean match(MageObject object, Game game) {
|
||||||
if (o instanceof Spell) {
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
return spellFilter.match((Spell) o, game);
|
// and currently FilterSpell accepts to filter Cards
|
||||||
} else if (o instanceof Permanent) {
|
if (object instanceof Permanent) {
|
||||||
return permanentFilter.match((Permanent) o, game);
|
return getPermanentFilter().match((Permanent) object, game);
|
||||||
}
|
} else if (object instanceof Spell) {
|
||||||
|
return getSpellFilter().match((Spell) object, game);
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(MageObject o, UUID playerId, Ability source, Game game) {
|
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
if (o instanceof Spell) {
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
return spellFilter.match((Spell) o, playerId, source, game);
|
// and currently FilterSpell accepts to filter Cards
|
||||||
} else if (o instanceof Permanent) {
|
if (object instanceof Permanent) {
|
||||||
return permanentFilter.match((Permanent) o, playerId, source, game);
|
return getPermanentFilter().match((Permanent) object, sourceControllerId, source, game);
|
||||||
}
|
} else if (object instanceof Spell) {
|
||||||
|
return getSpellFilter().match((Spell) object, sourceControllerId, source, game);
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLockedFilter(boolean lockedFilter) {
|
|
||||||
super.setLockedFilter(lockedFilter);
|
|
||||||
spellFilter.setLockedFilter(lockedFilter);
|
|
||||||
permanentFilter.setLockedFilter(lockedFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterPermanent getPermanentFilter() {
|
|
||||||
return this.permanentFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FilterSpell getSpellFilter() {
|
|
||||||
return this.spellFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermanentFilter(FilterPermanent permanentFilter) {
|
|
||||||
this.permanentFilter = permanentFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpellFilter(FilterSpell spellFilter) {
|
|
||||||
this.spellFilter = spellFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -89,4 +60,11 @@ public class FilterSpellOrPermanent extends FilterImpl<MageObject> implements Fi
|
||||||
return new FilterSpellOrPermanent(this);
|
return new FilterSpellOrPermanent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FilterPermanent getPermanentFilter() {
|
||||||
|
return (FilterPermanent) this.innerFilters.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilterSpell getSpellFilter() {
|
||||||
|
return (FilterSpell) this.innerFilters.get(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ public class ManaPool implements Serializable {
|
||||||
/**
|
/**
|
||||||
* @param manaType the mana type that should be paid
|
* @param manaType the mana type that should be paid
|
||||||
* @param ability
|
* @param ability
|
||||||
* @param filter
|
* @param filter filters the source of mana, only matching source are accepted.
|
||||||
* @param game
|
* @param game
|
||||||
* @param costToPay complete costs to pay (needed to check conditional
|
* @param costToPay complete costs to pay (needed to check conditional
|
||||||
* mana)
|
* mana)
|
||||||
|
|
@ -143,7 +143,8 @@ public class ManaPool implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ManaPoolItem mana : manaItems) {
|
for (ManaPoolItem mana : manaItems) {
|
||||||
if (filter != null && !filter.match(mana.getSourceObject(), game)) {
|
MageObject sourceObject = mana.getSourceObject();
|
||||||
|
if (filter != null && (!filter.checkObjectClass(sourceObject) || !filter.match(sourceObject, game))) {
|
||||||
// If here, then mana source does not match the filter
|
// If here, then mana source does not match the filter
|
||||||
// However, alternate mana payment abilities such as convoke won't match the filter but are valid
|
// However, alternate mana payment abilities such as convoke won't match the filter but are valid
|
||||||
// So we need to do some ugly checks to allow them
|
// So we need to do some ugly checks to allow them
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package mage.target.common;
|
package mage.target.common;
|
||||||
|
|
||||||
import mage.filter.FilterOpponent;
|
import mage.filter.FilterOpponent;
|
||||||
import mage.filter.FilterPlayer;
|
|
||||||
import mage.target.TargetPlayer;
|
import mage.target.TargetPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue