Search in sources :

Example 1 with Outcome

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);
}
Also used : Outcome(com.faforever.server.game.Outcome) ArmyScoreReport(com.faforever.server.game.ArmyScoreReport)

Example 2 with 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;
    });
}
Also used : Arrays(java.util.Arrays) ModService(com.faforever.server.mod.ModService) ArmyResult(com.faforever.server.entity.ArmyResult) Outcome(com.faforever.server.game.Outcome) CategoryStats(com.faforever.server.stats.ArmyStatistics.CategoryStats) ArrayList(java.util.ArrayList) Player(com.faforever.server.entity.Player) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ClientService(com.faforever.server.client.ClientService) AchievementUpdate(com.faforever.server.stats.achievements.AchievementUpdate) Unit(com.faforever.server.game.Unit) HUMAN(com.faforever.server.stats.ArmyStatistics.BrainType.HUMAN) ToIntFunction(java.util.function.ToIntFunction) Faction(com.faforever.server.game.Faction) AI(com.faforever.server.stats.ArmyStatistics.BrainType.AI) AchievementId(com.faforever.server.stats.achievements.AchievementId) EventId(com.faforever.server.stats.event.EventId) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Game(com.faforever.server.entity.Game) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) EventUpdate(com.faforever.server.stats.event.EventUpdate) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) AchievementService(com.faforever.server.stats.achievements.AchievementService) EventService(com.faforever.server.stats.event.EventService) ArrayList(java.util.ArrayList) AchievementUpdate(com.faforever.server.stats.achievements.AchievementUpdate) EventUpdate(com.faforever.server.stats.event.EventUpdate) Outcome(com.faforever.server.game.Outcome) ArmyResult(com.faforever.server.entity.ArmyResult) Faction(com.faforever.server.game.Faction) CategoryStats(com.faforever.server.stats.ArmyStatistics.CategoryStats)

Aggregations

Outcome (com.faforever.server.game.Outcome)2 ClientService (com.faforever.server.client.ClientService)1 ArmyResult (com.faforever.server.entity.ArmyResult)1 Game (com.faforever.server.entity.Game)1 Player (com.faforever.server.entity.Player)1 ArmyScoreReport (com.faforever.server.game.ArmyScoreReport)1 Faction (com.faforever.server.game.Faction)1 Unit (com.faforever.server.game.Unit)1 ModService (com.faforever.server.mod.ModService)1 AI (com.faforever.server.stats.ArmyStatistics.BrainType.AI)1 HUMAN (com.faforever.server.stats.ArmyStatistics.BrainType.HUMAN)1 CategoryStats (com.faforever.server.stats.ArmyStatistics.CategoryStats)1 AchievementId (com.faforever.server.stats.achievements.AchievementId)1 AchievementService (com.faforever.server.stats.achievements.AchievementService)1 AchievementUpdate (com.faforever.server.stats.achievements.AchievementUpdate)1 EventId (com.faforever.server.stats.event.EventId)1 EventService (com.faforever.server.stats.event.EventService)1 EventUpdate (com.faforever.server.stats.event.EventUpdate)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1