From 0608d2cf3d88eaa6d59a524ea17ab85e62fd74e4 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 8 Jan 2019 20:02:22 -0500 Subject: [PATCH] combined "one more more counters added" triggers into a single class --- .../src/mage/cards/b/BenthicBiomancer.java | 46 ++------------- .../mage/cards/g/GrowthChamberGuardian.java | 57 +++---------------- ...neOrMoreCountersAddedTriggeredAbility.java | 53 +++++++++++++++++ 3 files changed, 67 insertions(+), 89 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/common/OneOrMoreCountersAddedTriggeredAbility.java diff --git a/Mage.Sets/src/mage/cards/b/BenthicBiomancer.java b/Mage.Sets/src/mage/cards/b/BenthicBiomancer.java index b38154e0c4..54e0b622c0 100644 --- a/Mage.Sets/src/mage/cards/b/BenthicBiomancer.java +++ b/Mage.Sets/src/mage/cards/b/BenthicBiomancer.java @@ -1,7 +1,8 @@ package mage.cards.b; import mage.MageInt; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.Ability; +import mage.abilities.common.OneOrMoreCountersAddedTriggeredAbility; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.discard.DiscardControllerEffect; import mage.abilities.keyword.AdaptAbility; @@ -9,10 +10,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; -import mage.counters.CounterType; -import mage.game.Game; -import mage.game.events.GameEvent; import java.util.UUID; @@ -34,7 +31,9 @@ public final class BenthicBiomancer extends CardImpl { this.addAbility(new AdaptAbility(1, "{1}{U}")); // Whenever one or more +1/+1 counters are put on Benthic Biomancer, draw a card, then discard a card. - this.addAbility(new GrowthChamberGuardianTriggeredAbility()); + Ability ability = new OneOrMoreCountersAddedTriggeredAbility(new DrawCardSourceControllerEffect(1)); + ability.addEffect(new DiscardControllerEffect(1).setText(", then discard a card")); + this.addAbility(ability); } private BenthicBiomancer(final BenthicBiomancer card) { @@ -46,38 +45,3 @@ public final class BenthicBiomancer extends CardImpl { return new BenthicBiomancer(this); } } - -class GrowthChamberGuardianTriggeredAbility extends TriggeredAbilityImpl { - - GrowthChamberGuardianTriggeredAbility() { - super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), true); - this.addEffect(new DiscardControllerEffect(1)); - } - - private GrowthChamberGuardianTriggeredAbility(final GrowthChamberGuardianTriggeredAbility ability) { - super(ability); - } - - @Override - public GrowthChamberGuardianTriggeredAbility copy() { - return new GrowthChamberGuardianTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.COUNTERS_ADDED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - return event.getData().equals(CounterType.P1P1.getName()) - && event.getAmount() > 0 - && event.getTargetId().equals(this.getSourceId()); - } - - @Override - public String getRule() { - return "Whenever one or more +1/+1 counters are put on {this}, " + - "draw a card, then discard a card."; - } -} diff --git a/Mage.Sets/src/mage/cards/g/GrowthChamberGuardian.java b/Mage.Sets/src/mage/cards/g/GrowthChamberGuardian.java index 8048b31642..07e23ab62a 100644 --- a/Mage.Sets/src/mage/cards/g/GrowthChamberGuardian.java +++ b/Mage.Sets/src/mage/cards/g/GrowthChamberGuardian.java @@ -1,19 +1,15 @@ package mage.cards.g; import mage.MageInt; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.OneOrMoreCountersAddedTriggeredAbility; import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect; import mage.abilities.keyword.AdaptAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; -import mage.counters.CounterType; import mage.filter.FilterCard; import mage.filter.predicate.mageobject.NamePredicate; -import mage.game.Game; -import mage.game.events.GameEvent; import mage.target.common.TargetCardInLibrary; import java.util.UUID; @@ -23,6 +19,13 @@ import java.util.UUID; */ public final class GrowthChamberGuardian extends CardImpl { + private static final FilterCard filter + = new FilterCard("a card named Growth-Chamber Guardian"); + + static { + filter.add(new NamePredicate("Growth-Chamber Guardian")); + } + public GrowthChamberGuardian(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}"); @@ -36,7 +39,7 @@ public final class GrowthChamberGuardian extends CardImpl { this.addAbility(new AdaptAbility(2, "{2}{G}")); // Whenever one or more +1/+1 counters are put on Growth-Chamber Guardian, you may search your library for a card named Growth-Chamber Guardian, reveal it, put it into your hand, then shuffle your library. - this.addAbility(new GrowthChamberGuardianTriggeredAbility()); + this.addAbility(new OneOrMoreCountersAddedTriggeredAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true), true)); } private GrowthChamberGuardian(final GrowthChamberGuardian card) { @@ -48,45 +51,3 @@ public final class GrowthChamberGuardian extends CardImpl { return new GrowthChamberGuardian(this); } } - -class GrowthChamberGuardianTriggeredAbility extends TriggeredAbilityImpl { - - private static final FilterCard filter - = new FilterCard("a card named Growth-Chamber Guardian"); - - static { - filter.add(new NamePredicate("Growth-Chamber Guardian")); - } - - GrowthChamberGuardianTriggeredAbility() { - super(Zone.BATTLEFIELD, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true), true); - } - - private GrowthChamberGuardianTriggeredAbility(final GrowthChamberGuardianTriggeredAbility ability) { - super(ability); - } - - @Override - public GrowthChamberGuardianTriggeredAbility copy() { - return new GrowthChamberGuardianTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.COUNTERS_ADDED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - return event.getData().equals(CounterType.P1P1.getName()) - && event.getAmount() > 0 - && event.getTargetId().equals(this.getSourceId()); - } - - @Override - public String getRule() { - return "Whenever one or more +1/+1 counters are put on {this}, " + - "you may search your library for a card named Growth-Chamber Guardian, " + - "reveal it, put it into your hand, then shuffle your library."; - } -} diff --git a/Mage/src/main/java/mage/abilities/common/OneOrMoreCountersAddedTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/OneOrMoreCountersAddedTriggeredAbility.java new file mode 100644 index 0000000000..6619fcd853 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/common/OneOrMoreCountersAddedTriggeredAbility.java @@ -0,0 +1,53 @@ +package mage.abilities.common; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.GameEvent; + +public class OneOrMoreCountersAddedTriggeredAbility extends TriggeredAbilityImpl { + + private final CounterType counterType; + + public OneOrMoreCountersAddedTriggeredAbility(Effect effect) { + this(effect, false); + } + + public OneOrMoreCountersAddedTriggeredAbility(Effect effect, boolean optional) { + this(effect, optional, CounterType.P1P1); + } + + public OneOrMoreCountersAddedTriggeredAbility(Effect effect, boolean optional, CounterType counterType) { + super(Zone.BATTLEFIELD, effect, true); + this.counterType = counterType; + } + + private OneOrMoreCountersAddedTriggeredAbility(final OneOrMoreCountersAddedTriggeredAbility ability) { + super(ability); + this.counterType = ability.counterType; + } + + @Override + public OneOrMoreCountersAddedTriggeredAbility copy() { + return new OneOrMoreCountersAddedTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.COUNTERS_ADDED; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + return event.getData().equals(counterType.getName()) + && event.getAmount() > 0 + && event.getTargetId().equals(this.getSourceId()); + } + + @Override + public String getRule() { + return "Whenever one or more " + counterType + " counters are put on {this}, " + super.getRule(); + } +}