add option to set characters to distribute

This commit is contained in:
Alberto Xamin 2023-04-09 12:10:06 +01:00
parent 2501b96185
commit bda273849b
No known key found for this signature in database
GPG Key ID: 5ABFCD8A22EA6F5D
5 changed files with 77 additions and 11 deletions

View File

@ -246,6 +246,7 @@ class Game:
"expansions": self.expansions, "expansions": self.expansions,
"available_expansions": self.available_expansions, "available_expansions": self.available_expansions,
"is_replay": self.is_replay, "is_replay": self.is_replay,
"characters_to_distribute": self.characters_to_distribute,
}, },
) )
G.sio.emit("debug", room=self.name, data=self.debug) G.sio.emit("debug", room=self.name, data=self.debug)
@ -293,14 +294,14 @@ class Game:
return return
if player in self.players or len(self.players) >= 10: if player in self.players or len(self.players) >= 10:
return return
if len(self.players) > 7:
if "dodge_city" not in self.expansions:
self.expansions.append("dodge_city")
player.join_game(self) player.join_game(self)
if player.is_admin(): if player.is_admin():
self.feature_flags() self.feature_flags()
self.players.append(player) self.players.append(player)
print(f"{self.name}: Added player {player.name} to game") if len(self.players) > 7:
if "dodge_city" not in self.expansions:
self.expansions.append("dodge_city")
print(f"{self.name}: Added player {player.name} to game; {len(self.players)=}")
self.notify_room() self.notify_room()
G.sio.emit("chat_message", room=self.name, data=f"_joined|{player.name}") G.sio.emit("chat_message", room=self.name, data=f"_joined|{player.name}")
@ -346,9 +347,10 @@ class Game:
def choose_characters(self): def choose_characters(self):
n = self.characters_to_distribute n = self.characters_to_distribute
char_cards = self.rng.sample( all_chars = characters.all_characters(self.expansions)
characters.all_characters(self.expansions), len(self.players) * n if len(all_chars) // len(self.players) < n:
) n = len(all_chars) // len(self.players)
char_cards = self.rng.sample(all_chars, len(self.players) * n)
for i, player in enumerate(self.players): for i, player in enumerate(self.players):
player.set_available_character(char_cards[i * n : i * n + n]) player.set_available_character(char_cards[i * n : i * n + n])

View File

@ -742,6 +742,12 @@ def chat_message(sid, msg, pl=None):
if "/togglecomp" in msg and ses.game: if "/togglecomp" in msg and ses.game:
ses.game.toggle_competitive() ses.game.toggle_competitive()
return return
elif "/set_chars" in msg and not ses.game.started:
cmd = msg.split()
if len(cmd) == 2 and int(cmd[1]) > 0:
ses.game.characters_to_distribute = int(cmd[1])
ses.game.notify_room()
return
if "/debug" in msg: if "/debug" in msg:
cmd = msg.split() cmd = msg.split()
if ( if (
@ -775,10 +781,6 @@ def chat_message(sid, msg, pl=None):
"text": "debug mode is not active, only the owner of the room can enable it with /debug", "text": "debug mode is not active, only the owner of the room can enable it with /debug",
}, },
) )
elif "/set_chars" in msg and not ses.game.started:
cmd = msg.split()
if len(cmd) == 2 and int(cmd[1]) > 0:
ses.game.characters_to_distribute = int(cmd[1])
elif "/suicide" in msg and ses.game.started and ses.lives > 0: elif "/suicide" in msg and ses.game.started and ses.lives > 0:
ses.lives = 0 ses.lives = 0
ses.notify_self() ses.notify_self()

View File

@ -220,6 +220,57 @@
style="margin-top: 5px; margin-bottom: 3px" style="margin-top: 5px; margin-bottom: 3px"
>{{ $t("mod_comp") }}</PrettyCheck >{{ $t("mod_comp") }}</PrettyCheck
> >
<br/>
<br/>
<span>{{$t("characters_to_distribute")}}</span>
<input
type="button"
:class="{btn:true, 'small-btn':true, active: characters_to_distribute === 1}"
:value="1"
:disabled="!isRoomOwner"
@click="
(e) => {
this.$socket.emit('chat_message', '/set_chars 1');
e.preventDefault();
}
"
/>
<input
type="button"
:class="{btn:true, 'small-btn':true, active: characters_to_distribute === 2}"
:value="2"
:disabled="!isRoomOwner"
@click="
(e) => {
this.$socket.emit('chat_message', '/set_chars 2');
e.preventDefault();
}
"
/>
<input
type="button"
:class="{btn:true, 'small-btn':true, active: characters_to_distribute === 3}"
:value="3"
:disabled="!isRoomOwner"
@click="
(e) => {
this.$socket.emit('chat_message', '/set_chars 3');
e.preventDefault();
}
"
/>
<input
type="button"
:class="{btn:true, 'small-btn':true, active: characters_to_distribute === 4}"
:value="4"
:disabled="!isRoomOwner"
@click="
(e) => {
this.$socket.emit('chat_message', '/set_chars 4');
e.preventDefault();
}
"
/>
<h3>{{ $t("bots") }}</h3> <h3>{{ $t("bots") }}</h3>
<input <input
type="button" type="button"
@ -411,6 +462,7 @@ export default {
turn: -1, turn: -1,
deadRoleData: null, deadRoleData: null,
cardsToAnimate: [], cardsToAnimate: [],
characters_to_distribute: 2,
}), }),
sockets: { sockets: {
room(data) { room(data) {
@ -428,6 +480,7 @@ export default {
this.togglable_expansions = data.available_expansions; this.togglable_expansions = data.available_expansions;
this.expansions = data.expansions; this.expansions = data.expansions;
this.is_replay = data.is_replay; this.is_replay = data.is_replay;
this.characters_to_distribute = data.characters_to_distribute;
this.players = data.players.map((x) => { this.players = data.players.map((x) => {
return { return {
name: x.name, name: x.name,
@ -836,6 +889,13 @@ export default {
justify-content: space-evenly; justify-content: space-evenly;
margin-bottom: 12pt; margin-bottom: 12pt;
} }
.small-btn {
min-width: 28pt;
}
.small-btn.active {
color: var(--bg-color);
background: var(--font-color);
}
#admin-status { #admin-status {
position: absolute; position: absolute;
width: 100%; width: 100%;

View File

@ -19,6 +19,7 @@
"spectate_lobbies": "Spectate ongoing games:", "spectate_lobbies": "Spectate ongoing games:",
"no_lobby_available": "No lobbies available", "no_lobby_available": "No lobbies available",
"create_lobby": "Open a lobby:", "create_lobby": "Open a lobby:",
"characters_to_distribute": "Characters to distribute: ",
"lobby_name": "Name:", "lobby_name": "Name:",
"leave_room": "Leave lobby", "leave_room": "Leave lobby",
"warning": "Warning!", "warning": "Warning!",

View File

@ -19,6 +19,7 @@
"spectate_lobbies": "Osserva le partite in corso:", "spectate_lobbies": "Osserva le partite in corso:",
"no_lobby_available": "Nessuna stanza disponibile", "no_lobby_available": "Nessuna stanza disponibile",
"create_lobby": "Crea una stanza:", "create_lobby": "Crea una stanza:",
"characters_to_distribute": "Personaggi da distribuire: ",
"lobby_name": "Nome:", "lobby_name": "Nome:",
"leave_room": "Esci dalla stanza", "leave_room": "Esci dalla stanza",
"warning": "Attenzione!", "warning": "Attenzione!",