From 75bd6cf906676b95c9e9c44c3955d161a54a28ac Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 7 Apr 2022 19:58:37 -0400 Subject: [PATCH] [SNC] Implemented Ledger Shredder --- Mage.Sets/src/mage/cards/h/HowlingMoon.java | 2 +- .../src/mage/cards/l/LedgerShredder.java | 43 ++++++++++++++ .../src/mage/sets/StreetsOfNewCapenna.java | 1 + .../CastSecondSpellTriggeredAbility.java | 44 ++++++++++++-- .../effects/keyword/ConniveSourceEffect.java | 58 +++++++++++++++++++ .../effects/keyword/ConniveTargetEffect.java | 19 +----- 6 files changed, 142 insertions(+), 25 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/l/LedgerShredder.java create mode 100644 Mage/src/main/java/mage/abilities/effects/keyword/ConniveSourceEffect.java diff --git a/Mage.Sets/src/mage/cards/h/HowlingMoon.java b/Mage.Sets/src/mage/cards/h/HowlingMoon.java index c272a64586..cb55bb57ab 100644 --- a/Mage.Sets/src/mage/cards/h/HowlingMoon.java +++ b/Mage.Sets/src/mage/cards/h/HowlingMoon.java @@ -56,7 +56,7 @@ public final class HowlingMoon extends CardImpl { } class HowlingMoonTriggeredAbility extends TriggeredAbilityImpl { - + // TODO: replace this and others like it with CastSecondSpellTriggeredAbility public HowlingMoonTriggeredAbility() { super(Zone.BATTLEFIELD, new CreateTokenEffect(new WolfToken())); } diff --git a/Mage.Sets/src/mage/cards/l/LedgerShredder.java b/Mage.Sets/src/mage/cards/l/LedgerShredder.java new file mode 100644 index 0000000000..82254abcc3 --- /dev/null +++ b/Mage.Sets/src/mage/cards/l/LedgerShredder.java @@ -0,0 +1,43 @@ +package mage.cards.l; + +import mage.MageInt; +import mage.abilities.common.CastSecondSpellTriggeredAbility; +import mage.abilities.effects.keyword.ConniveSourceEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.TargetController; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class LedgerShredder extends CardImpl { + + public LedgerShredder(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}"); + + this.subtype.add(SubType.BIRD); + this.subtype.add(SubType.ADVISOR); + this.power = new MageInt(1); + this.toughness = new MageInt(3); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // Whenever a player casts their second spell each turn, Ledger Shredder connives. + this.addAbility(new CastSecondSpellTriggeredAbility(new ConniveSourceEffect(), TargetController.ANY)); + } + + private LedgerShredder(final LedgerShredder card) { + super(card); + } + + @Override + public LedgerShredder copy() { + return new LedgerShredder(this); + } +} diff --git a/Mage.Sets/src/mage/sets/StreetsOfNewCapenna.java b/Mage.Sets/src/mage/sets/StreetsOfNewCapenna.java index c7f620b802..6e07c09b0f 100644 --- a/Mage.Sets/src/mage/sets/StreetsOfNewCapenna.java +++ b/Mage.Sets/src/mage/sets/StreetsOfNewCapenna.java @@ -31,6 +31,7 @@ public final class StreetsOfNewCapenna extends ExpansionSet { cards.add(new SetCardInfo("Island", 264, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Jetmir's Garden", 250, Rarity.RARE, mage.cards.j.JetmirsGarden.class)); cards.add(new SetCardInfo("Jetmir, Nexus of Revels", 193, Rarity.MYTHIC, mage.cards.j.JetmirNexusOfRevels.class)); + cards.add(new SetCardInfo("Ledger Shredder", 46, Rarity.RARE, mage.cards.l.LedgerShredder.class)); cards.add(new SetCardInfo("Lord Xander, the Collector", 197, Rarity.MYTHIC, mage.cards.l.LordXanderTheCollector.class)); cards.add(new SetCardInfo("Maestros Charm", 199, Rarity.UNCOMMON, mage.cards.m.MaestrosCharm.class)); cards.add(new SetCardInfo("Mountain", 268, Rarity.LAND, mage.cards.basiclands.Mountain.class, NON_FULL_USE_VARIOUS)); diff --git a/Mage/src/main/java/mage/abilities/common/CastSecondSpellTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/CastSecondSpellTriggeredAbility.java index 6c40f07da5..a9012a8dad 100644 --- a/Mage/src/main/java/mage/abilities/common/CastSecondSpellTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/CastSecondSpellTriggeredAbility.java @@ -6,6 +6,7 @@ import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; import mage.abilities.hint.Hint; import mage.abilities.hint.ValueHint; +import mage.constants.TargetController; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; @@ -17,19 +18,28 @@ import mage.watchers.common.CastSpellLastTurnWatcher; public class CastSecondSpellTriggeredAbility extends TriggeredAbilityImpl { private static final Hint hint = new ValueHint("Spells you cast this turn", SpellCastValue.instance); + private final TargetController targetController; public CastSecondSpellTriggeredAbility(Effect effect) { - this(Zone.BATTLEFIELD, effect, false); + this(effect, TargetController.YOU); } - public CastSecondSpellTriggeredAbility(Zone zone, Effect effect, boolean optional) { + public CastSecondSpellTriggeredAbility(Effect effect, TargetController targetController) { + this(Zone.BATTLEFIELD, effect, targetController, false); + } + + public CastSecondSpellTriggeredAbility(Zone zone, Effect effect, TargetController targetController, boolean optional) { super(zone, effect, optional); this.addWatcher(new CastSpellLastTurnWatcher()); - this.addHint(hint); + if (targetController == TargetController.YOU) { + this.addHint(hint); + } + this.targetController = targetController; } private CastSecondSpellTriggeredAbility(final CastSecondSpellTriggeredAbility ability) { super(ability); + this.targetController = ability.targetController; } @Override @@ -39,8 +49,21 @@ public class CastSecondSpellTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - if (!isControlledBy(event.getPlayerId())) { - return false; + switch (targetController) { + case YOU: + if (!isControlledBy(event.getPlayerId())) { + return false; + } + break; + case OPPONENT: + if (!game.getOpponents(getControllerId()).contains(event.getPlayerId())) { + return false; + } + break; + case ANY: + break; + default: + throw new IllegalArgumentException("TargetController " + targetController + " not supported"); } CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); return watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2; @@ -48,7 +71,16 @@ public class CastSecondSpellTriggeredAbility extends TriggeredAbilityImpl { @Override public String getTriggerPhrase() { - return "Whenever you cast your second spell each turn, " ; + switch (targetController) { + case YOU: + return "Whenever you cast your second spell each turn, "; + case OPPONENT: + return "Whenever an opponent casts their second spell each turn, "; + case ANY: + return "Whenever a player casts their second spell each turn, "; + default: + throw new IllegalArgumentException("TargetController " + targetController + " not supported"); + } } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/keyword/ConniveSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/keyword/ConniveSourceEffect.java new file mode 100644 index 0000000000..5c3ac65790 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/keyword/ConniveSourceEffect.java @@ -0,0 +1,58 @@ +package mage.abilities.effects.keyword; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * @author TheElk801 + */ +public class ConniveSourceEffect extends OneShotEffect { + + public ConniveSourceEffect() { + super(Outcome.Benefit); + staticText = "{this} connives. (Draw a card, then discard a card. " + + "If you discarded a nonland card, put a +1/+1 counter on this creature.)"; + } + + private ConniveSourceEffect(final ConniveSourceEffect effect) { + super(effect); + } + + @Override + public ConniveSourceEffect copy() { + return new ConniveSourceEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null) { + return false; + } + return permanent != null && connive(permanent, 1, source, game); + } + + public static boolean connive(Permanent permanent, int amount, Ability source, Game game) { + if (amount < 1) { + return false; + } + Player player = game.getPlayer(permanent.getControllerId()); + if (player == null) { + return false; + } + player.drawCards(amount, source, game); + int counters = player + .discard(amount, false, false, source, game) + .count(StaticFilters.FILTER_CARDS_NON_LAND, game); + if (counters > 0) { + permanent.addCounters(CounterType.P1P1.createInstance(counters), source, game); + } + return true; + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/keyword/ConniveTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/keyword/ConniveTargetEffect.java index 529c91a833..086b999d94 100644 --- a/Mage/src/main/java/mage/abilities/effects/keyword/ConniveTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/keyword/ConniveTargetEffect.java @@ -6,11 +6,8 @@ import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; import mage.constants.Outcome; -import mage.counters.CounterType; -import mage.filter.StaticFilters; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.players.Player; /** * @author TheElk801 @@ -44,22 +41,8 @@ public class ConniveTargetEffect extends OneShotEffect { if (permanent == null) { return false; } - Player player = game.getPlayer(permanent.getControllerId()); - if (player == null) { - return false; - } int amount = xValue.calculate(game, source, this); - if (amount < 1) { - return false; - } - player.drawCards(amount, source, game); - int counters = player.discard( - amount, false, false, source, game - ).count(StaticFilters.FILTER_CARDS_NON_LAND, game); - if (counters > 0) { - permanent.addCounters(CounterType.P1P1.createInstance(counters), source, game); - } - return true; + return amount > 0 && ConniveSourceEffect.connive(permanent, amount, source, game); } @Override