[MIR] Implemented Meddle

This commit is contained in:
Evan Kranzler 2021-01-28 15:03:13 -05:00
parent 8a4bc80fa8
commit 88b8efefe5
3 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,91 @@
package mage.cards.m;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.target.Target;
import mage.target.TargetSpell;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class Meddle extends CardImpl {
public Meddle(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}");
// If target spell has only one target and that target is a creature, change that spell's target to another creature.
this.getSpellAbility().addEffect(new MeddleEffect());
this.getSpellAbility().addTarget(new TargetSpell());
}
private Meddle(final Meddle card) {
super(card);
}
@Override
public Meddle copy() {
return new Meddle(this);
}
}
class MeddleEffect extends OneShotEffect {
MeddleEffect() {
super(Outcome.Benefit);
staticText = "If target spell has only one target and that target is a creature, " +
"change that spell's target to another creature.";
}
private MeddleEffect(final MeddleEffect effect) {
super(effect);
}
@Override
public MeddleEffect copy() {
return new MeddleEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
if (!checkTarget(game, source)) {
return false;
}
Spell spell = game.getSpell(source.getFirstTarget());
spell.chooseNewTargets(game, source.getControllerId(), true, false, null);
return true;
}
private static final boolean checkTarget(Game game, Ability source) {
StackObject stackObject = game.getState().getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
int numberOfTargets = 0;
for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
Mode mode = stackObject.getStackAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) {
for (UUID targetId : target.getTargets()) {
if (numberOfTargets++ > 1) {
return false;
}
Permanent permanent = game.getPermanent(targetId);
if (permanent == null || !permanent.isCreature()) {
return false;
}
}
}
}
return numberOfTargets == 1;
}
}

View file

@ -194,6 +194,7 @@ public final class Mirage extends ExpansionSet {
cards.add(new SetCardInfo("Mangara's Tome", 309, Rarity.RARE, mage.cards.m.MangarasTome.class));
cards.add(new SetCardInfo("Marble Diamond", 310, Rarity.UNCOMMON, mage.cards.m.MarbleDiamond.class));
cards.add(new SetCardInfo("Maro", 228, Rarity.RARE, mage.cards.m.Maro.class));
cards.add(new SetCardInfo("Meddle", 73, Rarity.UNCOMMON, mage.cards.m.Meddle.class));
cards.add(new SetCardInfo("Melesse Spirit", 27, Rarity.UNCOMMON, mage.cards.m.MelesseSpirit.class));
cards.add(new SetCardInfo("Memory Lapse", 74, Rarity.COMMON, mage.cards.m.MemoryLapse.class));
cards.add(new SetCardInfo("Merfolk Raiders", 75, Rarity.COMMON, mage.cards.m.MerfolkRaiders.class));

View file

@ -207,6 +207,7 @@ public final class Onslaught extends ExpansionSet {
cards.add(new SetCardInfo("Lonely Sandbar", 320, Rarity.COMMON, mage.cards.l.LonelySandbar.class));
cards.add(new SetCardInfo("Mage's Guile", 91, Rarity.COMMON, mage.cards.m.MagesGuile.class));
cards.add(new SetCardInfo("Mana Echoes", 218, Rarity.RARE, mage.cards.m.ManaEchoes.class));
cards.add(new SetCardInfo("Meddle", 92, Rarity.UNCOMMON, mage.cards.m.Meddle.class));
cards.add(new SetCardInfo("Menacing Ogre", 219, Rarity.RARE, mage.cards.m.MenacingOgre.class));
cards.add(new SetCardInfo("Misery Charm", 158, Rarity.COMMON, mage.cards.m.MiseryCharm.class));
cards.add(new SetCardInfo("Mistform Dreamer", 93, Rarity.COMMON, mage.cards.m.MistformDreamer.class));