# Released under the MIT License. See LICENSE for details.#"""Functionality related to free-for-all sessions."""from__future__importannotationsfromtypingimportTYPE_CHECKING,overrideimportbabaseimport_bascenev1frombascenev1._multiteamsessionimportMultiTeamSessionifTYPE_CHECKING:importbascenev1classFreeForAllSession(MultiTeamSession):"""bascenev1.Session type for free-for-all mode games. Category: **Gameplay Classes** """use_teams=Falseuse_team_colors=False_playlist_selection_var='Free-for-All Playlist Selection'_playlist_randomize_var='Free-for-All Playlist Randomize'_playlists_var='Free-for-All Playlists'
[docs]defget_ffa_point_awards(self)->dict[int,int]:"""Return the number of points awarded for different rankings. This is based on the current number of players. """point_awards:dict[int,int]iflen(self.sessionplayers)==1:point_awards={}eliflen(self.sessionplayers)==2:point_awards={0:6}eliflen(self.sessionplayers)==3:point_awards={0:6,1:3}eliflen(self.sessionplayers)==4:point_awards={0:8,1:4,2:2}eliflen(self.sessionplayers)==5:point_awards={0:8,1:4,2:2}eliflen(self.sessionplayers)==6:point_awards={0:8,1:4,2:2}else:point_awards={0:8,1:4,2:2,3:1}returnpoint_awards
def__init__(self)->None:babase.increment_analytics_count('Free-for-all session start')super().__init__()@overridedef_switch_to_score_screen(self,results:bascenev1.GameResults)->None:# pylint: disable=cyclic-importfromefro.utilimportasserttypefrombascenev1lib.activity.multiteamvictoryimport(TeamSeriesVictoryScoreScreenActivity,)frombascenev1lib.activity.freeforallvictoryimport(FreeForAllVictoryScoreScreenActivity,)frombascenev1lib.activity.drawscoreimportDrawScoreScreenActivitywinners=results.winnergroups# If there's multiple players and everyone has the same score,# call it a draw.iflen(self.sessionplayers)>1andlen(winners)<2:self.setactivity(_bascenev1.newactivity(DrawScoreScreenActivity,{'results':results}))else:# Award different point amounts based on number of players.point_awards=self.get_ffa_point_awards()fori,winnerinenumerate(winners):forteaminwinner.teams:points=point_awards[i]ifiinpoint_awardselse0team.customdata['previous_score']=team.customdata['score']team.customdata['score']+=pointsseries_winners=[teamforteaminself.sessionteamsifteam.customdata['score']>=self._ffa_series_length]series_winners.sort(reverse=True,key=lambdat:asserttype(t.customdata['score'],int),)iflen(series_winners)==1or(len(series_winners)>1andseries_winners[0].customdata['score']!=series_winners[1].customdata['score']):self.setactivity(_bascenev1.newactivity(TeamSeriesVictoryScoreScreenActivity,{'winner':series_winners[0]},))else:self.setactivity(_bascenev1.newactivity(FreeForAllVictoryScoreScreenActivity,{'results':results},))