From f1bb76b40d156eff4898a867a82290b655413448 Mon Sep 17 00:00:00 2001 From: Jozsef Kerekes Date: Wed, 27 Jan 2021 14:40:55 +0200 Subject: [PATCH] [KHM] Implemented King Narfi's Betrayal (#7446) * [KHM] Implemented King Narfi's Betrayal * [KHM] Corrected rules text for King Narfi's Betrayal * [KHM] Allow adventure cards to go on adventures when exiled with King Narfi's Betrayal * CanPlayCardControllerEffect - Fixed handling of Adventure/Split Cards * [KHM] King Narfi's Betrayal - Added null check and fixed rules text Co-authored-by: Daniel Bomar --- .../src/mage/cards/k/KingNarfisBetrayal.java | 156 ++++++++++++++++++ Mage.Sets/src/mage/sets/Kaldheim.java | 1 + .../CanPlayCardControllerEffect.java | 2 +- 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 Mage.Sets/src/mage/cards/k/KingNarfisBetrayal.java diff --git a/Mage.Sets/src/mage/cards/k/KingNarfisBetrayal.java b/Mage.Sets/src/mage/cards/k/KingNarfisBetrayal.java new file mode 100644 index 0000000000..feec62e03e --- /dev/null +++ b/Mage.Sets/src/mage/cards/k/KingNarfisBetrayal.java @@ -0,0 +1,156 @@ +package mage.cards.k; + +import mage.abilities.Ability; +import mage.abilities.common.SagaAbility; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.MillCardsEachPlayerEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterCard; +import mage.filter.predicate.Predicates; +import mage.game.ExileZone; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetCard; +import mage.target.common.TargetCardInOpponentsGraveyard; +import mage.target.common.TargetCardInYourGraveyard; +import mage.util.CardUtil; + +import java.util.UUID; + +/** + * + * @author varaghar + */ +public final class KingNarfisBetrayal extends CardImpl { + + public KingNarfisBetrayal(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}{B}"); + + this.subtype.add(SubType.SAGA); + + // (As this Saga enters and after your draw step, add a lore counter. Sacrifice after III.) + SagaAbility sagaAbility = new SagaAbility(this, SagaChapter.CHAPTER_III); + + //I — Each player mills four cards. You may exile up to one creature or planeswalker card from each graveyard. + sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_I, new KingNarfisBetrayalFirstEffect()); + + //II, III — Until end of turn, you may cast spells from among cards exiled with King Narfi's Betrayal, and you may spend mana as though it were mana of any color to cast those spells. + sagaAbility.addChapterEffect(this, SagaChapter.CHAPTER_II, SagaChapter.CHAPTER_III, new KingNarfisBetrayalSecondEffect()); + + this.addAbility(sagaAbility); + } + + private KingNarfisBetrayal(final KingNarfisBetrayal card) { + super(card); + } + + @Override + public KingNarfisBetrayal copy() { + return new KingNarfisBetrayal(this); + } +} + +class KingNarfisBetrayalFirstEffect extends OneShotEffect { + + private static final Effect millEffect = new MillCardsEachPlayerEffect(4, TargetController.EACH_PLAYER); + private static final FilterCard filter = new FilterCard("creature or planeswalker card from each graveyard"); + + static { + filter.add(Predicates.or( + CardType.CREATURE.getPredicate(), + CardType.PLANESWALKER.getPredicate() + )); + } + + KingNarfisBetrayalFirstEffect() { + super(Outcome.Benefit); + staticText = "Each player mills four cards. You may exile up to one creature or planeswalker " + + "card from each graveyard"; + } + + private KingNarfisBetrayalFirstEffect(final KingNarfisBetrayalFirstEffect effect) { + super(effect); + } + + @Override + public KingNarfisBetrayalFirstEffect copy() { + return new KingNarfisBetrayalFirstEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + UUID controllerId = source.getControllerId(); + Player controller = game.getPlayer(controllerId); + if (controller == null) { + return false; + } + millEffect.apply(game, source); + + //Controller graveyard + if (controller.getGraveyard().count(filter, game) != 0) { + if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from your graveyard?", source, game)) { + TargetCard target = new TargetCardInYourGraveyard(filter); + target.setNotTarget(true); + if (controller.chooseTarget(outcome, controller.getGraveyard(), target, source, game)) { + controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null)); + } + } + } + + //Each opponent's graveyard + for (UUID opponentId : game.getOpponents(controllerId)) { + Player opponent = game.getPlayer(opponentId); + if (opponent == null) { + continue; + } + + if (opponent.getGraveyard().count(filter, game) != 0) { + if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from " + opponent.getName() + "'s graveyard?", source, game)) { + TargetCard target = new TargetCardInOpponentsGraveyard(1, 1, filter, true); + target.setNotTarget(true); + if (controller.chooseTarget(outcome, opponent.getGraveyard(), target, source, game)) { + controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null)); + } + } + } + } + + return true; + } +} + +class KingNarfisBetrayalSecondEffect extends OneShotEffect { + + + public KingNarfisBetrayalSecondEffect() { + super(Outcome.Benefit); + this.staticText = "Until end of turn, you may cast spells from among cards exiled with King Narfi's Betrayal," + + " and you may spend mana as though it were mana of any color to cast those spells"; + } + + public KingNarfisBetrayalSecondEffect(final KingNarfisBetrayalSecondEffect effect) { + super(effect); + } + + @Override + public KingNarfisBetrayalSecondEffect copy() { + return new KingNarfisBetrayalSecondEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + ExileZone zone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)); + if (zone != null) { + for (Card card : zone.getCards(game)) { + CardUtil.makeCardPlayableAndSpendManaAsAnyColor(game, source, card, Duration.EndOfTurn); + } + } + + return false; + } + +} diff --git a/Mage.Sets/src/mage/sets/Kaldheim.java b/Mage.Sets/src/mage/sets/Kaldheim.java index 836e11cb7d..12038679d8 100644 --- a/Mage.Sets/src/mage/sets/Kaldheim.java +++ b/Mage.Sets/src/mage/sets/Kaldheim.java @@ -189,6 +189,7 @@ public final class Kaldheim extends ExpansionSet { cards.add(new SetCardInfo("Kaya the Inexorable", 218, Rarity.MYTHIC, mage.cards.k.KayaTheInexorable.class)); cards.add(new SetCardInfo("Kaya's Onslaught", 18, Rarity.UNCOMMON, mage.cards.k.KayasOnslaught.class)); cards.add(new SetCardInfo("King Harald's Revenge", 180, Rarity.COMMON, mage.cards.k.KingHaraldsRevenge.class)); + cards.add(new SetCardInfo("King Narfi's Betrayal", 219, Rarity.RARE, mage.cards.k.KingNarfisBetrayal.class)); cards.add(new SetCardInfo("Koll, the Forgemaster", 220, Rarity.UNCOMMON, mage.cards.k.KollTheForgemaster.class)); cards.add(new SetCardInfo("Kolvori, God of Kinship", 181, Rarity.RARE, mage.cards.k.KolvoriGodOfKinship.class)); cards.add(new SetCardInfo("Koma's Faithful", 102, Rarity.COMMON, mage.cards.k.KomasFaithful.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/asthought/CanPlayCardControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/asthought/CanPlayCardControllerEffect.java index 45f98d8790..77c269c29a 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/asthought/CanPlayCardControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/asthought/CanPlayCardControllerEffect.java @@ -67,4 +67,4 @@ public class CanPlayCardControllerEffect extends AsThoughEffectImpl { UUID objectIdToCast = CardUtil.getMainCardId(game, sourceId); // affected to all card's parts return mor.refersTo(objectIdToCast, game) && source.isControlledBy(affectedControllerId); } -} \ No newline at end of file +}