Search in sources :

Example 1 with CoopLeaderboardEntry

use of com.faforever.server.entity.CoopLeaderboardEntry in project faf-java-server by FAForever.

the class CoopService method reportOperationComplete.

public void reportOperationComplete(Player player, boolean secondaryTargets, Duration duration) {
    Game game = player.getCurrentGame();
    Requests.verify(game != null, ErrorCode.COOP_CANT_REPORT_NOT_IN_GAME);
    log.debug("Player '{}' reported coop result '{}' with secondary targets '{}' for game: {}", player, duration, secondaryTargets, game);
    Optional<CoopMap> optional = coopMapRepository.findOneByFilenameLikeIgnoreCase(game.getMapName());
    if (optional.isPresent()) {
        CoopLeaderboardEntry coopLeaderboardEntry = new CoopLeaderboardEntry();
        coopLeaderboardEntry.setGameId(game.getId());
        coopLeaderboardEntry.setMission(optional.get());
        coopLeaderboardEntry.setPlayerCount(game.getPlayerStats().size());
        coopLeaderboardEntry.setSecondary(secondaryTargets);
        coopLeaderboardEntry.setTime(new Time(duration.toMillis()));
        coopLeaderboardRepository.save(coopLeaderboardEntry);
    }
}
Also used : Game(com.faforever.server.entity.Game) CoopMap(com.faforever.server.entity.CoopMap) CoopLeaderboardEntry(com.faforever.server.entity.CoopLeaderboardEntry) Time(java.sql.Time)

Example 2 with CoopLeaderboardEntry

use of com.faforever.server.entity.CoopLeaderboardEntry in project faf-java-server by FAForever.

the class CoopServiceTest method reportOperationComplete.

@Test
public void reportOperationComplete() throws Exception {
    Game game = new Game().setId(42).setMapName("SCMP_001");
    Map<Integer, GamePlayerStats> playerStats = game.getPlayerStats();
    playerStats.put(1, new GamePlayerStats());
    playerStats.put(2, new GamePlayerStats());
    playerStats.put(3, new GamePlayerStats());
    Player player = new Player();
    player.setCurrentGame(game);
    CoopMap mission = new CoopMap();
    when(coopMapRepository.findOneByFilenameLikeIgnoreCase("SCMP_001")).thenReturn(Optional.of(mission));
    instance.reportOperationComplete(player, false, Duration.ofMinutes(8));
    ArgumentCaptor<CoopLeaderboardEntry> captor = ArgumentCaptor.forClass(CoopLeaderboardEntry.class);
    verify(coopLeaderboardRepository).save(captor.capture());
    CoopLeaderboardEntry entry = captor.getValue();
    assertThat(entry.getGameId(), is(42L));
    assertThat(entry.getMission(), is(mission));
    assertThat(entry.getPlayerCount(), is(3));
    assertThat(entry.getTime(), is(Time.from(Instant.EPOCH.plus(Duration.ofMinutes(8)))));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) CoopMap(com.faforever.server.entity.CoopMap) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) CoopLeaderboardEntry(com.faforever.server.entity.CoopLeaderboardEntry) Test(org.junit.Test)

Aggregations

CoopLeaderboardEntry (com.faforever.server.entity.CoopLeaderboardEntry)2 CoopMap (com.faforever.server.entity.CoopMap)2 Game (com.faforever.server.entity.Game)2 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)1 Player (com.faforever.server.entity.Player)1 Time (java.sql.Time)1 Test (org.junit.Test)1