more progress
This commit is contained in:
parent
6e87f41dcc
commit
5a79919c4d
@ -59,10 +59,25 @@ class Game:
|
|||||||
|
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
"""
|
||||||
|
Cleanup channels as necessary
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
print("Delete is called")
|
||||||
|
|
||||||
|
self.game_over = True
|
||||||
|
if self.village_channel:
|
||||||
|
asyncio.ensure_future(self.village_channel.delete("Werewolf game-over"))
|
||||||
|
|
||||||
|
for c_data in self.p_channels.values():
|
||||||
|
asyncio.ensure_future(c_data["channel"].delete("Werewolf game-over"))
|
||||||
|
|
||||||
async def setup(self, ctx):
|
async def setup(self, ctx):
|
||||||
"""
|
"""
|
||||||
Runs the initial setup
|
Runs the initial setup
|
||||||
|
|
||||||
1. Assign Roles
|
1. Assign Roles
|
||||||
2. Create Channels
|
2. Create Channels
|
||||||
2a. Channel Permissions
|
2a. Channel Permissions
|
||||||
@ -184,11 +199,11 @@ class Game:
|
|||||||
return
|
return
|
||||||
self.can_vote = True
|
self.can_vote = True
|
||||||
|
|
||||||
await asyncio.sleep(120) # 4 minute days
|
await asyncio.sleep(12) # 4 minute days FixMe to 120 later
|
||||||
if check():
|
if check():
|
||||||
return
|
return
|
||||||
await self.village_channel.send(embed=discord.Embed(title="**Two minutes of daylight remain...**"))
|
await self.village_channel.send(embed=discord.Embed(title="**Two minutes of daylight remain...**"))
|
||||||
await asyncio.sleep(120) # 4 minute days
|
await asyncio.sleep(12) # 4 minute days FixMe to 120 later
|
||||||
|
|
||||||
# Need a loop here to wait for trial to end (can_vote?)
|
# Need a loop here to wait for trial to end (can_vote?)
|
||||||
|
|
||||||
@ -293,11 +308,11 @@ class Game:
|
|||||||
return
|
return
|
||||||
await self._notify(6)
|
await self._notify(6)
|
||||||
|
|
||||||
await asyncio.sleep(120) # 2 minutes
|
await asyncio.sleep(12) # 2 minutes FixMe to 120 later
|
||||||
await self.village_channel.send(embed=discord.Embed(title="**Two minutes of night remain...**"))
|
await self.village_channel.send(embed=discord.Embed(title="**Two minutes of night remain...**"))
|
||||||
await asyncio.sleep(90) # 1.5 minutes
|
await asyncio.sleep(9) # 1.5 minutes FixMe to 90 later
|
||||||
await self.village_channel.send(embed=discord.Embed(title="**Thirty seconds until sunrise...**"))
|
await self.village_channel.send(embed=discord.Embed(title="**Thirty seconds until sunrise...**"))
|
||||||
await asyncio.sleep(30) # .5 minutes
|
await asyncio.sleep(3) # .5 minutes FixMe to 3 Later
|
||||||
|
|
||||||
await self._at_night_end()
|
await self._at_night_end()
|
||||||
|
|
||||||
@ -352,12 +367,16 @@ class Game:
|
|||||||
if channel_id not in self.p_channels:
|
if channel_id not in self.p_channels:
|
||||||
self.p_channels[channel_id] = self.default_secret_channel.copy()
|
self.p_channels[channel_id] = self.default_secret_channel.copy()
|
||||||
|
|
||||||
await asyncio.sleep(1) # This will have multiple calls
|
for x in range(10): # Retry 10 times
|
||||||
|
try:
|
||||||
self.p_channels[channel_id]["players"].append(role.player)
|
await asyncio.sleep(1) # This will have multiple calls
|
||||||
|
self.p_channels[channel_id]["players"].append(role.player)
|
||||||
if votegroup:
|
if votegroup is not None:
|
||||||
self.p_channels[channel_id]["votegroup"] = votegroup
|
self.p_channels[channel_id]["votegroup"] = votegroup
|
||||||
|
except AttributeError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
async def join(self, member: discord.Member, channel: discord.TextChannel):
|
async def join(self, member: discord.Member, channel: discord.TextChannel):
|
||||||
"""
|
"""
|
||||||
@ -528,7 +547,7 @@ class Game:
|
|||||||
if source is None:
|
if source is None:
|
||||||
target = self.players[target_id]
|
target = self.players[target_id]
|
||||||
elif self.day_time:
|
elif self.day_time:
|
||||||
target = self.get_day_target(target_id, source)
|
target = await self.get_day_target(target_id, source)
|
||||||
else:
|
else:
|
||||||
target = await self.get_night_target(target_id, source)
|
target = await self.get_night_target(target_id, source)
|
||||||
if source is not None:
|
if source is not None:
|
||||||
@ -541,9 +560,9 @@ class Game:
|
|||||||
await self._visit(target, source) # Visit before killing
|
await self._visit(target, source) # Visit before killing
|
||||||
|
|
||||||
if not target.protected:
|
if not target.protected:
|
||||||
target.alive = False
|
target.alive = False # Set them as dead first
|
||||||
await target.kill(source)
|
await target.role.kill(source) # Notify target that someone is trying to kill them
|
||||||
await self._at_kill(target)
|
await self._at_kill(target) # Notify other roles of the kill attempt
|
||||||
if not target.alive: # Still dead after notifying
|
if not target.alive: # Still dead after notifying
|
||||||
if not self.day_time:
|
if not self.day_time:
|
||||||
self.night_results.append(await self.eval_results(target, source, method))
|
self.night_results.append(await self.eval_results(target, source, method))
|
||||||
@ -563,10 +582,10 @@ class Game:
|
|||||||
await self.dead_perms(self.village_channel, target.member)
|
await self.dead_perms(self.village_channel, target.member)
|
||||||
|
|
||||||
async def get_night_target(self, target_id, source=None):
|
async def get_night_target(self, target_id, source=None):
|
||||||
return self.players[target_id] # For now
|
return self.players[target_id] # ToDo
|
||||||
|
|
||||||
async def get_day_target(self, target_id, source=None):
|
async def get_day_target(self, target_id, source=None):
|
||||||
return self.players[target_id] # For now
|
return self.players[target_id] # ToDo
|
||||||
|
|
||||||
async def get_roles(self, game_code=None):
|
async def get_roles(self, game_code=None):
|
||||||
if game_code is not None:
|
if game_code is not None:
|
||||||
@ -602,7 +621,7 @@ class Game:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
async def dead_perms(self, channel, member):
|
async def dead_perms(self, channel, member):
|
||||||
await channel.set_permissions(member, read_messages=True, send_message=False, add_reactions=False)
|
await channel.set_permissions(member, read_messages=True, send_messages=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)
|
||||||
|
@ -15,7 +15,7 @@ class VoteGroup:
|
|||||||
self.properties = {} # Extra data for other options
|
self.properties = {} # Extra data for other options
|
||||||
|
|
||||||
self.action_list = [
|
self.action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 1), # (Action, Priority)
|
||||||
(self._at_day_start, 0),
|
(self._at_day_start, 0),
|
||||||
(self._at_voted, 0),
|
(self._at_voted, 0),
|
||||||
(self._at_kill, 1),
|
(self._at_kill, 1),
|
||||||
@ -44,11 +44,11 @@ class VoteGroup:
|
|||||||
|
|
||||||
async def _at_kill(self, data=None):
|
async def _at_kill(self, data=None):
|
||||||
if data["player"] in self.players:
|
if data["player"] in self.players:
|
||||||
self.players.pop(data["player"])
|
self.players.remove(data["player"])
|
||||||
|
|
||||||
async def _at_hang(self, data=None):
|
async def _at_hang(self, data=None):
|
||||||
if data["player"] in self.players:
|
if data["player"] in self.players:
|
||||||
self.players.pop(data["player"])
|
self.players.remove(data["player"])
|
||||||
|
|
||||||
async def _at_day_end(self, data=None):
|
async def _at_day_end(self, data=None):
|
||||||
pass
|
pass
|
||||||
@ -89,6 +89,10 @@ class VoteGroup:
|
|||||||
if player.id in self.players:
|
if player.id in self.players:
|
||||||
self.players.remove(player)
|
self.players.remove(player)
|
||||||
|
|
||||||
|
if not self.players:
|
||||||
|
# ToDo: Trigger deletion of votegroup
|
||||||
|
pass
|
||||||
|
|
||||||
async def vote(self, target, author, id):
|
async def vote(self, target, author, id):
|
||||||
"""
|
"""
|
||||||
Receive vote from game
|
Receive vote from game
|
||||||
|
@ -26,7 +26,7 @@ class WolfVote(VoteGroup):
|
|||||||
self.killer = None # Added killer
|
self.killer = None # Added killer
|
||||||
|
|
||||||
self.action_list = [
|
self.action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 1), # (Action, Priority)
|
||||||
(self._at_day_start, 0),
|
(self._at_day_start, 0),
|
||||||
(self._at_voted, 0),
|
(self._at_voted, 0),
|
||||||
(self._at_kill, 1),
|
(self._at_kill, 1),
|
||||||
@ -70,7 +70,9 @@ class WolfVote(VoteGroup):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await self.game.generate_targets(self.channel)
|
await self.game.generate_targets(self.channel)
|
||||||
await self.channel.send(" ".join(player.mention for player in self.players))
|
mention_list = " ".join(player.mention for player in self.players)
|
||||||
|
if mention_list != "":
|
||||||
|
await self.channel.send(mention_list)
|
||||||
self.killer = random.choice(self.players)
|
self.killer = random.choice(self.players)
|
||||||
|
|
||||||
await self.channel.send("{} has been selected as tonight's killer".format(self.killer.member.display_name))
|
await self.channel.send("{} has been selected as tonight's killer".format(self.killer.member.display_name))
|
||||||
|
@ -23,6 +23,11 @@ class Werewolf:
|
|||||||
|
|
||||||
self.games = {} # Active games stored here, id is per guild
|
self.games = {} # Active games stored here, id is per guild
|
||||||
|
|
||||||
|
def __unload(self):
|
||||||
|
print("Unload called")
|
||||||
|
for game in self.games.values():
|
||||||
|
del game
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
async def wwset(self, ctx: commands.Context):
|
async def wwset(self, ctx: commands.Context):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user