From 7b1e3fae7b6dab5c5338ae00e923173c1cb051f0 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 30 Sep 2021 08:52:24 -0400 Subject: [PATCH] [MIC] Implemented Wall of Mourning --- .../src/mage/cards/w/WallOfMourning.java | 125 ++++++++++++++++++ .../src/mage/sets/MidnightHuntCommander.java | 1 + Mage/src/main/java/mage/cards/CardsImpl.java | 3 +- 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/w/WallOfMourning.java diff --git a/Mage.Sets/src/mage/cards/w/WallOfMourning.java b/Mage.Sets/src/mage/cards/w/WallOfMourning.java new file mode 100644 index 00000000000..c97593d0a7c --- /dev/null +++ b/Mage.Sets/src/mage/cards/w/WallOfMourning.java @@ -0,0 +1,125 @@ +package mage.cards.w; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.condition.common.CovenCondition; +import mage.abilities.dynamicvalue.common.OpponentsCount; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.hint.common.CovenHint; +import mage.abilities.keyword.DefenderAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.ExileZone; +import mage.game.Game; +import mage.players.Player; +import mage.util.CardUtil; + +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class WallOfMourning extends CardImpl { + + public WallOfMourning(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}"); + + this.subtype.add(SubType.WALL); + this.power = new MageInt(0); + this.toughness = new MageInt(4); + + // Defender + this.addAbility(DefenderAbility.getInstance()); + + // When Wall of Mourning enters the battlefield, exile a card from the top of your library face down for each opponent you have. + this.addAbility(new EntersBattlefieldTriggeredAbility(new WallOfMourningExileEffect())); + + // Coven — At the beginning of your end step, if you control three or more creatures with different powers, put a card exiled with Wall of Mourning into its owner's hand. + this.addAbility(new BeginningOfEndStepTriggeredAbility( + Zone.BATTLEFIELD, new WallOfMourningReturnEffect(), + TargetController.YOU, CovenCondition.instance, false + ).addHint(CovenHint.instance).setAbilityWord(AbilityWord.COVEN)); + } + + private WallOfMourning(final WallOfMourning card) { + super(card); + } + + @Override + public WallOfMourning copy() { + return new WallOfMourning(this); + } +} + +class WallOfMourningExileEffect extends OneShotEffect { + + WallOfMourningExileEffect() { + super(Outcome.Benefit); + staticText = "exile a card from the top of your library face down for each opponent you have"; + } + + private WallOfMourningExileEffect(final WallOfMourningExileEffect effect) { + super(effect); + } + + @Override + public WallOfMourningExileEffect copy() { + return new WallOfMourningExileEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + int opponents = OpponentsCount.instance.calculate(game, source, this); + Set cards = player.getLibrary().getTopCards(game, opponents); + cards.removeIf(Objects::isNull); + player.moveCardsToExile( + cards, source, game, false, + CardUtil.getExileZoneId(game, source), + CardUtil.getSourceLogName(game, source) + ); + for (Card card : cards) { + card.setFaceDown(true, game); + } + return true; + } +} + +class WallOfMourningReturnEffect extends OneShotEffect { + + WallOfMourningReturnEffect() { + super(Outcome.Benefit); + staticText = "put a card exiled with {this} into its owner's hand"; + } + + private WallOfMourningReturnEffect(final WallOfMourningReturnEffect effect) { + super(effect); + } + + @Override + public WallOfMourningReturnEffect copy() { + return new WallOfMourningReturnEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)); + if (exileZone == null || exileZone.isEmpty()) { + return false; + } + return player.moveCards(exileZone.getRandom(game), Zone.HAND, source, game); + } +} diff --git a/Mage.Sets/src/mage/sets/MidnightHuntCommander.java b/Mage.Sets/src/mage/sets/MidnightHuntCommander.java index 031cb9042b2..7c13f01eab9 100644 --- a/Mage.Sets/src/mage/sets/MidnightHuntCommander.java +++ b/Mage.Sets/src/mage/sets/MidnightHuntCommander.java @@ -159,6 +159,7 @@ public final class MidnightHuntCommander extends ExpansionSet { cards.add(new SetCardInfo("Visions of Duplicity", 33, Rarity.RARE, mage.cards.v.VisionsOfDuplicity.class)); cards.add(new SetCardInfo("Visions of Glory", 32, Rarity.RARE, mage.cards.v.VisionsOfGlory.class)); cards.add(new SetCardInfo("Visions of Ruin", 36, Rarity.RARE, mage.cards.v.VisionsOfRuin.class)); + cards.add(new SetCardInfo("Wall of Mourning", 10, Rarity.RARE, mage.cards.w.WallOfMourning.class)); cards.add(new SetCardInfo("Wild Beastmaster", 146, Rarity.RARE, mage.cards.w.WildBeastmaster.class)); cards.add(new SetCardInfo("Wilhelt, the Rotcleaver", 2, Rarity.MYTHIC, mage.cards.w.WilheltTheRotcleaver.class)); cards.add(new SetCardInfo("Yavimaya Elder", 147, Rarity.COMMON, mage.cards.y.YavimayaElder.class)); diff --git a/Mage/src/main/java/mage/cards/CardsImpl.java b/Mage/src/main/java/mage/cards/CardsImpl.java index 4c7b2a725cb..b0f45e4ab9c 100644 --- a/Mage/src/main/java/mage/cards/CardsImpl.java +++ b/Mage/src/main/java/mage/cards/CardsImpl.java @@ -91,8 +91,7 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl if (this.isEmpty()) { return null; } - UUID[] cards = this.toArray(new UUID[this.size()]); - MageObject object = game.getObject(cards[RandomUtil.nextInt(cards.length)]); // neccessary if permanent tokens are in the collection + MageObject object = game.getObject(RandomUtil.randomFromCollection(this)); // neccessary if permanent tokens are in the collection if (object instanceof Card) { return (Card) object; }