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,
"available_expansions": self.available_expansions,
"is_replay": self.is_replay,
"characters_to_distribute": self.characters_to_distribute,
},
)
G.sio.emit("debug", room=self.name, data=self.debug)
@ -293,14 +294,14 @@ class Game:
return
if player in self.players or len(self.players) >= 10:
return
if len(self.players) > 7:
if "dodge_city" not in self.expansions:
self.expansions.append("dodge_city")
player.join_game(self)
if player.is_admin():
self.feature_flags()
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()
G.sio.emit("chat_message", room=self.name, data=f"_joined|{player.name}")
@ -346,9 +347,10 @@ class Game:
def choose_characters(self):
n = self.characters_to_distribute
char_cards = self.rng.sample(
characters.all_characters(self.expansions), len(self.players) * n
)
all_chars = characters.all_characters(self.expansions)
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):
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:
ses.game.toggle_competitive()
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:
cmd = msg.split()
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",
},
)
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:
ses.lives = 0
ses.notify_self()

View File

@ -220,6 +220,57 @@
style="margin-top: 5px; margin-bottom: 3px"
>{{ $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>
<input
type="button"
@ -411,6 +462,7 @@ export default {
turn: -1,
deadRoleData: null,
cardsToAnimate: [],
characters_to_distribute: 2,
}),
sockets: {
room(data) {
@ -428,6 +480,7 @@ export default {
this.togglable_expansions = data.available_expansions;
this.expansions = data.expansions;
this.is_replay = data.is_replay;
this.characters_to_distribute = data.characters_to_distribute;
this.players = data.players.map((x) => {
return {
name: x.name,
@ -836,6 +889,13 @@ export default {
justify-content: space-evenly;
margin-bottom: 12pt;
}
.small-btn {
min-width: 28pt;
}
.small-btn.active {
color: var(--bg-color);
background: var(--font-color);
}
#admin-status {
position: absolute;
width: 100%;

View File

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

View File

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