mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
- Fix ChangeTargets to work better with SpellAbility targets
This commit is contained in:
@@ -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,40 +306,39 @@ 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)) {
|
||||||
selectOptions.add(stackItem);
|
// By peeking at stack item, target is set to its SI state. So set it back before adding targets
|
||||||
}
|
tgt.resetTargets();
|
||||||
|
|
||||||
if (tgt.isMinTargetsChosen(this.ability.getSourceCard(), this.ability)) {
|
|
||||||
selectOptions.add("[FINISH TARGETING]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectOptions.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
final Object madeChoice = GuiChoose.oneOrNone(message, selectOptions);
|
|
||||||
if (madeChoice == null) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (madeChoice instanceof SpellAbility) {
|
else if (ability.canTargetSpellAbility(stackItem)) {
|
||||||
tgt.addTarget(madeChoice);
|
selectOptions.add(stackItem);
|
||||||
} else // only 'FINISH TARGETING' remains
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!bTargetingDone) {
|
||||||
|
if (tgt.isMaxTargetsChosen(this.ability.getSourceCard(), this.ability)) {
|
||||||
bTargetingDone = true;
|
bTargetingDone = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectOptions.contains("[FINISH TARGETING]") && tgt.isMinTargetsChosen(this.ability.getSourceCard(), this.ability)) {
|
||||||
|
selectOptions.add("[FINISH TARGETING]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectOptions.isEmpty()) {
|
||||||
|
// Not enough targets, cancel targeting
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
final Object madeChoice = GuiChoose.oneOrNone(message, selectOptions);
|
||||||
|
if (madeChoice == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (madeChoice instanceof SpellAbility) {
|
||||||
|
tgt.addTarget(madeChoice);
|
||||||
|
} else // 'FINISH TARGETING' chosen
|
||||||
|
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.
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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...
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user