diff --git a/Mage.Sets/src/mage/cards/s/SolsticeRevelations.java b/Mage.Sets/src/mage/cards/s/SolsticeRevelations.java new file mode 100644 index 00000000000..250f545d70a --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SolsticeRevelations.java @@ -0,0 +1,114 @@ +package mage.cards.s; + +import mage.abilities.Ability; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.FlashbackAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.FilterCard; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.game.Game; +import mage.players.Player; +import mage.util.CardUtil; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class SolsticeRevelations extends CardImpl { + + public SolsticeRevelations(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{R}"); + + this.subtype.add(SubType.LESSON); + + // Exile cards from the top of your library until you exile a nonland card. You may cast that card without paying its mana cost if the spell's mana value is less than the number of Mountains you control. If you don't cast that card this way, put it into your hand. + this.getSpellAbility().addEffect(new SolsticeRevelationsEffect()); + + // Flashback {6}{R} + this.addAbility(new FlashbackAbility(this, new ManaCostsImpl<>("{6}{R}"))); + } + + private SolsticeRevelations(final SolsticeRevelations card) { + super(card); + } + + @Override + public SolsticeRevelations copy() { + return new SolsticeRevelations(this); + } +} + +enum SolsticeRevelationsPredicate implements ObjectSourcePlayerPredicate { + instance; + private static final FilterPermanent filter = new FilterControlledPermanent(SubType.MOUNTAIN); + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + return input.getObject().getManaValue() + < game.getBattlefield().count(filter, input.getPlayerId(), input.getSource(), game); + } +} + +class SolsticeRevelationsEffect extends OneShotEffect { + + private static final FilterCard filter = new FilterCard(); + + static { + filter.add(SolsticeRevelationsPredicate.instance); + } + + SolsticeRevelationsEffect() { + super(Outcome.Benefit); + staticText = "exile cards from the top of your library until you exile a nonland card. " + + "You may cast that card without paying its mana cost if the spell's mana value is less than " + + "the number of Mountains you control. If you don't cast that card this way, put it into your hand"; + } + + private SolsticeRevelationsEffect(final SolsticeRevelationsEffect effect) { + super(effect); + } + + @Override + public SolsticeRevelationsEffect copy() { + return new SolsticeRevelationsEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + Card card = getCard(player, game, source); + if (card == null) { + return false; + } + if (!CardUtil.castSpellWithAttributesForFree(player, source, game, card, filter)) { + player.moveCards(card, Zone.HAND, source, game); + } + return true; + } + + private static Card getCard(Player player, Game game, Ability source) { + for (Card card : player.getLibrary().getCards(game)) { + player.moveCards(card, Zone.EXILED, source, game); + game.processAction(); + if (!card.isLand(game)) { + return card; + } + } + return null; + } + +} diff --git a/Mage.Sets/src/mage/sets/AvatarTheLastAirbender.java b/Mage.Sets/src/mage/sets/AvatarTheLastAirbender.java index c325f990126..50e56f00795 100644 --- a/Mage.Sets/src/mage/sets/AvatarTheLastAirbender.java +++ b/Mage.Sets/src/mage/sets/AvatarTheLastAirbender.java @@ -146,6 +146,7 @@ public final class AvatarTheLastAirbender extends ExpansionSet { cards.add(new SetCardInfo("Sokka, Bold Boomeranger", 240, Rarity.RARE, mage.cards.s.SokkaBoldBoomeranger.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Sokka, Bold Boomeranger", 383, Rarity.RARE, mage.cards.s.SokkaBoldBoomeranger.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Sokka, Lateral Strategist", 241, Rarity.UNCOMMON, mage.cards.s.SokkaLateralStrategist.class)); + cards.add(new SetCardInfo("Solstice Revelations", 153, Rarity.UNCOMMON, mage.cards.s.SolsticeRevelations.class)); cards.add(new SetCardInfo("Southern Air Temple", 36, Rarity.UNCOMMON, mage.cards.s.SouthernAirTemple.class)); cards.add(new SetCardInfo("Sozin's Comet", 154, Rarity.MYTHIC, mage.cards.s.SozinsComet.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Sozin's Comet", 309, Rarity.MYTHIC, mage.cards.s.SozinsComet.class, NON_FULL_USE_VARIOUS)); diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 65a79575a4b..db9ff9e8543 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -1536,7 +1536,7 @@ public final class CardUtil { } else { chosenAbility = player.chooseAbilityForCast(cardToCast, game, true); } - boolean result = false; + boolean result; if (chosenAbility instanceof SpellAbility) { result = player.cast( (SpellAbility) chosenAbility, @@ -1545,6 +1545,8 @@ public final class CardUtil { } else if (playLand && chosenAbility instanceof PlayLandAbility) { Card land = game.getCard(chosenAbility.getSourceId()); result = player.playLand(land, game, true); + } else { + result = false; } partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null)); if (result && spellCastTracker != null) {