From 717482583fca2fef1141e66f51f93c20b07a5493 Mon Sep 17 00:00:00 2001 From: PurpleCrowbar <26198472+PurpleCrowbar@users.noreply.github.com> Date: Sun, 9 Oct 2022 19:25:15 +0100 Subject: [PATCH] [40K] Implement Out of the Tombs (#9633) --- Mage.Sets/src/mage/cards/o/OutOfTheTombs.java | 110 ++++++++++++++++++ Mage.Sets/src/mage/sets/Warhammer40000.java | 1 + 2 files changed, 111 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/o/OutOfTheTombs.java diff --git a/Mage.Sets/src/mage/cards/o/OutOfTheTombs.java b/Mage.Sets/src/mage/cards/o/OutOfTheTombs.java new file mode 100644 index 0000000000..0a7a2761f8 --- /dev/null +++ b/Mage.Sets/src/mage/cards/o/OutOfTheTombs.java @@ -0,0 +1,110 @@ +package mage.cards.o; + +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.dynamicvalue.common.CountersSourceCount; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.MillCardsControllerEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; +import mage.target.common.TargetCardInYourGraveyard; + +import java.util.UUID; + +/** + * @author PurpleCrowbar + */ +public final class OutOfTheTombs extends CardImpl { + + public OutOfTheTombs(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{B}"); + + // At the beginning of your upkeep, put two eon counters on Out of the Tombs, then mill cards equal to the number of eon counters on it. + Ability ability = new BeginningOfUpkeepTriggeredAbility(new AddCountersSourceEffect(CounterType.EON.createInstance(2)), TargetController.YOU, false); + ability.addEffect(new MillCardsControllerEffect(new CountersSourceCount(CounterType.EON)).concatBy(", then").setText("mill cards equal to the number of eon counters on it")); + this.addAbility(ability); + + // If you would draw a card while your library has no cards in it, instead return a creature card from your graveyard to the battlefield. If you can’t, you lose the game. + this.addAbility(new SimpleStaticAbility(new OutOfTheTombsReplacementEffect())); + } + + private OutOfTheTombs(final OutOfTheTombs card) { + super(card); + } + + @Override + public OutOfTheTombs copy() { + return new OutOfTheTombs(this); + } +} + +class OutOfTheTombsReplacementEffect extends ReplacementEffectImpl { + + public OutOfTheTombsReplacementEffect() { + super(Duration.WhileOnBattlefield, Outcome.Benefit); + staticText = "If you would draw a card while your library has no cards in it, instead return a creature card " + + "from your graveyard to the battlefield. If you can't, you lose the game."; + } + + public OutOfTheTombsReplacementEffect(final OutOfTheTombsReplacementEffect effect) { + super(effect); + } + + @Override + public OutOfTheTombsReplacementEffect copy() { + return new OutOfTheTombsReplacementEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player player = game.getPlayer(event.getPlayerId()); + if (player == null) { + return false; + } + boolean cardReturned = false; + TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD); + target.setNotTarget(true); + if (target.canChoose(player.getId(), source, game)) { + if (target.choose(Outcome.PutCreatureInPlay, player.getId(), source.getSourceId(), source, game)) { + Card card = game.getCard(target.getFirstTarget()); + if (card != null) { + player.moveCards(card, Zone.BATTLEFIELD, source, game); + cardReturned = true; + } + } + } + if (!cardReturned) { + game.informPlayers(player.getLogName() + " can't return a card from graveyard to hand."); + player.lost(game); + } + return true; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DRAW_CARD; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getPlayerId().equals(source.getControllerId())) { + Player player = game.getPlayer(event.getPlayerId()); + return player != null && !player.hasLost() && !player.getLibrary().hasCards(); + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/Warhammer40000.java b/Mage.Sets/src/mage/sets/Warhammer40000.java index 5bed8a1878..ca7b112868 100644 --- a/Mage.Sets/src/mage/sets/Warhammer40000.java +++ b/Mage.Sets/src/mage/sets/Warhammer40000.java @@ -174,6 +174,7 @@ public final class Warhammer40000 extends ExpansionSet { cards.add(new SetCardInfo("Nurgle's Rot", 45, Rarity.UNCOMMON, mage.cards.n.NurglesRot.class)); cards.add(new SetCardInfo("Old One Eye", 96, Rarity.RARE, mage.cards.o.OldOneEye.class)); cards.add(new SetCardInfo("Opal Palace", 286, Rarity.COMMON, mage.cards.o.OpalPalace.class)); + cards.add(new SetCardInfo("Out of the Tombs", 46, Rarity.RARE, mage.cards.o.OutOfTheTombs.class)); cards.add(new SetCardInfo("Overgrowth", 219, Rarity.COMMON, mage.cards.o.Overgrowth.class)); cards.add(new SetCardInfo("Past in Flames", 206, Rarity.MYTHIC, mage.cards.p.PastInFlames.class)); cards.add(new SetCardInfo("Path of Ancestry", 287, Rarity.COMMON, mage.cards.p.PathOfAncestry.class));