diff --git a/Mage.Sets/src/mage/cards/h/HealingGrace.java b/Mage.Sets/src/mage/cards/h/HealingGrace.java index 5af0a8cea08..c6f603abddf 100644 --- a/Mage.Sets/src/mage/cards/h/HealingGrace.java +++ b/Mage.Sets/src/mage/cards/h/HealingGrace.java @@ -28,12 +28,17 @@ package mage.cards.h; import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.effects.common.GainLifeEffect; -import mage.abilities.effects.common.PreventDamageToTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.TargetSource; import mage.target.common.TargetAnyTarget; /** @@ -46,9 +51,7 @@ public class HealingGrace extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{W}"); // Prevent the next 3 damage that would be dealt to any target this turn by a source of your choice. You gain 3 life. - this.getSpellAbility().addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, 3) - .setText("Prevent the next 3 damage that would be dealt to any target this turn by a source of your choice.") - ); + this.getSpellAbility().addEffect(new HealingGraceEffect()); this.getSpellAbility().addEffect(new GainLifeEffect(3)); this.getSpellAbility().addTarget(new TargetAnyTarget()); } @@ -62,3 +65,45 @@ public class HealingGrace extends CardImpl { return new HealingGrace(this); } } + +class HealingGraceEffect extends PreventionEffectImpl { + + protected final TargetSource targetSource; + + public HealingGraceEffect() { + super(Duration.EndOfTurn, 3, false); + this.targetSource = new TargetSource(); + this.staticText = "Prevent the next 3 damage that would be dealt to any target this turn by a source of your choice"; + } + + public HealingGraceEffect(final HealingGraceEffect effect) { + super(effect); + this.targetSource = effect.targetSource.copy(); + } + + @Override + public HealingGraceEffect copy() { + return new HealingGraceEffect(this); + } + + @Override + public void init(Ability source, Game game) { + this.targetSource.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + preventDamageAction(event, source, game); + return false; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (super.applies(event, source, game)) { + if (event.getTargetId().equals(source.getFirstTarget()) && event.getSourceId().equals(targetSource.getFirstTarget())) { + return true; + } + } + return false; + } +}