there were 3 enums to compare ints, refactored to 1

This commit is contained in:
ingmargoudt 2017-04-10 00:21:09 +02:00
parent 813d84274a
commit cb693b5826
339 changed files with 1263 additions and 1225 deletions

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

@ -27,22 +27,23 @@
*/
package mage.abilities.condition.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.CountType;
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 CountType type;
protected final int value;
public CardsInAnyLibraryCondition(Condition.ComparisonType type, int value) {
public CardsInAnyLibraryCondition(CountType 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 CountType.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

@ -29,8 +29,8 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.CountType;
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(CountType.MORE_THAN, 3));
}