From 4daaaddbb086816909415b9b73cf78b6ae292196 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 10 Sep 2020 17:07:29 -0400 Subject: [PATCH] updated cost adjustment for Pteramander, added test --- Mage.Sets/src/mage/cards/p/Pteramander.java | 53 +++++++------------ .../cards/single/rna/PteramanderTest.java | 41 ++++++++++++++ 2 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/rna/PteramanderTest.java diff --git a/Mage.Sets/src/mage/cards/p/Pteramander.java b/Mage.Sets/src/mage/cards/p/Pteramander.java index 2172b5de82..4c85c1b069 100644 --- a/Mage.Sets/src/mage/cards/p/Pteramander.java +++ b/Mage.Sets/src/mage/cards/p/Pteramander.java @@ -3,17 +3,18 @@ package mage.cards.p; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.CostAdjuster; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount; -import mage.abilities.effects.common.cost.CostModificationEffectImpl; import mage.abilities.effects.keyword.AdaptEffect; +import mage.abilities.hint.Hint; import mage.abilities.hint.ValueHint; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.SubType; import mage.filter.StaticFilters; import mage.game.Game; import mage.players.Player; @@ -26,8 +27,6 @@ import java.util.UUID; */ public final class Pteramander extends CardImpl { - static final DynamicValue cardsCount = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY); - public Pteramander(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{U}"); @@ -40,11 +39,9 @@ public final class Pteramander extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // {7}{U}: Adapt 4. This ability costs {1} less to activate for each instant and sorcery card in your graveyard. - // TODO: Make ability properly copiable Ability ability = new SimpleActivatedAbility(new AdaptEffect(4).setText("Adapt 4. This ability costs {1} less to activate for each instant and sorcery card in your graveyard."), new ManaCostsImpl("{7}{U}")); - this.addAbility(ability); - this.addAbility(new SimpleStaticAbility(Zone.ALL, new PteramanderCostIncreasingEffect(ability.getOriginalId())) - .addHint(new ValueHint("Instant and sorcery cards in your graveyard", cardsCount))); + ability.setCostAdjuster(PteramanderAdjuster.instance); + this.addAbility(ability.addHint(PteramanderAdjuster.getHint())); } private Pteramander(final Pteramander card) { @@ -57,38 +54,24 @@ public final class Pteramander extends CardImpl { } } -class PteramanderCostIncreasingEffect extends CostModificationEffectImpl { +enum PteramanderAdjuster implements CostAdjuster { + instance; - private final UUID originalId; + private static final DynamicValue cardsCount = new CardsInControllerGraveyardCount( + StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY + ); + private static final Hint hint = new ValueHint("Instant and sorcery cards in your graveyard", cardsCount); - PteramanderCostIncreasingEffect(UUID originalId) { - super(Duration.EndOfGame, Outcome.Benefit, CostModificationType.REDUCE_COST); - this.originalId = originalId; - } - - private PteramanderCostIncreasingEffect(final PteramanderCostIncreasingEffect effect) { - super(effect); - this.originalId = effect.originalId; + static Hint getHint() { + return hint; } @Override - public boolean apply(Game game, Ability source, Ability abilityToModify) { - Player controller = game.getPlayer(source.getControllerId()); + public void adjustCosts(Ability ability, Game game) { + Player controller = game.getPlayer(ability.getControllerId()); if (controller != null) { - int count = Pteramander.cardsCount.calculate(game, source, this); - CardUtil.reduceCost(abilityToModify, count); + int count = cardsCount.calculate(game, ability, null); + CardUtil.reduceCost(ability, count); } - return true; } - - @Override - public boolean applies(Ability abilityToModify, Ability source, Game game) { - return abilityToModify.getOriginalId().equals(originalId); - } - - @Override - public PteramanderCostIncreasingEffect copy() { - return new PteramanderCostIncreasingEffect(this); - } - } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/rna/PteramanderTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/rna/PteramanderTest.java new file mode 100644 index 0000000000..62a1f36ccb --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/rna/PteramanderTest.java @@ -0,0 +1,41 @@ +package org.mage.test.cards.single.rna; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author TheElk801 + */ +public class PteramanderTest extends CardTestPlayerBase { + + @Test + public void testNoReduction() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 8); + addCard(Zone.BATTLEFIELD, playerA, "Pteramander"); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{7}"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPowerToughness(playerA, "Pteramander", 5, 5); + } + + @Test + public void testReduction() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 1); + addCard(Zone.BATTLEFIELD, playerA, "Pteramander"); + addCard(Zone.GRAVEYARD, playerA, "Ancestral Recall", 7); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{7}"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPowerToughness(playerA, "Pteramander", 5, 5); + } +}