From a6a5f95a5b56458ef5e7000b7169451cd6010be1 Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sun, 13 Dec 2020 10:31:16 +0100 Subject: [PATCH] gameplay modifiers --- backend/__init__.py | 14 +++++++++++++- backend/bang/game.py | 17 ++++++++++++++++- backend/bang/players.py | 8 ++++---- frontend/src/components/Lobby.vue | 16 ++++++++++++++++ frontend/src/i18n/en.json | 5 ++++- frontend/src/i18n/it.json | 5 ++++- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index c25285c..605b4a3 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -101,6 +101,14 @@ def toggle_expansion(sid, expansion_name): g = sio.get_session(sid).game g.toggle_expansion(expansion_name) +@sio.event +def toggle_comp(sid): + sio.get_session(sid).game.toggle_competitive() + +@sio.event +def toggle_replace_with_bot(sid): + sio.get_session(sid).game.toggle_disconnect_bot() + @sio.event def join_room(sid, room): room_name = room['name'] @@ -130,9 +138,13 @@ def chat_message(sid, msg): 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() - elif '/suicide' in msg and ses.game.started: + elif '/suicide' in msg and ses.game.started and ses.lives > 0: ses.lives = 0 ses.notify_self() + elif '/togglecomp' in msg and ses.game: + ses.game.toggle_competitive() + elif '/togglebot' in msg and ses.game: + ses.game.toggle_disconnect_bot() elif '/cancelgame' in msg and ses.game.started: ses.game.reset() elif '/gameinfo' in msg: diff --git a/backend/bang/game.py b/backend/bang/game.py index af20a9e..b6fc0b1 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -24,6 +24,8 @@ class Game: self.password = '' self.expansions = [] self.shutting_down = False + self.is_competitive = False + self.disconnect_bot = True def notify_room(self): if len([p for p in self.players if p.character == None]) != 0: @@ -32,6 +34,8 @@ class Game: 'started': self.started, 'players': [{'name':p.name, 'ready': p.character != None} for p in self.players], 'password': self.password, + 'is_competitive': self.is_competitive, + 'disconnect_bot': self.disconnect_bot, 'expansions': self.expansions, }) @@ -44,6 +48,14 @@ class Game: self.expansions.append(expansion_name) self.notify_room() + def toggle_competitive(self): + self.is_competitive = not self.is_competitive + self.notify_room() + + def toggle_disconnect_bot(self): + self.disconnect_bot = not self.disconnect_bot + self.notify_room() + def add_player(self, player: players.Player): if player.is_bot and len(self.players) >= 8: return @@ -215,7 +227,10 @@ class Game: def handle_disconnect(self, player: players.Player): print(f'player {player.name} left the game {self.name}') if player in self.players: - self.player_death(player=player, disconnected=True) + if self.disconnect_bot: + player.is_bot = True + else: + self.player_death(player=player, disconnected=True) else: self.dead_players.remove(player) if len([p for p in self.players if not p.is_bot])+len([p for p in self.dead_players if not p.is_bot]) == 0: diff --git a/backend/bang/players.py b/backend/bang/players.py index 382fa69..ad25c59 100644 --- a/backend/bang/players.py +++ b/backend/bang/players.py @@ -474,7 +474,7 @@ class Player: if self.mancato_needed <= 0: self.game.responders_did_respond_resume_turn() return - if len([c for c in self.hand if isinstance(c, cs.Mancato) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Bang)) or isinstance(self.character, chd.ElenaFuente)]) == 0\ + if not self.game.is_competitive and len([c for c in self.hand if isinstance(c, cs.Mancato) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Bang)) or isinstance(self.character, chd.ElenaFuente)]) == 0\ and len([c for c in self.equipment if c.can_be_used_now and isinstance(c, cs.Mancato)]) == 0: self.take_damage_response() self.game.responders_did_respond_resume_turn() @@ -492,7 +492,7 @@ class Player: for i in range(len(self.equipment)): if self.equipment[i].can_be_used_now: print('usable', self.equipment[i]) - if len([c for c in self.equipment if isinstance(c, cs.Barile)]) == 0 and not isinstance(self.character, chars.Jourdonnais)\ + if not self.game.is_competitive and len([c for c in self.equipment if isinstance(c, cs.Barile)]) == 0 and not isinstance(self.character, chars.Jourdonnais)\ and len([c for c in self.hand if isinstance(c, cs.Mancato) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Bang)) or isinstance(self.character, chd.ElenaFuente)]) == 0\ and len([c for c in self.equipment if c.can_be_used_now and isinstance(c, cs.Mancato)]) == 0: print('Cant defend') @@ -514,7 +514,7 @@ class Player: def get_indians(self, attacker): self.attacker = attacker - if len([c for c in self.hand if isinstance(c, cs.Bang) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Mancato))]) == 0: + if not self.game.is_competitive and len([c for c in self.hand if isinstance(c, cs.Bang) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Mancato))]) == 0: print('Cant defend') self.take_damage_response() return False @@ -528,7 +528,7 @@ class Player: def get_dueled(self, attacker): self.attacker = attacker - if len([c for c in self.hand if isinstance(c, cs.Bang) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Mancato))]) == 0: + if not self.game.is_competitive and len([c for c in self.hand if isinstance(c, cs.Bang) or (isinstance(self.character, chars.CalamityJanet) and isinstance(c, cs.Mancato))]) == 0: print('Cant defend') self.take_damage_response() self.game.responders_did_respond_resume_turn() diff --git a/frontend/src/components/Lobby.vue b/frontend/src/components/Lobby.vue index 86ec61b..e5940c6 100644 --- a/frontend/src/components/Lobby.vue +++ b/frontend/src/components/Lobby.vue @@ -31,6 +31,10 @@

{{$t("expansions")}}

Dodge City +

{{$t('mods')}}

+ {{$t('mod_comp')}} +
+ {{$t('disconnect_bot')}}
@@ -85,6 +89,8 @@ export default { password: '', useDodgeCity: false, hasToSetUsername: false, + is_competitive: false, + disconnect_bot: false, }), sockets: { room(data) { @@ -92,6 +98,8 @@ export default { this.started = data.started this.password = data.password this.privateRoom = data.password !== '' + this.is_competitive = data.is_competitive + this.disconnect_bot = data.disconnect_bot this.useDodgeCity = data.expansions.indexOf('dodge_city') !== -1 this.players = data.players.map(x => { return { @@ -161,6 +169,14 @@ export default { if (!this.isRoomOwner) return; this.$socket.emit('toggle_expansion', name) }, + toggleCompetitive() { + if (!this.isRoomOwner) return; + this.$socket.emit('toggle_comp') + }, + toggleReplaceWithBot() { + if (!this.isRoomOwner) return; + this.$socket.emit('toggle_replace_with_bot') + }, getActionEmoji(p) { if (p.is_my_turn === undefined || p.pending_action === undefined) return ''; if (p.pending_action != 4) { diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 4e46638..1a0b619 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -79,5 +79,8 @@ "special_bart_cassidy": "{0} received a compensation because he was injured.", "special_el_gringo": "{0} stole a card from {1} when he was was injured.", "special_calamity": "{0} played {1} as Bang! against {2}." - } + }, + "mods": "Modifiers", + "mod_comp": "Competitive mode (disables automatic take damage)", + "disconnect_bot": "Replace players that disconnect with bots" } \ No newline at end of file diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json index 99dbaae..2361cfe 100644 --- a/frontend/src/i18n/it.json +++ b/frontend/src/i18n/it.json @@ -79,5 +79,8 @@ "special_bart_cassidy": "{0} ha ricevuto un risarcimento perchè è stato ferito.", "special_el_gringo": "{0} rubato una carta a {1} mentre veniva colpito.", "special_calamity": "{0} ha giovato {1} come un Bang! contro {2}." - } + }, + "mods": "Modificatori", + "mod_comp": "Modalità competitiva (disattiva il prendi danno automatico)", + "disconnect_bot": "Sostituisci i giocatori che si disconnettono con bot" } \ No newline at end of file