From cb9822f91c8aeddce71c98160302fd74953265c1 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 10 Apr 2018 13:33:31 -0400 Subject: [PATCH] today's changes --- werewolf/game.py | 52 ++++++++++++++++++++++--------- werewolf/role.py | 6 +++- werewolf/roles/vanillawerewolf.py | 6 +++- werewolf/roles/villager.py | 2 +- werewolf/votegroup.py | 2 +- werewolf/votegroups/wolfvote.py | 18 ++++++----- werewolf/werewolf.py | 25 +++++++++++++-- 7 files changed, 83 insertions(+), 28 deletions(-) diff --git a/werewolf/game.py b/werewolf/game.py index 6aab13c..daead30 100644 --- a/werewolf/game.py +++ b/werewolf/game.py @@ -39,8 +39,8 @@ class Game: self.players = [] - self.day_vote = {} # author, target - self.vote_totals = {} # id, total_votes + self.day_vote = {} # author: target + self.vote_totals = {} # id: total_votes self.started = False self.game_over = False @@ -156,6 +156,8 @@ class Game: embed=discord.Embed(title=random.choice(self.morning_messages)) for result in self.night_results: embed.add_field(name=result, value="________", inline=False) + + self.night_results = [] # Clear for next day await self.village_channel.send(embed=embed) await self.generate_targets(self.village_channel) @@ -243,6 +245,9 @@ class Game: return self.can_vote = False + self.day_vote = {} + self.vote_totals = {} + await self.night_perms(self.village_channel) await self.village_channel.send(embed=discord.Embed(title="**The sun sets on the village...**")) @@ -352,7 +357,7 @@ class Game: """ Member attempts to cast a vote (usually to lynch) """ - player = self._get_player(author) + player = await self.get_player_by_member(author) if player is None: await channel.send("You're not in this game!") @@ -362,18 +367,17 @@ class Game: await channel.send("Corpses can't vote") return - channel_list = [] if channel == self.village_channel: if not self.can_vote: await channel.send("Voting is not allowed right now") return - else: - channel_list = [c["channel"] for c in self.p_channels.values()] - - if channel not in channel_list: + elif channel.name in self.p_channels: + pass + else: # Not part of the game - return # Don't say anything - + await channel.send("Cannot vote in this channel") + return + try: target = self.players[id] except IndexError: @@ -386,19 +390,36 @@ class Game: # Now handle village vote or send to votegroup if channel == self.village_channel: await self._village_vote(target, author, id) - elif channel in self.p_channels: + elif self.p_channels[channel.name]["votegroup"] is not None: + await self.vote_groups[channel.name].vote(target, author, id) + else: # Private channel voting, send to role + await self.player.role.vote(target, id) + + + async def _village_vote(self, target, author, id): if author in self.day_vote: self.vote_totals[self.day_vote[author]] -= 1 self.day_vote[author] = id - self.vote_totals[id] += 1 + if id not in self.vote_totals: + self.vote_totals[id] = 1 + else: + self.vote_totals[id] += 1 - if self.vote_totals[id] < + required_votes = len([player for player in self.players if player.alive]) // 7 + 2 + if self.vote_totals[id] < required_votes: + await self.village_channel.send("{} has voted to put {} to trial. {} more votes needed".format(author.mention, target.member.mention, required_votes - self.vote_totals[id])) + else: + self.vote_totals[id] = 0 + self.day_vote = {k:v for k,v in self.day_vote.items() if v != id} # Remove votes for this id + await self._at_voted(target) - if sum - await self.village_channel.send("{} has voted to put {} to trial. {} more votes needed".format( + + async def eval_results(self, target, source=None, method = None): + return "{} was found dead".format(target.member.display_name) + async def kill(self, target, source=None, method: str=None): """ Attempt to kill a target @@ -410,6 +431,7 @@ class Game: target.alive = False await self._at_kill(target) if not target.alive: # Still dead after notifying + self.night_results.append(await self.eval_results(target, source, method)) await self.dead_perms(target.member) else: target.protected = False diff --git a/werewolf/role.py b/werewolf/role.py index 6c585b1..ecf8903 100644 --- a/werewolf/role.py +++ b/werewolf/role.py @@ -46,7 +46,7 @@ class Role: game_start_message= ( "Your role is **Default**\n" "You win by testing the game\n" - "Lynch players during the day with `[p]ww lynch `" + "Lynch players during the day with `[p]ww vote `" ) def __init__(self, game): @@ -123,3 +123,7 @@ class Role: async def _at_night_end(self, data=None): pass + + async def vote(self, target, id): + """Handle night actions""" + pass \ No newline at end of file diff --git a/werewolf/roles/vanillawerewolf.py b/werewolf/roles/vanillawerewolf.py index 96be6b8..6d0c26b 100644 --- a/werewolf/roles/vanillawerewolf.py +++ b/werewolf/roles/vanillawerewolf.py @@ -15,7 +15,7 @@ class VanillaWerewolf(Role): game_start_message = ( "Your role is **Werewolf**\n" "You win by killing everyone else in the village\n" - "Lynch players during the day with `[p]ww lynch `\n" + "Lynch players during the day with `[p]ww vote `\n" "Vote to kill players at night with `[p]ww vote `" ) @@ -93,3 +93,7 @@ class VanillaWerewolf(Role): # async def _at_night_end(self, data=None): # super()._at_night_end(data) + + async def vote(self, target, id): + """Handle night actions""" + await self.player.member.send("Use this command in your wolf channel at night") diff --git a/werewolf/roles/villager.py b/werewolf/roles/villager.py index 3baaa9c..3e1ac22 100644 --- a/werewolf/roles/villager.py +++ b/werewolf/roles/villager.py @@ -12,7 +12,7 @@ class Villager(Role): game_start_message=( "Your role is **Villager**\n" "You win by lynching all evil in the town\n" - "Lynch players during the day with `[p]ww lynch `\n" + "Lynch players during the day with `[p]ww vote `\n" ) def __init__(self, game): diff --git a/werewolf/votegroup.py b/werewolf/votegroup.py index eab6361..7349846 100644 --- a/werewolf/votegroup.py +++ b/werewolf/votegroup.py @@ -92,7 +92,7 @@ class VoteGroup: if player.id in self.players: self.players.remove(player) - async def vote(self, author, id): + async def vote(self, target, author, id): """ Receive vote from game """ diff --git a/werewolf/votegroups/wolfvote.py b/werewolf/votegroups/wolfvote.py index 56bc776..51d8d8b 100644 --- a/werewolf/votegroups/wolfvote.py +++ b/werewolf/votegroups/wolfvote.py @@ -15,7 +15,7 @@ class WolfVote(VoteGroup): channel_id = "werewolves" kill_messages = [ - "**{ID}** - {target} was attacked by wolves", + "**{ID}** - {target} was mauled by wolves", "**{ID}** - {target} was found torn to shreds"] def __init__(self, game, channel): @@ -70,7 +70,7 @@ class WolfVote(VoteGroup): return await self.game.generate_targets(self.channel) - + await self.channel.send(" ".join(player.mention for player in 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)) @@ -87,10 +87,14 @@ class WolfVote(VoteGroup): if target and self.killer: await self.game.kill(target, self.killer, random.choice(self.kill_messages)) + else: + await self.channel.send("**No kill will be attempted tonight...**") - # async def vote(self, author, id): - # """ - # Receive vote from game - # """ + async def vote(self, target, author, id): + """ + Receive vote from game + """ + + self.vote_results[author.id] = id - # self.vote_results[author.id] = id + await self.channel.send("{} has voted to kill {}".format(author.mention, target.member.display_name)) diff --git a/werewolf/werewolf.py b/werewolf/werewolf.py index 34908cf..2672805 100644 --- a/werewolf/werewolf.py +++ b/werewolf/werewolf.py @@ -84,19 +84,40 @@ class Werewolf: await ctx.send("No game running, cannot start") await game.setup(ctx) + + @ww.command() + async def stop(self, ctx): + """ + Stops the current game + """ + game = self._get_game(ctx.guild) + if not game: + await ctx.send("No game running, cannot stop") + + game.game_over = True + @ww.command() - async def vote(self, ctx, id): + async def vote(self, ctx, id: int): """ Vote for a player by ID """ + try: + id = int(id) + except: + id = None + + if id is None: + await ctx.send("`id` must be an integer") + return + game = self._get_game(ctx.guild) if not game: await ctx.send("No game running, cannot vote") # Game handles response now channel = ctx.channel - if channel is game.village_channel: + if channel == game.village_channel: await game.vote(ctx.author, id, channel) elif channel in (c["channel"] for c in game.p_channels.values()): await game.vote(ctx.author, id, channel)