pull/5/head
Bobloy 7 years ago
parent 22aaa497f8
commit bae1355037

@ -11,6 +11,7 @@ class Game:
""" """
Base class to run a single game of Werewolf Base class to run a single game of Werewolf
""" """
village_channel: discord.TextChannel
default_secret_channel = { default_secret_channel = {
"channel": None, "channel": None,
@ -30,7 +31,7 @@ class Game:
# #
# return super().__new__(cls, guild, game_code) # return super().__new__(cls, guild, game_code)
def __init__(self, guild, role, game_code): def __init__(self, guild: discord.Guild, role: discord.Role, game_code):
self.guild = guild self.guild = guild
self.game_code = ["VanillaWerewolf"] self.game_code = ["VanillaWerewolf"]
self.game_role = role self.game_role = role
@ -355,7 +356,7 @@ class Game:
############END Notify structure############ ############END Notify structure############
async def generate_targets(self, channel): async def generate_targets(self, channel, with_roles = False):
embed = discord.Embed(title="Remaining Players") embed = discord.Embed(title="Remaining Players")
for i in range(len(self.players)): for i in range(len(self.players)):
player = self.players[i] player = self.players[i]
@ -363,7 +364,11 @@ class Game:
status = "" status = ""
else: else:
status = "*Dead*" status = "*Dead*"
embed.add_field(name="ID# **{}**".format(i), if with_roles:
embed.add_field(name="ID# **{}**".format(i),
value="{} {} {}".format(status, player.member.display_name, str(player.role)), inline=True)
else:
embed.add_field(name="ID# **{}**".format(i),
value="{} {}".format(status, player.member.display_name), inline=True) value="{} {}".format(status, player.member.display_name), inline=True)
return await channel.send(embed=embed) return await channel.send(embed=embed)
@ -654,17 +659,35 @@ class Game:
alive_players = [player for player in self.players if player.alive] alive_players = [player for player in self.players if player.alive]
if len(alive_players) <= 2: if len(alive_players) <= 2:
self.game_over = True
# Check 1v1 victory conditions ToDo # Check 1v1 victory conditions ToDo
pass pass
else: else:
# Check if everyone is on the same team # Check if everyone is on the same team
alignment = alive_players[0].role.alignment alignment = alive_players[0].role.alignment # Get first allignment and compare to rest
for player in alive_players: for player in alive_players:
if player.role.alignment != alignment: if player.role.alignment != alignment:
return False return
# Only remaining team wins # Only remaining team wins
self.game_over = True
await self._announce_winners(alive_players)
# If no return, cleanup and end game
await self._end_game()
async def _announce_winners(self, winnerlist):
await self.village_channel.send(self.game_role.mention)
embed = discord.Embed(title='Game Over', description='The Following Players have won!')
for player in winnerlist:
embed.add_field(name=player.member.display_name, value=str(player.role), inline=True)
embed.set_thumbnail(url='https://emojipedia-us.s3.amazonaws.com/thumbs/160/twitter/134/trophy_1f3c6.png')
await self.village_channel.send(embed=embed)
await self.generate_targets(self.village_channel, True)
async def _end_game(self): async def _end_game(self):
# ToDo # Remove game_role access for potential archiving for now
await self.village_channel.set_permissions(self.game_role, overwrite=None)
pass pass

@ -65,6 +65,9 @@ class Role:
(self._at_visit, 0) (self._at_visit, 0)
] ]
def __repr__(self):
return self.__class__.__name__
async def on_event(self, event, data): async def on_event(self, event, data):
""" """
See Game class for event guide See Game class for event guide

@ -1,3 +1,5 @@
from typing import Dict
import discord import discord
from discord.ext import commands from discord.ext import commands
from redbot.core import Config from redbot.core import Config
@ -10,6 +12,7 @@ class Werewolf:
""" """
Base to host werewolf on a guild Base to host werewolf on a guild
""" """
games: Dict[int, Game]
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -57,17 +60,17 @@ class Werewolf:
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command()
async def new(self, ctx, game_code): async def new(self, ctx, game_code=None):
""" """
Create and join a new game of Werewolf Create and join a new game of Werewolf
""" """
game = await self._get_game(ctx.guild, game_code) game = await self._get_game(ctx, game_code)
if not game: if not game:
await ctx.send("Failed to start a new game") await ctx.send("Failed to start a new game")
else: else:
await ctx.send("New game has started") await ctx.send("Game is ready to join! Use `[p]`ww join`")
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command()
@ -183,20 +186,21 @@ class Werewolf:
await game.choose(ctx, data) await game.choose(ctx, data)
async def _get_game(self, guild, game_code=None): async def _get_game(self, ctx, game_code=None):
if guild is None: if ctx.guild is None:
# Private message, can't get guild # Private message, can't get guild
return None return None
if guild.id not in self.games: if ctx.guild.id not in self.games or self.games[ctx.guild.id].game_over:
await ctx.send("Starting a new game...")
if not game_code: if not game_code:
return None return None
role = await self.config.guild(guild).role() role = await self.config.guild(ctx.guild).role()
role = discord.utils.get(guild.roles, id=role) role = discord.utils.get(ctx.guild.roles, id=role)
if role is None: if role is None:
return None return None
self.games[guild.id] = Game(guild, role, game_code) self.games[ctx.guild.id] = Game(ctx.guild, role, game_code)
return self.games[guild.id] return self.games[ctx.guild.id]
async def _game_start(self, game): async def _game_start(self, game):
await game.start() await game.start()

Loading…
Cancel
Save