From 08187e35d58c4a0f2a086743468ab3c1e63fef45 Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 9 Apr 2018 18:53:26 -0400 Subject: [PATCH] voting --- werewolf/game.py | 30 +++++++++++++++++++++++++----- werewolf/werewolf.py | 5 +++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/werewolf/game.py b/werewolf/game.py index eafe0d1..2d6872b 100644 --- a/werewolf/game.py +++ b/werewolf/game.py @@ -22,7 +22,7 @@ class Game: } # def __new__(cls, guild, game_code): - # game_code = ["DefaultWerewolf", "Villager", "Villager"] + # game_code = ["VanillaWerewolf", "Villager", "Villager"] # return super().__new__(cls, guild, game_code) @@ -33,7 +33,9 @@ class Game: self.roles = [] self.players = [] - self.day_vote = {} # ID, votes + + self.day_vote = {} # author, target + self.vote_totals = {} # id, total_votes self.started = False self.game_over = False @@ -331,12 +333,16 @@ class Game: if not player.alive: 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 - elif channel not in self.p_channels.values(): + else: + channel_list = [c["channel"] for c in self.p_channels.values()] + + if channel not in channel_list: # Not part of the game return # Don't say anything @@ -346,11 +352,25 @@ class Game: target = None if target is None: - await channel.send("Not a valid target") + await channel.send("Not a valid ID") return # 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: + + 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 self.vote_totals[id] < + if sum + await self.village_channel.send("{} has voted to put {} to trial. {} more votes needed".format( async def kill(self, target, source=None, method: str=None): """ Attempt to kill a target diff --git a/werewolf/werewolf.py b/werewolf/werewolf.py index 9e98c09..34908cf 100644 --- a/werewolf/werewolf.py +++ b/werewolf/werewolf.py @@ -98,9 +98,10 @@ class Werewolf: channel = ctx.channel if channel is game.village_channel: await game.vote(ctx.author, id, channel) - - if channel in (c["channel"] for c in game.p_channels.values()): + elif channel in (c["channel"] for c in game.p_channels.values()): await game.vote(ctx.author, id, channel) + else: + await ctx.send("Nothing to vote for in this channel") def _get_game(self, guild, game_code=None): if guild.id not in self.games: