diff --git a/Mage.Sets/src/mage/cards/r/RalLeylineProdigy.java b/Mage.Sets/src/mage/cards/r/RalLeylineProdigy.java new file mode 100644 index 00000000000..07d95045b10 --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RalLeylineProdigy.java @@ -0,0 +1,236 @@ +package mage.cards.r; + +import mage.MageIdentifier; +import mage.MageObject; +import mage.MageObjectReference; +import mage.ObjectColor; +import mage.abilities.Ability; +import mage.abilities.LoyaltyAbility; +import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.condition.Condition; +import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DamageMultiEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionAllEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.abilities.hint.ConditionHint; +import mage.abilities.hint.Hint; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.FilterCard; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterInstantOrSorceryCard; +import mage.filter.predicate.mageobject.AnotherPredicate; +import mage.filter.predicate.mageobject.ColorPredicate; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetAnyTargetAmount; +import mage.util.CardUtil; +import mage.watchers.common.SpellsCastWatcher; + +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +/** + * @author Susucr + */ +public final class RalLeylineProdigy extends CardImpl { + + private static final FilterPermanent filter = new FilterPermanent("blue permanent other than {this}"); + private static final Condition condition = new PermanentsOnTheBattlefieldCondition(filter, true); + private static final Hint hint = new ConditionHint(condition, "you control another blue permanent"); + + static { + filter.add(new ColorPredicate(ObjectColor.BLUE)); + filter.add(AnotherPredicate.instance); + } + + public RalLeylineProdigy(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.PLANESWALKER}, ""); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.RAL); + this.setStartingLoyalty(2); + + this.color.setBlue(true); + this.color.setRed(true); + this.nightCard = true; + + // Ral, Leyline Prodigy enters the battlefield with an additional loyalty counter on him for each instant and sorcery spell you've cast this turn. + this.addAbility(new EntersBattlefieldAbility( + new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(), RalLeylineProdigyValue.instance, false) + .setText("with an additional loyalty counter on him for each instant and sorcery spell you've cast this turn") + )); + + // +1: Until your next turn, instant and sorcery spells you cast cost {1} less to cast. + this.addAbility(new LoyaltyAbility(new RalLeylineProdigyCostReductionEffect(), 1)); + + // -2: Ral deals 2 damage divided as you choose among one or two targets. Draw a card if you control a blue permanent other than Ral. + Ability ability = new LoyaltyAbility(new DamageMultiEffect(2), -2); + ability.addTarget(new TargetAnyTargetAmount(2)); + ability.addEffect(new ConditionalOneShotEffect( + new DrawCardSourceControllerEffect(1), + condition, "Draw a card if you control a blue permanent other than {this}" + )); + ability.addHint(hint); + this.addAbility(ability); + + // -8: Exile the top eight cards of your library. You may cast instant and sorcery spells from among them this turn without paying their mana costs. + this.addAbility(new LoyaltyAbility(new RalLeylineProdigyMinusEightEffect(), -8) + .setIdentifier(MageIdentifier.WithoutPayingManaCostAlternateCast)); + } + + private RalLeylineProdigy(final RalLeylineProdigy card) { + super(card); + } + + @Override + public RalLeylineProdigy copy() { + return new RalLeylineProdigy(this); + } +} + +class RalLeylineProdigyCostReductionEffect extends OneShotEffect { + + private static final FilterCard filter = new FilterInstantOrSorceryCard("instant and sorcery spells"); + + RalLeylineProdigyCostReductionEffect() { + super(Outcome.Benefit); + this.staticText = "Until your next turn, instant and sorcery spells you cast cost {1} less to cast"; + } + + private RalLeylineProdigyCostReductionEffect(final RalLeylineProdigyCostReductionEffect effect) { + super(effect); + } + + @Override + public RalLeylineProdigyCostReductionEffect copy() { + return new RalLeylineProdigyCostReductionEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + SpellsCostReductionAllEffect effect = new SpellsCostReductionAllEffect(filter, 1); + effect.setDuration(Duration.UntilYourNextTurn); + game.addEffect(effect, source); + return true; + } +} + +enum RalLeylineProdigyValue implements DynamicValue { + instance; + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class); + if (watcher == null) { + return 0; + } + return watcher + .getSpellsCastThisTurn(sourceAbility.getControllerId()) + .stream() + .filter(Objects::nonNull) + .filter(spell -> spell.isInstantOrSorcery(game)) + .mapToInt(spell -> 1) + .sum(); + } + + @Override + public RalLeylineProdigyValue copy() { + return instance; + } + + @Override + public String getMessage() { + return "instant and sorcery spell you've cast this turn"; + } +} + +class RalLeylineProdigyMinusEightEffect extends OneShotEffect { + + RalLeylineProdigyMinusEightEffect() { + super(Outcome.Benefit); + staticText = "Exile the top eight cards of your library. " + + "You may cast instant and sorcery spells from among them this turn without paying their mana costs"; + } + + private RalLeylineProdigyMinusEightEffect(final RalLeylineProdigyMinusEightEffect effect) { + super(effect); + } + + @Override + public RalLeylineProdigyMinusEightEffect copy() { + return new RalLeylineProdigyMinusEightEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source); + if (player == null || sourceObject == null) { + return false; + } + Set cards = player.getLibrary().getTopCards(game, 8); + UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); + player.moveCardsToExile(cards, source, game, true, exileId, sourceObject.getIdName()); + for (Card card : cards) { + if (game.getState().getZone(card.getId()) == Zone.EXILED) { + game.addEffect(new RalLeylineProdigyCastEffect(new MageObjectReference(card, game)), source); + } + } + return true; + } + +} + +class RalLeylineProdigyCastEffect extends AsThoughEffectImpl { + + private final MageObjectReference mor; + + public RalLeylineProdigyCastEffect(MageObjectReference mor) { + super(AsThoughEffectType.CAST_FROM_NOT_OWN_HAND_ZONE, Duration.EndOfTurn, Outcome.Benefit); + this.mor = mor; + } + + private RalLeylineProdigyCastEffect(final RalLeylineProdigyCastEffect effect) { + super(effect); + this.mor = effect.mor; + } + + @Override + public RalLeylineProdigyCastEffect copy() { + return new RalLeylineProdigyCastEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { + if (mor.getCard(game) == null) { + discard(); + return false; + } + Card theCard = game.getCard(objectId); + if (theCard == null || !theCard.isInstantOrSorcery(game)) { + return false; + } + UUID mainId = theCard.getMainCard().getId(); // for split cards/MDFC/Adventure cards + if (!source.isControlledBy(affectedControllerId) || !mor.refersTo(mainId, game)) { + return false; + } + allowCardToPlayWithoutMana(mainId, source, affectedControllerId, MageIdentifier.WithoutPayingManaCostAlternateCast, game); + return true; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/r/RalMonsoonMage.java b/Mage.Sets/src/mage/cards/r/RalMonsoonMage.java new file mode 100644 index 00000000000..bb063eee661 --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RalMonsoonMage.java @@ -0,0 +1,119 @@ +package mage.cards.r; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.Pronoun; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.common.SpellCastControllerTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DamageControllerEffect; +import mage.abilities.effects.common.ExileAndReturnSourceEffect; +import mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect; +import mage.abilities.keyword.TransformAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterCard; +import mage.filter.StaticFilters; +import mage.filter.common.FilterInstantOrSorceryCard; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author Susucr + */ +public final class RalMonsoonMage extends CardImpl { + + private static final FilterCard filter = new FilterInstantOrSorceryCard("Instant and sorcery spells"); + + public RalMonsoonMage(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}"); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.WIZARD); + this.power = new MageInt(1); + this.toughness = new MageInt(3); + + this.secondSideCardClazz = RalLeylineProdigy.class; + + // Instant and sorcery spells you cast cost {1} less to cast. + this.addAbility(new SimpleStaticAbility(new SpellsCostReductionControllerEffect(filter, 1))); + + // Whenever you cast an instant or sorcery spell during your turn, flip a coin. If you lose the flip, Ral, Monsoon Mage deals 1 damage to you. If you win the flip, you may exile Ral. If you do, return him to the battlefield transformed under his owner control. + this.addAbility(new TransformAbility()); + this.addAbility(new RalMonsoonMageTriggeredAbility()); + } + + private RalMonsoonMage(final RalMonsoonMage card) { + super(card); + } + + @Override + public RalMonsoonMage copy() { + return new RalMonsoonMage(this); + } +} + +class RalMonsoonMageTriggeredAbility extends SpellCastControllerTriggeredAbility { + + RalMonsoonMageTriggeredAbility() { + super(new RalMonsoonMageEffect(), StaticFilters.FILTER_SPELL_AN_INSTANT_OR_SORCERY, false); + setTriggerPhrase("Whenever you cast an instant or sorcery spell during your turn, "); + } + + private RalMonsoonMageTriggeredAbility(final RalMonsoonMageTriggeredAbility ability) { + super(ability); + } + + @Override + public RalMonsoonMageTriggeredAbility copy() { + return new RalMonsoonMageTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + return game.getActivePlayerId().equals(getControllerId()) && super.checkTrigger(event, game); + } +} + +class RalMonsoonMageEffect extends OneShotEffect { + + RalMonsoonMageEffect() { + super(Outcome.Benefit); + staticText = "flip a coin. If you lose the flip, {this} deals 1 damage to you. " + + "If you win the flip, you may exile {this}. If you do, return him to the battlefield transformed under his owner control"; + } + + private RalMonsoonMageEffect(final RalMonsoonMageEffect effect) { + super(effect); + } + + @Override + public RalMonsoonMageEffect copy() { + return new RalMonsoonMageEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + boolean wonFlip = player.flipCoin(source, game, true); + if (wonFlip) { + if (player.chooseUse(outcome, "Exile {this} and return transformed?", source, game)) { + new ExileAndReturnSourceEffect(PutCards.BATTLEFIELD_TRANSFORMED, Pronoun.HE) + .apply(game, source); + } + } else { + new DamageControllerEffect(1) + .apply(game, source); + } + return true; + } +} + diff --git a/Mage.Sets/src/mage/sets/ModernHorizons3.java b/Mage.Sets/src/mage/sets/ModernHorizons3.java index 49fe9d349dd..27516ccffe1 100644 --- a/Mage.Sets/src/mage/sets/ModernHorizons3.java +++ b/Mage.Sets/src/mage/sets/ModernHorizons3.java @@ -77,6 +77,8 @@ public final class ModernHorizons3 extends ExpansionSet { cards.add(new SetCardInfo("Polluted Delta", 224, Rarity.RARE, mage.cards.p.PollutedDelta.class)); cards.add(new SetCardInfo("Priest of Titania", 286, Rarity.UNCOMMON, mage.cards.p.PriestOfTitania.class)); cards.add(new SetCardInfo("Psychic Frog", 199, Rarity.RARE, mage.cards.p.PsychicFrog.class)); + cards.add(new SetCardInfo("Ral, Monsoon Mage", 247, Rarity.MYTHIC, mage.cards.r.RalMonsoonMage.class)); + cards.add(new SetCardInfo("Ral, Leyline Prodigy", 247, Rarity.MYTHIC, mage.cards.r.RalLeylineProdigy.class)); cards.add(new SetCardInfo("Ruby Medallion", 295, Rarity.RARE, mage.cards.r.RubyMedallion.class)); cards.add(new SetCardInfo("Sapphire Medallion", 296, Rarity.RARE, mage.cards.s.SapphireMedallion.class)); cards.add(new SetCardInfo("Scurrilous Sentry", 108, Rarity.COMMON, mage.cards.s.ScurrilousSentry.class)); diff --git a/Mage/src/main/java/mage/MageIdentifier.java b/Mage/src/main/java/mage/MageIdentifier.java index 6b1c5300a84..a160f2fdf4a 100644 --- a/Mage/src/main/java/mage/MageIdentifier.java +++ b/Mage/src/main/java/mage/MageIdentifier.java @@ -67,8 +67,8 @@ public enum MageIdentifier { WorldheartPhoenixAlternateCast, XandersPactAlternateCast, TheTombOfAclazotzWatcher, - - MeTheImmortalAlternateCast; + MeTheImmortalAlternateCast, + WithoutPayingManaCostAlternateCast; /** * Additional text if there is need to differentiate two very similar effects