implement [MH3] Invert Polarity

This commit is contained in:
Susucre 2024-06-04 17:14:59 +02:00
parent d350485d64
commit b7d376a559
2 changed files with 103 additions and 0 deletions

View file

@ -0,0 +1,102 @@
package mage.cards.i;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CounterTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.target.TargetSpell;
import java.util.UUID;
/**
* @author Susucr
*/
public final class InvertPolarity extends CardImpl {
public InvertPolarity(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{U}{U}{R}");
// Choose target spell, then flip a coin. If you win the flip, gain control of that spell and you may choose new targets for it. If you lose the flip, counter that spell.
this.getSpellAbility().addTarget(new TargetSpell());
this.getSpellAbility().addEffect(new InvertPolarityTargetEffect());
}
private InvertPolarity(final InvertPolarity card) {
super(card);
}
@Override
public InvertPolarity copy() {
return new InvertPolarity(this);
}
}
class InvertPolarityTargetEffect extends OneShotEffect {
InvertPolarityTargetEffect() {
super(Outcome.Detriment);
staticText = "choose target spell, then flip a coin. If you win the flip, gain control of that spell "
+ "and you may choose new targets for it. If you lose the flip, counter that spell";
}
private InvertPolarityTargetEffect(final InvertPolarityTargetEffect effect) {
super(effect);
}
@Override
public InvertPolarityTargetEffect copy() {
return new InvertPolarityTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
if (player.flipCoin(source, game, true)) {
new InvertPolarityGainControlTargetEffect()
.setTargetPointer(getTargetPointer().copy())
.apply(game, source);
} else {
new CounterTargetEffect()
.setTargetPointer(getTargetPointer().copy())
.apply(game, source);
}
return true;
}
}
class InvertPolarityGainControlTargetEffect extends OneShotEffect {
InvertPolarityGainControlTargetEffect() {
super(Outcome.GainControl);
}
private InvertPolarityGainControlTargetEffect(final InvertPolarityGainControlTargetEffect effect) {
super(effect);
}
@Override
public InvertPolarityGainControlTargetEffect copy() {
return new InvertPolarityGainControlTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (controller != null && spell != null) {
spell.setControllerId(controller.getId());
spell.chooseNewTargets(game, controller.getId(), false, false, null);
return true;
}
return false;
}
}

View file

@ -147,6 +147,7 @@ public final class ModernHorizons3 extends ExpansionSet {
cards.add(new SetCardInfo("Infernal Captor", 125, Rarity.COMMON, mage.cards.i.InfernalCaptor.class));
cards.add(new SetCardInfo("Inspired Inventor", 32, Rarity.COMMON, mage.cards.i.InspiredInventor.class));
cards.add(new SetCardInfo("Inventor's Axe", 126, Rarity.COMMON, mage.cards.i.InventorsAxe.class));
cards.add(new SetCardInfo("Invert Polarity", 190, Rarity.RARE, mage.cards.i.InvertPolarity.class));
cards.add(new SetCardInfo("Island", 305, Rarity.LAND, mage.cards.basiclands.Island.class, FULL_ART_BFZ_VARIOUS));
cards.add(new SetCardInfo("It That Heralds the End", 9, Rarity.UNCOMMON, mage.cards.i.ItThatHeraldsTheEnd.class));
cards.add(new SetCardInfo("Izzet Generatorium", 191, Rarity.UNCOMMON, mage.cards.i.IzzetGeneratorium.class));