Search in sources :

Example 1 with PassAbility

use of mage.abilities.common.PassAbility 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 PassAbility

use of mage.abilities.common.PassAbility in project mage by magefree.

the class ComputerPlayer6 method act.

protected void act(Game game) {
    if (actions == null || actions.isEmpty()) {
        pass(game);
    } else {
        boolean usedStack = false;
        while (actions.peek() != null) {
            Ability ability = actions.poll();
            // example: ===> SELECTED ACTION for PlayerA: Play Swamp
            logger.info(String.format("===> SELECTED ACTION for %s: %s", getName(), ability.toString() + listTargets(game, ability.getTargets(), " (targeting %s)", "")));
            if (!ability.getTargets().isEmpty()) {
                for (Target target : ability.getTargets()) {
                    for (UUID id : target.getTargets()) {
                        target.updateTarget(id, game);
                        if (!target.isNotTarget()) {
                            game.addSimultaneousEvent(GameEvent.getEvent(GameEvent.EventType.TARGETED, id, ability, ability.getControllerId()));
                        }
                    }
                }
                Player player = game.getPlayer(ability.getFirstTarget());
                if (player != null) {
                    logger.info("targets = " + player.getName());
                }
            }
            this.activateAbility((ActivatedAbility) ability, game);
            if (ability.isUsesStack()) {
                usedStack = true;
            }
            if (!suggestedActions.isEmpty() && !(ability instanceof PassAbility)) {
                Iterator<String> it = suggestedActions.iterator();
                while (it.hasNext()) {
                    String action = it.next();
                    Card card = game.getCard(ability.getSourceId());
                    if (card != null && action.equals(card.getName())) {
                        logger.info("-> removed from suggested=" + action);
                        it.remove();
                    }
                }
            }
        }
        if (usedStack) {
            pass(game);
        }
    }
}
Also used : StaticAbility(mage.abilities.StaticAbility) ActivatedAbility(mage.abilities.ActivatedAbility) PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Target(mage.target.Target) Player(mage.players.Player) PassAbility(mage.abilities.common.PassAbility) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 3 with PassAbility

use of mage.abilities.common.PassAbility in project mage by magefree.

the class ComputerPlayer6 method checkForRepeatedAction.

private boolean checkForRepeatedAction(Game sim, SimulationNode2 node, Ability action, UUID playerId) {
    // pass or casting two times a spell multiple times on hand is ok
    if (action instanceof PassAbility || action instanceof SpellAbility || action.getAbilityType() == AbilityType.MANA) {
        return false;
    }
    int newVal = GameStateEvaluator2.evaluate(playerId, sim).getTotalScore();
    SimulationNode2 test = node.getParent();
    while (test != null) {
        if (test.getPlayerId().equals(playerId)) {
            if (test.getAbilities() != null && test.getAbilities().size() == 1) {
                if (action.toString().equals(test.getAbilities().get(0).toString())) {
                    if (test.getParent() != null) {
                        Game prevGame = node.getGame();
                        if (prevGame != null) {
                            int oldVal = GameStateEvaluator2.evaluate(playerId, prevGame).getTotalScore();
                            if (oldVal >= newVal) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
        test = test.getParent();
    }
    return false;
}
Also used : PassAbility(mage.abilities.common.PassAbility) Game(mage.game.Game) SpellAbility(mage.abilities.SpellAbility)

Example 4 with PassAbility

use of mage.abilities.common.PassAbility in project mage by magefree.

the class RandomPlayer method priority.

@Override
public boolean priority(Game game) {
    boolean didSomething = false;
    Ability ability = getAction(game);
    if (!(ability instanceof PassAbility)) {
        didSomething = true;
    }
    activateAbility((ActivatedAbility) ability, game);
    actionCount++;
    return didSomething;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) PassAbility(mage.abilities.common.PassAbility)

Example 5 with PassAbility

use of mage.abilities.common.PassAbility in project mage by magefree.

the class PlayerImpl method activateAbility.

@Override
public boolean activateAbility(ActivatedAbility ability, Game game) {
    if (ability == null) {
        return false;
    }
    boolean result;
    if (ability instanceof PassAbility) {
        pass(game);
        return true;
    }
    Card card = game.getCard(ability.getSourceId());
    if (ability instanceof PlayLandAsCommanderAbility) {
        // LAND as commander: play land with cost, but without stack
        ActivationStatus activationStatus = ability.canActivate(this.playerId, game);
        if (!activationStatus.canActivate() || !this.canPlayLand()) {
            return false;
        }
        if (card == null) {
            return false;
        }
        // as copy, tries to applie cost effects and pays
        Ability activatingAbility = ability.copy();
        if (activatingAbility.activate(game, false)) {
            result = playLand(card, game, false);
        } else {
            result = false;
        }
    } else if (ability instanceof PlayLandAbility) {
        // LAND as normal card: without cost and stack
        result = playLand(card, game, false);
    } else {
        // ABILITY
        ActivationStatus activationStatus = ability.canActivate(this.playerId, game);
        if (!activationStatus.canActivate()) {
            return false;
        }
        switch(ability.getAbilityType()) {
            case SPECIAL_ACTION:
                result = specialAction((SpecialAction) ability.copy(), game);
                break;
            case SPECIAL_MANA_PAYMENT:
                result = specialManaPayment((SpecialAction) ability.copy(), game);
                break;
            case MANA:
                result = playManaAbility((ActivatedManaAbilityImpl) ability.copy(), game);
                break;
            case SPELL:
                result = cast((SpellAbility) ability, game, false, activationStatus.getApprovingObject());
                break;
            default:
                result = playAbility(ability.copy(), game);
                break;
        }
    }
    // if player has taken an action then reset all player passed flags
    justActivatedType = null;
    if (result) {
        if (isHuman() && (ability.getAbilityType() == AbilityType.SPELL || ability.getAbilityType() == AbilityType.ACTIVATED)) {
            if (ability.isUsesStack()) {
                // if the ability does not use the stack (e.g. Suspend) auto pass would go to next phase unintended
                setJustActivatedType(ability.getAbilityType());
            }
        }
        game.getPlayers().resetPassed();
    }
    return result;
}
Also used : AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) StackAbility(mage.game.stack.StackAbility) WhileSearchingPlayFromLibraryAbility(mage.abilities.common.WhileSearchingPlayFromLibraryAbility) AtTheEndOfTurnStepPostDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility) PassAbility(mage.abilities.common.PassAbility) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) PassAbility(mage.abilities.common.PassAbility) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) ActivationStatus(mage.abilities.ActivatedAbility.ActivationStatus) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard)

Aggregations

PassAbility (mage.abilities.common.PassAbility)9 StackAbility (mage.game.stack.StackAbility)5 Ability (mage.abilities.Ability)4 ActivatedAbility (mage.abilities.ActivatedAbility)3 SpellAbility (mage.abilities.SpellAbility)3 Card (mage.cards.Card)3 Game (mage.game.Game)3 java.util (java.util)2 java.util.concurrent (java.util.concurrent)2 Collectors (java.util.stream.Collectors)2 StaticAbility (mage.abilities.StaticAbility)2 Cards (mage.cards.Cards)2 Choice (mage.choices.Choice)2 Permanent (mage.game.permanent.Permanent)2 StackObject (mage.game.stack.StackObject)2 Player (mage.players.Player)2 TargetCard (mage.target.TargetCard)2 java.io (java.io)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1