You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fox-V3/werewolf/votegroup.py

86 lines
2.2 KiB

4 years ago
import logging
from werewolf.listener import WolfListener, wolflistener
4 years ago
log = logging.getLogger("red.fox_v3.werewolf.votegroup")
class VoteGroup(WolfListener):
"""
Base VoteGroup class for werewolf game
Handles secret channels and group decisions
"""
7 years ago
alignment = 0 # 1: Town, 2: Werewolf, 3: Neutral
channel_id = ""
def __init__(self, game, channel):
super().__init__(game)
self.game = game
self.channel = channel
self.players = []
self.vote_results = {}
self.properties = {} # Extra data for other options
7 years ago
@wolflistener("at_game_start", priority=1)
async def _at_game_start(self):
7 years ago
await self.channel.send(" ".join(player.mention for player in self.players))
@wolflistener("at_kill", priority=1)
async def _at_kill(self, player):
if player in self.players:
self.players.remove(player)
7 years ago
@wolflistener("at_hang", priority=1)
async def _at_hang(self, player):
if player in self.players:
self.players.remove(player)
7 years ago
@wolflistener("at_night_start", priority=2)
async def _at_night_start(self):
if self.channel is None:
return
self.vote_results = {}
7 years ago
await self.game.generate_targets(self.channel)
7 years ago
@wolflistener("at_night_end", priority=5)
async def _at_night_end(self):
if self.channel is None:
7 years ago
return
7 years ago
7 years ago
target = None
vote_list = list(self.vote_results.values())
7 years ago
7 years ago
if vote_list:
target = max(set(vote_list), key=vote_list.count)
7 years ago
7 years ago
if target:
# Do what the votegroup votes on
raise NotImplementedError
7 years ago
async def register_players(self, *players):
7 years ago
"""
Extend players by passed list
7 years ago
"""
self.players.extend(players)
7 years ago
async def remove_player(self, player):
7 years ago
"""
Remove a player from player list
7 years ago
"""
if player.id in self.players:
self.players.remove(player)
7 years ago
7 years ago
if not self.players:
# TODO: Confirm deletion
7 years ago
pass
async def vote(self, target, author, target_id):
7 years ago
"""
Receive vote from game
"""
7 years ago
self.vote_results[author.id] = target_id