From 360457907b94424df18af0c5cddcd9b2fe5302e7 Mon Sep 17 00:00:00 2001 From: Alberto Xamin Date: Sun, 22 Nov 2020 16:13:21 +0100 Subject: [PATCH] emportio --- backend/game.py | 28 ++++++++++++++++++++++++- backend/players.py | 33 ++++++++++++++++-------------- frontend/src/components/Player.vue | 15 ++++++++++++-- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/backend/game.py b/backend/game.py index 1446131..e593aba 100644 --- a/backend/game.py +++ b/backend/game.py @@ -6,7 +6,7 @@ from cards import Bang import players from characters import all_characters from deck import Deck -from players import Player +from players import PendingAction, Player import roles class Game: @@ -109,6 +109,9 @@ class Game: if p != attacker: if p.get_banged(): self.waiting_for += 1 + if self.waiting_for == 0: + attacker.pending_action = players.PendingAction.PLAY + attacker.notify_self() def indian_others(self, attacker:Player): attacker.pending_action = players.PendingAction.WAIT @@ -119,6 +122,9 @@ class Game: if p != attacker: if p.get_indians(): self.waiting_for += 1 + if self.waiting_for == 0: + attacker.pending_action = players.PendingAction.PLAY + attacker.notify_self() def attack(self, attacker:Player, target_username:str): if self.players[self.players_map[target_username]].get_banged(): @@ -134,6 +140,26 @@ class Game: attacker.pending_action = players.PendingAction.WAIT attacker.notify_self() + def emporio(self): + self.available_cards = [self.deck.draw() for i in range(len(self.players))] + self.players[self.turn].pending_action = players.PendingAction.CHOOSE + self.players[self.turn].available_cards = [self.deck.draw() for i in range(len(self.players))] + self.players[self.turn].notify_self() + + def respond_emporio(self, player, i): + player.hand.append(self.available_cards.pop(i)) + player.available_cards = [] + player.pending_action = players.PendingAction.WAIT + player.notify_self() + nextPlayer = self.players[(self.turn + (len(self.players)-len(self.available_cards))) % len(self.players)] + if nextPlayer == self.players[self.turn]: + self.players[self.turn].pending_action = players.PendingAction.PLAY + self.players[self.turn].notify_self() + else: + nextPlayer.pending_action = players.PendingAction.CHOOSE + nextPlayer.available_cards = self.available_cards + nextPlayer.notify_self() + def get_player_named(self, name:str): return self.players[self.players_map[name]] diff --git a/backend/players.py b/backend/players.py index bcacf19..4b61773 100644 --- a/backend/players.py +++ b/backend/players.py @@ -217,7 +217,7 @@ class Player: self.game.duel(self, againts) if isinstance(card, cards.Emporio): self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.') - pass + self.game.emporio() if isinstance(card, cards.Gatling): self.sio.emit('chat_message', room=self.game.name, data=f'{self.name} ha giocato {card.name}.') self.game.attack_others(self) @@ -247,21 +247,24 @@ class Player: def choose(self, card_index): if self.pending_action != PendingAction.CHOOSE: return - target = self.game.get_player_named(self.target_p) - card = None - if card_index >= len(target.hand): - card = target.equipment.pop(card_index - len(target.hand)) + if self.target_p and self.target_p != '': + target = self.game.get_player_named(self.target_p) + card = None + if card_index >= len(target.hand): + card = target.equipment.pop(card_index - len(target.hand)) + else: + card = target.hand.pop(card_index) + target.notify_self() + if self.choose_action == 'steal': + self.hand.append(card) + else: + self.game.deck.scrap(card) + self.target_p = '' + self.choose_action = '' + self.pending_action = PendingAction.PLAY + self.notify_self() else: - card = target.hand.pop(card_index) - target.notify_self() - if self.choose_action == 'steal': - self.hand.append(card) - else: - self.game.deck.scrap(card) - self.target_p = '' - self.choose_action = '' - self.pending_action = PendingAction.PLAY - self.notify_self() + self.game.respond_emporio(self, card_index) def barrel_pick(self): pickable_cards = 1 + self.character.pick_mod diff --git a/frontend/src/components/Player.vue b/frontend/src/components/Player.vue index b8dee47..c5a7950 100644 --- a/frontend/src/components/Player.vue +++ b/frontend/src/components/Player.vue @@ -24,6 +24,7 @@

{{hint}}

+ @@ -56,6 +57,8 @@ export default { visiblePlayers: [], is_my_turn: false, expected_response: null, + shouldChooseCard: false, + available_cards: [], }), sockets: { role(role) { @@ -73,8 +76,11 @@ export default { this.has_played_bang = self.has_played_bang this.is_my_turn = self.is_my_turn this.expected_response = self.expected_response - if (this.pending_action == 5) { + this.available_cards = self.available_cards + if (this.pending_action == 5 && self.target_p) { this.chooseCardFromPlayer(self.target_p) + } else if (this.pending_action == 5) { + this.shouldChooseCard = true } }, self_vis(vis) { @@ -140,7 +146,12 @@ export default { } console.log(card_data) this.$socket.emit('play_card', card_data) - } + }, + choose(card) { + this.$socket.emit('choose', this.available_cards.indexOf(card)) + this.available_cards = [] + this.shouldChooseCard = false + }, }, mounted() { this.$socket.emit('refresh')