diff --git a/GameFiles/Game.py b/GameFiles/Game.py index e457b61..0f0e6db 100644 --- a/GameFiles/Game.py +++ b/GameFiles/Game.py @@ -225,6 +225,18 @@ class Game: def get_enacted_policies(self) -> List[Policy]: return [Policy(policy_str) for policy_str in self.config["enacted"]] + @game_started + def get_nb_policies_to_victory(self, faction: Policy) -> int: + if faction == Policy.LIBERAL: + return self.config["nb_policies_to_victory"][Policy.LIBERAL.value] + else: + return self.config["nb_policies_to_victory"][Policy.FASCIST.value] + + @game_started + @save_on_success + async def set_nb_policies_to_victory(self, faction: Policy, value: int): + self.config["nb_policies_to_victory"][faction.value] = value + @save_on_success async def start(self, player_role: discord.Role, bot_user_id: int): if self.is_started(): @@ -245,6 +257,10 @@ class Game: self.config["drawn"] = None self.config["enacted"] = [] self.config["chaos"] = 0 + self.config["nb_policies_to_victory"] = { + Policy.LIBERAL.value: 5, + Policy.FASCIST.value: 6, + } gm_role = await self.guild.create_role(name = "GM", hoist = True, mentionable = True, permissions = self.guild.default_role.permissions) self.config["gm_role"] = gm_role.id @@ -539,13 +555,13 @@ class Game: message_content = [ f"{self.get_player_role().mention} A **{last_enacted.name}** policy {last_enacted.square_emoji()} has been enacted!", f"In total, **{enacted_count[Policy.LIBERAL]} {Policy.LIBERAL.name}** policies and **{enacted_count[Policy.FASCIST]} {Policy.FASCIST.name}** policies have been enacted", - " ".join([Policy.LIBERAL.square_emoji()] * enacted_count[Policy.LIBERAL] + [":black_small_square:"] * (5 - enacted_count[Policy.LIBERAL])), - " ".join([Policy.FASCIST.square_emoji()] * enacted_count[Policy.FASCIST] + [":black_small_square:"] * (6 - enacted_count[Policy.FASCIST])), + " ".join([Policy.LIBERAL.square_emoji()] * enacted_count[Policy.LIBERAL] + [":black_small_square:"] * (self.get_nb_policies_to_victory(Policy.LIBERAL) - enacted_count[Policy.LIBERAL])), + " ".join([Policy.FASCIST.square_emoji()] * enacted_count[Policy.FASCIST] + [":black_small_square:"] * (self.get_nb_policies_to_victory(Policy.FASCIST) - enacted_count[Policy.FASCIST])), ] if last_enacted == Policy.FASCIST: - if enacted_count[Policy.FASCIST] == 3: + if enacted_count[Policy.FASCIST] == self.get_nb_policies_to_victory(Policy.FASCIST) // 2: message_content.append("Be careful about who you elect as chancellor!") - elif enacted_count[Policy.FASCIST] == 5: + elif enacted_count[Policy.FASCIST] == self.get_nb_policies_to_victory(Policy.FASCIST) - 1: message_content.append(":person_gesturing_no: Veto power unlocked :person_gesturing_no:") await self.get_announcements_channel().send("\n".join(message_content), allowed_mentions = discord.AllowedMentions(roles = True)) diff --git a/SecretBot.py b/SecretBot.py index 57c5ef8..c78edce 100755 --- a/SecretBot.py +++ b/SecretBot.py @@ -417,6 +417,17 @@ class SecretBot(commands.Cog): else: await ctx.reply(":warning: You should do this in a channel that is hidden from the players!") + @commands.command("NbToWin", help = "Set the number of policies needed for a win for each faction") + async def set_nb_policies_to_win(self, ctx: commands.Context, nb_liberals: int, nb_fascist: int): + game = await self.get_running_game_or_error_message(ctx) + await self.check_is_administrator_or_gm(ctx) + if nb_liberals > 1 and nb_fascist > 1: + await game.set_nb_policies_to_victory(Policy.LIBERAL, nb_liberals) + await game.set_nb_policies_to_victory(Policy.FASCIST, nb_fascist) + await ctx.reply(f":white_check_mark: Game ends on {nb_liberals} {Policy.LIBERAL.name} policies or {nb_fascist} {Policy.FASCIST.name} policies") + else: + await ctx.reply(":x: Number of policies required to win must be greater than 1") + if __name__ == '__main__': argparser = argparse.ArgumentParser(description = "Secret Hitler helper bot", formatter_class = argparse.ArgumentDefaultsHelpFormatter)