fixed Healing Grace not preventing damage correctly (fixes #4840 and #4852)

This commit is contained in:
Evan Kranzler 2018-04-23 15:37:52 -04:00
parent 944b8f8f43
commit 9a47d13e3e

View file

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