[CLB] Implemented Bane's Contingency

This commit is contained in:
Evan Kranzler 2022-05-31 21:29:06 -04:00
parent 2f9644b7ee
commit 265b341868
2 changed files with 88 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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("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("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("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("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 Collar", 300, Rarity.RARE, mage.cards.b.BasiliskCollar.class));
cards.add(new SetCardInfo("Basilisk Gate", 346, Rarity.COMMON, mage.cards.b.BasiliskGate.class)); cards.add(new SetCardInfo("Basilisk Gate", 346, Rarity.COMMON, mage.cards.b.BasiliskGate.class));