Add !ready and !unready
This commit is contained in:
parent
57f8f60980
commit
c09ddf4bda
1 changed files with 52 additions and 11 deletions
63
gameloop.py
63
gameloop.py
|
@ -5,7 +5,7 @@ from collections import namedtuple
|
||||||
import cardcast_api
|
import cardcast_api
|
||||||
|
|
||||||
class events(enum.Enum):
|
class events(enum.Enum):
|
||||||
quit, nick_change, status, start, kill, join, leave, players, deck_add, deck_add_random, deck_remove, deck_list, limit, card, cards = range(15)
|
quit, nick_change, status, start, ready, unready, kill, join, leave, players, deck_add, deck_add_random, deck_remove, deck_list, limit, card, cards = range(17)
|
||||||
|
|
||||||
class limit_types(enum.Enum):
|
class limit_types(enum.Enum):
|
||||||
points, rounds = range(2)
|
points, rounds = range(2)
|
||||||
|
@ -41,9 +41,15 @@ def get_event():
|
||||||
old = input('old> ')
|
old = input('old> ')
|
||||||
new = input('new> ')
|
new = input('new> ')
|
||||||
return (events.nick_change, old, new)
|
return (events.nick_change, old, new)
|
||||||
if t == 'start':
|
elif t == 'start':
|
||||||
nick = input('nick> ')
|
nick = input('nick> ')
|
||||||
return (events.start, nick)
|
return (events.start, nick)
|
||||||
|
elif t == 'ready':
|
||||||
|
nick = input('nick> ')
|
||||||
|
return (events.ready, nick)
|
||||||
|
elif t == 'unready':
|
||||||
|
nick = input('nick> ')
|
||||||
|
return (events.unready, nick)
|
||||||
elif t == 'status':
|
elif t == 'status':
|
||||||
return (events.status,)
|
return (events.status,)
|
||||||
elif t == 'kill':
|
elif t == 'kill':
|
||||||
|
@ -265,12 +271,12 @@ def game():
|
||||||
limit_type = {limit_types.rounds: 'rounds', limit_types.points: 'points'}[limit.type]
|
limit_type = {limit_types.rounds: 'rounds', limit_types.points: 'points'}[limit.type]
|
||||||
send('Limit set to %i %s' % (limit.number, limit_type))
|
send('Limit set to %i %s' % (limit.number, limit_type))
|
||||||
|
|
||||||
elif event == events.card:
|
elif event == events.card or event == events.cards:
|
||||||
# Ignore selecting cards if it's not available
|
# Ignore selecting and listing cards if it's not available
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif event == events.cards:
|
elif event == events.ready or event == events.unready:
|
||||||
# Ignore listing cards if it's not available
|
# Ignore readiness commands by default
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -309,7 +315,12 @@ def game():
|
||||||
def game_setup():
|
def game_setup():
|
||||||
nonlocal players
|
nonlocal players
|
||||||
|
|
||||||
|
players_ready = set()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
players_unready = [i for i in players.values() if i not in players_ready]
|
||||||
|
if len(players_unready) == 0: break
|
||||||
|
|
||||||
if len(players) == 0:
|
if len(players) == 0:
|
||||||
send('Lost all players, quiting game setup')
|
send('Lost all players, quiting game setup')
|
||||||
return no_game
|
return no_game
|
||||||
|
@ -317,18 +328,48 @@ def game():
|
||||||
event, *args = get_event()
|
event, *args = get_event()
|
||||||
|
|
||||||
if event == events.status:
|
if event == events.status:
|
||||||
send('Game setup')
|
if len(players_ready) == 0:
|
||||||
|
send('Game setup')
|
||||||
|
else:
|
||||||
|
send('Game setup, waiting for %s to be ready' % ', '.join(i.nick for i in players_unready))
|
||||||
|
|
||||||
elif event == events.start:
|
elif event == events.start:
|
||||||
if len(players) < 2:
|
break
|
||||||
send('Not enough players')
|
|
||||||
else:
|
elif event == events.ready:
|
||||||
return setup_round
|
nick, = args
|
||||||
|
|
||||||
|
# Ignore if not in the game
|
||||||
|
if nick not in players:
|
||||||
|
continue
|
||||||
|
|
||||||
|
player = players[nick]
|
||||||
|
|
||||||
|
if player not in players_ready:
|
||||||
|
players_ready.add(player)
|
||||||
|
|
||||||
|
elif event == events.unready:
|
||||||
|
nick, = args
|
||||||
|
|
||||||
|
# Ignore if not in the game
|
||||||
|
if nick not in players:
|
||||||
|
continue
|
||||||
|
|
||||||
|
player = players[nick]
|
||||||
|
|
||||||
|
if player in players_ready:
|
||||||
|
players_ready.remove(player)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
r = common_handler(event, args)
|
r = common_handler(event, args)
|
||||||
if r is not None: return r
|
if r is not None: return r
|
||||||
|
|
||||||
|
if len(players) < 2:
|
||||||
|
send('Not enough players')
|
||||||
|
return game_setup
|
||||||
|
else:
|
||||||
|
return setup_round
|
||||||
|
|
||||||
def total_calls():
|
def total_calls():
|
||||||
nonlocal decks
|
nonlocal decks
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue