From 83359eb49761274217acb267193c9b30e50377cc Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Tue, 22 Dec 2020 14:40:55 +0100 Subject: [PATCH] fix stuff --- backend/__init__.py | 8 +++++++- backend/bang/cards.py | 1 + backend/bang/game.py | 2 +- backend/bang/players.py | 37 ++++++++++++++++++++----------------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 45fee6f..b49947d 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -232,7 +232,10 @@ def chat_message(sid, msg): sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'🚨 {ses.name} is in debug mode and removed a card'}) cmd = msg.split() if len(cmd) == 2: - ses.hand.pop(int(cmd[1])) + if len(ses.hand) > int(cmd[1]): + ses.hand.pop(int(cmd[1])) + else: + ses.hand.pop(int(cmd[1])-len(ses.hand)) ses.notify_self() elif '/getcard' in msg: sio.emit('chat_message', room=ses.game.name, data={'color': f'red','text':f'🚨 {ses.name} is in debug mode and got a card'}) @@ -246,6 +249,9 @@ def chat_message(sid, msg): sio.emit('chat_message', room=sid, data={'color': f'','text':f'info: {ses.game.__dict__}'}) elif '/meinfo' in msg: sio.emit('chat_message', room=sid, data={'color': f'','text':f'info: {ses.__dict__}'}) + elif '/mebot' in msg: + ses.is_bot = not ses.is_bot + ses.notify_self() else: sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} COMMAND NOT FOUND'}) else: diff --git a/backend/bang/cards.py b/backend/bang/cards.py index b1553fd..20816d4 100644 --- a/backend/bang/cards.py +++ b/backend/bang/cards.py @@ -122,6 +122,7 @@ class Prigione(Card): data=f'_play_card_against|{player.name}|{self.name}|{against}') player.game.get_player_named(against).equipment.append(self) player.game.get_player_named(against).notify_self() + return True return False class Remington(Card): diff --git a/backend/bang/game.py b/backend/bang/game.py index 142d290..ccba5a6 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -187,7 +187,7 @@ class Game: self.get_player_named(target_username).notify_self() def emporio(self): - self.available_cards = [self.deck.draw(True) for i in range(len(self.players))] + self.available_cards = [self.deck.draw(True) for i in range(len([p for p in self.players if p.lives > 0]))] self.players[self.turn].pending_action = pl.PendingAction.CHOOSE self.players[self.turn].available_cards = self.available_cards self.players[self.turn].notify_self() diff --git a/backend/bang/players.py b/backend/bang/players.py index 00533f2..863c4c6 100644 --- a/backend/bang/players.py +++ b/backend/bang/players.py @@ -223,37 +223,35 @@ class Player: elif self.pending_action == PendingAction.DRAW: self.draw('') elif self.pending_action == PendingAction.PLAY: - has_played = False - if len([c for c in self.hand if (c.is_equipment or c.usable_next_turn) and not self.game.check_event(ce.IlGiudice)]) > 0: - for i in range(len(self.hand)): - if self.hand[i].is_equipment or self.hand[i].usable_next_turn: - self.play_card(i) - has_played = True - break + equippables = [c for c in self.hand if (c.is_equipment or c.usable_next_turn) and not isinstance(c, cs.Prigione) and not self.game.check_event(ce.IlGiudice) and not any([type(c) == type(x) for x in self.equipment])] + if len(equippables) > 0: + for c in equippables: + if self.play_card(self.hand.index(c)): + return elif any([isinstance(c, cs.WellsFargo) or isinstance(c, cs.Diligenza) or isinstance(c, cs.Emporio) or isinstance(c, cs.Birra) for c in self.hand]): for i in range(len(self.hand)): c = self.hand[i] if isinstance(c, cs.WellsFargo) or isinstance(c, cs.Diligenza) or isinstance(c, cs.Emporio) or (isinstance(c, cs.Birra) and self.lives < self.max_lives): - self.play_card(i) - has_played = True - break + if self.play_card(i): + return elif len([c for c in self.hand if c.need_target and c.can_be_used_now and not (c.is_equipment and self.game.check_event(ce.IlGiudice)) and not (self.has_played_bang and not (any([isinstance(c, cs.Volcanic) for c in self.equipment]) and not self.game.check_event(ce.Lazo)))]) > 0: for i in range(len(self.hand)): if self.hand[i].need_target and not (self.has_played_bang and not any([isinstance(c, cs.Volcanic) for c in self.equipment])): if self.hand[i].need_with and len(self.hand) < 2: continue _range = self.get_sight() if self.hand[i].name == 'Bang!' or self.hand[i].name == "Pepperbox" else self.hand[i].range - others = [p for p in self.game.get_visible_players(self) if _range >= p['dist'] and not (isinstance(self.role, r.Vice) and p['is_sheriff'])] + others = [p for p in self.game.get_visible_players(self) if _range >= p['dist'] and not (isinstance(self.role, r.Vice) and p['is_sheriff']) and p['lives'] > 0] if len(others) == 0: continue target = others[randrange(0, len(others))] if target['is_sheriff'] and isinstance(self.role, r.Renegade): target = others[randrange(0, len(others))] if not self.hand[i].need_with: - self.play_card(i, against=target['name']) + if self.play_card(i, against=target['name']): + return else: - self.play_card(i, against=target['name'], _with=sample([j for j in range(len(self.hand)) if j != i], 1)[0]) - has_played = True + if self.play_card(i, against=target['name'], _with=sample([j for j in range(len(self.hand)) if j != i], 1)[0]): + return break elif any([not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now for c in self.equipment if not self.game.check_event(ce.Lazo)]): print('hmm', [not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now for c in self.equipment]) @@ -261,7 +259,8 @@ class Player: c = self.equipment[i] if not isinstance(c, cs.Mancato) and c.usable_next_turn and c.can_be_used_now: if not c.need_target: - self.play_card(len(self.hand)+i) + if self.play_card(len(self.hand)+i): + return else: _range = self.get_sight() if c.name == "Pepperbox" else c.range others = [p for p in self.game.get_visible_players(self) if _range >= p['dist'] and not (isinstance(self.role, r.Vice) and p['is_sheriff'])] @@ -270,8 +269,8 @@ class Player: target = others[randrange(0, len(others))] if target['is_sheriff'] and isinstance(self.role, r.Renegade): target = others[randrange(0, len(others))] - self.play_card(len(self.hand)+i, against=target['name']) - has_played = True + if self.play_card(len(self.hand)+i, against=target['name']): + return break maxcards = self.lives if not isinstance(self.character, chd.SeanMallory) else 10 if len(self.hand) > maxcards: @@ -507,8 +506,12 @@ class Player: elif card.is_equipment or (card.usable_next_turn and not card.can_be_used_now): if not did_play_card: self.hand.insert(hand_index, card) + else: + did_play_card = True print("did play card:", did_play_card) self.notify_self() + if self.is_bot: + return did_play_card or card.is_equipment or (card.usable_next_turn and not card.can_be_used_now) def choose(self, card_index): if self.pending_action != PendingAction.CHOOSE: