add player shuffling

This commit is contained in:
Alberto Xamin 2023-01-09 15:31:56 +00:00
parent c13b79c38b
commit 02311e7cec
5 changed files with 31 additions and 2 deletions

View File

@ -80,6 +80,11 @@ class Game:
self.rpc_log = [] self.rpc_log = []
self.is_replay = False self.is_replay = False
def shuffle_players(self):
if not self.started:
random.shuffle(self.players)
self.notify_room()
def reset(self): def reset(self):
for p in self.players: for p in self.players:
if (p.sid == p.name): if (p.sid == p.name):

View File

@ -330,6 +330,12 @@ def start_game(sid):
ses.game.start_game() ses.game.start_game()
advertise_lobbies() advertise_lobbies()
@sio.event
@bang_handler
def shuffle_players(sid):
ses: Player = sio.get_session(sid)
ses.game.shuffle_players()
@sio.event @sio.event
@bang_handler @bang_handler
def set_character(sid, name): def set_character(sid, name):

View File

@ -70,6 +70,7 @@
<span>🤖</span> <span>🤖</span>
</div> </div>
</div> </div>
<Card v-if="startGameCard" key="_shuffle_players_" :donotlocalize="true" :card="shufflePlayersCard" @click.native="shufflePlayers" class="fistful-of-cards"/>
</transition-group> </transition-group>
</div> </div>
<div v-if="started"> <div v-if="started">
@ -240,7 +241,7 @@ export default {
return '' return ''
}, },
isRoomOwner() { isRoomOwner() {
return this.players.length > 0 && this.players[0].name == this.username return this.players.length > 0 && this.players.filter(x => !x.is_bot)[0].name == this.username
}, },
startGameCard() { startGameCard() {
if (!this.started && this.players.length > 2 && this.isRoomOwner) { if (!this.started && this.players.length > 2 && this.isRoomOwner) {
@ -253,6 +254,16 @@ export default {
} }
return null; return null;
}, },
shufflePlayersCard() {
if (!this.started && this.players.length > 2 && this.isRoomOwner) {
return {
name: this.$t('shuffle_players'),
icon: '🔀',
is_equipment: true,
}
}
return null;
},
playersTable() { playersTable() {
if (Vue.config.devtools) if (Vue.config.devtools)
console.log('update players') console.log('update players')
@ -302,11 +313,12 @@ export default {
}, },
getPlayerCard(player) { getPlayerCard(player) {
let icon = '' let icon = ''
let owner = this.players.filter(x => !x.is_bot)[0];
if (!this.started) icon = '🤠' if (!this.started) icon = '🤠'
else icon = player.ready !== undefined ? ((player.ready)?'👍': '🤔') : (player.is_sheriff ? '⭐' : player.icon) else icon = player.ready !== undefined ? ((player.ready)?'👍': '🤔') : (player.is_sheriff ? '⭐' : player.icon)
return { return {
name: player.name, name: player.name,
number: ((this.username == player.name) ? this.$t('you') : (this.players[0].name == player.name) ? this.$t('owner') :'') + (player.dist ? `${player.dist}` : ''), number: ((this.username == player.name) ? this.$t('you') : (owner.name == player.name) ? this.$t('owner') :'') + (player.dist ? `${player.dist}` : ''),
icon: icon, icon: icon,
is_character: true, is_character: true,
avatar: player.avatar, avatar: player.avatar,
@ -316,6 +328,10 @@ export default {
this.started = true; this.started = true;
this.$socket.emit('start_game') this.$socket.emit('start_game')
}, },
shufflePlayers() {
this.started = true;
this.$socket.emit('shuffle_players')
},
choose(player_name) { choose(player_name) {
if (Vue.config.devtools) if (Vue.config.devtools)
console.log('choose from' + player_name) console.log('choose from' + player_name)

View File

@ -9,6 +9,7 @@
"tip_7": "If you want to help us translate the game in your language, ping us on discord!", "tip_7": "If you want to help us translate the game in your language, ping us on discord!",
"tip_8": "If you disconnect during in an ongoing game you will be replaced by a bot (while you are gone)!", "tip_8": "If you disconnect during in an ongoing game you will be replaced by a bot (while you are gone)!",
"online_players": "Online players: ", "online_players": "Online players: ",
"shuffle_players": "Shuffle Players",
"choose_username": "Pick an username:", "choose_username": "Pick an username:",
"report_bug": "Write what the bug consists of", "report_bug": "Write what the bug consists of",
"report": "Report a bug", "report": "Report a bug",

View File

@ -9,6 +9,7 @@
"tip_7": "Se vuoi aiutarci a tradurre il gioco nella tua lingua scrivicelo su discord!", "tip_7": "Se vuoi aiutarci a tradurre il gioco nella tua lingua scrivicelo su discord!",
"tip_8": "Se ti disconnetti durante una partita verrai sostituito da un bot (durante la tua assenza)!", "tip_8": "Se ti disconnetti durante una partita verrai sostituito da un bot (durante la tua assenza)!",
"online_players": "Giocatori online: ", "online_players": "Giocatori online: ",
"shuffle_players": "Riordina Giocatori",
"choose_username": "Scegli un username:", "choose_username": "Scegli un username:",
"report_bug":"Scrivi in cosa consiste il bug", "report_bug":"Scrivi in cosa consiste il bug",
"report":"Segnala un bug", "report":"Segnala un bug",