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);
}
}
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)))));
}
Aggregations