small readability updates
This commit is contained in:
parent
9ea0a49c2e
commit
8a5e25385f
@ -224,6 +224,7 @@ class Game:
|
|||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def notify_room(self, sid=None):
|
def notify_room(self, sid=None):
|
||||||
|
"""Notify all players in the room of the room's state."""
|
||||||
if any((p.character is None for p in self.players)) or sid:
|
if any((p.character is None for p in self.players)) or sid:
|
||||||
G.sio.emit(
|
G.sio.emit(
|
||||||
"room",
|
"room",
|
||||||
@ -265,6 +266,7 @@ class Game:
|
|||||||
G.sio.emit("spectators", room=self.name, data=len(self.spectators))
|
G.sio.emit("spectators", room=self.name, data=len(self.spectators))
|
||||||
|
|
||||||
def toggle_expansion(self, expansion_name):
|
def toggle_expansion(self, expansion_name):
|
||||||
|
"""Toggles an expansion on or off."""
|
||||||
if not self.started:
|
if not self.started:
|
||||||
print(f"{self.name}: toggling", expansion_name)
|
print(f"{self.name}: toggling", expansion_name)
|
||||||
if expansion_name in self.expansions:
|
if expansion_name in self.expansions:
|
||||||
@ -274,10 +276,12 @@ class Game:
|
|||||||
self.notify_room()
|
self.notify_room()
|
||||||
|
|
||||||
def toggle_competitive(self):
|
def toggle_competitive(self):
|
||||||
|
"""Toggles the competitive mode on or off."""
|
||||||
self.is_competitive = not self.is_competitive
|
self.is_competitive = not self.is_competitive
|
||||||
self.notify_room()
|
self.notify_room()
|
||||||
|
|
||||||
def toggle_disconnect_bot(self):
|
def toggle_disconnect_bot(self):
|
||||||
|
"""Toggles the disconnect bot on or off."""
|
||||||
self.disconnect_bot = not self.disconnect_bot
|
self.disconnect_bot = not self.disconnect_bot
|
||||||
self.notify_room()
|
self.notify_room()
|
||||||
|
|
||||||
@ -605,7 +609,7 @@ class Game:
|
|||||||
player.pending_action = pl.PendingAction.WAIT
|
player.pending_action = pl.PendingAction.WAIT
|
||||||
player.notify_self()
|
player.notify_self()
|
||||||
pls = self.get_alive_players()
|
pls = self.get_alive_players()
|
||||||
nextPlayer = pls[
|
next_player = pls[
|
||||||
(
|
(
|
||||||
pls.index(self.players[self.turn])
|
pls.index(self.players[self.turn])
|
||||||
+ (len(pls) - len(self.available_cards))
|
+ (len(pls) - len(self.available_cards))
|
||||||
@ -613,28 +617,33 @@ class Game:
|
|||||||
% len(pls)
|
% len(pls)
|
||||||
]
|
]
|
||||||
if len(self.available_cards) == 1:
|
if len(self.available_cards) == 1:
|
||||||
nextPlayer.hand.append(self.available_cards.pop())
|
G.sio.emit(
|
||||||
nextPlayer.notify_self()
|
"chat_message",
|
||||||
|
room=self.name,
|
||||||
|
data=f"_choose_emporio|{next_player.name}|{self.available_cards[0].name}",
|
||||||
|
)
|
||||||
|
next_player.hand.append(self.available_cards.pop())
|
||||||
|
next_player.notify_self()
|
||||||
G.sio.emit("emporio", room=self.name, data='{"name":"","cards":[]}')
|
G.sio.emit("emporio", room=self.name, data='{"name":"","cards":[]}')
|
||||||
self.players[self.turn].pending_action = pl.PendingAction.PLAY
|
self.players[self.turn].pending_action = pl.PendingAction.PLAY
|
||||||
self.players[self.turn].notify_self()
|
self.players[self.turn].notify_self()
|
||||||
elif nextPlayer == self.players[self.turn]:
|
elif next_player == self.players[self.turn]:
|
||||||
G.sio.emit("emporio", room=self.name, data='{"name":"","cards":[]}')
|
G.sio.emit("emporio", room=self.name, data='{"name":"","cards":[]}')
|
||||||
self.players[self.turn].pending_action = pl.PendingAction.PLAY
|
self.players[self.turn].pending_action = pl.PendingAction.PLAY
|
||||||
self.players[self.turn].notify_self()
|
self.players[self.turn].notify_self()
|
||||||
else:
|
else:
|
||||||
nextPlayer.pending_action = pl.PendingAction.CHOOSE
|
next_player.pending_action = pl.PendingAction.CHOOSE
|
||||||
nextPlayer.choose_text = "choose_card_to_get"
|
next_player.choose_text = "choose_card_to_get"
|
||||||
nextPlayer.available_cards = self.available_cards
|
next_player.available_cards = self.available_cards
|
||||||
G.sio.emit(
|
G.sio.emit(
|
||||||
"emporio",
|
"emporio",
|
||||||
room=self.name,
|
room=self.name,
|
||||||
data=json.dumps(
|
data=json.dumps(
|
||||||
{"name": nextPlayer.name, "cards": self.available_cards},
|
{"name": next_player.name, "cards": self.available_cards},
|
||||||
default=lambda o: o.__dict__,
|
default=lambda o: o.__dict__,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
nextPlayer.notify_self()
|
next_player.notify_self()
|
||||||
|
|
||||||
def get_player_named(self, name: str, next=False) -> pl.Player:
|
def get_player_named(self, name: str, next=False) -> pl.Player:
|
||||||
if next:
|
if next:
|
||||||
@ -642,6 +651,7 @@ class Game:
|
|||||||
return self.players[self.players_map[name]]
|
return self.players[self.players_map[name]]
|
||||||
|
|
||||||
def responders_did_respond_resume_turn(self, did_lose=False):
|
def responders_did_respond_resume_turn(self, did_lose=False):
|
||||||
|
"""Called when all Players have responded to an event/attack."""
|
||||||
print(f"{self.name}: did_lose", did_lose)
|
print(f"{self.name}: did_lose", did_lose)
|
||||||
if self.player_bangs > 0 and self.check_event(ce.PerUnPugnoDiCarte):
|
if self.player_bangs > 0 and self.check_event(ce.PerUnPugnoDiCarte):
|
||||||
self.player_bangs -= 1
|
self.player_bangs -= 1
|
||||||
@ -727,6 +737,7 @@ class Game:
|
|||||||
self.players[self.turn].notify_self()
|
self.players[self.turn].notify_self()
|
||||||
|
|
||||||
def announces_winners(self, winners=None):
|
def announces_winners(self, winners=None):
|
||||||
|
"""Announces the winners of the game in the chat"""
|
||||||
if winners is None:
|
if winners is None:
|
||||||
print(f"{self.name}: WE HAVE A WINNER - pending winners")
|
print(f"{self.name}: WE HAVE A WINNER - pending winners")
|
||||||
else:
|
else:
|
||||||
@ -760,10 +771,12 @@ class Game:
|
|||||||
return self.reset()
|
return self.reset()
|
||||||
|
|
||||||
def next_player(self):
|
def next_player(self):
|
||||||
|
"""Returns the next player in turn order"""
|
||||||
pls = self.get_alive_players()
|
pls = self.get_alive_players()
|
||||||
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):
|
||||||
|
"""Starts the turn of the current player"""
|
||||||
self.incremental_turn += 1
|
self.incremental_turn += 1
|
||||||
if not self.is_replay:
|
if not self.is_replay:
|
||||||
Metrics.send_metric(
|
Metrics.send_metric(
|
||||||
|
@ -312,9 +312,9 @@ class Player:
|
|||||||
if self.gold_nuggets >= 2 and any(
|
if self.gold_nuggets >= 2 and any(
|
||||||
(isinstance(c, grc.Zaino) for c in self.gold_rush_equipment)
|
(isinstance(c, grc.Zaino) for c in self.gold_rush_equipment)
|
||||||
):
|
):
|
||||||
for i in range(len(self.gold_rush_equipment)):
|
for card in self.gold_rush_equipment:
|
||||||
if isinstance(self.gold_rush_equipment[i], grc.Zaino):
|
if isinstance(card, grc.Zaino):
|
||||||
self.gold_rush_equipment[i].play_card(self, None)
|
card.play_card(self, None)
|
||||||
return # play card will notify the player
|
return # play card will notify the player
|
||||||
if self.character.check(self.game, chw.TerenKill):
|
if self.character.check(self.game, chw.TerenKill):
|
||||||
picked: cs.Card = self.game.deck.pick_and_scrap()
|
picked: cs.Card = self.game.deck.pick_and_scrap()
|
||||||
@ -523,8 +523,8 @@ class Player:
|
|||||||
if self.gold_nuggets > 0 and any(
|
if self.gold_nuggets > 0 and any(
|
||||||
(c.number <= self.gold_nuggets for c in self.game.deck.shop_cards)
|
(c.number <= self.gold_nuggets for c in self.game.deck.shop_cards)
|
||||||
):
|
):
|
||||||
for i in range(len(self.game.deck.shop_cards)):
|
for i, card in enumerate(self.game.deck.shop_cards):
|
||||||
if self.game.deck.shop_cards[i].number <= self.gold_nuggets:
|
if card.number <= self.gold_nuggets:
|
||||||
self.game.rpc_log.append(f"{self.name};buy_gold_rush_card;{i}")
|
self.game.rpc_log.append(f"{self.name};buy_gold_rush_card;{i}")
|
||||||
self.buy_gold_rush_card(i)
|
self.buy_gold_rush_card(i)
|
||||||
return
|
return
|
||||||
@ -676,19 +676,19 @@ class Player:
|
|||||||
self.end_turn()
|
self.end_turn()
|
||||||
elif self.pending_action == PendingAction.RESPOND:
|
elif self.pending_action == PendingAction.RESPOND:
|
||||||
did_respond = False
|
did_respond = False
|
||||||
for i in range(len(self.hand)):
|
for i, card in enumerate(self.hand):
|
||||||
if self.hand[i].can_be_used_now and (
|
if card.can_be_used_now and (
|
||||||
self.hand[i].name in self.expected_response
|
card.name in self.expected_response
|
||||||
or self.character.check(self.game, chd.ElenaFuente)
|
or self.character.check(self.game, chd.ElenaFuente)
|
||||||
):
|
):
|
||||||
self.game.rpc_log.append(f"{self.name};respond;{i}")
|
self.game.rpc_log.append(f"{self.name};respond;{i}")
|
||||||
self.respond(i)
|
self.respond(i)
|
||||||
did_respond = True
|
did_respond = True
|
||||||
break
|
break
|
||||||
for i in range(len(self.equipment)):
|
for i, card in enumerate(self.equipment):
|
||||||
if (
|
if (
|
||||||
not self.game.check_event(ce.Lazo)
|
not self.game.check_event(ce.Lazo)
|
||||||
and self.equipment[i].name in self.expected_response
|
and card.name in self.expected_response
|
||||||
):
|
):
|
||||||
self.game.rpc_log.append(f"{self.name};respond;{len(self.hand)+i}")
|
self.game.rpc_log.append(f"{self.name};respond;{len(self.hand)+i}")
|
||||||
self.respond(len(self.hand) + i)
|
self.respond(len(self.hand) + i)
|
||||||
@ -1012,10 +1012,8 @@ class Player:
|
|||||||
if any((isinstance(c, grc.FerroDiCavallo) for c in self.gold_rush_equipment)):
|
if any((isinstance(c, grc.FerroDiCavallo) for c in self.gold_rush_equipment)):
|
||||||
pickable_cards += 1
|
pickable_cards += 1
|
||||||
if self.is_my_turn and self.attacker is None:
|
if self.is_my_turn and self.attacker is None:
|
||||||
for i in range(len(self.equipment)):
|
for i, card in enumerate(self.equipment):
|
||||||
if i < len(self.equipment) and isinstance(
|
if i < len(self.equipment) and isinstance(card, cs.Dinamite):
|
||||||
self.equipment[i], cs.Dinamite
|
|
||||||
):
|
|
||||||
while pickable_cards > 0:
|
while pickable_cards > 0:
|
||||||
pickable_cards -= 1
|
pickable_cards -= 1
|
||||||
picked: cs.Card = self.game.deck.pick_and_scrap()
|
picked: cs.Card = self.game.deck.pick_and_scrap()
|
||||||
@ -1088,8 +1086,8 @@ class Player:
|
|||||||
):
|
):
|
||||||
self.notify_self()
|
self.notify_self()
|
||||||
return
|
return
|
||||||
for i in range(len(self.equipment)):
|
for i, card in enumerate(self.equipment):
|
||||||
if isinstance(self.equipment[i], cs.Prigione):
|
if isinstance(card, cs.Prigione):
|
||||||
while pickable_cards > 0:
|
while pickable_cards > 0:
|
||||||
pickable_cards -= 1
|
pickable_cards -= 1
|
||||||
picked: cs.Card = self.game.deck.pick_and_scrap()
|
picked: cs.Card = self.game.deck.pick_and_scrap()
|
||||||
@ -1124,8 +1122,8 @@ class Player:
|
|||||||
)
|
)
|
||||||
break
|
break
|
||||||
break
|
break
|
||||||
for i in range(len(self.equipment)):
|
for i, card in enumerate(self.equipment):
|
||||||
if isinstance(self.equipment[i], tvosc.SerpenteASonagli):
|
if isinstance(card, tvosc.SerpenteASonagli):
|
||||||
while pickable_cards > 0:
|
while pickable_cards > 0:
|
||||||
pickable_cards -= 1
|
pickable_cards -= 1
|
||||||
picked: cs.Card = self.game.deck.pick_and_scrap()
|
picked: cs.Card = self.game.deck.pick_and_scrap()
|
||||||
@ -1184,8 +1182,7 @@ class Player:
|
|||||||
|
|
||||||
def get_playable_cards(self):
|
def get_playable_cards(self):
|
||||||
playable_cards = []
|
playable_cards = []
|
||||||
for i in range(len(self.hand)):
|
for i, card in enumerate(self.hand):
|
||||||
card = self.hand[i]
|
|
||||||
if (
|
if (
|
||||||
isinstance(card, cs.Bang)
|
isinstance(card, cs.Bang)
|
||||||
and self.has_played_bang
|
and self.has_played_bang
|
||||||
|
Loading…
Reference in New Issue
Block a user