Tyvar Kell and gain ability fixes:

* GainAbilityTargetEffect - reworked to support static/dynamic targets, added support of spells (card + related permanent);
* SpellCastControllerTriggeredAbility - now it can setup the target to a card instead a spell;
* Added checks/errors on wrong ability adding code (example: if you add permanent's ability by game state instead permanent's method);
* Tyvar Kell Emblem now use a standard code;
* Test framework: added additional logs for some errors;
This commit is contained in:
Oleg Agafonov 2021-01-12 04:37:13 +04:00
parent f131fd0d12
commit 6dcbcbe962
13 changed files with 291 additions and 140 deletions

View file

@ -0,0 +1,87 @@
package org.mage.test.cards.single.khm;
import mage.abilities.keyword.HasteAbility;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author JayDi85
*/
public class TyvarKellTest extends CardTestPlayerBase {
@Test
public void test_Emblem_Normal() {
removeAllCardsFromHand(playerA);
// 6: You get an emblem with "Whenever you cast an Elf spell, it gains haste until end of turn and you draw two cards."
addCard(Zone.BATTLEFIELD, playerA, "Tyvar Kell");
//
addCard(Zone.HAND, playerA, "Arbor Elf", 1); // {G}
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
// prepare emblem
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tyvar Kell", CounterType.LOYALTY, 10);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "-6:");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkHandCount("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, 1); // 1x elf
// cast elf and draw
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arbor Elf");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkHandCount("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, 2); // 2x from draw
checkAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arbor Elf", HasteAbility.class, true);
// check that it can attack
attack(1, playerA, "Arbor Elf", playerB);
// haste must end on next turn
checkAbility("end", 2, PhaseStep.PRECOMBAT_MAIN, playerA, "Arbor Elf", HasteAbility.class, false);
setStrictChooseMode(true);
setStopAt(2, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertLife(playerB, 20 - 1); // 1x from elf
}
@Test
public void test_Emblem_Blink() {
removeAllCardsFromHand(playerA);
// 6: You get an emblem with "Whenever you cast an Elf spell, it gains haste until end of turn and you draw two cards."
addCard(Zone.BATTLEFIELD, playerA, "Tyvar Kell");
//
addCard(Zone.HAND, playerA, "Arbor Elf", 1); // {G}
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
//
// Exile target creature you control, then return that card to the battlefield under your control.
addCard(Zone.HAND, playerA, "Cloudshift", 1); // {W}
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
// prepare emblem
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tyvar Kell", CounterType.LOYALTY, 10);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "-6:");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkHandCount("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, 2); // 1x elf + 1x shift
// cast elf and draw
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arbor Elf");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkHandCount("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, 3); // 2x from draw + 1x shift
checkAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arbor Elf", HasteAbility.class, true);
// blink elf, so it must lose haste
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cloudshift", "Arbor Elf");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkAbility("blink", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arbor Elf", HasteAbility.class, false);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
}
}

View file

@ -29,8 +29,10 @@ public class HallOfTheBanditLordTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Goblin Roughrider");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
this.assertAbility(playerA, "Goblin Roughrider", HasteAbility.getInstance(), true);
}

View file

@ -1392,7 +1392,12 @@ public class TestPlayer implements Player {
}
private void assertHandCount(PlayerAction action, Game game, Player player, int count) {
Assert.assertEquals(action.getActionName() + " - hand must contain " + count, count, player.getHand().size());
if (player.getHand().size() != count) {
printStart("Hand of " + player.getName());
printCards(player.getHand().getCards(game));
printEnd();
Assert.fail(action.getActionName() + " - hand must contain " + count + ", but found " + player.getHand().size());
}
}
private void assertHandCardCount(PlayerAction action, Game game, Player player, String cardName, int count) {
@ -1416,7 +1421,12 @@ public class TestPlayer implements Player {
}
}
Assert.assertEquals(action.getActionName() + " - command zone must contain " + count + " cards of " + cardName, count, realCount);
if (realCount != count) {
printStart("Cards in command zone from " + player.getName());
printCards(game.getCommanderCardsFromCommandZone(player));
printEnd();
Assert.fail(action.getActionName() + " - must have " + count + " cards with name " + cardName + ", but found " + realCount);
}
}
private void assertColor(PlayerAction action, Game game, Player player, String permanentName, String colors, boolean mustHave) {