Search in sources :

Example 6 with Match

use of mage.game.match.Match 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 7 with Match

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

the class TableManagerImpl method removeTable.

@Override
public void removeTable(UUID tableId) {
    TableController tableController = controllers.get(tableId);
    if (tableController != null) {
        Lock w = controllersLock.writeLock();
        w.lock();
        try {
            controllers.remove(tableId);
        } finally {
            w.unlock();
        }
        // deletes the table chat and references to users
        tableController.cleanUp();
        Table table = tables.get(tableId);
        w = tablesLock.writeLock();
        w.lock();
        try {
            tables.remove(tableId);
        } finally {
            w.unlock();
        }
        Match match = table.getMatch();
        Game game = null;
        if (match != null) {
            game = match.getGame();
            if (game != null && !game.hasEnded()) {
                game.end();
            }
        }
        // If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update())
        if (table.getState() != TableState.FINISHED) {
            if (game != null) {
                managerFactory.gameManager().removeGame(game.getId());
            // something goes wrong, so don't add it to ended stats
            }
            managerFactory.gamesRoomManager().removeTable(tableId);
        }
    }
}
Also used : Table(mage.game.Table) Game(mage.game.Game) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) Match(mage.game.match.Match)

Aggregations

Match (mage.game.match.Match)7 FreeformUnlimitedCommanderMatch (mage.game.FreeformUnlimitedCommanderMatch)3 MatchOptions (mage.game.match.MatchOptions)3 Test (org.junit.Test)3 Game (mage.game.Game)2 MatchPlayer (mage.game.match.MatchPlayer)2 Date (java.util.Date)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Table (mage.game.Table)1 MatchProto (mage.game.result.ResultProtos.MatchProto)1 TourneyProto (mage.game.result.ResultProtos.TourneyProto)1 TourneyRoundProto (mage.game.result.ResultProtos.TourneyRoundProto)1