From acc1edd23950099759296eada2bc09353fe8f568 Mon Sep 17 00:00:00 2001 From: Bobloy Date: Mon, 12 Mar 2018 14:55:35 -0400 Subject: [PATCH] Continued progress --- werewolf/Game.py | 38 ++++++++++++++++++----- werewolf/Player.py | 10 +++--- werewolf/Role.py | 74 ++++++++++++++++++++++++++++++++++++++++++++ werewolf/Werewolf.py | 3 +- 4 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 werewolf/Role.py diff --git a/werewolf/Game.py b/werewolf/Game.py index 26f902e..704444d 100644 --- a/werewolf/Game.py +++ b/werewolf/Game.py @@ -8,7 +8,7 @@ from .builder import parse_code class Game: """ - Base to host a game of werewolf + Base class to run a single game of Werewolf """ def __init__(self, role_code=None): @@ -27,6 +27,8 @@ class Game: self.village_channel = None self.secret_channels = {} + self.loop = asyncio.get_event_loop() + @@ -59,21 +61,41 @@ class Game: """ await self._at_start(): - async def _at_start(self): - + async def _at_game_start(self): + asyncio.sleep(60) + await self._at_day_start() + async def _at_day_start(self): - + asyncio.sleep(240) # 4 minute days + await self._at_day_end() + async def _at_vote(self): async def _at_kill(self): - + async def _at_day_end(self): - + asyncio.sleep(60) + await self._at_night_start() + async def _at_night_start(self): - + asyncio.sleep(240) + await self._at_night_end() + async def _at_night_end(self): + self._notify() + asyncio.sleep(15) + await self._at_day_start() - + async def _notify(self, event): + for i in range(10): + tasks = [] + role_action = [role for role in self.roles if role.action==i] + for role in role_action: + tasks.append(asyncio.ensure_future(role.on_event(event)) + # self.loop.create_task(role.on_event(event)) + self.loop.run_until_complete(asyncio.gather(*tasks)) + + async def join(self, member: discord.Member): """ Joins a game diff --git a/werewolf/Player.py b/werewolf/Player.py index 944f76e..53fa431 100644 --- a/werewolf/Player.py +++ b/werewolf/Player.py @@ -6,22 +6,22 @@ from datetime import datetime,timedelta class Player: """ - Base to host a game of werewolf + Base player class for Werewolf game """ def __init__(self, member: discord.Member): self.user = member self.role = None + self.alive = True self.muted = False + self.protected = False - async def assign_role(self, role): """ - Base command for this cog. Check help for the commands list. + Give this player a role """ - if ctx.invoked_subcommand is None: - await ctx.send_help() + self.role = role async def join(self, ctx: commands.Context): """ diff --git a/werewolf/Role.py b/werewolf/Role.py new file mode 100644 index 0000000..06442d2 --- /dev/null +++ b/werewolf/Role.py @@ -0,0 +1,74 @@ +import asyncio + +import discord + +from datetime import datetime,timedelta + +class Role: + """ + Base Role class for werewolf game + + Category enrollment guide as follows: + + Town: + 1: Random, 2: Investigative, 3: Protective, 4: Government, + 5: Killing, 6: Power + + Mafia: + 11: Random, 12: Deception, 15: Killing, 16: Support + + Neutral: + 21: Benign, 22: Evil, 23: Killing + """ + + random_choice = True # Determines if it can be picked as a random + category = [0] # List of enrolled categories + priority = 0 # 0 is "No Action" + + def __init__(self): + self.player = None + self.blocked = False + + async def on_event(self, event): + """ + Action guide as follows: + + _at_night_start + 1. Detain actions (Jailer/Kidnapper) + 2. Group discussions and Pick targets + + _at_night_end + 1. Self actions (Veteran) + 2. Target switching and role blocks (bus driver, witch, escort) + 3. Protection / Preempt actions (bodyguard/framer) + 4. Non-disruptive actions (seer/silencer) + 5. Disruptive actions (werewolf kill) + 6. Role altering actions (Cult / Mason) + """ + + async def assign_player(self, player): + """ + Give this role a player + """ + self.player = player + + async def _at_game_start(self): + pass + + async def _at_day_start(self): + pass + + async def _at_vote(self): + pass + + async def _at_kill(self): + pass + + async def _at_day_end(self): + pass + + async def _at_night_start(self): + pass + + async def _at_night_end(self): + pass \ No newline at end of file diff --git a/werewolf/Werewolf.py b/werewolf/Werewolf.py index 3f85ed4..0fa80d9 100644 --- a/werewolf/Werewolf.py +++ b/werewolf/Werewolf.py @@ -11,7 +11,7 @@ from .game import Game class Werewolf: """ - Base to host a game of werewolf + Base to host werewolf on a server """ def __init__(self, bot): @@ -67,4 +67,3 @@ class Werewolf: async def _game_start(self, game): await game.start() -