Search in sources :

Example 1 with MatchPlayer

use of mage.game.match.MatchPlayer in project mage by magefree.

the class TableController method sideboard.

private void sideboard() {
    table.sideboard();
    setupTimeout(Match.SIDEBOARD_TIME);
    if (table.isTournamentSubTable()) {
        for (MatchPlayer matchPlayer : match.getPlayers()) {
            if (!matchPlayer.hasQuit()) {
                TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(matchPlayer.getPlayer().getId());
                if (tournamentPlayer != null) {
                    tournamentPlayer.setStateInfo("sideboarding");
                }
            }
        }
    }
    match.sideboard();
    cancelTimeout();
    if (table.isTournamentSubTable()) {
        for (MatchPlayer matchPlayer : match.getPlayers()) {
            TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(matchPlayer.getPlayer().getId());
            if (tournamentPlayer != null && tournamentPlayer.getStateInfo().equals("sideboarding")) {
                tournamentPlayer.setStateInfo("");
            }
        }
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer) MatchPlayer(mage.game.match.MatchPlayer)

Example 2 with MatchPlayer

use of mage.game.match.MatchPlayer in project mage by magefree.

the class TableController method matchEnd.

private void matchEnd() {
    if (match != null) {
        for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
            MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
            // opponent(s) left during sideboarding
            if (matchPlayer != null) {
                if (!matchPlayer.hasQuit()) {
                    managerFactory.userManager().getUser(entry.getKey()).ifPresent(user -> {
                        if (table.getState() == TableState.SIDEBOARDING) {
                            StringBuilder sb = new StringBuilder();
                            if (table.isTournamentSubTable()) {
                                sb.append("Your tournament match of round ");
                                sb.append(table.getTournament().getRounds().size());
                                sb.append(" is over. ");
                            } else {
                                sb.append("Match [").append(match.getName()).append("] is over. ");
                            }
                            if (match.getPlayers().size() > 2) {
                                sb.append("All your opponents have lost or quit the match.");
                            } else {
                                sb.append("Your opponent has quit the match.");
                            }
                            user.showUserMessage("Match info", sb.toString());
                        }
                        // removeUserFromAllTablesAndChat table from user - table manager holds table for display of finished matches
                        if (!table.isTournamentSubTable()) {
                            user.removeTable(entry.getValue());
                        }
                    });
                }
            }
            // free resources no longer needed
            match.cleanUpOnMatchEnd(managerFactory.configSettings().isSaveGameActivated(), table.isTournament());
        }
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer)

Example 3 with MatchPlayer

use of mage.game.match.MatchPlayer in project mage by magefree.

the class TableController method startGame.

private void startGame(UUID choosingPlayerId) throws GameException {
    try {
        match.startGame();
        table.initGame();
        GameOptions gameOptions = new GameOptions();
        gameOptions.rollbackTurnsAllowed = match.getOptions().isRollbackTurnsAllowed();
        gameOptions.bannedUsers = match.getOptions().getBannedUsers();
        gameOptions.planeChase = match.getOptions().isPlaneChase();
        match.getGame().setGameOptions(gameOptions);
        managerFactory.gameManager().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
        String creator = null;
        StringBuilder opponent = new StringBuilder();
        for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
            // do only for no AI players
            if (match.getPlayer(entry.getValue()) != null && !match.getPlayer(entry.getValue()).hasQuit()) {
                Optional<User> _user = managerFactory.userManager().getUser(entry.getKey());
                if (_user.isPresent()) {
                    User user = _user.get();
                    user.ccGameStarted(match.getGame().getId(), entry.getValue());
                    if (creator == null) {
                        creator = user.getName();
                    } else {
                        if (opponent.length() > 0) {
                            opponent.append(" - ");
                        }
                        opponent.append(user.getName());
                    }
                } else {
                    logger.error("Unable to find user: " + entry.getKey() + "  playerId: " + entry.getValue());
                    MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
                    if (matchPlayer != null && !matchPlayer.hasQuit()) {
                        matchPlayer.setQuit(true);
                    }
                }
            }
        }
        // Append AI opponents to the log file
        for (MatchPlayer mPlayer : match.getPlayers()) {
            if (!mPlayer.getPlayer().isHuman()) {
                if (opponent.length() > 0) {
                    opponent.append(" - ");
                }
                opponent.append(mPlayer.getName());
            }
        }
        ServerMessagesUtil.instance.incGamesStarted();
        // log about game started
        logger.info("GAME started " + (match.getGame() != null ? match.getGame().getId() : "no Game") + " [" + match.getName() + "] " + creator + " - " + opponent);
        logger.debug("- matchId: " + match.getId() + " [" + match.getName() + ']');
        if (match.getGame() != null) {
            logger.debug("- chatId:  " + managerFactory.gameManager().getChatId(match.getGame().getId()));
        }
    } catch (Exception ex) {
        logger.fatal("Error starting game table: " + table.getId(), ex);
        if (table != null) {
            managerFactory.tableManager().removeTable(table.getId());
        }
        if (match != null) {
            Game game = match.getGame();
            if (game != null) {
                managerFactory.gameManager().removeGame(game.getId());
            // game ended by error, so don't add it to ended stats
            }
        }
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) MageException(mage.MageException)

Example 4 with MatchPlayer

use of mage.game.match.MatchPlayer in project mage by magefree.

the class TournamentImpl method updateResults.

/**
 */
@Override
public void updateResults() {
    for (TournamentPlayer player : players.values()) {
        player.setResults("");
        player.setPoints(0);
        player.setStateInfo("");
    }
    for (Round round : rounds) {
        for (TournamentPairing pair : round.getPairs()) {
            Match match = pair.getMatch();
            if (match != null && match.hasEnded()) {
                TournamentPlayer tp1 = pair.getPlayer1();
                TournamentPlayer tp2 = pair.getPlayer2();
                MatchPlayer mp1 = match.getPlayer(pair.getPlayer1().getPlayer().getId());
                MatchPlayer mp2 = match.getPlayer(pair.getPlayer2().getPlayer().getId());
                // set player state if they finished the round
                if (round.getRoundNumber() == rounds.size()) {
                    // for elimination getRoundNumber = 0 so never true here
                    match.setTournamentRound(round.getRoundNumber());
                    if (tp1.getState() == TournamentPlayerState.DUELING) {
                        if (round.getRoundNumber() == getNumberRounds()) {
                            tp1.setState(TournamentPlayerState.FINISHED);
                        } else {
                            tp1.setState(TournamentPlayerState.WAITING);
                        }
                    }
                    if (tp2.getState() == TournamentPlayerState.DUELING) {
                        if (round.getRoundNumber() == getNumberRounds()) {
                            tp2.setState(TournamentPlayerState.FINISHED);
                        } else {
                            tp2.setState(TournamentPlayerState.WAITING);
                        }
                    }
                }
                // Add round result
                tp1.setResults(addRoundResult(round.getRoundNumber(), pair, tp1, tp2));
                tp2.setResults(addRoundResult(round.getRoundNumber(), pair, tp2, tp1));
                // Add points
                if ((!mp1.hasQuit() && mp1.getWins() > mp2.getWins()) || mp2.hasQuit()) {
                    tp1.setPoints(tp1.getPoints() + 3);
                } else if ((!mp2.hasQuit() && mp1.getWins() < mp2.getWins()) || mp1.hasQuit()) {
                    tp2.setPoints(tp2.getPoints() + 3);
                } else {
                    tp1.setPoints(tp1.getPoints() + 1);
                    tp2.setPoints(tp2.getPoints() + 1);
                }
            }
        }
        for (TournamentPlayer tp : round.getPlayerByes()) {
            tp.setResults(new StringBuilder(tp.getResults()).append('R').append(round.getRoundNumber()).append(' ').append("Bye ").toString());
            tp.setPoints(tp.getPoints() + 3);
        }
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Match(mage.game.match.Match)

Example 5 with MatchPlayer

use of mage.game.match.MatchPlayer in project mage by magefree.

the class TournamentPairing method eliminatePlayers.

/**
 * Called by eliminate tournaments after each match
 */
public void eliminatePlayers() {
    if (match != null && match.hasEnded()) {
        MatchPlayer mPlayer1 = match.getPlayer(player1.getPlayer().getId());
        MatchPlayer mPlayer2 = match.getPlayer(player2.getPlayer().getId());
        if (mPlayer1.hasQuit() || !mPlayer1.isMatchWinner()) {
            player1.setEliminated();
        }
        if (mPlayer2.hasQuit() || !mPlayer2.isMatchWinner()) {
            player2.setEliminated();
        }
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer)

Aggregations

MatchPlayer (mage.game.match.MatchPlayer)11 Match (mage.game.match.Match)2 TournamentPlayer (mage.game.tournament.TournamentPlayer)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MageException (mage.MageException)1 Deck (mage.cards.decks.Deck)1 DeckValidatorError (mage.cards.decks.DeckValidatorError)1 Game (mage.game.Game)1 MatchQuitStatus (mage.game.result.ResultProtos.MatchQuitStatus)1 Player (mage.players.Player)1 User (mage.server.User)1