small reworking to PermanentsOnTheBattlefieldCondition

This commit is contained in:
Evan Kranzler 2021-11-02 19:00:54 -04:00
parent a85560a012
commit ee09285d54
12 changed files with 29 additions and 55 deletions

View file

@ -40,7 +40,7 @@ public final class AscendantPackleader extends CardImpl {
// Ascendant Packleader enters the battlefield with a +1/+1 counter on it if you control a permanent with mana value 4 or greater.
this.addAbility(new EntersBattlefieldAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance()),
new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filter),
null,
"with a +1/+1 counter on it if you control a permanent with mana value 4 or greater"
));

View file

@ -44,7 +44,7 @@ public final class KavuRunner extends CardImpl {
// Kavu Runner has haste as long as no opponent controls a white or blue creature.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new ConditionalContinuousEffect(new GainAbilitySourceEffect(HasteAbility.getInstance(),
Duration.WhileOnBattlefield), new InvertCondition(new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, false)),
Duration.WhileOnBattlefield), new InvertCondition(new PermanentsOnTheBattlefieldCondition(filter, false)),
"{this} has haste as long as no opponent controls a white or blue creature")));
}

View file

@ -31,7 +31,7 @@ public final class Lifeline extends CardImpl {
// Whenever a creature dies, if another creature is on the battlefield, return the first card to the battlefield under its owner's control at the beginning of the next end step.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new DiesCreatureTriggeredAbility(Zone.BATTLEFIELD, new LifelineEffect(), false, StaticFilters.FILTER_PERMANENT_CREATURE, true),
new PermanentsOnTheBattlefieldCondition(StaticFilters.FILTER_PERMANENT_CREATURE, ComparisonType.MORE_THAN, 0, false),
new PermanentsOnTheBattlefieldCondition(StaticFilters.FILTER_PERMANENT_CREATURE, false),
"Whenever a creature dies, if another creature is on the battlefield, return the first card to the battlefield under its owner's control at the beginning of the next end step.");
this.addAbility(ability);
}

View file

@ -40,23 +40,23 @@ public final class MagnigothTreefolk extends CardImpl {
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD,
new ConditionalContinuousEffect(
new GainAbilitySourceEffect(new PlainswalkAbility()),
new PermanentsOnTheBattlefieldCondition(filterPlains, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filterPlains),
"Domain — For each basic land type among lands you control, {this} has landwalk of that type."));
ability.addEffect(new ConditionalContinuousEffect(
new GainAbilitySourceEffect(new IslandwalkAbility(), Duration.WhileOnBattlefield, false, true),
new PermanentsOnTheBattlefieldCondition(filterIsland, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filterIsland),
""));
ability.addEffect(new ConditionalContinuousEffect(
new GainAbilitySourceEffect(new SwampwalkAbility(), Duration.WhileOnBattlefield, false, true),
new PermanentsOnTheBattlefieldCondition(filterSwamp, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filterSwamp),
""));
ability.addEffect(new ConditionalContinuousEffect(
new GainAbilitySourceEffect(new MountainwalkAbility(), Duration.WhileOnBattlefield, false, true),
new PermanentsOnTheBattlefieldCondition(filterMountain, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filterMountain),
""));
ability.addEffect(new ConditionalContinuousEffect(
new GainAbilitySourceEffect(new ForestwalkAbility(), Duration.WhileOnBattlefield, false, true),
new PermanentsOnTheBattlefieldCondition(filterForest, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filterForest),
""));
this.addAbility(ability);
}

View file

@ -44,7 +44,7 @@ public final class NemesisTrap extends CardImpl {
this.subtype.add(SubType.TRAP);
// If a white creature is attacking, you may pay {B}{B} rather than pay Nemesis Trap's mana cost.
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{B}{B}"), new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, false)));
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{B}{B}"), new PermanentsOnTheBattlefieldCondition(filter, false)));
// Exile target attacking creature. Create a token that's a copy of that creature. Exile it at the beginning of the next end step.
this.getSpellAbility().addEffect(new NemesisTrapEffect());

View file

@ -45,7 +45,7 @@ public final class ReaverDrone extends CardImpl {
// At the beginning of your upkeep, you lose 1 life unless you control another colorless creature.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new ConditionalOneShotEffect(
new LoseLifeSourceControllerEffect(1),
new InvertCondition(new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, true)),
new InvertCondition(new PermanentsOnTheBattlefieldCondition(filter)),
"you lose 1 life unless you control another colorless creature"), TargetController.YOU, false));
}

View file

@ -1,12 +1,12 @@
package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.ControlsPermanentsControllerTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SkipUntapOptionalAbility;
import mage.abilities.condition.CompoundCondition;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
import mage.abilities.condition.common.SourceTappedCondition;
import mage.abilities.costs.common.TapSourceCost;
@ -23,8 +23,9 @@ import mage.filter.predicate.mageobject.CardIdPredicate;
import mage.filter.predicate.permanent.ControllerControlsIslandPredicate;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class Seasinger extends CardImpl {
@ -39,7 +40,7 @@ public final class Seasinger extends CardImpl {
}
public Seasinger(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{U}");
this.subtype.add(SubType.MERFOLK);
this.power = new MageInt(0);
@ -48,6 +49,7 @@ public final class Seasinger extends CardImpl {
FilterPermanent seasinger = new FilterPermanent();
seasinger.add(TargetController.YOU.getControllerPredicate());
seasinger.add(new CardIdPredicate(this.getId()));
Condition condition = new CompoundCondition(new PermanentsOnTheBattlefieldCondition(seasinger, ComparisonType.EQUAL_TO, 1), SourceTappedCondition.instance);
// When you control no Islands, sacrifice Seasinger.
this.addAbility(new ControlsPermanentsControllerTriggeredAbility(
@ -60,7 +62,7 @@ public final class Seasinger extends CardImpl {
// {tap}: Gain control of target creature whose controller controls an Island for as long as you control Seasinger and Seasinger remains tapped.
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(
new GainControlTargetEffect(Duration.Custom),
new PermanentsOnTheBattlefieldCondition(seasinger, ComparisonType.EQUAL_TO, 1, SourceTappedCondition.instance), rule);
condition, rule);
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new TapSourceCost());
creatureWhoseControllerControlsIsland.add(new ControllerControlsIslandPredicate());
ability.addTarget(new TargetCreaturePermanent(creatureWhoseControllerControlsIsland));

View file

@ -43,7 +43,7 @@ public final class SkittishKavu extends CardImpl {
// Skittish Kavu gets +1/+1 as long as no opponent controls a white or blue creature.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new ConditionalContinuousEffect(new BoostSourceEffect(1, 1, Duration.WhileOnBattlefield),
new InvertCondition(new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, false)),
new InvertCondition(new PermanentsOnTheBattlefieldCondition(filter, false)),
"{this} gets +1/+1 as long as no opponent controls a white or blue creature")));
}

View file

@ -36,7 +36,7 @@ public final class StatuteOfDenial extends CardImpl {
this.getSpellAbility().addTarget(new TargetSpell());
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
new DrawDiscardControllerEffect(1,1),
new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, true),
new PermanentsOnTheBattlefieldCondition(filter),
"If you control a blue creature, draw a card, then discard a card"));
}

View file

@ -41,11 +41,11 @@ public final class TenaciousHunter extends CardImpl {
// As long as a creature has a -1/-1 counter on it, Tenacious Hunter has vigilance and deathtouch.
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD,
new ConditionalContinuousEffect(new GainAbilitySourceEffect(VigilanceAbility.getInstance()),
new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, false),
new PermanentsOnTheBattlefieldCondition(filter, false),
"As long as a creature has a -1/-1 counter on it, {this} has vigilance"));
ability.addEffect(new ConditionalContinuousEffect(new GainAbilitySourceEffect(DeathtouchAbility.getInstance()),
new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, false),
new PermanentsOnTheBattlefieldCondition(filter, false),
"and deathtouch"));
this.addAbility(ability);

View file

@ -35,7 +35,7 @@ public final class TideShaper extends CardImpl {
filter.add(TargetController.OPPONENT.getControllerPredicate());
}
private static final Condition condition = new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 0, false);
private static final Condition condition = new PermanentsOnTheBattlefieldCondition(filter, false);
private static final Hint hint = new ConditionHint(condition);
public TideShaper(UUID ownerId, CardSetInfo setInfo) {

View file

@ -14,12 +14,10 @@ import mage.game.Game;
* @author nantuko
* @author maurer.it_at_gmail.com
* @see #Controls(mage.filter.Filter)
* @see #Controls(mage.filter.Filter, mage.abilities.condition.Condition)
*/
public class PermanentsOnTheBattlefieldCondition implements Condition {
private final FilterPermanent filter;
private final Condition condition;
private final ComparisonType type;
private final int count;
private final boolean onlyControlled;
@ -58,46 +56,20 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
this.type = type;
this.count = count;
this.onlyControlled = onlyControlled;
this.condition = null;
}
/**
* 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.
*
* @param filter
* @param type
* @param count
* @param conditionToDecorate
*/
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, ComparisonType type, int count, Condition conditionToDecorate) {
this.filter = filter;
this.type = type;
this.count = count;
this.onlyControlled = true;
this.condition = conditionToDecorate;
}
@Override
public boolean apply(Game game, Ability source) {
boolean conditionApplies;
FilterPermanent localFilter = filter.copy();
FilterPermanent localFilter;
if (onlyControlled) {
localFilter = filter.copy();
localFilter.add(new ControllerIdPredicate(source.getControllerId()));
} else {
localFilter = filter;
}
int permanentsOnBattlefield = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game);
conditionApplies = ComparisonType.compare(permanentsOnBattlefield, type, count);
//If a decorated condition exists, check it as well and apply them together.
if (this.condition != null) {
conditionApplies = conditionApplies && this.condition.apply(game, source);
}
return conditionApplies;
return ComparisonType.compare(game.getBattlefield().count(
localFilter, source.getSourceId(), source.getControllerId(), game
), type, count);
}
@Override