mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
refactored IntCompareCondition
This commit is contained in:
parent
1f89b4eedf
commit
22c842dfec
12 changed files with 46 additions and 55 deletions
|
|
@ -138,7 +138,7 @@ public interface MageObject extends MageItem, Serializable {
|
|||
}
|
||||
|
||||
default void addCardType(CardType cardType) {
|
||||
addCardType(cardType);
|
||||
getCardType().add(cardType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
package mage.abilities.condition;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.CountType;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
|
|
@ -36,10 +37,10 @@ import mage.game.Game;
|
|||
*/
|
||||
public abstract class IntCompareCondition implements Condition {
|
||||
|
||||
protected final Condition.ComparisonType type;
|
||||
protected final CountType type;
|
||||
protected final int value;
|
||||
|
||||
public IntCompareCondition(Condition.ComparisonType type, int value) {
|
||||
public IntCompareCondition(CountType type, int value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
|
@ -49,24 +50,7 @@ public abstract class IntCompareCondition implements Condition {
|
|||
@Override
|
||||
public final boolean apply(Game game, Ability source) {
|
||||
int inputValue = getInputValue(game, source);
|
||||
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 CountType.compare(inputValue , type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.CountType;
|
||||
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(Condition.ComparisonType type, int value) {
|
||||
public DevouredCreaturesCondition(CountType type, int value) {
|
||||
super(type, value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@
|
|||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.CountType;
|
||||
import mage.abilities.condition.IntCompareCondition;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.PlayerLostLifeWatcher;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Describes condition when an opponent has lost an amount of life
|
||||
*
|
||||
|
|
@ -42,7 +42,7 @@ import mage.watchers.common.PlayerLostLifeWatcher;
|
|||
*/
|
||||
public class OpponentLostLifeCondition extends IntCompareCondition {
|
||||
|
||||
public OpponentLostLifeCondition(Condition.ComparisonType type, int value) {
|
||||
public OpponentLostLifeCondition(CountType type, int value) {
|
||||
super(type, value);
|
||||
}
|
||||
|
||||
|
|
@ -65,13 +65,13 @@ public class OpponentLostLifeCondition extends IntCompareCondition {
|
|||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("if an opponent lost ");
|
||||
switch (type) {
|
||||
case GreaterThan:
|
||||
case MORE_THAN:
|
||||
sb.append(value + 1).append(" or more life this turn ");
|
||||
break;
|
||||
case Equal:
|
||||
case EQUAL_TO:
|
||||
sb.append(value).append(" life this turn ");
|
||||
break;
|
||||
case LessThan:
|
||||
case FEWER_THAN:
|
||||
sb.append(" less than ").append(value).append(" life this turn ");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue