update dead man

This commit is contained in:
Alberto Xamin 2020-12-24 11:01:59 +01:00
parent d0595b9cf5
commit 3394b10896
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
2 changed files with 33 additions and 15 deletions

View File

@ -34,6 +34,8 @@ class Game:
self.is_russian_roulette_on = False self.is_russian_roulette_on = False
self.dalton_on = False self.dalton_on = False
self.bot_speed = 1.5 self.bot_speed = 1.5
self.incremental_turn = 0
self.did_resuscitate_deadman = False
def notify_room(self, sid=None): def notify_room(self, sid=None):
if len([p for p in self.players if p.character == None]) != 0 or sid: if len([p for p in self.players if p.character == None]) != 0 or sid:
@ -266,18 +268,23 @@ class Game:
return pls[(pls.index(self.players[self.turn]) + 1) % len(pls)] return pls[(pls.index(self.players[self.turn]) + 1) % len(pls)]
def play_turn(self): def play_turn(self):
if self.players[self.turn].lives <= 0: self.incremental_turn += 1
return self.next_turn() if self.players[self.turn].lives <= 0 or self.players[self.turn].is_dead:
if self.check_event(ce.DeadMan) and not self.did_resuscitate_deadman and len(self.get_dead_players()) > 0:
self.did_resuscitate_deadman = True
pl = sorted(self.get_dead_players(), key=lambda x:x.death_turn)[0]
pl.is_dead = False
pl.lives = 2
pl.hand.append(self.deck.draw())
pl.hand.append(self.deck.draw())
pl.notify_self()
else:
return self.next_turn()
self.player_bangs = 0 self.player_bangs = 0
if isinstance(self.players[self.turn].role, roles.Sheriff): if isinstance(self.players[self.turn].role, roles.Sheriff):
self.deck.flip_event() self.deck.flip_event()
if self.check_event(ce.DeadMan) and len(self.dead_players) > 0: if self.check_event(ce.DeadMan):
self.players.append(self.dead_players.pop(0)) self.did_resuscitate_deadman = False
self.players[-1].lives = 2
self.players[-1].hand.append(self.deck.draw())
self.players[-1].hand.append(self.deck.draw())
self.players_map = {c.name: i for i, c in enumerate(self.players)}
self.players[-1].notify_self()
elif self.check_event(ce.RouletteRussa): elif self.check_event(ce.RouletteRussa):
self.is_russian_roulette_on = True self.is_russian_roulette_on = True
if self.players[self.turn].get_banged(self.deck.event_cards[0]): if self.players[self.turn].get_banged(self.deck.event_cards[0]):
@ -317,11 +324,12 @@ class Game:
def next_turn(self): def next_turn(self):
if self.shutting_down: return if self.shutting_down: return
pls = self.get_alive_players() pls = self.get_alive_players()
print(self.turn)
if len(pls) > 0: if len(pls) > 0:
if self.check_event(ceh.CorsaAllOro): if self.check_event(ceh.CorsaAllOro):
self.turn = (pls.index(self.players[self.turn]) - 1) % len(pls) self.turn = (self.turn - 1) % len(self.players)
else: else:
self.turn = (pls.index(self.players[self.turn]) + 1) % len(pls) self.turn = (self.turn + 1) % len(self.players)
self.play_turn() self.play_turn()
def notify_event_card(self): def notify_event_card(self):
@ -384,11 +392,13 @@ class Game:
# if self.started and index <= self.turn: # if self.started and index <= self.turn:
# self.turn -= 1 # self.turn -= 1
player.lives = 0 player.lives = 0
player.is_dead = True
player.death_turn = self.incremental_turn
# corpse = self.players.pop(index) # corpse = self.players.pop(index)
corpse = player corpse = player
if not disconnected: # if not disconnected:
self.dead_players.append(corpse) # self.dead_players.append(corpse)
self.notify_room() self.notify_room()
self.sio.emit('chat_message', room=self.name, data=f'_died|{player.name}') self.sio.emit('chat_message', room=self.name, data=f'_died|{player.name}')
if self.started: if self.started:
@ -458,6 +468,7 @@ class Game:
print(self.players) print(self.players)
self.started = False self.started = False
self.waiting_for = 0 self.waiting_for = 0
self.incremental_turn = 0
for p in self.players: for p in self.players:
p.reset() p.reset()
p.notify_self() p.notify_self()
@ -484,7 +495,10 @@ class Game:
} for j in range(len(pls)) if i != j] } for j in range(len(pls)) if i != j]
def get_alive_players(self): def get_alive_players(self):
return [p for p in self.players if p.lives > 0] return [p for p in self.players if not p.is_dead]
def get_dead_players(self):
return [p for p in self.players if p.is_dead]
def notify_all(self): def notify_all(self):
if self.started: if self.started:

View File

@ -61,6 +61,8 @@ class Player:
self.is_bot = bot self.is_bot = bot
self.bang_used = 0 self.bang_used = 0
self.special_use_count = 0 self.special_use_count = 0
self.is_dead = False
self.death_turn = 0
def reset(self): def reset(self):
self.hand: cs.Card = [] self.hand: cs.Card = []
@ -93,6 +95,8 @@ class Player:
pass pass
self.mancato_needed = 0 self.mancato_needed = 0
self.molly_discarded_cards = 0 self.molly_discarded_cards = 0
self.is_dead = False
self.death_turn = 0
def join_game(self, game): def join_game(self, game):
self.game = game self.game = game
@ -306,7 +310,7 @@ class Player:
self.choose(randrange(0, len(target.hand)+len(target.equipment))) self.choose(randrange(0, len(target.hand)+len(target.equipment)))
def play_turn(self, can_play_vendetta = True): def play_turn(self, can_play_vendetta = True):
if self.lives == 0: if self.lives == 0 or self.is_dead:
return self.end_turn(forced=True) return self.end_turn(forced=True)
self.scrapped_cards = 0 self.scrapped_cards = 0
self.can_play_ranch = True self.can_play_ranch = True