Technically opens now

fight-fixes
bobloy 7 years ago
parent 8dfbf0972a
commit d5e7ac3432

@ -6,7 +6,8 @@ from datetime import datetime,timedelta
from random import shuffle from random import shuffle
from .builder import parse_code # from .builder import parse_code
class Game: class Game:
""" """
@ -20,7 +21,7 @@ class Game:
} }
def __new__(cls, game_code): def __new__(cls, game_code):
game_code = ["DefaultWerewolf", "Villager", "Villager""] game_code = ["DefaultWerewolf", "Villager", "Villager"]
return Game(game_code) return Game(game_code)
def __init__(self, guild, game_code): def __init__(self, guild, game_code):
@ -48,7 +49,6 @@ class Game:
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
async def setup(self, ctx): async def setup(self, ctx):
""" """
Runs the initial setup Runs the initial setup
@ -97,7 +97,6 @@ class Game:
await vote_group.register_player() await vote_group.register_player()
self.vote_groups[channel_id] = self.p_channels[channel_id]["votegroup"](self, channel) self.vote_groups[channel_id] = self.p_channels[channel_id]["votegroup"](self, channel)
############START Notify structure############ ############START Notify structure############
async def _cycle(self): async def _cycle(self):
""" """
@ -114,7 +113,7 @@ class Game:
and repeat with _at_day_start() again and repeat with _at_day_start() again
""" """
await self._at_day_start(): await self._at_day_start()
async def _at_game_start(self): # ID 0 async def _at_game_start(self): # ID 0
if self.game_over: if self.game_over:
@ -123,7 +122,6 @@ class Game:
await self._notify(0) await self._notify(0)
async def _at_day_start(self): # ID 1 async def _at_day_start(self): # ID 1
if self.game_over: if self.game_over:
return return
@ -188,7 +186,6 @@ class Game:
if not self.can_vote: if not self.can_vote:
await self._at_day_end() await self._at_day_end()
async def _at_kill(self, target): # ID 3 async def _at_kill(self, target): # ID 3
if self.game_over: if self.game_over:
return return
@ -238,15 +235,14 @@ class Game:
async def _notify(self, event, data=None): async def _notify(self, event, data=None):
for i in range(10): for i in range(10):
tasks = [] tasks = []
# Role priorities # Role priorities
role_order = [role for role in self.roles if role.action_list[event][1]==i] role_order = [role for role in self.roles if role.action_list[event][1]==i]
for role in role_order: for role in role_order:
tasks.append(asyncio.ensure_future(role.on_event(event, data)) tasks.append(asyncio.ensure_future(role.on_event(event, data)))
# VoteGroup priorities # VoteGroup priorities
vote_order = [votes for votes in self.vote_groups.values() if votes.action_list[event][1]==i] vote_order = [votes for votes in self.vote_groups.values() if votes.action_list[event][1]==i]
for vote_group in vote_order: for vote_group in vote_order:
tasks.append(asyncio.ensure_future(vote_group.on_event(event, data)) tasks.append(asyncio.ensure_future(vote_group.on_event(event, data)))
self.loop.run_until_complete(asyncio.gather(*tasks)) self.loop.run_until_complete(asyncio.gather(*tasks))
# Run same-priority task simultaneously # Run same-priority task simultaneously
@ -280,7 +276,7 @@ class Game:
if votegroup: if votegroup:
self.p_channels[channel_id]["votegroup"] = votegroup self.p_channels[channel_id]["votegroup"] = votegroup
async def join(self, member: discord.Member, channel: discord.Channel): async def join(self, member: discord.Member, channel: discord.TextChannel):
""" """
Have a member join a game Have a member join a game
""" """
@ -326,8 +322,9 @@ class Game:
if not self.can_vote: if not self.can_vote:
channel.send("Voting is not allowed right now") channel.send("Voting is not allowed right now")
return return
elif channel not in self.p_channels.values():
if channel in self.p_channels.values(): # Not part of the game
return # Don't say anything
try: try:
target = self.players[id] target = self.players[id]
@ -338,6 +335,8 @@ class Game:
channel.send("Not a valid target") channel.send("Not a valid target")
return return
# Now handle village vote or send to votegroup
async def kill(self, target, source=None, method: str=None): async def kill(self, target, source=None, method: str=None):
""" """
Attempt to kill a target Attempt to kill a target
@ -345,14 +344,23 @@ class Game:
Be sure to remove permissions appropriately Be sure to remove permissions appropriately
Important to finish execution before triggering notify Important to finish execution before triggering notify
""" """
pass if not target.protected:
target.alive = False
await self._at_kill(target)
if not target.alive: # Still dead after notifying
await self.dead_perms(target.member)
else:
target.protected = False
async def lynch(self, target): async def lynch(self, target):
""" """
Attempt to lynch a target Attempt to lynch a target
Important to finish execution before triggering notify Important to finish execution before triggering notify
""" """
pass target.alive = False
await self._at_hang(target)
if not target.alive: # Still dead after notifying
await self.dead_perms(target.member)
async def get_roles(self, game_code=None): async def get_roles(self, game_code=None):
if game_code: if game_code:
@ -366,6 +374,10 @@ class Game:
if not self.roles: if not self.roles:
return False return False
async def dead_perms(self, channel, member):
await channel.set_permissions(member, read_messages=True, send_message=False, add_reactions=False)
async def night_perms(self, channel): async def night_perms(self, channel):
await channel.set_permissions(self.guild.default_role, read_messages=False, send_messages=False) await channel.set_permissions(self.guild.default_role, read_messages=False, send_messages=False)
@ -376,7 +388,7 @@ class Game:
if undo: if undo:
await channel.set_permissions(self.guild.default_role, read_messages=False) await channel.set_permissions(self.guild.default_role, read_messages=False)
await channel.set_permissions(member, read_messages=True) await channel.set_permissions(member, read_messages=True)
elif: else:
await channel.set_permissions(self.guild.default_role, read_messages=False, send_messages=False) await channel.set_permissions(self.guild.default_role, read_messages=False, send_messages=False)
await channel.set_permissions(member, read_messages=True, send_messages=True) await channel.set_permissions(member, read_messages=True, send_messages=True)

@ -9,6 +9,7 @@ from datetime import datetime,timedelta
from .game import Game from .game import Game
class Werewolf: class Werewolf:
""" """
Base to host werewolf on a guild Base to host werewolf on a guild
@ -21,7 +22,6 @@ class Werewolf:
default_guild = { default_guild = {
} }
self.config.register_global(**default_global) self.config.register_global(**default_global)
self.config.register_guild(**default_guild) self.config.register_guild(**default_guild)
@ -95,19 +95,5 @@ class Werewolf:
return self.games[guild.id] return self.games[guild.id]
async def _game_start(self, game): async def _game_start(self, game):
await game.start() 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
if channel is game.village_channel:

Loading…
Cancel
Save