More progress
This commit is contained in:
parent
acc1edd239
commit
f09ea6d2cd
@ -11,7 +11,7 @@ class Game:
|
||||
Base class to run a single game of Werewolf
|
||||
"""
|
||||
|
||||
def __init__(self, role_code=None):
|
||||
def __init__(self, role_code):
|
||||
self.roles = []
|
||||
self.role_code = role_code
|
||||
|
||||
@ -42,6 +42,11 @@ class Game:
|
||||
3. Check Initial role setup (including alerts)
|
||||
4. Start game
|
||||
"""
|
||||
if len(self.players) != self.roles:
|
||||
ctx.send("Players does not match roles, cannot start")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
async def _cycle(self):
|
||||
@ -61,35 +66,70 @@ class Game:
|
||||
"""
|
||||
await self._at_start():
|
||||
|
||||
async def _at_game_start(self):
|
||||
async def _at_game_start(self): # ID 0
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(0)
|
||||
|
||||
asyncio.sleep(60)
|
||||
await self._at_day_start()
|
||||
|
||||
async def _at_day_start(self):
|
||||
async def _at_day_start(self): # ID 1
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(1)
|
||||
|
||||
asyncio.sleep(240) # 4 minute days
|
||||
await self._at_day_end()
|
||||
|
||||
async def _at_vote(self):
|
||||
async def _at_vote(self, target): # ID 2
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(2, target)
|
||||
|
||||
async def _at_kill(self):
|
||||
async def _at_kill(self, target): # ID 3
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(3, target)
|
||||
|
||||
async def _at_hang(self, target): # ID 4
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(4, target)
|
||||
|
||||
async def _at_day_end(self): # ID 5
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(5)
|
||||
|
||||
async def _at_day_end(self):
|
||||
asyncio.sleep(60)
|
||||
await self._at_night_start()
|
||||
|
||||
async def _at_night_start(self):
|
||||
asyncio.sleep(240)
|
||||
async def _at_night_start(self): # ID 6
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(6)
|
||||
|
||||
asyncio.sleep(120)
|
||||
# 2 minutes left
|
||||
asyncio.sleep(90)
|
||||
# 30 seconds left
|
||||
asyncio.sleep(30)
|
||||
|
||||
await self._at_night_end()
|
||||
|
||||
async def _at_night_end(self):
|
||||
self._notify()
|
||||
async def _at_night_end(self): # ID 7
|
||||
if self.game_over:
|
||||
return
|
||||
await self._notify(7)
|
||||
|
||||
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]
|
||||
role_order = [role for role in self.roles if role.priority==i]
|
||||
for role in role_action:
|
||||
tasks.append(asyncio.ensure_future(role.on_event(event))
|
||||
# self.loop.create_task(role.on_event(event))
|
||||
@ -98,7 +138,7 @@ class Game:
|
||||
|
||||
async def join(self, member: discord.Member):
|
||||
"""
|
||||
Joins a game
|
||||
Have a member join a game
|
||||
"""
|
||||
if self.started:
|
||||
return "**Game has already started!**"
|
||||
@ -108,7 +148,27 @@ class Game:
|
||||
|
||||
self.started.append(member)
|
||||
|
||||
return "{} has been added to the game, total players is **{}**".format(member.mention, len(self.players))
|
||||
out = "{} has been added to the game, total players is **{}**".format(member.mention, len(self.players))
|
||||
|
||||
async def quit(self, member: discord.Member):
|
||||
"""
|
||||
Have a member quit a game
|
||||
"""
|
||||
player = await self.get_player_by_member(member)
|
||||
|
||||
if not player:
|
||||
return "You're not in a game!"
|
||||
if self.started:
|
||||
await self.kill()
|
||||
|
||||
if member in self.players:
|
||||
return "{} is already in the game!".format(member.mention)
|
||||
|
||||
self.started.append(member)
|
||||
|
||||
out = "{} has been added to the game, total players is **{}**".format(member.mention, len(self.players))
|
||||
|
||||
|
||||
|
||||
async def get_roles(self, role_code=None):
|
||||
if role_code:
|
||||
|
@ -12,6 +12,7 @@ class Player:
|
||||
def __init__(self, member: discord.Member):
|
||||
self.user = member
|
||||
self.role = None
|
||||
self.id = -1
|
||||
|
||||
self.alive = True
|
||||
self.muted = False
|
||||
@ -22,11 +23,3 @@ class Player:
|
||||
Give this player a role
|
||||
"""
|
||||
self.role = role
|
||||
|
||||
async def join(self, ctx: commands.Context):
|
||||
"""
|
||||
Joins a game
|
||||
"""
|
||||
|
||||
await self.config.guild(ctx.guild).days.set(days)
|
||||
await ctx.send("Success")
|
||||
|
@ -12,24 +12,32 @@ class Role:
|
||||
|
||||
Town:
|
||||
1: Random, 2: Investigative, 3: Protective, 4: Government,
|
||||
5: Killing, 6: Power
|
||||
5: Killing, 6: Power (Special night action)
|
||||
|
||||
Mafia:
|
||||
Werewolf:
|
||||
11: Random, 12: Deception, 15: Killing, 16: Support
|
||||
|
||||
Neutral:
|
||||
21: Benign, 22: Evil, 23: Killing
|
||||
|
||||
|
||||
Example category:
|
||||
category = [1, 5, 6] Could be Veteran
|
||||
category = [1, 5] Could be Bodyguard
|
||||
"""
|
||||
|
||||
random_choice = True # Determines if it can be picked as a random
|
||||
category = [0] # List of enrolled categories
|
||||
priority = 0 # 0 is "No Action"
|
||||
allignment = 0 # 1: Town, 2: Werewolf, 3: Neutral
|
||||
private_channel_id = "" # No private channel
|
||||
unique = False # Only one of this role per game
|
||||
|
||||
def __init__(self):
|
||||
self.player = None
|
||||
self.blocked = False
|
||||
|
||||
async def on_event(self, event):
|
||||
async def on_event(self, event, data):
|
||||
"""
|
||||
Action guide as follows:
|
||||
|
||||
@ -46,22 +54,42 @@ class Role:
|
||||
6. Role altering actions (Cult / Mason)
|
||||
"""
|
||||
|
||||
"""
|
||||
See Game class for event guide
|
||||
"""
|
||||
action_list = [
|
||||
self._at_game_start(data),
|
||||
self._at_day_start(data),
|
||||
self._at_vote(data),
|
||||
self._at_kill(data),
|
||||
self._at_hang(data),
|
||||
self._at_day_end(data),
|
||||
self._at_night_start(data),
|
||||
self._at_night_end(data)
|
||||
]
|
||||
|
||||
await action_list[event]
|
||||
|
||||
|
||||
async def assign_player(self, player):
|
||||
"""
|
||||
Give this role a player
|
||||
"""
|
||||
self.player = player
|
||||
|
||||
async def _at_game_start(self):
|
||||
async def _at_game_start(self, data=None):
|
||||
pass
|
||||
|
||||
async def _at_day_start(self):
|
||||
async def _at_day_start(self, data=None):
|
||||
pass
|
||||
|
||||
async def _at_vote(self):
|
||||
async def _at_vote(self, target=None):
|
||||
pass
|
||||
|
||||
async def _at_kill(self):
|
||||
async def _at_kill(self, target=None):
|
||||
pass
|
||||
|
||||
async def _at_hang(self, target=None):
|
||||
pass
|
||||
|
||||
async def _at_day_end(self):
|
||||
|
@ -36,15 +36,18 @@ class Werewolf:
|
||||
await ctx.send_help()
|
||||
|
||||
@ww.command()
|
||||
async def join(self, ctx, role_code=None):
|
||||
async def join(self, ctx, role_code):
|
||||
"""
|
||||
Joins a game of Werewolf or start a new one
|
||||
"""
|
||||
|
||||
game = self._get_game(ctx, setup_id)
|
||||
out = await game.join(ctx.author)
|
||||
game = self._get_game(ctx.guild, role_code)
|
||||
|
||||
ctx.send(out)
|
||||
if not game:
|
||||
ctx.send("Please provide a role code to get started!")
|
||||
return
|
||||
|
||||
ctx.send(await game.join(ctx.author))
|
||||
|
||||
@ww.command()
|
||||
async def quit(self, ctx):
|
||||
@ -52,18 +55,35 @@ class Werewolf:
|
||||
Quit a game of Werewolf
|
||||
"""
|
||||
|
||||
game = self._get_game(ctx)
|
||||
game = self._get_game(ctx.guild)
|
||||
|
||||
out = await game.quit(ctx.author)
|
||||
|
||||
ctx.send(out)
|
||||
|
||||
def _get_game(self, ctx, role_code):
|
||||
if ctx.guild.id not in self.games:
|
||||
self.games[ctx.guild.id] = Game(role_code)
|
||||
def _get_game(self, guild, role_code = None):
|
||||
if guild.id not in self.games:
|
||||
if not role_code:
|
||||
return None
|
||||
self.games[guild.id] = Game(role_code)
|
||||
|
||||
return self.games[ctx.guild.id]
|
||||
return self.games[guild.id]
|
||||
|
||||
|
||||
async def _game_start(self, game):
|
||||
await game.start()
|
||||
|
||||
|
||||
async def on_message(self, message):
|
||||
if message.author.id == self.bot.user.id:
|
||||
return
|
||||
|
||||
author = message.author
|
||||
channel = message.channel
|
||||
guild = message.guild
|
||||
game = self._get_game(guild)
|
||||
if not game:
|
||||
return
|
||||
|
||||
if channel is game.village_channel:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user