@@ -20,6 +20,7 @@ import GameServer from "../Game";
2020import ArenaEntity from "../Native/Arena" ;
2121import Client from "../Client" ;
2222
23+ import ObjectEntity from "../Entity/Object" ;
2324import TeamBase from "../Entity/Misc/TeamBase" ;
2425import TankBody from "../Entity/Tank/TankBody" ;
2526
@@ -37,30 +38,40 @@ export default class Teams2Arena extends ArenaEntity {
3738 static override GAMEMODE_ID : string = "teams" ;
3839
3940 /** Blue Team entity */
40- public blueTeamBase : TeamBase ;
41+ public blueTeamEntity : TeamEntity ;
4142 /** Red Team entity */
42- public redTeamBase : TeamBase ;
43+ public redTeamEntity : TeamEntity ;
4344 /** Maps clients to their teams */
44- public playerTeamMap : WeakMap < Client , TeamBase > = new WeakMap ( ) ;
45+ public playerTeamMap : WeakMap < Client , TeamEntity > = new WeakMap ( ) ;
4546
4647 public constructor ( game : GameServer ) {
4748 super ( game ) ;
4849 this . updateBounds ( arenaSize * 2 , arenaSize * 2 ) ;
49- this . blueTeamBase = new TeamBase ( game , new TeamEntity ( this . game , Color . TeamBlue ) , - arenaSize + baseWidth / 2 , 0 , arenaSize * 2 , baseWidth , true , 12 , 2 ) ;
50- this . redTeamBase = new TeamBase ( game , new TeamEntity ( this . game , Color . TeamRed ) , arenaSize - baseWidth / 2 , 0 , arenaSize * 2 , baseWidth , true , 12 , 2 ) ;
50+
51+ this . blueTeamEntity = new TeamEntity ( this . game , Color . TeamBlue ) ;
52+ this . redTeamEntity = new TeamEntity ( this . game , Color . TeamRed ) ;
53+
54+ new TeamBase ( game , this . blueTeamEntity , - arenaSize + baseWidth / 2 , 0 , arenaSize * 2 , baseWidth , true , 12 , 2 ) ;
55+ new TeamBase ( game , this . redTeamEntity , arenaSize - baseWidth / 2 , 0 , arenaSize * 2 , baseWidth , true , 12 , 2 ) ;
5156 }
5257
53- public spawnPlayer ( tank : TankBody , client : Client ) {
54- tank . positionData . values . y = 2 * arenaSize * Math . random ( ) - arenaSize ;
58+ public decideTeam ( client : Client ) : TeamEntity {
59+ const team = this . playerTeamMap . get ( client ) || randomFrom ( [ this . blueTeamEntity , this . redTeamEntity ] ) ;
60+ this . playerTeamMap . set ( client , team ) ;
5561
56- const xOffset = ( Math . random ( ) - 0.5 ) * baseWidth ;
62+ return team ;
63+ }
64+
65+ public spawnPlayer ( tank : TankBody , client : Client ) {
66+ const team = this . decideTeam ( client ) ;
67+ TeamEntity . setTeam ( team , tank ) ;
5768
58- const base = this . playerTeamMap . get ( client ) || randomFrom ( [ this . blueTeamBase , this . redTeamBase ] ) ;
59- tank . relationsData . values . team = base . relationsData . values . team ;
60- tank . styleData . values . color = base . styleData . values . color ;
61- tank . positionData . values . x = base . positionData . values . x + xOffset ;
62- this . playerTeamMap . set ( client , base ) ;
69+ const success = this . attemptFactorySpawn ( tank ) ;
70+ if ( success ) return ; // This player was spawned from a factory instead
6371
64- if ( client . camera ) client . camera . relationsData . team = tank . relationsData . values . team ;
72+ const base = team . base as TeamBase ;
73+ const pos = ObjectEntity . getRandomPosition ( base ) ;
74+ tank . positionData . x = pos . x ;
75+ tank . positionData . y = pos . y ;
6576 }
6677}
0 commit comments