diff --git a/Mage.Sets/src/mage/cards/r/RiseOfTheWitchKing.java b/Mage.Sets/src/mage/cards/r/RiseOfTheWitchKing.java new file mode 100644 index 00000000000..b16ff02eef6 --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RiseOfTheWitchKing.java @@ -0,0 +1,120 @@ +package mage.cards.r; + +import java.util.ArrayList; +import java.util.List; +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.TargetController; +import mage.constants.Zone; +import mage.filter.StaticFilters; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.common.FilterControlledPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.common.TargetCardInYourGraveyard; + +/** + * + * @author Susucr + */ +public final class RiseOfTheWitchKing extends CardImpl { + + public RiseOfTheWitchKing(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{B}{G}"); + + + // Each player sacrifices a creature. If you sacrificed a creature this way, + // you may return another permanent card from your graveyard to the battlefield. + this.getSpellAbility().addEffect(new RiseOfTheWitchKingEffect()); + } + + private RiseOfTheWitchKing(final RiseOfTheWitchKing card) { + super(card); + } + + @Override + public RiseOfTheWitchKing copy() { + return new RiseOfTheWitchKing(this); + } +} + +class RiseOfTheWitchKingEffect extends OneShotEffect { + private static final FilterControlledPermanent filter = new FilterControlledCreaturePermanent("creature"); + + static { + filter.add(TargetController.YOU.getControllerPredicate()); + } + + RiseOfTheWitchKingEffect() { + super(Outcome.Benefit); + staticText = "each player sacrifices a creature. If you sacrificed a creature this way, " + + "you may return another permanent card from your graveyard to the battlefield"; + } + + private RiseOfTheWitchKingEffect(final RiseOfTheWitchKingEffect effect) { + super(effect); + } + + @Override + public RiseOfTheWitchKingEffect copy() { + return new RiseOfTheWitchKingEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller == null) { + return false; + } + List toSacrifice = new ArrayList<>(); + Permanent yours = null; + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player == null) { + continue; + } + TargetPermanent target = new TargetPermanent(filter); + target.setNotTarget(true); + if (!target.canChoose(playerId, source, game)) { + continue; + } + player.choose(outcome, target, source, game); + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent == null) { + continue; + } + if (permanent.isControlledBy(source.getControllerId())) { + yours = permanent; + } else { + toSacrifice.add(permanent); + } + } + for (Permanent permanent : toSacrifice) { + if (permanent == null) { + continue; + } + permanent.sacrifice(source, game); + } + Cards yourGrave = new CardsImpl(controller.getGraveyard()); + yourGrave.removeIf(uuid -> !game.getCard(uuid).isPermanent(game)); + if (yours == null || !yours.sacrifice(source, game)) { + return true; + } + TargetCardInYourGraveyard target = new TargetCardInYourGraveyard( + 0, 1, StaticFilters.FILTER_CARD_PERMANENT, true + ); + controller.choose(outcome, yourGrave, target, source, game); + Card card = controller.getGraveyard().get(target.getFirstTarget(), game); + if (card != null) { + controller.moveCards(card, Zone.BATTLEFIELD, source, game); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java index 91dbb92e7a1..6143295f71f 100644 --- a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java +++ b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java @@ -182,6 +182,7 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet { cards.add(new SetCardInfo("Revive the Shire", 185, Rarity.COMMON, mage.cards.r.ReviveTheShire.class)); cards.add(new SetCardInfo("Ringsight", 220, Rarity.UNCOMMON, mage.cards.r.Ringsight.class)); cards.add(new SetCardInfo("Ringwraiths", 284, Rarity.RARE, mage.cards.r.Ringwraiths.class)); + cards.add(new SetCardInfo("Rise of the Witch-king", 221, Rarity.UNCOMMON, mage.cards.r.RiseOfTheWitchKing.class)); cards.add(new SetCardInfo("Rising of the Day", 145, Rarity.UNCOMMON, mage.cards.r.RisingOfTheDay.class)); cards.add(new SetCardInfo("Rivendell", 259, Rarity.RARE, mage.cards.r.Rivendell.class)); cards.add(new SetCardInfo("Rohirrim Lancer", 146, Rarity.COMMON, mage.cards.r.RohirrimLancer.class));