mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Correct handling of unless costs
This commit is contained in:
@@ -107,5 +107,13 @@ public class FThreads {
|
||||
Singletons.getModel().getMatch().getInput().setInput(input);
|
||||
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();
|
||||
}
|
||||
|
||||
public final boolean isEmpty() {
|
||||
return inputStack.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* updateInput.
|
||||
@@ -118,12 +122,6 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
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
|
||||
// to next phase
|
||||
if (!handler.isPlayerPriorityAllowed()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package forge.control.input;
|
||||
|
||||
public interface InputPayment {
|
||||
public interface InputPayment extends InputSynchronized {
|
||||
boolean isPaid();
|
||||
}
|
||||
@@ -61,7 +61,6 @@ import forge.control.input.InputPayDiscardCostWithCommands;
|
||||
import forge.control.input.InputPayManaExecuteCommands;
|
||||
import forge.control.input.InputPayReturnCost;
|
||||
import forge.control.input.InputPayment;
|
||||
import forge.control.input.InputSynchronized;
|
||||
import forge.game.event.CardDamagedEvent;
|
||||
import forge.game.event.LifeLossEvent;
|
||||
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
|
||||
|
||||
|
||||
InputSynchronized toSet = null;
|
||||
InputPayment toSet = null;
|
||||
if (costPart instanceof CostReturn) {
|
||||
toSet = new InputPayReturnCost((CostReturn) costPart, ability);
|
||||
}
|
||||
@@ -589,7 +588,7 @@ public final class GameActionUtil {
|
||||
if (toSet != null) {
|
||||
|
||||
FThreads.setInputAndWait(toSet);
|
||||
if (((InputPayment)toSet).isPaid() ) {
|
||||
if (toSet.isPaid() ) {
|
||||
paid.execute();
|
||||
} else {
|
||||
unpaid.execute();
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.game.ai;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.game.GameState;
|
||||
import forge.game.phase.CombatUtil;
|
||||
@@ -38,6 +39,7 @@ public class AiInputBlock extends InputBase {
|
||||
CombatUtil.orderMultipleCombatants(game.getCombat());
|
||||
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 forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.card.trigger.TriggerType;
|
||||
import forge.game.GameState;
|
||||
@@ -399,7 +400,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
|
||||
// This line fixes Combat Damage triggers not going off when they should
|
||||
game.getStack().unfreezeStack();
|
||||
|
||||
|
||||
// UNTAP
|
||||
if (this.getPhase() != PhaseType.UNTAP) {
|
||||
// during untap
|
||||
@@ -734,7 +735,17 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
nextPhase();
|
||||
return;
|
||||
} else if (!game.getStack().hasSimultaneousStackEntries()) {
|
||||
game.getStack().resolveStack();
|
||||
Runnable proc = new Runnable(){
|
||||
@Override public void run() {
|
||||
game.getStack().resolveStack();
|
||||
game.getStack().chooseOrderOfSimultaneousStackEntryAll();
|
||||
}
|
||||
};
|
||||
|
||||
if ( FThreads.isEDT() )
|
||||
FThreads.invokeInNewThread(proc, true);
|
||||
else
|
||||
proc.run();
|
||||
}
|
||||
} else {
|
||||
// pass the priority to other player
|
||||
@@ -742,7 +753,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
Singletons.getModel().getMatch().getInput().updateObservers();
|
||||
|
||||
}
|
||||
game.getStack().chooseOrderOfSimultaneousStackEntryAll();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,12 +50,23 @@ public class InputProxy implements Observer {
|
||||
@Override
|
||||
public final synchronized void update(final Observable observable, final Object obj) {
|
||||
ButtonUtil.disableAll();
|
||||
GameState game = match.getCurrentGame();
|
||||
PhaseHandler ph = game.getPhaseHandler();
|
||||
final GameState game = match.getCurrentGame();
|
||||
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);
|
||||
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) {
|
||||
this.input = nextInput;
|
||||
|
||||
Reference in New Issue
Block a user