updated cost adjustment for Pteramander, added test

This commit is contained in:
Evan Kranzler 2020-09-10 17:07:29 -04:00
parent c61f8bcd01
commit 4daaaddbb0
2 changed files with 59 additions and 35 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}