From 323bd80179c1df5e7d41d1fa14b3918a8d4a007c Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sun, 20 Dec 2020 21:13:54 +0100 Subject: [PATCH] fix logica per un pugno di carte --- backend/bang/deck.py | 5 ++--- backend/bang/expansions/fistful_of_cards/card_events.py | 9 ++++++--- backend/bang/game.py | 2 +- backend/bang/players.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/backend/bang/deck.py b/backend/bang/deck.py index dd07c24..b539e0a 100644 --- a/backend/bang/deck.py +++ b/backend/bang/deck.py @@ -22,15 +22,14 @@ class Deck: self.event_cards: List[ce.CardEvent] = [] if 'fistful_of_cards' in game.expansions: self.event_cards.extend(ce.get_all_events()) - random.shuffle(self.event_cards) random.shuffle(self.cards) self.scrap_pile: List[cs.Card] = [] print(f'Deck initialized with {len(self.cards)} cards') def flip_event(self): - if len(self.event_cards) > 0: + if len(self.event_cards) > 0 and not isinstance(self.event_cards[0], ce.PerUnPugnoDiCarte): self.event_cards.append(self.event_cards.pop(0)) - self.game.notify_event_card() + self.game.notify_event_card() def peek(self, n_cards: int) -> list: return self.cards[:n_cards] diff --git a/backend/bang/expansions/fistful_of_cards/card_events.py b/backend/bang/expansions/fistful_of_cards/card_events.py index 0a3dabb..644d378 100644 --- a/backend/bang/expansions/fistful_of_cards/card_events.py +++ b/backend/bang/expansions/fistful_of_cards/card_events.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +import random class CardEvent(ABC): def __init__(self, name, icon): @@ -96,7 +97,7 @@ class Vendetta(CardEvent): self.desc_eng = "When ending the turn, the player flips a card from the deck, if it's ♥️ he plays another turn (but he does not flip another card)" def get_all_events(): - return [ + cards = [ Agguato(), # Cecchino(), DeadMan(), @@ -106,10 +107,12 @@ def get_all_events(): LeggeDelWest(), LiquoreForte(), MinieraAbbandonata(), - PerUnPugnoDiCarte(), Peyote(), # Ranch(), # Rimbalzo(), RouletteRussa(), Vendetta(), - ] \ No newline at end of file + ] + random.shuffle(cards) + cards.append(PerUnPugnoDiCarte()) + return cards \ No newline at end of file diff --git a/backend/bang/game.py b/backend/bang/game.py index ba4dd00..4c93bd4 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -266,7 +266,7 @@ class Game: else: self.responders_did_respond_resume_turn(did_lose=True) return - if self.check_event(ce.PerUnPugnoDiCarte): + if self.check_event(ce.PerUnPugnoDiCarte) and len(self.players[self.turn].hand) > 0: self.player_bangs = len(self.players[self.turn].hand) if self.players[self.turn].get_banged(self.deck.event_cards[0]): self.players[self.turn].notify_self() diff --git a/backend/bang/players.py b/backend/bang/players.py index 4c300f6..56ce288 100644 --- a/backend/bang/players.py +++ b/backend/bang/players.py @@ -671,9 +671,9 @@ class Player: def respond(self, hand_index): if self.pending_action != PendingAction.RESPOND: return self.pending_action = PendingAction.WAIT - if hand_index != -1 and ( + if hand_index != -1 and hand_index < (len(self.hand)+len(self.equipment)) and ( ((hand_index < len(self.hand) and self.hand[hand_index].name in self.expected_response)) or - self.equipment[hand_index-len(self.hand)].name in self.expected_response): + (hand_index-len(self.hand) < len(self.equipment) and self.equipment[hand_index-len(self.hand)].name in self.expected_response)): card = self.hand.pop(hand_index) if hand_index < len(self.hand) else self.equipment.pop(hand_index-len(self.hand)) if isinstance(self.character, chd.MollyStark) and hand_index < len(self.hand)+1 and not self.is_my_turn and self.event_type != 'duel': self.hand.append(self.game.deck.draw())