From e2dfa61fa6771339a5639b98cf13651689fe30d3 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Tue, 31 Oct 2017 16:35:04 +0100 Subject: [PATCH] Fix for #4137 --- Mage.Sets/src/mage/cards/p/PaleWayfarer.java | 71 ++++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/Mage.Sets/src/mage/cards/p/PaleWayfarer.java b/Mage.Sets/src/mage/cards/p/PaleWayfarer.java index ea50659cbf7..60b860f48f0 100644 --- a/Mage.Sets/src/mage/cards/p/PaleWayfarer.java +++ b/Mage.Sets/src/mage/cards/p/PaleWayfarer.java @@ -29,27 +29,36 @@ package mage.cards.p; import java.util.UUID; import mage.MageInt; +import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.UntapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; import mage.constants.CardType; import mage.constants.SubType; +import mage.constants.Duration; +import mage.constants.Layer; import mage.constants.Outcome; +import mage.constants.SubLayer; import mage.constants.Zone; +import mage.filter.FilterObject; +import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetCreaturePermanent; +import mage.target.targetpointer.FixedTarget; /** * - * @author jeffwadsworth - * + * @author jeffwadsworth & L_J */ public class PaleWayfarer extends CardImpl { @@ -91,8 +100,8 @@ class PaleWayfarerEffect extends OneShotEffect { } @Override - public boolean apply(Game game, Ability source) { - Permanent targetCreature = game.getPermanent(source.getFirstTarget()); + public boolean apply(Game game, Ability source + Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); if (targetCreature != null) { Player player = game.getPlayer(targetCreature.getControllerId()); if (player != null) { @@ -100,6 +109,13 @@ class PaleWayfarerEffect extends OneShotEffect { if (player.choose(Outcome.Neutral, colorChoice, game)) { game.informPlayers(targetCreature.getName() + ": " + player.getLogName() + " has chosen " + colorChoice.getChoice()); game.getState().setValue(targetCreature.getId() + "_color", colorChoice.getColor()); + + ObjectColor protectColor = (ObjectColor) game.getState().getValue(targetCreature.getId() + "_color"); + if (protectColor != null) { + ContinuousEffect effect = new ProtectionChosenColorTargetEffect(); + effect.setTargetPointer(new FixedTarget(targetCreature, game)); + game.addEffect(effect, source); + } } } } @@ -110,4 +126,49 @@ class PaleWayfarerEffect extends OneShotEffect { public PaleWayfarerEffect copy() { return new PaleWayfarerEffect(this); } -} \ No newline at end of file +} + + +class ProtectionChosenColorTargetEffect extends ContinuousEffectImpl { + + protected ObjectColor chosenColor; + protected ProtectionAbility protectionAbility; + + public ProtectionChosenColorTargetEffect() { + super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + } + + public ProtectionChosenColorTargetEffect(final ProtectionChosenColorTargetEffect effect) { + super(effect); + if (effect.chosenColor != null) { + this.chosenColor = effect.chosenColor.copy(); + } + if (effect.protectionAbility != null) { + this.protectionAbility = effect.protectionAbility.copy(); + } + } + + @Override + public ProtectionChosenColorTargetEffect copy() { + return new ProtectionChosenColorTargetEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (permanent != null) { + ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color"); + if (color != null && (protectionAbility == null || !color.equals(chosenColor))) { + chosenColor = color; + FilterObject protectionFilter = new FilterObject(chosenColor.getDescription()); + protectionFilter.add(new ColorPredicate(chosenColor)); + protectionAbility = new ProtectionAbility(protectionFilter); + } + if (protectionAbility != null) { + permanent.addAbility(protectionAbility, source.getSourceId(), game); + return true; + } + } + return false; + } +}