use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class RandomBoosterDraftSwissTournament method draft.
@Override
protected void draft() {
draft = new RandomBoosterDraft((DraftOptions) options.getLimitedOptions(), getSets());
for (TournamentPlayer player : players.values()) {
draft.addPlayer(player.getPlayer());
player.setState(TournamentPlayerState.DRAFTING);
}
tableEventSource.fireTableEvent(EventType.START_DRAFT, null, draft);
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class RichManDraftEliminationTournament method draft.
protected void draft() {
draft = new RichManBoosterDraft((DraftOptions) options.getLimitedOptions(), getSets());
for (TournamentPlayer player : players.values()) {
draft.addPlayer(player.getPlayer());
player.setState(TournamentPlayerState.DRAFTING);
}
tableEventSource.fireTableEvent(EventType.START_DRAFT, null, draft);
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TableController method joinTournament.
public synchronized boolean joinTournament(UUID userId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws GameException {
if (table.getState() != TableState.WAITING) {
return false;
}
Seat seat = table.getNextAvailableSeat(playerType);
if (seat == null) {
throw new GameException("No available seats.");
}
Optional<User> _user = managerFactory.userManager().getUser(userId);
if (!_user.isPresent()) {
logger.fatal("couldn't get user " + name + " for join tournament userId = " + userId);
return false;
}
User user = _user.get();
// check password
if (!table.getTournament().getOptions().getPassword().isEmpty() && playerType == PlayerType.HUMAN) {
if (!table.getTournament().getOptions().getPassword().equals(password)) {
user.showUserMessage("Join Table", "Wrong password.");
return false;
}
}
if (userPlayerMap.containsKey(userId) && playerType == PlayerType.HUMAN) {
user.showUserMessage("Join Table", "You can join a table only one time.");
return false;
}
Deck deck = null;
if (!table.getTournament().getTournamentType().isLimited()) {
if (deckList != null) {
deck = Deck.load(deckList, false, false);
} else {
user.showUserMessage("Join Table", "No valid deck selected!");
return false;
}
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
StringBuilder sb = new StringBuilder("You (").append(name).append(") have an 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\nSelect a deck that is appropriate for the selected format and try again!");
user.showUserMessage("Join Table", sb.toString());
if (isOwner(userId)) {
logger.debug("New table removed because owner submitted invalid deck tableId " + table.getId());
managerFactory.tableManager().removeTable(table.getId());
}
return false;
}
}
// Check quit ratio.
int quitRatio = table.getTournament().getOptions().getQuitRatio();
if (quitRatio < user.getTourneyQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getTourneyQuitRatio()).append("% is higher than the table requirement ").append(quitRatio).append('%').toString();
user.showUserMessage("Join Table", message);
return false;
}
// Check minimum rating.
int minimumRating = table.getTournament().getOptions().getMinimumRating();
int userRating;
if (table.getTournament().getOptions().getMatchOptions().isLimited()) {
userRating = user.getUserData().getLimitedRating();
} else {
userRating = user.getUserData().getConstructedRating();
}
if (userRating < minimumRating) {
String message = new StringBuilder("Your rating ").append(userRating).append(" is lower than the table requirement ").append(minimumRating).toString();
user.showUserMessage("Join Table", message);
return false;
}
Optional<Player> playerOptional = createPlayer(name, seat.getPlayerType(), skill);
if (playerOptional.isPresent()) {
Player player = playerOptional.get();
if (!player.canJoinTable(table)) {
user.showUserMessage("Join Table", new StringBuilder("A ").append(seat.getPlayerType()).append(" player can't join this table.").toString());
return false;
}
tournament.addPlayer(player, seat.getPlayerType());
TournamentPlayer tournamentPlayer = tournament.getPlayer(player.getId());
if (deck != null && tournamentPlayer != null) {
tournamentPlayer.submitDeck(deck);
}
table.joinTable(player, seat);
logger.debug("Player " + player.getName() + " id: " + player.getId() + " joined tableId: " + table.getId());
// only inform human players and add them to sessionPlayerMap
if (seat.getPlayer().isHuman()) {
seat.getPlayer().setUserData(user.getUserData());
user.addTable(player.getId(), table);
user.ccJoinedTable(table.getRoomId(), table.getId(), true);
userPlayerMap.put(userId, player.getId());
}
return true;
} else {
throw new GameException("Playertype " + seat.getPlayerType() + " could not be created.");
}
}
use of mage.game.tournament.TournamentPlayer 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("");
}
}
}
}
use of mage.game.tournament.TournamentPlayer in project mage by magefree.
the class TournamentController method init.
private void init() {
tournament.addTableEventListener((Listener<TableEvent>) event -> {
switch(event.getEventType()) {
case CHECK_STATE_PLAYERS:
checkPlayersState();
break;
case INFO:
managerFactory.chatManager().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, null, MessageType.STATUS, null);
logger.debug(tournament.getId() + " " + event.getMessage());
break;
case START_DRAFT:
startDraft(event.getDraft());
break;
case CONSTRUCT:
if (!isAbort()) {
construct();
} else {
endTournament();
}
break;
case START_MATCH:
if (!isAbort()) {
initTournament();
startMatch(event.getPair(), event.getMatchOptions());
}
break;
case START_MULTIPLAYER_MATCH:
if (!isAbort()) {
initTournament();
MatchOptions matchOptions = event.getMatchOptions();
if (matchOptions != null && event.getMultiplayerRound() != null) {
for (TournamentPlayer player : event.getMultiplayerRound().getAllPlayers()) {
matchOptions.getPlayerTypes().add(player.getPlayerType());
}
}
startMultiplayerMatch(event.getMultiplayerRound(), event.getMatchOptions());
}
break;
case END:
endTournament();
break;
}
});
tournament.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
try {
switch(event.getQueryType()) {
case CONSTRUCT:
construct(event.getPlayerId(), event.getMax());
break;
}
} catch (MageException ex) {
logger.fatal("Player event listener error", ex);
}
});
for (TournamentPlayer player : tournament.getPlayers()) {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
}
}
checkStart();
}
Aggregations