From ee09285d548f139a479a3ab71250cfda90ee6588 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 2 Nov 2021 19:00:54 -0400 Subject: [PATCH] small reworking to PermanentsOnTheBattlefieldCondition --- .../src/mage/cards/a/AscendantPackleader.java | 2 +- Mage.Sets/src/mage/cards/k/KavuRunner.java | 2 +- Mage.Sets/src/mage/cards/l/Lifeline.java | 2 +- .../src/mage/cards/m/MagnigothTreefolk.java | 10 ++--- Mage.Sets/src/mage/cards/n/NemesisTrap.java | 2 +- Mage.Sets/src/mage/cards/r/ReaverDrone.java | 2 +- Mage.Sets/src/mage/cards/s/Seasinger.java | 12 +++--- Mage.Sets/src/mage/cards/s/SkittishKavu.java | 2 +- .../src/mage/cards/s/StatuteOfDenial.java | 2 +- .../src/mage/cards/t/TenaciousHunter.java | 4 +- Mage.Sets/src/mage/cards/t/TideShaper.java | 2 +- .../PermanentsOnTheBattlefieldCondition.java | 42 ++++--------------- 12 files changed, 29 insertions(+), 55 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AscendantPackleader.java b/Mage.Sets/src/mage/cards/a/AscendantPackleader.java index 2024725547b..21d87ecc1c0 100644 --- a/Mage.Sets/src/mage/cards/a/AscendantPackleader.java +++ b/Mage.Sets/src/mage/cards/a/AscendantPackleader.java @@ -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" )); diff --git a/Mage.Sets/src/mage/cards/k/KavuRunner.java b/Mage.Sets/src/mage/cards/k/KavuRunner.java index 6662584229d..45c08991051 100644 --- a/Mage.Sets/src/mage/cards/k/KavuRunner.java +++ b/Mage.Sets/src/mage/cards/k/KavuRunner.java @@ -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"))); } diff --git a/Mage.Sets/src/mage/cards/l/Lifeline.java b/Mage.Sets/src/mage/cards/l/Lifeline.java index e828d0daa6c..a605b975ceb 100644 --- a/Mage.Sets/src/mage/cards/l/Lifeline.java +++ b/Mage.Sets/src/mage/cards/l/Lifeline.java @@ -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); } diff --git a/Mage.Sets/src/mage/cards/m/MagnigothTreefolk.java b/Mage.Sets/src/mage/cards/m/MagnigothTreefolk.java index 93b0353f422..422bad620d0 100644 --- a/Mage.Sets/src/mage/cards/m/MagnigothTreefolk.java +++ b/Mage.Sets/src/mage/cards/m/MagnigothTreefolk.java @@ -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); } diff --git a/Mage.Sets/src/mage/cards/n/NemesisTrap.java b/Mage.Sets/src/mage/cards/n/NemesisTrap.java index d86c393656e..96ffeac5a85 100644 --- a/Mage.Sets/src/mage/cards/n/NemesisTrap.java +++ b/Mage.Sets/src/mage/cards/n/NemesisTrap.java @@ -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()); diff --git a/Mage.Sets/src/mage/cards/r/ReaverDrone.java b/Mage.Sets/src/mage/cards/r/ReaverDrone.java index 91699d555c0..457909fbb30 100644 --- a/Mage.Sets/src/mage/cards/r/ReaverDrone.java +++ b/Mage.Sets/src/mage/cards/r/ReaverDrone.java @@ -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)); } diff --git a/Mage.Sets/src/mage/cards/s/Seasinger.java b/Mage.Sets/src/mage/cards/s/Seasinger.java index 229e667271e..24f16be1592 100644 --- a/Mage.Sets/src/mage/cards/s/Seasinger.java +++ b/Mage.Sets/src/mage/cards/s/Seasinger.java @@ -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)); diff --git a/Mage.Sets/src/mage/cards/s/SkittishKavu.java b/Mage.Sets/src/mage/cards/s/SkittishKavu.java index 769ac48fb37..86d2e590e2e 100644 --- a/Mage.Sets/src/mage/cards/s/SkittishKavu.java +++ b/Mage.Sets/src/mage/cards/s/SkittishKavu.java @@ -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"))); } diff --git a/Mage.Sets/src/mage/cards/s/StatuteOfDenial.java b/Mage.Sets/src/mage/cards/s/StatuteOfDenial.java index c81b0c419c3..794d2716ad5 100644 --- a/Mage.Sets/src/mage/cards/s/StatuteOfDenial.java +++ b/Mage.Sets/src/mage/cards/s/StatuteOfDenial.java @@ -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")); } diff --git a/Mage.Sets/src/mage/cards/t/TenaciousHunter.java b/Mage.Sets/src/mage/cards/t/TenaciousHunter.java index b6aec6dc1df..bf1e7677678 100644 --- a/Mage.Sets/src/mage/cards/t/TenaciousHunter.java +++ b/Mage.Sets/src/mage/cards/t/TenaciousHunter.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/t/TideShaper.java b/Mage.Sets/src/mage/cards/t/TideShaper.java index 2c42a2c3154..a3a9b830944 100644 --- a/Mage.Sets/src/mage/cards/t/TideShaper.java +++ b/Mage.Sets/src/mage/cards/t/TideShaper.java @@ -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) { diff --git a/Mage/src/main/java/mage/abilities/condition/common/PermanentsOnTheBattlefieldCondition.java b/Mage/src/main/java/mage/abilities/condition/common/PermanentsOnTheBattlefieldCondition.java index 6e7c0a161e8..0643c27dd8a 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/PermanentsOnTheBattlefieldCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/PermanentsOnTheBattlefieldCondition.java @@ -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