disconnect and death and barrel fix
This commit is contained in:
parent
eabf71e27b
commit
996271d97c
@ -62,7 +62,7 @@ class Mustang(Card):
|
|||||||
|
|
||||||
class Prigione(Card):
|
class Prigione(Card):
|
||||||
def __init__(self, suit, number):
|
def __init__(self, suit, number):
|
||||||
super().__init__(suit, 'Prigione', number, is_equipment=False)
|
super().__init__(suit, 'Prigione', number, is_equipment=True)
|
||||||
self.icon = '⛓'
|
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.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
|
self.need_target = True
|
||||||
@ -126,6 +126,7 @@ class Diligenza(Card):
|
|||||||
class Duello(Card):
|
class Duello(Card):
|
||||||
def __init__(self, suit, number):
|
def __init__(self, suit, number):
|
||||||
super().__init__(suit, 'Duello', number)
|
super().__init__(suit, 'Duello', number)
|
||||||
|
self.need_target = True
|
||||||
self.icon = '⚔️'
|
self.icon = '⚔️'
|
||||||
|
|
||||||
class Emporio(Card):
|
class Emporio(Card):
|
||||||
|
@ -19,8 +19,12 @@ class Game:
|
|||||||
self.readyCount = 0
|
self.readyCount = 0
|
||||||
|
|
||||||
def handle_disconnect(self, player: players.Player):
|
def handle_disconnect(self, player: players.Player):
|
||||||
|
|
||||||
print(f'player {player.name} left the game {self.name}')
|
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:
|
if len(self.players) == 0:
|
||||||
print(f'no players left in game {self.name}')
|
print(f'no players left in game {self.name}')
|
||||||
return True
|
return True
|
||||||
@ -110,7 +114,10 @@ class Game:
|
|||||||
|
|
||||||
def player_death(self, player: players.Player):
|
def player_death(self, player: players.Player):
|
||||||
print(f'player {player.name} died')
|
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:
|
if len(self.players) == 0:
|
||||||
print(f'no players left in game {self.name}')
|
print(f'no players left in game {self.name}')
|
||||||
return True
|
return True
|
||||||
|
@ -139,6 +139,7 @@ class Player:
|
|||||||
self.pending_action = PendingAction.DRAW
|
self.pending_action = PendingAction.DRAW
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
else:
|
else:
|
||||||
|
self.pending_action = PendingAction.WAIT
|
||||||
self.on_pick_cb()
|
self.on_pick_cb()
|
||||||
|
|
||||||
def get_playable_cards(self):
|
def get_playable_cards(self):
|
||||||
@ -164,7 +165,10 @@ class Player:
|
|||||||
return
|
return
|
||||||
card: cards.Card = self.hand.pop(hand_index)
|
card: cards.Card = self.hand.pop(hand_index)
|
||||||
print(self.name, 'is playing ', card, ' against:', againts)
|
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:
|
if card.is_weapon:
|
||||||
has_weapon = False
|
has_weapon = False
|
||||||
for i in range(len(self.equipment)):
|
for i in range(len(self.equipment)):
|
||||||
@ -178,10 +182,38 @@ class Player:
|
|||||||
else:
|
else:
|
||||||
self.equipment.append(card)
|
self.equipment.append(card)
|
||||||
else:
|
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
|
return
|
||||||
if isinstance(card, cards.Bang) and againts != None:
|
if isinstance(card, cards.Bang) and againts != None:
|
||||||
|
self.has_played_bang = True
|
||||||
self.game.attack(self, againts)
|
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.game.deck.scrap(card)
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
|
|
||||||
@ -192,7 +224,6 @@ class Player:
|
|||||||
picked: cards.Card = self.game.deck.pick_and_scrap()
|
picked: cards.Card = self.game.deck.pick_and_scrap()
|
||||||
print(f'Did pick {picked}')
|
print(f'Did pick {picked}')
|
||||||
if picked.suit == cards.Suit.HEARTS:
|
if picked.suit == cards.Suit.HEARTS:
|
||||||
self.pending_action = PendingAction.WAIT
|
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
self.game.responders_did_respond()
|
self.game.responders_did_respond()
|
||||||
return
|
return
|
||||||
@ -202,16 +233,16 @@ class Player:
|
|||||||
else:
|
else:
|
||||||
self.pending_action = PendingAction.RESPOND
|
self.pending_action = PendingAction.RESPOND
|
||||||
self.expected_response = cards.Mancato
|
self.expected_response = cards.Mancato
|
||||||
self.on_response_cb = self.take_damage_response()
|
self.on_response_cb = self.take_damage_response
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
|
|
||||||
def get_banged(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')
|
print('Cant defend')
|
||||||
self.take_damage_response()
|
self.take_damage_response()
|
||||||
return False
|
return False
|
||||||
else:
|
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')
|
print('has barrel')
|
||||||
self.pending_action = PendingAction.PICK
|
self.pending_action = PendingAction.PICK
|
||||||
self.on_pick_cb = self.barrel_pick
|
self.on_pick_cb = self.barrel_pick
|
||||||
@ -219,7 +250,7 @@ class Player:
|
|||||||
print('has mancato')
|
print('has mancato')
|
||||||
self.pending_action = PendingAction.RESPOND
|
self.pending_action = PendingAction.RESPOND
|
||||||
self.expected_response = cards.Mancato
|
self.expected_response = cards.Mancato
|
||||||
self.on_response_cb = self.take_damage_response()
|
self.on_response_cb = self.take_damage_response
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -256,6 +287,7 @@ class Player:
|
|||||||
if len(self.hand) > self.max_lives and not forced:
|
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")
|
print(f"I {self.name} have to many cards in my hand and I can't end the turn")
|
||||||
else:
|
else:
|
||||||
|
self.is_my_turn = False
|
||||||
self.pending_action = PendingAction.WAIT
|
self.pending_action = PendingAction.WAIT
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
self.game.next_turn()
|
self.game.next_turn()
|
||||||
|
@ -48,6 +48,7 @@ export default {
|
|||||||
hint: '',
|
hint: '',
|
||||||
pending_action: null,
|
pending_action: null,
|
||||||
card_against: null,
|
card_against: null,
|
||||||
|
has_played_bang: false,
|
||||||
visiblePlayers: []
|
visiblePlayers: []
|
||||||
}),
|
}),
|
||||||
sockets: {
|
sockets: {
|
||||||
@ -63,6 +64,7 @@ export default {
|
|||||||
this.equipment = self.equipment
|
this.equipment = self.equipment
|
||||||
this.lives = self.lives
|
this.lives = self.lives
|
||||||
this.max_lives = self.max_lives
|
this.max_lives = self.max_lives
|
||||||
|
this.has_played_bang = self.has_played_bang
|
||||||
},
|
},
|
||||||
self_vis(vis) {
|
self_vis(vis) {
|
||||||
console.log('received visibility update')
|
console.log('received visibility update')
|
||||||
@ -105,7 +107,7 @@ export default {
|
|||||||
},
|
},
|
||||||
play_card(card) {
|
play_card(card) {
|
||||||
if (this.pending_action == 2) {
|
if (this.pending_action == 2) {
|
||||||
if (card.need_target) {
|
if (card.need_target && !(card.name == 'Bang!' && this.has_played_bang)) {
|
||||||
this.card_against = card
|
this.card_against = card
|
||||||
} else {
|
} else {
|
||||||
this.really_play_card(card, null)
|
this.really_play_card(card, null)
|
||||||
|
Loading…
Reference in New Issue
Block a user