diff --git a/Mage.Sets/src/mage/cards/d/DoubleVision.java b/Mage.Sets/src/mage/cards/d/DoubleVision.java new file mode 100644 index 0000000000..f71749174e --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DoubleVision.java @@ -0,0 +1,86 @@ +package mage.cards.d; + +import mage.abilities.common.SpellCastControllerTriggeredAbility; +import mage.abilities.effects.common.CopyTargetSpellEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.filter.common.FilterInstantOrSorcerySpell; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.stack.Spell; +import mage.target.targetpointer.FixedTarget; +import mage.watchers.common.SpellsCastWatcher; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @author htrajan + */ +public final class DoubleVision extends CardImpl { + + public DoubleVision(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{R}{R}"); + + // Whenever you cast your first instant or sorcery spell each turn, copy that spell. You may choose new targets for the copy. + this.addAbility(new DoubleVisionCopyTriggeredAbility(), new SpellsCastWatcher()); + } + + private DoubleVision(final DoubleVision card) { + super(card); + } + + @Override + public DoubleVision copy() { + return new DoubleVision(this); + } +} + +class DoubleVisionCopyTriggeredAbility extends SpellCastControllerTriggeredAbility { + + DoubleVisionCopyTriggeredAbility() { + super(new CopyTargetSpellEffect(true), new FilterInstantOrSorcerySpell(), false); + } + + DoubleVisionCopyTriggeredAbility(DoubleVisionCopyTriggeredAbility ability) { + super(ability); + } + + @Override + public DoubleVisionCopyTriggeredAbility copy() { + return new DoubleVisionCopyTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (super.checkTrigger(event, game)) { + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (isFirstInstantOrSorceryCastByPlayerOnTurn(spell, game)) { + this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId())); + return true; + } + } + return false; + } + + private boolean isFirstInstantOrSorceryCastByPlayerOnTurn(Spell spell, Game game) { + if (spell != null) { + SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class); + if (watcher != null) { + List eligibleSpells = watcher.getSpellsCastThisTurn(this.getControllerId()) + .stream() + .filter(s -> s.isInstant() || s.isSorcery()) + .collect(Collectors.toList()); + return eligibleSpells.size() == 1 && eligibleSpells.get(0).getId().equals(spell.getId()); + } + } + return false; + } + + @Override + public String getRule() { + return "Whenever you cast your first instant or sorcery spell each turn, copy that spell. You may choose new targets for the copy."; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/CoreSet2021.java b/Mage.Sets/src/mage/sets/CoreSet2021.java index e168cdd015..92bf871119 100644 --- a/Mage.Sets/src/mage/sets/CoreSet2021.java +++ b/Mage.Sets/src/mage/sets/CoreSet2021.java @@ -33,6 +33,7 @@ public final class CoreSet2021 extends ExpansionSet { this.ratioBoosterMythic = 8; this.maxCardNumberInBooster = 274; + cards.add(new SetCardInfo("Double Vision", 142, Rarity.RARE, mage.cards.d.DoubleVision.class)); cards.add(new SetCardInfo("Mangara, the Diplomat", 27, Rarity.MYTHIC, mage.cards.m.MangaraTheDiplomat.class)); } }