def _switch_to_score_screen(self, results: ba.TeamGameResults) -> None: # pylint: disable=cyclic-import from bastd.activity.drawscore import DrawScoreScreenActivity from bastd.activity.dualteamscore import ( TeamVictoryScoreScreenActivity) from bastd.activity.multiteamvictory import ( TeamSeriesVictoryScoreScreenActivity) winners = results.get_winners() # If everyone has the same score, call it a draw. if len(winners) < 2: self.setactivity(_ba.new_activity(DrawScoreScreenActivity)) else: winner = winners[0].teams[0] winner.sessiondata['score'] += 1 # If a team has won, show final victory screen. if winner.sessiondata['score'] >= (self._series_length - 1) / 2 + 1: self.setactivity( _ba.new_activity(TeamSeriesVictoryScoreScreenActivity, {'winner': winner})) else: self.setactivity( _ba.new_activity(TeamVictoryScoreScreenActivity, {'winner': winner}))
def _switch_to_score_screen(self, results: ba.TeamGameResults) -> None: # pylint: disable=cyclic-import from bastd.activity import drawscreen from bastd.activity import multiteamendscreen from bastd.activity import freeforallendscreen winners = results.get_winners() # If there's multiple players and everyone has the same score, # call it a draw. if len(self.players) > 1 and len(winners) < 2: self.set_activity( _ba.new_activity(drawscreen.DrawScoreScreenActivity, {'results': results})) else: # Award different point amounts based on number of players. point_awards = self.get_ffa_point_awards() for i, winner in enumerate(winners): for team in winner.teams: points = (point_awards[i] if i in point_awards else 0) team.sessiondata['previous_score'] = ( team.sessiondata['score']) team.sessiondata['score'] += points series_winners = [ team for team in self.teams if team.sessiondata['score'] >= self._ffa_series_length ] series_winners.sort(reverse=True, key=lambda tm: (tm.sessiondata['score'])) if (len(series_winners) == 1 or (len(series_winners) > 1 and series_winners[0].sessiondata['score'] != series_winners[1].sessiondata['score'])): self.set_activity( _ba.new_activity( multiteamendscreen. TeamSeriesVictoryScoreScreenActivity, {'winner': series_winners[0]})) else: self.set_activity( _ba.new_activity( freeforallendscreen. FreeForAllVictoryScoreScreenActivity, {'results': results}))
def announce_game_results(self, activity: ba.GameActivity, results: ba.TeamGameResults, delay: float, announce_winning_team: bool = True) -> None: """Show basic game result at the end of a game. (before transitioning to a score screen). This will include a zoom-text of 'BLUE WINS' or whatnot, along with a possible audio announcement of the same. """ # pylint: disable=cyclic-import # pylint: disable=too-many-locals from ba import _math from ba import _general from ba._gameutils import cameraflash from ba import _lang from ba._freeforallsession import FreeForAllSession from ba._messages import CelebrateMessage _ba.timer(delay, _general.Call(_ba.playsound, _ba.getsound('boxingBell'))) if announce_winning_team: winning_team = results.get_winning_team() if winning_team is not None: # Have all players celebrate. celebrate_msg = CelebrateMessage(duration=10.0) assert winning_team.gameteam is not None for player in winning_team.gameteam.players: if player.actor: player.actor.handlemessage(celebrate_msg) cameraflash() # Some languages say "FOO WINS" different for teams vs players. if isinstance(self, FreeForAllSession): wins_resource = 'winsPlayerText' else: wins_resource = 'winsTeamText' wins_text = _lang.Lstr(resource=wins_resource, subs=[('${NAME}', winning_team.name)]) activity.show_zoom_message(wins_text, scale=0.85, color=_math.normalized_color( winning_team.color))