diff --git a/Mage.Sets/src/mage/cards/o/OneWithTheMultiverse.java b/Mage.Sets/src/mage/cards/o/OneWithTheMultiverse.java new file mode 100644 index 00000000000..53ae8926797 --- /dev/null +++ b/Mage.Sets/src/mage/cards/o/OneWithTheMultiverse.java @@ -0,0 +1,125 @@ +package mage.cards.o; + +import mage.MageIdentifier; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.common.continuous.LookAtTopCardOfLibraryAnyTimeEffect; +import mage.abilities.effects.common.continuous.PlayTheTopCardEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; +import mage.util.CardUtil; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class OneWithTheMultiverse extends CardImpl { + + public OneWithTheMultiverse(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{6}{U}{U}"); + + // You may look at the top card of your library any time. + this.addAbility(new SimpleStaticAbility(new LookAtTopCardOfLibraryAnyTimeEffect())); + + // You may play lands and cast spells from the top of your library. + this.addAbility(new SimpleStaticAbility(new PlayTheTopCardEffect())); + + // Once during each of your turns, you may cast a spell from your hand or the top of your library without paying its mana cost. + this.addAbility(new SimpleStaticAbility(new OneWithTheMultiverseEffect()) + .setIdentifier(MageIdentifier.OneWithTheMultiverseWatcher), new OneWithTheMultiverseWatcher()); + } + + private OneWithTheMultiverse(final OneWithTheMultiverse card) { + super(card); + } + + @Override + public OneWithTheMultiverse copy() { + return new OneWithTheMultiverse(this); + } +} + +class OneWithTheMultiverseEffect extends AsThoughEffectImpl { + + public OneWithTheMultiverseEffect() { + super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.WhileOnBattlefield, Outcome.PlayForFree, true); + staticText = "once during each of your turns, you may cast a spell from your hand " + + "or the top of your library without paying its mana cost."; + } + + private OneWithTheMultiverseEffect(final OneWithTheMultiverseEffect effect) { + super(effect); + } + + @Override + public OneWithTheMultiverseEffect copy() { + return new OneWithTheMultiverseEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { + if (!source.isControlledBy(affectedControllerId) || !game.isActivePlayer(source.getControllerId())) { + return false; + } + Player controller = game.getPlayer(source.getControllerId()); + Card card = game.getCard(CardUtil.getMainCardId(game, objectId)); + OneWithTheMultiverseWatcher watcher = game.getState().getWatcher(OneWithTheMultiverseWatcher.class); + if (controller == null + || card == null + || watcher == null + || watcher.isAbilityUsed(new MageObjectReference(source)) + || !card.isOwnedBy(source.getControllerId())) { + return false; + } + Zone zone = game.getState().getZone(card.getId()); + if (!Zone.HAND.match(zone) && + (!Zone.LIBRARY.match(zone) || !controller.getLibrary().getFromTop(game).getId().equals(card.getId()))) { + return false; + } + allowCardToPlayWithoutMana(objectId, source, affectedControllerId, game); + return true; + } +} + +class OneWithTheMultiverseWatcher extends Watcher { + + private final Set usedFrom = new HashSet<>(); + + public OneWithTheMultiverseWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.SPELL_CAST + && event.hasApprovingIdentifier(MageIdentifier.OneWithTheMultiverseWatcher)) { + usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference()); + } + } + + @Override + public void reset() { + super.reset(); + usedFrom.clear(); + } + + public boolean isAbilityUsed(MageObjectReference mor) { + return usedFrom.contains(mor); + } +} diff --git a/Mage.Sets/src/mage/sets/TheBrothersWar.java b/Mage.Sets/src/mage/sets/TheBrothersWar.java index e01c864f2b9..f45ea77dc3c 100644 --- a/Mage.Sets/src/mage/sets/TheBrothersWar.java +++ b/Mage.Sets/src/mage/sets/TheBrothersWar.java @@ -204,6 +204,7 @@ public final class TheBrothersWar extends ExpansionSet { cards.add(new SetCardInfo("No One Left Behind", 109, Rarity.UNCOMMON, mage.cards.n.NoOneLeftBehind.class)); cards.add(new SetCardInfo("Obliterating Bolt", 145, Rarity.UNCOMMON, mage.cards.o.ObliteratingBolt.class)); cards.add(new SetCardInfo("Obstinate Baloth", 187, Rarity.UNCOMMON, mage.cards.o.ObstinateBaloth.class)); + cards.add(new SetCardInfo("One with the Multiverse", 59, Rarity.MYTHIC, mage.cards.o.OneWithTheMultiverse.class)); cards.add(new SetCardInfo("Over the Top", 146, Rarity.RARE, mage.cards.o.OverTheTop.class)); cards.add(new SetCardInfo("Overwhelming Remorse", 110, Rarity.COMMON, mage.cards.o.OverwhelmingRemorse.class)); cards.add(new SetCardInfo("Painful Quandary", 111, Rarity.RARE, mage.cards.p.PainfulQuandary.class)); diff --git a/Mage/src/main/java/mage/MageIdentifier.java b/Mage/src/main/java/mage/MageIdentifier.java index e3e50252c1a..4ff929fc67d 100644 --- a/Mage/src/main/java/mage/MageIdentifier.java +++ b/Mage/src/main/java/mage/MageIdentifier.java @@ -17,5 +17,6 @@ public enum MageIdentifier { ShareTheSpoilsWatcher, WishWatcher, GlimpseTheCosmosWatcher, - SerraParagonWatcher + SerraParagonWatcher, + OneWithTheMultiverseWatcher }