Search in sources :

Example 1 with TurnPhase

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;
    }
}
Also used : Player(mage.players.Player) TurnPhase(mage.constants.TurnPhase) PhaseChangedEvent(mage.game.events.PhaseChangedEvent) TurnPhase(mage.constants.TurnPhase)

Example 2 with TurnPhase

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;
}
Also used : Permanent(mage.game.permanent.Permanent) Step(mage.game.turn.Step) PhaseStep(mage.constants.PhaseStep) TurnPhase(mage.constants.TurnPhase)

Example 3 with TurnPhase

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;
        }
    }
}
Also used : TurnPhase(mage.constants.TurnPhase) PhaseChangedEvent(mage.game.events.PhaseChangedEvent) PhaseStep(mage.constants.PhaseStep) UUID(java.util.UUID) TurnPhase(mage.constants.TurnPhase)

Aggregations

TurnPhase (mage.constants.TurnPhase)3 PhaseStep (mage.constants.PhaseStep)2 PhaseChangedEvent (mage.game.events.PhaseChangedEvent)2 UUID (java.util.UUID)1 Permanent (mage.game.permanent.Permanent)1 Step (mage.game.turn.Step)1 Player (mage.players.Player)1