async def test_game_outcomes_conflicting(game: Game, database, players): game.state = GameState.LOBBY players.hosting.ratings[RatingType.LADDER_1V1] = Rating(1500, 250) players.joining.ratings[RatingType.LADDER_1V1] = Rating(1500, 250) add_connected_players(game, [players.hosting, players.joining]) await game.launch() await game.add_result(players.hosting.id, 0, "victory", 1) await game.add_result(players.joining.id, 1, "victory", 0) await game.add_result(players.hosting.id, 0, "defeat", 1) await game.add_result(players.joining.id, 1, "defeat", 0) game.set_player_option(players.hosting.id, "Team", 1) game.set_player_option(players.joining.id, "Team", 1) host_outcome = game.get_player_outcome(players.hosting) guest_outcome = game.get_player_outcome(players.joining) assert host_outcome is GameOutcome.CONFLICTING assert guest_outcome is GameOutcome.CONFLICTING
async def test_game_outcomes_no_results(game: Game, database, players): game.state = GameState.LOBBY players.hosting.ratings[RatingType.LADDER_1V1] = Rating(1500, 250) players.joining.ratings[RatingType.LADDER_1V1] = Rating(1500, 250) add_connected_players(game, [players.hosting, players.joining]) await game.launch() game.set_player_option(players.hosting.id, "Team", 1) game.set_player_option(players.joining.id, "Team", 1) host_outcome = game.get_player_outcome(players.hosting) guest_outcome = game.get_player_outcome(players.joining) assert host_outcome is GameOutcome.UNKNOWN assert guest_outcome is GameOutcome.UNKNOWN await game.on_game_end() expected_scores = {(players.hosting.id, 0), (players.joining.id, 0)} assert await game_player_scores(database, game) == expected_scores
async def test_game_outcomes(game: Game, database, players): game.state = GameState.LOBBY players.hosting.ratings[RatingType.LADDER_1V1] = Rating(1500, 250) players.joining.ratings[RatingType.LADDER_1V1] = Rating(1500, 250) add_connected_players(game, [players.hosting, players.joining]) await game.launch() await game.add_result(players.hosting.id, 0, "victory", 1) await game.add_result(players.joining.id, 1, "defeat", 0) game.set_player_option(players.hosting.id, "Team", 1) game.set_player_option(players.joining.id, "Team", 1) host_outcome = game.get_player_outcome(players.hosting) guest_outcome = game.get_player_outcome(players.joining) assert host_outcome is GameOutcome.VICTORY assert guest_outcome is GameOutcome.DEFEAT default_values_before_end = {(players.hosting.id, 0), (players.joining.id, 0)} assert await game_player_scores(database, game) == default_values_before_end await game.on_game_end() expected_scores = {(players.hosting.id, 1), (players.joining.id, 0)} assert await game_player_scores(database, game) == expected_scores
async def process_game_stats(self, player: Player, game: Game, army_stats_list: List): stats = None number_of_humans = 0 highest_score = 0 highest_scorer = None for army_stats in army_stats_list: if army_stats["type"] == "AI" and army_stats["name"] != "civilian": self._logger.debug("Ignoring AI game reported by %s", player.login) return if army_stats["type"] == "Human": number_of_humans += 1 if highest_score < army_stats["general"]["score"]: highest_score = army_stats["general"]["score"] highest_scorer = army_stats["name"] if army_stats["name"] == player.login: stats = army_stats if number_of_humans < 2: self._logger.debug("Ignoring single player game reported by %s", player.login) return if stats is None: self._logger.warning( "Player %s reported stats of a game he was not part of", player.login) return army_result = game.get_player_outcome(player) if army_result is GameOutcome.UNKNOWN: self._logger.warning("No army result available for player %s", player.login) return self._logger.debug("Processing game stats for player: %s", player.login) faction = stats["faction"] # Stores achievements to batch update a_queue = [] # Stores events to batch update e_queue = [] self._logger.debug("Army result for %s => %s ", player, army_result) survived = army_result is GameOutcome.VICTORY blueprint_stats = stats["blueprints"] unit_stats = stats["units"] scored_highest = highest_scorer == player.login if survived and game.game_mode == FeaturedModType.LADDER_1V1: self._unlock(ACH_FIRST_SUCCESS, a_queue) self._increment(ACH_NOVICE, 1, a_queue) self._increment(ACH_JUNIOR, 1, a_queue) self._increment(ACH_SENIOR, 1, a_queue) self._increment(ACH_VETERAN, 1, a_queue) self._increment(ACH_ADDICT, 1, a_queue) self._faction_played(faction, survived, a_queue, e_queue) self._category_stats(unit_stats, survived, a_queue, e_queue) self._killed_acus(unit_stats, survived, a_queue) self._built_mercies(_count_built_units(blueprint_stats, Unit.MERCY), a_queue) self._built_fire_beetles( _count_built_units(blueprint_stats, Unit.FIRE_BEETLE), a_queue) self._built_salvations( _count_built_units(blueprint_stats, Unit.SALVATION), survived, a_queue) self._built_yolona_oss( _count_built_units(blueprint_stats, Unit.YOLONA_OSS), survived, a_queue) self._built_paragons(_count_built_units(blueprint_stats, Unit.PARAGON), survived, a_queue) self._built_atlantis( _count_built_units(blueprint_stats, Unit.ATLANTIS), a_queue) self._built_tempests(_count_built_units(blueprint_stats, Unit.TEMPEST), a_queue) self._built_scathis(_count_built_units(blueprint_stats, Unit.SCATHIS), survived, a_queue) self._built_mavors(_count_built_units(blueprint_stats, Unit.MAVOR), survived, a_queue) self._built_czars(_count_built_units(blueprint_stats, Unit.CZAR), a_queue) self._built_ahwassas(_count_built_units(blueprint_stats, Unit.AHWASSA), a_queue) self._built_ythothas(_count_built_units(blueprint_stats, Unit.YTHOTHA), a_queue) self._built_fatboys(_count_built_units(blueprint_stats, Unit.FATBOY), a_queue) self._built_monkeylords( _count_built_units(blueprint_stats, Unit.MONKEYLORD), a_queue) self._built_galactic_colossus( _count_built_units(blueprint_stats, Unit.GALACTIC_COLOSSUS), a_queue) self._built_soul_rippers( _count_built_units(blueprint_stats, Unit.SOUL_RIPPER), a_queue) self._built_megaliths( _count_built_units(blueprint_stats, Unit.MEGALITH), a_queue) self._built_asfs(_count_built_units(blueprint_stats, *ASFS), a_queue) self._built_transports(unit_stats["transportation"].get("built", 0), a_queue) self._built_sacus(unit_stats["sacu"].get("built", 0), a_queue) self._lowest_acu_health( _count(blueprint_stats, lambda x: x.get("lowest_health", 0), *ACUS), survived, a_queue) self._highscore(scored_highest, number_of_humans, a_queue) if config.USE_API: updated_achievements = await self._achievement_service.execute_batch_update( player.id, a_queue) if updated_achievements is None: self._logger.warning( "API returned an error while handling the achievements batch update." ) return await self._event_service.execute_batch_update(player.id, e_queue) if player.lobby_connection is not None: await player.lobby_connection.send_updated_achievements( updated_achievements)