From 532b81fa54aa65938e5514c295b8187ba2e5973b Mon Sep 17 00:00:00 2001 From: Elnath Date: Sun, 13 Jun 2021 19:18:53 +0200 Subject: [PATCH] Implemented chaos counter for failed votes --- GameFiles/Game.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/GameFiles/Game.py b/GameFiles/Game.py index 8440ef3..99653fe 100644 --- a/GameFiles/Game.py +++ b/GameFiles/Game.py @@ -168,6 +168,10 @@ class Game: vote_count[self.config["vote"][str(player_id)]] += 1 return vote_count[True] > vote_count[False] + @game_started + def get_chaos(self) -> int: + return self.config["chaos"] + @game_started def get_player_channel_id(self, player: Union[int, discord.Member]) -> int: if isinstance(player, discord.Member): @@ -196,6 +200,7 @@ class Game: self.config["discard"] = [] self.config["drawn"] = None self.config["enacted"] = [] + self.config["chaos"] = 0 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 @@ -366,6 +371,21 @@ class Game: president = self.config["vote"]["president"] chancellor = self.config["vote"]["chancellor"] announcement_content.append(f"Congratulations to president <@{president}> and chancellor <@{chancellor}>!") + if self.config["chaos"] > 0: # If there was some chaos + announcement_content.append(":relaxed: The country has calmed and the chaos counter has been reset") + self.config["chaos"] = 0 # Anyway, the chaos is reset by a successful vote + + else: + chaos = self.config["chaos"] + 1 + if chaos < 3: + self.config["chaos"] = chaos + announcement_content.append( + ":fire: The country slowly descends into chaos " + " ".join([":fire:" for _ in range(chaos)] + [":black_small_square:" for _ in range(3 - chaos)]) + ) + else: # Too many rejected votes throw the country into chaos + announcement_content.append(":fire: :fire: :fire: **The country is thrown into chaos by too many rejected votes** :fire: :fire: :fire:") + tasks.append(asyncio.create_task(self.enact_top_policy(delay = 10))) + tasks.append(asyncio.create_task(self.get_announcements_channel().send("\n".join(announcement_content), allowed_mentions = discord.AllowedMentions(roles = True)))) await asyncio.wait(tasks) self.config["vote"] = None @@ -394,9 +414,25 @@ class Game: self.config["discard"].append(policy_str) self.config["drawn"] = None if len(self.config["deck"]) < 3: - self.config["deck"].extend(self.config["discard"]) - self.config["discard"] = [] - random.shuffle(self.config["deck"]) + self.shuffle_discard_into_deck() + await self.announce_latest_enacted_policy() + + @game_started + @save_on_success + def shuffle_discard_into_deck(self): + self.config["deck"].extend(self.config["discard"]) + self.config["discard"] = [] + random.shuffle(self.config["deck"]) + + @game_started + @save_on_success + async def enact_top_policy(self, delay = 10): + logger.debug(f"[{self.guild.name}] Enacting top policy in {delay} seconds...") + await asyncio.sleep(delay) + self.config["chaos"] = 0 # We reset the counter + self.config["enacted"].append(self.config["deck"].pop(0)) + if len(self.config["deck"]) < 3: + self.shuffle_discard_into_deck() await self.announce_latest_enacted_policy() @game_started