* Fixed target change handling (e.g. with opponent filter - fixes #574). Added some tests.

This commit is contained in:
LevelX2 2015-05-31 18:44:02 +02:00
parent af1892a6e7
commit 1b690e5c8c
22 changed files with 531 additions and 484 deletions

View file

@ -362,4 +362,40 @@ public class ManifestTest extends CardTestPlayerBase {
assertPermanentCount(playerB, "", 1);
}
/**
* Whisperwood Elemental - Its sacrifice ability doesn't work..
*
*/
@Test
public void testWhisperwoodElemental() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
// Seismic Rupture deals 2 damage to each creature without flying.
addCard(Zone.HAND, playerA, "Seismic Rupture", 1);
// At the beginning of your end step, manifest the top card of your library.
// Sacrifice Whisperwood Elemental: Until end of turn, face-up, nontoken creatures you control gain "When this creature dies, manifest the top card of your library."
addCard(Zone.BATTLEFIELD, playerB, "Whisperwood Elemental", 1);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 2);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Sacrifice");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Seismic Rupture");
setStopAt(1, PhaseStep.END_TURN);
execute();
// no life gain
assertLife(playerA, 20);
assertLife(playerB, 20);
assertGraveyardCount(playerA, "Seismic Rupture", 1);
assertGraveyardCount(playerB, "Whisperwood Elemental", 1);
assertGraveyardCount(playerB, "Silvercoat Lion", 2);
assertPermanentCount(playerB, "", 2);
}
}

View file

@ -31,14 +31,20 @@ public class TargetOpponentGainsControlTest extends CardTestPlayerBase {
@Test
public void testChangeControlEffectFromTwoCards() {
addCard(Zone.HAND, playerA, "Lightning Bolt", 3);
addCard(Zone.HAND, playerA, "Unhallowed Pact", 3);
addCard(Zone.BATTLEFIELD, playerA, "Treacherous Pit-Dweller");
// Enchant creature
// When enchanted creature dies, return that card to the battlefield under your control.
addCard(Zone.HAND, playerA, "Unhallowed Pact", 1); // {2}{B}
// Undying
// When Treacherous Pit-Dweller enters the battlefield from a graveyard, target opponent gains control of it.
addCard(Zone.BATTLEFIELD, playerA, "Treacherous Pit-Dweller"); // 4/3
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Treacherous Pit-Dweller");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Unhallowed Pact", "Treacherous Pit-Dweller");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", "Treacherous Pit-Dweller");
castSpell(1, PhaseStep.UPKEEP, playerA, "Lightning Bolt", "Treacherous Pit-Dweller"); // comes back with undying
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Unhallowed Pact", "Treacherous Pit-Dweller");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", "Treacherous Pit-Dweller"); // Treacherous Pit-Dweller is now 5/4
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", "Treacherous Pit-Dweller");
setStopAt(1, PhaseStep.END_TURN);
@ -46,8 +52,10 @@ public class TargetOpponentGainsControlTest extends CardTestPlayerBase {
// went to graveyard
assertGraveyardCount(playerA, "Unhallowed Pact", 1);
assertGraveyardCount(playerA, "Lightning Bolt", 3);
// returned back
assertPermanentCount(playerA, "Treacherous Pit-Dweller", 1);
assertGraveyardCount(playerA, "Treacherous Pit-Dweller", 0);
assertPermanentCount(playerB, "Treacherous Pit-Dweller", 1); // opponent gets it because ETB of Dweller resolves always last
}
}

View file

@ -68,6 +68,74 @@ public class MisdirectionTest extends CardTestPlayerBase {
assertGraveyardCount(playerA, "Rakshasa's Secret", 1);
assertGraveyardCount(playerB, "Misdirection", 1);
assertHandCount(playerB, "Silvercoat Lion", 0);
}
// check to change target permanent creature legal to to a creature the opponent of the spell controller controls
@Test
public void testChangePublicExecution() {
// Destroy target creature an opponent controls. Each other creature that player controls gets -2/-0 until end of turn.
addCard(Zone.HAND, playerA, "Public Execution");
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 6);
/*
Misdirection {3}{U}{U}
Instant
You may exile a blue card from your hand rather than pay Misdirection's mana cost.
Change the target of target spell with a single target.
*/
addCard(Zone.HAND, playerB, "Misdirection");
addCard(Zone.BATTLEFIELD, playerB, "Pillarfield Ox", 1);
addCard(Zone.BATTLEFIELD, playerB, "Custodian of the Trove", 1); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Island", 5);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Public Execution", "Pillarfield Ox");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Misdirection", "Public Execution", "Public Execution");
addTarget(playerB, "Custodian of the Trove");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerA, "Public Execution", 1);
assertGraveyardCount(playerB, "Misdirection", 1);
assertGraveyardCount(playerB, "Custodian of the Trove",1);
assertPermanentCount(playerB, "Pillarfield Ox", 1);
assertPowerToughness(playerB, "Pillarfield Ox", 0, 4);
}
// check to change target permanent creature not legal to to a creature the your opponent controls
@Test
public void testChangePublicExecution2() {
// Destroy target creature an opponent controls. Each other creature that player controls gets -2/-0 until end of turn.
addCard(Zone.HAND, playerA, "Public Execution");
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 6);
addCard(Zone.BATTLEFIELD, playerA, "Keeper of the Lens", 1);
/*
Misdirection {3}{U}{U}
Instant
You may exile a blue card from your hand rather than pay Misdirection's mana cost.
Change the target of target spell with a single target.
*/
addCard(Zone.HAND, playerB, "Misdirection");
addCard(Zone.BATTLEFIELD, playerB, "Pillarfield Ox", 1);
addCard(Zone.BATTLEFIELD, playerB, "Custodian of the Trove", 1); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Island", 5);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Public Execution", "Custodian of the Trove");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Misdirection", "Public Execution", "Public Execution");
addTarget(playerB, "Keeper of the Lens");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerA, "Public Execution", 1);
assertGraveyardCount(playerB, "Misdirection", 1);
assertPermanentCount(playerA, "Keeper of the Lens", 1);
assertPermanentCount(playerB, "Pillarfield Ox", 1);
assertPowerToughness(playerB, "Pillarfield Ox", 0, 4);
assertGraveyardCount(playerB, "Custodian of the Trove",1);
}
}

View file

@ -65,4 +65,32 @@ public class SpellCastTriggerTest extends CardTestPlayerBase {
assertPowerToughness(playerA, "Sunscorch Regent", 5, 4);
}
}
/**
* Monastery Mentor triggers are causing a "rollback" error.
*/
@Test
public void testMonasteryMentor() {
// Prowess (Whenever you cast a noncreature spell, this creature gets +1/+1 until end of turn.)
// Whenever you cast a noncreature spell, put a 1/1 white Monk creature token with prowess onto the battlefield.
addCard(Zone.BATTLEFIELD, playerA, "Monastery Mentor", 1);
addCard(Zone.HAND, playerA, "Lightning Bolt", 2);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 14);
assertGraveyardCount(playerA, "Lightning Bolt", 2);
assertPermanentCount(playerA, "Monk", 2);
assertPowerToughness(playerA, "Monk", 2, 2);
assertPowerToughness(playerA, "Monk", 1, 1);
assertPowerToughness(playerA, "Monastery Mentor", 4, 4);
}
}

View file

@ -389,6 +389,10 @@ public class TestPlayer extends ComputerPlayer {
@Override
public boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game) {
if (!targets.isEmpty()) {
UUID abilityControllerId = playerId;
if (target.getTargetController() != null && target.getAbilityController() != null) {
abilityControllerId = target.getAbilityController();
}
if ((target instanceof TargetPermanent) || (target instanceof TargetPermanentOrPlayer)) {
for (String targetDefinition: targets) {
String[] targetList = targetDefinition.split("\\^");
@ -408,7 +412,7 @@ public class TestPlayer extends ComputerPlayer {
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents((FilterPermanent)target.getFilter(), game)) {
if (permanent.getName().equals(targetName) || (permanent.getName()+"-"+permanent.getExpansionSetCode()).equals(targetName)) {
if (((TargetPermanent)target).canTarget(source == null ? this.getId(): source.getControllerId(), permanent.getId(), source, game) && !target.getTargets().contains(permanent.getId())) {
if (((TargetPermanent)target).canTarget(abilityControllerId, permanent.getId(), source, game) && !target.getTargets().contains(permanent.getId())) {
if ((permanent.isCopy() && !originOnly) || (!permanent.isCopy() && !copyOnly )) {
target.add(permanent.getId(), game);
targetFound = true;
@ -446,7 +450,7 @@ public class TestPlayer extends ComputerPlayer {
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(this.getId(), card.getId(), source, game) && !target.getTargets().contains(card.getId())) {
if (((TargetCardInHand)target).canTarget(abilityControllerId, card.getId(), source, game) && !target.getTargets().contains(card.getId())) {
target.add(card.getId(), game);
targetFound = true;
break;