Search in sources :

Example 1 with RatingRange

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);
}
Also used : Consumer(java.util.function.Consumer) RatingRange(com.faforever.client.remote.domain.RatingRange) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage)

Example 2 with RatingRange

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()));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RatingRange(com.faforever.client.remote.domain.RatingRange) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with RatingRange

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();
}
Also used : NewGameInfo(com.faforever.client.game.NewGameInfo) Arrays(java.util.Arrays) PUBLIC(com.faforever.client.remote.domain.GameAccess.PUBLIC) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Timer(java.util.Timer) Faction(com.faforever.client.game.Faction) ConnectionState(com.faforever.client.net.ConnectionState) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Collections.singletonList(java.util.Collections.singletonList) HIGH(com.faforever.client.task.CompletableTask.Priority.HIGH) IceServer(com.faforever.client.remote.domain.IceServersServerMessage.IceServer) GameStatus(com.faforever.client.remote.domain.GameStatus) TimerTask(java.util.TimerTask) FafClientApplication(com.faforever.client.FafClientApplication) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) PASSWORD(com.faforever.client.remote.domain.GameAccess.PASSWORD) PlayersMessage(com.faforever.client.remote.domain.PlayersMessage) List(java.util.List) Lazy(org.springframework.context.annotation.Lazy) TaskService(com.faforever.client.task.TaskService) Player(com.faforever.client.remote.domain.Player) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) MatchmakerQueue(com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) Avatar(com.faforever.client.remote.domain.Avatar) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) CompletableTask(com.faforever.client.task.CompletableTask) LoginMessage(com.faforever.client.remote.domain.LoginMessage) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) GameAccess(com.faforever.client.remote.domain.GameAccess) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) KnownFeaturedMod(com.faforever.client.game.KnownFeaturedMod) LinkedList(java.util.LinkedList) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Action(com.faforever.client.notification.Action) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) Profile(org.springframework.context.annotation.Profile) PersistentNotification(com.faforever.client.notification.PersistentNotification) Consumer(java.util.function.Consumer) ServerMessage(com.faforever.client.remote.domain.ServerMessage) Component(org.springframework.stereotype.Component) RatingRange(com.faforever.client.remote.domain.RatingRange) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) I18n(com.faforever.client.i18n.I18n) Collections(java.util.Collections) GpgGameMessage(com.faforever.client.fa.relay.GpgGameMessage) Player(com.faforever.client.remote.domain.Player) Action(com.faforever.client.notification.Action) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) CompletableTask(com.faforever.client.task.CompletableTask) PlayersMessage(com.faforever.client.remote.domain.PlayersMessage) MatchmakerQueue(com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue) TimerTask(java.util.TimerTask) RatingRange(com.faforever.client.remote.domain.RatingRange) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) LoginMessage(com.faforever.client.remote.domain.LoginMessage) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Example 4 with RatingRange

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)));
}
Also used : PreferencesService(com.faforever.client.preferences.PreferencesService) Pos(javafx.geometry.Pos) UiService(com.faforever.client.theme.UiService) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) HashMap(java.util.HashMap) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) Map(java.util.Map) TableView(javafx.scene.control.TableView) SortedList(javafx.collections.transformation.SortedList) StringCell(com.faforever.client.fx.StringCell) ObjectProperty(javafx.beans.property.ObjectProperty) Pair(javafx.util.Pair) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) Node(javafx.scene.Node) TableRow(javafx.scene.control.TableRow) Observable(javafx.beans.Observable) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Platform(javafx.application.Platform) SortType(javafx.scene.control.TableColumn.SortType) Component(org.springframework.stereotype.Component) List(java.util.List) SortEvent(javafx.scene.control.SortEvent) RatingRange(com.faforever.client.remote.domain.RatingRange) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) NotNull(org.jetbrains.annotations.NotNull) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Joiner(com.google.common.base.Joiner) RatingRange(com.faforever.client.remote.domain.RatingRange) SortedList(javafx.collections.transformation.SortedList) Label(javafx.scene.control.Label) Observable(javafx.beans.Observable)

Example 5 with RatingRange

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())));
}
Also used : StageStyle(javafx.stage.StageStyle) MINIMIZE(com.faforever.client.fx.WindowController.WindowButtonType.MINIMIZE) GameService(com.faforever.client.game.GameService) UiService(com.faforever.client.theme.UiService) PseudoClass(javafx.css.PseudoClass) Open1v1Event(com.faforever.client.main.event.Open1v1Event) InvalidationListener(javafx.beans.InvalidationListener) NavigateEvent(com.faforever.client.main.event.NavigateEvent) WindowController(com.faforever.client.fx.WindowController) MAXIMIZE_RESTORE(com.faforever.client.fx.WindowController.WindowButtonType.MAXIMIZE_RESTORE) PlayerService(com.faforever.client.player.PlayerService) Path(java.nio.file.Path) Pane(javafx.scene.layout.Pane) ClientProperties(com.faforever.client.config.ClientProperties) SettingsController(com.faforever.client.preferences.ui.SettingsController) LoggedOutEvent(com.faforever.client.user.event.LoggedOutEvent) LoginController(com.faforever.client.login.LoginController) Rectangle2D(javafx.geometry.Rectangle2D) Platform.runLater(javafx.application.Platform.runLater) Collection(java.util.Collection) UpdateApplicationBadgeEvent(com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent) PersistentNotificationsController(com.faforever.client.notification.PersistentNotificationsController) TransientNotificationsController(com.faforever.client.notification.TransientNotificationsController) AbstractViewController(com.faforever.client.fx.AbstractViewController) Screen(javafx.stage.Screen) Observable(javafx.beans.Observable) NavigationItem(com.faforever.client.main.event.NavigationItem) Platform(javafx.application.Platform) Objects(java.util.Objects) Player(com.faforever.client.player.Player) StageHolder(com.faforever.client.ui.StageHolder) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ToggleButton(javafx.scene.control.ToggleButton) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) ObservableList(javafx.collections.ObservableList) Bounds(javafx.geometry.Bounds) PreferencesService(com.faforever.client.preferences.PreferencesService) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) AnchorLocation(javafx.stage.PopupWindow.AnchorLocation) SplashScreen(com.install4j.api.launcher.SplashScreen) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) PlatformService(com.faforever.client.fx.PlatformService) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) GamePathHandler(com.faforever.client.game.GamePathHandler) NotificationService(com.faforever.client.notification.NotificationService) ClientUpdateService(com.faforever.client.update.ClientUpdateService) Subscribe(com.google.common.eventbus.Subscribe) Labeled(javafx.scene.control.Labeled) Modality(javafx.stage.Modality) Controller(com.faforever.client.fx.Controller) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) CLOSE(com.faforever.client.fx.WindowController.WindowButtonType.CLOSE) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) PersistentNotification(com.faforever.client.notification.PersistentNotification) Popup(javafx.stage.Popup) UnreadPrivateMessageEvent(com.faforever.client.chat.event.UnreadPrivateMessageEvent) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) Component(org.springframework.stereotype.Component) UnreadNewsEvent(com.faforever.client.news.UnreadNewsEvent) RatingRange(com.faforever.client.remote.domain.RatingRange) Stage(javafx.stage.Stage) Severity(com.faforever.client.notification.Severity) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) WindowPrefs(com.faforever.client.preferences.WindowPrefs) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) Cache(com.google.common.cache.Cache) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) ImmediateNotificationController(com.faforever.client.notification.ImmediateNotificationController) Collections(java.util.Collections) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) Player(com.faforever.client.player.Player) Open1v1Event(com.faforever.client.main.event.Open1v1Event) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) TransientNotification(com.faforever.client.notification.TransientNotification) RatingRange(com.faforever.client.remote.domain.RatingRange) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Aggregations

RatingRange (com.faforever.client.remote.domain.RatingRange)6 MatchmakerMessage (com.faforever.client.rankedmatch.MatchmakerMessage)5 I18n (com.faforever.client.i18n.I18n)3 List (java.util.List)3 Consumer (java.util.function.Consumer)3 Inject (javax.inject.Inject)3 Component (org.springframework.stereotype.Component)3 Controller (com.faforever.client.fx.Controller)2 NotificationService (com.faforever.client.notification.NotificationService)2 PersistentNotification (com.faforever.client.notification.PersistentNotification)2 Severity (com.faforever.client.notification.Severity)2 TransientNotification (com.faforever.client.notification.TransientNotification)2 PreferencesService (com.faforever.client.preferences.PreferencesService)2 UiService (com.faforever.client.theme.UiService)2 LoginSuccessEvent (com.faforever.client.user.event.LoginSuccessEvent)2 EventBus (com.google.common.eventbus.EventBus)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Platform (javafx.application.Platform)2