mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
apply review
This commit is contained in:
parent
19b8a80ab5
commit
d1f190a287
5 changed files with 77 additions and 1 deletions
|
|
@ -73,6 +73,9 @@ public class FilterCard extends FilterObject<Card> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkObjectClass(Object object) {
|
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;
|
return object instanceof Card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +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.addAll(filter.extraPredicates);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,6 +46,7 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
|
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
if (!this.match(object, game)) {
|
if (!this.match(object, game)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a Filter out of multiple inner filters.
|
* 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
|
* @author Susucr
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,6 +29,9 @@ public abstract class MultiFilterImpl<E> implements Filter<E> {
|
||||||
|
|
||||||
protected MultiFilterImpl(String name, Filter<? extends E>... filters) {
|
protected MultiFilterImpl(String name, Filter<? extends E>... filters) {
|
||||||
this.message = name;
|
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).collect(Collectors.toList()));
|
this.innerFilters.addAll(Arrays.stream(filters).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,6 +49,7 @@ public abstract class MultiFilterImpl<E> implements Filter<E> {
|
||||||
.anyMatch((Filter filter) -> filter.match(object, game));
|
.anyMatch((Filter filter) -> filter.match(object, game));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
|
public boolean match(E object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
return innerFilters
|
return innerFilters
|
||||||
.stream()
|
.stream()
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
package mage.filter.common;
|
package mage.filter.common;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.keyword.SuspendAbility;
|
import mage.abilities.keyword.SuspendAbility;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.FilterCard;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.MultiFilterImpl;
|
import mage.filter.MultiFilterImpl;
|
||||||
import mage.filter.predicate.mageobject.AbilityPredicate;
|
import mage.filter.predicate.mageobject.AbilityPredicate;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author emerald000
|
* @author emerald000
|
||||||
|
|
@ -27,6 +33,32 @@ public class FilterPermanentOrSuspendedCard extends MultiFilterImpl<MageObject>
|
||||||
super(filter);
|
super(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(MageObject object, Game game) {
|
||||||
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
|
// so a Permanent could get filtered by the FilterCard
|
||||||
|
if (object instanceof Permanent) {
|
||||||
|
return getPermanentFilter().match((Permanent) object, game);
|
||||||
|
} else if (object instanceof Card) {
|
||||||
|
return getCardFilter().match((Card) object, game);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
|
// so a Permanent could get filtered by the FilterCard
|
||||||
|
if (object instanceof Permanent) {
|
||||||
|
return getPermanentFilter().match((Permanent) object, sourceControllerId, source, game);
|
||||||
|
} else if (object instanceof Card) {
|
||||||
|
return getCardFilter().match((Card) object, sourceControllerId, source, game);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FilterPermanentOrSuspendedCard copy() {
|
public FilterPermanentOrSuspendedCard copy() {
|
||||||
return new FilterPermanentOrSuspendedCard(this);
|
return new FilterPermanentOrSuspendedCard(this);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
package mage.filter.common;
|
package mage.filter.common;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.FilterSpell;
|
import mage.filter.FilterSpell;
|
||||||
import mage.filter.MultiFilterImpl;
|
import mage.filter.MultiFilterImpl;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.game.stack.Spell;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author LevelX
|
* @author LevelX
|
||||||
|
|
@ -22,6 +28,33 @@ public class FilterSpellOrPermanent extends MultiFilterImpl<MageObject> {
|
||||||
super(filter);
|
super(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(MageObject object, Game game) {
|
||||||
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
|
// and currently FilterSpell accepts to filter Cards
|
||||||
|
if (object instanceof Permanent) {
|
||||||
|
return getPermanentFilter().match((Permanent) object, game);
|
||||||
|
} else if (object instanceof Spell) {
|
||||||
|
return getSpellFilter().match((Spell) object, game);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(MageObject object, UUID sourceControllerId, Ability source, Game game) {
|
||||||
|
// We can not rely on super.match, since Permanent extend Card
|
||||||
|
// and currently FilterSpell accepts to filter Cards
|
||||||
|
if (object instanceof Permanent) {
|
||||||
|
return getPermanentFilter().match((Permanent) object, sourceControllerId, source, game);
|
||||||
|
} else if (object instanceof Spell) {
|
||||||
|
return getSpellFilter().match((Spell) object, sourceControllerId, source, game);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FilterSpellOrPermanent copy() {
|
public FilterSpellOrPermanent copy() {
|
||||||
return new FilterSpellOrPermanent(this);
|
return new FilterSpellOrPermanent(this);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue