opens and creates a game instance
This commit is contained in:
parent
9447dd87fc
commit
a87f6dfa71
@ -6,7 +6,9 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
|
|
||||||
# from .builder import parse_code
|
from werewolf.player import Player
|
||||||
|
|
||||||
|
from werewolf.builder import parse_code
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
@ -20,19 +22,17 @@ class Game:
|
|||||||
"votegroup": None
|
"votegroup": None
|
||||||
}
|
}
|
||||||
|
|
||||||
def __new__(cls, game_code):
|
# def __new__(cls, guild, game_code):
|
||||||
game_code = ["DefaultWerewolf", "Villager", "Villager"]
|
# game_code = ["DefaultWerewolf", "Villager", "Villager"]
|
||||||
return Game(game_code)
|
|
||||||
|
# return super().__new__(cls, guild, game_code)
|
||||||
|
|
||||||
def __init__(self, guild, game_code):
|
def __init__(self, guild, game_code):
|
||||||
self.guild = guild
|
self.guild = guild
|
||||||
self.game_code = game_code
|
self.game_code = ["VanillaWerewolf", "Villager", "Villager"]
|
||||||
|
|
||||||
self.roles = []
|
self.roles = []
|
||||||
|
|
||||||
if self.game_code:
|
|
||||||
self.get_roles()
|
|
||||||
|
|
||||||
self.players = []
|
self.players = []
|
||||||
self.day_vote = {} # ID, votes
|
self.day_vote = {} # ID, votes
|
||||||
|
|
||||||
@ -59,8 +59,15 @@ class Game:
|
|||||||
3. Check Initial role setup (including alerts)
|
3. Check Initial role setup (including alerts)
|
||||||
4. Start game
|
4. Start game
|
||||||
"""
|
"""
|
||||||
|
if self.game_code:
|
||||||
|
await self.get_roles()
|
||||||
|
else:
|
||||||
|
await ctx.send("Number of players does not match number of roles, adjust before starting")
|
||||||
|
return False
|
||||||
|
|
||||||
if len(self.players) != self.roles:
|
if len(self.players) != self.roles:
|
||||||
ctx.send("Player count does not match role count, cannot start")
|
await ctx.send("Player count does not match role count, cannot start")
|
||||||
|
self.roles = []
|
||||||
return False
|
return False
|
||||||
# Create category and channel with individual overwrites
|
# Create category and channel with individual overwrites
|
||||||
overwrite = {
|
overwrite = {
|
||||||
@ -284,15 +291,15 @@ class Game:
|
|||||||
await channel.send("**Game has already started!**")
|
await channel.send("**Game has already started!**")
|
||||||
return
|
return
|
||||||
|
|
||||||
if member in self.players:
|
if await self.get_player_by_member(member):
|
||||||
await channel.send("{} is already in the game!".format(member.mention))
|
await channel.send("{} is already in the game!".format(member.mention))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.started.append(member)
|
self.players.append(Player(member))
|
||||||
|
|
||||||
channel.send("{} has been added to the game, total players is **{}**".format(member.mention, len(self.players)))
|
await channel.send("{} has been added to the game, total players is **{}**".format(member.mention, len(self.players)))
|
||||||
|
|
||||||
async def quit(self, member: discord.Member):
|
async def quit(self, member: discord.Member, channel: discord.TextChannel = None):
|
||||||
"""
|
"""
|
||||||
Have a member quit a game
|
Have a member quit a game
|
||||||
"""
|
"""
|
||||||
@ -302,7 +309,11 @@ class Game:
|
|||||||
return "You're not in a game!"
|
return "You're not in a game!"
|
||||||
|
|
||||||
if self.started:
|
if self.started:
|
||||||
await self.kill()
|
await self.kill(member)
|
||||||
|
await channel.send("{} has left the game".format(member.mention))
|
||||||
|
else:
|
||||||
|
self.players = [player for player in self.players if player.member != member]
|
||||||
|
await channel.send("{} chickened out, player count is now **{}**".format(member.mention, len(self.players)))
|
||||||
|
|
||||||
async def vote(self, author, id, channel):
|
async def vote(self, author, id, channel):
|
||||||
"""
|
"""
|
||||||
@ -311,16 +322,16 @@ class Game:
|
|||||||
player = self._get_player(author)
|
player = self._get_player(author)
|
||||||
|
|
||||||
if player is None:
|
if player is None:
|
||||||
channel.send("You're not in this game!")
|
await channel.send("You're not in this game!")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not player.alive:
|
if not player.alive:
|
||||||
channel.send("Corpses can't vote")
|
await channel.send("Corpses can't vote")
|
||||||
return
|
return
|
||||||
|
|
||||||
if channel == self.village_channel:
|
if channel == self.village_channel:
|
||||||
if not self.can_vote:
|
if not self.can_vote:
|
||||||
channel.send("Voting is not allowed right now")
|
await channel.send("Voting is not allowed right now")
|
||||||
return
|
return
|
||||||
elif channel not in self.p_channels.values():
|
elif channel not in self.p_channels.values():
|
||||||
# Not part of the game
|
# Not part of the game
|
||||||
@ -332,7 +343,7 @@ class Game:
|
|||||||
target = None
|
target = None
|
||||||
|
|
||||||
if target is None:
|
if target is None:
|
||||||
channel.send("Not a valid target")
|
await channel.send("Not a valid target")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Now handle village vote or send to votegroup
|
# Now handle village vote or send to votegroup
|
||||||
@ -373,6 +384,12 @@ class Game:
|
|||||||
|
|
||||||
if not self.roles:
|
if not self.roles:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def get_player_by_member(self, member):
|
||||||
|
for player in self.players:
|
||||||
|
if player.member == member:
|
||||||
|
return player
|
||||||
|
return False
|
||||||
|
|
||||||
async def dead_perms(self, channel, member):
|
async def dead_perms(self, channel, member):
|
||||||
await channel.set_permissions(member, read_messages=True, send_message=False, add_reactions=False)
|
await channel.set_permissions(member, read_messages=True, send_message=False, add_reactions=False)
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import discord
|
|
||||||
|
|
||||||
from datetime import datetime,timedelta
|
|
||||||
|
|
||||||
class Role:
|
class Role:
|
||||||
"""
|
"""
|
||||||
Base Role class for werewolf game
|
Base Role class for werewolf game
|
||||||
@ -52,7 +48,14 @@ class Role:
|
|||||||
You win by testing the game
|
You win by testing the game
|
||||||
Lynch players during the day with `[p]ww lynch <ID>`
|
Lynch players during the day with `[p]ww lynch <ID>`
|
||||||
"""
|
"""
|
||||||
action_list = [
|
|
||||||
|
def __init__(self, game):
|
||||||
|
self.game = game
|
||||||
|
self.player = None
|
||||||
|
self.blocked = False
|
||||||
|
self.properties = {} # Extra data for other roles (i.e. arsonist)
|
||||||
|
|
||||||
|
self.action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 0), # (Action, Priority)
|
||||||
(self._at_day_start, 0),
|
(self._at_day_start, 0),
|
||||||
(self._at_voted, 0),
|
(self._at_voted, 0),
|
||||||
@ -62,12 +65,6 @@ class Role:
|
|||||||
(self._at_night_start, 0),
|
(self._at_night_start, 0),
|
||||||
(self._at_night_end, 0)
|
(self._at_night_end, 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, game):
|
|
||||||
self.game = game
|
|
||||||
self.player = None
|
|
||||||
self.blocked = False
|
|
||||||
self.properties = {} # Extra data for other roles (i.e. arsonist)
|
|
||||||
|
|
||||||
async def on_event(self, event, data):
|
async def on_event(self, event, data):
|
||||||
"""
|
"""
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import discord
|
from werewolf.role import Role
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from werewolf.votegroups.wolfvote import WolfVote
|
||||||
|
|
||||||
from cogs.werewolf.Role import Role
|
|
||||||
|
|
||||||
from cogs.werewolf.votegroups.wolfvote import WolfVote
|
|
||||||
|
|
||||||
|
|
||||||
class VanillaWerewolf(Role):
|
class VanillaWerewolf(Role):
|
||||||
@ -22,7 +18,14 @@ class VanillaWerewolf(Role):
|
|||||||
Lynch players during the day with `[p]ww lynch <ID>`
|
Lynch players during the day with `[p]ww lynch <ID>`
|
||||||
Vote to kill players at night with `[p]ww vote <ID>`
|
Vote to kill players at night with `[p]ww vote <ID>`
|
||||||
"""
|
"""
|
||||||
action_list = [
|
|
||||||
|
|
||||||
|
def __init__(self, game):
|
||||||
|
# self.game = game
|
||||||
|
# self.player = None
|
||||||
|
# self.blocked = False
|
||||||
|
# self.properties = {} # Extra data for other roles (i.e. arsonist)
|
||||||
|
self.action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 0), # (Action, Priority)
|
||||||
(self._at_day_start, 0),
|
(self._at_day_start, 0),
|
||||||
(self._at_voted, 0),
|
(self._at_voted, 0),
|
||||||
@ -30,14 +33,8 @@ class VanillaWerewolf(Role):
|
|||||||
(self._at_hang, 0),
|
(self._at_hang, 0),
|
||||||
(self._at_day_end, 0),
|
(self._at_day_end, 0),
|
||||||
(self._at_night_start, 2),
|
(self._at_night_start, 2),
|
||||||
(self._at_night_end, 5)
|
(self._at_night_end, 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
# def __init__(self, game):
|
|
||||||
# self.game = game
|
|
||||||
# self.player = None
|
|
||||||
# self.blocked = False
|
|
||||||
# self.properties = {} # Extra data for other roles (i.e. arsonist)
|
|
||||||
|
|
||||||
# async def on_event(self, event, data):
|
# async def on_event(self, event, data):
|
||||||
# """
|
# """
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import discord
|
from werewolf.role import Role
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
class Villager(Role):
|
class Villager(Role):
|
||||||
|
|
||||||
@ -16,17 +14,7 @@ class Villager(Role):
|
|||||||
You win by lynching all evil in the town
|
You win by lynching all evil in the town
|
||||||
Lynch players during the day with `[p]ww lynch <ID>`
|
Lynch players during the day with `[p]ww lynch <ID>`
|
||||||
"""
|
"""
|
||||||
action_list = [
|
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
|
||||||
(self._at_day_start, 0),
|
|
||||||
(self._at_voted, 0),
|
|
||||||
(self._at_kill, 0),
|
|
||||||
(self._at_hang, 0),
|
|
||||||
(self._at_day_end, 0),
|
|
||||||
(self._at_night_start, 0),
|
|
||||||
(self._at_night_end, 0)
|
|
||||||
]
|
|
||||||
|
|
||||||
# def __init__(self, game):
|
# def __init__(self, game):
|
||||||
# self.game = game
|
# self.game = game
|
||||||
# self.player = None
|
# self.player = None
|
||||||
|
@ -14,7 +14,14 @@ class VoteGroup:
|
|||||||
allignment = 0 # 1: Town, 2: Werewolf, 3: Neutral
|
allignment = 0 # 1: Town, 2: Werewolf, 3: Neutral
|
||||||
channel_id = ""
|
channel_id = ""
|
||||||
|
|
||||||
action_list = [
|
def __init__(self, game, channel):
|
||||||
|
self.game = game
|
||||||
|
self.channel = channel
|
||||||
|
self.players = []
|
||||||
|
self.vote_results = {}
|
||||||
|
self.properties = {} # Extra data for other options
|
||||||
|
|
||||||
|
self.action_list = [
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
(self._at_game_start, 0), # (Action, Priority)
|
||||||
(self._at_day_start, 0),
|
(self._at_day_start, 0),
|
||||||
(self._at_voted, 0),
|
(self._at_voted, 0),
|
||||||
@ -24,15 +31,6 @@ class VoteGroup:
|
|||||||
(self._at_night_start, 2),
|
(self._at_night_start, 2),
|
||||||
(self._at_night_end, 0)
|
(self._at_night_end, 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, game, channel):
|
|
||||||
self.game = game
|
|
||||||
self.channel = channel
|
|
||||||
self.players = []
|
|
||||||
self.vote_results = {}
|
|
||||||
self.properties = {} # Extra data for other options
|
|
||||||
|
|
||||||
|
|
||||||
async def on_event(self, event, data):
|
async def on_event(self, event, data):
|
||||||
"""
|
"""
|
||||||
|
@ -4,7 +4,7 @@ import discord
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from cogs.werewolf.votegroup import VoteGroup
|
from werewolf.votegroup import VoteGroup
|
||||||
|
|
||||||
class WolfVote(VoteGroup):
|
class WolfVote(VoteGroup):
|
||||||
"""
|
"""
|
||||||
@ -14,18 +14,6 @@ class WolfVote(VoteGroup):
|
|||||||
allignment = 2 # 1: Town, 2: Werewolf, 3: Neutral
|
allignment = 2 # 1: Town, 2: Werewolf, 3: Neutral
|
||||||
channel_id = "werewolves"
|
channel_id = "werewolves"
|
||||||
|
|
||||||
action_list = [
|
|
||||||
(self._at_game_start, 0), # (Action, Priority)
|
|
||||||
(self._at_day_start, 0),
|
|
||||||
(self._at_voted, 0),
|
|
||||||
(self._at_kill, 0),
|
|
||||||
(self._at_hang, 0),
|
|
||||||
(self._at_day_end, 0),
|
|
||||||
(self._at_night_start, 2),
|
|
||||||
(self._at_night_end, 5) # Kill priority
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
kill_messages = [
|
kill_messages = [
|
||||||
"**{ID}** - {target} was attacked by wolves",
|
"**{ID}** - {target} was attacked by wolves",
|
||||||
"**{ID}** - {target} was found torn to shreds"]
|
"**{ID}** - {target} was found torn to shreds"]
|
||||||
@ -36,9 +24,20 @@ class WolfVote(VoteGroup):
|
|||||||
# self.players = []
|
# self.players = []
|
||||||
# self.vote_results = {}
|
# self.vote_results = {}
|
||||||
# self.properties = {} # Extra data for other options
|
# self.properties = {} # Extra data for other options
|
||||||
self.killer = None # Added killer
|
|
||||||
super().__init__(game, channel)
|
super().__init__(game, channel)
|
||||||
|
|
||||||
|
self.killer = None # Added killer
|
||||||
|
|
||||||
|
self.action_list = [
|
||||||
|
(self._at_game_start, 0), # (Action, Priority)
|
||||||
|
(self._at_day_start, 0),
|
||||||
|
(self._at_voted, 0),
|
||||||
|
(self._at_kill, 0),
|
||||||
|
(self._at_hang, 0),
|
||||||
|
(self._at_day_end, 0),
|
||||||
|
(self._at_night_start, 2),
|
||||||
|
(self._at_night_end, 5) # Kill priority
|
||||||
|
]
|
||||||
|
|
||||||
# async def on_event(self, event, data):
|
# async def on_event(self, event, data):
|
||||||
# """
|
# """
|
||||||
|
@ -7,7 +7,7 @@ from redbot.core import Config
|
|||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from .game import Game
|
from werewolf.game import Game
|
||||||
|
|
||||||
|
|
||||||
class Werewolf:
|
class Werewolf:
|
||||||
@ -44,7 +44,11 @@ class Werewolf:
|
|||||||
game = self._get_game(ctx.guild, game_code)
|
game = self._get_game(ctx.guild, game_code)
|
||||||
|
|
||||||
if not game:
|
if not game:
|
||||||
ctx.send("Failed to start a new game")
|
await ctx.send("Failed to start a new game")
|
||||||
|
else:
|
||||||
|
await ctx.send("New game has started")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ww.command()
|
@ww.command()
|
||||||
async def join(self, ctx):
|
async def join(self, ctx):
|
||||||
@ -55,7 +59,7 @@ class Werewolf:
|
|||||||
game = self._get_game(ctx.guild)
|
game = self._get_game(ctx.guild)
|
||||||
|
|
||||||
if not game:
|
if not game:
|
||||||
ctx.send("No game to join!\nCreate a new one with `[p]ww new`")
|
await ctx.send("No game to join!\nCreate a new one with `[p]ww new`")
|
||||||
return
|
return
|
||||||
|
|
||||||
await game.join(ctx.author, ctx.channel)
|
await game.join(ctx.author, ctx.channel)
|
||||||
@ -69,7 +73,18 @@ class Werewolf:
|
|||||||
game = self._get_game(ctx.guild)
|
game = self._get_game(ctx.guild)
|
||||||
|
|
||||||
await game.quit(ctx.author, ctx.channel)
|
await game.quit(ctx.author, ctx.channel)
|
||||||
|
|
||||||
|
@ww.command()
|
||||||
|
async def start(self, ctx):
|
||||||
|
"""
|
||||||
|
Checks number of players and attempts to start the game
|
||||||
|
"""
|
||||||
|
game = self._get_game(guild)
|
||||||
|
if not game:
|
||||||
|
await ctx.send("No game running, cannot start")
|
||||||
|
|
||||||
|
await game.setup(ctx)
|
||||||
|
|
||||||
@ww.command()
|
@ww.command()
|
||||||
async def vote(self, ctx, id):
|
async def vote(self, ctx, id):
|
||||||
"""
|
"""
|
||||||
@ -77,7 +92,7 @@ class Werewolf:
|
|||||||
"""
|
"""
|
||||||
game = self._get_game(guild)
|
game = self._get_game(guild)
|
||||||
if not game:
|
if not game:
|
||||||
ctx.send("No game running, cannot vote")
|
await ctx.send("No game running, cannot vote")
|
||||||
|
|
||||||
# Game handles response now
|
# Game handles response now
|
||||||
channel = ctx.channel
|
channel = ctx.channel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user