Code cleanup

This commit is contained in:
drdev
2013-12-05 02:02:34 +00:00
parent be7f4e5192
commit 5c31890066
4 changed files with 70 additions and 54 deletions

View File

@@ -1453,22 +1453,23 @@ public class GameAction {
Player first = determineFirstTurnPlayer(lastGameOutcome); Player first = determineFirstTurnPlayer(lastGameOutcome);
do { do {
if (game.isGameOver()) break; // conceded during "play or draw" if (game.isGameOver()) { break; } // conceded during "play or draw"
// FControl should determine now if there are any human players. // FControl should determine now if there are any human players.
// Where there are none, it should bring up speed controls // Where there are none, it should bring up speed controls
game.fireEvent(new GameEventGameStarted(game.getType(), first, game.getPlayers())); game.fireEvent(new GameEventGameStarted(game.getType(), first, game.getPlayers()));
game.setAge(GameStage.Mulligan); game.setAge(GameStage.Mulligan);
for (final Player p1 : game.getPlayers()) for (final Player p1 : game.getPlayers()) {
p1.drawCards(p1.getMaxHandSize()); p1.drawCards(p1.getMaxHandSize());
}
performMulligans(first, game.getType() == GameType.Commander); performMulligans(first, game.getType() == GameType.Commander);
if (game.isGameOver()) break; // conceded during "mulligan" prompt if (game.isGameOver()) { break; } // conceded during "mulligan" prompt
game.setAge(GameStage.Play); game.setAge(GameStage.Play);
// THIS CODE WILL WORK WITH PHASE = NULL { //<THIS CODE WILL WORK WITH PHASE = NULL>
if (game.getType() == GameType.Planechase) { if (game.getType() == GameType.Planechase) {
first.initPlane(); first.initPlane();
} }
@@ -1479,7 +1480,7 @@ public class GameAction {
// Run Trigger beginning of the game // Run Trigger beginning of the game
final HashMap<String, Object> runParams = new HashMap<String, Object>(); final HashMap<String, Object> runParams = new HashMap<String, Object>();
game.getTriggerHandler().runTrigger(TriggerType.NewGame, runParams, false); game.getTriggerHandler().runTrigger(TriggerType.NewGame, runParams, false);
// } //</THIS CODE WILL WORK WITH PHASE = NULL>
game.getPhaseHandler().startFirstTurn(first); game.getPhaseHandler().startFirstTurn(first);

View File

@@ -197,7 +197,8 @@ public class PhaseHandler implements java.io.Serializable {
if (this.bRepeatCleanup) { // for when Cleanup needs to repeat itself if (this.bRepeatCleanup) { // for when Cleanup needs to repeat itself
this.bRepeatCleanup = false; this.bRepeatCleanup = false;
} else { }
else {
// If the phase that's ending has a stack of additional phases // 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 // Take the LIFO one and move to that instead of the normal one
if (this.extraPhases.containsKey(phase)) { if (this.extraPhases.containsKey(phase)) {
@@ -208,7 +209,8 @@ public class PhaseHandler implements java.io.Serializable {
this.extraPhases.remove(phase); this.extraPhases.remove(phase);
} }
this.phase = nextPhase; this.phase = nextPhase;
} else { }
else {
this.phase = PhaseType.getNext(phase); this.phase = PhaseType.getNext(phase);
} }
} }
@@ -272,9 +274,11 @@ public class PhaseHandler implements java.io.Serializable {
if (isSkippingPhase(phase)) { if (isSkippingPhase(phase)) {
skipped = true; skipped = true;
givePriorityToPlayer = false; givePriorityToPlayer = false;
if( phase == PhaseType.COMBAT_DECLARE_ATTACKERS ) if (phase == PhaseType.COMBAT_DECLARE_ATTACKERS) {
playerTurn.removeKeyword("Skip your next combat phase."); playerTurn.removeKeyword("Skip your next combat phase.");
} else { }
}
else {
// Perform turn-based actions // Perform turn-based actions
switch(this.getPhase()) { switch(this.getPhase()) {
case UNTAP: case UNTAP:
@@ -309,8 +313,9 @@ public class PhaseHandler implements java.io.Serializable {
declareAttackersTurnBasedAction(); declareAttackersTurnBasedAction();
game.getStack().unfreezeStack(); game.getStack().unfreezeStack();
if (combat != null && combat.getAttackers().isEmpty() ) if (combat != null && combat.getAttackers().isEmpty()) {
combat = null; combat = null;
}
givePriorityToPlayer = inCombat(); givePriorityToPlayer = inCombat();
break; break;
@@ -328,7 +333,8 @@ public class PhaseHandler implements java.io.Serializable {
// no first strikers, skip this step // no first strikers, skip this step
if (!combat.assignCombatDamage(true)) { if (!combat.assignCombatDamage(true)) {
this.givePriorityToPlayer = false; this.givePriorityToPlayer = false;
} else { }
else {
combat.dealAssignedDamage(); combat.dealAssignedDamage();
} }
break; break;
@@ -338,7 +344,8 @@ public class PhaseHandler implements java.io.Serializable {
if (!combat.assignCombatDamage(false)) { if (!combat.assignCombatDamage(false)) {
this.givePriorityToPlayer = false; this.givePriorityToPlayer = false;
} else { }
else {
combat.dealAssignedDamage(); combat.dealAssignedDamage();
} }
break; break;
@@ -433,9 +440,10 @@ public class PhaseHandler implements java.io.Serializable {
p.loseLife(burn); p.loseLife(burn);
} }
// Play the Mana Burn sound // Play the Mana Burn sound
if ( burn > 0 ) if (burn > 0) {
game.fireEvent(new GameEventManaBurn(burn, dealDamage)); game.fireEvent(new GameEventManaBurn(burn, dealDamage));
} }
}
switch (this.phase) { switch (this.phase) {
case UNTAP: case UNTAP:
@@ -460,8 +468,9 @@ public class PhaseHandler implements java.io.Serializable {
combat = null; combat = null;
this.getPlayerTurn().resetAttackedThisCombat(); this.getPlayerTurn().resetAttackedThisCombat();
if ( eventEndCombat != null ) if (eventEndCombat != null) {
game.fireEvent(eventEndCombat); game.fireEvent(eventEndCombat);
}
break; break;
case CLEANUP: case CLEANUP:
@@ -632,8 +641,9 @@ public class PhaseHandler implements java.io.Serializable {
} }
for (final Card c1 : combat.getAllBlockers()) { for (final Card c1 : combat.getAllBlockers()) {
if ( c1.getDamageHistory().getCreatureBlockedThisCombat() ) if (c1.getDamageHistory().getCreatureBlockedThisCombat()) {
continue; continue;
}
if (!c1.getDamageHistory().getCreatureBlockedThisCombat()) { if (!c1.getDamageHistory().getCreatureBlockedThisCombat()) {
for (final SpellAbility ab : CardFactoryUtil.getBushidoEffects(c1)) { for (final SpellAbility ab : CardFactoryUtil.getBushidoEffects(c1)) {
@@ -656,8 +666,9 @@ public class PhaseHandler implements java.io.Serializable {
} }
List<Card> blockers = combat.getBlockers(a); List<Card> blockers = combat.getBlockers(a);
if ( blockers.isEmpty() ) if (blockers.isEmpty()) {
continue; continue;
}
// Run triggers // Run triggers
final HashMap<String, Object> runParams = new HashMap<String, Object>(); final HashMap<String, Object> runParams = new HashMap<String, Object>();
@@ -748,8 +759,7 @@ public class PhaseHandler implements java.io.Serializable {
Player next = getNextActivePlayer(); Player next = getNextActivePlayer();
if (game.getType() == GameType.Planechase) { if (game.getType() == GameType.Planechase) {
for(Card p :game.getActivePlanes()) for (Card p :game.getActivePlanes()) {
{
if (p != null) { if (p != null) {
p.setController(next, 0); p.setController(next, 0);
game.getAction().controllerChangeZoneCorrection(p); game.getAction().controllerChangeZoneCorrection(p);
@@ -947,8 +957,9 @@ public class PhaseHandler implements java.io.Serializable {
FThreads.assertExecutedByEdt(false); FThreads.assertExecutedByEdt(false);
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
if(phase != null) if (phase != null) {
throw new IllegalStateException("Turns already started, call this only once per game"); throw new IllegalStateException("Turns already started, call this only once per game");
}
setPlayerTurn(goesFirst); setPlayerTurn(goesFirst);
advanceToNextPhase(); advanceToNextPhase();
@@ -958,22 +969,22 @@ public class PhaseHandler implements java.io.Serializable {
givePriorityToPlayer = false; givePriorityToPlayer = false;
while (!game.isGameOver()) { // loop only while is playing while (!game.isGameOver()) { // loop only while is playing
if (DEBUG_PHASES) { if (DEBUG_PHASES) {
System.out.println("\t\tStack: " + game.getStack()); System.out.println("\t\tStack: " + game.getStack());
System.out.print(FThreads.prependThreadId(debugPrintState(givePriorityToPlayer))); System.out.print(FThreads.prependThreadId(debugPrintState(givePriorityToPlayer)));
} }
if (givePriorityToPlayer) { if (givePriorityToPlayer) {
if( DEBUG_PHASES ) if (DEBUG_PHASES) {
sw.start(); sw.start();
}
// Rule 704.3 Whenever a player would get priority, the game checks ... for state-based actions, // Rule 704.3 Whenever a player would get priority, the game checks ... for state-based actions,
game.getAction().checkStateEffects(); game.getAction().checkStateEffects();
game.fireEvent(new GameEventPlayerPriority(getPlayerTurn(), getPhase(), getPriorityPlayer())); game.fireEvent(new GameEventPlayerPriority(getPlayerTurn(), getPhase(), getPriorityPlayer()));
// SBA could lead to game over // SBA could lead to game over
if ( game.isGameOver() ) return; if (game.isGameOver()) { return; }
pPlayerPriority.getController().takePriority(); pPlayerPriority.getController().takePriority();
@@ -983,7 +994,8 @@ public class PhaseHandler implements java.io.Serializable {
System.out.println("\t\tStack: " + game.getStack()); System.out.println("\t\tStack: " + game.getStack());
sw.reset(); sw.reset();
} }
} else if( DEBUG_PHASES ){ }
else if (DEBUG_PHASES){
System.out.print(" >>\n"); System.out.print(" >>\n");
} }
@@ -992,7 +1004,7 @@ public class PhaseHandler implements java.io.Serializable {
// of Priority // of Priority
Player nextPlayer = game.getNextPlayerAfter(this.getPriorityPlayer()); Player nextPlayer = game.getNextPlayerAfter(this.getPriorityPlayer());
if ( game.isGameOver() || nextPlayer == null ) return; // conceded? if (game.isGameOver() || nextPlayer == null) { return; } // conceded?
// System.out.println(String.format("%s %s: %s passes priority to %s", playerTurn, phase, actingPlayer, nextPlayer)); // System.out.println(String.format("%s %s: %s passes priority to %s", playerTurn, phase, actingPlayer, nextPlayer));
if (getFirstPriority() == nextPlayer) { if (getFirstPriority() == nextPlayer) {
@@ -1004,11 +1016,13 @@ public class PhaseHandler implements java.io.Serializable {
onPhaseEnd(); onPhaseEnd();
advanceToNextPhase(); advanceToNextPhase();
onPhaseBegin(); onPhaseBegin();
} else if (!game.getStack().hasSimultaneousStackEntries()) { }
else if (!game.getStack().hasSimultaneousStackEntries()) {
game.getStack().resolveStack(); game.getStack().resolveStack();
game.getStack().chooseOrderOfSimultaneousStackEntryAll(); game.getStack().chooseOrderOfSimultaneousStackEntryAll();
} }
} else { }
else {
// pass the priority to other player // pass the priority to other player
this.pPlayerPriority = nextPlayer; this.pPlayerPriority = nextPlayer;
} }
@@ -1026,8 +1040,9 @@ public class PhaseHandler implements java.io.Serializable {
// as it avoids calling any of the phase effects that may be necessary in a less enforced context // as it avoids calling any of the phase effects that may be necessary in a less enforced context
public final void devModeSet(final PhaseType phase0, final Player player0) { public final void devModeSet(final PhaseType phase0, final Player player0) {
if (null != phase0) this.phase = phase0; if (null != phase0) this.phase = phase0;
if (null != player0 ) if (null != player0) {
setPlayerTurn(player0); setPlayerTurn(player0);
}
game.fireEvent(new GameEventTurnPhase(this.getPlayerTurn(), this.getPhase(), "")); game.fireEvent(new GameEventTurnPhase(this.getPlayerTurn(), this.getPhase(), ""));
combat = null; // not-null can be created only when declare attackers phase begins combat = null; // not-null can be created only when declare attackers phase begins