change is none checks

This commit is contained in:
Alberto Xamin 2023-01-23 14:50:03 +00:00
parent 1b8690a5c6
commit 6ae2360adb
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
10 changed files with 68 additions and 68 deletions

View File

@ -153,7 +153,7 @@ class Prigione(Card):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if (player.game.check_event(ce.IlGiudice)): if (player.game.check_event(ce.IlGiudice)):
return False return False
if against != None and not isinstance(player.game.get_player_named(against).role, r.Sheriff): if against is not None and not isinstance(player.game.get_player_named(against).role, r.Sheriff):
self.can_be_used_now = False self.can_be_used_now = False
G.sio.emit('chat_message', room=player.game.name, G.sio.emit('chat_message', room=player.game.name,
data=f'_play_card_against|{player.name}|{self.name}|{against}') data=f'_play_card_against|{player.name}|{self.name}|{against}')
@ -218,9 +218,9 @@ class Bang(Card):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if player.game.check_event(ceh.Sermone) and not self.number == 42: # 42 gold rush if player.game.check_event(ceh.Sermone) and not self.number == 42: # 42 gold rush
return False return False
if ((player.has_played_bang and not self.number == 42) and (not any((isinstance(c, Volcanic) for c in player.equipment)) or player.game.check_event(ce.Lazo)) and against != None): # 42 gold rush: if ((player.has_played_bang and not self.number == 42) and (not any((isinstance(c, Volcanic) for c in player.equipment)) or player.game.check_event(ce.Lazo)) and against is not None): # 42 gold rush:
return False return False
elif against != None: elif against is not None:
import bang.characters as chars import bang.characters as chars
super().play_card(player, against=against) super().play_card(player, against=against)
if not self.number == 42: # 42 gold rush if not self.number == 42: # 42 gold rush
@ -285,7 +285,7 @@ class CatBalou(Card):
self.can_target_self = True self.can_target_self = True
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None and (len(player.game.get_player_named(against).hand) + len(player.game.get_player_named(against).equipment)) > 0 and (player.name != against or len(player.equipment) > 0): if against is not None and (len(player.game.get_player_named(against).hand) + len(player.game.get_player_named(against).equipment)) > 0 and (player.name != against or len(player.equipment) > 0):
if self.name == 'Cat Balou': if self.name == 'Cat Balou':
super().play_card(player, against=against) super().play_card(player, against=against)
from bang.players import PendingAction from bang.players import PendingAction
@ -322,7 +322,7 @@ class Duello(Card):
# self.desc_eng = "Play this card against any player. In turn, starting with your opponent, you can discard a Bang! Card, the first player who does not do so loses 1 life." # self.desc_eng = "Play this card against any player. In turn, starting with your opponent, you can discard a Bang! Card, the first player who does not do so loses 1 life."
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None: if against is not None:
super().play_card(player, against=against) super().play_card(player, against=against)
player.game.duel(player, against) player.game.duel(player, against)
return True return True
@ -378,7 +378,7 @@ class Mancato(Card):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
import bang.characters as chars import bang.characters as chars
if against != None and player.character.check(player.game, chars.CalamityJanet): if against is not None and player.character.check(player.game, chars.CalamityJanet):
if player.has_played_bang and (not any((isinstance(c, Volcanic) for c in player.equipment)) or player.game.check_event(ce.Lazo)): if player.has_played_bang and (not any((isinstance(c, Volcanic) for c in player.equipment)) or player.game.check_event(ce.Lazo)):
return False return False
if player.game.check_event(ceh.Sermone): if player.game.check_event(ceh.Sermone):
@ -402,7 +402,7 @@ class Panico(Card):
# self.desc_eng = "Steal a card from a player at distance 1" # self.desc_eng = "Steal a card from a player at distance 1"
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None and (len(player.game.get_player_named(against).hand) + len(player.game.get_player_named(against).equipment)) > 0 and (player.name != against or len(player.equipment) > 0): if against is not None and (len(player.game.get_player_named(against).hand) + len(player.game.get_player_named(against).equipment)) > 0 and (player.name != against or len(player.equipment) > 0):
super().play_card(player, against=against) super().play_card(player, against=against)
from bang.players import PendingAction from bang.players import PendingAction
player.pending_action = PendingAction.CHOOSE player.pending_action = PendingAction.CHOOSE

View File

@ -52,10 +52,10 @@ class Deck:
self.game.notify_event_card() self.game.notify_event_card()
def fill_gold_rush_shop(self): def fill_gold_rush_shop(self):
if not any((c == None for c in self.shop_cards)): if not any((c is None for c in self.shop_cards)):
return return
for i in range(3): for i in range(3):
if self.shop_cards[i] == None: if self.shop_cards[i] is None:
print(f'replacing gr-card {i}') print(f'replacing gr-card {i}')
self.shop_cards[i] = self.shop_deck.pop(0) self.shop_cards[i] = self.shop_deck.pop(0)
self.shop_cards[i].reset_card() self.shop_cards[i].reset_card()

View File

@ -24,7 +24,7 @@ class Pugno(Card):
self.need_target = True self.need_target = True
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None: if against is not None:
super().play_card(player, against=against) super().play_card(player, against=against)
player.game.attack(player, against, card_name=self.name) player.game.attack(player, against, card_name=self.name)
return True return True
@ -57,7 +57,7 @@ class RagTime(Panico):
self.alt_text = '2🃏 | 👤😱' self.alt_text = '2🃏 | 👤😱'
def play_card(self, player, against, _with): def play_card(self, player, against, _with):
if against != None and _with != None: if against is not None and _with is not None:
player.game.deck.scrap(_with) player.game.deck.scrap(_with)
super().play_card(player, against=against) super().play_card(player, against=against)
return True return True
@ -75,7 +75,7 @@ class Rissa(CatBalou):
self.alt_text = '2🃏 | 👤💃' self.alt_text = '2🃏 | 👤💃'
def play_card(self, player, against, _with): def play_card(self, player, against, _with):
if _with != None: if _with is not None:
if not any((p != player and (len(p.hand)+len(p.equipment)) > 0 for p in player.game.players)): if not any((p != player and (len(p.hand)+len(p.equipment)) > 0 for p in player.game.players)):
return False return False
#se sono qui vuol dire che ci sono giocatori con carte in mano oltre a me #se sono qui vuol dire che ci sono giocatori con carte in mano oltre a me
@ -104,7 +104,7 @@ class SpringField(Card):
self.alt_text = '2🃏 | 👤💥' self.alt_text = '2🃏 | 👤💥'
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None and _with != None: if against is not None and _with is not None:
player.game.deck.scrap(_with) player.game.deck.scrap(_with)
super().play_card(player, against=against) super().play_card(player, against=against)
player.game.attack(player, against, card_name=self.name) player.game.attack(player, against, card_name=self.name)
@ -123,7 +123,7 @@ class Tequila(Card):
self.alt_text = "2🃏 | 👤🍺" self.alt_text = "2🃏 | 👤🍺"
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None and _with != None: if against is not None and _with is not None:
G.sio.emit('chat_message', room=player.game.name, data=f'_play_card_for|{player.name}|{self.name}|{against}') G.sio.emit('chat_message', room=player.game.name, data=f'_play_card_for|{player.name}|{self.name}|{against}')
player.game.deck.scrap(_with) player.game.deck.scrap(_with)
player.game.get_player_named(against).lives = min(player.game.get_player_named(against).lives+1, player.game.get_player_named(against).max_lives) player.game.get_player_named(against).lives = min(player.game.get_player_named(against).lives+1, player.game.get_player_named(against).max_lives)
@ -141,7 +141,7 @@ class Whisky(Card):
self.alt_text = '2🃏 | 🍺🍺' self.alt_text = '2🃏 | 🍺🍺'
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if _with != None: if _with is not None:
super().play_card(player, against=against) super().play_card(player, against=against)
player.game.deck.scrap(_with) player.game.deck.scrap(_with)
player.lives = min(player.lives+2, player.max_lives) player.lives = min(player.lives+2, player.max_lives)
@ -366,7 +366,7 @@ class Pepperbox(Bang):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if self.can_be_used_now: if self.can_be_used_now:
if against != None: if against is not None:
Card.play_card(self, player, against=against) Card.play_card(self, player, against=against)
player.game.attack(player, against, card_name=self.name) player.game.attack(player, against, card_name=self.name)
return True return True
@ -391,7 +391,7 @@ class FucileDaCaccia(Card):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if self.can_be_used_now: if self.can_be_used_now:
if against != None: if against is not None:
super().play_card(player, against=against) super().play_card(player, against=against)
player.game.attack(player, against, card_name=self.name) player.game.attack(player, against, card_name=self.name)
return True return True

View File

@ -45,7 +45,7 @@ class SerpenteASonagli(Card):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if (player.game.check_event(ce.IlGiudice)) or not self.can_be_used_now: if (player.game.check_event(ce.IlGiudice)) or not self.can_be_used_now:
return False return False
if against != None: if against is not None:
self.can_be_used_now = False self.can_be_used_now = False
G.sio.emit('chat_message', room=player.game.name, G.sio.emit('chat_message', room=player.game.name,
data=f'_play_card_against|{player.name}|{self.name}|{against}') data=f'_play_card_against|{player.name}|{self.name}|{against}')
@ -68,7 +68,7 @@ class Taglia(Card):
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if (player.game.check_event(ce.IlGiudice)) or not self.can_be_used_now: if (player.game.check_event(ce.IlGiudice)) or not self.can_be_used_now:
return False return False
if against != None: if against is not None:
self.can_be_used_now = False self.can_be_used_now = False
G.sio.emit('chat_message', room=player.game.name, G.sio.emit('chat_message', room=player.game.name,
data=f'_play_card_against|{player.name}|{self.name}|{against}') data=f'_play_card_against|{player.name}|{self.name}|{against}')
@ -100,7 +100,7 @@ class Tomahawk(Card):
self.need_target = True self.need_target = True
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None and player.game.can_card_reach(self, player, against): if against is not None and player.game.can_card_reach(self, player, against):
super().play_card(player, against=against) super().play_card(player, against=against)
player.game.attack(player, against, card_name=self.name) player.game.attack(player, against, card_name=self.name)
return True return True
@ -125,7 +125,7 @@ class Sventagliata(Bang): # : conta come un normale BANG! del turno. Il BANG! se
self.need_target = True self.need_target = True
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None: if against is not None:
t = player.game.get_player_named(against) t = player.game.get_player_named(against)
player.available_cards = [dict(p, **{'original_target':against}) for p in player.game.get_visible_players(t) if p['name'] != player.name and p['name'] != t.name and p['dist']] player.available_cards = [dict(p, **{'original_target':against}) for p in player.game.get_visible_players(t) if p['name'] != player.name and p['name'] != t.name and p['dist']]
if len(player.available_cards) > 0: if len(player.available_cards) > 0:
@ -145,7 +145,7 @@ class Salvo(Card): # puoi anche prevenire un danno inferto da te, duello?
self.need_target = True self.need_target = True
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None: if against is not None:
#TODO #TODO
# super().play_card(player, against=against) # super().play_card(player, against=against)
# player.game.attack(player, against, card_name=self.name) # player.game.attack(player, against, card_name=self.name)
@ -161,7 +161,7 @@ class Mira(Card):
self.need_with = True self.need_with = True
def play_card(self, player, against, _with=None): def play_card(self, player, against, _with=None):
if against != None: if against is not None:
#TODO #TODO
# super().play_card(player, against=against) # super().play_card(player, against=against)
# player.game.attack(player, against, card_name=self.name) # player.game.attack(player, against, card_name=self.name)

View File

@ -145,7 +145,7 @@ class Game:
continue continue
player = [p for p in self.players if p.name == cmd[0]][0] player = [p for p in self.players if p.name == cmd[0]][0]
if cmd[1] == 'set_character': if cmd[1] == 'set_character':
if player.character != None and isinstance(player.real_character, chd.VeraCuster): if player.character is not None and isinstance(player.real_character, chd.VeraCuster):
player.set_available_character([p.character for p in self.get_alive_players() if p != player]) player.set_available_character([p.character for p in self.get_alive_players() if p != player])
player.set_character(cmd[2]) player.set_character(cmd[2])
if cmd[1] == 'draw': if cmd[1] == 'draw':
@ -184,11 +184,11 @@ class Game:
def notify_room(self, sid=None): def notify_room(self, sid=None):
if any((p.character == None for p in self.players)) or sid: if any((p.character is None for p in self.players)) or sid:
G.sio.emit('room', room=self.name if not sid else sid, data={ G.sio.emit('room', room=self.name if not sid else sid, data={
'name': self.name, 'name': self.name,
'started': self.started, 'started': self.started,
'players': [{'name':p.name, 'ready': p.character != None, 'is_bot': p.is_bot, 'avatar': p.avatar} for p in self.players], 'players': [{'name':p.name, 'ready': p.character is not None, 'is_bot': p.is_bot, 'avatar': p.avatar} for p in self.players],
'password': self.password, 'password': self.password,
'is_competitive': self.is_competitive, 'is_competitive': self.is_competitive,
'disconnect_bot': self.disconnect_bot, 'disconnect_bot': self.disconnect_bot,
@ -255,7 +255,7 @@ class Game:
def notify_character_selection(self): def notify_character_selection(self):
self.notify_room() self.notify_room()
if not any((p.character == None for p in self.players)): if not any((p.character is None for p in self.players)):
for i in range(len(self.players)): for i in range(len(self.players)):
print(self.name, self.players[i].name, self.players[i].character) print(self.name, self.players[i].name, self.players[i].character)
G.sio.emit('chat_message', room=self.name, data=f'_choose_character|{self.players[i].name}|{self.players[i].character.name}') G.sio.emit('chat_message', room=self.name, data=f'_choose_character|{self.players[i].name}|{self.players[i].character.name}')
@ -282,7 +282,7 @@ class Game:
if self.started: if self.started:
return return
print(f'{self.name}: GAME IS STARING') print(f'{self.name}: GAME IS STARING')
if SEED == None: if SEED is None:
import time import time
SEED = int(time.time()) SEED = int(time.time())
print(f'{self.name}: SEED IS {SEED}') print(f'{self.name}: SEED IS {SEED}')
@ -582,7 +582,7 @@ class Game:
self.player_bangs = 0 self.player_bangs = 0
if isinstance(self.players[self.turn].role, roles.Sheriff) or ((self.initial_players == 3 and isinstance(self.players[self.turn].role, roles.Vice) and not self.players[self.turn].is_ghost) or (self.initial_players == 3 and any((p for p in self.players if p.is_dead and p.role.name == 'Vice')) and isinstance(self.players[self.turn].role, roles.Renegade))): if isinstance(self.players[self.turn].role, roles.Sheriff) or ((self.initial_players == 3 and isinstance(self.players[self.turn].role, roles.Vice) and not self.players[self.turn].is_ghost) or (self.initial_players == 3 and any((p for p in self.players if p.is_dead and p.role.name == 'Vice')) and isinstance(self.players[self.turn].role, roles.Renegade))):
self.deck.flip_event() self.deck.flip_event()
if len(self.deck.event_cards) > 0 and self.deck.event_cards[0] != None: if len(self.deck.event_cards) > 0 and self.deck.event_cards[0] is not None:
print(f'{self.name}: flip new event {self.deck.event_cards[0].name}') print(f'{self.name}: flip new event {self.deck.event_cards[0].name}')
G.sio.emit('chat_message', room=self.name, data={'color': f'orange','text':f'_flip_event|{self.deck.event_cards[0].name}'}) G.sio.emit('chat_message', room=self.name, data={'color': f'orange','text':f'_flip_event|{self.deck.event_cards[0].name}'})
if self.check_event(ce.DeadMan): if self.check_event(ce.DeadMan):
@ -640,21 +640,21 @@ class Game:
def notify_event_card(self, sid=None): def notify_event_card(self, sid=None):
if len(self.deck.event_cards) > 0: if len(self.deck.event_cards) > 0:
room = self.name if sid == None else sid room = self.name if sid is None else sid
if self.deck.event_cards[0] != None: if self.deck.event_cards[0] is not None:
G.sio.emit('event_card', room=room, data=self.deck.event_cards[0].__dict__) G.sio.emit('event_card', room=room, data=self.deck.event_cards[0].__dict__)
else: else:
G.sio.emit('event_card', room=room, data=None) G.sio.emit('event_card', room=room, data=None)
def notify_gold_rush_shop(self, sid=None): def notify_gold_rush_shop(self, sid=None):
if 'gold_rush' in self.expansions and self.deck and self.deck.shop_cards and len(self.deck.shop_cards) > 0: if 'gold_rush' in self.expansions and self.deck and self.deck.shop_cards and len(self.deck.shop_cards) > 0:
room = self.name if sid == None else sid room = self.name if sid is None else sid
print(f'{self.name}: gold_rush_shop room={room}, data={self.deck.shop_cards}') print(f'{self.name}: gold_rush_shop room={room}, data={self.deck.shop_cards}')
G.sio.emit('gold_rush_shop', room=room, data=json.dumps(self.deck.shop_cards, default=lambda o: o.__dict__)) G.sio.emit('gold_rush_shop', room=room, data=json.dumps(self.deck.shop_cards, default=lambda o: o.__dict__))
def notify_scrap_pile(self, sid=None): def notify_scrap_pile(self, sid=None):
print(f'{self.name}: scrap') print(f'{self.name}: scrap')
room = self.name if sid == None else sid room = self.name if sid is None else sid
if self.deck.peek_scrap_pile(): if self.deck.peek_scrap_pile():
G.sio.emit('scrap', room=room, data=self.deck.peek_scrap_pile().__dict__) G.sio.emit('scrap', room=room, data=self.deck.peek_scrap_pile().__dict__)
else: else:
@ -767,7 +767,7 @@ class Game:
attacker_role = None attacker_role = None
if player.attacker and player.attacker in self.players: if player.attacker and player.attacker in self.players:
attacker_role = player.attacker.role attacker_role = player.attacker.role
winners = [p for p in self.players if p.role != None and p.role.on_player_death([p for p in self.get_alive_players() if not p.is_ghost], initial_players=self.initial_players, dead_role=player.role, attacker_role=attacker_role)] winners = [p for p in self.players if p.role is not None and p.role.on_player_death([p for p in self.get_alive_players() if not p.is_ghost], initial_players=self.initial_players, dead_role=player.role, attacker_role=attacker_role)]
if not self.attack_in_progress and len(winners) > 0 and not self.someone_won: if not self.attack_in_progress and len(winners) > 0 and not self.someone_won:
return self.announces_winners(winners) return self.announces_winners(winners)
elif len(winners) > 0 and not self.someone_won: # non tutti hanno risposto, ma ci sono vincitori. elif len(winners) > 0 and not self.someone_won: # non tutti hanno risposto, ma ci sono vincitori.
@ -826,7 +826,7 @@ class Game:
self.next_turn() self.next_turn()
def check_event(self, ev): def check_event(self, ev):
if self.deck == None or len(self.deck.event_cards) == 0: return False if self.deck is None or len(self.deck.event_cards) == 0: return False
return isinstance(self.deck.event_cards[0], ev) return isinstance(self.deck.event_cards[0], ev)
def get_visible_players(self, player: pl.Player): # returns a dictionary because we need to add the distance def get_visible_players(self, player: pl.Player): # returns a dictionary because we need to add the distance

View File

@ -59,7 +59,7 @@ class Player:
if r.status_code == 200: if r.status_code == 200:
res = r.json() res = r.json()
print(res) print(res)
if res["avatar"] == None: if res["avatar"] is None:
self.avatar = robot_pictures[randrange(len(robot_pictures))] self.avatar = robot_pictures[randrange(len(robot_pictures))]
else: else:
self.avatar = f'https://cdn.discordapp.com/avatars/{res["id"]}/{res["avatar"]}.png' self.avatar = f'https://cdn.discordapp.com/avatars/{res["id"]}/{res["avatar"]}.png'
@ -161,7 +161,7 @@ class Player:
def set_character(self, character: str): def set_character(self, character: str):
print(self.available_characters, character) print(self.available_characters, character)
if self.character == None: if self.character is None:
try: try:
self.character = next(x for x in self.available_characters if x.name == character) self.character = next(x for x in self.available_characters if x.name == character)
except: except:
@ -300,14 +300,14 @@ class Player:
G.sio.emit('self', room=self.sid, data=json.dumps(ser, default=lambda o: o.__dict__)) G.sio.emit('self', room=self.sid, data=json.dumps(ser, default=lambda o: o.__dict__))
def bot_spin(self): def bot_spin(self):
while self.is_bot and self.game != None and not self.game.shutting_down: while self.is_bot and self.game is not None and not self.game.shutting_down:
G.sio.sleep(max(0.2, uniform(self.game.bot_speed/2-0.1, self.game.bot_speed))) G.sio.sleep(max(0.2, uniform(self.game.bot_speed/2-0.1, self.game.bot_speed)))
if self.lives > 0 or self.is_ghost: if self.lives > 0 or self.is_ghost:
self.bot_logic() self.bot_logic()
def bot_logic(self): def bot_logic(self):
if self.game == None or self.game.shutting_down: return if self.game is None or self.game.shutting_down: return
if self.pending_action != None and self.pending_action != PendingAction.WAIT: if self.pending_action is not None and self.pending_action != PendingAction.WAIT:
# eventlet.sleep(uniform(self.game.bot_speed/2-0.1, self.game.bot_speed)) # eventlet.sleep(uniform(self.game.bot_speed/2-0.1, self.game.bot_speed))
pass pass
else: else:
@ -480,7 +480,7 @@ class Player:
self.choose_text = 'choose_fratelli_di_sangue' self.choose_text = 'choose_fratelli_di_sangue'
self.pending_action = PendingAction.CHOOSE self.pending_action = PendingAction.CHOOSE
self.is_giving_life = True self.is_giving_life = True
elif self.game.check_event(ceh.NuovaIdentita) and self.not_chosen_character != None and not again: elif self.game.check_event(ceh.NuovaIdentita) and self.not_chosen_character is not None and not again:
self.available_cards = [self.character, self.not_chosen_character] self.available_cards = [self.character, self.not_chosen_character]
self.choose_text = 'choose_nuova_identita' self.choose_text = 'choose_nuova_identita'
self.pending_action = PendingAction.CHOOSE self.pending_action = PendingAction.CHOOSE
@ -595,7 +595,7 @@ class Player:
pickable_cards = 1 + self.character.pick_mod pickable_cards = 1 + self.character.pick_mod
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 == None: if self.is_my_turn and self.attacker is None:
for i in range(len(self.equipment)): for i in range(len(self.equipment)):
if i < len(self.equipment) and isinstance(self.equipment[i], cs.Dinamite): if i < len(self.equipment) and isinstance(self.equipment[i], cs.Dinamite):
while pickable_cards > 0: while pickable_cards > 0:
@ -708,12 +708,12 @@ class Player:
return card.play_card(self) return card.play_card(self)
card: cs.Card = self.hand.pop(hand_index) if hand_index < len(self.hand) else self.equipment.pop(hand_index-len(self.hand)) card: cs.Card = self.hand.pop(hand_index) if hand_index < len(self.hand) else self.equipment.pop(hand_index-len(self.hand))
withCard: cs.Card = None withCard: cs.Card = None
if _with != None: if _with is not None:
withCard = self.hand.pop(_with) if hand_index > _with else self.hand.pop(_with - 1) withCard = self.hand.pop(_with) if hand_index > _with else self.hand.pop(_with - 1)
print(self.name, 'is playing ', card, ' against:', against, ' with:', _with) print(self.name, 'is playing ', card, ' against:', against, ' with:', _with)
did_play_card = False did_play_card = False
event_blocks_card = (self.game.check_event(ce.IlGiudice) and (card.is_equipment or (card.usable_next_turn and not card.can_be_used_now))) or (self.game.check_event(ce.Lazo) and card.usable_next_turn and card.can_be_used_now) or ((self.game.check_event(ceh.Manette) and card.suit != self.committed_suit_manette) and not (card.usable_next_turn and card.can_be_used_now)) event_blocks_card = (self.game.check_event(ce.IlGiudice) and (card.is_equipment or (card.usable_next_turn and not card.can_be_used_now))) or (self.game.check_event(ce.Lazo) and card.usable_next_turn and card.can_be_used_now) or ((self.game.check_event(ceh.Manette) and card.suit != self.committed_suit_manette) and not (card.usable_next_turn and card.can_be_used_now))
if not(against != None and (self.game.get_player_named(against).character.check(self.game, chd.ApacheKid) or any((isinstance(c, grc.Calumet) for c in self.game.get_player_named(against).gold_rush_equipment))) and card.check_suit(self.game, [cs.Suit.DIAMONDS])) or (isinstance(card, grc.ShopCard) and card.kind == grc.ShopCardKind.BLACK) and not event_blocks_card: if not(against is not None and (self.game.get_player_named(against).character.check(self.game, chd.ApacheKid) or any((isinstance(c, grc.Calumet) for c in self.game.get_player_named(against).gold_rush_equipment))) and card.check_suit(self.game, [cs.Suit.DIAMONDS])) or (isinstance(card, grc.ShopCard) and card.kind == grc.ShopCardKind.BLACK) and not event_blocks_card:
if (against == self.name and not isinstance(card, csd.Tequila) and not isinstance(card, cs.Panico) and not isinstance(card, cs.CatBalou)) or event_blocks_card: if (against == self.name and not isinstance(card, csd.Tequila) and not isinstance(card, cs.Panico) and not isinstance(card, cs.CatBalou)) or event_blocks_card:
did_play_card = False did_play_card = False
else: else:
@ -1119,7 +1119,7 @@ class Player:
self.attacking_card = card_name self.attacking_card = card_name
print(f'attacker -> {attacker}') print(f'attacker -> {attacker}')
self.mancato_needed = 1 if not double else 2 self.mancato_needed = 1 if not double else 2
if card_index != None: if card_index is not None:
self.dmg_card_index = card_index self.dmg_card_index = card_index
else: else:
self.dmg_card_index = -1 self.dmg_card_index = -1
@ -1260,7 +1260,7 @@ class Player:
self.attacker = None self.attacker = None
def take_no_damage_response(self): def take_no_damage_response(self):
if self.dmg_card_index != None and self.dmg_card_index != -1 and self.game.check_event(ce.Rimbalzo): if self.dmg_card_index is not None and self.dmg_card_index != -1 and self.game.check_event(ce.Rimbalzo):
self.game.deck.scrap(self.equipment.pop(self.dmg_card_index)) self.game.deck.scrap(self.equipment.pop(self.dmg_card_index))
self.dmg_card_index = -1 self.dmg_card_index = -1
self.mancato_needed = 0 self.mancato_needed = 0

View File

@ -40,7 +40,7 @@ class Vice(Role):
def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None):
if initial_players == 3 and len(alive_players) == 1: if initial_players == 3 and len(alive_players) == 1:
return True return True
elif initial_players == 3 and attacker_role != None: elif initial_players == 3 and attacker_role is not None:
return isinstance(dead_role, Renegade) and isinstance(attacker_role, Vice) return isinstance(dead_role, Renegade) and isinstance(attacker_role, Vice)
elif initial_players != 3 and not any((isinstance(p.role, Outlaw) or isinstance(p.role, Renegade) for p in alive_players)): elif initial_players != 3 and not any((isinstance(p.role, Outlaw) or isinstance(p.role, Renegade) for p in alive_players)):
print("The Vice won!") print("The Vice won!")
@ -60,7 +60,7 @@ class Outlaw(Role):
def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None):
if initial_players == 3 and len(alive_players) == 1: if initial_players == 3 and len(alive_players) == 1:
return True return True
elif initial_players == 3 and attacker_role != None: elif initial_players == 3 and attacker_role is not None:
return isinstance(dead_role, Vice) and isinstance(attacker_role, Outlaw) return isinstance(dead_role, Vice) and isinstance(attacker_role, Outlaw)
elif (initial_players != 3 and (not any((isinstance(p.role, Sheriff) for p in alive_players))) elif (initial_players != 3 and (not any((isinstance(p.role, Sheriff) for p in alive_players)))
and (any((isinstance(p.role, Outlaw) for p in alive_players)) and (any((isinstance(p.role, Outlaw) for p in alive_players))
@ -82,7 +82,7 @@ class Renegade(Role):
def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None): def on_player_death(self, alive_players: list, initial_players: int, dead_role=None, attacker_role=None):
if initial_players == 3 and len(alive_players) == 1: if initial_players == 3 and len(alive_players) == 1:
return True return True
elif initial_players == 3 and attacker_role != None: elif initial_players == 3 and attacker_role is not None:
return isinstance(dead_role, Outlaw) and isinstance(attacker_role, Renegade) return isinstance(dead_role, Outlaw) and isinstance(attacker_role, Renegade)
elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0].role, Renegade): elif initial_players != 3 and len(alive_players) == 1 and isinstance(alive_players[0].role, Renegade):
print("The Renegade won!") print("The Renegade won!")

View File

@ -127,7 +127,7 @@ def set_username(sid, username):
sio.save_session(sid, Player(username["name"], sid, discord_token=dt)) sio.save_session(sid, Player(username["name"], sid, discord_token=dt))
print(f'{sid} is now {username}') print(f'{sid} is now {username}')
advertise_lobbies() advertise_lobbies()
elif ses.game == None or not ses.game.started: elif ses.game is None or not ses.game.started:
username = username["name"] username = username["name"]
print(f'{sid} changed username to {username}') print(f'{sid} changed username to {username}')
prev = ses.name prev = ses.name
@ -149,7 +149,7 @@ def get_me(sid, data):
else: else:
dt = data["discord_token"] if 'discord_token' in data else None dt = data["discord_token"] if 'discord_token' in data else None
sio.save_session(sid, Player('player', sid, discord_token=dt)) sio.save_session(sid, Player('player', sid, discord_token=dt))
if 'replay' in data and data['replay'] != None: if 'replay' in data and data['replay'] is not None:
create_room(sid, data['replay']) create_room(sid, data['replay'])
sid = sio.get_session(sid) sid = sio.get_session(sid)
sid.game.is_hidden = True sid.game.is_hidden = True
@ -170,9 +170,9 @@ def get_me(sid, data):
join_room(sid, data) join_room(sid, data)
elif room.started: elif room.started:
print('room exists') print('room exists')
if data['username'] != None and any((p.name == data['username'] for p in room.players if (p.is_bot or (dt != None and p.discord_token == dt) or p.sid == None))): if data['username'] is not None and any((p.name == data['username'] for p in room.players if (p.is_bot or (dt is not None and p.discord_token == dt) or p.sid is None))):
print('getting inside the bot') print('getting inside the bot')
bot = [p for p in room.players if (p.is_bot or (dt != None and p.discord_token == dt) or p.sid == None) and p.name == data['username']][0] bot = [p for p in room.players if (p.is_bot or (dt is not None and p.discord_token == dt) or p.sid is None) and p.name == data['username']][0]
bot.sid = sid bot.sid = sid
bot.is_bot = False bot.is_bot = False
sio.enter_room(sid, room.name) sio.enter_room(sid, room.name)
@ -202,7 +202,7 @@ def get_me(sid, data):
sio.emit('me', data={'error':'Wrong password/Cannot connect'}, room=sid) sio.emit('me', data={'error':'Wrong password/Cannot connect'}, room=sid)
else: else:
sio.emit('me', data=p.name, room=sid) sio.emit('me', data=p.name, room=sid)
if data['username'] == None or any((pl.name == data['username'] for pl in p.game.players if not ((dt != None and pl.discord_token == dt) or pl.sid == None))): if data['username'] is None or any((pl.name == data['username'] for pl in p.game.players if not ((dt is not None and pl.discord_token == dt) or pl.sid is None))):
sio.emit('change_username', room=sid) sio.emit('change_username', room=sid)
else: else:
sio.emit('chat_message', room=p.game.name, data=f"_change_username|{p.name}|{data['username']}") sio.emit('chat_message', room=p.game.name, data=f"_change_username|{p.name}|{data['username']}")

View File

@ -6,7 +6,7 @@ def test_card_flip():
g = Game('test') g = Game('test')
g.deck = Deck(g) g.deck = Deck(g)
l = len(g.deck.cards) l = len(g.deck.cards)
assert g.deck.pick_and_scrap() != None assert g.deck.pick_and_scrap() is not None
assert len(g.deck.cards) == l - 1 assert len(g.deck.cards) == l - 1
assert len(g.deck.scrap_pile) == 1 assert len(g.deck.scrap_pile) == 1
@ -14,7 +14,7 @@ def test_draw():
g = Game('test') g = Game('test')
g.deck = Deck(g) g.deck = Deck(g)
l = len(g.deck.cards) l = len(g.deck.cards)
assert g.deck.draw(True) != None assert g.deck.draw(True) is not None
assert len(g.deck.cards) == l - 1 assert len(g.deck.cards) == l - 1
assert len(g.deck.scrap_pile) == 0 assert len(g.deck.scrap_pile) == 0
@ -23,7 +23,7 @@ def test_reshuffle():
g.deck = Deck(g) g.deck = Deck(g)
l = len(g.deck.cards) l = len(g.deck.cards)
for i in range(80): for i in range(80):
assert g.deck.pick_and_scrap() != None assert g.deck.pick_and_scrap() is not None
assert len(g.deck.cards) == 79 assert len(g.deck.cards) == 79
assert len(g.deck.scrap_pile) == 1 assert len(g.deck.scrap_pile) == 1
@ -31,7 +31,7 @@ def test_draw_from_scrap():
g = Game('test') g = Game('test')
g.deck = Deck(g) g.deck = Deck(g)
l = len(g.deck.cards) l = len(g.deck.cards)
assert g.deck.pick_and_scrap() != None assert g.deck.pick_and_scrap() is not None
assert g.deck.draw_from_scrap_pile() != None assert g.deck.draw_from_scrap_pile() is not None
assert len(g.deck.cards) == 79 assert len(g.deck.cards) == 79
assert len(g.deck.scrap_pile) == 0 assert len(g.deck.scrap_pile) == 0

View File

@ -14,24 +14,24 @@ def test_game_start():
g.add_player(p2) g.add_player(p2)
p3 = Player('p3', 'p3') p3 = Player('p3', 'p3')
g.add_player(p3) g.add_player(p3)
assert p1.role == None assert p1.role is None
assert p2.role == None assert p2.role is None
assert p3.role == None assert p3.role is None
assert not g.started assert not g.started
g.start_game() g.start_game()
assert g.started assert g.started
assert p1.role != None assert p1.role is not None
assert p2.role != None assert p2.role is not None
assert p3.role != None assert p3.role is not None
assert len(p1.available_characters) == g.characters_to_distribute assert len(p1.available_characters) == g.characters_to_distribute
assert len(p2.available_characters) == g.characters_to_distribute assert len(p2.available_characters) == g.characters_to_distribute
assert len(p3.available_characters) == g.characters_to_distribute assert len(p3.available_characters) == g.characters_to_distribute
p1.set_character(p1.available_characters[0].name) p1.set_character(p1.available_characters[0].name)
assert p1.character != None assert p1.character is not None
p2.set_character(p2.available_characters[0].name) p2.set_character(p2.available_characters[0].name)
assert p2.character != None assert p2.character is not None
p3.set_character(p3.available_characters[0].name) p3.set_character(p3.available_characters[0].name)
assert p3.character != None assert p3.character is not None
assert g.players[g.turn].pending_action == PendingAction.DRAW assert g.players[g.turn].pending_action == PendingAction.DRAW
# test that dodge_city is added to games with more than 8 players # test that dodge_city is added to games with more than 8 players