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

102 lines
2.6 KiB

class VoteGroup:
"""
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):
self.game = game
self.channel = channel
self.players = []
self.vote_results = {}
self.properties = {} # Extra data for other options
7 years ago
self.action_list = [
7 years ago
(self._at_game_start, 1), # (Action, Priority)
(self._at_day_start, 0),
(self._at_voted, 0),
7 years ago
(self._at_kill, 1),
(self._at_hang, 1),
(self._at_day_end, 0),
(self._at_night_start, 2),
7 years ago
(self._at_night_end, 0),
(self._at_visit, 0)
7 years ago
]
async def on_event(self, event, data):
"""
See Game class for event guide
"""
7 years ago
await self.action_list[event][0](data)
async def _at_game_start(self, data=None):
7 years ago
await self.channel.send(" ".join(player.mention for player in self.players))
async def _at_day_start(self, data=None):
7 years ago
pass
7 years ago
async def _at_voted(self, data=None):
pass
7 years ago
async def _at_kill(self, data=None):
if data["player"] in self.players:
7 years ago
self.players.remove(data["player"])
7 years ago
async def _at_hang(self, data=None):
if data["player"] in self.players:
7 years ago
self.players.remove(data["player"])
async def _at_day_end(self, data=None):
pass
7 years ago
async def _at_night_start(self, data=None):
if self.channel is None:
return
7 years ago
await self.game.generate_targets(self.channel)
7 years ago
async def _at_night_end(self, data=None):
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 you voted on
pass
7 years ago
async def _at_visit(self, data=None):
pass
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: Trigger deletion of votegroup
pass
7 years ago
async def vote(self, target, author, id):
7 years ago
"""
Receive vote from game
"""
7 years ago
7 years ago
self.vote_results[author.id] = id