Continued progress
This commit is contained in:
parent
976d041073
commit
acc1edd239
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
74
werewolf/Role.py
Normal file
74
werewolf/Role.py
Normal file
@ -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
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user