diff --git a/src/main/java/forge/control/input/InputQueue.java b/src/main/java/forge/control/input/InputQueue.java index 96a21036da9..ebb7929798b 100644 --- a/src/main/java/forge/control/input/InputQueue.java +++ b/src/main/java/forge/control/input/InputQueue.java @@ -43,14 +43,10 @@ public class InputQueue extends MyObservable implements java.io.Serializable { private static final long serialVersionUID = 3955194449319994301L; private final BlockingDeque inputStack = new LinkedBlockingDeque(); - private final GameState game; - - private final InputLockUI inputLock; - public InputQueue(GameState game0) { - game = game0; + public InputQueue() { inputLock = new InputLockUI(this); } @@ -80,17 +76,6 @@ public class InputQueue extends MyObservable implements java.io.Serializable { return inputStack.isEmpty() ? null : this.inputStack.peek(); } - /** - *
- * clearInput. - *
- */ - public final void clearInput() { - this.inputStack.clear(); - this.updateObservers(); - } - - /** *
* resetInput.
@@ -101,19 +86,11 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
*/
final void removeInput(Input inp) {
FThreads.assertExecutedByEdt(false);
-
Input topMostInput = inputStack.isEmpty() ? null : inputStack.pop();
-
-// StackTraceElement[] trace = Thread.currentThread().getStackTrace();
-// System.out.printf("%s > Remove input %s -- called from %s%n", FThreads.isEDT() ? "EDT" : "TRD", topMostInput, trace[2].toString());
-// if( trace[2].toString().contains("InputBase.stop"))
-// for(StackTraceElement se : trace) {
-// System.out.println(se.toString());
-// }
-
+
if( topMostInput != inp )
throw new RuntimeException("Inputs adding/removal into stack is imbalanced! Check your code again!");
-
+
this.updateObservers();
}
@@ -128,7 +105,7 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
*
* @return a {@link forge.control.input.InputBase} object.
*/
- public final Input getActualInput() {
+ public final Input getActualInput(GameState game) {
GameAge age = game.getAge();
if ( game.isGameOver() )
@@ -142,7 +119,7 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
return inputLock;
final PhaseHandler handler = game.getPhaseHandler();
- final PhaseType phase = handler.getPhase();
+
final Player playerTurn = handler.getPlayerTurn();
final Player priority = handler.getPriorityPlayer();
if (priority == null)
@@ -155,6 +132,7 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
}
// Special Inputs needed for the following phases:
+ final PhaseType phase = handler.getPhase();
final MagicStack stack = game.getStack();
switch (phase) {
case COMBAT_DECLARE_ATTACKERS:
@@ -168,12 +146,8 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
case COMBAT_DECLARE_BLOCKERS:
stack.freezeStack();
- if (game.getCombat().isPlayerAttacked(priority)) {
- return pc.getBlockInput();
- }
-
- // noone attacks you
- return pc.getAutoPassPriorityInput();
+ boolean isAttacked = game.getCombat().isPlayerAttacked(priority);
+ return isAttacked ? pc.getBlockInput() : pc.getAutoPassPriorityInput();
case CLEANUP:
// discard
diff --git a/src/main/java/forge/game/GameAction.java b/src/main/java/forge/game/GameAction.java
index 03c7ef7fb02..e7a9883ac40 100644
--- a/src/main/java/forge/game/GameAction.java
+++ b/src/main/java/forge/game/GameAction.java
@@ -1476,12 +1476,16 @@ public class GameAction {
public void mulligan(final Player firstPlayer) {
performMulligans(firstPlayer, game.getType() == GameType.Commander);
- handleLeylinesAndChancellors();
- // Run Trigger beginning of the game
- final HashMap
diff --git a/src/main/java/forge/game/phase/PhaseType.java b/src/main/java/forge/game/phase/PhaseType.java
index a75cc138b06..d3f3693faea 100644
--- a/src/main/java/forge/game/phase/PhaseType.java
+++ b/src/main/java/forge/game/phase/PhaseType.java
@@ -106,9 +106,9 @@ public enum PhaseType {
* Get the next PhaseType in turn order.
* @return
*/
- public PhaseType getNextPhase() {
- int iNext = ALL_PHASES.indexOf(this) + 1;
- while (iNext >= ALL_PHASES.size()) {
+ public static PhaseType getNext(PhaseType current) {
+ int iNext = ALL_PHASES.indexOf(current) + 1;
+ if (iNext >= ALL_PHASES.size()) {
iNext = 0;
}
return ALL_PHASES.get(iNext);
diff --git a/src/main/java/forge/gui/InputProxy.java b/src/main/java/forge/gui/InputProxy.java
index 702db29bcf7..bd07228e212 100644
--- a/src/main/java/forge/gui/InputProxy.java
+++ b/src/main/java/forge/gui/InputProxy.java
@@ -43,11 +43,10 @@ public class InputProxy implements Observer {
private AtomicReference input = new AtomicReference();
private GameState game = null;
- private static final boolean INPUT_DEBUG = false;
+ private static final boolean DEBUG_INPUT = false;
public void setGame(GameState game0) {
game = game0;
- // game.getStack().addObserver(this);
game.getPhaseHandler().addObserver(this);
game.getInputQueue().addObserver(this);
}
@@ -58,19 +57,15 @@ public class InputProxy implements Observer {
FThreads.assertExecutedByEdt(false);
final PhaseHandler ph = game.getPhaseHandler();
- final Input nextInput = game.getInputQueue().getActualInput();
+ final Input nextInput = game.getInputQueue().getActualInput(game);
-
- if(INPUT_DEBUG) {
- System.out.print(FThreads.debugGetStackTraceItem(6, true) + " ... ");
- System.out.printf("\t%s on %s, \tstack = %s%n", nextInput == null ? "null" : nextInput.getClass().getSimpleName(), ph.debugPrintState(), game.getInputQueue().printInputStack());
- }
+ if(DEBUG_INPUT)
+ System.out.printf("%s ... \t%s on %s, \tstack = %s%n", FThreads.debugGetStackTraceItem(6, true), nextInput == null ? "null" : nextInput.getClass().getSimpleName(), ph.debugPrintState(), game.getInputQueue().printInputStack());
this.input.set(nextInput);
Runnable showMessage = new Runnable() {
@Override public void run() {
- //if(INPUT_DEBUG)
- // System.out.printf("%s > showMessage @ %s/%s during %s%n%n", FThreads.debugGetCurrThreadId(), nextInput.getClass().getSimpleName(), getInput().getClass().getSimpleName(), ph.debugPrintState());
+ // System.out.printf("%s > showMessage @ %s/%s during %s%n%n", FThreads.debugGetCurrThreadId(), nextInput.getClass().getSimpleName(), getInput().getClass().getSimpleName(), ph.debugPrintState());
getInput().showMessage(game.getInputQueue());
}
};
serialVersionUID=5207222278370963197L. */
private static final long serialVersionUID = 5207222278370963197L;
- private PhaseType phase = PhaseType.UNTAP;
- private int turn = 1;
- // Start turn at 1, since first untap is where we start
+ // Start turn at 0, since we start even before first untap
+ private PhaseType phase = null;
+ private int turn = 0;
+
private final transient Stack