mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Correct handling of unless costs
This commit is contained in:
@@ -108,4 +108,12 @@ public class FThreads {
|
|||||||
input.awaitLatchRelease();
|
input.awaitLatchRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this method.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isEDT() {
|
||||||
|
return SwingUtilities.isEventDispatchThread();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
this.updateObservers();
|
this.updateObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean isEmpty() {
|
||||||
|
return inputStack.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* updateInput.
|
* updateInput.
|
||||||
@@ -118,12 +122,6 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
return this.inputStack.peek();
|
return this.inputStack.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handler.hasPhaseEffects()) {
|
|
||||||
// Handle begin phase stuff, then start back from the top
|
|
||||||
handler.handleBeginPhase();
|
|
||||||
return this.getActualInput(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Phase we're in doesn't allow for Priority, return null to move
|
// If the Phase we're in doesn't allow for Priority, return null to move
|
||||||
// to next phase
|
// to next phase
|
||||||
if (!handler.isPlayerPriorityAllowed()) {
|
if (!handler.isPlayerPriorityAllowed()) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package forge.control.input;
|
package forge.control.input;
|
||||||
|
|
||||||
public interface InputPayment {
|
public interface InputPayment extends InputSynchronized {
|
||||||
boolean isPaid();
|
boolean isPaid();
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,6 @@ import forge.control.input.InputPayDiscardCostWithCommands;
|
|||||||
import forge.control.input.InputPayManaExecuteCommands;
|
import forge.control.input.InputPayManaExecuteCommands;
|
||||||
import forge.control.input.InputPayReturnCost;
|
import forge.control.input.InputPayReturnCost;
|
||||||
import forge.control.input.InputPayment;
|
import forge.control.input.InputPayment;
|
||||||
import forge.control.input.InputSynchronized;
|
|
||||||
import forge.game.event.CardDamagedEvent;
|
import forge.game.event.CardDamagedEvent;
|
||||||
import forge.game.event.LifeLossEvent;
|
import forge.game.event.LifeLossEvent;
|
||||||
import forge.game.player.AIPlayer;
|
import forge.game.player.AIPlayer;
|
||||||
@@ -575,7 +574,7 @@ public final class GameActionUtil {
|
|||||||
//the following costs need inputs and can't be combined at the moment
|
//the following costs need inputs and can't be combined at the moment
|
||||||
|
|
||||||
|
|
||||||
InputSynchronized toSet = null;
|
InputPayment toSet = null;
|
||||||
if (costPart instanceof CostReturn) {
|
if (costPart instanceof CostReturn) {
|
||||||
toSet = new InputPayReturnCost((CostReturn) costPart, ability);
|
toSet = new InputPayReturnCost((CostReturn) costPart, ability);
|
||||||
}
|
}
|
||||||
@@ -589,7 +588,7 @@ public final class GameActionUtil {
|
|||||||
if (toSet != null) {
|
if (toSet != null) {
|
||||||
|
|
||||||
FThreads.setInputAndWait(toSet);
|
FThreads.setInputAndWait(toSet);
|
||||||
if (((InputPayment)toSet).isPaid() ) {
|
if (toSet.isPaid() ) {
|
||||||
paid.execute();
|
paid.execute();
|
||||||
} else {
|
} else {
|
||||||
unpaid.execute();
|
unpaid.execute();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package forge.game.ai;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
|
import forge.Singletons;
|
||||||
import forge.control.input.InputBase;
|
import forge.control.input.InputBase;
|
||||||
import forge.game.GameState;
|
import forge.game.GameState;
|
||||||
import forge.game.phase.CombatUtil;
|
import forge.game.phase.CombatUtil;
|
||||||
@@ -38,6 +39,7 @@ public class AiInputBlock extends InputBase {
|
|||||||
CombatUtil.orderMultipleCombatants(game.getCombat());
|
CombatUtil.orderMultipleCombatants(game.getCombat());
|
||||||
game.getPhaseHandler().setPlayersPriorityPermission(false);
|
game.getPhaseHandler().setPlayersPriorityPermission(false);
|
||||||
|
|
||||||
stop();
|
// was not added to stack, so will be replaced by plain update
|
||||||
|
Singletons.getModel().getMatch().getInput().updateObservers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.Stack;
|
|||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
|
import forge.FThreads;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.trigger.TriggerType;
|
import forge.card.trigger.TriggerType;
|
||||||
import forge.game.GameState;
|
import forge.game.GameState;
|
||||||
@@ -734,7 +735,17 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
|||||||
nextPhase();
|
nextPhase();
|
||||||
return;
|
return;
|
||||||
} else if (!game.getStack().hasSimultaneousStackEntries()) {
|
} else if (!game.getStack().hasSimultaneousStackEntries()) {
|
||||||
|
Runnable proc = new Runnable(){
|
||||||
|
@Override public void run() {
|
||||||
game.getStack().resolveStack();
|
game.getStack().resolveStack();
|
||||||
|
game.getStack().chooseOrderOfSimultaneousStackEntryAll();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if ( FThreads.isEDT() )
|
||||||
|
FThreads.invokeInNewThread(proc, true);
|
||||||
|
else
|
||||||
|
proc.run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// pass the priority to other player
|
// pass the priority to other player
|
||||||
@@ -742,7 +753,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
|||||||
Singletons.getModel().getMatch().getInput().updateObservers();
|
Singletons.getModel().getMatch().getInput().updateObservers();
|
||||||
|
|
||||||
}
|
}
|
||||||
game.getStack().chooseOrderOfSimultaneousStackEntryAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,12 +50,23 @@ public class InputProxy implements Observer {
|
|||||||
@Override
|
@Override
|
||||||
public final synchronized void update(final Observable observable, final Object obj) {
|
public final synchronized void update(final Observable observable, final Object obj) {
|
||||||
ButtonUtil.disableAll();
|
ButtonUtil.disableAll();
|
||||||
GameState game = match.getCurrentGame();
|
final GameState game = match.getCurrentGame();
|
||||||
PhaseHandler ph = game.getPhaseHandler();
|
final PhaseHandler ph = game.getPhaseHandler();
|
||||||
|
|
||||||
|
//System.out.print((FThreads.isEDT() ? "EDT > " : "TRD > ") + ph.debugPrintState());
|
||||||
|
if ( match.getInput().isEmpty() && ph.hasPhaseEffects()) {
|
||||||
|
//System.out.println(" handle begin phase");
|
||||||
|
FThreads.invokeInNewThread(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
ph.handleBeginPhase();
|
||||||
|
update(observable, obj);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Input nextInput = match.getInput().getActualInput(game);
|
final Input nextInput = match.getInput().getActualInput(game);
|
||||||
System.out.print(ph.debugPrintState());
|
//System.out.printf(" input is %s \t stack = %s%n", nextInput == null ? "null" : nextInput.getClass().getSimpleName(), match.getInput().printInputStack());
|
||||||
System.out.printf(" input is %s \t stack = %s%n", nextInput == null ? "null" : nextInput.getClass().getSimpleName(), match.getInput().printInputStack());
|
|
||||||
|
|
||||||
if (nextInput != null) {
|
if (nextInput != null) {
|
||||||
this.input = nextInput;
|
this.input = nextInput;
|
||||||
|
|||||||
Reference in New Issue
Block a user