simplifying init

Co-authored-by: Alberto Xamin <alberto@xamin.it>
This commit is contained in:
Giulio 2021-06-12 13:09:12 +02:00
parent 3aa786395a
commit f7a527fcaf
2 changed files with 27 additions and 56 deletions

View File

@ -44,6 +44,26 @@ class Game:
self.characters_to_distribute = 2 # personaggi da dare a inizio partita
self.debug = False
def reset(self):
print('resetting lobby')
self.players.extend(self.spectators)
self.spectators = []
for bot in [p for p in self.players if p.is_bot]:
bot.game = None
self.players = [p for p in self.players if not p.is_bot]
print(self.players)
self.started = False
self.is_handling_death = False
self.waiting_for = 0
self.incremental_turn = 0
self.turn = 0
self.pending_winners = []
for p in self.players:
p.reset()
p.notify_self()
eventlet.sleep(0.5)
self.notify_room()
def notify_room(self, sid=None):
if len([p for p in self.players if p.character == None]) != 0 or sid:
self.sio.emit('room', room=self.name if not sid else sid, data={
@ -549,25 +569,6 @@ class Game:
corpse.notify_self()
self.next_turn()
def reset(self):
print('resetting lobby')
self.players.extend(self.spectators)
self.spectators = []
for bot in [p for p in self.players if p.is_bot]:
bot.game = None
self.players = [p for p in self.players if not p.is_bot]
print(self.players)
self.started = False
self.is_handling_death = False
self.waiting_for = 0
self.incremental_turn = 0
self.turn = 0
self.pending_winners = []
for p in self.players:
p.reset()
p.notify_self()
eventlet.sleep(0.5)
self.notify_room()
def check_event(self, ev):
if self.deck == None or len(self.deck.event_cards) == 0: return False

View File

@ -28,44 +28,9 @@ class Player:
self.name = name
self.sid = sid
self.sio = sio
self.hand: cs.Card = []
self.equipment: cs.Card = []
self.role: r.Role = None
self.character: chars.Character = None
self.real_character: chars.Character = None
self.lives = 0
self.max_lives = 0
self.game: g = None
self.is_my_turn = False
self.is_waiting_for_action = True
self.has_played_bang = False
self.pending_action: PendingAction = None
self.available_characters = []
self.was_shot = False
self.on_pick_cb = None
self.on_failed_response_cb = None
self.event_type: str = None
self.expected_response = []
self.attacker: Player = None
self.target_p: str = None
self.is_drawing = False
self.can_play_vendetta = True
self.is_giving_life = False
self.is_using_checchino = False
self.choose_text = 'choose_card_to_get'
self.using_rimbalzo = 0 # 0 no, 1 scegli giocatore, 2 scegli carta
self.can_play_ranch = True
self.is_playing_ranch = False
self.mancato_needed = 0
self.molly_discarded_cards = 0
self.is_bot = bot
self.bang_used = 0
self.special_use_count = 0
self.is_dead = False
self.death_turn = 0
self.is_ghost = False
self.not_chosen_character = None
self.noStar = False
self.game: g = None
self.reset()
def reset(self):
self.hand: cs.Card = []
@ -103,6 +68,11 @@ class Player:
self.is_ghost = False
self.death_turn = 0
self.noStar = False
self.can_play_vendetta = True
self.is_giving_life = False
self.choose_text = 'choose_card_to_get'
self.using_rimbalzo = 0 # 0 no, 1 scegli giocatore, 2 scegli carta
self.bang_used = 0
def join_game(self, game):
self.game = game