* Fixed a bug that number of targets for spells with multiple modal selection (e. g. Cryptic Command) was not calulated correctly.

This commit is contained in:
LevelX2 2015-04-29 23:46:39 +02:00
parent d39dad518d
commit 0cb6c7ee26
3 changed files with 68 additions and 4 deletions

View file

@ -80,5 +80,44 @@ public class CrypticCommandTest extends CardTestPlayerBase {
assertHandCount(playerB, 0); // Because Cryptic Command has no legal target playerB does not draw a card and has 0 cards in hand
}
/**
* Game is not letting me play Ricochet Trap targetting oponent's Cryptic Command,
* modes 1 and 4. It only has one target and should be allowed
*/
@Test
public void testCommandChangeTarget() {
addCard(Zone.HAND, playerA, "Thoughtseize");
// Counter target spell. If that spell is countered this way, put it into its owner's hand instead of into that player's graveyard.
// Draw a card.
addCard(Zone.HAND, playerA, "Ricochet Trap");
addCard(Zone.HAND, playerA, "Lightning Bolt");
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
addCard(Zone.HAND, playerB, "Cryptic Command");
addCard(Zone.BATTLEFIELD, playerB, "Island", 4);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Thoughtseize", playerB);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cryptic Command", "Thoughtseize");
setModeChoice(playerB, "1"); // Counter target spell
setModeChoice(playerB, "4"); // Draw a card
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ricochet Trap", "Cryptic Command");
addTarget(playerA, "Lightning Bolt");
setStopAt(1, PhaseStep.CLEANUP);
execute();
assertLife(playerA, 18); // -2 from Thoughtseize
assertLife(playerB, 20);
assertGraveyardCount(playerA, "Ricochet Trap", 1);
assertGraveyardCount(playerA, "Thoughtseize", 1);
assertGraveyardCount(playerB, "Cryptic Command", 1);
assertGraveyardCount(playerA, "Lightning Bolt", 1);
assertHandCount(playerB, 1); // card drawn from Cryptic Command
}
}

View file

@ -68,6 +68,7 @@ import mage.abilities.mana.ManaOptions;
import mage.cards.Card;
import mage.constants.Zone;
import mage.target.TargetSource;
import mage.target.TargetSpell;
import mage.target.common.TargetCardInHand;
import mage.target.common.TargetPermanentOrPlayer;
@ -445,6 +446,26 @@ public class TestPlayer extends ComputerPlayer {
}
}
if (target instanceof TargetSpell) {
for (String targetDefinition: targets) {
String[] targetList = targetDefinition.split("\\^");
boolean targetFound = false;
for (String targetName: targetList) {
for(StackObject stackObject: game.getStack()) {
if (stackObject.getName().equals(targetName)) {
target.add(stackObject.getId(), game);
targetFound = true;
break;
}
}
}
if (targetFound) {
targets.remove(targetDefinition);
return true;
}
}
}
}
return super.chooseTarget(outcome, target, source, game);

View file

@ -27,7 +27,9 @@
*/
package mage.filter.predicate.mageobject;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Mode;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.stack.Spell;
@ -50,10 +52,12 @@ public class NumberOfTargetsPredicate implements Predicate<MageObject> {
public boolean apply(MageObject input, Game game) {
Spell spell = game.getStack().getSpell(input.getId());
if (spell != null) {
Targets spellTargets = spell.getSpellAbility().getTargets();
int numberOfTargets = 0;
for (Target target : spellTargets) {
numberOfTargets += target.getTargets().size();
for (UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) {
Mode mode = spell.getSpellAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) {
numberOfTargets += target.getTargets().size();
}
}
if (numberOfTargets == targets) {
return true;