From 22bf9220765c0c3962497621b7badf01c835f690 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Fri, 9 Jul 2021 09:24:51 -0400 Subject: [PATCH] [AFR] Implemented The Book of Vile Darkness --- .../mage/cards/t/TheBookOfVileDarkness.java | 196 ++++++++++++++++++ .../sets/AdventuresInTheForgottenRealms.java | 1 + .../mage/game/permanent/token/VecnaToken.java | 33 +++ 3 files changed, 230 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/t/TheBookOfVileDarkness.java create mode 100644 Mage/src/main/java/mage/game/permanent/token/VecnaToken.java diff --git a/Mage.Sets/src/mage/cards/t/TheBookOfVileDarkness.java b/Mage.Sets/src/mage/cards/t/TheBookOfVileDarkness.java new file mode 100644 index 00000000000..a03132e0df6 --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TheBookOfVileDarkness.java @@ -0,0 +1,196 @@ +package mage.cards.t; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.TriggeredAbility; +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.condition.Condition; +import mage.abilities.costs.Cost; +import mage.abilities.costs.CostImpl; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.CardsImpl; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledArtifactPermanent; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.Token; +import mage.game.permanent.token.VecnaToken; +import mage.game.permanent.token.ZombieToken; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.watchers.common.PlayerLostLifeWatcher; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class TheBookOfVileDarkness extends CardImpl { + + public TheBookOfVileDarkness(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{B}{B}{B}"); + + this.addSuperType(SuperType.LEGENDARY); + + // At the beginning of your end step, if you lost 2 or more life this turn, create a 2/2 black Zombie creature token. + this.addAbility(new BeginningOfEndStepTriggeredAbility( + Zone.BATTLEFIELD, new CreateTokenEffect(new ZombieToken()), TargetController.YOU, + TheBookOfVileDarknessCondition.instance, false + )); + + // {T}, Exile The Book of Vile Darkness and artifacts you control named Eye of Vecna and Hand of Vecna: Create Vecna, a legendary 8/8 black Zombie God creature token with indestructible and all triggered abilities of the exiled cards. + Ability ability = new SimpleActivatedAbility(new TheBookOfVileDarknessEffect(), new TapSourceCost()); + ability.addCost(new TheBookOfVileDarknessCost()); + this.addAbility(ability); + } + + private TheBookOfVileDarkness(final TheBookOfVileDarkness card) { + super(card); + } + + @Override + public TheBookOfVileDarkness copy() { + return new TheBookOfVileDarkness(this); + } +} + +enum TheBookOfVileDarknessCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class); + return watcher != null && watcher.getLifeLost(source.getControllerId()) >= 2; + } + + @Override + public String toString() { + return "if you lost 2 or more life this turn"; + } +} + +class TheBookOfVileDarknessCost extends CostImpl { + + private static final FilterPermanent filter1 + = new FilterControlledArtifactPermanent("artifact you control named Eye of Vecna"); + private static final FilterPermanent filter2 + = new FilterControlledArtifactPermanent("artifact you control named Hand of Vecna"); + + static { + filter1.add(new NamePredicate("Eye of Vecna")); + filter2.add(new NamePredicate("Hand of Vecna")); + } + + public TheBookOfVileDarknessCost() { + this.text = "exile {this} and artifacts you control named Eye of Vecna and Hand of Vecna"; + } + + public TheBookOfVileDarknessCost(final TheBookOfVileDarknessCost cost) { + super(cost); + } + + @Override + public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) { + Player controller = game.getPlayer(controllerId); + Permanent sourcePermanent = ability.getSourcePermanentIfItStillExists(game); + if (controller == null || sourcePermanent == null) { + return paid; + } + Permanent eye = getPermanent(filter1, controller, ability, game); + if (eye == null) { + return paid; + } + Permanent hand = getPermanent(filter2, controller, ability, game); + if (hand == null) { + return paid; + } + controller.moveCards(new CardsImpl(Arrays.asList(sourcePermanent, eye, hand)), Zone.EXILED, source, game); + Set morSet = new HashSet<>(); + morSet.add(new MageObjectReference(sourcePermanent, game)); + morSet.add(new MageObjectReference(eye, game)); + morSet.add(new MageObjectReference(hand, game)); + ability.getEffects().setValue("BookEyeHand", morSet); + paid = true; + return paid; + } + + @Override + public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { + return source.getSourcePermanentIfItStillExists(game) != null + && game.getBattlefield().count(filter1, source.getSourceId(), source.getControllerId(), game) > 0 + && game.getBattlefield().count(filter2, source.getSourceId(), source.getControllerId(), game) > 0; + } + + private static Permanent getPermanent(FilterPermanent filter, Player controller, Ability source, Game game) { + int count = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game); + switch (count) { + case 0: + return null; + case 1: + return game.getBattlefield().getActivePermanents( + filter, source.getControllerId(), source.getSourceId(), game + ).stream().findFirst().orElse(null); + default: + break; + } + TargetPermanent target = new TargetPermanent(filter); + target.setNotTarget(true); + controller.choose(Outcome.Sacrifice, target, source.getControllerId(), game); + return game.getPermanent(target.getFirstTarget()); + } + + @Override + public TheBookOfVileDarknessCost copy() { + return new TheBookOfVileDarknessCost(this); + } +} + +class TheBookOfVileDarknessEffect extends OneShotEffect { + + TheBookOfVileDarknessEffect() { + super(Outcome.Benefit); + staticText = "create Vecna, a legendary 8/8 black Zombie God creature token " + + "with indestructible and all triggered abilities of the exiled cards"; + } + + private TheBookOfVileDarknessEffect(final TheBookOfVileDarknessEffect effect) { + super(effect); + } + + @Override + public TheBookOfVileDarknessEffect copy() { + return new TheBookOfVileDarknessEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Set morSet = (Set) getValue("BookEyeHand"); + if (morSet == null) { + return false; + } + Token token = new VecnaToken(); + for (MageObjectReference mor : morSet) { + Card card = mor.getCard(game); + if (card == null) { + continue; + } + for (Ability ability : card.getAbilities(game)) { + if (ability instanceof TriggeredAbility) { + token.addAbility(ability.copy()); + } + } + } + return token.putOntoBattlefield(1, game, source, source.getControllerId()); + } +} diff --git a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java index 7c292f64508..cd44c4e5e84 100644 --- a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java +++ b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java @@ -205,6 +205,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet { cards.add(new SetCardInfo("Targ Nar, Demon-Fang Gnoll", 234, Rarity.UNCOMMON, mage.cards.t.TargNarDemonFangGnoll.class)); cards.add(new SetCardInfo("Tasha's Hideous Laughter", 78, Rarity.RARE, mage.cards.t.TashasHideousLaughter.class)); cards.add(new SetCardInfo("The Book of Exalted Deeds", 4, Rarity.MYTHIC, mage.cards.t.TheBookOfExaltedDeeds.class)); + cards.add(new SetCardInfo("The Book of Vile Darkness", 91, Rarity.MYTHIC, mage.cards.t.TheBookOfVileDarkness.class)); cards.add(new SetCardInfo("The Deck of Many Things", 241, Rarity.MYTHIC, mage.cards.t.TheDeckOfManyThings.class)); cards.add(new SetCardInfo("Thieves' Tools", 122, Rarity.COMMON, mage.cards.t.ThievesTools.class)); cards.add(new SetCardInfo("Tiamat", 235, Rarity.MYTHIC, mage.cards.t.Tiamat.class)); diff --git a/Mage/src/main/java/mage/game/permanent/token/VecnaToken.java b/Mage/src/main/java/mage/game/permanent/token/VecnaToken.java new file mode 100644 index 00000000000..a1d4ebf13db --- /dev/null +++ b/Mage/src/main/java/mage/game/permanent/token/VecnaToken.java @@ -0,0 +1,33 @@ +package mage.game.permanent.token; + +import mage.MageInt; +import mage.abilities.keyword.IndestructibleAbility; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.SuperType; + +/** + * @author TheElk801 + */ +public final class VecnaToken extends TokenImpl { + + public VecnaToken() { + super("Vecna", "Vecna, a legendary 8/8 black Zombie God creature token with indestructible and all triggered abilities of the exiled cards"); + supertype.add(SuperType.LEGENDARY); + cardType.add(CardType.CREATURE); + color.setBlack(true); + subtype.add(SubType.ZOMBIE); + subtype.add(SubType.GOD); + power = new MageInt(8); + toughness = new MageInt(8); + addAbility(IndestructibleAbility.getInstance()); + } + + private VecnaToken(final VecnaToken token) { + super(token); + } + + public VecnaToken copy() { + return new VecnaToken(this); + } +}