Added target handling for modal spells with multiple targets in different modes. Fixed target handling bugs in test project.

This commit is contained in:
LevelX2 2015-05-30 12:43:17 +02:00
parent f8f21bd8ce
commit 907b029bdb
5 changed files with 45 additions and 17 deletions

View file

@ -46,7 +46,6 @@ public class GodsWilling extends CardImpl {
super(ownerId, 16, "Gods Willing", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{W}");
this.expansionSetCode = "THS";
// Target creature you control gains protection from the color of your choice until end of turn. Scry 1.
this.getSpellAbility().addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn));
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());

View file

@ -76,7 +76,9 @@ public class HexproofTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerB, "Island", 4);
addCard(Zone.HAND, playerB, "Into the Void");
// Return up to two target creatures to their owners' hands.
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Into the Void", "Elder of Laurels^Arbor Elf");
// Target creature you control gets +1/+1 and gains hexproof until end of turn. (It can't be the target of spells or abilities your opponents control.)
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerA, "Ranger's Guile", "Elder of Laurels");
setStopAt(2, PhaseStep.END_TURN);

View file

@ -446,7 +446,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(source.getControllerId(), card.getId(), source, game) && !target.getTargets().contains(card.getId())) {
if (((TargetCardInHand)target).canTarget(this.getId(), card.getId(), source, game) && !target.getTargets().contains(card.getId())) {
target.add(card.getId(), game);
targetFound = true;
break;
@ -663,42 +663,61 @@ public class TestPlayer extends ComputerPlayer {
int index = 0;
int targetsSet = 0;
for (String targetName: targetList) {
if (targetName.startsWith("mode=")) {
int modeNr = Integer.parseInt(targetName.substring(5, 6));
if (modeNr == 0 || modeNr > ability.getModes().size()) {
throw new UnsupportedOperationException("Given mode number (" + modeNr + ") not available for " + ability.toString());
}
int modeCounter = 1;
for (Mode mode :ability.getModes().values()) {
if (modeCounter == modeNr) {
ability.getModes().setMode(mode);
index=0; // reset target index if mode changes
break;
}
modeCounter++;
}
targetName = targetName.substring(6);
}
if (ability.getTargets().size() == 0) {
throw new AssertionError("Ability has no targets. " + ability.toString());
}
if (index >= ability.getTargets().size()) {
break; // this can happen if targets should be set but can't be used because of hexproof e.g.
}
Target currentTarget = ability.getTargets().get(index);
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);
currentTarget.addTarget(player.getId(), ability, game);
index++;
targetsSet++;
break;
}
}
} else {
if (ability.getTargets().size() == 0) {
throw new AssertionError("Ability has no targets. " + ability.toString());
}
for (UUID id: ability.getTargets().get(0).possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
for (UUID id: currentTarget.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
MageObject object = game.getObject(id);
if (object != null &&
((!targetName.isEmpty() && object.getName().startsWith(targetName)) || (targetName.isEmpty() && object.getName().isEmpty()))) {
if (index >= ability.getTargets().size()) {
index--;
if (currentTarget.getNumberOfTargets() == 1) {
currentTarget.clearChosen();
}
if (ability.getTargets().get(index).getNumberOfTargets() == 1) {
ability.getTargets().get(index).clearChosen();
}
if (ability.getTargets().get(index) instanceof TargetCreaturePermanentAmount) {
if (currentTarget instanceof TargetCreaturePermanentAmount) {
// supports only to set the complete amount to one target
TargetCreaturePermanentAmount targetAmount = (TargetCreaturePermanentAmount) ability.getTargets().get(index);
TargetCreaturePermanentAmount targetAmount = (TargetCreaturePermanentAmount) currentTarget;
targetAmount.setAmount(ability, game);
int amount = targetAmount.getAmountRemaining();
targetAmount.addTarget(id, amount,ability, game);
targetsSet++;
} else {
ability.getTargets().get(index).addTarget(id, ability, game);
currentTarget.addTarget(id, ability, game);
targetsSet++;
}
index++;
if (currentTarget.getTargets().size() == currentTarget.getMaxNumberOfTargets()) {
index++;
}
break;
}
}

View file

@ -850,6 +850,14 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addAction(turnNum, step, "activate:Cast " + cardName + "$targetPlayer=" + target.getName() + "$manaInPool=" + manaInPool);
}
/**
*
* @param turnNum
* @param step
* @param player
* @param cardName
* @param targetName for modes you can add "mode=3" before target name, multiple targets can be seperated by ^
*/
public void castSpell(int turnNum, PhaseStep step, TestPlayer player, String cardName, String targetName) {
player.addAction(turnNum, step, "activate:Cast " + cardName + "$target=" + targetName);
}

View file

@ -51,7 +51,7 @@ public class GainProtectionFromColorTargetEffect extends GainAbilityTargetEffect
public GainProtectionFromColorTargetEffect(Duration duration) {
super(new ProtectionAbility(new FilterCard()), duration);
choice = new ChoiceColor();
choice = new ChoiceColor(true);
}
public GainProtectionFromColorTargetEffect(final GainProtectionFromColorTargetEffect effect) {