Search in sources :

Example 1 with PhaseChangedEvent

use of mage.game.events.PhaseChangedEvent in project mage by magefree.

the class Turn method play.

/**
 * @param game
 * @param activePlayer
 * @return true if turn is skipped
 */
public boolean play(Game game, Player activePlayer) {
    // uncomment this to trace triggered abilities and/or continous effects
    // TraceUtil.traceTriggeredAbilities(game);
    // game.getState().getContinuousEffects().traceContinuousEffects(game);
    activePlayer.becomesActivePlayer();
    this.setDeclareAttackersStepStarted(false);
    if (game.isPaused() || game.checkIfGameIsOver()) {
        return false;
    }
    if (game.getState().getTurnMods().skipTurn(activePlayer.getId())) {
        game.informPlayers(activePlayer.getLogName() + " skips their turn.");
        return true;
    }
    logStartOfTurn(game, activePlayer);
    checkTurnIsControlledByOtherPlayer(game, activePlayer.getId());
    this.activePlayerId = activePlayer.getId();
    resetCounts();
    game.getPlayer(activePlayer.getId()).beginTurn(game);
    for (Phase phase : phases) {
        if (game.isPaused() || game.checkIfGameIsOver()) {
            return false;
        }
        if (isEndTurnRequested() && phase.getType() != TurnPhase.END) {
            continue;
        }
        currentPhase = phase;
        game.fireEvent(new PhaseChangedEvent(activePlayer.getId(), null));
        if (game.getState().getTurnMods().skipPhase(activePlayer.getId(), currentPhase.getType()) || !phase.play(game, activePlayer.getId())) {
            continue;
        }
        if (game.executingRollback()) {
            return false;
        }
        // 20091005 - 500.4/703.4n
        game.emptyManaPools(null);
        game.saveState(false);
        // 20091005 - 500.8
        while (playExtraPhases(game, phase.getType())) ;
    }
    return false;
}
Also used : TurnPhase(mage.constants.TurnPhase) PhaseChangedEvent(mage.game.events.PhaseChangedEvent)

Example 2 with PhaseChangedEvent

use of mage.game.events.PhaseChangedEvent 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 3 with PhaseChangedEvent

use of mage.game.events.PhaseChangedEvent 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 PhaseChangedEvent (mage.game.events.PhaseChangedEvent)3 UUID (java.util.UUID)1 PhaseStep (mage.constants.PhaseStep)1 Player (mage.players.Player)1