- Fix ChangeTargets to work better with SpellAbility targets

This commit is contained in:
Sol
2013-04-06 18:58:39 +00:00
parent 669b83044b
commit a7eb64cec9
2 changed files with 46 additions and 43 deletions

View File

@@ -94,8 +94,9 @@ public class TargetSelection {
final boolean choiceResult; final boolean choiceResult;
if (zone.size() == 1 && zone.get(0) == ZoneType.Stack) { if (zone.size() == 1 && zone.get(0) == ZoneType.Stack) {
// If Zone is Stack, the choices are handled slightly differently // If Zone is Stack, the choices are handled slightly differently.
choiceResult = this.chooseCardFromStack(mandatory); // Handle everything inside function due to interaction with StackInstance
return this.chooseCardFromStack(mandatory);
} else { } else {
List<Card> validTargets = this.getValidCardsToTarget(); List<Card> validTargets = this.getValidCardsToTarget();
if (zone.size() == 1 && zone.get(0) == ZoneType.Battlefield) { if (zone.size() == 1 && zone.get(0) == ZoneType.Battlefield) {
@@ -305,15 +306,27 @@ public class TargetSelection {
final GameState game = ability.getActivatingPlayer().getGame(); final GameState game = ability.getActivatingPlayer().getGame();
for (int i = 0; i < game.getStack().size(); i++) { for (int i = 0; i < game.getStack().size(); i++) {
SpellAbility stackItem = game.getStack().peekAbility(i); SpellAbility stackItem = game.getStack().peekAbility(i);
if( ability.canTargetSpellAbility(stackItem)) if (ability.equals(stackItem)) {
// By peeking at stack item, target is set to its SI state. So set it back before adding targets
tgt.resetTargets();
}
else if (ability.canTargetSpellAbility(stackItem)) {
selectOptions.add(stackItem); selectOptions.add(stackItem);
} }
}
if (tgt.isMinTargetsChosen(this.ability.getSourceCard(), this.ability)) { while(!bTargetingDone) {
if (tgt.isMaxTargetsChosen(this.ability.getSourceCard(), this.ability)) {
bTargetingDone = true;
return true;
}
if (!selectOptions.contains("[FINISH TARGETING]") && tgt.isMinTargetsChosen(this.ability.getSourceCard(), this.ability)) {
selectOptions.add("[FINISH TARGETING]"); selectOptions.add("[FINISH TARGETING]");
} }
if (selectOptions.isEmpty()) { if (selectOptions.isEmpty()) {
// Not enough targets, cancel targeting
return false; return false;
} else { } else {
final Object madeChoice = GuiChoose.oneOrNone(message, selectOptions); final Object madeChoice = GuiChoose.oneOrNone(message, selectOptions);
@@ -322,23 +335,10 @@ public class TargetSelection {
} }
if (madeChoice instanceof SpellAbility) { if (madeChoice instanceof SpellAbility) {
tgt.addTarget(madeChoice); tgt.addTarget(madeChoice);
} else // only 'FINISH TARGETING' remains } else // 'FINISH TARGETING' chosen
bTargetingDone = true; bTargetingDone = true;
} }
}
return true; return true;
} }
/**
* <p>
* matchSpellAbility.
* </p>
*
* @param sa
* a {@link forge.card.spellability.SpellAbility} object.
* @param topSA
* a {@link forge.card.spellability.SpellAbility} object.
* @param tgt
* a {@link forge.card.spellability.Target} object.
* @return a boolean.
*/
} }

View File

@@ -625,18 +625,18 @@ public class MagicStack extends MyObservable {
// TODO: change to use forge.view.FView? // TODO: change to use forge.view.FView?
//GuiDisplayUtil.updateGUI(); //GuiDisplayUtil.updateGUI();
this.freezeStack(); // freeze the stack while we're in the middle of // freeze the stack while we're in the middle of resolving
// resolving this.freezeStack();
this.setResolving(true); this.setResolving(true);
final SpellAbility sa = this.pop(); final SpellAbility sa = this.top();
// ActivePlayer gains priority first after Resolve
game.getPhaseHandler().resetPriority();
game.getPhaseHandler().resetPriority(); // ActivePlayer gains priority first
// after Resolve
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
curResolvingCard = source; curResolvingCard = source;
boolean thisHasFizzled = this.hasFizzled(sa, source, false); boolean thisHasFizzled = this.hasFizzled(sa, source, false);
String messageForLog = thisHasFizzled ? source.getName() + " ability fizzles." : sa.getStackDescription(); String messageForLog = thisHasFizzled ? source.getName() + " ability fizzles." : sa.getStackDescription();
game.getGameLog().add("ResolveStack", messageForLog, 2); game.getGameLog().add("ResolveStack", messageForLog, 2);
@@ -756,8 +756,9 @@ public class MagicStack extends MyObservable {
*/ */
public final void finishResolving(final SpellAbility sa, final boolean fizzle) { public final void finishResolving(final SpellAbility sa, final boolean fizzle) {
// remove card from the stack // remove SA and card from the stack
this.removeCardFromStack(sa, fizzle); this.removeCardFromStack(sa, fizzle);
this.remove(sa);
// After SA resolves we have to do a handful of things // After SA resolves we have to do a handful of things
this.setResolving(false); this.setResolving(false);
@@ -876,13 +877,15 @@ public class MagicStack extends MyObservable {
public final SpellAbility pop() { public final SpellAbility pop() {
final SpellAbilityStackInstance si = this.getStack().pop(); final SpellAbilityStackInstance si = this.getStack().pop();
final SpellAbility sp = si.getSpellAbility(); final SpellAbility sp = si.getSpellAbility();
// NOTE (12/04/22): Update Observers here causes multi-targeting bug
// We Update Observers after the Stack Finishes Resolving
// No need to do it sooner
//this.updateObservers();
return sp; return sp;
} }
public final SpellAbility top() {
final SpellAbilityStackInstance si = this.getStack().peek();
final SpellAbility sa = si.getSpellAbility();
return sa;
}
// CAREFUL! Peeking while an SAs Targets are being choosen may cause issues // CAREFUL! Peeking while an SAs Targets are being choosen may cause issues
// index = 0 is the top, index = 1 is the next to top, etc... // index = 0 is the top, index = 1 is the next to top, etc...
/** /**