use of mage.game.events.TableEvent 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();
}
use of mage.game.events.TableEvent in project mage by magefree.
the class DraftController method init.
private void init() {
draft.addTableEventListener((Listener<TableEvent>) event -> {
try {
switch(event.getEventType()) {
case UPDATE:
updateDraft();
break;
case END:
endDraft();
break;
}
} catch (MageException ex) {
logger.fatal("Table event listener error", ex);
}
});
draft.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
try {
switch(event.getQueryType()) {
case PICK_CARD:
pickCard(event.getPlayerId(), event.getMax());
break;
}
} catch (MageException ex) {
logger.fatal("Table event listener error", ex);
}
});
for (DraftPlayer player : draft.getPlayers()) {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.debug("player " + player.getPlayer().getId() + " has joined draft " + draft.getId());
}
}
checkStart();
}
use of mage.game.events.TableEvent in project mage by magefree.
the class GameController method init.
private void init() {
game.addTableEventListener((Listener<TableEvent>) event -> {
try {
PriorityTimer timer;
UUID playerId;
switch(event.getEventType()) {
case UPDATE:
updateGame();
break;
case INFO:
managerFactory.chatManager().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, event.getGame(), MessageType.GAME, null);
logger.trace(game.getId() + " " + event.getMessage());
break;
case STATUS:
managerFactory.chatManager().broadcast(chatId, "", event.getMessage(), MessageColor.ORANGE, event.getWithTime(), event.getWithTurnInfo() ? event.getGame() : null, MessageType.GAME, null);
logger.trace(game.getId() + " " + event.getMessage());
break;
case ERROR:
error(event.getMessage(), event.getException());
break;
case END_GAME_INFO:
endGameInfo();
break;
case INIT_TIMER:
final UUID initPlayerId = event.getPlayerId();
if (initPlayerId == null) {
throw new MageException("INIT_TIMER: playerId can't be null");
}
createPlayerTimer(event.getPlayerId(), game.getPriorityTime());
break;
case RESUME_TIMER:
playerId = event.getPlayerId();
if (playerId == null) {
throw new MageException("RESUME_TIMER: playerId can't be null");
}
timer = timers.get(playerId);
if (timer == null) {
Player player = game.getState().getPlayer(playerId);
if (player != null) {
timer = createPlayerTimer(event.getPlayerId(), player.getPriorityTimeLeft());
} else {
throw new MageException("RESUME_TIMER: player can't be null");
}
}
timer.resume();
break;
case PAUSE_TIMER:
playerId = event.getPlayerId();
if (playerId == null) {
throw new MageException("PAUSE_TIMER: playerId can't be null");
}
timer = timers.get(playerId);
if (timer == null) {
throw new MageException("PAUSE_TIMER: couldn't find timer for player: " + playerId);
}
timer.pause();
break;
}
} catch (MageException ex) {
logger.fatal("Table event listener error ", ex);
}
});
game.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
logger.trace(new StringBuilder(event.getPlayerId().toString()).append("--").append(event.getQueryType()).append("--").append(event.getMessage()).toString());
try {
switch(event.getQueryType()) {
case ASK:
ask(event.getPlayerId(), event.getMessage(), event.getOptions());
break;
case PICK_TARGET:
target(event.getPlayerId(), event.getMessage(), event.getCards(), event.getPerms(), event.getTargets(), event.isRequired(), event.getOptions());
break;
case PICK_ABILITY:
target(event.getPlayerId(), event.getMessage(), event.getAbilities(), event.isRequired(), event.getOptions());
break;
case SELECT:
select(event.getPlayerId(), event.getMessage(), event.getOptions());
break;
case PLAY_MANA:
playMana(event.getPlayerId(), event.getMessage(), event.getOptions());
break;
case PLAY_X_MANA:
playXMana(event.getPlayerId(), event.getMessage());
break;
case CHOOSE_ABILITY:
String objectName = null;
if (event.getChoices() != null && !event.getChoices().isEmpty()) {
objectName = event.getChoices().iterator().next();
}
chooseAbility(event.getPlayerId(), objectName, event.getAbilities(), event.getMessage());
break;
case CHOOSE_PILE:
choosePile(event.getPlayerId(), event.getMessage(), event.getPile1(), event.getPile2());
break;
case CHOOSE_MODE:
chooseMode(event.getPlayerId(), event.getModes(), event.getMessage());
break;
case CHOOSE_CHOICE:
chooseChoice(event.getPlayerId(), event.getChoice());
break;
case AMOUNT:
amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax());
break;
case MULTI_AMOUNT:
multiAmount(event.getPlayerId(), event.getMessages(), event.getMin(), event.getMax(), event.getOptions());
break;
case PERSONAL_MESSAGE:
informPersonal(event.getPlayerId(), event.getMessage());
break;
}
} catch (MageException ex) {
logger.fatal("Player event listener error ", ex);
}
});
joinWaitingExecutor.scheduleAtFixedRate(() -> {
try {
sendInfoAboutPlayersNotJoinedYetAndTryToFixIt();
} catch (Exception ex) {
logger.fatal("Send info about player not joined yet:", ex);
}
}, GAME_TIMEOUTS_CHECK_JOINING_STATUS_EVERY_SECS, GAME_TIMEOUTS_CHECK_JOINING_STATUS_EVERY_SECS, TimeUnit.SECONDS);
checkStart();
}
Aggregations