From 05a0c8818b6ddfa1eca79bf326ff79e0679807ba Mon Sep 17 00:00:00 2001 From: Daniel Bomar Date: Tue, 30 Aug 2022 14:58:09 -0500 Subject: [PATCH] [DMU] Implemented Chaotic Transformation --- .../mage/cards/c/ChaoticTransformation.java | 108 ++++++++++++++++++ Mage.Sets/src/mage/sets/DominariaUnited.java | 1 + 2 files changed, 109 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/c/ChaoticTransformation.java diff --git a/Mage.Sets/src/mage/cards/c/ChaoticTransformation.java b/Mage.Sets/src/mage/cards/c/ChaoticTransformation.java new file mode 100644 index 00000000000..ed912039f2e --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/ChaoticTransformation.java @@ -0,0 +1,108 @@ +package mage.cards.c; + +import java.util.HashSet; +import java.util.UUID; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.*; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.Target; +import mage.target.common.*; + +/** + * + * @author weirddan455 + */ +public final class ChaoticTransformation extends CardImpl { + + public ChaoticTransformation(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{5}{R}"); + + // Exile up to one target artifact, up to one target creature, up to one target enchantment, up to one target planeswalker, and/or up to one target land. + // For each permanent exiled this way, its controller reveals cards from the top of their library until they reveal a card that shares a card type with it, puts that card onto the battlefield, then shuffles. + this.getSpellAbility().addTarget(new TargetArtifactPermanent(0, 1)); + this.getSpellAbility().addTarget(new TargetCreaturePermanent(0, 1)); + this.getSpellAbility().addTarget(new TargetEnchantmentPermanent(0, 1)); + this.getSpellAbility().addTarget(new TargetPlaneswalkerPermanent(0, 1)); + this.getSpellAbility().addTarget(new TargetLandPermanent(0, 1)); + this.getSpellAbility().addEffect(new ChaoticTransformationEffect()); + } + + private ChaoticTransformation(final ChaoticTransformation card) { + super(card); + } + + @Override + public ChaoticTransformation copy() { + return new ChaoticTransformation(this); + } +} + +class ChaoticTransformationEffect extends OneShotEffect { + + public ChaoticTransformationEffect() { + super(Outcome.PutCardInPlay); + this.staticText = "Exile up to one target artifact, up to one target creature, up to one target enchantment, up to one target planeswalker, and/or up to one target land. " + + "For each permanent exiled this way, its controller reveals cards from the top of their library until they reveal a card that shares a card type with it, puts that card onto the battlefield, then shuffles."; + } + + private ChaoticTransformationEffect(final ChaoticTransformationEffect effect) { + super(effect); + } + + @Override + public ChaoticTransformationEffect copy() { + return new ChaoticTransformationEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player sourceController = game.getPlayer(source.getControllerId()); + if (sourceController == null) { + return false; + } + for (Target target : source.getTargets()) { + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent == null) { + continue; + } + Player permanentController = game.getPlayer(permanent.getControllerId()); + HashSet types = new HashSet<>(permanent.getCardType(game)); + if (!sourceController.moveCards(permanent, Zone.EXILED, source, game) || permanentController == null) { + continue; + } + Cards revealedCards = new CardsImpl(); + Card toBattlefield = null; + for (Card card : permanentController.getLibrary().getCards(game)) { + revealedCards.add(card); + if (sharesType(card, types, game)) { + toBattlefield = card; + break; + } + } + if (!revealedCards.isEmpty()) { + permanentController.revealCards(source, revealedCards, game); + } + if (toBattlefield != null) { + permanentController.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game); + } + permanentController.shuffleLibrary(source, game); + } + return true; + } + + private boolean sharesType(Card card, HashSet types, Game game) { + for (CardType type : card.getCardType(game)) { + if (types.contains(type)) { + return true; + } + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/DominariaUnited.java b/Mage.Sets/src/mage/sets/DominariaUnited.java index bd920328184..2d833cda586 100644 --- a/Mage.Sets/src/mage/sets/DominariaUnited.java +++ b/Mage.Sets/src/mage/sets/DominariaUnited.java @@ -60,6 +60,7 @@ public final class DominariaUnited extends ExpansionSet { cards.add(new SetCardInfo("Broken Wings", 157, Rarity.COMMON, mage.cards.b.BrokenWings.class)); cards.add(new SetCardInfo("Captain's Call", 9, Rarity.COMMON, mage.cards.c.CaptainsCall.class)); cards.add(new SetCardInfo("Caves of Koilos", 244, Rarity.RARE, mage.cards.c.CavesOfKoilos.class)); + cards.add(new SetCardInfo("Chaotic Transformation", 117, Rarity.RARE, mage.cards.c.ChaoticTransformation.class)); cards.add(new SetCardInfo("Charismatic Vanguard", 10, Rarity.COMMON, mage.cards.c.CharismaticVanguard.class)); cards.add(new SetCardInfo("Choking Miasma", 86, Rarity.UNCOMMON, mage.cards.c.ChokingMiasma.class)); cards.add(new SetCardInfo("Citizen's Arrest", 11, Rarity.COMMON, mage.cards.c.CitizensArrest.class));