예제 #1
0
def command_startgame(bot, update, rebalance=False):
    log.info('command_startgame called')
    log.info(bot)
    log.info(update)
    cid = update.message.chat_id
    game = GamesController.games.get(cid, None)
    if not game:
        bot.send_message(
            cid,
            "There is no game in this chat. Create a new game with /newgame")
    elif game.board:
        bot.send_message(cid, "The game is already running!")
    elif update.message.from_user.id != game.initiator and bot.getChatMember(
            cid, update.message.from_user.id).status not in ("administrator",
                                                             "creator"):
        bot.send_message(
            game.cid,
            "Only the initiator of the game or a group admin can start the game with /startgame or /startrebalanced"
        )
    elif len(game.playerlist) < 5:
        bot.send_message(
            game.cid,
            "There are not enough players (min. 5, max. 10). Join the game with /join"
        )
    else:
        player_number = len(game.playerlist)
        MainController.inform_players(bot, game, game.cid, player_number)
        MainController.inform_fascists(bot, game, player_number)
        if rebalance and len(game.playerlist) == 6:
            bot.send_message(
                cid,
                "Game started in rebalanced mode. One F will be played at the start to help the poor helpless fascists."
            )
            game.board = Board(player_number, game)
            game.board.state.player_claims.append(
                ['F elected at start of game'])
            game.board.state.fascist_track += 1
        elif rebalance and len(game.playerlist) in [7, 9]:
            removeF = 1 if len(game.playerlist) == 7 else 2
            label = "policy" if removeF == 1 else "policies"
            bot.send_message(
                cid,
                "Game started in rebalanced mode. %d F %s will be removed from the deck for this game, so the liberals at least have a chancce now."
                % (removeF, label))
            game.board = Board(player_number, game, removeF)
            game.board.state.player_claims.append(
                ["%d F %s removed from deck" % (removeF, label)])
        else:
            game.board = Board(player_number, game)
        log.info(game.board)
        log.info("len(games) Command_startgame: " +
                 str(len(GamesController.games)))
        game.shuffle_player_sequence()
        game.board.state.player_counter = 0
        bot.send_message(game.cid, game.board.print_board())
        #group_name = update.message.chat.title
        #bot.send_message(ADMIN, "Game of Secret Hitler started in group %s (%d)" % (group_name, cid))
        MainController.start_round(bot, game)
예제 #2
0
 def __init__(self, playercount, game):
     BaseBoard.__init__(self, playercount, game)
     self.arcanaCards = random.sample(copy.deepcopy(ARCANACARDS),
                                      len(ARCANACARDS))
     self.fateTokens = random.sample(copy.deepcopy(FATETOKENS),
                                     len(FATETOKENS))
     self.fateTokensDiscard = []
     # Se seteara en difficultad el doom inicial
     self.state = State()
예제 #3
0
def command_startgame(update: Update, context: CallbackContext):
	bot = context.bot
	args = context.args
	log.info('command_startgame called')
	groupName = update.message.chat.title
	cid = update.message.chat_id
	game = get_game(cid)
	if not game:
		bot.send_message(cid, "Bu odada henüz bir oyun kurulmamış, lütfen /yenioyun ile bir oyun açın")
	elif game.board:
		bot.send_message(cid, "Oyun çoktan başladı!")
	elif update.message.from_user.id != game.initiator and bot.getChatMember(cid, update.message.from_user.id).status not in ("administrator", "creator"):
		bot.send_message(game.cid, "Yalnızca bu oyunu kuran kişi (veya yönetici) /oyunubaslat ile oyunu başlatabilir")
	elif len(game.playerlist) < 5:
		bot.send_message(game.cid, "Yeterli sayıda oyuncu yok (min. 5, max. 10). Oyuna /katil ile katılabilirsiniz.")
	else:
		player_number = len(game.playerlist)
		MainController.inform_players(bot, game, game.cid, player_number)
		MainController.inform_fascists(bot, game, player_number)
		game.board = Board(player_number, game)
		log.info(game.board)
		log.info("len(games) Command_startgame: " + str(len(GamesController.games)))
		game.shuffle_player_sequence()
		game.board.state.player_counter = 0
		#print_board(bot, game, cid)
		#group_name = update.message.chat.title
		#bot.send_message(ADMIN, "Game of Secret Hitler started in group %s (%d)" % (group_name, cid))		
		MainController.start_round(bot, game)
예제 #4
0
def command_startgame(bot, update):
    log.info('command_startgame called')
    cid = update.message.chat_id
    game = GamesController.games.get(cid, None)
    if not game:
        bot.send_message(cid, "There is no game in this chat. Create a new game with /newgame")
    elif game.board:
        bot.send_message(cid, "The game is already running!")
    elif update.message.from_user.id != game.initiator and bot.getChatMember(cid, update.message.from_user.id).status not in ("administrator", "creator"):
        bot.send_message(game.cid, "Only the initiator of the game or a group admin can start the game with /startgame")
    elif len(game.playerlist) < 5:
        bot.send_message(game.cid, "There are not enough players (min. 5, max. 10). Join the game with /join")
    else:
        player_number = len(game.playerlist)
        MainController.inform_players(bot, game, game.cid, player_number)
        MainController.inform_fascists(bot, game, player_number)
        game.board = Board(player_number, game)
        log.info(game.board)
        log.info("len(games) Command_startgame: " + str(len(GamesController.games)))
        game.shuffle_player_sequence()
        game.board.state.player_counter = 0
        bot.send_message(game.cid, game.board.print_board())
        #group_name = update.message.chat.title
        #bot.send_message(ADMIN, "Game of Secret Hitler started in group %s (%d)" % (group_name, cid))
        MainController.start_round(bot, game)
예제 #5
0
파일: Commands.py 프로젝트: ib90/colordice
def command_startgame(bot, update):
	log.info('command_startgame called')
	groupName = update.message.chat.title
	cid = update.message.chat_id
	game = GamesController.games.get(cid, None)
	if not game:
		bot.send_message(cid, "No hay juego en este chat. Crea un nuevo juego con /newgame")
	elif game.board:
		bot.send_message(cid, "El juego ya ha comenzado!")
	elif update.message.from_user.id != game.initiator and bot.getChatMember(cid, update.message.from_user.id).status not in ("administrator", "creator"):
		bot.send_message(game.cid, "Solo el creador del juego or el admisnitrador del grupo pueden comenzar el juego con /startgame")
	elif len(game.playerlist) < 5:
		bot.send_message(game.cid, "No hay suficientes jugadores (min. 5, max. 10). Uneté al juego con /join")
	else:
		player_number = len(game.playerlist)
		MainController.inform_players(bot, game, game.cid, player_number)
		MainController.inform_fascists(bot, game, player_number)
		game.board = Board(player_number, game)
		log.info(game.board)
		log.info("len(games) Command_startgame: " + str(len(GamesController.games)))
		game.shuffle_player_sequence()
		game.board.state.player_counter = 0
		#print_board(bot, game, cid)
		#group_name = update.message.chat.title
		#bot.send_message(ADMIN, "Game of Secret Hitler started in group %s (%d)" % (group_name, cid))		
		MainController.start_round(bot, game)
예제 #6
0
def command_comecarjogo(bot, update):
    log.info('command_startgame called')
    cid = update.message.chat_id
    game = GamesController.games.get(cid, None)
    if not game:
        bot.send_message(cid, "Não há nenhum jogo neste chat. Crie um novo jogo com /novojogo")
    elif game.board:
        bot.send_message(cid, "O jogo já começou!")
    elif update.message.from_user.id != game.initiator and bot.getChatMember(cid, update.message.from_user.id).status not in ("administrator", "creator"):
            bot.send_message(cid, "Só quem começou o jogo ou o admin do grupo podem comecar o jogo com /comecarjogo, o resto é golpe")
    elif len(game.playerlist) < 5:
        bot.send_message(game.cid, "Não têm jogadores o suficiente na partida (min. 5, máx. 10). Entre no jogo com /participar")
    else:
        player_number = len(game.playerlist)
        MainController.inform_players(bot, game, game.cid, player_number)
        MainController.inform_fascists(bot, game, player_number)
        game.board = Board(player_number, game)
        log.info(game.board)
        log.info("len(games) Command_startgame: " + str(len(GamesController.games)))
        game.shuffle_player_sequence()
        game.board.state.player_counter = 0
        bot.send_message(game.cid, game.board.print_board())
        #group_name = update.message.chat.title
        #bot.send_message(ADMIN, "Game of Secret Hitler started in group %s (%d)" % (group_name, cid))
        MainController.start_round(bot, game)
예제 #7
0
def init_game(bot, game):
	log.info('Game Init called')
	player_number = len(game.playerlist)
	game.board = Board(player_number, game)	
	bot.send_message(game.cid, "Juego iniciado")
	if game.tipo == "LostExpedition":
		init_lost_expedition(bot, game, player_number)
	elif game.tipo == "JustOne":
		JustOneController.init_game(bot, game)
	elif game.tipo == "SayAnything":
		game.create_board()
		SayAnythingController.init_game(bot, game)
	elif game.tipo == "Arcana":
		game.create_board()
		ArcanaController.init_game(bot, game)
예제 #8
0
 def test_board_when_game_is_running(self):
     game = Game(-999, 12345)
     game.board = Board(5, game)
     GamesController.games[-999] = game
     self.updater.dispatcher.add_handler(
         CommandHandler("board", command_board))
     self.updater.start_polling()
     chat = self.cg.get_chat(cid=-999)
     update = self.mg.get_message(chat=chat, text="/board")
     self.bot.insertUpdate(update)
     self.assertEqual(len(self.bot.sent_messages), 1)
     sent = self.bot.sent_messages[0]
     self.assertEqual(sent['method'], "sendMessage")
     self.assertIn("--- Liberal acts ---", sent['text'])
     self.updater.stop()
예제 #9
0
def callback_finish_game_buttons(bot, update):
    callback = update.callback_query
    try:
        #log.info('callback_finish_game_buttons called: %s' % callback.data)
        regex = re.search("(-[0-9]*)\*chooseend\*(.*)\*([0-9]*)",
                          callback.data)
        cid, strcid, opcion, uid, struid = int(
            regex.group(1)), regex.group(1), regex.group(2), int(
                regex.group(3)), regex.group(3)
        mensaje_edit = "Has elegido el diccionario: {0}".format(opcion)
        try:
            bot.edit_message_text(mensaje_edit, cid,
                                  callback.message.message_id)
        except Exception as e:
            bot.edit_message_text(mensaje_edit, uid,
                                  callback.message.message_id)
        game = Commands.get_game(cid)

        # Obtengo el diccionario actual, primero casos no tendre el config y pondre el community
        try:
            dicc = game.configs.get('diccionario', 'community')
        except Exception as e:
            dicc = 'community'

        # Obtengo datos de juego anterior
        groupName = game.groupName
        tipojuego = game.tipo
        modo = game.modo
        descarte = game.board.discards
        # Dependiendo de la opcion veo que como lo inicio
        players = game.playerlist.copy()
        # Creo nuevo juego
        game = Game(cid, uid, groupName, tipojuego, modo)
        GamesController.games[cid] = game
        # Guarda los descartes en configs para asi puedo recuperarlos
        game.configs['discards'] = descarte
        if opcion == "Nuevo":
            bot.send_message(
                cid,
                "Cada jugador puede unirse al juego con el comando /join.\nEl iniciador del juego (o el administrador) pueden unirse tambien y escribir /startgame cuando todos se hayan unido al juego!"
            )
            return
        #log.info('Llego hasta la creacion')
        game.playerlist = players
        # StartGame
        player_number = len(game.playerlist)
        game.board = Board(player_number, game)
        game.player_sequence = []
        game.shuffle_player_sequence()

        if opcion == "Mismo Diccionario":
            #(Beta) Nuevo Partido, mismos jugadores, mismo diccionario
            #log.info('Llego hasta el new2')
            game.configs['diccionario'] = dicc
            finish_config(bot, game, dicc)
        if opcion == "Otro Diccionario":
            #(Beta) Nuevo Partido, mismos jugadores, diferente diccionario
            call_dicc_buttons(bot, game)
    except Exception as e:
        bot.send_message(ADMIN[0],
                         'No se ejecuto el comando debido a: ' + str(e))
        bot.send_message(ADMIN[0], callback.data)
예제 #10
0
	def __init__(self, playercount, game):
		BaseBoard.__init__(self, playercount, game)