use of mage.constants.TurnPhase in project mage by magefree.
the class Turn method playExtraPhases.
private boolean playExtraPhases(Game game, TurnPhase afterPhase) {
while (true) {
TurnMod extraPhaseTurnMod = game.getState().getTurnMods().extraPhase(activePlayerId, afterPhase);
if (extraPhaseTurnMod == null) {
return false;
}
TurnPhase extraPhase = extraPhaseTurnMod.getExtraPhase();
if (extraPhase == null) {
return false;
}
Phase phase;
switch(extraPhase) {
case BEGINNING:
phase = new BeginningPhase();
break;
case PRECOMBAT_MAIN:
phase = new PreCombatMainPhase();
break;
case COMBAT:
phase = new CombatPhase();
break;
case POSTCOMBAT_MAIN:
phase = new PostCombatMainPhase();
break;
default:
phase = new EndPhase();
}
currentPhase = phase;
game.fireEvent(new PhaseChangedEvent(activePlayerId, extraPhaseTurnMod));
Player activePlayer = game.getPlayer(activePlayerId);
if (activePlayer != null && !game.isSimulation()) {
game.informPlayers(activePlayer.getLogName() + " starts an additional " + phase.getType().toString() + " phase");
}
phase.play(game, activePlayerId);
afterPhase = extraPhase;
}
}
use of mage.constants.TurnPhase in project mage by magefree.
the class SourceTappedBeforeUntapStepCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
TurnPhase turnPhase = game.getTurn().getPhase().getType();
Step step = game.getPhase().getStep();
Permanent permanent = game.getBattlefield().getPermanent(permanentId);
if (permanent != null) {
if (lastTurnNum != game.getTurnNum() && turnPhase == TurnPhase.BEGINNING) {
lastTurnNum = game.getTurnNum();
permanentWasTappedBeforeUntapStep = permanent.isTapped();
}
if (step.getType() == PhaseStep.UNTAP) {
return permanentWasTappedBeforeUntapStep;
} else {
return permanent.isTapped();
}
}
return false;
}
use of mage.constants.TurnPhase in project mage by magefree.
the class Turn method resumePlay.
public void resumePlay(Game game, boolean wasPaused) {
activePlayerId = game.getActivePlayerId();
UUID priorityPlayerId = game.getPriorityPlayerId();
TurnPhase phaseType = game.getPhase().getType();
PhaseStep stepType = game.getStep().getType();
Iterator<Phase> it = phases.iterator();
Phase phase;
do {
phase = it.next();
currentPhase = phase;
} while (phase.type != phaseType);
if (phase.resumePlay(game, stepType, wasPaused)) {
// 20091005 - 500.4/703.4n
game.emptyManaPools(null);
// game.saveState();
// 20091005 - 500.8
playExtraPhases(game, phase.getType());
}
while (it.hasNext()) {
phase = it.next();
if (game.isPaused() || game.checkIfGameIsOver()) {
return;
}
currentPhase = phase;
if (!game.getState().getTurnMods().skipPhase(activePlayerId, currentPhase.getType())) {
if (phase.play(game, activePlayerId)) {
// 20091005 - 500.4/703.4n
game.emptyManaPools(null);
// game.saveState();
// 20091005 - 500.8
playExtraPhases(game, phase.getType());
}
}
if (!currentPhase.equals(phase)) {
// phase was changed from the card
game.fireEvent(new PhaseChangedEvent(activePlayerId, null));
break;
}
}
}