use of com.faforever.server.game.Outcome in project faf-java-server by FAForever.
the class LegacyRequestTransformer method handleGameResult.
private ClientMessage handleGameResult(Map<String, Object> source) {
List<Object> args;
args = getArgs(source);
int armyId = (int) args.get(0);
String[] results = ((String) args.get(1)).split(" ");
if ("score".equals(results[0])) {
return new ArmyScoreReport(armyId, Integer.parseInt(results[1]));
}
Outcome outcome = Outcome.fromString(results[0]);
return ArmyOutcomeReport.valueOf(armyId, outcome);
}
use of com.faforever.server.game.Outcome 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;
});
}
Aggregations