* Elite Scaleguard - Fixed not working triggered ability (fixes #6689).

This commit is contained in:
LevelX2 2020-06-21 09:10:33 +02:00
parent 3f2a5fc362
commit 313829c826
2 changed files with 115 additions and 29 deletions

View file

@ -1,10 +1,11 @@
package mage.cards.e;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksCreatureYouControlTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.TapTargetEffect;
import mage.abilities.effects.keyword.BolsterEffect;
import mage.cards.CardImpl;
@ -14,13 +15,12 @@ import mage.constants.SubType;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.filter.predicate.permanent.CounterPredicate;
import mage.filter.predicate.permanent.DefendingPlayerControlsPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
import mage.target.targetadjustment.TargetAdjuster;
import mage.target.targetpointer.FirstTargetPointer;
/**
* @author emerald000
@ -28,11 +28,9 @@ import java.util.UUID;
public final class EliteScaleguard extends CardImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature you control with a +1/+1 counter on it");
private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature defending player controls");
static {
filter.add(new CounterPredicate(CounterType.P1P1));
filter2.add(DefendingPlayerControlsPredicate.instance);
}
public EliteScaleguard(UUID ownerId, CardSetInfo setInfo) {
@ -46,8 +44,9 @@ public final class EliteScaleguard extends CardImpl {
this.addAbility(new EntersBattlefieldTriggeredAbility(new BolsterEffect(2)));
// Whenever a creature you control with a +1/+1 counter on it attacks, tap target creature defending player controls.
Ability ability = new AttacksCreatureYouControlTriggeredAbility(new EliteScaleguardTapEffect(), false, filter, true);
ability.addTarget(new TargetCreaturePermanent(filter2));
Ability ability = new AttacksCreatureYouControlTriggeredAbility(new TapTargetEffect(), false, filter, true);
ability.addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature defending player controls")));
ability.setTargetAdjuster(EliteScaleguardTargetAdjuster.instance);
this.addAbility(ability);
}
@ -61,28 +60,21 @@ public final class EliteScaleguard extends CardImpl {
}
}
class EliteScaleguardTapEffect extends TapTargetEffect {
EliteScaleguardTapEffect() {
super();
}
EliteScaleguardTapEffect(final EliteScaleguardTapEffect effect) {
super(effect);
}
enum EliteScaleguardTargetAdjuster implements TargetAdjuster {
instance;
@Override
public EliteScaleguardTapEffect copy() {
return new EliteScaleguardTapEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
permanent.tap(game);
return true;
public void adjustTargets(Ability ability, Game game) {
FilterCreaturePermanent filterDefender = new FilterCreaturePermanent("creature defending player controls");
for (Effect effect : ability.getEffects()) {
if (effect instanceof TapTargetEffect) {
filterDefender.add(new ControllerIdPredicate(game.getCombat().getDefendingPlayerId(effect.getTargetPointer().getFirst(game, ability), game)));
effect.setTargetPointer(new FirstTargetPointer());// reset target pointer to first target to tap correct target
break;
}
}
return false;
ability.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filterDefender);
ability.addTarget(target);
}
}

View file

@ -0,0 +1,94 @@
package org.mage.test.cards.abilities.keywords;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class BolsterTest extends CardTestPlayerBase {
/**
* Tests keyword bolster
*
* 701.32. Bolster <br>
* 701.32a "Bolster N" means Choose a creature you control with the least
* toughness or tied for least toughness among creatures you control. Put N
* +1/+1 counters on that creature.
*/
@Test
public void Basic1Test() {
// When Elite Scaleguard enters the battlefield, bolster 2.
// Whenever a creature you control with a +1/+1 counter on it attacks, tap target creature defending player controls.
addCard(Zone.HAND, playerA, "Elite Scaleguard"); // Creature 2/3 {4}{W}
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elite Scaleguard");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertCounterCount("Elite Scaleguard", CounterType.P1P1, 2);
assertPowerToughness(playerA, "Elite Scaleguard", 4, 5);
}
@Test
public void Basic2Test() {
setStrictChooseMode(true);
// When Elite Scaleguard enters the battlefield, bolster 2.
// Whenever a creature you control with a +1/+1 counter on it attacks, tap target creature defending player controls.
addCard(Zone.HAND, playerA, "Elite Scaleguard"); // Creature 2/3 {4}{W}
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elite Scaleguard");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, "Elite Scaleguard", 2, 3);
assertCounterCount("Silvercoat Lion", CounterType.P1P1, 2);
assertPowerToughness(playerA, "Silvercoat Lion", 4, 4);
}
@Test
public void EliteScaleguardTriggerTest() {
// When Elite Scaleguard enters the battlefield, bolster 2.
// Whenever a creature you control with a +1/+1 counter on it attacks, tap target creature defending player controls.
addCard(Zone.HAND, playerA, "Elite Scaleguard"); // Creature 2/3 {4}{W}
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerB, "Pillarfield Ox", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elite Scaleguard");
attack(3, playerA, "Silvercoat Lion");
addTarget(playerA, "Pillarfield Ox"); // Tap from triggered ability of Elite Scaleguard
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, "Elite Scaleguard", 2, 3);
assertCounterCount("Silvercoat Lion", CounterType.P1P1, 2);
assertPowerToughness(playerA, "Silvercoat Lion", 4, 4);
assertTapped("Silvercoat Lion", true);
assertPermanentCount(playerB, "Pillarfield Ox", 1);
assertTapped("Pillarfield Ox", true);
assertLife(playerB, 16);
}
}