Search in sources :

Example 6 with MatchPlayer

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

the class TournamentImpl method getMatchResultString.

private static String getMatchResultString(TournamentPlayer p1, TournamentPlayer p2, Match match) {
    MatchPlayer mp1 = match.getPlayer(p1.getPlayer().getId());
    MatchPlayer mp2 = match.getPlayer(p2.getPlayer().getId());
    StringBuilder matchResult = new StringBuilder();
    matchResult.append(p2.getPlayer().getName());
    matchResult.append(" [").append(mp1.getWins());
    if (mp1.hasQuit()) {
        matchResult.append(mp1.getPlayer().hasIdleTimeout() ? "I" : (mp1.getPlayer().hasTimerTimeout() ? "T" : "Q"));
    }
    if (match.getDraws() > 0) {
        matchResult.append('-').append(match.getDraws());
    }
    matchResult.append('-').append(mp2.getWins());
    if (mp2.hasQuit()) {
        matchResult.append(mp2.getPlayer().hasIdleTimeout() ? "I" : (mp2.getPlayer().hasTimerTimeout() ? "T" : "Q"));
    }
    matchResult.append("] ");
    return matchResult.toString();
}
Also used : MatchPlayer(mage.game.match.MatchPlayer)

Example 7 with MatchPlayer

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

the class TournamentImpl method matchToProto.

private MatchPlayerProto matchToProto(Match match, TournamentPlayer player) {
    MatchPlayer matchPlayer = match.getPlayer(player.getPlayer().getId());
    MatchQuitStatus quit = !matchPlayer.hasQuit() ? MatchQuitStatus.NO_MATCH_QUIT : matchPlayer.getPlayer().hasIdleTimeout() ? MatchQuitStatus.IDLE_TIMEOUT : matchPlayer.getPlayer().hasTimerTimeout() ? MatchQuitStatus.TIMER_TIMEOUT : MatchQuitStatus.QUIT;
    return MatchPlayerProto.newBuilder().setName(player.getPlayer().getName()).setHuman(player.getPlayer().isHuman()).setWins(matchPlayer.getWins()).setQuit(quit).build();
}
Also used : MatchQuitStatus(mage.game.result.ResultProtos.MatchQuitStatus) MatchPlayer(mage.game.match.MatchPlayer)

Example 8 with MatchPlayer

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

the class MatchView method initMatchTable.

// used for matches
private void initMatchTable(Table table) {
    Match match = table.getMatch();
    this.matchId = match.getId();
    this.matchName = match.getName();
    this.gameType = match.getOptions().getGameType();
    if (table.getName() != null && !table.getName().isEmpty()) {
        this.deckType = match.getOptions().getDeckType() + " [" + table.getName() + ']';
    } else {
        this.deckType = match.getOptions().getDeckType();
    }
    for (Game game : match.getGames()) {
        games.add(game.getId());
    }
    StringBuilder sb1 = new StringBuilder();
    StringBuilder sb2 = new StringBuilder();
    for (MatchPlayer matchPlayer : match.getPlayers()) {
        sb1.append(matchPlayer.getName());
        if (matchPlayer.hasQuit()) {
            if (matchPlayer.getPlayer().hasTimerTimeout()) {
                sb1.append(" [timer] ");
            } else if (matchPlayer.getPlayer().hasIdleTimeout()) {
                sb1.append(" [idle] ");
            } else {
                sb1.append(" [quit] ");
            }
        }
        int lostGames = match.getNumGames() - (matchPlayer.getWins() + match.getDraws());
        sb1.append(", ");
        sb2.append(matchPlayer.getName()).append(" [");
        sb2.append(matchPlayer.getWins()).append('-');
        if (match.getDraws() > 0) {
            sb2.append(match.getDraws()).append('-');
        }
        sb2.append(lostGames).append("], ");
    }
    if (sb1.length() > 2) {
        players = sb1.substring(0, sb1.length() - 2);
        result = sb2.substring(0, sb2.length() - 2);
    } else {
        players = "[no players]";
        result = "";
    }
    this.startTime = match.getStartTime();
    this.endTime = match.getEndTime();
    this.replayAvailable = match.isReplayAvailable();
    this.rated = match.getOptions().isRated();
}
Also used : Game(mage.game.Game) MatchPlayer(mage.game.match.MatchPlayer) Match(mage.game.match.Match)

Example 9 with MatchPlayer

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

the class TableController method submitDeck.

public synchronized boolean submitDeck(UUID userId, DeckCardLists deckList) throws MageException {
    UUID playerId = userPlayerMap.get(userId);
    if (table.isTournament()) {
        TournamentPlayer player = tournament.getPlayer(playerId);
        if (player == null || player.hasQuit()) {
            // so the construct panel closes after submit
            return true;
        }
    } else if (table.getMatch() != null) {
        MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
        if (mPlayer == null || mPlayer.hasQuit()) {
            // so the construct panel closes after submit
            return true;
        }
        if (table.isTournamentSubTable()) {
            TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(mPlayer.getPlayer().getId());
            if (tournamentPlayer != null) {
                // reset sideboarding state
                tournamentPlayer.setStateInfo("");
            }
        }
    }
    if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
        return false;
    }
    Deck deck = Deck.load(deckList, false, false);
    if (table.getState() == TableState.SIDEBOARDING && table.getMatch() != null) {
        MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
        if (mPlayer != null) {
            deck.setName(mPlayer.getDeck().getName());
        }
    }
    if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
        Optional<User> _user = managerFactory.userManager().getUser(userId);
        if (!_user.isPresent()) {
            return false;
        }
        StringBuilder sb = new StringBuilder("Invalid deck for the selected ").append(table.getValidator().getName()).append(" format. \n\n");
        List<DeckValidatorError> errorsList = table.getValidator().getErrorsListSorted();
        errorsList.stream().forEach(error -> {
            sb.append(error.getGroup()).append(": ").append(error.getMessage()).append("\n");
        });
        sb.append("\n\nAdd enough cards and try again!");
        _user.get().showUserMessage("Submit deck", sb.toString());
        return false;
    }
    submitDeck(userId, playerId, deck);
    return true;
}
Also used : DeckValidatorError(mage.cards.decks.DeckValidatorError) TournamentPlayer(mage.game.tournament.TournamentPlayer) MatchPlayer(mage.game.match.MatchPlayer) Deck(mage.cards.decks.Deck)

Example 10 with MatchPlayer

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

the class TableController method isMatchTableStillValid.

public boolean isMatchTableStillValid() {
    // removes active match only, not tourney
    if (table.isTournament()) {
        return true;
    }
    // only started games need to check
    if (Arrays.asList(TableState.WAITING, TableState.READY_TO_START, TableState.STARTING).contains(table.getState())) {
        // waiting in start dialog
        return true;
    }
    if (match != null && !match.isDoneSideboarding()) {
        // waiting sideboard complete
        return true;
    }
    // no games in started match (error in match init code?)
    if (match.getGame() == null) {
        logger.error("- Match without started games:");
        logger.error("-- matchId:" + match.getId());
        // critical error
        return false;
    }
    // find player stats
    int validHumanPlayers = 0;
    int validAIPlayers = 0;
    // check humans
    for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
        MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
        // de-synced users and players listst?
        if (matchPlayer == null) {
            logger.error("- Match player not found in started game:");
            logger.error("-- matchId:" + match.getId());
            logger.error("-- userId:" + userPlayerEntry.getKey());
            logger.error("-- playerId:" + userPlayerEntry.getValue());
            continue;
        }
        if (matchPlayer.getPlayer().isHuman()) {
            if (matchPlayer.getPlayer().isInGame()) {
                Optional<User> user = managerFactory.userManager().getUser(userPlayerEntry.getKey());
                // user was logout or disconnected from server, but still in the game somehow
                if (!user.isPresent() || !user.get().isActive()) {
                    logger.error("- Active user of match is missing: " + matchPlayer.getName());
                    logger.error("-- matchId:" + match.getId());
                    logger.error("-- userId:" + userPlayerEntry.getKey());
                    logger.error("-- playerId:" + userPlayerEntry.getValue());
                    // critical error
                    return false;
                }
                // user exits on the server and match player has not quit -> player is valid
                validHumanPlayers++;
            }
        }
    }
    // check AI
    for (MatchPlayer matchPlayer : match.getPlayers()) {
        if (!matchPlayer.getPlayer().isHuman()) {
            if (matchPlayer.getPlayer().isInGame()) {
                validAIPlayers++;
            }
        }
    }
    // if someone can play 1 vs 1 (e.g. 2+ players) then keep table
    return validAIPlayers + validHumanPlayers >= 2;
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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