fix death and room still playing with bots

This commit is contained in:
Alberto Xamin 2020-12-06 15:40:28 +01:00
parent 66c99574c9
commit 153a5177e1
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
3 changed files with 19 additions and 4 deletions

View File

@ -130,7 +130,8 @@ def chat_message(sid, msg):
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:
ses.game.player_death(player=ses)
ses.lives = 0
ses.notify_self()
@sio.event
def start_game(sid):

View File

@ -23,6 +23,7 @@ class Game:
self.initial_players = 0
self.password = ''
self.expansions = []
self.shutting_down = False
def notify_room(self):
if len([p for p in self.players if p.character == None]) != 0:
@ -197,6 +198,7 @@ class Game:
self.players[self.turn].play_turn()
def next_turn(self):
if self.shutting_down: return
if len(self.players) > 0:
self.turn = (self.turn + 1) % len(self.players)
self.play_turn()
@ -210,9 +212,16 @@ class Game:
def handle_disconnect(self, player: players.Player):
print(f'player {player.name} left the game {self.name}')
self.player_death(player=player, disconnected=True)
if len([p for p in self.players if not p.is_bot]) == 0:
if player in self.players:
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:
print(f'no players left in game {self.name}')
self.shutting_down = True
self.players = []
self.dead_players = []
self.deck = None
return True
else: return False

View File

@ -155,6 +155,10 @@ class Player:
randrange(0, len(self.hand))))
if self.lives <= 0 and self.max_lives > 0:
self.pending_action = PendingAction.WAIT
ser['hand'] = []
ser['equipment'] = []
self.sio.emit('self', room=self.sid, data=json.dumps(
ser, default=lambda o: o.__dict__))
self.game.player_death(self)
elif not self.is_bot:
self.sio.emit('self_vis', room=self.sid, data=json.dumps(
@ -169,6 +173,7 @@ class Player:
self.game.notify_all()
def bot_logic(self):
if self.game.shutting_down: return
if self.pending_action != PendingAction.WAIT:
eventlet.sleep(uniform(0.6, 1.5))
else:
@ -218,7 +223,7 @@ class Player:
if not c.need_target:
self.play_card(len(self.hand)+i)
else:
_range = self.get_sight() if c.name == "Pepperbox" else self.hand[i].range
_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'])]
if len(others) == 0:
continue