Maybe dispatch? WIP

pull/147/head
bobloy 4 years ago
parent 7e1a6e108e
commit fe1f11b2eb

@ -5,6 +5,7 @@ from typing import List, Any, Dict, Set, Union
import discord import discord
from redbot.core import commands from redbot.core import commands
from redbot.core.bot import Red
from .builder import parse_code from .builder import parse_code
from .player import Player from .player import Player
@ -34,10 +35,15 @@ class Game:
"**Morning has arrived on day {}..**", "**Morning has arrived on day {}..**",
] ]
night_messages = [
"**Dawn falls on day {}..****"
]
day_vote_count = 3 day_vote_count = 3
def __init__( def __init__(
self, self,
bot: Red,
guild: discord.Guild, guild: discord.Guild,
role: discord.Role = None, role: discord.Role = None,
category: discord.CategoryChannel = None, category: discord.CategoryChannel = None,
@ -45,6 +51,7 @@ class Game:
log_channel: discord.TextChannel = None, log_channel: discord.TextChannel = None,
game_code=None, game_code=None,
): ):
self.bot = bot
self.guild = guild self.guild = guild
self.game_code = game_code self.game_code = game_code
@ -340,6 +347,9 @@ class Game:
await self.village_channel.send( await self.village_channel.send(
"**{} will be put to trial and has 30 seconds to defend themselves**".format( "**{} will be put to trial and has 30 seconds to defend themselves**".format(
target.mention target.mention
),
allowed_mentions=discord.AllowedMentions(
everyone=False, users=[target]
) )
) )
@ -347,11 +357,14 @@ class Game:
await self.speech_perms(self.village_channel, target.member, undo=True) # No one can talk await self.speech_perms(self.village_channel, target.member, undo=True) # No one can talk
message = await self.village_channel.send( message: discord.Message = await self.village_channel.send(
"Everyone will now vote whether to lynch {}\n" "Everyone will now vote whether to lynch {}\n"
"👍 to save, 👎 to lynch\n" "👍 to save, 👎 to lynch\n"
"*Majority rules, no-lynch on ties, " "*Majority rules, no-lynch on ties, "
"vote both or neither to abstain, 15 seconds to vote*".format(target.mention) "vote both or neither to abstain, 15 seconds to vote*".format(target.mention),
allowed_mentions=discord.AllowedMentions(
everyone=False, users=[target]
)
) )
await message.add_reaction("👍") await message.add_reaction("👍")
@ -442,7 +455,7 @@ class Game:
await self.village_channel.send( await self.village_channel.send(
embed=discord.Embed(title="**Thirty seconds until sunrise...**") embed=discord.Embed(title="**Thirty seconds until sunrise...**")
) )
await asyncio.sleep(3) # .5 minutes FixMe to 3 Later await asyncio.sleep(3) # .5 minutes FixMe to 30 Later
await self._at_night_end() await self._at_night_end()
@ -462,19 +475,20 @@ class Game:
async def _notify(self, event, data=None): async def _notify(self, event, data=None):
for i in range(1, 7): # action guide 1-6 (0 is no action) for i in range(1, 7): # action guide 1-6 (0 is no action)
tasks = [] self.bot.dispatch(f"red.fox.werewolf.{event}", data=data, priority=i)
# Role priorities # tasks = []
role_order = [role for role in self.roles if role.action_list[event][1] == i] # # Role priorities
for role in role_order: # role_order = [role for role in self.roles if role.action_list[event][1] == i]
tasks.append(asyncio.ensure_future(role.on_event(event, data), loop=self.loop)) # for role in role_order:
# VoteGroup priorities # tasks.append(asyncio.ensure_future(role.on_event(event, data), loop=self.loop))
vote_order = [vg for vg in self.vote_groups.values() if vg.action_list[event][1] == i] # # VoteGroup priorities
for vote_group in vote_order: # vote_order = [vg for vg in self.vote_groups.values() if vg.action_list[event][1] == i]
tasks.append( # for vote_group in vote_order:
asyncio.ensure_future(vote_group.on_event(event, data), loop=self.loop) # tasks.append(
) # asyncio.ensure_future(vote_group.on_event(event, data), loop=self.loop)
if tasks: # )
await asyncio.gather(*tasks) # if tasks:
# await asyncio.gather(*tasks)
# Run same-priority task simultaneously # Run same-priority task simultaneously
############END Notify structure############ ############END Notify structure############

@ -38,7 +38,7 @@ class Role:
3. Protection / Preempt actions (bodyguard/framer) 3. Protection / Preempt actions (bodyguard/framer)
4. Non-disruptive actions (seer/silencer) 4. Non-disruptive actions (seer/silencer)
5. Disruptive actions (Killing) 5. Disruptive actions (Killing)
6. Role altering actions (Cult / Mason) 6. Role altering actions (Cult / Mason / Shifter)
""" """
rand_choice = False # Determines if it can be picked as a random role (False for unusually disruptive roles) rand_choice = False # Determines if it can be picked as a random role (False for unusually disruptive roles)

@ -14,8 +14,10 @@ class Seer(Role):
"Lynch players during the day with `[p]ww vote <ID>`\n" "Lynch players during the day with `[p]ww vote <ID>`\n"
"Check for werewolves at night with `[p]ww choose <ID>`" "Check for werewolves at night with `[p]ww choose <ID>`"
) )
description = "A mystic in search of answers in a chaotic town.\n" \ description = (
"Calls upon the cosmos to discern those of Lycan blood" "A mystic in search of answers in a chaotic town.\n"
"Calls upon the cosmos to discern those of Lycan blood"
)
def __init__(self, game): def __init__(self, game):
super().__init__(game) super().__init__(game)
@ -33,7 +35,7 @@ class Seer(Role):
(self._at_day_end, 0), (self._at_day_end, 0),
(self._at_night_start, 2), (self._at_night_start, 2),
(self._at_night_end, 4), (self._at_night_end, 4),
(self._at_visit, 0) (self._at_visit, 0),
] ]
async def see_alignment(self, source=None): async def see_alignment(self, source=None):
@ -87,4 +89,8 @@ class Seer(Role):
await super().choose(ctx, data) await super().choose(ctx, data)
self.see_target, target = await pick_target(self, ctx, data) self.see_target, target = await pick_target(self, ctx, data)
await ctx.send("**You will attempt to see the role of {} tonight...**".format(target.member.display_name)) await ctx.send(
"**You will attempt to see the role of {} tonight...**".format(
target.member.display_name
)
)

@ -37,7 +37,7 @@ class Shifter(Role):
3. Protection / Preempt actions (bodyguard/framer) 3. Protection / Preempt actions (bodyguard/framer)
4. Non-disruptive actions (seer/silencer) 4. Non-disruptive actions (seer/silencer)
5. Disruptive actions (Killing) 5. Disruptive actions (Killing)
6. Role altering actions (Cult / Mason) 6. Role altering actions (Cult / Mason / Shifter)
""" """
rand_choice = False # Determines if it can be picked as a random role (False for unusually disruptive roles) rand_choice = False # Determines if it can be picked as a random role (False for unusually disruptive roles)

@ -13,7 +13,8 @@ class WolfVote(VoteGroup):
kill_messages = [ kill_messages = [
"**{ID}** - {target} was mauled by wolves", "**{ID}** - {target} was mauled by wolves",
"**{ID}** - {target} was found torn to shreds"] "**{ID}** - {target} was found torn to shreds",
]
def __init__(self, game, channel): def __init__(self, game, channel):
super().__init__(game, channel) super().__init__(game, channel)
@ -34,7 +35,7 @@ class WolfVote(VoteGroup):
(self._at_day_end, 0), (self._at_day_end, 0),
(self._at_night_start, 2), (self._at_night_start, 2),
(self._at_night_end, 5), # Kill priority (self._at_night_end, 5), # Kill priority
(self._at_visit, 0) (self._at_visit, 0),
] ]
# async def on_event(self, event, data): # async def on_event(self, event, data):
@ -75,7 +76,9 @@ class WolfVote(VoteGroup):
await self.channel.send(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)
)
async def _at_night_end(self, data=None): async def _at_night_end(self, data=None):
if self.channel is None: if self.channel is None:
@ -90,7 +93,9 @@ class WolfVote(VoteGroup):
print("Target id: {}\nKiller: {}".format(target_id, self.killer.member.display_name)) print("Target id: {}\nKiller: {}".format(target_id, self.killer.member.display_name))
if target_id is not None and self.killer: if target_id is not None and self.killer:
await self.game.kill(target_id, self.killer, random.choice(self.kill_messages)) await self.game.kill(target_id, self.killer, random.choice(self.kill_messages))
await self.channel.send("**{} has left to complete the kill...**".format(self.killer.member.display_name)) await self.channel.send(
"**{} has left to complete the kill...**".format(self.killer.member.display_name)
)
else: else:
await self.channel.send("**No kill will be attempted tonight...**") await self.channel.send("**No kill will be attempted tonight...**")
@ -117,4 +122,6 @@ class WolfVote(VoteGroup):
self.vote_results[author.id] = target_id self.vote_results[author.id] = target_id
await self.channel.send("{} has voted to kill {}".format(author.mention, target.member.display_name)) await self.channel.send(
"{} has voted to kill {}".format(author.mention, target.member.display_name)
)

@ -97,7 +97,7 @@ class Werewolf(Cog):
@wwset.command(name="role") @wwset.command(name="role")
async def wwset_role(self, ctx: commands.Context, role: discord.Role = None): async def wwset_role(self, ctx: commands.Context, role: discord.Role = None):
""" """
Assign the game role Set the game role
This role should not be manually assigned This role should not be manually assigned
""" """
if role is None: if role is None:
@ -222,7 +222,7 @@ class Werewolf(Cog):
await ctx.send("No game running, cannot start") await ctx.send("No game running, cannot start")
if not await game.setup(ctx): if not await game.setup(ctx):
pass # Do something? pass # ToDo something?
@commands.guild_only() @commands.guild_only()
@ww.command(name="stop") @ww.command(name="stop")
@ -230,10 +230,10 @@ class Werewolf(Cog):
""" """
Stops the current game Stops the current game
""" """
if ctx.guild is None: # if ctx.guild is None:
# Private message, can't get guild # # Private message, can't get guild
await ctx.send("Cannot start game from PM!") # await ctx.send("Cannot stop game from PM!")
return # return
if ctx.guild.id not in self.games or self.games[ctx.guild.id].game_over: if ctx.guild.id not in self.games or self.games[ctx.guild.id].game_over:
await ctx.send("No game to stop") await ctx.send("No game to stop")
return return
@ -354,11 +354,11 @@ class Werewolf(Cog):
await ctx.send("Role ID not found") await ctx.send("Role ID not found")
async def _get_game(self, ctx: commands.Context, game_code=None): async def _get_game(self, ctx: commands.Context, game_code=None):
guild: discord.Guild = ctx.guild guild: discord.Guild = getattr(ctx, "guild", None)
if guild is None: if guild is None:
# Private message, can't get guild # Private message, can't get guild
await ctx.send("Cannot start game from PM!") await ctx.send("Cannot start game from DM!")
return None return None
if guild.id not in self.games or self.games[guild.id].game_over: if guild.id not in self.games or self.games[guild.id].game_over:
await ctx.send("Starting a new game...") await ctx.send("Starting a new game...")
@ -368,7 +368,7 @@ class Werewolf(Cog):
await ctx.send("Cannot start a new game") await ctx.send("Cannot start a new game")
return None return None
self.games[guild.id] = Game(guild, role, category, channel, log_channel, game_code) self.games[guild.id] = Game(self.bot, guild, role, category, channel, log_channel, game_code)
return self.games[guild.id] return self.games[guild.id]

Loading…
Cancel
Save