Merge pull request #28 from bobloy/werewolf_develop

Werewolf develop
secrethitler-develop
bobloy 6 years ago committed by GitHub
commit 108857b3a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -318,7 +318,7 @@ class GameBuilder:
pass pass
if page >= len(ROLE_LIST): if page >= len(ROLE_LIST):
self.rand_roles.append(CATEGORY_COUNT[page-len(ROLE_LIST)]) self.rand_roles.append(CATEGORY_COUNT[page - len(ROLE_LIST)])
else: else:
self.code.append(page) self.code.append(page)

@ -1,17 +1,23 @@
import asyncio import asyncio
import random import random
from typing import List, Any, Dict, Set, Union
import discord import discord
from redbot.core import commands from redbot.core import commands
from werewolf.builder import parse_code from werewolf.builder import parse_code
from werewolf.player import Player from werewolf.player import Player
from werewolf.role import Role
from werewolf.votegroup import VoteGroup
class Game: class Game:
""" """
Base class to run a single game of Werewolf Base class to run a single game of Werewolf
""" """
vote_groups: Dict[str, VoteGroup]
roles: List[Role]
players: List[Player]
default_secret_channel = { default_secret_channel = {
"channel": None, "channel": None,

@ -3,3 +3,21 @@ from werewolf.role import Role
def night_immune(role: Role): def night_immune(role: Role):
role.player.alive = True role.player.alive = True
async def pick_target(role: Role, ctx, data):
if not role.player.alive: # FixMe: Game handles this?
await role.player.send_dm("You're already dead!")
return None
target_id = int(data)
try:
target = role.game.players[target_id]
except IndexError:
target = None
if target is None:
await ctx.send("Not a valid ID")
return None
return target_id, target

@ -1,3 +1,4 @@
from werewolf.night_powers import pick_target
from werewolf.role import Role from werewolf.role import Role
@ -61,7 +62,7 @@ class Seer(Role):
return return
self.see_target = None self.see_target = None
await self.game.generate_targets(self.player.member) await self.game.generate_targets(self.player.member)
await self.player.send_dm("**Pick a target to see tonight**\n") await self.player.send_dm("**Pick a target to see tonight**")
async def _at_night_end(self, data=None): async def _at_night_end(self, data=None):
if self.see_target is None: if self.see_target is None:
@ -83,19 +84,7 @@ class Seer(Role):
async def choose(self, ctx, data): async def choose(self, ctx, data):
"""Handle night actions""" """Handle night actions"""
if not self.player.alive: # FixMe: Game handles this? await super().choose(ctx, data)
await self.player.send_dm("You're already dead!")
return
target_id = int(data)
try:
target = self.game.players[target_id]
except IndexError:
target = None
if target is None:
await ctx.send("Not a valid ID")
return
self.see_target = target_id self.see_target, target = await pick_target(self, ctx, data)
await ctx.send("**You will attempt to see the role of {} tonight...**".format(target.member.display_name)) await ctx.send("**You will attempt to see the role of {} tonight...**".format(target.member.display_name))

@ -1,3 +1,4 @@
from werewolf.night_powers import pick_target
from werewolf.role import Role from werewolf.role import Role
@ -59,6 +60,7 @@ class Shifter(Role):
def __init__(self, game): def __init__(self, game):
super().__init__(game) super().__init__(game)
self.shift_target = None
self.action_list = [ self.action_list = [
(self._at_game_start, 1), # (Action, Priority) (self._at_game_start, 1), # (Action, Priority)
(self._at_day_start, 0), (self._at_day_start, 0),
@ -74,7 +76,7 @@ class Shifter(Role):
async def see_alignment(self, source=None): async def see_alignment(self, source=None):
""" """
Interaction for investigative roles attempting Interaction for investigative roles attempting
to see alignment (Village, Werewolf Other) to see alignment (Village, Werewolf, Other)
""" """
return "Other" return "Other"
@ -90,14 +92,38 @@ class Shifter(Role):
Interaction for investigative roles. Interaction for investigative roles.
More common to be able to deceive this action More common to be able to deceive this action
""" """
return "MyRole" return "Shifter"
async def _at_night_start(self, data=None): async def _at_night_start(self, data=None):
await super()._at_night_start(data) await super()._at_night_start(data)
self.shift_target = None
await self.game.generate_targets(self.player.member)
await self.player.send_dm("**Pick a target to shift into**")
async def _at_night_end(self, data=None): async def _at_night_end(self, data=None):
await super()._at_night_end(data) await super()._at_night_end(data)
if self.shift_target is None:
if self.player.alive:
await self.player.send_dm("You will not use your powers tonight...")
return
target = await self.game.visit(self.shift_target, self.player)
if target and target.player.alive:
await target.role.assign_player(self.player)
await self.assign_player(target)
# Roles have now been swapped
await self.player.send_dm("Your role has been stolen...\n"
"You are now a **Shifter**.")
await self.player.send_dm(self.game_start_message)
await target.send_dm(target.role.game_start_message)
else:
await self.player.send_dm("**Your shift failed...**")
async def choose(self, ctx, data): async def choose(self, ctx, data):
"""Handle night actions""" """Handle night actions"""
await super().choose(ctx, data) await super().choose(ctx, data)
self.shift_target, target = await pick_target(self, ctx, data)
await ctx.send("**You will attempt to see the role of {} tonight...**".format(target.member.display_name))

@ -392,4 +392,3 @@ class Werewolf(Cog):
return False, None, None, None, None return False, None, None, None, None
return True, role, category, channel, log_channel return True, role, category, channel, log_channel

Loading…
Cancel
Save