def night(): """Start the second part of the day. The function assumes all polls have been evaluated, and that looking after attacks can begin. The function returns a Mailbox.""" threat = db.get_kill() answer = Mailbox().log("**Results from daily deaths:**") if dy.get_stage() == "Night": return Mailbox().respond("Sure, man. Whatever.") while threat != None: answer = roles.attack(threat[1],threat[2],threat[3],answer) threat = db.get_kill() for player in db.player_list(True): # Give potential night uses user_role = db_get(player,'role') for i in range(len(roles.night_users)): if user_role in roles.night_users[i]: # Give one-time users their one-time power if i == 0: if dy.day_number() == 0: db_set(player,'uses',1) break if user_role in ['White Werewolf'] and dy.day_number() % 2 == 0: i = 1 db_set(player,'uses',i) answer.msg(power.power(user_role),db_get(player,'channel')) break answer.story(evening.evening(db.get_deadies())) db.delete_deadies() # Add polls for player in db.player_list(): if db_get(player,'role') in pos.wolf_pack: for channel_id in db.get_secret_channels('Werewolf'): answer.new_poll(channel_id,'wolf',db.random_wolf(),story_text('wolf')) break for player in db.player_list(): if db_get(player,'role') == 'Cult Leader': for channel_id in db.get_secret_channels('Cult_Leader'): answer.new_poll(channel_id,'cult',db.random_cult(),story_text('cult')) break for channel_id in db.get_secret_channels('Swamp'): answer.new_poll(channel_id,'thing','',story_text('thing')) answer.log("```Night {}```".format(dy.day_number())) dy.set_stage("Night") return answer
def day(): """Start the second part of the day. The function assumes all polls have been evaluated, and that looking after attacks can begin. The function returns a Mailbox.""" threat = db.get_kill() answer = Mailbox().log("**Results from night attacks:**") if dy.get_stage() == "Day": return Mailbox().respond("Sure, man. Whatever.") while threat != None: answer = roles.attack(threat[1], threat[2], threat[3], answer) threat = db.get_kill() for player in db.player_list(True): # Give potential day uses user_role = db_get(player, 'role') for i in range(len(roles.day_users)): if user_role in roles.day_users[i]: # Give one-time users their one-time power if i == 0: if dy.day_number() == 0: db_set(player, 'uses', 1) break db_set(player, 'uses', i) answer.msg(power.power(user_role), db_get(player, 'channel')) break answer.story(morning.story_time(db.get_deadies())) db.delete_deadies() db.delete_hookers() # Add polls if dy.day_number() != 0: answer.new_poll(dy.voting_booth(), 'lynch', '', story_text('lynch')) if dy.get_mayor() == 0: answer.new_poll(dy.voting_booth(), 'Mayor', '', story_text('Mayor')) elif dy.get_reporter() == 0: answer.new_poll(dy.voting_booth(), 'Reporter', '', story_text('Reporter')) dy.next_day() dy.set_stage('Day') answer.log("```Day {}```".format(dy.day_number())) return answer
def power(self, me, victim): if me.undead == True: return Mailbox().respond( "You're undead! You can't use your powers!", me.channel) if me.uses > 0 and me.frozen == False: if me.id == victim.id: return Mailbox().respond( "Whether suicide is an option or not is for you to find out. However, it is not in this game. Try again, please.", me.channel) for player in Game_Control().participants: if player.id == victim.id and player.role.name not in [ "Spectator", "Dead" ]: mail = Mailbox().log( "The **Barber** <@{}> has chosen to assassinate". format(me.id)) if player.souls > 0: mail.log_add( " <@{}>, a soulless **{}** who happened to have a soul protecting them." .format(player.id, player.role.name)) mail.respond( "Though you thought you had cut up your target nicely enough, it seems they have somehow survived! Too bad...", me.channel) return mail if player.role.name == "Immortal": mail.log_add( " <@{}>. This failed, as the **Immortal** does not die to a mere **Barber**." .format(player.id)) mail.respond( "Though you thought you had cut up your target nicely enough, it seems they have somehow survived! Too bad...", me.channel) return mail mail.log_add(" <@{}>, the town's favourite **{}**.") mail.story(barber_kill_story(me.id, player.id)) mail.spam(">kill <@{}> {} 1".format( player.id, player.emoji)) return mail return Mailbox().respond( "Hmmm, it seems like I wasn't able to find the person you were looking for, sorry.", me.channel) return Mailbox().respond( "Sorry, bud! Now is not the time to use your powers!", me.channel)
def start_game(): """This function is triggered at the start of the game. If successful, the function returns a Mailbox. If unsuccessful, the function still returns a Mailbox, but will also confirm the error in the console.""" # Make sure there isn't already a game going on! if dy.get_stage() != "NA": print("ERROR: According to " + dy.dynamic_config + ", there's already a game going on!") return Mailbox().respond( "I'm sorry! A game cannot be started while there's another one going on already!" ) # Choose the roles out of the given role-pool role_pool = [] for choice in view_roles(): for i in range(choice.amount): role_pool.append(choice.role) if len(db.player_list()) > len(role_pool): print( "The game cannot be started while there are less roles available than that there are participants signed up." ) return Mailbox().respond("Not enough roles to distribute available!", True) # If there are enough roles available, make a selection, evaluate the selection, and, if accepted, distribute the roles. if not pos.valid_distribution(role_pool, True): return Mailbox().respond( "I am sorry, but I cannot use an invalid distribution to start the game!", True) answer = Mailbox(True) attempts = 0 while attempts < 1000: attempts += 1 chosen_roles = random.sample(role_pool, len(db.player_list())) if pos.valid_distribution(chosen_roles, True) == True: answer.create_cc("Graveyard", 0, [], [], True) answer.create_cc("Market", 0, [], [], True) answer.create_cc("Reporter", 0, [], [], True) # Assign the roles to all users. user_list = db.player_list() for i in range(len(user_list)): user_id = user_list[i] user_role = chosen_roles[i] db_set(user_id, 'role', user_role) db_set(user_id, 'fakerole', user_role) db_set(user_id, 'channel', config.game_log) answer.log( "{} - <@{}> has received the role of the `{}`!".format( db_get(user_id, 'emoji'), user_id, user_role)) answer.dm( "This message is giving you your role for season `{}` of the *Werewolves* game.\n\n" .format(config.season), user_id) answer.dm_add('Your role is `{}`.\n\n'.format(user_role)) answer.dm_add( "**You are not allowed to share a screenshot of this message!** " ) answer.dm_add( "You can claim whatever you want about your role, but you may under **NO** " ) answer.dm_add( "circumstances show this message in any way to any other participants.\n" ) answer.dm_add( "We hope you are happy with the role you gained, and we hope you'll enjoy the game as much as we do.\n\n" ) answer.dm_add("Good luck... 🌕") if user_role in pos.personal_secrets: answer.create_sc(user_id, user_role) if user_role in pos.shared_secrets: answer.add_to_sc(user_id, user_role) if user_role == "Cult Member": answer.add_to_sc(user_id, "Cult Leader") if user_role in pos.wolf_pack: answer.add_to_sc(user_id, "Werewolf") if user_role == "Bloody Butcher": answer.add_to_sc(user_id, "Butcher") if user_role == "Devil": answer.add_to_sc(user_id, "Demon") if user_role == "Vampire": answer.add_to_sc(user_id, "Undead") if user_role == "Witch": db_set(user_id, 'uses', 3) answer.story( 'The current distribution is {}'.format(chosen_roles)) # TODO answer.story( 'I know, I know. That looks ugly as hell. We\'re trying to make it look good!' ) if "Flute Player" in chosen_roles: answer.create_cc("Flute_Victims", 0, [], [], True) # If the four horsemen are part of the game, assign numbers to all players. if "Horseman" in chosen_roles: nothorse_table = [ user_id for user_id in db.player_list() if db_get(user_id, 'role') != 'Horseman' ] horse_table = [ user_id for user_id in db.player_list() if db_get(user_id, 'role') == 'Horseman' ] nothorse_table.shuffle() horse_table.shuffle() for i in range(4): db_set(horse_table[i], 'horseman', i + 1) for i in range(16): db_set(nothorse_table[i], 'horseman', (i % 4) + 1) # Reset the day timer dy.reset_day() dy.set_stage('Night') return answer.respond( "Very well! The game will start tomorrow morning.") answer.respond("Timeout reached! Your distribution is too crazy!", True) return answer