From d2fb82c0f336123591d873877d5c7c2f17c5b83b Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 25 Jun 2019 19:41:08 -0400 Subject: [PATCH] fixed implementation of Razor Barrier --- Mage.Sets/src/mage/cards/r/RazorBarrier.java | 73 +++++++++----------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/Mage.Sets/src/mage/cards/r/RazorBarrier.java b/Mage.Sets/src/mage/cards/r/RazorBarrier.java index 74562c9e49..c5f502a51b 100644 --- a/Mage.Sets/src/mage/cards/r/RazorBarrier.java +++ b/Mage.Sets/src/mage/cards/r/RazorBarrier.java @@ -1,41 +1,37 @@ - package mage.cards.r; -import java.util.UUID; import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; +import mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.choices.ChoiceColorOrArtifact; import mage.constants.CardType; import mage.constants.Duration; -import mage.filter.FilterCard; +import mage.constants.Outcome; +import mage.filter.FilterObject; import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.players.Player; -import mage.target.Target; import mage.target.common.TargetControlledPermanent; +import java.util.UUID; + /** - * - * @author LevelX2 + * @author TheElk801 */ public final class RazorBarrier extends CardImpl { public RazorBarrier(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{W}"); - + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); // Target permanent you control gains protection from artifacts or from the color of your choice until end of turn. - this.getSpellAbility().addEffect(new RazorBarrierEffect(Duration.EndOfTurn)); - Target target = new TargetControlledPermanent(); - this.getSpellAbility().addTarget(target); + this.getSpellAbility().addEffect(new RazorBarrierEffect()); + this.getSpellAbility().addTarget(new TargetControlledPermanent()); } - public RazorBarrier(final RazorBarrier card) { + private RazorBarrier(final RazorBarrier card) { super(card); } @@ -45,14 +41,21 @@ public final class RazorBarrier extends CardImpl { } } -class RazorBarrierEffect extends GainAbilityTargetEffect { +class RazorBarrierEffect extends OneShotEffect { - public RazorBarrierEffect(Duration duration) { - super(new ProtectionAbility(new FilterCard()), duration); - staticText = "Target permanent you control gains protection from artifacts or from the color of your choice until end of turn"; + private static final FilterObject filter = new FilterObject("colorless"); + + static { + filter.add(new CardTypePredicate(CardType.ARTIFACT)); } - public RazorBarrierEffect(final RazorBarrierEffect effect) { + RazorBarrierEffect() { + super(Outcome.Benefit); + staticText = "Target permanent you control gains protection from artifacts " + + "or from the color of your choice until end of turn."; + } + + private RazorBarrierEffect(final RazorBarrierEffect effect) { super(effect); } @@ -63,27 +66,15 @@ class RazorBarrierEffect extends GainAbilityTargetEffect { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - FilterCard protectionFilter = new FilterCard(); - ChoiceColorOrArtifact choice = new ChoiceColorOrArtifact(); - if (controller.choose(outcome, choice, game)) { - if (choice.isArtifactSelected()) { - protectionFilter.add(new CardTypePredicate(CardType.ARTIFACT)); - } else { - protectionFilter.add(new ColorPredicate(choice.getColor())); - } - - protectionFilter.setMessage(choice.getChoice()); - ((ProtectionAbility) ability).setFilter(protectionFilter); - Permanent creature = game.getPermanent(source.getFirstTarget()); - if (creature != null) { - creature.addAbility(ability, source.getSourceId(), game); - return true; - } - } + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; } - return false; + if (player.chooseUse(outcome, "Give the targeted permanent protection from artifacts?", null, "Yes", "No (choose a color instead)", source, game)) { + game.addEffect(new GainAbilityTargetEffect(new ProtectionAbility(filter), Duration.EndOfTurn), source); + return true; + } + game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source); + return true; } - }