diff --git a/Mage.Sets/src/mage/cards/n/NissaGenesisMage.java b/Mage.Sets/src/mage/cards/n/NissaGenesisMage.java index 1ec5a10b4c3..c3e4e70a211 100644 --- a/Mage.Sets/src/mage/cards/n/NissaGenesisMage.java +++ b/Mage.Sets/src/mage/cards/n/NissaGenesisMage.java @@ -1,10 +1,10 @@ - package mage.cards.n; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.dynamicvalue.common.StaticValue; +import mage.abilities.effects.Effect; import mage.abilities.effects.common.LookLibraryAndPickControllerEffect; import mage.abilities.effects.common.UntapTargetEffect; import mage.abilities.effects.common.continuous.BoostTargetEffect; @@ -20,6 +20,7 @@ import mage.filter.StaticFilters; import mage.filter.predicate.Predicates; import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetLandPermanent; +import mage.target.targetpointer.EachTargetPointer; /** * @@ -44,7 +45,9 @@ public final class NissaGenesisMage extends CardImpl { this.setStartingLoyalty(5); //+2: Untap up to two target creatures and up to two target lands. - Ability ability = new LoyaltyAbility(new UntapTargetEffect(false).setText("Untap up to two target creatures and up to two target lands"), +2); + Effect effect = new UntapTargetEffect("untap up to two target creatures and up to two target lands"); + effect.setTargetPointer(new EachTargetPointer()); + Ability ability = new LoyaltyAbility(effect, +2); ability.addTarget(new TargetCreaturePermanent(0, 2, StaticFilters.FILTER_PERMANENT_CREATURES, false)); ability.addTarget(new TargetLandPermanent(0, 2, StaticFilters.FILTER_LANDS, false)); this.addAbility(ability); diff --git a/Mage.Sets/src/mage/cards/r/RealitySpasm.java b/Mage.Sets/src/mage/cards/r/RealitySpasm.java index 8c145d24001..7826915199f 100644 --- a/Mage.Sets/src/mage/cards/r/RealitySpasm.java +++ b/Mage.Sets/src/mage/cards/r/RealitySpasm.java @@ -1,34 +1,31 @@ - package mage.cards.r; -import java.util.List; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.Mode; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.TapTargetEffect; +import mage.abilities.effects.common.UntapTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.filter.FilterPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; +import mage.target.targetadjustment.XTargetsAdjuster; /** * - * @author jeffwadsworth + * @author awjackson */ public final class RealitySpasm extends CardImpl { public RealitySpasm(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{X}{U}{U}"); - // Choose one - Tap X target permanents; or untap X target permanents. - this.getSpellAbility().addEffect(new RealitySpasmTapEffect()); - Mode mode = new Mode(new RealitySpasmUntapEffect()); + this.getSpellAbility().addEffect(new TapTargetEffect("tap X target permanents")); + this.getSpellAbility().addTarget(new TargetPermanent()); + Mode mode = new Mode(new UntapTargetEffect("untap X target permanents")); + mode.addTarget(new TargetPermanent()); this.getSpellAbility().addMode(mode); + this.getSpellAbility().setTargetAdjuster(XTargetsAdjuster.instance); } private RealitySpasm(final RealitySpasm card) { @@ -40,83 +37,3 @@ public final class RealitySpasm extends CardImpl { return new RealitySpasm(this); } } - -class RealitySpasmTapEffect extends OneShotEffect { - - private static final FilterPermanent filter = new FilterPermanent("permanent"); - - public RealitySpasmTapEffect() { - super(Outcome.Tap); - staticText = "Tap X target permanents"; - } - - public RealitySpasmTapEffect(final RealitySpasmTapEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - int numberToTap = source.getManaCostsToPay().getX(); - numberToTap = Math.min(game.getBattlefield().getAllActivePermanents().size(), numberToTap); - TargetPermanent target = new TargetPermanent(numberToTap, filter); - if (target.canChoose(source.getControllerId(), source, game) && target.choose(Outcome.Tap, source.getControllerId(), source.getSourceId(), source, game)) { - if (!target.getTargets().isEmpty()) { - List targets = target.getTargets(); - for (UUID targetId : targets) { - Permanent permanent = game.getPermanent(targetId); - if (permanent != null) { - permanent.tap(source, game); - } - } - } - return true; - } - return false; - } - - @Override - public RealitySpasmTapEffect copy() { - return new RealitySpasmTapEffect(this); - } - -} - -class RealitySpasmUntapEffect extends OneShotEffect { - - private static final FilterPermanent filter = new FilterPermanent("permanent"); - - public RealitySpasmUntapEffect() { - super(Outcome.Untap); - staticText = "Untap X target permanents"; - } - - public RealitySpasmUntapEffect(final RealitySpasmUntapEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - int numberToTap = source.getManaCostsToPay().getX(); - numberToTap = Math.min(game.getBattlefield().getAllActivePermanents().size(), numberToTap); - TargetPermanent target = new TargetPermanent(numberToTap, filter); - if (target.canChoose(source.getControllerId(), source, game) && target.choose(Outcome.Untap, source.getControllerId(), source.getSourceId(), source, game)) { - if (!target.getTargets().isEmpty()) { - List targets = target.getTargets(); - for (UUID targetId : targets) { - Permanent permanent = game.getPermanent(targetId); - if (permanent != null) { - permanent.untap(game); - } - } - } - return true; - } - return false; - } - - @Override - public RealitySpasmUntapEffect copy() { - return new RealitySpasmUntapEffect(this); - } - -} diff --git a/Mage/src/main/java/mage/abilities/effects/common/UntapTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/UntapTargetEffect.java index 2c7d0601446..41595adeb20 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/UntapTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/UntapTargetEffect.java @@ -16,20 +16,19 @@ import java.util.UUID; */ public class UntapTargetEffect extends OneShotEffect { - protected boolean useOnlyTargetPointer; - public UntapTargetEffect() { - this(true); + this((String) null); } - public UntapTargetEffect(boolean useOnlyTargetPointer) { + public UntapTargetEffect(String text) { super(Outcome.Untap); - this.useOnlyTargetPointer = useOnlyTargetPointer; + if (text != null) { + this.staticText = text; + } } public UntapTargetEffect(final UntapTargetEffect effect) { super(effect); - this.useOnlyTargetPointer = effect.useOnlyTargetPointer; } @Override @@ -39,21 +38,10 @@ public class UntapTargetEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - if (!useOnlyTargetPointer && source.getTargets().size() > 1) { - source.getTargets().forEach((target) -> { - for (UUID targetId : target.getTargets()) { - Permanent permanent = game.getPermanent(targetId); - if (permanent != null) { - permanent.untap(game); - } - } - }); - } else { - for (UUID target : targetPointer.getTargets(game, source)) { - Permanent permanent = game.getPermanent(target); - if (permanent != null) { - permanent.untap(game); - } + for (UUID target : targetPointer.getTargets(game, source)) { + Permanent permanent = game.getPermanent(target); + if (permanent != null) { + permanent.untap(game); } } return true; @@ -88,4 +76,4 @@ public class UntapTargetEffect extends OneShotEffect { return sb.toString(); } -} \ No newline at end of file +}