mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
BugReporter indicates thread in console,
ComputerUtilMana - commented out is debug code PhaseHandler: nextPhase & handleBeginPhase are called consequently, no observer updates happen between calls GuiDisplayUtil: generate mana button caused wrong thread exception VMessage - remove useless import
This commit is contained in:
@@ -79,6 +79,7 @@ public class BugReporter {
|
||||
if (message != null) {
|
||||
System.err.printf("%s > %s%n", FThreads.debugGetCurrThreadId(), message);
|
||||
}
|
||||
System.err.print( FThreads.debugGetCurrThreadId() + " > " );
|
||||
ex.printStackTrace();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -106,6 +106,8 @@ public class ComputerUtilMana {
|
||||
MapOfLists<ManaCostShard, SpellAbility> sourcesForShards = ComputerUtilMana.groupAndOrderToPayShards(ai, manaAbilityMap, cost);
|
||||
|
||||
// Loop over mana needed
|
||||
|
||||
//List<String> paymentPlan = new ArrayList<String>();
|
||||
|
||||
ManaCostShard toPay = null;
|
||||
while (!cost.isPaid()) {
|
||||
@@ -124,6 +126,8 @@ public class ComputerUtilMana {
|
||||
}
|
||||
}
|
||||
|
||||
//paymentPlan.add(String.format("%s : (%s) %s", toPay, saPayment == null ? "LIFE" : saPayment.getSourceCard(), saPayment));
|
||||
|
||||
if( saPayment == null ) {
|
||||
if(!toPay.isPhyrexian() || !ai.canPayLife(2))
|
||||
break; // cannot pay
|
||||
@@ -172,6 +176,8 @@ public class ComputerUtilMana {
|
||||
}
|
||||
|
||||
manapool.clearManaPaid(sa, test);
|
||||
|
||||
//System.err.printf("[%s] payment %s for (%s)+%d %s:%n\t%s%n%n", test ? "test" : "PROD", cost.isPaid() ? "*PAID*" : "failed", sa.getSourceCard(), extraMana, sa.toUnsuppressedString(), StringUtils.join(paymentPlan, "\n\t") );
|
||||
if(!cost.isPaid()) {
|
||||
if( test )
|
||||
return false;
|
||||
|
||||
@@ -74,9 +74,8 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
|
||||
private Player pPlayerPriority = null;
|
||||
private Player pFirstPriority = null;
|
||||
private boolean bPhaseEffects = true;
|
||||
private AtomicBoolean bCombat = new AtomicBoolean(false);
|
||||
private boolean bRepeat = false;
|
||||
private boolean bRepeatCleanup = false;
|
||||
|
||||
/** The need to next phase. */
|
||||
private boolean isPlayerPriorityAllowed = false;
|
||||
@@ -176,29 +175,6 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
this.setPriority(this.playerTurn);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* doPhaseEffects.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean hasPhaseEffects() {
|
||||
return this.bPhaseEffects;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setPhaseEffects.
|
||||
* </p>
|
||||
*
|
||||
* @param b
|
||||
* a boolean.
|
||||
*/
|
||||
private final void setPhaseEffects(final boolean b) {
|
||||
this.bPhaseEffects = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* inCombat.
|
||||
@@ -228,14 +204,104 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
* </p>
|
||||
*/
|
||||
public final void repeatPhase() {
|
||||
this.bRepeat = true;
|
||||
this.bRepeatCleanup = true;
|
||||
}
|
||||
|
||||
public final void handleBeginPhase() {
|
||||
/**
|
||||
* <p>
|
||||
* nextPhase.
|
||||
* </p>
|
||||
*/
|
||||
private final void nextPhase() {
|
||||
this.setPlayersPriorityPermission(true); // PlayerPriorityAllowed = false;
|
||||
|
||||
// If the Stack isn't empty why is nextPhase being called?
|
||||
if (!game.getStack().isEmpty()) {
|
||||
Log.debug("Phase.nextPhase() is called, but Stack isn't empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player p : game.getPlayers()) {
|
||||
int burn = p.getManaPool().clearPool(true);
|
||||
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_MANABURN)) {
|
||||
p.loseLife(burn);
|
||||
|
||||
// Play the Mana Burn sound
|
||||
game.getEvents().post(new ManaBurnEvent());
|
||||
}
|
||||
p.updateObservers();
|
||||
}
|
||||
|
||||
switch (this.phase) {
|
||||
case UNTAP:
|
||||
this.nCombatsThisTurn = 0;
|
||||
break;
|
||||
|
||||
case COMBAT_DECLARE_ATTACKERS:
|
||||
game.getStack().unfreezeStack();
|
||||
this.nCombatsThisTurn++;
|
||||
break;
|
||||
|
||||
case COMBAT_DECLARE_BLOCKERS:
|
||||
game.getStack().unfreezeStack();
|
||||
break;
|
||||
|
||||
case COMBAT_END:
|
||||
//SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
|
||||
game.getCombat().reset(playerTurn);
|
||||
this.getPlayerTurn().resetAttackedThisCombat();
|
||||
this.bCombat.set(false);
|
||||
|
||||
break;
|
||||
|
||||
case CLEANUP:
|
||||
this.bPreventCombatDamageThisTurn = false;
|
||||
if (!this.bRepeatCleanup) {
|
||||
this.setPlayerTurn(this.handleNextTurn());
|
||||
}
|
||||
this.planarDiceRolledthisTurn = 0;
|
||||
// Play the End Turn sound
|
||||
game.getEvents().post(new EndOfTurnEvent());
|
||||
break;
|
||||
default: // no action
|
||||
}
|
||||
|
||||
String phaseType = "";
|
||||
if (this.bRepeatCleanup) { // for when Cleanup needs to repeat itself
|
||||
this.bRepeatCleanup = false;
|
||||
phaseType = "Repeat ";
|
||||
} else {
|
||||
// If the phase that's ending has a stack of additional phases
|
||||
// Take the LIFO one and move to that instead of the normal one
|
||||
if (this.extraPhases.containsKey(phase)) {
|
||||
PhaseType nextPhase = this.extraPhases.get(phase).pop();
|
||||
// If no more additional phases are available, remove it from the map
|
||||
// and let the next add, reput the key
|
||||
if (this.extraPhases.get(phase).isEmpty()) {
|
||||
this.extraPhases.remove(phase);
|
||||
}
|
||||
this.phase = nextPhase;
|
||||
phaseType = "Additional ";
|
||||
} else {
|
||||
this.phase = phase.getNextPhase();
|
||||
}
|
||||
}
|
||||
|
||||
// **** Anything BELOW Here is actually in the next phase. Maybe move
|
||||
// this to handleBeginPhase
|
||||
if (this.phase == PhaseType.UNTAP) {
|
||||
this.turn++;
|
||||
game.getGameLog().add(GameEventType.TURN, "Turn " + this.turn + " (" + this.getPlayerTurn() + ")");
|
||||
}
|
||||
|
||||
game.getGameLog().add(GameEventType.PHASE, phaseType + Lang.getPossesive(this.getPlayerTurn().getName()) + " " + this.getPhase().Name);
|
||||
PhaseUtil.visuallyActivatePhase(this.getPlayerTurn(), this.getPhase());
|
||||
}
|
||||
|
||||
private final void handleBeginPhase() {
|
||||
if (null == playerTurn) {
|
||||
return;
|
||||
}
|
||||
this.setPhaseEffects(false);
|
||||
|
||||
// Handle effects that happen at the beginning of phases
|
||||
game.getAction().checkStateEffects();
|
||||
@@ -245,7 +311,6 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
case UNTAP:
|
||||
//SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
|
||||
game.getPhaseHandler().setPlayersPriorityPermission(false);
|
||||
//updateObservers();
|
||||
PhaseUtil.handleUntap(game);
|
||||
break;
|
||||
|
||||
@@ -399,7 +464,6 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
runParams.put("Phase", this.getPhase().Name);
|
||||
runParams.put("Player", this.getPlayerTurn());
|
||||
game.getTriggerHandler().runTrigger(TriggerType.Phase, runParams, false);
|
||||
|
||||
}
|
||||
|
||||
// This line fixes Combat Damage triggers not going off when they should
|
||||
@@ -421,104 +485,6 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
return this.bPreventCombatDamageThisTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* nextPhase.
|
||||
* </p>
|
||||
*/
|
||||
public final void nextPhase() {
|
||||
|
||||
this.setPlayersPriorityPermission(true); // PlayerPriorityAllowed = false;
|
||||
|
||||
// If the Stack isn't empty why is nextPhase being called?
|
||||
if (!game.getStack().isEmpty()) {
|
||||
Log.debug("Phase.nextPhase() is called, but Stack isn't empty.");
|
||||
return;
|
||||
}
|
||||
setPhaseEffects(true);
|
||||
|
||||
for (Player p : game.getPlayers()) {
|
||||
int burn = p.getManaPool().clearPool(true);
|
||||
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_MANABURN)) {
|
||||
p.loseLife(burn);
|
||||
|
||||
// Play the Mana Burn sound
|
||||
game.getEvents().post(new ManaBurnEvent());
|
||||
}
|
||||
p.updateObservers();
|
||||
}
|
||||
|
||||
switch (this.phase) {
|
||||
case UNTAP:
|
||||
this.nCombatsThisTurn = 0;
|
||||
break;
|
||||
|
||||
case COMBAT_DECLARE_ATTACKERS:
|
||||
game.getStack().unfreezeStack();
|
||||
this.nCombatsThisTurn++;
|
||||
break;
|
||||
|
||||
case COMBAT_DECLARE_BLOCKERS:
|
||||
game.getStack().unfreezeStack();
|
||||
break;
|
||||
|
||||
case COMBAT_END:
|
||||
//SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
|
||||
game.getCombat().reset(playerTurn);
|
||||
this.getPlayerTurn().resetAttackedThisCombat();
|
||||
this.bCombat.set(false);
|
||||
|
||||
break;
|
||||
|
||||
case CLEANUP:
|
||||
this.bPreventCombatDamageThisTurn = false;
|
||||
if (!this.bRepeat) {
|
||||
this.setPlayerTurn(this.handleNextTurn());
|
||||
}
|
||||
this.planarDiceRolledthisTurn = 0;
|
||||
// Play the End Turn sound
|
||||
game.getEvents().post(new EndOfTurnEvent());
|
||||
break;
|
||||
default: // no action
|
||||
}
|
||||
|
||||
String phaseType = "";
|
||||
if (this.bRepeat) { // for when Cleanup needs to repeat itself
|
||||
this.bRepeat = false;
|
||||
phaseType = "Repeat ";
|
||||
} else {
|
||||
// If the phase that's ending has a stack of additional phases
|
||||
// Take the LIFO one and move to that instead of the normal one
|
||||
if (this.extraPhases.containsKey(phase)) {
|
||||
PhaseType nextPhase = this.extraPhases.get(phase).pop();
|
||||
// If no more additional phases are available, remove it from the map
|
||||
// and let the next add, reput the key
|
||||
if (this.extraPhases.get(phase).isEmpty()) {
|
||||
this.extraPhases.remove(phase);
|
||||
}
|
||||
this.phase = nextPhase;
|
||||
phaseType = "Additional ";
|
||||
} else {
|
||||
this.phase = phase.getNextPhase();
|
||||
}
|
||||
}
|
||||
|
||||
// **** Anything BELOW Here is actually in the next phase. Maybe move
|
||||
// this to handleBeginPhase
|
||||
if (this.phase == PhaseType.UNTAP) {
|
||||
this.turn++;
|
||||
game.getGameLog().add(GameEventType.TURN, "Turn " + this.turn + " (" + this.getPlayerTurn() + ")");
|
||||
}
|
||||
|
||||
game.getGameLog().add(GameEventType.PHASE, phaseType + Lang.getPossesive(this.getPlayerTurn().getName()) + " " + this.getPhase().Name);
|
||||
PhaseUtil.visuallyActivatePhase(this.getPlayerTurn(), this.getPhase());
|
||||
|
||||
// When consecutively skipping phases (like in combat) this section
|
||||
// pushes through that block
|
||||
this.updateObservers();
|
||||
// it no longer does.
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* handleNextTurn.
|
||||
@@ -750,7 +716,11 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
// end phase
|
||||
setPlayersPriorityPermission(true);
|
||||
nextPhase();
|
||||
return;
|
||||
// When consecutively skipping phases (like in combat) this section
|
||||
// pushes through that block
|
||||
handleBeginPhase();
|
||||
// it no longer does.
|
||||
updateObservers();
|
||||
} else if (!game.getStack().hasSimultaneousStackEntries()) {
|
||||
game.getStack().resolveStack();
|
||||
game.getStack().chooseOrderOfSimultaneousStackEntryAll();
|
||||
|
||||
@@ -65,7 +65,9 @@ public final class GuiDisplayUtil {
|
||||
Map<String, String> produced = new HashMap<String, String>();
|
||||
produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7");
|
||||
final AbilityManaPart abMana = new AbilityManaPart(dummy, produced);
|
||||
abMana.produceMana(null);
|
||||
getGame().getInputQueue().invokeGameAction(new Runnable() {
|
||||
@Override public void run() { abMana.produceMana(null); }
|
||||
});
|
||||
}
|
||||
|
||||
public static void devSetupGameState() {
|
||||
|
||||
@@ -58,20 +58,13 @@ public class InputProxy implements Observer {
|
||||
FThreads.assertExecutedByEdt(false);
|
||||
|
||||
final PhaseHandler ph = game.getPhaseHandler();
|
||||
|
||||
if(INPUT_DEBUG)
|
||||
System.out.println(FThreads.debugGetStackTraceItem(6, true));
|
||||
|
||||
if ( game.getInputQueue().isEmpty() && ph.hasPhaseEffects()) {
|
||||
if(INPUT_DEBUG)
|
||||
System.out.printf("\t%s > handle begin phase for %s%n", FThreads.debugGetCurrThreadId(), ph.debugPrintState());
|
||||
ph.handleBeginPhase();
|
||||
}
|
||||
|
||||
final Input nextInput = game.getInputQueue().getActualInput();
|
||||
|
||||
if(INPUT_DEBUG)
|
||||
|
||||
if(INPUT_DEBUG) {
|
||||
System.out.print(FThreads.debugGetStackTraceItem(6, true) + " ... ");
|
||||
System.out.printf("\tinput is %s during %s, \tstack = %s%n", nextInput == null ? "null" : nextInput.getClass().getSimpleName(), ph.debugPrintState(), game.getInputQueue().printInputStack());
|
||||
}
|
||||
|
||||
this.input.set(nextInput);
|
||||
Runnable showMessage = new Runnable() {
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.swing.SwingConstants;
|
||||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Constant.Preferences;
|
||||
import forge.Singletons;
|
||||
import forge.gui.framework.DragCell;
|
||||
import forge.gui.framework.DragTab;
|
||||
|
||||
Reference in New Issue
Block a user