@@ -48,7 +48,8 @@ const ENABLE_DOMINATOR = false;
4848 */
4949export class TagShapeManager extends ShapeManager {
5050 protected get wantedShapes ( ) {
51- const ratio = Math . ceil ( Math . pow ( this . game . arena . width / 2500 , 2 ) ) ;
51+ const size = ( this . game . arena . width + this . game . arena . height ) / 2 ;
52+ const ratio = Math . ceil ( Math . pow ( size / 2500 , 2 ) ) ;
5253
5354 return Math . floor ( 12.5 * ratio ) ;
5455 }
@@ -61,9 +62,12 @@ export default class TagArena extends ArenaEntity {
6162 static override GAMEMODE_ID : string = "tag" ;
6263
6364 protected shapes : ShapeManager = new TagShapeManager ( this ) ;
64-
65+
6566 /** All team entities in game */
6667 public teams : TeamEntity [ ] = [ ] ;
68+
69+ /** Maps teams to their total score. */
70+ public teamScoreMap : Map < TeamEntity , number > = new Map ( ) ;
6771
6872 /** Maps clients to their team */
6973 public playerTeamMap : WeakMap < Client , TeamEntity > = new WeakMap ( ) ;
@@ -75,6 +79,7 @@ export default class TagArena extends ArenaEntity {
7579 this . arenaData . values . flags |= ArenaFlags . hiddenScores ;
7680 const teamOrder = TEAM_COLORS . slice ( ) ;
7781 shuffleArray ( teamOrder ) ;
82+
7883 for ( const teamColor of teamOrder ) {
7984 const team = new TeamEntity ( this . game , teamColor ) ;
8085 this . teams . push ( team ) ;
@@ -115,6 +120,8 @@ export default class TagArena extends ArenaEntity {
115120 const team = this . decideTeam ( client ) ;
116121 TeamEntity . setTeam ( team , tank ) ;
117122
123+ this . updateTeamScores ( ) ; // update team counts
124+
118125 const success = this . attemptFactorySpawn ( tank ) ;
119126 if ( success ) return ; // This player was spawned from a factory instead
120127
@@ -128,9 +135,9 @@ export default class TagArena extends ArenaEntity {
128135 const length = Math . min ( 10 , this . teams . length ) ;
129136 for ( let i = 0 ; i < length ; ++ i ) {
130137 const team = this . teams [ i ] ;
131- const playerCount = this . getTeamPlayers ( team ) . length ;
132- if ( team . teamData . values . teamColor === Color . Tank ) this . arenaData . values . scoreboardColors [ i as ValidScoreboardIndex ] = Color . ScoreboardBar ;
133- else this . arenaData . values . scoreboardColors [ i as ValidScoreboardIndex ] = team . teamData . values . teamColor ;
138+ const playerCount = this . getTeamScore ( team ) ;
139+
140+ this . arenaData . values . scoreboardColors [ i as ValidScoreboardIndex ] = team . teamData . values . teamColor ;
134141 this . arenaData . values . scoreboardNames [ i as ValidScoreboardIndex ] = team . teamName ;
135142 this . arenaData . values . scoreboardTanks [ i as ValidScoreboardIndex ] = - 1 ;
136143 this . arenaData . values . scoreboardScores [ i as ValidScoreboardIndex ] = playerCount ;
@@ -139,24 +146,38 @@ export default class TagArena extends ArenaEntity {
139146
140147 this . arenaData . scoreboardAmount = Math . min ( 10 , length ) ;
141148 }
149+
150+ public getTeamScore ( team : TeamEntity ) : number {
151+ return this . teamScoreMap . get ( team ) || 0 ;
152+ }
153+
154+ public updateTeamScores ( ) {
155+ for ( let i = 0 ; i < this . teams . length ; ++ i ) {
156+ const team = this . teams [ i ] ;
157+
158+ this . teamScoreMap . set ( team , this . getTeamPlayers ( team ) . length ) ;
159+ }
160+ this . teams . sort ( ( t1 , t2 ) => this . getTeamScore ( t2 ) - this . getTeamScore ( t1 ) ) ;
161+ }
142162
143163 public updateArenaState ( ) {
144- this . teams . sort ( ( t1 , t2 ) => this . getTeamPlayers ( t2 ) . length - this . getTeamPlayers ( t1 ) . length ) ;
164+ this . updateTeamScores ( ) ;
165+
145166 const length = Math . min ( 10 , this . teams . length ) ;
146167 const arenaPlayerCount = this . getAlivePlayers ( ) . length ; // Only count alive players for win condition
147- const leaderTeam = this . teams [ 0 ] ; // Most players are in this team
168+ const leaderTeam = this . teams [ 0 ] ; // Most players are on this team
169+
148170 for ( let i = 0 ; i < length ; ++ i ) {
149171 const team = this . teams [ i ] ;
150172
151173 if ( this . getTeamPlayers ( leaderTeam ) . length === arenaPlayerCount && arenaPlayerCount >= MIN_PLAYERS ) { // If all alive players are in the leading team, it has won since all other team's players have died
152174 if ( this . state === ArenaState . OPEN ) {
153- this . game . broadcast ( )
154- . u8 ( ClientBound . Notification )
155- . stringNT ( `${ leaderTeam . teamName } HAS WON THE GAME!` )
156- . u32 ( ColorsHexCode [ leaderTeam . teamData . values . teamColor ] )
157- . float ( - 1 )
158- . stringNT ( "" ) . send ( ) ;
159-
175+ this . game . broadcastMessage (
176+ `${ leaderTeam . teamName } HAS WON THE GAME!` ,
177+ ColorsHexCode [ leaderTeam . teamData . values . teamColor ] ,
178+ - 1
179+ )
180+
160181 this . state = ArenaState . OVER ;
161182 setTimeout ( ( ) => {
162183 this . close ( ) ;
@@ -178,8 +199,12 @@ export default class TagArena extends ArenaEntity {
178199 if ( ( this . game . tick % scoreboardUpdateInterval ) === 0 ) {
179200 this . updateScoreboard ( ) ;
180201 }
202+ }
203+
204+ public tick ( tick : number ) {
205+ super . tick ( tick ) ;
181206
182- if ( ( this . game . tick % SHRINK_INTERVAL ) === 0 && this . width > MIN_SIZE ) {
207+ if ( ( tick % SHRINK_INTERVAL ) === 0 && this . width > MIN_SIZE ) {
183208 this . updateBounds ( this . width - SHRINK_AMOUNT , this . height - SHRINK_AMOUNT ) ;
184209 }
185210 }
0 commit comments