diff --git a/Mage.Sets/src/mage/cards/j/JaceWielderOfMysteries.java b/Mage.Sets/src/mage/cards/j/JaceWielderOfMysteries.java new file mode 100644 index 0000000000..4b05923f51 --- /dev/null +++ b/Mage.Sets/src/mage/cards/j/JaceWielderOfMysteries.java @@ -0,0 +1,134 @@ +package mage.cards.j; + +import mage.abilities.Ability; +import mage.abilities.LoyaltyAbility; +import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.PutLibraryIntoGraveTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; + +import java.util.UUID; + +import static mage.constants.Outcome.Benefit; + +/** + * @author TheElk801 + */ +public final class JaceWielderOfMysteries extends CardImpl { + + public JaceWielderOfMysteries(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.PLANESWALKER}, "{1}{U}{U}{U}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.JACE); + this.addAbility(new PlaneswalkerEntersWithLoyaltyCountersAbility(4)); + + // If you would draw a card while your library has no cards in it, you win the game instead. + this.addAbility(new SimpleStaticAbility(new JaceWielderOfMysteriesContinuousEffect())); + + // +1 Target player puts the top two cards of their library into their graveyard. Draw a card. + Ability ability = new LoyaltyAbility(new PutLibraryIntoGraveTargetEffect(2), 1); + ability.addEffect(new DrawCardSourceControllerEffect(1)); + this.addAbility(ability); + + // -8: Draw seven cards. Then if your library has no cards in it, you win the game. + this.addAbility(new LoyaltyAbility(new JaceWielderOfMysteriesEffect(), -8)); + } + + private JaceWielderOfMysteries(final JaceWielderOfMysteries card) { + super(card); + } + + @Override + public JaceWielderOfMysteries copy() { + return new JaceWielderOfMysteries(this); + } +} + +class JaceWielderOfMysteriesContinuousEffect extends ReplacementEffectImpl { + + JaceWielderOfMysteriesContinuousEffect() { + super(Duration.WhileOnBattlefield, Benefit); + staticText = "If you would draw a card while your library has no cards in it, you win the game instead"; + } + + private JaceWielderOfMysteriesContinuousEffect(final JaceWielderOfMysteriesContinuousEffect effect) { + super(effect); + } + + @Override + public JaceWielderOfMysteriesContinuousEffect copy() { + return new JaceWielderOfMysteriesContinuousEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player player = game.getPlayer(event.getPlayerId()); + if (player != null) { + player.won(game); + } + return true; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.EMPTY_DRAW; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getPlayerId().equals(source.getControllerId())) { + Player player = game.getPlayer(event.getPlayerId()); + if (player != null && !player.hasLost() && player.isEmptyDraw()) { + return true; + } + } + return false; + } +} + +class JaceWielderOfMysteriesEffect extends OneShotEffect { + + JaceWielderOfMysteriesEffect() { + super(Benefit); + staticText = "Draw seven cards. Then if your library has no cards in it, you win the game."; + } + + private JaceWielderOfMysteriesEffect(final JaceWielderOfMysteriesEffect effect) { + super(effect); + } + + @Override + public JaceWielderOfMysteriesEffect copy() { + return new JaceWielderOfMysteriesEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + player.drawCards(7, game); + if (!player.getLibrary().hasCards()) { + player.won(game); + } + return true; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/WarOfTheSpark.java b/Mage.Sets/src/mage/sets/WarOfTheSpark.java index 5502c69761..1a93a8b59d 100644 --- a/Mage.Sets/src/mage/sets/WarOfTheSpark.java +++ b/Mage.Sets/src/mage/sets/WarOfTheSpark.java @@ -40,6 +40,7 @@ public final class WarOfTheSpark extends ExpansionSet { cards.add(new SetCardInfo("Island", 253, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Island", 254, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Island", 255, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Jace, Wielder of Mysteries", 54, Rarity.RARE, mage.cards.j.JaceWielderOfMysteries.class)); cards.add(new SetCardInfo("Mountain", 259, Rarity.LAND, mage.cards.basiclands.Mountain.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Mountain", 260, Rarity.LAND, mage.cards.basiclands.Mountain.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Mountain", 261, Rarity.LAND, mage.cards.basiclands.Mountain.class, NON_FULL_USE_VARIOUS));