mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
[filters] replaced Name condition with Predicate
This commit is contained in:
parent
3d1f23e03b
commit
98feeb9968
28 changed files with 120 additions and 83 deletions
|
|
@ -3,6 +3,7 @@ package mage.abilities.dynamicvalue.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
public class UrzaTerrainValue implements DynamicValue {
|
||||
|
|
@ -15,19 +16,19 @@ public class UrzaTerrainValue implements DynamicValue {
|
|||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility) {
|
||||
FilterControlledPermanent pp = new FilterControlledPermanent("Urza's Power Plant");
|
||||
pp.getName().add("Urza's Power Plant");
|
||||
pp.add(new NamePredicate("Urza's Power Plant"));
|
||||
PermanentsOnBattlefieldCount ppP = new PermanentsOnBattlefieldCount(pp);
|
||||
if (ppP.calculate(game, sourceAbility) < 1)
|
||||
return 1;
|
||||
|
||||
FilterControlledPermanent to = new FilterControlledPermanent("Urza's Tower");
|
||||
to.getName().add("Urza's Tower");
|
||||
to.add(new NamePredicate("Urza's Tower"));
|
||||
PermanentsOnBattlefieldCount toP = new PermanentsOnBattlefieldCount(to);
|
||||
if (toP.calculate(game, sourceAbility) < 1)
|
||||
return 1;
|
||||
|
||||
FilterControlledPermanent mi = new FilterControlledPermanent("Urza's Mine");
|
||||
mi.getName().add("Urza's Mine");
|
||||
mi.add(new NamePredicate("Urza's Mine"));
|
||||
PermanentsOnBattlefieldCount miP = new PermanentsOnBattlefieldCount(mi);
|
||||
if (miP.calculate(game, sourceAbility) < 1)
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -28,20 +28,17 @@
|
|||
|
||||
package mage.abilities.effects.common.continious;
|
||||
|
||||
import mage.abilities.condition.common.ControlsPermanentCondition;
|
||||
import mage.abilities.effects.WhileConditionContiniousEffect;
|
||||
import mage.Constants.Duration;
|
||||
import mage.Constants.Layer;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.Constants.SubLayer;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.common.ControlsPermanentCondition;
|
||||
import mage.abilities.effects.WhileConditionContiniousEffect;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -50,13 +47,13 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContiniousEffe
|
|||
|
||||
private int power;
|
||||
private int toughness;
|
||||
private List<String> filterDescription;
|
||||
private String filterDescription;
|
||||
|
||||
public BoostSourceWhileControlsEffect(FilterPermanent filter, int power, int toughness) {
|
||||
super(Duration.WhileOnBattlefield, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, new ControlsPermanentCondition(filter), Outcome.BoostCreature);
|
||||
this.power = power;
|
||||
this.toughness = toughness;
|
||||
this.filterDescription = filter.getName();
|
||||
this.filterDescription = filter.getMessage();
|
||||
staticText = "{this} gets " + String.format("%1$+d/%2$+d", power, toughness) + " as long as you control a " + filterDescription;
|
||||
}
|
||||
|
||||
|
|
@ -64,8 +61,7 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContiniousEffe
|
|||
super(effect);
|
||||
this.power = effect.power;
|
||||
this.toughness = effect.toughness;
|
||||
this.filterDescription = new ArrayList<String>();
|
||||
this.filterDescription.addAll(effect.filterDescription);
|
||||
this.filterDescription = effect.filterDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,18 +28,33 @@
|
|||
|
||||
package mage.filter;
|
||||
|
||||
import mage.game.Game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author North
|
||||
*/
|
||||
public interface Filter<E> extends Serializable {
|
||||
|
||||
public enum ComparisonType {
|
||||
GreaterThan, Equal, LessThan
|
||||
|
||||
GreaterThan(">"),
|
||||
Equal("=="),
|
||||
LessThan("<");
|
||||
|
||||
private String text;
|
||||
|
||||
ComparisonType(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ComparisonScope {
|
||||
|
|
@ -47,9 +62,10 @@ public interface Filter<E> extends Serializable {
|
|||
}
|
||||
|
||||
public boolean match(E o, Game game);
|
||||
public void add(Predicate predicate);
|
||||
|
||||
public String getMessage();
|
||||
public void setMessage(String message);
|
||||
public void setNotFilter(boolean notFilter);
|
||||
|
||||
public Filter<E> copy();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,18 +28,23 @@
|
|||
|
||||
package mage.filter;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import mage.Constants.CardType;
|
||||
import mage.ObjectColor;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author North
|
||||
*/
|
||||
public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filter<E> {
|
||||
|
||||
protected static ListComparer<CardType> compCardType = new ListComparer<CardType>();
|
||||
protected static ListComparer<String> compString = new ListComparer<String>();
|
||||
|
||||
protected List<Predicate> predicates = new LinkedList<Predicate>();
|
||||
protected String message;
|
||||
protected boolean notFilter = false;
|
||||
|
||||
|
|
@ -53,6 +58,7 @@ public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filte
|
|||
public FilterImpl(FilterImpl filter) {
|
||||
this.message = filter.message;
|
||||
this.notFilter = filter.notFilter;
|
||||
this.predicates = new LinkedList<Predicate>(filter.predicates);
|
||||
}
|
||||
|
||||
protected boolean compareInts(int int1, int int2, ComparisonType type) {
|
||||
|
|
@ -73,11 +79,19 @@ public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filte
|
|||
return true;
|
||||
}
|
||||
|
||||
protected boolean compareColors(ObjectColor color1, ObjectColor color2, ComparisonScope scope) {
|
||||
if (scope == ComparisonScope.All)
|
||||
return color2.equals(color1);
|
||||
else
|
||||
return color2.contains(color1);
|
||||
@Override
|
||||
public boolean match(E e, Game game) {
|
||||
for (int i = 0; i < predicates.size(); i++) {
|
||||
if (!predicates.get(i).apply(e, game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void add(Predicate predicate) {
|
||||
predicates.add(predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -90,7 +104,6 @@ public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filte
|
|||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotFilter(boolean notFilter) {
|
||||
this.notFilter = notFilter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import java.util.List;
|
|||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author North
|
||||
*/
|
||||
public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> extends FilterImpl<E, T> implements Filter<E> {
|
||||
protected Abilities<Ability> abilities;
|
||||
|
|
@ -57,8 +58,6 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
|
|||
protected ObjectColor color;
|
||||
protected ComparisonScope scopeColor = ComparisonScope.Any;
|
||||
protected boolean notColor;
|
||||
protected List<String> name = new ArrayList<String>();
|
||||
protected boolean notName;
|
||||
protected List<String> subtype = new ArrayList<String>();
|
||||
protected ComparisonScope scopeSubtype = ComparisonScope.All;
|
||||
protected boolean notSubtype;
|
||||
|
|
@ -102,8 +101,6 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
|
|||
this.color = filter.color.copy();
|
||||
this.scopeColor = filter.scopeColor;
|
||||
this.notColor = filter.notColor;
|
||||
this.name.addAll(filter.name);
|
||||
this.notName = filter.notName;
|
||||
this.subtype.addAll(filter.subtype);
|
||||
this.scopeSubtype = filter.scopeSubtype;
|
||||
this.notSubtype = filter.notSubtype;
|
||||
|
|
@ -121,10 +118,8 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
|
|||
|
||||
@Override
|
||||
public boolean match(E object, Game game) {
|
||||
|
||||
if (name.size() > 0) {
|
||||
if (name.contains(object.getName()) == notName)
|
||||
return notFilter;
|
||||
if (!super.match(object, game)) {
|
||||
return notFilter;
|
||||
}
|
||||
|
||||
if (useColor) {
|
||||
|
|
@ -242,14 +237,6 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
|
|||
this.notColor = notColor;
|
||||
}
|
||||
|
||||
public List<String> getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setNotName(boolean notName) {
|
||||
this.notName = notName;
|
||||
}
|
||||
|
||||
public List<String> getSubtype() {
|
||||
return this.subtype;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,12 @@
|
|||
|
||||
package mage.game;
|
||||
|
||||
import mage.Constants.*;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.Constants.PhaseStep;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.Constants.Zone;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
|
|
@ -52,6 +57,7 @@ import mage.counters.CounterType;
|
|||
import mage.filter.Filter;
|
||||
import mage.filter.Filter.ComparisonScope;
|
||||
import mage.filter.common.*;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.combat.Combat;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.command.Emblem;
|
||||
|
|
@ -1045,7 +1051,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
if (legendary.size() > 1) { //don't bother checking if less than 2 legends in play
|
||||
for (Permanent legend: legendary) {
|
||||
FilterLegendaryPermanent filterLegendName = new FilterLegendaryPermanent();
|
||||
filterLegendName.getName().add(legend.getName());
|
||||
filterLegendName.add(new NamePredicate(legend.getName()));
|
||||
if (getBattlefield().contains(filterLegendName, legend.getControllerId(), this, 2)) {
|
||||
for (Permanent dupLegend: getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
|
||||
dupLegend.moveToZone(Zone.GRAVEYARD, null, this, false);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@
|
|||
|
||||
package mage.target.common;
|
||||
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -35,12 +38,11 @@ package mage.target.common;
|
|||
public class TargetNonBasicLandPermanent extends TargetLandPermanent<TargetNonBasicLandPermanent> {
|
||||
|
||||
public TargetNonBasicLandPermanent() {
|
||||
filter.setNotName(true);
|
||||
filter.getName().add("Island");
|
||||
filter.getName().add("Forest");
|
||||
filter.getName().add("Mountain");
|
||||
filter.getName().add("Swamp");
|
||||
filter.getName().add("Plains");
|
||||
filter.add(Predicates.not(new NamePredicate("Island")));
|
||||
filter.add(Predicates.not(new NamePredicate("Forest")));
|
||||
filter.add(Predicates.not(new NamePredicate("Mountain")));
|
||||
filter.add(Predicates.not(new NamePredicate("Swamp")));
|
||||
filter.add(Predicates.not(new NamePredicate("Plains")));
|
||||
this.targetName = "nonbasic land";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue