use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TournamentController method checkToReplaceDraftPlayerByAi.
private boolean checkToReplaceDraftPlayerByAi(UUID userId, TournamentPlayer leavingPlayer) {
int humans = 0;
for (TournamentPlayer tPlayer : tournament.getPlayers()) {
if (tPlayer.getPlayer().isHuman()) {
humans++;
}
}
// replace player that quits with draft bot
if (humans > 1) {
Optional<User> user = managerFactory.userManager().getUser(userId);
managerFactory.tableManager().getController(tableId).ifPresent(tableController -> {
String replacePlayerName = "Draftbot";
if (user.isPresent()) {
replacePlayerName = "Draftbot (" + user.get().getName() + ')';
}
tableController.replaceDraftPlayer(leavingPlayer.getPlayer(), replacePlayerName, PlayerType.COMPUTER_DRAFT_BOT, 5);
if (user.isPresent()) {
user.get().removeDraft(leavingPlayer.getPlayer().getId());
user.get().removeTable(leavingPlayer.getPlayer().getId());
user.get().removeTournament(leavingPlayer.getPlayer().getId());
}
managerFactory.chatManager().broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, null, MessageType.STATUS, null);
});
return true;
}
return false;
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TournamentController method startMultiplayerMatch.
private void startMultiplayerMatch(MultiplayerRound round, MatchOptions matchOptions) {
try {
TableManager tableManager = managerFactory.tableManager();
Table table = tableManager.createTable(managerFactory.gamesRoomManager().getMainRoomId(), matchOptions);
table.setTournamentSubTable(true);
table.setTournament(tournament);
table.setState(TableState.WAITING);
if (round.getAllPlayers().stream().allMatch(tournamentPlayer -> getPlayerUserId(tournamentPlayer.getPlayer().getId()).isPresent())) {
for (TournamentPlayer player : round.getAllPlayers()) {
tableManager.addPlayer(getPlayerUserId(player.getPlayer().getId()).get(), table.getId(), player);
}
table.setState(TableState.STARTING);
tableManager.startTournamentSubMatch(null, table.getId());
tableManager.getMatch(table.getId()).ifPresent(match -> {
match.setTableId(tableId);
round.setMatch(match);
round.setTableId(table.getId());
for (TournamentPlayer player : round.getAllPlayers()) {
player.setState(TournamentPlayerState.DUELING);
}
});
}
} catch (GameException ex) {
logger.fatal("TournamentController startMatch error", ex);
}
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TournamentController method join.
public synchronized void join(UUID userId) {
UUID playerId = userPlayerMap.get(userId);
if (playerId == null) {
if (logger.isDebugEnabled()) {
managerFactory.userManager().getUser(userId).ifPresent(user -> logger.debug(user.getName() + " shows tournament panel tournamentId: " + tournament.getId()));
}
return;
}
if (tournamentSessions.containsKey(playerId)) {
logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
return;
}
// first join of player
TournamentSession tournamentSession = new TournamentSession(managerFactory, tournament, userId, tableId, playerId);
tournamentSessions.put(playerId, tournamentSession);
Optional<User> _user = managerFactory.userManager().getUser(userId);
if (_user.isPresent()) {
User user = _user.get();
user.addTournament(playerId, tournament.getId());
TournamentPlayer player = tournament.getPlayer(playerId);
player.setJoined();
logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
checkStart();
} else {
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
}
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TournamentController method startMatch.
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
try {
TableManager tableManager = managerFactory.tableManager();
Table table = tableManager.createTable(managerFactory.gamesRoomManager().getMainRoomId(), matchOptions);
table.setTournamentSubTable(true);
table.setTournament(tournament);
table.setState(TableState.WAITING);
TournamentPlayer player1 = pair.getPlayer1();
TournamentPlayer player2 = pair.getPlayer2();
UUID user1Uuid = null;
UUID user2Uuid = null;
if (player1.getPlayerType() == PlayerType.HUMAN) {
Optional<UUID> user1Id = getPlayerUserId(player1.getPlayer().getId());
if (!user1Id.isPresent()) {
logger.fatal("Player 1 not found");
} else {
user1Uuid = user1Id.get();
}
}
if (player2.getPlayerType() == PlayerType.HUMAN) {
Optional<UUID> user2Id = getPlayerUserId(player2.getPlayer().getId());
if (!user2Id.isPresent()) {
logger.fatal("Player 2 not found");
} else {
user2Uuid = user2Id.get();
}
}
tableManager.addPlayer(user1Uuid, table.getId(), player1);
tableManager.addPlayer(user2Uuid, table.getId(), player2);
table.setState(TableState.STARTING);
tableManager.startTournamentSubMatch(null, table.getId());
tableManager.getMatch(table.getId()).ifPresent(match -> {
match.setTableId(tableId);
pair.setMatch(match);
pair.setTableId(table.getId());
player1.setState(TournamentPlayerState.DUELING);
player2.setState(TournamentPlayerState.DUELING);
});
} catch (GameException ex) {
logger.fatal("TournamentController startMatch error", ex);
}
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TournamentController method checkPlayersState.
private void checkPlayersState() {
for (TournamentPlayer tournamentPlayer : tournament.getPlayers()) {
if (!tournamentPlayer.isEliminated() && tournamentPlayer.getPlayer().isHuman()) {
if (tournamentSessions.containsKey(tournamentPlayer.getPlayer().getId())) {
if (tournamentSessions.get(tournamentPlayer.getPlayer().getId()).isKilled()) {
tournamentPlayer.setEliminated();
tournamentPlayer.setStateInfo("disconnected");
}
} else {
tournamentPlayer.setEliminated();
tournamentPlayer.setStateInfo("no tournament session");
}
}
}
}
Aggregations