use of com.faforever.client.remote.domain.RatingRange in project downlords-faf-client by FAForever.
the class MainControllerTest method prepareTestMatchmakerMessageTest.
private void prepareTestMatchmakerMessageTest(float deviation) {
@SuppressWarnings("unchecked") ArgumentCaptor<Consumer<MatchmakerMessage>> matchmakerMessageCaptor = ArgumentCaptor.forClass(Consumer.class);
when(notificationPrefs.getLadder1v1ToastEnabled()).thenReturn(true);
when(playerService.getCurrentPlayer()).thenReturn(Optional.ofNullable(PlayerBuilder.create("JUnit").leaderboardRatingMean(1500).leaderboardRatingDeviation(deviation).get()));
verify(gameService).addOnRankedMatchNotificationListener(matchmakerMessageCaptor.capture());
MatchmakerMessage matchmakerMessage = new MatchmakerMessage();
matchmakerMessage.setQueues(singletonList(new MatchmakerMessage.MatchmakerQueue("ladder1v1", singletonList(new RatingRange(1500, 1510)), singletonList(new RatingRange(1500, 1510)))));
matchmakerMessageCaptor.getValue().accept(matchmakerMessage);
}
use of com.faforever.client.remote.domain.RatingRange in project downlords-faf-client by FAForever.
the class ServerAccessorImplTest method testRankedMatchNotification.
@Test
public void testRankedMatchNotification() throws Exception {
connectAndLogIn();
MatchmakerMessage matchmakerMessage = new MatchmakerMessage();
matchmakerMessage.setQueues(singletonList(new MatchmakerMessage.MatchmakerQueue("ladder1v1", singletonList(new RatingRange(100, 200)), singletonList(new RatingRange(100, 200)))));
CompletableFuture<MatchmakerMessage> serviceStateDoneFuture = new CompletableFuture<>();
WaitForAsyncUtils.waitForAsyncFx(200, () -> instance.addOnMessageListener(MatchmakerMessage.class, serviceStateDoneFuture::complete));
sendFromServer(matchmakerMessage);
MatchmakerMessage matchmakerServerMessage = serviceStateDoneFuture.get(TIMEOUT, TIMEOUT_UNIT);
assertThat(matchmakerServerMessage.getQueues(), not(empty()));
}
use of com.faforever.client.remote.domain.RatingRange in project downlords-faf-client by FAForever.
the class MockFafServerAccessor method connectAndLogIn.
@Override
public CompletableFuture<LoginMessage> connectAndLogIn(String username, String password) {
return taskService.submitTask(new CompletableTask<LoginMessage>(HIGH) {
@Override
protected LoginMessage call() throws Exception {
updateTitle(i18n.get("login.progress.message"));
Player player = new Player();
player.setId(4812);
player.setLogin(USER_NAME);
player.setClan("ABC");
player.setCountry("A1");
player.setGlobalRating(new float[] { 1500, 220 });
player.setLadderRating(new float[] { 1500, 220 });
player.setNumberOfGames(330);
PlayersMessage playersMessage = new PlayersMessage();
playersMessage.setPlayers(singletonList(player));
eventBus.post(new LoginSuccessEvent(username, password, player.getId()));
messageListeners.getOrDefault(playersMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(playersMessage));
timer.schedule(new TimerTask() {
@Override
public void run() {
UpdatedAchievementsMessage updatedAchievementsMessage = new UpdatedAchievementsMessage();
UpdatedAchievement updatedAchievement = new UpdatedAchievement();
updatedAchievement.setAchievementId("50260d04-90ff-45c8-816b-4ad8d7b97ecd");
updatedAchievement.setNewlyUnlocked(true);
updatedAchievementsMessage.setUpdatedAchievements(Arrays.asList(updatedAchievement));
messageListeners.getOrDefault(updatedAchievementsMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(updatedAchievementsMessage));
}
}, 7000);
timer.schedule(new TimerTask() {
@Override
public void run() {
MatchmakerMessage matchmakerServerMessage = new MatchmakerMessage();
matchmakerServerMessage.setQueues(singletonList(new MatchmakerQueue("ladder1v1", singletonList(new RatingRange(100, 200)), singletonList(new RatingRange(100, 200)))));
messageListeners.getOrDefault(matchmakerServerMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(matchmakerServerMessage));
}
}, 7000);
List<GameInfoMessage> gameInfoMessages = Arrays.asList(createGameInfo(1, "Mock game 500 - 800", PUBLIC, "faf", "scmp_010", 1, 6, "Mock user"), createGameInfo(2, "Mock game 500+", PUBLIC, "faf", "scmp_011", 2, 6, "Mock user"), createGameInfo(3, "Mock game +500", PUBLIC, "faf", "scmp_012", 3, 6, "Mock user"), createGameInfo(4, "Mock game <1000", PUBLIC, "faf", "scmp_013", 4, 6, "Mock user"), createGameInfo(5, "Mock game >1000", PUBLIC, "faf", "scmp_014", 5, 6, "Mock user"), createGameInfo(6, "Mock game ~600", PASSWORD, "faf", "scmp_015", 6, 6, "Mock user"), createGameInfo(7, "Mock game 7", PASSWORD, "faf", "scmp_016", 7, 6, "Mock user"));
gameInfoMessages.forEach(gameInfoMessage -> messageListeners.getOrDefault(gameInfoMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(gameInfoMessage)));
notificationService.addNotification(new PersistentNotification("How about a long-running (7s) mock task?", Severity.INFO, Arrays.asList(new Action("Execute", event -> taskService.submitTask(new CompletableTask<Void>(HIGH) {
@Override
protected Void call() throws Exception {
updateTitle("Mock task");
Thread.sleep(2000);
for (int i = 0; i < 5; i++) {
updateProgress(i, 5);
Thread.sleep(1000);
}
return null;
}
})), new Action("Nope"))));
LoginMessage sessionInfo = new LoginMessage();
sessionInfo.setId(123);
sessionInfo.setLogin(USER_NAME);
return sessionInfo;
}
}).getFuture();
}
use of com.faforever.client.remote.domain.RatingRange in project downlords-faf-client by FAForever.
the class GamesTableController method initializeGameTable.
public void initializeGameTable(ObservableList<Game> games) {
SortedList<Game> sortedList = new SortedList<>(games);
sortedList.comparatorProperty().bind(gamesTable.comparatorProperty());
gamesTable.setPlaceholder(new Label(i18n.get("games.noGamesAvailable")));
gamesTable.setRowFactory(param1 -> gamesRowFactory());
gamesTable.setItems(sortedList);
applyLastSorting(gamesTable);
gamesTable.setOnSort(this::onColumnSorted);
sortedList.addListener((Observable observable) -> selectFirstGame());
selectFirstGame();
passwordProtectionColumn.setCellValueFactory(param -> param.getValue().passwordProtectedProperty());
passwordProtectionColumn.setCellFactory(param -> passwordIndicatorColumn());
mapPreviewColumn.setCellFactory(param -> new MapPreviewTableCell(uiService));
mapPreviewColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> mapService.loadPreview(param.getValue().getMapFolderName(), PreviewSize.SMALL), param.getValue().mapFolderNameProperty()));
gameTitleColumn.setCellValueFactory(param -> param.getValue().titleProperty());
gameTitleColumn.setCellFactory(param -> new StringCell<>(title -> title));
playersColumn.setCellValueFactory(param -> Bindings.createObjectBinding(() -> new PlayerFill(param.getValue().getNumPlayers(), param.getValue().getMaxPlayers()), param.getValue().numPlayersProperty(), param.getValue().maxPlayersProperty()));
playersColumn.setCellFactory(param -> playersCell());
ratingColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(new RatingRange(param.getValue().getMinRating(), param.getValue().getMaxRating())));
ratingColumn.setCellFactory(param -> ratingTableCell());
hostColumn.setCellValueFactory(param -> param.getValue().hostProperty());
hostColumn.setCellFactory(param -> new StringCell<>(String::toString));
modsColumn.setCellValueFactory(this::modCell);
modsColumn.setCellFactory(param -> new StringCell<>(String::toString));
gamesTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> selectedGame.set(newValue)));
}
use of com.faforever.client.remote.domain.RatingRange in project downlords-faf-client by FAForever.
the class MainController method onMatchmakerMessage.
private void onMatchmakerMessage(MatchmakerMessage message) {
if (message.getQueues() == null || gameService.gameRunningProperty().get() || !preferencesService.getPreferences().getNotification().getLadder1v1ToastEnabled() || !playerService.getCurrentPlayer().isPresent()) {
return;
}
Player currentPlayer = playerService.getCurrentPlayer().get();
int deviationFor80PercentQuality = (int) (ratingBeta / 2.5f);
int deviationFor75PercentQuality = (int) (ratingBeta / 1.25f);
float leaderboardRatingDeviation = currentPlayer.getLeaderboardRatingDeviation();
Function<MatchmakerMessage.MatchmakerQueue, List<RatingRange>> ratingRangesSupplier;
if (leaderboardRatingDeviation <= deviationFor80PercentQuality) {
ratingRangesSupplier = MatchmakerMessage.MatchmakerQueue::getBoundary80s;
} else if (leaderboardRatingDeviation <= deviationFor75PercentQuality) {
ratingRangesSupplier = MatchmakerMessage.MatchmakerQueue::getBoundary75s;
} else {
return;
}
float leaderboardRatingMean = currentPlayer.getLeaderboardRatingMean();
boolean showNotification = false;
for (MatchmakerMessage.MatchmakerQueue matchmakerQueue : message.getQueues()) {
if (!Objects.equals("ladder1v1", matchmakerQueue.getQueueName())) {
continue;
}
List<RatingRange> ratingRanges = ratingRangesSupplier.apply(matchmakerQueue);
for (RatingRange ratingRange : ratingRanges) {
if (ratingRange.getMin() <= leaderboardRatingMean && leaderboardRatingMean <= ratingRange.getMax()) {
showNotification = true;
break;
}
}
}
if (!showNotification) {
return;
}
notificationService.addNotification(new TransientNotification(i18n.get("ranked1v1.notification.title"), i18n.get("ranked1v1.notification.message"), uiService.getThemeImage(UiService.LADDER_1V1_IMAGE), event -> eventBus.post(new Open1v1Event())));
}
Aggregations