* Fixed Miracle handling (fixes #447).

This commit is contained in:
LevelX2 2014-10-13 23:41:08 +02:00
parent dce9ea978e
commit 81408b3649
18 changed files with 222 additions and 63 deletions

View file

@ -17,7 +17,9 @@ public class MiracleTest extends CardTestPlayerBase {
public void testMiracleCost() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
// Put all creatures on the bottom of their owners' libraries.
addCard(Zone.LIBRARY, playerA, "Terminus");
// Draw a card.
addCard(Zone.HAND, playerA, "Think Twice");
skipInitShuffling();
@ -55,4 +57,61 @@ public class MiracleTest extends CardTestPlayerBase {
assertPermanentCount(playerB, "Elite Vanguard", 0);
}
/**
* Test that you can cast a card by miracle if you don't put it back to library before casting
*/
@Test
public void testMiracleWillWorkFromHand() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.LIBRARY, playerA, "Plains");
addCard(Zone.LIBRARY, playerA, "Forest");
addCard(Zone.LIBRARY, playerA, "Thunderous Wrath"); // must be the top most card
addCard(Zone.HAND, playerA, "Brainstorm");
skipInitShuffling();
castSpell(1, PhaseStep.UPKEEP, playerA, "Brainstorm");
addTarget(playerA, "Forest");
addTarget(playerA, "Plains");
addTarget(playerA, playerB);
setStopAt(1, PhaseStep.DRAW);
execute();
assertGraveyardCount(playerA, "Brainstorm", 1);
assertHandCount(playerA, "Thunderous Wrath", 0);
assertGraveyardCount(playerA, "Thunderous Wrath", 1);
assertHandCount(playerA, 0);
// check Thunderous Wrath was played
assertLife(playerA, 20);
assertLife(playerB, 15);
}
/**
* Test that you can't cast a card by miracle if you put it back to library before casting
*/
@Test
public void testMiracleWontWorkFromLibrary() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
addCard(Zone.LIBRARY, playerA, "Plains");
addCard(Zone.LIBRARY, playerA, "Forest");
addCard(Zone.LIBRARY, playerA, "Thunderous Wrath");
addCard(Zone.HAND, playerA, "Brainstorm");
skipInitShuffling();
castSpell(1, PhaseStep.UPKEEP, playerA, "Brainstorm");
addTarget(playerA, "Thunderous Wrath");
addTarget(playerA, "Plains");
addTarget(playerA, playerB);
setStopAt(1, PhaseStep.DRAW);
execute();
// check Thunderous Wrath was not played
assertLife(playerA, 20);
assertLife(playerB, 20);
}
}

View file

@ -64,8 +64,10 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.mana.ManaAbility;
import mage.cards.Card;
import mage.constants.Zone;
import mage.target.TargetSource;
import mage.target.common.TargetCardInHand;
/**
*
@ -395,6 +397,29 @@ public class TestPlayer extends ComputerPlayer {
}
}
if (target instanceof TargetCardInHand) {
for (String targetDefinition: targets) {
String[] targetList = targetDefinition.split("\\^");
boolean targetFound = false;
for (String targetName: targetList) {
for (Card card: this.getHand().getCards(((TargetCardInHand)target).getFilter(), game)) {
if (card.getName().equals(targetName) || (card.getName()+"-"+card.getExpansionSetCode()).equals(targetName)) {
if (((TargetCardInHand)target).canTarget(source.getControllerId(), card.getId(), source, game) && !target.getTargets().contains(card.getId())) {
target.add(card.getId(), game);
targetFound = true;
break;
}
}
}
}
if (targetFound) {
targets.remove(targetDefinition);
return true;
}
}
}
}
return super.chooseTarget(outcome, target, source, game);
}