From 9cdcc6b35dda47c9e24179316451ca8a0f3ce837 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 7 Apr 2022 22:11:22 -0400 Subject: [PATCH] deduplicated code with CastSecondSpellTriggeredAbility --- Mage.Sets/src/mage/cards/h/HowlingMoon.java | 54 ++++------------- .../src/mage/cards/k/KraumLudevicsOpus.java | 55 +++-------------- .../src/mage/cards/m/MangaraTheDiplomat.java | 60 ++++--------------- Mage.Sets/src/mage/cards/m/MonologueTax.java | 50 +++------------- 4 files changed, 35 insertions(+), 184 deletions(-) diff --git a/Mage.Sets/src/mage/cards/h/HowlingMoon.java b/Mage.Sets/src/mage/cards/h/HowlingMoon.java index cb55bb57ab..1a489ce69b 100644 --- a/Mage.Sets/src/mage/cards/h/HowlingMoon.java +++ b/Mage.Sets/src/mage/cards/h/HowlingMoon.java @@ -1,25 +1,24 @@ package mage.cards.h; -import java.util.UUID; - import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.BeginningOfCombatTriggeredAbility; +import mage.abilities.common.CastSecondSpellTriggeredAbility; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.SubType; +import mage.constants.TargetController; import mage.filter.common.FilterControlledPermanent; import mage.filter.predicate.Predicates; -import mage.game.Game; -import mage.game.events.GameEvent; import mage.game.permanent.token.WolfToken; import mage.target.common.TargetControlledPermanent; -import mage.watchers.common.CastSpellLastTurnWatcher; + +import java.util.UUID; /** - * * @author weirddan455 */ public final class HowlingMoon extends CardImpl { @@ -42,7 +41,9 @@ public final class HowlingMoon extends CardImpl { this.addAbility(ability); // Whenever an opponent casts their second spell each turn, create a 2/2 green Wolf creature token. - this.addAbility(new HowlingMoonTriggeredAbility(), new CastSpellLastTurnWatcher()); + this.addAbility(new CastSecondSpellTriggeredAbility( + new CreateTokenEffect(new WolfToken()), TargetController.OPPONENT + )); } private HowlingMoon(final HowlingMoon card) { @@ -54,38 +55,3 @@ public final class HowlingMoon extends CardImpl { return new HowlingMoon(this); } } - -class HowlingMoonTriggeredAbility extends TriggeredAbilityImpl { - // TODO: replace this and others like it with CastSecondSpellTriggeredAbility - public HowlingMoonTriggeredAbility() { - super(Zone.BATTLEFIELD, new CreateTokenEffect(new WolfToken())); - } - - private HowlingMoonTriggeredAbility(final HowlingMoonTriggeredAbility ability) { - super(ability); - } - - @Override - public HowlingMoonTriggeredAbility copy() { - return new HowlingMoonTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.SPELL_CAST; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (game.getOpponents(controllerId).contains(event.getPlayerId())) { - CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); - return watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2; - } - return false; - } - - @Override - public String getTriggerPhrase() { - return "Whenever an opponent casts their second spell each turn, "; - } -} diff --git a/Mage.Sets/src/mage/cards/k/KraumLudevicsOpus.java b/Mage.Sets/src/mage/cards/k/KraumLudevicsOpus.java index 5341966c66..955727ba83 100644 --- a/Mage.Sets/src/mage/cards/k/KraumLudevicsOpus.java +++ b/Mage.Sets/src/mage/cards/k/KraumLudevicsOpus.java @@ -1,9 +1,7 @@ - package mage.cards.k; -import java.util.UUID; import mage.MageInt; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.CastSecondSpellTriggeredAbility; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.HasteAbility; @@ -13,14 +11,11 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.SuperType; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.watchers.common.CastSpellLastTurnWatcher; +import mage.constants.TargetController; + +import java.util.UUID; /** - * * @author Styxo */ public final class KraumLudevicsOpus extends CardImpl { @@ -40,11 +35,12 @@ public final class KraumLudevicsOpus extends CardImpl { this.addAbility(HasteAbility.getInstance()); // Whenever an opponent casts their second spell each turn, draw a card. - this.addAbility(new KraumLudevicsOpusTriggeredAbility(), new CastSpellLastTurnWatcher()); + this.addAbility(new CastSecondSpellTriggeredAbility( + new DrawCardSourceControllerEffect(1), TargetController.OPPONENT + )); // Partner this.addAbility(PartnerAbility.getInstance()); - } private KraumLudevicsOpus(final KraumLudevicsOpus card) { @@ -56,40 +52,3 @@ public final class KraumLudevicsOpus extends CardImpl { return new KraumLudevicsOpus(this); } } - -class KraumLudevicsOpusTriggeredAbility extends TriggeredAbilityImpl { - - public KraumLudevicsOpusTriggeredAbility() { - super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1)); - } - - public KraumLudevicsOpusTriggeredAbility(final KraumLudevicsOpusTriggeredAbility ability) { - super(ability); - } - - @Override - public KraumLudevicsOpusTriggeredAbility copy() { - return new KraumLudevicsOpusTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.SPELL_CAST; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (game.getOpponents(controllerId).contains(event.getPlayerId())) { - CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); - if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2) { - return true; - } - } - return false; - } - - @Override - public String getRule() { - return "Whenever an opponent casts their second spell each turn, draw a card."; - } -} diff --git a/Mage.Sets/src/mage/cards/m/MangaraTheDiplomat.java b/Mage.Sets/src/mage/cards/m/MangaraTheDiplomat.java index 7b1d5b3135..2906626a04 100644 --- a/Mage.Sets/src/mage/cards/m/MangaraTheDiplomat.java +++ b/Mage.Sets/src/mage/cards/m/MangaraTheDiplomat.java @@ -2,18 +2,15 @@ package mage.cards.m; import mage.MageInt; import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.CastSecondSpellTriggeredAbility; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.keyword.LifelinkAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.SuperType; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; -import mage.watchers.common.CastSpellLastTurnWatcher; import java.util.UUID; @@ -35,10 +32,12 @@ public final class MangaraTheDiplomat extends CardImpl { this.addAbility(LifelinkAbility.getInstance()); // Whenever an opponent attacks with creatures, if two or more of those creatures are attacking you and/or a planeswalker you control, draw a card. - this.addAbility(new MangaraTheDiplomatAttackTriggeredAbility()); + this.addAbility(new MangaraTheDiplomatTriggeredAbility()); // Whenever an opponent casts their second spell each turn, draw a card. - this.addAbility(new MangaraTheDiplomatCastTriggeredAbility()); + this.addAbility(new CastSecondSpellTriggeredAbility( + new DrawCardSourceControllerEffect(1), TargetController.OPPONENT + )); } private MangaraTheDiplomat(final MangaraTheDiplomat card) { @@ -51,13 +50,13 @@ public final class MangaraTheDiplomat extends CardImpl { } } -class MangaraTheDiplomatAttackTriggeredAbility extends TriggeredAbilityImpl { +class MangaraTheDiplomatTriggeredAbility extends TriggeredAbilityImpl { - MangaraTheDiplomatAttackTriggeredAbility() { + MangaraTheDiplomatTriggeredAbility() { super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1)); } - private MangaraTheDiplomatAttackTriggeredAbility(final MangaraTheDiplomatAttackTriggeredAbility ability) { + private MangaraTheDiplomatTriggeredAbility(final MangaraTheDiplomatTriggeredAbility ability) { super(ability); } @@ -81,8 +80,8 @@ class MangaraTheDiplomatAttackTriggeredAbility extends TriggeredAbilityImpl { } @Override - public MangaraTheDiplomatAttackTriggeredAbility copy() { - return new MangaraTheDiplomatAttackTriggeredAbility(this); + public MangaraTheDiplomatTriggeredAbility copy() { + return new MangaraTheDiplomatTriggeredAbility(this); } @Override @@ -92,40 +91,3 @@ class MangaraTheDiplomatAttackTriggeredAbility extends TriggeredAbilityImpl { "and/or planeswalkers you control, draw a card."; } } - - -class MangaraTheDiplomatCastTriggeredAbility extends TriggeredAbilityImpl { - - MangaraTheDiplomatCastTriggeredAbility() { - super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1)); - } - - private MangaraTheDiplomatCastTriggeredAbility(final MangaraTheDiplomatCastTriggeredAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.SPELL_CAST; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Player player = game.getPlayer(getControllerId()); - CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); - return player != null - && watcher != null - && player.hasOpponent(event.getPlayerId(), game) - && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2; - } - - @Override - public MangaraTheDiplomatCastTriggeredAbility copy() { - return new MangaraTheDiplomatCastTriggeredAbility(this); - } - - @Override - public String getRule() { - return "Whenever an opponent casts their second spell each turn, draw a card."; - } -} diff --git a/Mage.Sets/src/mage/cards/m/MonologueTax.java b/Mage.Sets/src/mage/cards/m/MonologueTax.java index 2aece48210..78d14c97e6 100644 --- a/Mage.Sets/src/mage/cards/m/MonologueTax.java +++ b/Mage.Sets/src/mage/cards/m/MonologueTax.java @@ -1,16 +1,12 @@ package mage.cards.m; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.CastSecondSpellTriggeredAbility; import mage.abilities.effects.common.CreateTokenEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; +import mage.constants.TargetController; import mage.game.permanent.token.TreasureToken; -import mage.players.Player; -import mage.watchers.common.CastSpellLastTurnWatcher; import java.util.UUID; @@ -23,7 +19,11 @@ public final class MonologueTax extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); // Whenever an opponent casts their second spell each turn, you create a Treasure token. - this.addAbility(new MonologueTaxTriggeredAbility()); + this.addAbility(new CastSecondSpellTriggeredAbility( + new CreateTokenEffect(new TreasureToken()) + .setText("you create a Treasure token"), + TargetController.OPPONENT + )); } private MonologueTax(final MonologueTax card) { @@ -35,39 +35,3 @@ public final class MonologueTax extends CardImpl { return new MonologueTax(this); } } - -class MonologueTaxTriggeredAbility extends TriggeredAbilityImpl { - - MonologueTaxTriggeredAbility() { - super(Zone.BATTLEFIELD, new CreateTokenEffect(new TreasureToken())); - } - - private MonologueTaxTriggeredAbility(final MonologueTaxTriggeredAbility ability) { - super(ability); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.SPELL_CAST; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Player player = game.getPlayer(getControllerId()); - CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); - return player != null - && watcher != null - && player.hasOpponent(event.getPlayerId(), game) - && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) == 2; - } - - @Override - public MonologueTaxTriggeredAbility copy() { - return new MonologueTaxTriggeredAbility(this); - } - - @Override - public String getRule() { - return "Whenever an opponent casts their second spell each turn, you create a Treasure token."; - } -}