From 7a6d8b31d6107b718fb157bf50f4eb5102666dee Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sat, 22 May 2021 17:59:30 +0200 Subject: [PATCH] add debug mode --- backend/__init__.py | 38 ++++++++++++++++++++++--------- backend/bang/game.py | 9 +++++--- backend/bang/players.py | 9 ++++++-- frontend/src/components/Lobby.vue | 5 ++++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 89b1690..f3660bc 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -201,9 +201,31 @@ def chat_message(sid, msg): bot = Player(f'AI_{random.randint(0,10)}', 'bot', sio, bot=True) ses.game.add_player(bot) bot.bot_spin() + return elif '/removebot' in msg and not ses.game.started: if any([p.is_bot for p in ses.game.players]): [p for p in ses.game.players if p.is_bot][-1].disconnect() + return + elif '/togglecomp' in msg and ses.game: + ses.game.toggle_competitive() + return + if '/debug' in msg: + cmd = msg.split() + if len(cmd) == 2 and 'DEPLOY_KEY' in os.environ and cmd[1] == os.environ['DEPLOY_KEY']: # solo chi ha la deploy key può attivare la modalità debug + ses.game.debug = not ses.game.debug + ses.game.notify_room() + elif ses == ses.game.players[0]: # solo l'owner può attivare la modalità debug + ses.game.debug = not ses.game.debug + ses.game.notify_room() + if ses.game.debug: + sio.emit('chat_message', room=sid, data={'color': f'red','text':f'debug mode is now active, only the owner of the room can disable it with /debug'}) + return + if not ses.game.debug: + sio.emit('chat_message', room=sid, data={'color': f'','text':f'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() @@ -221,7 +243,7 @@ def chat_message(sid, msg): }) else: sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} bad format'}) - elif '/debug_show_cards' in msg and ses.game.started: + elif '/show_cards' in msg and ses.game.started: cmd = msg.split() if len(cmd) == 2: if cmd[1] in ses.game.players_map: @@ -231,8 +253,8 @@ def chat_message(sid, msg): eventlet.sleep(0.3) else: sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} bad format'}) - elif '/ddc' in msg and ses.game.started: #/ddc * - cmd = msg.split() + elif '/ddc' in msg and ses.game.started: # debug destroy cards usage: [/ddc *] [/ddc username] + cmd = msg.split() if len(cmd) == 2: sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'🚨 {ses.name} is in debug mode destroyed {cmd[1]} cards'}) if cmd[1] == "*": @@ -246,7 +268,7 @@ def chat_message(sid, msg): ses.game.get_player_named(cmd[1]).notify_self() else: sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} bad format'}) - elif '/dsh' in msg and ses.game.started: #/dsh * 1 + elif '/dsh' in msg and ses.game.started: #debug set health usage [/dsh * hp] [/dsh username hp] cmd = msg.split() if len(cmd) == 3: sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'🚨 {ses.name} is in debug mode and is changing {cmd[1]} health'}) @@ -259,17 +281,11 @@ def chat_message(sid, msg): ses.game.get_player_named(cmd[1]).notify_self() else: sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} bad format'}) - elif '/togglecomp' in msg and ses.game: - ses.game.toggle_competitive() elif '/togglebot' in msg and ses.game: ses.game.toggle_disconnect_bot() - elif '/cancelgamesudo' in msg and ses.game.started: + elif '/cancelgame' in msg and ses.game.started: sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'🚨 {ses.name} stopped the current game'}) ses.game.reset() - elif '/cancelgame' in msg and ses.game.started: - if (ses == ses.game.players[0]): - sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'🚨 {ses.name} stopped the current game'}) - ses.game.reset() elif '/startgame' in msg and not ses.game.started: ses.game.start_game() elif '/setbotspeed' in msg: diff --git a/backend/bang/game.py b/backend/bang/game.py index b5dbbcf..6d91f2d 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -41,7 +41,8 @@ class Game: self.pending_winners = [] self.someone_won = False self.attack_in_progress = False - + self.characters_to_distribute = 2 # personaggi da dare a inizio partita + self.debug = False def notify_room(self, sid=None): if len([p for p in self.players if p.character == None]) != 0 or sid: @@ -50,6 +51,7 @@ class Game: 'started': self.started, 'players': [{'name':p.name, 'ready': p.character != None, 'is_bot': p.is_bot} for p in self.players], 'password': self.password, + 'debug': self.debug, 'is_competitive': self.is_competitive, 'disconnect_bot': self.disconnect_bot, 'expansions': self.expansions, @@ -118,9 +120,10 @@ class Game: self.play_turn() def choose_characters(self): - char_cards = random.sample(characters.all_characters(self.expansions), len(self.players)*2) + n = self.characters_to_distribute + char_cards = random.sample(characters.all_characters(self.expansions), len(self.players)*n) for i in range(len(self.players)): - self.players[i].set_available_character(char_cards[i * 2 : i * 2 + 2]) + self.players[i].set_available_character(char_cards[i * n : i * n + n]) def start_game(self): print('GAME IS STARING') diff --git a/backend/bang/players.py b/backend/bang/players.py index 73838be..3fe6b0e 100644 --- a/backend/bang/players.py +++ b/backend/bang/players.py @@ -90,6 +90,7 @@ class Player: self.target_p: str = None self.is_drawing = False self.special_use_count = 0 + self.not_chosen_character = None try: del self.win_status except: @@ -116,8 +117,12 @@ class Player: def set_character(self, character: str): print(self.available_characters, character) if self.character == None: - self.character = next( - x for x in self.available_characters if x.name == character) + self.character = next(x for x in self.available_characters if x.name == character) + if 'high_noon' in self.game.expansions: + # questo viene utilizzato per la carta nuova identità + self.not_chosen_character = next(x for x in self.available_characters if x.name != character) + else: + self.not_chosen_character = None self.real_character = self.character self.available_characters = [] print(f'{self.name}: I chose character {self.character.name}') diff --git a/frontend/src/components/Lobby.vue b/frontend/src/components/Lobby.vue index efd014f..5806dfd 100644 --- a/frontend/src/components/Lobby.vue +++ b/frontend/src/components/Lobby.vue @@ -6,6 +6,9 @@

{{$t('room_players', {username:username})}}

+
+

DEBUG ON

+
{{$t("private_room")}} @@ -114,6 +117,7 @@ export default { hasToSetUsername: false, is_competitive: false, disconnect_bot: false, + debug: false, }), sockets: { room(data) { @@ -130,6 +134,7 @@ export default { this.disconnect_bot = data.disconnect_bot this.togglable_expansions = data.available_expansions this.expansions = data.expansions + this.debug = data.debug this.players = data.players.map(x => { return { name: x.name,