From b8be6f72d4591e2cd2c319b5c68cfd1237c9e2ce Mon Sep 17 00:00:00 2001 From: Noah Gleason Date: Sun, 8 Jul 2018 22:48:51 -0400 Subject: [PATCH] Implement Truth or Tale --- Mage.Sets/src/mage/cards/t/TruthOrTale.java | 126 ++++++++++++++++++++ Mage.Sets/src/mage/sets/TimeSpiral.java | 1 + 2 files changed, 127 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/t/TruthOrTale.java diff --git a/Mage.Sets/src/mage/cards/t/TruthOrTale.java b/Mage.Sets/src/mage/cards/t/TruthOrTale.java new file mode 100644 index 00000000000..f76c7eed66e --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TruthOrTale.java @@ -0,0 +1,126 @@ +package mage.cards.t; + +import java.util.*; + +import mage.MageObject; +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.filter.FilterCard; +import mage.game.Game; +import mage.players.Library; +import mage.players.Player; +import mage.target.Target; +import mage.target.TargetCard; +import mage.target.common.TargetOpponent; +import mage.util.GameLog; + +/** + * + * @author noahg + */ +public final class TruthOrTale extends CardImpl { + + public TruthOrTale(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}"); + + + // Reveal the top five cards of your library and separate them into two piles. An opponent chooses one of those piles. Put a card from the chosen pile into your hand, then put all other cards revealed this way on the bottom of your library in any order. + this.getSpellAbility().addEffect(new TruthOrTaleEffect()); + } + + public TruthOrTale(final TruthOrTale card) { + super(card); + } + + @Override + public TruthOrTale copy() { + return new TruthOrTale(this); + } +} + +class TruthOrTaleEffect extends OneShotEffect { + + public TruthOrTaleEffect() { + super(Outcome.DrawCard); + this.staticText = "Reveal the top five cards of your library and separate them into two piles. An opponent chooses one of those piles. Put a card from the chosen pile into your hand, then put all other cards revealed this way on the bottom of your library in any order"; + } + + public TruthOrTaleEffect(final TruthOrTaleEffect effect) { + super(effect); + } + + @Override + public TruthOrTaleEffect copy() { + return new TruthOrTaleEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source.getSourceId()); + if (controller == null || sourceObject == null) { + return false; + } + + Cards cards = new CardsImpl(); + cards.addAll(controller.getLibrary().getTopCards(game, 5)); + controller.revealCards(sourceObject.getIdName(), cards, game); + + Player opponent; + Set opponents = game.getOpponents(controller.getId()); + if (opponents.size() == 1) { + opponent = game.getPlayer(opponents.iterator().next()); + } else { + Target target = new TargetOpponent(true); + controller.chooseTarget(Outcome.Detriment, target, source, game); + opponent = game.getPlayer(target.getFirstTarget()); + } + + if (opponent != null) { + TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile")); + List pile1 = new ArrayList<>(); + target.setRequired(false); + if (controller.choose(Outcome.Neutral, cards, target, game)) { + List targets = target.getTargets(); + for (UUID targetId : targets) { + Card card = game.getCard(targetId); + if (card != null) { + pile1.add(card); + } + } + } + List pile2 = new ArrayList<>(); + for (UUID cardId : cards) { + Card card = game.getCard(cardId); + if (card != null && !pile1.contains(card)) { + pile2.add(card); + } + } + boolean choice = opponent.choosePile(Outcome.Detriment, "Choose a pile for " + controller.getName() + " to choose a card from.", pile1, pile2, game); + + List chosen = choice ? pile1 : pile2; + if (!chosen.isEmpty()) { + Cards chosenCards = new CardsImpl(new HashSet<>(chosen)); + TargetCard finalChosenCardTarget = new TargetCard(Zone.LIBRARY,new FilterCard("card to put into your hand")); + if (controller.choose(Outcome.DrawCard, chosenCards, finalChosenCardTarget, game)){ + Card finalChosenCard = game.getCard(finalChosenCardTarget.getFirstTarget()); + if (finalChosenCard != null) { + if (!game.isSimulation()) { + game.informPlayers(controller.getName() + " chose to put " + finalChosenCard.getIdName() + " into their hand."); + } + cards.remove(finalChosenCard); + controller.moveCards(finalChosenCard, Zone.HAND, source, game); + } + } + } + + controller.putCardsOnBottomOfLibrary(cards, game, source, true); + } + + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/TimeSpiral.java b/Mage.Sets/src/mage/sets/TimeSpiral.java index 44f41aa06d8..be584c20ac9 100644 --- a/Mage.Sets/src/mage/sets/TimeSpiral.java +++ b/Mage.Sets/src/mage/sets/TimeSpiral.java @@ -294,6 +294,7 @@ public final class TimeSpiral extends ExpansionSet { cards.add(new SetCardInfo("Trickbind", 88, Rarity.RARE, mage.cards.t.Trickbind.class)); cards.add(new SetCardInfo("Triskelavus", 266, Rarity.RARE, mage.cards.t.Triskelavus.class)); cards.add(new SetCardInfo("Tromp the Domains", 230, Rarity.UNCOMMON, mage.cards.t.TrompTheDomains.class)); + cards.add(new SetCardInfo("Truth or Tale", 89, Rarity.UNCOMMON, mage.cards.t.TruthOrTale.class)); cards.add(new SetCardInfo("Two-Headed Sliver", 183, Rarity.COMMON, mage.cards.t.TwoHeadedSliver.class)); cards.add(new SetCardInfo("Undying Rage", 184, Rarity.UNCOMMON, mage.cards.u.UndyingRage.class)); cards.add(new SetCardInfo("Unyaro Bees", 231, Rarity.RARE, mage.cards.u.UnyaroBees.class));