foul-magics/Mage.Sets/src/mage/cards/d/DeflectingPalm.java
Susucre a6ca052106 refactor one-use prevention effect for a chosen source
fixes a few bugs along the way:

[[Pilgrim and Justice]] & [[Pilgrim of Virue]] were incorrectly adding a "to you" to their damage clause.
[[Ajani's Aid]] was improperly a one-use prevention effect.

[[Story Circle]] and [[Prismatic Circle]] have not been refactor as it is not currently possible to have a proper filter for them. Would require a FilterSource with a 4-argument match most likely.
2025-06-10 19:45:02 -07:00

64 lines
No EOL
2.2 KiB
Java

package mage.cards.d;
import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectData;
import mage.abilities.effects.common.PreventNextDamageFromChosenSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.target.TargetSource;
import java.util.UUID;
/**
* @author LevelX2
*/
public final class DeflectingPalm extends CardImpl {
public DeflectingPalm(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{R}{W}");
// The next time a source of your choice would deal damage to you this turn, prevent that damage. If damage is prevented this way, Deflecting Palm deals that much damage to that source's controller.
this.getSpellAbility().addEffect(
new PreventNextDamageFromChosenSourceEffect(
Duration.EndOfTurn, true,
DeflectingPalmPreventionApplier.instance
)
);
}
private DeflectingPalm(final DeflectingPalm card) {
super(card);
}
@Override
public DeflectingPalm copy() {
return new DeflectingPalm(this);
}
}
enum DeflectingPalmPreventionApplier implements PreventNextDamageFromChosenSourceEffect.ApplierOnPrevention {
instance;
public boolean apply(PreventionEffectData data, TargetSource targetSource, GameEvent event, Ability source, Game game) {
if (data == null || data.getPreventedDamage() <= 0) {
return false;
}
int prevented = data.getPreventedDamage();
UUID objectControllerId = game.getControllerId(targetSource.getFirstTarget());
Player objectController = game.getPlayer(objectControllerId);
if (objectController == null) {
return false;
}
objectController.damage(prevented, source.getSourceId(), source, game);
return true;
}
public String getText() {
return "If damage is prevented this way, {this} deals that much damage to that source's controller";
}
}