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();
}
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();
}
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();
}
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;
}
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;
}
Aggregations