From 1d4fc1369aa68cf086c7366cf970ec125a332a87 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 6 Apr 2021 09:25:48 -0400 Subject: [PATCH] [STX] Implemented Silverquill Silencer --- .../src/mage/cards/s/SilverquillSilencer.java | 78 +++++++++++++++++++ .../mage/sets/StrixhavenSchoolOfMages.java | 1 + .../SpellCastOpponentTriggeredAbility.java | 41 +++++----- 3 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/s/SilverquillSilencer.java diff --git a/Mage.Sets/src/mage/cards/s/SilverquillSilencer.java b/Mage.Sets/src/mage/cards/s/SilverquillSilencer.java new file mode 100644 index 0000000000..8ea5ef8ed9 --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SilverquillSilencer.java @@ -0,0 +1,78 @@ +package mage.cards.s; + +import mage.MageInt; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.AsEntersBattlefieldAbility; +import mage.abilities.common.SpellCastOpponentTriggeredAbility; +import mage.abilities.effects.common.ChooseACardNameEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.LoseLifeTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SetTargetPointer; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.FilterSpell; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.game.Game; +import mage.util.CardUtil; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class SilverquillSilencer extends CardImpl { + + private static final FilterSpell filter = new FilterSpell("a spell with the chosen name"); + + static { + filter.add(SilverquillSilencerPredicate.instance); + } + + public SilverquillSilencer(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{W}{B}"); + + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.CLERIC); + this.power = new MageInt(3); + this.toughness = new MageInt(2); + + // As Silverquill Silencer enters the battlefield, choose a nonland card name. + this.addAbility(new AsEntersBattlefieldAbility( + new ChooseACardNameEffect(ChooseACardNameEffect.TypeOfName.NON_LAND_NAME) + )); + + // Whenever an opponent casts a spell with the chosen name, they lose 3 life and you draw a card. + Ability ability = new SpellCastOpponentTriggeredAbility( + Zone.BATTLEFIELD, new LoseLifeTargetEffect(3).setText("they lose 3 life"), + filter, false, SetTargetPointer.PLAYER + ); + ability.addEffect(new DrawCardSourceControllerEffect(1).concatBy("and you")); + this.addAbility(ability); + } + + private SilverquillSilencer(final SilverquillSilencer card) { + super(card); + } + + @Override + public SilverquillSilencer copy() { + return new SilverquillSilencer(this); + } +} + +enum SilverquillSilencerPredicate implements ObjectSourcePlayerPredicate> { + instance; + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + String cardName = (String) game.getState().getValue( + input.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY + ); + return CardUtil.haveSameNames(input.getObject().getName(), cardName); + } +} diff --git a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java index c741508e01..95ab969918 100644 --- a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java +++ b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java @@ -204,6 +204,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet { cards.add(new SetCardInfo("Silverquill Campus", 273, Rarity.COMMON, mage.cards.s.SilverquillCampus.class)); cards.add(new SetCardInfo("Silverquill Command", 232, Rarity.RARE, mage.cards.s.SilverquillCommand.class)); cards.add(new SetCardInfo("Silverquill Pledgemage", 233, Rarity.COMMON, mage.cards.s.SilverquillPledgemage.class)); + cards.add(new SetCardInfo("Silverquill Silencer", 234, Rarity.RARE, mage.cards.s.SilverquillSilencer.class)); cards.add(new SetCardInfo("Snow Day", 53, Rarity.UNCOMMON, mage.cards.s.SnowDay.class)); cards.add(new SetCardInfo("Solve the Equation", 54, Rarity.UNCOMMON, mage.cards.s.SolveTheEquation.class)); cards.add(new SetCardInfo("Soothsayer Adept", 55, Rarity.COMMON, mage.cards.s.SoothsayerAdept.class)); diff --git a/Mage/src/main/java/mage/abilities/common/SpellCastOpponentTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/SpellCastOpponentTriggeredAbility.java index df7e7e02ae..47ced845e9 100644 --- a/Mage/src/main/java/mage/abilities/common/SpellCastOpponentTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/SpellCastOpponentTriggeredAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.common; import mage.abilities.TriggeredAbilityImpl; @@ -58,28 +57,26 @@ public class SpellCastOpponentTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - if (game.getPlayer(this.getControllerId()).hasOpponent(event.getPlayerId(), game)) { - Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && filter.match(spell, game)) { - if (setTargetPointer != SetTargetPointer.NONE) { - for (Effect effect : this.getEffects()) { - switch (setTargetPointer) { - case SPELL: - effect.setTargetPointer(new FixedTarget(event.getTargetId())); - break; - case PLAYER: - effect.setTargetPointer(new FixedTarget(event.getPlayerId())); - break; - default: - throw new UnsupportedOperationException("Value of SetTargetPointer not supported!"); - } - - } - } - return true; - } + if (!game.getPlayer(this.getControllerId()).hasOpponent(event.getPlayerId(), game)) { + return false; } - return false; + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (spell == null || !filter.match(spell, getSourceId(), getControllerId(), game)) { + return false; + } + switch (setTargetPointer) { + case NONE: + break; + case SPELL: + getEffects().setTargetPointer(new FixedTarget(event.getTargetId())); + break; + case PLAYER: + getEffects().setTargetPointer(new FixedTarget(event.getPlayerId())); + break; + default: + throw new UnsupportedOperationException("Value of SetTargetPointer not supported!"); + } + return true; } @Override