mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
Improved target handling of test project. Fixed some incompatible / unclean tests.
This commit is contained in:
parent
89fe41379a
commit
cec37305da
9 changed files with 73 additions and 21 deletions
|
@ -132,7 +132,7 @@ class HuntmasterOfTheFellsAbility extends TriggeredAbilityImpl<HuntmasterOfTheFe
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever this creature enters the battlefield or transforms into Huntmaster of the Fells, put a 2/2 green Wolf creature token onto the battlefield and you gain 2 life.";
|
||||
return "Whenever this creature enters the battlefield or transforms into {this}, put a 2/2 green Wolf creature token onto the battlefield and you gain 2 life.";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ class RavagerOfTheFellsTarget extends TargetPermanent<RavagerOfTheFellsTarget> {
|
|||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
|
||||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
MageObject object = game.getObject(sourceId);
|
||||
|
||||
for (StackObject item: game.getState().getStack()) {
|
||||
|
|
|
@ -55,7 +55,7 @@ public class CloudshiftTest extends CardTestPlayerBase {
|
|||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Clone");
|
||||
setChoice(playerA, "Knight of Meadowgrain");
|
||||
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Clone");
|
||||
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Knight of Meadowgrain"); // clone has name of copied permanent
|
||||
setChoice(playerA, "Heirs of Stromkirk");
|
||||
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
|
|
|
@ -11,6 +11,9 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
|
|||
*/
|
||||
public class SecondGuessTest extends CardTestPlayerBase {
|
||||
|
||||
/**
|
||||
* Counter target spell that's the second spell cast this turn.
|
||||
*/
|
||||
@Test
|
||||
public void testCounterFirstSpell() {
|
||||
addCard(Zone.HAND, playerA, "Lightning Bolt");
|
||||
|
@ -36,11 +39,12 @@ public class SecondGuessTest extends CardTestPlayerBase {
|
|||
addCard(Zone.HAND, playerA, "Shock", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
|
||||
|
||||
addCard(Zone.HAND, playerA, "Second Guess");
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shock", playerB);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Lightning Bolt");
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Shock");
|
||||
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
@ -56,14 +60,14 @@ public class SecondGuessTest extends CardTestPlayerBase {
|
|||
public void testCounterThirdSpell() {
|
||||
addCard(Zone.HAND, playerA, "Lightning Bolt", 2);
|
||||
addCard(Zone.HAND, playerA, "Shock", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
|
||||
addCard(Zone.HAND, playerA, "Second Guess");
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Shock", playerB);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Shock");
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Second Guess", "Shock"); // can't be cast (no valid target), so Secon Guess spell stays on hand
|
||||
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
@ -71,8 +75,8 @@ public class SecondGuessTest extends CardTestPlayerBase {
|
|||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 12);
|
||||
|
||||
assertHandCount(playerA, 0);
|
||||
assertGraveyardCount(playerA, 4);
|
||||
assertHandCount(playerA, 1);
|
||||
assertGraveyardCount(playerA, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -129,14 +129,16 @@ public class PhantasmalImageTest extends CardTestPlayerBase {
|
|||
addCard(Zone.BATTLEFIELD, playerB, "Forest", 2);
|
||||
addCard(Zone.HAND, playerB, "Phantasmal Image");
|
||||
addCard(Zone.HAND, playerB, "Titanic Growth");
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Huntmaster of the Fells");
|
||||
|
||||
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Phantasmal Image");
|
||||
castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Titanic Growth", "Ravager of the Fells-M12");
|
||||
castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Titanic Growth", "Ravager of the Fells");
|
||||
|
||||
setStopAt(2, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertLife(playerB, 18);
|
||||
// check opponent's creature wasn't chosen as a target for Titanic Growth
|
||||
assertPowerToughness(playerA, "Ravager of the Fells", 4, 4);
|
||||
// check playerA's creature was sacrificed
|
||||
|
|
|
@ -30,7 +30,7 @@ public class FaithsShieldTest extends CardTestPlayerBase {
|
|||
execute();
|
||||
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 17);
|
||||
assertLife(playerB, 20);
|
||||
assertPermanentCount(playerA, "White Knight", 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,14 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
|
|||
*/
|
||||
public class IncreasingCardsTest extends CardTestPlayerBase {
|
||||
|
||||
/**
|
||||
* Increasing Ambition
|
||||
* Sorcery, 4B
|
||||
* Search your library for a card and put that card into your hand. If Increasing
|
||||
* Ambition was cast from a graveyard, instead search your library for two cards
|
||||
* and put those cards into your hand. Then shuffle your library.
|
||||
* Flashback {7}{B} (You may cast this card from your graveyard for its flashback cost. Then exile it.)
|
||||
*/
|
||||
@Test
|
||||
public void testIncreasingAmbition() {
|
||||
removeAllCardsFromHand(playerA);
|
||||
|
|
|
@ -63,9 +63,9 @@ import mage.filter.common.FilterCreatureForCombatBlock;
|
|||
@Ignore
|
||||
public class TestPlayer extends ComputerPlayer<TestPlayer> {
|
||||
|
||||
private List<PlayerAction> actions = new ArrayList<PlayerAction>();
|
||||
private List<String> choices = new ArrayList<String>();
|
||||
private List<String> targets = new ArrayList<String>();
|
||||
private final List<PlayerAction> actions = new ArrayList<>();
|
||||
private final List<String> choices = new ArrayList<>();
|
||||
private final List<String> targets = new ArrayList<>();
|
||||
|
||||
public TestPlayer(String name, RangeOfInfluence range) {
|
||||
super(name, range);
|
||||
|
@ -103,10 +103,14 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
|
|||
String[] groups = command.split(";");
|
||||
for (Ability ability: this.getPlayable(game, true)) {
|
||||
if (ability.toString().startsWith(groups[0])) {
|
||||
Ability newAbility = ability.copy();
|
||||
if (groups.length > 1) {
|
||||
addTargets(ability, groups, game);
|
||||
if (!addTargets(newAbility, groups, game)) {
|
||||
// targets could not be set -> try next priority
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.activateAbility((ActivatedAbility)ability, game);
|
||||
this.activateAbility((ActivatedAbility)newAbility, game);
|
||||
actions.remove(action);
|
||||
return true;
|
||||
}
|
||||
|
@ -261,30 +265,38 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void addTargets(Ability ability, String[] groups, Game game) {
|
||||
private boolean addTargets(Ability ability, String[] groups, Game game) {
|
||||
boolean result = true;
|
||||
for (int i = 1; i < groups.length; i++) {
|
||||
String group = groups[i];
|
||||
String target;
|
||||
if (group.startsWith("targetPlayer=")) {
|
||||
int targetsSet = 0;
|
||||
target = group.substring(group.indexOf("targetPlayer=") + 13);
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
if (player.getName().equals(target)) {
|
||||
ability.getTargets().get(0).addTarget(player.getId(), ability, game);
|
||||
targetsSet++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetsSet < 1) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else if (group.startsWith("target=")) {
|
||||
target = group.substring(group.indexOf("target=") + 7);
|
||||
String[] targets = target.split("\\^");
|
||||
String[] targetList = target.split("\\^");
|
||||
int index = 0;
|
||||
for (String t: targets) {
|
||||
if (t.startsWith("targetPlayer=")) {
|
||||
target = t.substring(t.indexOf("targetPlayer=") + 13);
|
||||
int targetsSet = 0;
|
||||
for (String targetName: targetList) {
|
||||
if (targetName.startsWith("targetPlayer=")) {
|
||||
target = targetName.substring(targetName.indexOf("targetPlayer=") + 13);
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
if (player.getName().equals(target)) {
|
||||
ability.getTargets().get(index).addTarget(player.getId(), ability, game);
|
||||
index++;
|
||||
targetsSet++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +306,7 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
|
|||
}
|
||||
for (UUID id: ability.getTargets().get(0).possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
|
||||
MageObject object = game.getObject(id);
|
||||
if (object != null && object.getName().equals(t)) {
|
||||
if (object != null && object.getName().equals(targetName)) {
|
||||
if (index >= ability.getTargets().size()) {
|
||||
index--;
|
||||
}
|
||||
|
@ -307,8 +319,10 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
|
|||
targetAmount.setAmount(ability, game);
|
||||
int amount = targetAmount.getAmountRemaining();
|
||||
targetAmount.addTarget(id, amount,ability, game);
|
||||
targetsSet++;
|
||||
} else {
|
||||
ability.getTargets().get(index).addTarget(id, ability, game);
|
||||
targetsSet++;
|
||||
}
|
||||
index++;
|
||||
break;
|
||||
|
@ -316,8 +330,12 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (targetsSet != targetList.length) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
/**
|
||||
* Default game initialization params for red player (that plays with Mountains)
|
||||
*/
|
||||
@Override
|
||||
public void useRedDefault() {
|
||||
// *** ComputerA ***
|
||||
// battlefield:ComputerA:Mountain:5
|
||||
|
@ -105,6 +106,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
*
|
||||
* @param player {@link Player} to remove all library cards from.
|
||||
*/
|
||||
@Override
|
||||
public void removeAllCardsFromLibrary(TestPlayer player) {
|
||||
getCommands(player).put(Zone.LIBRARY, "clear");
|
||||
}
|
||||
|
@ -126,6 +128,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
*/
|
||||
@Override
|
||||
public void addCard(Zone gameZone, TestPlayer player, String cardName) {
|
||||
addCard(gameZone, player, cardName, 1, false);
|
||||
}
|
||||
|
@ -138,6 +141,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param cardName Card name in string format.
|
||||
* @param count Amount of cards to be added.
|
||||
*/
|
||||
@Override
|
||||
public void addCard(Zone gameZone, TestPlayer player, String cardName, int count) {
|
||||
addCard(gameZone, player, cardName, count, false);
|
||||
}
|
||||
|
@ -152,6 +156,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped.
|
||||
* In case gameZone is other than Battlefield, {@link IllegalArgumentException} is thrown
|
||||
*/
|
||||
@Override
|
||||
public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) {
|
||||
|
||||
if (gameZone.equals(Zone.BATTLEFIELD)) {
|
||||
|
@ -206,13 +211,16 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param player {@link Player} to set life count for.
|
||||
* @param life Life count to set.
|
||||
*/
|
||||
@Override
|
||||
public void setLife(TestPlayer player, int life) {
|
||||
getCommands(player).put(Zone.OUTSIDE, "life:" + String.valueOf(life));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define turn number to stop the game on.
|
||||
* @param turn
|
||||
*/
|
||||
@Override
|
||||
public void setStopOnTurn(int turn) {
|
||||
stopOnTurn = turn == -1 ? null : Integer.valueOf(turn);
|
||||
stopAtStep = PhaseStep.UNTAP;
|
||||
|
@ -220,7 +228,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
|
||||
/**
|
||||
* Define turn number and step to stop the game on.
|
||||
* @param turn
|
||||
* @param step
|
||||
*/
|
||||
@Override
|
||||
public void setStopAt(int turn, PhaseStep step) {
|
||||
stopOnTurn = turn == -1 ? null : Integer.valueOf(turn);
|
||||
stopAtStep = step;
|
||||
|
@ -231,6 +242,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
*
|
||||
* @param turn Expected turn number to compare with. 1-based.
|
||||
*/
|
||||
@Override
|
||||
public void assertTurn(int turn) throws AssertionError {
|
||||
Assert.assertEquals("Turn numbers are not equal", turn, currentGame.getTurnNum());
|
||||
}
|
||||
|
@ -240,6 +252,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
*
|
||||
* @param result Expected {@link GameResult} to compare with.
|
||||
*/
|
||||
@Override
|
||||
public void assertResult(Player player, GameResult result) throws AssertionError {
|
||||
if (player.equals(playerA)) {
|
||||
GameResult actual = CardTestAPI.GameResult.DRAW;
|
||||
|
@ -266,6 +279,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param player {@link Player} to get life for comparison.
|
||||
* @param life Expected player's life to compare with.
|
||||
*/
|
||||
@Override
|
||||
public void assertLife(Player player, int life) throws AssertionError {
|
||||
int actual = currentGame.getPlayer(player.getId()).getLife();
|
||||
Assert.assertEquals("Life amounts are not equal for player " + player.getName(), life, actual);
|
||||
|
@ -288,6 +302,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param scope {@link mage.filter.Filter.ComparisonScope} Use ANY, if you want "at least one creature with given name should have specified p\t"
|
||||
* Use ALL, if you want "all creature with gived name should have specified p\t"
|
||||
*/
|
||||
@Override
|
||||
public void assertPowerToughness(Player player, String cardName, int power, int toughness, Filter.ComparisonScope scope)
|
||||
throws AssertionError {
|
||||
int count = 0;
|
||||
|
@ -339,6 +354,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void assertAbilities(Player player, String cardName, List<Ability> abilities)
|
||||
throws AssertionError {
|
||||
int count = 0;
|
||||
|
@ -401,6 +417,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param player {@link Player} which permanents should be counted.
|
||||
* @param count Expected count.
|
||||
*/
|
||||
@Override
|
||||
public void assertPermanentCount(Player player, int count) throws AssertionError {
|
||||
int actualCount = 0;
|
||||
for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) {
|
||||
|
@ -418,6 +435,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* @param cardName Name of the cards that should be counted.
|
||||
* @param count Expected count.
|
||||
*/
|
||||
@Override
|
||||
public void assertPermanentCount(Player player, String cardName, int count) throws AssertionError {
|
||||
int actualCount = 0;
|
||||
for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) {
|
||||
|
|
|
@ -15,6 +15,7 @@ public class TestActivatedContinuousEffect extends CardTestPlayerBase {
|
|||
@Test
|
||||
public void testCard() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||
// {R}: Target creature gets +1/+0 until end of turn.
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Captive Flame");
|
||||
addCard(Zone.BATTLEFIELD, playerA, "White Knight");
|
||||
|
||||
|
@ -33,6 +34,7 @@ public class TestActivatedContinuousEffect extends CardTestPlayerBase {
|
|||
@Test
|
||||
public void testCard2() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||
// {R}: Target creature gets +1/+0 until end of turn.
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Captive Flame");
|
||||
addCard(Zone.BATTLEFIELD, playerA, "White Knight");
|
||||
|
||||
|
|
Loading…
Reference in a new issue