use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class SocialService method onPlayerOnlineEvent.
@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
Player player = event.getPlayer();
List<SocialRelation> socialRelations = player.getSocialRelations();
if (socialRelations == null) {
return;
}
clientService.sendSocialRelations(new SocialRelationListResponse(socialRelations.stream().map(socialRelation -> new SocialRelationResponse(socialRelation.getSubjectId(), RelationType.valueOf(socialRelation.getStatus().toString()))).collect(Collectors.toList())), player);
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class ArmyStatisticsService method process.
public void process(Player player, Game game, List<ArmyStatistics> statistics) {
int numberOfHumans = 0;
float highestScore = 0;
String highestScorerName = null;
ArmyStatistics armyStats = null;
int currentIndex = 0;
int playerArmyId = -1;
for (ArmyStatistics statsItem : statistics) {
currentIndex++;
if (statsItem.getType() == AI && !CIVILIAN_ARMY_NAME.equals(statsItem.getName())) {
log.debug("AI game reported by '{}', aborting stats processing", player);
return;
}
if (statsItem.getType() == HUMAN) {
numberOfHumans += 1;
}
if (highestScore < statsItem.getGeneral().getScore()) {
highestScore = statsItem.getGeneral().getScore();
highestScorerName = statsItem.getName();
}
if (Objects.equals(statsItem.getName(), player.getLogin())) {
armyStats = statsItem;
playerArmyId = currentIndex;
}
}
if (playerArmyId == -1) {
log.warn("No army stats available for player '{}' in game '{}', aborting stats processing", player, game);
return;
}
if (numberOfHumans < 2) {
log.debug("Single player game '{}' reported by '{}', aborting stats processing", game, player);
return;
}
int finalArmyId = playerArmyId;
Optional<ArmyResult> armyOutcome = game.getReportedArmyResults().values().stream().flatMap(map -> map.values().stream()).filter(item -> item.getArmyId() == finalArmyId).findFirst();
if (!armyOutcome.isPresent()) {
log.warn("No outcome for army '{}ยด (player '{}') has been reported for game '{}', " + "aborting stats processing", playerArmyId, player, game);
return;
}
Outcome outcome = armyOutcome.get().getOutcome();
log.debug("Processing stats for army '{}' (player '{}') in game '{}'", playerArmyId, player, game);
Faction faction = armyStats.getFaction();
ArrayList<AchievementUpdate> achievementUpdates = new ArrayList<>();
ArrayList<EventUpdate> eventUpdates = new ArrayList<>();
boolean survived = outcome == Outcome.VICTORY;
Map<String, ArmyStatistics.UnitStats> unitStats = firstNonNull(armyStats.getUnitStats(), Collections.emptyMap());
ArmyStatistics.CategoryStats categoryStats = armyStats.getCategoryStats();
boolean scoredHighest = Objects.equals(highestScorerName, player.getLogin());
int playerId = player.getId();
if (survived && modService.isLadder1v1(game.getFeaturedMod())) {
unlock(AchievementId.ACH_FIRST_SUCCESS, achievementUpdates, playerId);
if (Duration.between(game.getStartTime(), game.getEndTime()).compareTo(Duration.ofMinutes(RUSHER_MINUTE_LIMIT)) < 0) {
unlock(AchievementId.ACH_RUSHER, achievementUpdates, playerId);
}
}
increment(AchievementId.ACH_NOVICE, 1, achievementUpdates, playerId);
increment(AchievementId.ACH_JUNIOR, 1, achievementUpdates, playerId);
increment(AchievementId.ACH_SENIOR, 1, achievementUpdates, playerId);
increment(AchievementId.ACH_VETERAN, 1, achievementUpdates, playerId);
increment(AchievementId.ACH_ADDICT, 1, achievementUpdates, playerId);
factionPlayed(faction, survived, achievementUpdates, eventUpdates, playerId);
categoryStats(categoryStats, survived, achievementUpdates, eventUpdates, playerId);
killedAcus(categoryStats, survived, achievementUpdates, playerId);
builtMercies(countBuiltUnits(unitStats, Unit.MERCY), achievementUpdates, playerId);
builtFireBeetles(countBuiltUnits(unitStats, Unit.FIRE_BEETLE), achievementUpdates, playerId);
builtSalvations(countBuiltUnits(unitStats, Unit.SALVATION), survived, achievementUpdates, playerId);
builtYolonaOss(countBuiltUnits(unitStats, Unit.YOLONA_OSS), survived, achievementUpdates, playerId);
builtParagons(countBuiltUnits(unitStats, Unit.PARAGON), survived, achievementUpdates, playerId);
builtAtlantis(countBuiltUnits(unitStats, Unit.ATLANTIS), achievementUpdates, playerId);
builtTempests(countBuiltUnits(unitStats, Unit.TEMPEST), achievementUpdates, playerId);
builtScathis(countBuiltUnits(unitStats, Unit.SCATHIS), survived, achievementUpdates, playerId);
builtMavors(countBuiltUnits(unitStats, Unit.MAVOR), survived, achievementUpdates, playerId);
builtCzars(countBuiltUnits(unitStats, Unit.CZAR), achievementUpdates, playerId);
builtAhwassas(countBuiltUnits(unitStats, Unit.AHWASSA), achievementUpdates, playerId);
builtYthothas(countBuiltUnits(unitStats, Unit.YTHOTHA), achievementUpdates, playerId);
builtFatboys(countBuiltUnits(unitStats, Unit.FATBOY), achievementUpdates, playerId);
builtMonkeylords(countBuiltUnits(unitStats, Unit.MONKEYLORD), achievementUpdates, playerId);
builtGalacticColossus(countBuiltUnits(unitStats, Unit.GALACTIC_COLOSSUS), achievementUpdates, playerId);
builtSoulRippers(countBuiltUnits(unitStats, Unit.SOUL_RIPPER), achievementUpdates, playerId);
builtMegaliths(countBuiltUnits(unitStats, Unit.MEGALITH), achievementUpdates, playerId);
builtAsfs(countBuiltUnits(unitStats, Unit.ASFS), achievementUpdates, playerId);
builtTransports(categoryStats.getTransportation().getBuilt(), achievementUpdates, playerId);
builtSacus(categoryStats.getSacu().getBuilt(), achievementUpdates, playerId);
lowestAcuHealth(count(unitStats, ArmyStatistics.UnitStats::getLowestHealth, Unit.ACUS), survived, achievementUpdates, playerId);
highscore(scoredHighest, numberOfHumans, achievementUpdates, playerId);
eventService.executeBatchUpdate(eventUpdates).exceptionally(throwable -> {
log.warn("Could not report '" + eventUpdates.size() + "' event updates for player '" + player + "'", throwable);
return null;
});
achievementService.executeBatchUpdate(achievementUpdates).thenAccept(playerAchievements -> clientService.reportUpdatedAchievements(playerAchievements, player)).exceptionally(throwable -> {
log.warn("Could not report '" + achievementUpdates.size() + "' achievement updates for player '" + player + "'", throwable);
return null;
});
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class MatchMakerService method processPool.
private void processPool(String poolName, Map<Integer, MatchMakerSearch> pool) {
Set<MatchMakerSearch> processedSearches = new HashSet<>();
log.trace("Processing '{}' entries of pool '{}'", pool.size(), poolName);
pool.values().stream().sorted(Comparator.comparingInt(search -> search.player.getId())).map((search) -> {
processedSearches.add(search);
return findMatch(search, processedSearches);
}).filter(Optional::isPresent).forEach(optional -> {
Match match = optional.get();
MatchMakerSearch leftSearch = match.leftSearch;
MatchMakerSearch rightSearch = match.rightSearch;
Player leftPlayer = leftSearch.player;
Player rightPlayer = rightSearch.player;
log.debug("Player '{}' was matched against '{}' with game quality '{}'", leftPlayer, rightPlayer, match.quality);
pool.remove(leftSearch.player.getId());
pool.remove(rightSearch.player.getId());
String technicalModName = modByPoolName.get(leftSearch.poolName).getTechnicalName();
startGame(technicalModName, leftPlayer, leftSearch.faction, rightPlayer, rightSearch.faction);
});
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class DivisionService method getCurrentPlayerDivision.
public Optional<Division> getCurrentPlayerDivision(Player player) {
int season = properties.getLadder1v1().getSeason();
PlayerDivisionInfo info = playerDivisionInfoRepository.findByPlayerAndSeason(player, season);
if (info == null) {
return Optional.empty();
}
return Optional.of(divisions.stream().filter(division -> Objects.equals(division.getLeague(), info.getLeague())).filter(division -> info.getScore() <= division.getThreshold()).findFirst().orElseThrow(() -> new IllegalStateException(MessageFormat.format("Could not determine division for PlayerDivisionInfo {0}", info))));
}
use of com.faforever.server.entity.Player in project faf-java-server by FAForever.
the class SocialServiceActivatorsTest method setUp.
@Before
public void setUp() throws Exception {
player = (Player) new Player().setId(1);
clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player).setPassword("pw").setLogin("JUnit")), null));
instance = new SocialServiceActivators(socialService);
}
Aggregations