From e951ca480a2ffec787b115e4505043771ac9613a Mon Sep 17 00:00:00 2001 From: Daniel Bomar Date: Thu, 9 Sep 2021 17:23:08 -0500 Subject: [PATCH] [MID] Implemented Dire-Strain Rampage --- .../src/mage/cards/d/DireStrainRampage.java | 129 ++++++++++++++++++ .../src/mage/sets/InnistradMidnightHunt.java | 1 + 2 files changed, 130 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/d/DireStrainRampage.java diff --git a/Mage.Sets/src/mage/cards/d/DireStrainRampage.java b/Mage.Sets/src/mage/cards/d/DireStrainRampage.java new file mode 100644 index 00000000000..5b4e90df050 --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DireStrainRampage.java @@ -0,0 +1,129 @@ +package mage.cards.d; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +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.TimingRule; +import mage.constants.Zone; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; +import mage.filter.predicate.Predicates; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.common.TargetCardInLibrary; + +/** + * + * @author weirddan455 + */ +public final class DireStrainRampage extends CardImpl { + + private static final FilterPermanent filter = new FilterPermanent("artifact, enchantment, or land"); + + static { + filter.add(Predicates.or( + CardType.ARTIFACT.getPredicate(), + CardType.ENCHANTMENT.getPredicate(), + CardType.LAND.getPredicate() + )); + } + + public DireStrainRampage(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{R}{G}"); + + // Destroy target artifact, enchantment, or land. If a land was destroyed this way, + // its controller may search their library for up to two basic land cards, put them onto the battlefield tapped, then shuffle. + // Otherwise, its controller may search their library for a basic land card, put it onto the battlefield tapped, then shuffle. + this.getSpellAbility().addEffect(new DireStrainRampageEffect()); + this.getSpellAbility().addTarget(new TargetPermanent(filter)); + + // Flashback {3}{R}{G} + this.addAbility(new FlashbackAbility(new ManaCostsImpl<>("{3}{R}{G}"), TimingRule.SORCERY)); + } + + private DireStrainRampage(final DireStrainRampage card) { + super(card); + } + + @Override + public DireStrainRampage copy() { + return new DireStrainRampage(this); + } +} + +class DireStrainRampageEffect extends OneShotEffect { + + public DireStrainRampageEffect() { + super(Outcome.DestroyPermanent); + staticText = "Destroy target artifact, enchantment, or land. If a land was destroyed this way, " + + "its controller may search their library for up to two basic land cards, put them onto the battlefield tapped, then shuffle. " + + "Otherwise, its controller may search their library for a basic land card, put it onto the battlefield tapped, then shuffle"; + } + + private DireStrainRampageEffect(final DireStrainRampageEffect effect) { + super(effect); + } + + @Override + public DireStrainRampageEffect copy() { + return new DireStrainRampageEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getFirstTarget()); + if (permanent == null) { + return false; + } + Player player = game.getPlayer(permanent.getControllerId()); + boolean landTargeted = permanent.isLand(game); + boolean destroyed = permanent.destroy(source, game, false); + boolean twoLands = false; + if (landTargeted && destroyed) { + // Check that no replacement happened (card actually went to the graveyard and "was destroyed this way") + if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) { + twoLands = true; + } + } + String searchString; + if (twoLands) { + searchString = "Search your library for up to two basic land cards, put them onto the battlefield tapped, then shuffle?"; + } else { + searchString = "Search your library for a basic land card, put it onto the battlefield tapped, then shuffle?"; + } + if (player != null && player.chooseUse(Outcome.PutLandInPlay, searchString, source, game)) { + TargetCardInLibrary target; + if (twoLands) { + target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LANDS); + } else { + target = new TargetCardInLibrary(1, 1, StaticFilters.FILTER_CARD_BASIC_LAND); + } + if (player.searchLibrary(target, source, game)) { + Set lands = new HashSet<>(); + for (UUID cardId : target.getTargets()) { + Card card = game.getCard(cardId); + if (card != null) { + lands.add(card); + } + } + if (!lands.isEmpty()) { + player.moveCards(lands, Zone.BATTLEFIELD, source, game, true, false, false, null); + } + } + player.shuffleLibrary(source, game); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/InnistradMidnightHunt.java b/Mage.Sets/src/mage/sets/InnistradMidnightHunt.java index d77f3a9445a..6b18d10b7e5 100644 --- a/Mage.Sets/src/mage/sets/InnistradMidnightHunt.java +++ b/Mage.Sets/src/mage/sets/InnistradMidnightHunt.java @@ -62,6 +62,7 @@ public final class InnistradMidnightHunt extends ExpansionSet { cards.add(new SetCardInfo("Delver of Secrets", 47, Rarity.UNCOMMON, mage.cards.d.DelverOfSecrets.class)); cards.add(new SetCardInfo("Deserted Beach", 260, Rarity.RARE, mage.cards.d.DesertedBeach.class)); cards.add(new SetCardInfo("Dire-Strain Demolisher", 174, Rarity.UNCOMMON, mage.cards.d.DireStrainDemolisher.class)); + cards.add(new SetCardInfo("Dire-Strain Rampage", 219, Rarity.RARE, mage.cards.d.DireStrainRampage.class)); cards.add(new SetCardInfo("Diregraf Horde", 96, Rarity.COMMON, mage.cards.d.DiregrafHorde.class)); cards.add(new SetCardInfo("Diregraf Rebirth", 220, Rarity.UNCOMMON, mage.cards.d.DiregrafRebirth.class)); cards.add(new SetCardInfo("Dissipate", 49, Rarity.UNCOMMON, mage.cards.d.Dissipate.class));