def vote(user_id, action, game_state, target_name):
    user_map = UserMap()
    target_id = user_map.get(name=target_name)
    user_name = user_map.get(user_id)

    if not status.player_in_game(game_state, user_id):
        return False, RESPONSE['u_not_in_game']

    if not status.is_player_alive(game_state, user_id):
        return False, RESPONSE['u_not_alive']

    if status.get_current_round(game_state) != 'day':
        return False, RESPONSE['not_day']

    if target_name == 'pass':
        return True, user_name + RESPONSE['pass']

    if not status.player_in_game(game_state, target_id):
        return False, RESPONSE['t_not_in_game']

    if not status.is_player_alive(game_state, target_id):
        return False, RESPONSE['t_not_alive']

    if status.has_voted(game_state, user_id):
        return True, user_name + ' changed vote to ' + '*' + target_name + '*'

    return True, user_name + ' voted for ' + '*' + target_name + '*'
Ejemplo n.º 2
0
    def vote():
        # 1) Make sure player who made the command
        # is in the game
        if not player_in_game(g, user_id):
            return False, MSG['u_not_in_game']
        # is alive
        if not is_player_alive(g, user_id):
            return False, MSG['u_not_alive']
        # only valid during day
        if get_current_round(g) != 'day':
            return False, MSG['not_day']

        # if target_name=pass is okay
        if target_name == 'pass':
            return True, user_name + ' wants to pass.'

        # target is in game
        if not player_in_game(g, target_id):
            return False, MSG['t_not_in_game']
        # target is alive
        if not is_player_alive(g, target_id):
            return False, MSG['t_not_alive']

        # voting again just changes your vote.
        if has_voted(g, user_id):
            return True, user_name + ' changed vote to ' + '*'+target_name + '.*'

        # after each success vote should list all votes.
        return True, user_name + ' voted for ' + '*' + target_name + '.*'
    def check():
        check_game = get_game_state()

        result, message = mod_valid_action(user_id, 'countdown', check_game)
        if not result:
            return False, message

        all_alive = status.get_all_alive(game_state)
        yet_to_vote_list = [player_id for player_id in all_alive if not status.has_voted(game_state, player_id)]
        if len(yet_to_vote_list) > 1:
            return False, 'Countdown cannot start now.'

        yet_to_vote = yet_to_vote_list[0]
        return True, yet_to_vote
Ejemplo n.º 4
0
    def check():
        # who hasn't voted.
        # if round is still day
        check_g = get_game_state() # make sure state hasn't changed.
        result, message = mod_valid_action(user_id, 'countdown', check_g)
        if not result:
            return False, message

        all_alive = get_all_alive(g)
        yet_to_vote_list = [
                p_id for p_id in all_alive
                if not has_voted(g, p_id)]

        if len(yet_to_vote_list) > 1:
            return False, 'Countdown cannot start now.'

        yet_to_vote = yet_to_vote_list[0]
        return True, yet_to_vote