fixed implementation of Razor Barrier

This commit is contained in:
Evan Kranzler 2019-06-25 19:41:08 -04:00
parent 78389c073f
commit d2fb82c0f3

View file

@ -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;
}
}