From 8792e0b5cf899d39a59b60155c5dc06f331e68c9 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 18 Sep 2018 11:42:37 -0400 Subject: [PATCH] Implemented Discovery // Dispersal --- .../src/mage/cards/d/DiscoveryDispersal.java | 126 ++++++++++++++++++ Mage.Sets/src/mage/cards/p/Preordain.java | 14 +- Mage.Sets/src/mage/sets/GuildsOfRavnica.java | 1 + 3 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/d/DiscoveryDispersal.java diff --git a/Mage.Sets/src/mage/cards/d/DiscoveryDispersal.java b/Mage.Sets/src/mage/cards/d/DiscoveryDispersal.java new file mode 100644 index 0000000000..762421895e --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DiscoveryDispersal.java @@ -0,0 +1,126 @@ +package mage.cards.d; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.StaticValue; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; +import mage.abilities.effects.common.discard.DiscardEachPlayerEffect; +import mage.abilities.effects.keyword.SurveilEffect; +import mage.cards.CardSetInfo; +import mage.cards.SplitCard; +import mage.constants.CardType; +import mage.constants.ComparisonType; +import mage.constants.Outcome; +import mage.constants.SpellAbilityType; +import mage.constants.TargetController; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterNonlandPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; +import mage.filter.predicate.permanent.ControllerIdPredicate; +import mage.filter.predicate.permanent.PermanentIdPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.Target; +import mage.target.TargetPermanent; + +/** + * + * @author TheElk801 + */ +public final class DiscoveryDispersal extends SplitCard { + + public DiscoveryDispersal(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, new CardType[]{CardType.INSTANT}, "{1}{U/B}", "{3}{U}{B}", SpellAbilityType.SPLIT); + + // Discovery + // Surveil 2, then draw a card. + this.getLeftHalfCard().getSpellAbility().addEffect( + new SurveilEffect(2).setText("Surveil 2,") + ); + this.getLeftHalfCard().getSpellAbility().addEffect( + new DrawCardSourceControllerEffect(1 + ).setText("then draw a card. (To surveil 2, " + + "look at the top two cards of your library, " + + "then put any number of them into your graveyard " + + "and the rest on top of your library " + + "in any order.)") + ); + + // Dispersal + // Each opponent returns a nonland permanent they control with the highest converted mana cost among permanents they control to its owner’s hand, then discards a card. + this.getLeftHalfCard().getSpellAbility().addEffect(new DispersalEffect()); + } + + public DiscoveryDispersal(final DiscoveryDispersal card) { + super(card); + } + + @Override + public DiscoveryDispersal copy() { + return new DiscoveryDispersal(this); + } +} + +class DispersalEffect extends OneShotEffect { + + public DispersalEffect() { + super(Outcome.Benefit); + this.staticText = "Each opponent returns a nonland permanent " + + "they control with the highest converted mana cost " + + "among permanents they control to its owner’s hand, " + + "then discards a card."; + } + + public DispersalEffect(final DispersalEffect effect) { + super(effect); + } + + @Override + public DispersalEffect copy() { + return new DispersalEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + Set permsToReturn = new HashSet(); + for (UUID opponentId : game.getOpponents(player.getId())) { + Player opponent = game.getPlayer(opponentId); + if (opponent == null) { + continue; + } + int highestCMC = 0; + for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) { + if (permanent != null && !permanent.isLand()) { + highestCMC = Math.max(highestCMC, permanent.getConvertedManaCost()); + } + } + FilterPermanent filter = new FilterNonlandPermanent("permanent you control with converted mana cost " + highestCMC); + filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, highestCMC)); + filter.add(new ControllerIdPredicate(opponentId)); + Target target = new TargetPermanent(1, 1, filter, true); + if (opponent.choose(outcome, target, source.getSourceId(), game)) { + if (target.getFirstTarget() == null) { + continue; + } + permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget())); + } + } + FilterPermanent filter = new FilterPermanent(); + filter.add(Predicates.or(permsToReturn)); + new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source); + new DiscardEachPlayerEffect( + new StaticValue(1), false, TargetController.OPPONENT + ).apply(game, source); + return true; + } +} diff --git a/Mage.Sets/src/mage/cards/p/Preordain.java b/Mage.Sets/src/mage/cards/p/Preordain.java index 519fd4a4f4..4eae38cd40 100644 --- a/Mage.Sets/src/mage/cards/p/Preordain.java +++ b/Mage.Sets/src/mage/cards/p/Preordain.java @@ -1,4 +1,3 @@ - package mage.cards.p; import java.util.UUID; @@ -18,8 +17,17 @@ public final class Preordain extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{U}"); // Scry 2, then draw a card. (To scry 2, look at the top two cards of your library, then put any number of them on the bottom of your library and the rest on top in any order.) - this.getSpellAbility().addEffect(new ScryEffect(2)); - this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect(1)); + this.getSpellAbility().addEffect( + new ScryEffect(2).setText("Scry 2, ") + ); + this.getSpellAbility().addEffect( + new DrawCardSourceControllerEffect(1) + .setText("then draw a card. (To scry 2, " + + "look at the top two cards of your library, " + + "then put any number of them on the " + + "bottom of your library and the rest on " + + "top in any order.)") + ); } public Preordain(final Preordain card) { diff --git a/Mage.Sets/src/mage/sets/GuildsOfRavnica.java b/Mage.Sets/src/mage/sets/GuildsOfRavnica.java index 57139111bb..7dd179fe5a 100644 --- a/Mage.Sets/src/mage/sets/GuildsOfRavnica.java +++ b/Mage.Sets/src/mage/sets/GuildsOfRavnica.java @@ -63,6 +63,7 @@ public final class GuildsOfRavnica extends ExpansionSet { cards.add(new SetCardInfo("Dimir Locket", 234, Rarity.COMMON, mage.cards.d.DimirLocket.class)); cards.add(new SetCardInfo("Dimir Spybug", 166, Rarity.UNCOMMON, mage.cards.d.DimirSpybug.class)); cards.add(new SetCardInfo("Direct Current", 96, Rarity.COMMON, mage.cards.d.DirectCurrent.class)); + cards.add(new SetCardInfo("Discovery // Dispersal", 223, Rarity.UNCOMMON, mage.cards.d.DiscoveryDispersal.class)); cards.add(new SetCardInfo("Disdainful Stroke", 37, Rarity.COMMON, mage.cards.d.DisdainfulStroke.class)); cards.add(new SetCardInfo("Disinformation Campaign", 167, Rarity.UNCOMMON, mage.cards.d.DisinformationCampaign.class)); cards.add(new SetCardInfo("District Guide", 128, Rarity.UNCOMMON, mage.cards.d.DistrictGuide.class));