cleanup and add tests on '{this} enters the battlefield tapped unless [Condition]'

Almost a refactor. The only change is that all those cards were missing the notTarget argument in TapSourceEffect.

closes  #12411
This commit is contained in:
Susucre 2024-06-08 19:35:35 +02:00
parent 5b74858573
commit 40a1fc6c23
77 changed files with 1119 additions and 897 deletions

View file

@ -0,0 +1,32 @@
package mage.abilities.common;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.common.TapSourceEffect;
/**
* @author Susucr
*/
public class EntersBattlefieldTappedUnlessAbility extends EntersBattlefieldAbility {
public EntersBattlefieldTappedUnlessAbility(Condition condition) {
this(condition, condition.toString());
}
public EntersBattlefieldTappedUnlessAbility(Condition condition, String conditionText) {
super(
new ConditionalOneShotEffect(null, new TapSourceEffect(true), condition, null),
"tapped unless " + conditionText
);
}
private EntersBattlefieldTappedUnlessAbility(final EntersBattlefieldTappedUnlessAbility ability) {
super(ability);
}
@Override
public EntersBattlefieldTappedUnlessAbility copy() {
return new EntersBattlefieldTappedUnlessAbility(this);
}
}

View file

@ -6,15 +6,15 @@ import mage.abilities.condition.Condition;
import mage.game.Game;
public enum MyTurnCondition implements Condition {
instance;
instance;
@Override
public boolean apply(Game game, Ability source) {
return game.isActivePlayer(source.getControllerId());
}
@Override
public String toString() {
return "during your turn";
return "during your turn";
}
}

View file

@ -17,9 +17,9 @@ import mage.game.Game;
*/
public class PermanentsOnTheBattlefieldCondition implements Condition {
private final FilterPermanent filter;
private final ComparisonType type;
private final int count;
protected final FilterPermanent filter;
protected final ComparisonType type;
protected final int count;
private final boolean onlyControlled;
/**

View file

@ -9,21 +9,20 @@ import java.util.Objects;
/**
* @author TheElk801
*/
public enum OneOpponentCondition implements Condition {
public enum TwoOrMoreOpponentsCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
return game.getOpponents(source.getControllerId(), true)
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.count() <= 1;
.count() >= 2;
}
@Override
public String toString() {
return "you have one opponent";
return "you have two or more opponents";
}
}

View file

@ -0,0 +1,59 @@
package mage.abilities.condition.common;
import mage.abilities.hint.ConditionHint;
import mage.abilities.hint.Hint;
import mage.constants.ComparisonType;
import mage.filter.FilterPermanent;
import mage.util.CardUtil;
/**
* PermanentsOnTheBattlefieldCondition with onlyControlled parameter at true
* Separate as it has a name closer to card's text, so easier to find.
*
* @author Susucr
*/
public class YouControlPermanentCondition extends PermanentsOnTheBattlefieldCondition {
public Hint getHint() {
return new ConditionHint(this);
}
public YouControlPermanentCondition(FilterPermanent filter) {
this(filter, ComparisonType.OR_GREATER, 1);
}
public YouControlPermanentCondition(FilterPermanent filter, ComparisonType comparisonType, int count) {
super(filter, comparisonType, count, true);
}
@Override
public String toString() {
String text = "you control ";
String filterText = filter.getMessage();
if (filterText.endsWith(" you control")) {
filterText = filterText.substring(0, filterText.length() - " you control".length());
}
switch (type) {
case OR_LESS:
text += CardUtil.numberToText(count) + " or fewer " + filterText;
break;
case OR_GREATER:
if (count == 1) {
text += CardUtil.addArticle(filterText);
} else {
text += CardUtil.numberToText(count) + " or more " + filterText;
}
break;
case EQUAL_TO:
if (count == 0) {
text += "no " + filterText;
} else {
text += "exactly " + CardUtil.numberToText(count) + " " + filterText;
}
break;
default:
throw new IllegalArgumentException("Wrong code usage: ComparisonType not handled in text generation: " + type);
}
return text;
}
}

View file

@ -5,6 +5,7 @@ import mage.abilities.Mode;
import mage.abilities.condition.Condition;
import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.util.CardUtil;
@ -27,8 +28,18 @@ public class ConditionalOneShotEffect extends OneShotEffect {
this(effect, null, condition, text);
}
private static Outcome generateOutcome(OneShotEffect effect, OneShotEffect otherwiseEffect) {
if (effect != null) {
return effect.getOutcome();
}
if (otherwiseEffect != null) {
return Outcome.inverse(otherwiseEffect.getOutcome());
}
throw new IllegalArgumentException("Wrong code usage: ConditionalOneShot should start with an effect to generate Outcome.");
}
public ConditionalOneShotEffect(OneShotEffect effect, OneShotEffect otherwiseEffect, Condition condition, String text) {
super(effect.getOutcome());
super(generateOutcome(effect, otherwiseEffect));
if (effect != null) {
this.effects.add(effect);
}