X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=game.js;h=0946568e9bbd8adc5c99d82832261fa1ac254d5d;hb=0149bfd84c21bd3c53e6e0e4d4eee96c50b3f232;hp=b43a75c42a36fd69212b75a29aa9f140ea153d1f;hpb=c381788fa303d9ca392fc4b7b25c4d55344717da;p=lmno-server diff --git a/game.js b/game.js index b43a75c..0946568 100644 --- a/game.js +++ b/game.js @@ -169,6 +169,19 @@ class Game { this.players_by_session[session.id] = player; this.next_player_id++; + /* After adding the player to the list, and if we are already past + * the first move, assign this player to the first team that + * doesn't already have a player aissgned (if any). */ + if (! this.first_move) { + const have_players = Array(this.teams.length).fill(false); + this.players.forEach(p => { + if (p.team.id !== undefined) + have_players[p.team.id] = true; + }); + const first_empty = have_players.findIndex(i => i === false); + this.assign_player_to_team_perhaps(player, this.teams[first_empty]); + } + return player; }