From 265b34186866e1a2334d3c887c2fff2fceed35fe Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 31 May 2022 21:29:06 -0400 Subject: [PATCH] [CLB] Implemented Bane's Contingency --- .../src/mage/cards/b/BanesContingency.java | 87 +++++++++++++++++++ .../CommanderLegendsBattleForBaldursGate.java | 1 + 2 files changed, 88 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/b/BanesContingency.java diff --git a/Mage.Sets/src/mage/cards/b/BanesContingency.java b/Mage.Sets/src/mage/cards/b/BanesContingency.java new file mode 100644 index 0000000000..31bde6e086 --- /dev/null +++ b/Mage.Sets/src/mage/cards/b/BanesContingency.java @@ -0,0 +1,87 @@ +package mage.cards.b; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.filter.predicate.mageobject.CommanderPredicate; +import mage.game.Game; +import mage.game.stack.Spell; +import mage.players.Player; +import mage.target.Target; +import mage.target.TargetSpell; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class BanesContingency extends CardImpl { + + public BanesContingency(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}{U}"); + + // Counter target spell. If that spell targets a commander you control, instead counter that spell, scry 2, then draw a card. + this.getSpellAbility().addEffect(new BanesContingencyEffect()); + this.getSpellAbility().addTarget(new TargetSpell()); + } + + private BanesContingency(final BanesContingency card) { + super(card); + } + + @Override + public BanesContingency copy() { + return new BanesContingency(this); + } +} + +class BanesContingencyEffect extends OneShotEffect { + + BanesContingencyEffect() { + super(Outcome.Benefit); + staticText = "counter target spell. If that spell targets a commander you control, " + + "instead counter that spell, scry 2, then draw a card"; + } + + private BanesContingencyEffect(final BanesContingencyEffect effect) { + super(effect); + } + + @Override + public BanesContingencyEffect copy() { + return new BanesContingencyEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = game.getSpell(getTargetPointer().getFirst(game, source)); + if (spell == null) { + return false; + } + boolean flag = spell + .getSpellAbility() + .getTargets() + .stream() + .map(Target::getTargets) + .flatMap(Collection::stream) + .map(game::getPermanent) + .filter(Objects::nonNull) + .filter(permanent -> permanent.isControlledBy(source.getControllerId())) + .anyMatch(permanent -> CommanderPredicate.instance.apply(permanent, game)); + game.getStack().counter(spell.getId(), source, game); + if (!flag) { + return true; + } + Player player = game.getPlayer(source.getControllerId()); + if (player != null) { + player.scry(2, source, game); + player.drawCards(1, source, game); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java index ecba35bdc3..4c9f42c5b8 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java +++ b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java @@ -52,6 +52,7 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet { cards.add(new SetCardInfo("Bag of Holding", 299, Rarity.UNCOMMON, mage.cards.b.BagOfHolding.class)); cards.add(new SetCardInfo("Baldur's Gate", 345, Rarity.RARE, mage.cards.b.BaldursGate.class)); cards.add(new SetCardInfo("Band Together", 216, Rarity.COMMON, mage.cards.b.BandTogether.class)); + cards.add(new SetCardInfo("Bane's Contingency", 57, Rarity.UNCOMMON, mage.cards.b.BanesContingency.class)); cards.add(new SetCardInfo("Bane's Invoker", 7, Rarity.COMMON, mage.cards.b.BanesInvoker.class)); cards.add(new SetCardInfo("Basilisk Collar", 300, Rarity.RARE, mage.cards.b.BasiliskCollar.class)); cards.add(new SetCardInfo("Basilisk Gate", 346, Rarity.COMMON, mage.cards.b.BasiliskGate.class));