From 996271d97cd8e9e90ada0311bff31f47a0c0dbfc Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sat, 21 Nov 2020 13:50:53 +0100 Subject: [PATCH] disconnect and death and barrel fix --- backend/cards.py | 3 +- backend/game.py | 11 +++++-- backend/players.py | 46 +++++++++++++++++++++++++----- frontend/src/components/Player.vue | 4 ++- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/backend/cards.py b/backend/cards.py index 03a577f..c6bd4c7 100644 --- a/backend/cards.py +++ b/backend/cards.py @@ -62,7 +62,7 @@ class Mustang(Card): class Prigione(Card): def __init__(self, suit, number): - super().__init__(suit, 'Prigione', number, is_equipment=False) + super().__init__(suit, 'Prigione', number, is_equipment=True) self.icon = '⛓' self.desc = "Equipaggia questa carta a un altro giocatore, tranne lo Sceriffo. Il giocatore scelto all'inizio del suo turno, prima di pescare dovrà estrarre: se esce Cuori scarta questa carta e gioca normalmente il turno, altrimenti scarta questa carta e salta il turno" self.need_target = True @@ -126,6 +126,7 @@ class Diligenza(Card): class Duello(Card): def __init__(self, suit, number): super().__init__(suit, 'Duello', number) + self.need_target = True self.icon = '⚔️' class Emporio(Card): diff --git a/backend/game.py b/backend/game.py index 857aea1..796f124 100644 --- a/backend/game.py +++ b/backend/game.py @@ -19,8 +19,12 @@ class Game: self.readyCount = 0 def handle_disconnect(self, player: players.Player): + print(f'player {player.name} left the game {self.name}') - self.players.pop(self.players.index(player)) + index = self.players.index(player) + if self.started and index < self.turn: + self.turn -= 1 + self.players.pop(index) if len(self.players) == 0: print(f'no players left in game {self.name}') return True @@ -110,7 +114,10 @@ class Game: def player_death(self, player: players.Player): print(f'player {player.name} died') - self.players.pop(self.players.index(player)) + index = self.players.index(player) + if index < self.turn: + self.turn -= 1 + self.players.pop(index) if len(self.players) == 0: print(f'no players left in game {self.name}') return True diff --git a/backend/players.py b/backend/players.py index 2ebad5d..c377c5a 100644 --- a/backend/players.py +++ b/backend/players.py @@ -139,6 +139,7 @@ class Player: self.pending_action = PendingAction.DRAW self.notify_self() else: + self.pending_action = PendingAction.WAIT self.on_pick_cb() def get_playable_cards(self): @@ -164,7 +165,10 @@ class Player: return card: cards.Card = self.hand.pop(hand_index) print(self.name, 'is playing ', card, ' against:', againts) - if card.is_equipment and card.name not in [c.name for c in self.equipment]: + if isinstance(card, cards.Prigione) and isinstance(self.game.players_map[againts].role, roles.Sheriff): + self.game.players_map[againts].equipment.append(card) + self.game.players_map[againts].notify_self() + elif card.is_equipment and card.name not in [c.name for c in self.equipment]: if card.is_weapon: has_weapon = False for i in range(len(self.equipment)): @@ -178,10 +182,38 @@ class Player: else: self.equipment.append(card) else: - if isinstance(card, cards.Bang) and self.has_played_bang and not any([isinstance(c, cards.Volcanic) for c in self.equipment]): + if isinstance(card, cards.Bang) and self.has_played_bang and not any([isinstance(c, cards.Volcanic) for c in self.equipment]) and againts != None: + self.hand.insert(hand_index, card) return if isinstance(card, cards.Bang) and againts != None: + self.has_played_bang = True self.game.attack(self, againts) + if isinstance(card, cards.Birra) and len(self.game.players) != 2: + self.lives = min(self.lives+1, self.max_lives) + if isinstance(card, cards.CatBalou): + pass + if isinstance(card, cards.Diligenza): + for i in range(2): + self.hand.append(self.game.deck.draw()) + if isinstance(card, cards.Duello): + pass + if isinstance(card, cards.Emporio): + pass + if isinstance(card, cards.Gatling): + pass + if isinstance(card, cards.Indiani): + pass + if isinstance(card, cards.Mancato): + pass + if isinstance(card, cards.Panico): + pass + if isinstance(card, cards.Saloon): + for p in self.game.players: + p.lives = min(p.lives+1, p.max_lives) + p.notify_self() + if isinstance(card, cards.WellsFargo): + for i in range(3): + self.hand.append(self.game.deck.draw()) self.game.deck.scrap(card) self.notify_self() @@ -192,7 +224,6 @@ class Player: picked: cards.Card = self.game.deck.pick_and_scrap() print(f'Did pick {picked}') if picked.suit == cards.Suit.HEARTS: - self.pending_action = PendingAction.WAIT self.notify_self() self.game.responders_did_respond() return @@ -202,16 +233,16 @@ class Player: else: self.pending_action = PendingAction.RESPOND self.expected_response = cards.Mancato - self.on_response_cb = self.take_damage_response() + self.on_response_cb = self.take_damage_response self.notify_self() def get_banged(self): - if len([c for c in self.hand if isinstance(c, cards.Mancato) or isinstance(c, cards.Barile)]) == 0: + if len([c for c in self.hand if isinstance(c, cards.Mancato)]) == 0 and len([c for c in self.equipment if isinstance(c, cards.Barile)]) == 0: print('Cant defend') self.take_damage_response() return False else: - if len([c for c in self.hand if isinstance(c, cards.Barile)]) > 0: + if len([c for c in self.equipment if isinstance(c, cards.Barile)]) > 0: print('has barrel') self.pending_action = PendingAction.PICK self.on_pick_cb = self.barrel_pick @@ -219,7 +250,7 @@ class Player: print('has mancato') self.pending_action = PendingAction.RESPOND self.expected_response = cards.Mancato - self.on_response_cb = self.take_damage_response() + self.on_response_cb = self.take_damage_response self.notify_self() return True @@ -256,6 +287,7 @@ class Player: if len(self.hand) > self.max_lives and not forced: print(f"I {self.name} have to many cards in my hand and I can't end the turn") else: + self.is_my_turn = False self.pending_action = PendingAction.WAIT self.notify_self() self.game.next_turn() diff --git a/frontend/src/components/Player.vue b/frontend/src/components/Player.vue index cc7f0b0..308b96d 100644 --- a/frontend/src/components/Player.vue +++ b/frontend/src/components/Player.vue @@ -48,6 +48,7 @@ export default { hint: '', pending_action: null, card_against: null, + has_played_bang: false, visiblePlayers: [] }), sockets: { @@ -63,6 +64,7 @@ export default { this.equipment = self.equipment this.lives = self.lives this.max_lives = self.max_lives + this.has_played_bang = self.has_played_bang }, self_vis(vis) { console.log('received visibility update') @@ -105,7 +107,7 @@ export default { }, play_card(card) { if (this.pending_action == 2) { - if (card.need_target) { + if (card.need_target && !(card.name == 'Bang!' && this.has_played_bang)) { this.card_against = card } else { this.really_play_card(card, null)