fix bot wait and add commands

This commit is contained in:
Alberto Xamin 2020-12-06 19:29:40 +01:00
parent 6abd3bfffe
commit c356917ec2
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
3 changed files with 26 additions and 13 deletions

View File

@ -119,7 +119,8 @@ def join_room(sid, room):
@sio.event
def chat_message(sid, msg):
ses: Player = sio.get_session(sid)
sio.emit('chat_message', room=ses.game.name, data=f'[{ses.name}]: {msg}')
if len(msg) > 0:
if msg[0] == '/':
if '/addbot' in msg and not ses.game.started:
if len(msg.split()) > 1:
for _ in range(int(msg.split()[1])):
@ -132,6 +133,16 @@ def chat_message(sid, msg):
elif '/suicide' in msg and ses.game.started:
ses.lives = 0
ses.notify_self()
elif '/cancelgame' in msg and ses.game.started:
ses.game.reset()
elif '/gameinfo' in msg:
sio.emit('chat_message', room=sid, data=f'info: {ses.game.__dict__}')
elif '/meinfo' in msg:
sio.emit('chat_message', room=sid, data=f'info: {ses.__dict__}')
else:
sio.emit('chat_message', room=sid, data=f'{msg} COMMAND NOT FOUND')
else:
sio.emit('chat_message', room=ses.game.name, data=f'[{ses.name}]: {msg}')
@sio.event
def start_game(sid):

View File

@ -45,6 +45,8 @@ class Game:
self.notify_room()
def add_player(self, player: players.Player):
if player.is_bot and len(self.players) >= 8:
return
if player in self.players or len(self.players) >= 10:
return
if len(self.players) > 7:

View File

@ -174,7 +174,7 @@ class Player:
def bot_logic(self):
if self.game.shutting_down: return
if self.pending_action != PendingAction.WAIT:
if self.pending_action != None and self.pending_action != PendingAction.WAIT:
eventlet.sleep(uniform(0.6, 1.5))
else:
return