Search in sources :

Example 1 with Phase

use of mage.game.turn.Phase in project mage by magefree.

the class GameController method attemptToFixGame.

public String attemptToFixGame(User user) {
    if (game == null) {
        return "";
    }
    GameState state = game.getState();
    if (state == null) {
        return "";
    }
    logger.warn("FIX command was called by " + user.getName() + " for game " + game.getId() + " - players: " + game.getPlayerList().stream().map(game::getPlayer).filter(Objects::nonNull).map(p -> p.getName() + (p.isInGame() ? " (play)" : " (out)")).collect(Collectors.joining(", ")));
    StringBuilder sb = new StringBuilder();
    sb.append("<font color='red'>FIX command called by ").append(user.getName()).append("</font>");
    // font resize start for all next logs
    sb.append("<font size='-2'>");
    sb.append("<br>Game ID: ").append(game.getId());
    if (game.getTurn().getPhaseType() == null) {
        sb.append("<br>Phase: not started").append(" Step: not started");
    } else {
        sb.append("<br>Phase: ").append(game.getTurn().getPhaseType().toString()).append(" Step: ").append(game.getTurn().getStepType().toString());
    }
    // pings info
    sb.append("<br>");
    sb.append(getPingsInfo());
    boolean fixedAlready = false;
    // for logs info
    List<String> fixActions = new ArrayList<>();
    // fix active
    Player playerActive = game.getPlayer(state.getActivePlayerId());
    sb.append("<br>Fixing active player: ").append(getName(playerActive));
    if (playerActive != null && !playerActive.canRespond()) {
        fixActions.add("active player fix");
        sb.append("<br><font color='red'>WARNING, active player can't respond.</font>");
        sb.append("<br>Try to concede...");
        playerActive.concede(game);
        // abort any wait response actions
        playerActive.leave();
        sb.append(" (").append(asWarning("OK")).append(", concede done)");
        sb.append("<br>Try to skip step...");
        Phase currentPhase = game.getPhase();
        if (currentPhase != null) {
            currentPhase.getStep().skipStep(game, state.getActivePlayerId());
            fixedAlready = true;
            sb.append(" (").append(asWarning("OK")).append(", skip step done)");
        } else {
            sb.append(" (").append(asBad("FAIL")).append(", step is null)");
        }
    } else {
        sb.append(playerActive != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
    }
    // fix lost choosing dialog
    Player choosingPlayer = game.getPlayer(state.getChoosingPlayerId());
    sb.append("<br>Fixing choosing player: ").append(getName(choosingPlayer));
    if (choosingPlayer != null && !choosingPlayer.canRespond()) {
        fixActions.add("choosing player fix");
        sb.append("<br><font color='red'>WARNING, choosing player can't respond.</font>");
        sb.append("<br>Try to concede...");
        choosingPlayer.concede(game);
        // abort any wait response actions
        choosingPlayer.leave();
        sb.append(" (").append(asWarning("OK")).append(", concede done)");
        sb.append("<br>Try to skip step...");
        if (fixedAlready) {
            sb.append(" (OK, already skipped before)");
        } else {
            Phase currentPhase = game.getPhase();
            if (currentPhase != null) {
                currentPhase.getStep().skipStep(game, state.getActivePlayerId());
                fixedAlready = true;
                sb.append(" (").append(asWarning("OK")).append(", skip step done)");
            } else {
                sb.append(" (").append(asBad("FAIL")).append(", step is null)");
            }
        }
    } else {
        sb.append(choosingPlayer != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
    }
    // fix lost priority
    Player priorityPlayer = game.getPlayer(state.getPriorityPlayerId());
    sb.append("<br>Fixing priority player: ").append(getName(priorityPlayer));
    if (priorityPlayer != null && !priorityPlayer.canRespond()) {
        fixActions.add("priority player fix");
        sb.append("<br><font color='red'>WARNING, priority player can't respond.</font>");
        sb.append("<br>Try to concede...");
        priorityPlayer.concede(game);
        // abort any wait response actions
        priorityPlayer.leave();
        sb.append(" (").append(asWarning("OK")).append(", concede done)");
        sb.append("<br>Try to skip step...");
        if (fixedAlready) {
            sb.append(" (").append(asWarning("OK")).append(", already skipped before)");
        } else {
            Phase currentPhase = game.getPhase();
            if (currentPhase != null) {
                currentPhase.getStep().skipStep(game, state.getActivePlayerId());
                fixedAlready = true;
                sb.append(" (").append(asWarning("OK")).append(", skip step done)");
            } else {
                sb.append(" (").append(asBad("FAIL")).append(", step is null)");
            }
        }
    } else {
        sb.append(priorityPlayer != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
    }
    // fix timeout
    sb.append("<br>Fixing future timeout: ");
    if (futureTimeout != null) {
        sb.append("cancelled?=").append(futureTimeout.isCancelled());
        sb.append("...done?=").append(futureTimeout.isDone());
        int delay = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
        sb.append("...getDelay?=").append(delay);
        if (delay < 25) {
            fixActions.add("future timeout fix");
            sb.append("<br><font color='red'>WARNING, future timeout delay < 25</font>");
            sb.append("<br>Try to pass...");
            PassAbility pass = new PassAbility();
            game.endTurn(pass);
            sb.append(" (").append(asWarning("OK")).append(", pass done)");
        } else {
            sb.append(" (").append(asGood("OK")).append(", delay > 25)");
        }
    } else {
        sb.append(" (").append(asGood("OK")).append(", timeout is not using)");
    }
    // ALL DONE
    if (fixActions.isEmpty()) {
        fixActions.add("none");
    }
    String appliedFixes = fixActions.stream().collect(Collectors.joining(", "));
    sb.append("<br>Applied fixes: ").append(appliedFixes);
    // font resize end
    sb.append("</font>");
    sb.append("<br>");
    logger.warn("FIX command result for game " + game.getId() + ": " + appliedFixes);
    return sb.toString();
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) java.util(java.util) Zone(mage.constants.Zone) MessageType(mage.view.ChatMessage.MessageType) Splitter(mage.server.util.Splitter) mage.game(mage.game) MessageColor(mage.view.ChatMessage.MessageColor) TableEvent(mage.game.events.TableEvent) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Player(mage.players.Player) mage.view(mage.view) Logger(org.apache.log4j.Logger) ManaType(mage.constants.ManaType) PlayerAction(mage.constants.PlayerAction) User(mage.server.User) SystemUtil(mage.server.util.SystemUtil) StreamUtils(mage.utils.StreamUtils) Card(mage.cards.Card) DeckCardLists(mage.cards.decks.DeckCardLists) PriorityTimer(mage.utils.timer.PriorityTimer) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Choice(mage.choices.Choice) PassAbility(mage.abilities.common.PassAbility) java.util.concurrent(java.util.concurrent) Cards(mage.cards.Cards) Deck(mage.cards.decks.Deck) Plane(mage.game.command.Plane) MageException(mage.MageException) CardRepository(mage.cards.repository.CardRepository) Collectors(java.util.stream.Collectors) Phase(mage.game.turn.Phase) Action(mage.interfaces.Action) Lock(java.util.concurrent.locks.Lock) PlayerQueryEvent(mage.game.events.PlayerQueryEvent) ManagerFactory(mage.server.managers.ManagerFactory) Main(mage.server.Main) java.io(java.io) CardInfo(mage.cards.repository.CardInfo) Permanent(mage.game.permanent.Permanent) Entry(java.util.Map.Entry) Listener(mage.game.events.Listener) GZIPOutputStream(java.util.zip.GZIPOutputStream) Ability(mage.abilities.Ability) MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) PassAbility(mage.abilities.common.PassAbility) Phase(mage.game.turn.Phase)

Example 2 with Phase

use of mage.game.turn.Phase in project mage by magefree.

the class IllusionistsGambitRestrictionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> attackers = game.getCombat().getAttackers();
    for (UUID attackerId : attackers) {
        Permanent creature = game.getPermanent(attackerId);
        if (creature != null) {
            creature.removeFromCombat(game);
            creature.untap(game);
        }
    }
    if (!attackers.isEmpty()) {
        Phase phase = game.getTurn().getPhase();
        game.getState().getTurnMods().add(new TurnMod(game.getActivePlayerId(), TurnPhase.COMBAT, null, false));
        ContinuousEffect effect = new IllusionistsGambitRequirementEffect(attackers, phase);
        game.addEffect(effect, source);
        effect = new IllusionistsGambitRestrictionEffect(attackers, phase);
        game.addEffect(effect, source);
    }
    return true;
}
Also used : Phase(mage.game.turn.Phase) Permanent(mage.game.permanent.Permanent) TurnMod(mage.game.turn.TurnMod) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Aggregations

Permanent (mage.game.permanent.Permanent)2 Phase (mage.game.turn.Phase)2 java.io (java.io)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 java.util.concurrent (java.util.concurrent)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Collectors (java.util.stream.Collectors)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 MageException (mage.MageException)1 Ability (mage.abilities.Ability)1 PassAbility (mage.abilities.common.PassAbility)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Card (mage.cards.Card)1 Cards (mage.cards.Cards)1 Deck (mage.cards.decks.Deck)1 DeckCardLists (mage.cards.decks.DeckCardLists)1