Redirect added. M13 is complete. 2 unimplemented cards in T2 remaining.

This commit is contained in:
Maxmtg
2013-06-21 12:41:21 +00:00
parent 10c41c9dfa
commit b92eaa14a5
8 changed files with 26 additions and 15 deletions

View File

@@ -8,7 +8,6 @@ import org.apache.commons.lang3.tuple.Pair;
import com.google.common.collect.Iterables;
import forge.Card;
import forge.ITargetable;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;
@@ -38,13 +37,18 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
// If there isn't a Stack Instance, there isn't really a target
continue;
}
boolean preserveNumber = sa.hasParam("PreserveNumber"); // Redirect is not supposed to change number of targets
boolean changesOneTarget = sa.hasParam("ChangeSingleTarget"); // The only card known to replace targets with self is Spellskite
// There is also Muck Drubb but it replaces ALL occurences of a single target with itself (unlike Spellskite that has to be activated for each).
SpellAbilityStackInstance changingTgtSI = si;
Player chooser = sa.getActivatingPlayer();
// Redirect rules read 'you MAY choose new targets' ... okay!
boolean isOptional = sa.hasParam("Optional");
if( isOptional && !chooser.getController().confirmAction(sa, null, "Do you want to change targets of " + tgtSA.getSourceCard() + "?"))
continue;
if( changesOneTarget ) {
// 1. choose a target of target spell
List<Pair<SpellAbilityStackInstance, ITargetable>> allTargets = new ArrayList<>();
@@ -57,6 +61,7 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
changingTgtSI = changingTgtSI.getSubInstace();
}
if( allTargets.isEmpty() ) {
// is it an error or not?
System.err.println("Player managed to target a spell without targets with Spellskite's ability.");
return;
}
@@ -81,7 +86,7 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
// Update targets, with a potential new target
SpellAbility changingTgtSA = changingTgtSI.getSpellAbility();
TargetChoices newTarget = sa.getActivatingPlayer().getController().chooseNewTargetsFor(changingTgtSA);
if ( null != newTarget)
if (null != newTarget)
changingTgtSI.updateTarget(newTarget);
changingTgtSI = changingTgtSI.getSubInstace();
}

View File

@@ -28,7 +28,6 @@ import forge.CardColor;
import forge.CardUtil;
import forge.Command;
import forge.CounterType;
import forge.ITargetable;
import forge.ImageCache;
import forge.card.CardCharacteristics;
import forge.card.CardDb;

View File

@@ -109,7 +109,7 @@ public class HumanPlaySpellAbility {
if( tgt != null && tgt.doesTarget()) {
clearTargets(beingTargeted);
final TargetSelection select = new TargetSelection(beingTargeted);
if (!select.chooseTargets() ) {
if (!select.chooseTargets(null) ) {
return false;
}
}

View File

@@ -65,14 +65,15 @@ public class TargetSelection {
* </p>
*/
public final boolean chooseTargets() {
public final boolean chooseTargets(Integer numTargets) {
TargetRestrictions tgt = getTgt();
final boolean canTarget = tgt != null && tgt.doesTarget();
if( !canTarget )
throw new RuntimeException("TargetSelection.chooseTargets called for ability that does not target - " + ability);
final int minTargets = tgt.getMinTargets(ability.getSourceCard(), ability);
final int maxTargets = tgt.getMaxTargets(ability.getSourceCard(), ability);
// Number of targets is explicitly set only if spell is being redirected (ex. Swerve or Redirect)
final int minTargets = numTargets != null ? numTargets.intValue() : tgt.getMinTargets(ability.getSourceCard(), ability);
final int maxTargets = numTargets != null ? numTargets.intValue() : tgt.getMaxTargets(ability.getSourceCard(), ability);
final int numTargeted = ability.getTargets().getNumTargeted();
boolean hasEnoughTargets = minTargets == 0 || numTargeted >= minTargets;
@@ -81,7 +82,6 @@ public class TargetSelection {
// if not enough targets chosen, cancel Ability
if (this.bTargetingDone && !hasEnoughTargets)
return false;
if (this.bTargetingDone && hasEnoughTargets || hasAllTargets || tgt.isDividedAsYouChoose() && tgt.getStillToDivide() == 0) {
return true;
@@ -118,7 +118,7 @@ public class TargetSelection {
}
}
// some inputs choose cards one-by-one and need to be called again
return choiceResult && chooseTargets();
return choiceResult && chooseTargets(numTargets);
}

View File

@@ -454,7 +454,7 @@ public class PlayerControllerHuman extends PlayerController {
TargetChoices oldTarget = ability.getTargets();
TargetSelection select = new TargetSelection(ability);
ability.resetTargets();
if (select.chooseTargets()) {
if (select.chooseTargets(oldTarget.getNumTargeted())) {
return ability.getTargets();
} else {
// Return old target, since we had to reset them above