Merge pull request #3088 from ingmargoudt/fixes

Fixes
This commit is contained in:
Derek M 2017-04-12 10:08:27 -04:00 committed by GitHub
commit 3e6a925271
571 changed files with 1896 additions and 1817 deletions

View file

@ -1,22 +0,0 @@
package mage.abilities;
/**
* Created by IGOUDT on 5-3-2017.
*/
public enum CountType {
MORE_THAN, FEWER_THAN, EQUAL_TO;
public static boolean compare(int source, CountType comparison, int target){
switch (comparison){
case MORE_THAN:
return source > target;
case FEWER_THAN:
return source < target;
case EQUAL_TO:
return source == target;
default:
throw new IllegalArgumentException("comparison rules for "+comparison + " missing");
}
}
}

View file

@ -27,10 +27,10 @@
*/
package mage.abilities.common;
import mage.constants.ComparisonType;
import mage.abilities.StateTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.filter.Filter.ComparisonType;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -69,24 +69,7 @@ public class ControlsPermanentsControllerTriggeredAbility extends StateTriggered
@Override
public boolean checkTrigger(GameEvent event, Game game) {
int inputValue = game.getBattlefield().countAll(filter, getControllerId(), game);
switch (type) {
case Equal:
if (inputValue != value) {
return false;
}
break;
case GreaterThan:
if (inputValue <= value) {
return false;
}
break;
case LessThan:
if (inputValue >= value) {
return false;
}
break;
}
return true;
return ComparisonType.compare(value, type, inputValue);
}
@Override

View file

@ -1,9 +1,10 @@
package mage.abilities.condition;
import java.io.Serializable;
import mage.abilities.Ability;
import mage.game.Game;
import java.io.Serializable;
/**
* Interface describing condition occurrence.
@ -13,24 +14,6 @@ import mage.game.Game;
@FunctionalInterface
public interface Condition extends Serializable {
enum ComparisonType {
GreaterThan(">"),
Equal("=="),
LessThan("<");
private final String text;
ComparisonType(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
/**
* Checks the game to see if this condition applies for the given ability.
*

View file

@ -28,7 +28,7 @@
package mage.abilities.condition;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.game.Game;
/**
@ -37,10 +37,10 @@ import mage.game.Game;
*/
public abstract class IntCompareCondition implements Condition {
protected final CountType type;
protected final ComparisonType type;
protected final int value;
public IntCompareCondition(CountType type, int value) {
public IntCompareCondition(ComparisonType type, int value) {
this.type = type;
this.value = value;
}
@ -50,7 +50,7 @@ public abstract class IntCompareCondition implements Condition {
@Override
public final boolean apply(Game game, Ability source) {
int inputValue = getInputValue(game, source);
return CountType.compare(inputValue , type, value);
return ComparisonType.compare(inputValue , type, value);
}
@Override

View file

@ -27,22 +27,23 @@
*/
package mage.abilities.condition.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.constants.ComparisonType;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class CardsInAnyLibraryCondition implements Condition {
protected final Condition.ComparisonType type;
protected final ComparisonType type;
protected final int value;
public CardsInAnyLibraryCondition(Condition.ComparisonType type, int value) {
public CardsInAnyLibraryCondition(ComparisonType type, int value) {
this.type = type;
this.value = value;
}
@ -54,23 +55,8 @@ public class CardsInAnyLibraryCondition implements Condition {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
switch (type) {
case GreaterThan:
if (player.getLibrary().size() > value) {
return true;
}
break;
case Equal:
if (player.getLibrary().size() == value) {
return true;
}
break;
case LessThan:
if (player.getLibrary().size() < value) {
return true;
}
break;
}
return ComparisonType.compare(player.getLibrary().size(), type, value);
}
}
}
@ -81,13 +67,13 @@ public class CardsInAnyLibraryCondition implements Condition {
public String toString() {
StringBuilder sb = new StringBuilder("a library has ");
switch (type) {
case GreaterThan:
case MORE_THAN:
sb.append(value + 1).append(" or more cards in it ");
break;
case Equal:
case EQUAL_TO:
sb.append(value).append(" cards in it ");
break;
case LessThan:
case FEWER_THAN:
sb.append(value - 1).append(" or fewer cards in it ");
break;
}

View file

@ -30,7 +30,7 @@ package mage.abilities.condition.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.Condition;
import mage.constants.TargetController;
import mage.game.Game;
@ -47,23 +47,23 @@ public class CardsInHandCondition implements Condition {
private Condition condition;
private CountType type;
private ComparisonType type;
private int count;
private TargetController targetController;
public CardsInHandCondition() {
this(CountType.EQUAL_TO, 0);
this(ComparisonType.EQUAL_TO, 0);
}
public CardsInHandCondition(CountType type, int count) {
public CardsInHandCondition(ComparisonType type, int count) {
this(type, count, null);
}
public CardsInHandCondition(CountType type, int count, Condition conditionToDecorate) {
public CardsInHandCondition(ComparisonType type, int count, Condition conditionToDecorate) {
this(type, count, conditionToDecorate, TargetController.YOU);
}
public CardsInHandCondition(CountType type, int count, Condition conditionToDecorate, TargetController targetController) {
public CardsInHandCondition(ComparisonType type, int count, Condition conditionToDecorate, TargetController targetController) {
this.type = type;
this.count = count;
this.condition = conditionToDecorate;
@ -77,12 +77,12 @@ public class CardsInHandCondition implements Condition {
if (controller != null) {
switch (targetController) {
case YOU:
conditionApplies = CountType.compare(game.getPlayer(source.getControllerId()).getHand().size(), type, count);
conditionApplies = ComparisonType.compare(game.getPlayer(source.getControllerId()).getHand().size(), type, count);
break;
case ACTIVE:
Player player = game.getPlayer(game.getActivePlayerId());
if (player != null) {
conditionApplies = CountType.compare(player.getHand().size(), type, count);
conditionApplies = ComparisonType.compare(player.getHand().size(), type, count);
}
break;
case ANY:
@ -90,7 +90,7 @@ public class CardsInHandCondition implements Condition {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
player = game.getPlayer(playerId);
if (player != null) {
if (!CountType.compare(player.getHand().size(), type, this.count)) {
if (!ComparisonType.compare(player.getHand().size(), type, this.count)) {
conflict = true;
break;
}

View file

@ -28,7 +28,7 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.IntCompareCondition;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DevourEffect;
@ -43,7 +43,7 @@ import mage.game.permanent.Permanent;
*/
public class DevouredCreaturesCondition extends IntCompareCondition {
public DevouredCreaturesCondition(CountType type, int value) {
public DevouredCreaturesCondition(ComparisonType type, int value) {
super(type, value);
}

View file

@ -29,8 +29,8 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.constants.ComparisonType;
import mage.abilities.condition.Condition;
import mage.filter.Filter;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.PowerPredicate;
import mage.game.Game;
@ -43,7 +43,7 @@ public enum FerociousCondition implements Condition {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
static {
filter.add(new PowerPredicate(Filter.ComparisonType.GreaterThan, 3));
filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 3));
}

View file

@ -31,7 +31,7 @@ package mage.abilities.condition.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.Condition;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
@ -48,18 +48,18 @@ public class OpponentControlsPermanentCondition implements Condition {
private FilterPermanent filter;
private CountType type;
private ComparisonType type;
private int count;
/**
* @param filter
*/
public OpponentControlsPermanentCondition(FilterPermanent filter) {
this(filter, CountType.MORE_THAN, 0);
this(filter, ComparisonType.MORE_THAN, 0);
}
/**
* Applies a filter, a {@link CountType}, and count to permanents on the
* Applies a filter, a {@link ComparisonType}, and count to permanents on the
* battlefield when checking the condition during the
* {@link #apply(mage.game.Game, mage.abilities.Ability) apply} method invocation.
*
@ -67,7 +67,7 @@ public class OpponentControlsPermanentCondition implements Condition {
* @param type
* @param count
*/
public OpponentControlsPermanentCondition(FilterPermanent filter, CountType type, int count) {
public OpponentControlsPermanentCondition(FilterPermanent filter, ComparisonType type, int count) {
this.filter = filter;
this.type = type;
this.count = count;
@ -79,7 +79,7 @@ public class OpponentControlsPermanentCondition implements Condition {
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
FilterPermanent localFilter = filter.copy();
localFilter.add(new ControllerIdPredicate(opponentId));
if (CountType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
if (ComparisonType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
conditionApplies = true;
break;
}

View file

@ -28,7 +28,7 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.IntCompareCondition;
import mage.game.Game;
import mage.watchers.common.PlayerLostLifeWatcher;
@ -42,7 +42,7 @@ import java.util.UUID;
*/
public class OpponentLostLifeCondition extends IntCompareCondition {
public OpponentLostLifeCondition(CountType type, int value) {
public OpponentLostLifeCondition(ComparisonType type, int value) {
super(type, value);
}

View file

@ -28,7 +28,7 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.Condition;
import mage.counters.CounterType;
import mage.game.Game;
@ -47,15 +47,15 @@ public class PermanentHasCounterCondition implements Condition {
private CounterType counterType;
private int amount;
private FilterPermanent filter;
private CountType counttype;
private ComparisonType counttype;
private boolean anyPlayer;
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter) {
this(counterType, amount, filter, CountType.EQUAL_TO);
this(counterType, amount, filter, ComparisonType.EQUAL_TO);
this.anyPlayer = false;
}
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter, CountType type) {
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter, ComparisonType type) {
this.counterType = counterType;
this.amount = amount;
this.filter = filter;
@ -63,7 +63,7 @@ public class PermanentHasCounterCondition implements Condition {
this.anyPlayer = false;
}
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter, CountType type, boolean any) {
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter, ComparisonType type, boolean any) {
this.counterType = counterType;
this.amount = amount;
this.filter = filter;
@ -77,7 +77,7 @@ public class PermanentHasCounterCondition implements Condition {
permanents = game.getBattlefield().getAllActivePermanents(this.filter, game);
}
for (Permanent permanent : permanents) {
if(CountType.compare(permanent.getCounters(game).getCount(this.counterType), counttype, this.amount))
if(ComparisonType.compare(permanent.getCounters(game).getCount(this.counterType), counttype, this.amount))
{
return true;
}

View file

@ -28,7 +28,7 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.Condition;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
@ -47,23 +47,23 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
private FilterPermanent filter;
private Condition condition;
private CountType type;
private ComparisonType type;
private int count;
private boolean onlyControlled;
/**
* Applies a filter and delegates creation to
* {@link #ControlsPermanent(mage.filter.FilterPermanent, mage.abilities.condition.common.ControlsPermanent.CountType, int)}
* with {@link CountType#MORE_THAN}, and 0.
* with {@link ComparisonType#MORE_THAN}, and 0.
*
* @param filter
*/
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter) {
this(filter, CountType.MORE_THAN, 0);
this(filter, ComparisonType.MORE_THAN, 0);
}
/**
* Applies a filter, a {@link CountType}, and count to permanents on the
* Applies a filter, a {@link ComparisonType}, and count to permanents on the
* battlefield when checking the condition during the
* {@link #apply(mage.game.Game, mage.abilities.Ability) apply} method invocation.
*
@ -71,11 +71,11 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
* @param type
* @param count
*/
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, CountType type, int count) {
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, ComparisonType type, int count) {
this(filter, type, count, true);
}
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, CountType type, int count, boolean onlyControlled) {
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, ComparisonType type, int count, boolean onlyControlled) {
this.filter = filter;
this.type = type;
this.count = count;
@ -83,7 +83,7 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
}
/**
* Applies a filter, a {@link CountType}, and count to permanents on the
* Applies a filter, a {@link ComparisonType}, and count to permanents on the
* battlefield and calls the decorated condition to see if it
* {@link #apply(mage.game.Game, mage.abilities.Ability) applies}
* as well. This will force both conditions to apply for this to be true.
@ -93,7 +93,7 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
* @param count
* @param conditionToDecorate
*/
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, CountType type, int count, Condition conditionToDecorate) {
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, ComparisonType type, int count, Condition conditionToDecorate) {
this(filter, type, count);
this.condition = conditionToDecorate;
}
@ -108,7 +108,7 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
}
int permanentsOnBattlefield = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game);
conditionApplies = CountType.compare(permanentsOnBattlefield, type, count);
conditionApplies = ComparisonType.compare(permanentsOnBattlefield, type, count);
//If a decorated condition exists, check it as well and apply them together.
if (this.condition != null) {

View file

@ -1,7 +1,7 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.CountType;
import mage.constants.ComparisonType;
import mage.abilities.condition.IntCompareCondition;
import mage.game.Game;
import mage.watchers.common.PlayerGainedLifeWatcher;
@ -11,7 +11,7 @@ import mage.watchers.common.PlayerGainedLifeWatcher;
*/
public class YouGainedLifeCondition extends IntCompareCondition {
public YouGainedLifeCondition(CountType type, int value) {
public YouGainedLifeCondition(ComparisonType type, int value) {
super(type, value);
}

View file

@ -27,7 +27,6 @@
*/
package mage.abilities.effects.common;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
@ -40,6 +39,8 @@ import mage.game.permanent.PermanentCard;
import mage.game.permanent.PermanentToken;
import mage.util.functions.ApplyToPermanent;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -130,7 +131,7 @@ public class CopyEffect extends ContinuousEffectImpl {
}
permanent.getSuperType().clear();
for (SuperType type : copyFromObject.getSuperType()) {
permanent.getSuperType().add(type);
permanent.addSuperType(type);
}
permanent.removeAllAbilities(source.getSourceId(), game);

View file

@ -36,7 +36,7 @@ public class CopyTokenEffect extends ContinuousEffectImpl {
}
permanent.getSuperType().clear();
for (SuperType type: token.getSuperType()) {
permanent.getSuperType().add(type);
permanent.addSuperType(type);
}
permanent.getAbilities().clear();
for (Ability ability: token.getAbilities()) {

View file

@ -29,10 +29,10 @@
package mage.abilities.effects.common.cost;
import mage.abilities.Ability;
import mage.constants.ComparisonType;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.filter.Filter;
import mage.filter.common.FilterNonlandCard;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
@ -58,7 +58,7 @@ public class CastWithoutPayingManaCostEffect extends OneShotEffect {
public CastWithoutPayingManaCostEffect(int maxCost) {
super(Outcome.PlayForFree);
filter = new FilterNonlandCard("card with converted mana cost " + maxCost + " or less from your hand");
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, maxCost + 1));
filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, maxCost + 1));
this.manaCost = maxCost;
this.staticText = "you may cast a card with converted mana cost " + maxCost + " or less from your hand without paying its mana cost";
}

View file

@ -28,11 +28,11 @@
package mage.abilities.effects.common.search;
import mage.abilities.Ability;
import mage.constants.ComparisonType;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
@ -67,7 +67,7 @@ public class SearchLibraryWithLessCMCPutInPlayEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard advancedFilter = filter.copy(); // never change static objects so copy the object here before
advancedFilter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, source.getManaCostsToPay().getX() + 1));
advancedFilter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
TargetCardInLibrary target = new TargetCardInLibrary(advancedFilter);
if (controller.searchLibrary(target, game)) {
if (!target.getTargets().isEmpty()) {

View file

@ -28,6 +28,7 @@
package mage.abilities.effects.keyword;
import mage.abilities.Ability;
import mage.constants.ComparisonType;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.Effect;
@ -35,7 +36,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.filter.Filter;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent;
@ -96,7 +96,7 @@ public class BolsterEffect extends OneShotEffect {
if (leastToughness != Integer.MAX_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with toughness " + leastToughness);
filter.add(new ToughnessPredicate(Filter.ComparisonType.Equal, leastToughness));
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(1,1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());

View file

@ -28,18 +28,19 @@
package mage.abilities.keyword;
import java.util.UUID;
import mage.constants.ComparisonType;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.common.ReturnToHandTargetEffect;
import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.UUID;
/**
*
* 702.45. Soulshift
@ -75,7 +76,7 @@ public class SoulshiftAbility extends DiesTriggeredAbility {
this.getTargets().clear();
int intValue = amount.calculate(game, this, null);
FilterCard filter = new FilterCard("Spirit card with converted mana cost " + intValue + " or less from your graveyard");
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, intValue + 1));
filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, intValue + 1));
filter.add(new SubtypePredicate("Spirit"));
this.addTarget(new TargetCardInYourGraveyard(filter));
super.trigger(game, controllerId); //To change body of generated methods, choose Tools | Templates.

View file

@ -85,7 +85,7 @@ public class TransformAbility extends SimpleStaticAbility {
}
permanent.getSuperType().clear();
for (SuperType type : sourceCard.getSuperType()) {
permanent.getSuperType().add(type);
permanent.addSuperType(type);
}
permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
permanent.getAbilities().clear();

View file

@ -1,6 +1,8 @@
package mage.abilities.keyword;
import mage.MageObject;
import mage.abilities.Ability;
import mage.constants.ComparisonType;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.DiscardSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
@ -8,17 +10,14 @@ import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.MageObject;
import mage.constants.TimingRule;
/**
*
* 702.52. Transmute
@ -79,7 +78,7 @@ class TransmuteEffect extends OneShotEffect {
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
FilterCard filter = new FilterCard("card with converted mana cost " + sourceObject.getConvertedManaCost());
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal, sourceObject.getConvertedManaCost()));
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, sourceObject.getConvertedManaCost()));
TargetCardInLibrary target = new TargetCardInLibrary(1, filter);
if (controller.searchLibrary(target, game)) {
if (!target.getTargets().isEmpty()) {

View file

@ -0,0 +1,33 @@
package mage.constants;
/**
* Created by IGOUDT on 5-3-2017.
*/
public enum ComparisonType {
MORE_THAN(">"), FEWER_THAN("<"), EQUAL_TO("==");
String operator;
ComparisonType(String op) {
operator = op;
}
@Override
public String toString() {
return operator;
}
public static boolean compare(int source, ComparisonType comparison, int target) {
switch (comparison) {
case MORE_THAN:
return source > target;
case FEWER_THAN:
return source < target;
case EQUAL_TO:
return source == target;
default:
throw new IllegalArgumentException("comparison rules for " + comparison + " missing");
}
}
}

View file

@ -27,37 +27,18 @@
*/
package mage.filter;
import java.io.Serializable;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import java.io.Serializable;
/**
*
* @param <E>
* @author BetaSteward_at_googlemail.com
* @author North
*
* @param <E>
*/
public interface Filter<E> extends Serializable {
enum ComparisonType {
GreaterThan(">"),
Equal("=="),
LessThan("<");
private final String text;
ComparisonType(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
enum ComparisonScope {
Any, All
}

View file

@ -28,7 +28,7 @@
package mage.filter.predicate;
import mage.MageObject;
import mage.filter.Filter;
import mage.constants.ComparisonType;
import mage.game.Game;
/**
@ -38,10 +38,10 @@ import mage.game.Game;
*/
public abstract class IntComparePredicate<T extends MageObject> implements Predicate<T> {
protected final Filter.ComparisonType type;
protected final ComparisonType type;
protected final int value;
public IntComparePredicate(Filter.ComparisonType type, int value) {
public IntComparePredicate(ComparisonType type, int value) {
this.type = type;
this.value = value;
}
@ -51,24 +51,7 @@ public abstract class IntComparePredicate<T extends MageObject> implements Predi
@Override
public final boolean apply(T input, Game game) {
int inputValue = getInputValue(input);
switch (type) {
case Equal:
if (inputValue != value) {
return false;
}
break;
case GreaterThan:
if (inputValue <= value) {
return false;
}
break;
case LessThan:
if (inputValue >= value) {
return false;
}
break;
}
return true;
return ComparisonType.compare(inputValue, type, value);
}
@Override

View file

@ -28,7 +28,7 @@
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.filter.Filter;
import mage.constants.ComparisonType;
import mage.filter.predicate.IntComparePredicate;
/**
@ -37,7 +37,7 @@ import mage.filter.predicate.IntComparePredicate;
*/
public class ConvertedManaCostPredicate extends IntComparePredicate<MageObject> {
public ConvertedManaCostPredicate(Filter.ComparisonType type, int value) {
public ConvertedManaCostPredicate(ComparisonType type, int value) {
super(type, value);
}

View file

@ -28,7 +28,7 @@
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.filter.Filter;
import mage.constants.ComparisonType;
import mage.filter.predicate.IntComparePredicate;
/**
@ -37,7 +37,7 @@ import mage.filter.predicate.IntComparePredicate;
*/
public class PowerPredicate extends IntComparePredicate<MageObject> {
public PowerPredicate(Filter.ComparisonType type, int value) {
public PowerPredicate(ComparisonType type, int value) {
super(type, value);
}

View file

@ -44,10 +44,6 @@ public class SupertypePredicate implements Predicate<MageObject> {
this.supertype = supertype;
}
public SupertypePredicate(String supertype){
this.supertype = SuperType.valueOf(supertype.trim().toUpperCase());
}
@Override
public boolean apply(MageObject input, Game game) {
return input.getSuperType().contains(supertype);

View file

@ -28,7 +28,7 @@
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.filter.Filter;
import mage.constants.ComparisonType;
import mage.filter.predicate.IntComparePredicate;
/**
@ -37,7 +37,7 @@ import mage.filter.predicate.IntComparePredicate;
*/
public class ToughnessPredicate extends IntComparePredicate<MageObject> {
public ToughnessPredicate(Filter.ComparisonType type, int value) {
public ToughnessPredicate(ComparisonType type, int value) {
super(type, value);
}

View file

@ -101,7 +101,7 @@ public class CopyTokenFunction implements Function<Token, Card> {
}
target.getSuperType().clear();
for (SuperType type : sourceObj.getSuperType()) {
target.getSuperType().add(type);
target.addSuperType(type);
}
target.getAbilities().clear();