Set some stuff up for werewolf 🐺
This commit is contained in:
@@ -5,14 +5,14 @@ from funcs import logThis
|
|||||||
|
|
||||||
class GamesCog(commands.Cog):
|
class GamesCog(commands.Cog):
|
||||||
|
|
||||||
def __init__(self,client):
|
def __init__(self,bot):
|
||||||
"""Runs game stuff."""
|
"""Runs game stuff."""
|
||||||
self.client = client
|
self.bot = bot
|
||||||
|
|
||||||
# Checks user balance
|
# Checks user balance
|
||||||
@commands.command(aliases = ["b"])
|
@commands.command(aliases = ["b"])
|
||||||
async def balance(self, ctx):
|
async def balance(self, ctx):
|
||||||
response = self.client.money.checkBalance("#"+str(ctx.message.author.id))
|
response = self.bot.money.checkBalance("#"+str(ctx.message.author.id))
|
||||||
if response == 1:
|
if response == 1:
|
||||||
new_message = ctx.message.author.display_name + " has " + str(response) + " GwendoBuck"
|
new_message = ctx.message.author.display_name + " has " + str(response) + " GwendoBuck"
|
||||||
else:
|
else:
|
||||||
@@ -25,19 +25,19 @@ class GamesCog(commands.Cog):
|
|||||||
commands = content.split(" ")
|
commands = content.split(" ")
|
||||||
amount = int(commands[-1])
|
amount = int(commands[-1])
|
||||||
username = " ".join(commands[:-1])
|
username = " ".join(commands[:-1])
|
||||||
if self.client.funcs.getID(username) == None:
|
if self.bot.funcs.getID(username) == None:
|
||||||
async for member in ctx.guild.fetch_members(limit=None):
|
async for member in ctx.guild.fetch_members(limit=None):
|
||||||
if member.display_name.lower() == username.lower():
|
if member.display_name.lower() == username.lower():
|
||||||
username = member.display_name
|
username = member.display_name
|
||||||
userID = "#" + str(member.id)
|
userID = "#" + str(member.id)
|
||||||
self.client.database["users"].insert_one({"_id":userID,"user name":username,"money":0})
|
self.bot.database["users"].insert_one({"_id":userID,"user name":username,"money":0})
|
||||||
response = self.client.money.giveMoney("#"+str(ctx.message.author.id),username,amount)
|
response = self.bot.money.giveMoney("#"+str(ctx.message.author.id),username,amount)
|
||||||
await ctx.send(response)
|
await ctx.send(response)
|
||||||
|
|
||||||
# Invest GwendoBucks in the stock market
|
# Invest GwendoBucks in the stock market
|
||||||
@commands.command(aliases=["i"])
|
@commands.command(aliases=["i"])
|
||||||
async def invest(self, ctx, *, content = "check"):
|
async def invest(self, ctx, *, content = "check"):
|
||||||
response = self.client.invest.parseInvest(content,"#"+str(ctx.message.author.id))
|
response = self.bot.invest.parseInvest(content,"#"+str(ctx.message.author.id))
|
||||||
if response.startswith("**"):
|
if response.startswith("**"):
|
||||||
responses = response.split("\n")
|
responses = response.split("\n")
|
||||||
em = discord.Embed(title=responses[0],description="\n".join(responses[1:]),colour=0x00FF00)
|
em = discord.Embed(title=responses[0],description="\n".join(responses[1:]),colour=0x00FF00)
|
||||||
@@ -49,7 +49,7 @@ class GamesCog(commands.Cog):
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def trivia(self, ctx, *, content = ""):
|
async def trivia(self, ctx, *, content = ""):
|
||||||
if content == "":
|
if content == "":
|
||||||
question, answers, correctAnswer = self.client.trivia.triviaStart(str(ctx.message.channel.id))
|
question, answers, correctAnswer = self.bot.trivia.triviaStart(str(ctx.message.channel.id))
|
||||||
if answers != "":
|
if answers != "":
|
||||||
results = "**"+question+"**\n"
|
results = "**"+question+"**\n"
|
||||||
for x, answer in enumerate(answers):
|
for x, answer in enumerate(answers):
|
||||||
@@ -59,9 +59,9 @@ class GamesCog(commands.Cog):
|
|||||||
|
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
self.client.trivia.triviaCountPoints(str(ctx.message.channel.id))
|
self.bot.trivia.triviaCountPoints(str(ctx.message.channel.id))
|
||||||
|
|
||||||
self.client.funcs.deleteGame("trivia questions",str(ctx.message.channel.id))
|
self.bot.funcs.deleteGame("trivia questions",str(ctx.message.channel.id))
|
||||||
|
|
||||||
logThis("Time's up for the trivia question",str(ctx.message.channel.id))
|
logThis("Time's up for the trivia question",str(ctx.message.channel.id))
|
||||||
await ctx.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
|
await ctx.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
|
||||||
@@ -69,7 +69,7 @@ class GamesCog(commands.Cog):
|
|||||||
await ctx.send(question)
|
await ctx.send(question)
|
||||||
|
|
||||||
elif content in ["a","b","c","d"]:
|
elif content in ["a","b","c","d"]:
|
||||||
response = self.client.trivia.triviaAnswer("#"+str(ctx.message.author.id),str(ctx.message.channel.id),content)
|
response = self.bot.trivia.triviaAnswer("#"+str(ctx.message.author.id),str(ctx.message.channel.id),content)
|
||||||
if response.startswith("Locked in "):
|
if response.startswith("Locked in "):
|
||||||
await ctx.message.add_reaction("👍")
|
await ctx.message.add_reaction("👍")
|
||||||
else:
|
else:
|
||||||
@@ -81,32 +81,37 @@ class GamesCog(commands.Cog):
|
|||||||
# Runs a game of blackjack
|
# Runs a game of blackjack
|
||||||
@commands.command(aliases = ["bj"])
|
@commands.command(aliases = ["bj"])
|
||||||
async def blackjack(self, ctx, *, content = ""):
|
async def blackjack(self, ctx, *, content = ""):
|
||||||
await self.client.blackjack.parseBlackjack(content,ctx)
|
await self.bot.blackjack.parseBlackjack(content,ctx)
|
||||||
|
|
||||||
# Runs a game of Connect four
|
# Runs a game of Connect four
|
||||||
@commands.command(aliases = ["fiar","connect4","connectfour","4iar","4inarow"])
|
@commands.command(aliases = ["fiar","connect4","connectfour","4iar","4inarow"])
|
||||||
async def fourinarow(self, ctx, *, content = ""):
|
async def fourinarow(self, ctx, *, content = ""):
|
||||||
await self.client.gameLoops.fiar(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
await self.bot.gameLoops.fiar(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
||||||
|
|
||||||
# Runs a game of Monopoly
|
# Runs a game of Monopoly
|
||||||
@commands.command(aliases = ["m","mon","mono"])
|
@commands.command(aliases = ["m","mon","mono"])
|
||||||
async def monopoly(self, ctx, *, content = ""):
|
async def monopoly(self, ctx, *, content = ""):
|
||||||
await self.client.gameLoops.runMonopoly(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
await self.bot.gameLoops.runMonopoly(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
||||||
|
|
||||||
# Runs a game of Hangman
|
# Runs a game of Hangman
|
||||||
@commands.command(aliases = ["hm"])
|
@commands.command(aliases = ["hm"])
|
||||||
async def hangman(self, ctx, *, content = "start"):
|
async def hangman(self, ctx, *, content = "start"):
|
||||||
await self.client.gameLoops.runHangman(ctx.message.channel,"#"+str(ctx.message.author.id),content)
|
await self.bot.gameLoops.runHangman(ctx.message.channel,"#"+str(ctx.message.author.id),content)
|
||||||
|
|
||||||
# Runs a game of Hex
|
# Runs a game of Hex
|
||||||
@commands.command(name="hex")
|
@commands.command(name="hex")
|
||||||
async def hexCommand(self, ctx, *, content = ""):
|
async def hexCommand(self, ctx, *, content = ""):
|
||||||
await self.client.gameLoops.runHex(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
await self.bot.gameLoops.runHex(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
||||||
|
|
||||||
# Runs a game of Love Letter
|
# Runs a game of Love Letter
|
||||||
@commands.command(aliases = ["ll"])
|
@commands.command(aliases = ["ll"])
|
||||||
async def loveletter(self, ctx, *, content = ""):
|
async def loveletter(self, ctx, *, content = ""):
|
||||||
await self.client.gameLoops.runLoveletter(ctx.message.channel,content,"#"+str(ctx.message.author.id),ctx.message.author)
|
await self.bot.gameLoops.runLoveletter(ctx.message.channel,content,"#"+str(ctx.message.author.id),ctx.message.author)
|
||||||
|
|
||||||
def setup(client):
|
# Runs a game of Werewolf
|
||||||
client.add_cog(GamesCog(client))
|
@commands.command()
|
||||||
|
async def werewolf(self,ctx, *,content = "start"):
|
||||||
|
await self.bot.werewolf.parseWerewolf(ctx,content.lower())
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(GamesCog(bot))
|
||||||
@@ -30,6 +30,7 @@ class Funcs():
|
|||||||
def stopServer(self):
|
def stopServer(self):
|
||||||
self.bot.database["trivia questions"].delete_many({})
|
self.bot.database["trivia questions"].delete_many({})
|
||||||
self.bot.database["blackjack games"].delete_many({})
|
self.bot.database["blackjack games"].delete_many({})
|
||||||
|
self.bot.database["werewolf games"].delete_many({})
|
||||||
|
|
||||||
g = git.cmd.Git("")
|
g = git.cmd.Git("")
|
||||||
g.pull()
|
g.pull()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class Blackjack():
|
|||||||
else:
|
else:
|
||||||
for x in range(len(values)):
|
for x in range(len(values)):
|
||||||
values[x] += int(cardValue)
|
values[x] += int(cardValue)
|
||||||
print(values[x])
|
|
||||||
|
|
||||||
values.sort()
|
values.sort()
|
||||||
|
|
||||||
@@ -91,9 +90,7 @@ class Blackjack():
|
|||||||
else:
|
else:
|
||||||
done = True
|
done = True
|
||||||
|
|
||||||
print(dealerHand)
|
|
||||||
if self.calcHandValue(dealerHand) > 21:
|
if self.calcHandValue(dealerHand) > 21:
|
||||||
print("yeet")
|
|
||||||
self.bot.database["blackjack games"].update_one({"_id":channel},{"$set":{"dealer busted":True}})
|
self.bot.database["blackjack games"].update_one({"_id":channel},{"$set":{"dealer busted":True}})
|
||||||
|
|
||||||
return done
|
return done
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from .gameLoops import GameLoops
|
|||||||
from .monopoly import Monopoly
|
from .monopoly import Monopoly
|
||||||
from .hangman import Hangman
|
from .hangman import Hangman
|
||||||
from .hex import HexGame
|
from .hex import HexGame
|
||||||
|
from .werewolf import Werewolf
|
||||||
|
|
||||||
class Games():
|
class Games():
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
@@ -19,3 +20,4 @@ class Games():
|
|||||||
bot.monopoly = Monopoly(bot)
|
bot.monopoly = Monopoly(bot)
|
||||||
bot.hangman = Hangman(bot)
|
bot.hangman = Hangman(bot)
|
||||||
bot.hex = HexGame(bot)
|
bot.hex = HexGame(bot)
|
||||||
|
bot.werewolf = Werewolf(bot)
|
||||||
|
|||||||
133
funcs/games/werewolf.py
Normal file
133
funcs/games/werewolf.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import datetime
|
||||||
|
import discord
|
||||||
|
import asyncio
|
||||||
|
from funcs import logThis
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
minimumPlayers = 1
|
||||||
|
minimumPlayersWithAI = 5
|
||||||
|
|
||||||
|
class Team(Enum):
|
||||||
|
Villager = 1
|
||||||
|
Werewolf = 2
|
||||||
|
|
||||||
|
class Role():
|
||||||
|
def __init__(self,team,isWerewolf=False,isSeer=False,isSorcerer=False):
|
||||||
|
self.alive = True
|
||||||
|
self.team = team
|
||||||
|
self.isWerewolf = isWerewolf
|
||||||
|
self.isSeer = isSeer
|
||||||
|
self.isSorcerer = isSorcerer
|
||||||
|
|
||||||
|
class VillagerRole(Role):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(Team.Villager)
|
||||||
|
|
||||||
|
class WerewolfRole(Role):
|
||||||
|
def __init__(self):
|
||||||
|
super.__init__(Team.Werewolf,isWerewolf=True)
|
||||||
|
|
||||||
|
class SeerRole(Role):
|
||||||
|
def __init__(self):
|
||||||
|
super.__init__(Team.Villager,isSeer=True)
|
||||||
|
|
||||||
|
class SorcererRole(Role):
|
||||||
|
def __init__(self):
|
||||||
|
super.__init__(Team.Werewolf,isSorcerer=True)
|
||||||
|
|
||||||
|
class SorcererWerewolfRole(Role):
|
||||||
|
def __init__(self):
|
||||||
|
super.__init__(Team.Werewolf,isWerewolf=True,isSorcerer=True)
|
||||||
|
|
||||||
|
class Werewolf():
|
||||||
|
def __init__(self,bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
# Starts a game of werewolf
|
||||||
|
def werewolfStart(self,channel:str):
|
||||||
|
game = self.bot.database["werewolf games"].find_one({"_id":channel})
|
||||||
|
|
||||||
|
logThis("Trying to start a werewolf game in "+channel)
|
||||||
|
|
||||||
|
if game == None:
|
||||||
|
|
||||||
|
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
|
|
||||||
|
newGame = {"_id":channel,"users": {},"round":0,"turn":0,"turnOrder":[],"current message":None,"gameID":gameID}
|
||||||
|
|
||||||
|
self.bot.database["werewolf games"].insert_one(newGame)
|
||||||
|
|
||||||
|
return "Started a game of werewolf. Use \"!werewolf join\" to join the game", True
|
||||||
|
else:
|
||||||
|
logThis("There is already a werewolf game going on in "+channel)
|
||||||
|
return "There's already a werewolf game going on in this channel. Try again in a few minutes.", False
|
||||||
|
|
||||||
|
# Stops the game of werewolf
|
||||||
|
def werewolfStop(self,channel:str):
|
||||||
|
game = self.bot.database["werewolf games"].find_one({"_id":channel})
|
||||||
|
|
||||||
|
if game != None:
|
||||||
|
self.bot.database["werewolf games"].delete_one({"_id":channel})
|
||||||
|
return "Ended the werewolf game"
|
||||||
|
else:
|
||||||
|
return "There's no game going on right now"
|
||||||
|
|
||||||
|
async def werewolfLoop(self,ctx,round):
|
||||||
|
logThis(f"Starting loop {round} of Werewolf game")
|
||||||
|
channel = "#"+str(ctx.channel.id)
|
||||||
|
if round == 0:
|
||||||
|
await asyncio.sleep(120)
|
||||||
|
game = self.bot.database["werewolf games"].find_one({"_id":channel})
|
||||||
|
AINumber = 1
|
||||||
|
while len(game["users"].keys()) >= minimumPlayers and len(game["users"].keys()) < minimumPlayersWithAI:
|
||||||
|
user = {"role": None}
|
||||||
|
self.bot.database["werewolf games"].update_one({"_id":"#"+str(ctx.channel.id)},
|
||||||
|
{"$set":{"users."+str(AINumber):user}})
|
||||||
|
game = self.bot.database["werewolf games"].find_one({"_id":channel})
|
||||||
|
AINumber += 1
|
||||||
|
self.bot.database["werewolf games"].update_one({"_id":channel},{"$inc":{"round":1}})
|
||||||
|
await self.werewolfLoop(ctx,round+1)
|
||||||
|
else:
|
||||||
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
|
async def werewolfJoin(self,ctx):
|
||||||
|
currentGames = list(self.bot.database["werewolf games"].find({}))
|
||||||
|
for game in currentGames:
|
||||||
|
if "#"+str(ctx.message.author.id) in game["users"].keys():
|
||||||
|
return f"{ctx.message.author.display_name} is already in a werewolf game", False
|
||||||
|
|
||||||
|
game = self.bot.database["werewolf games"].find_one({"_id":"#"+str(ctx.channel.id)})
|
||||||
|
if game["round"] == 0:
|
||||||
|
user = {"role": None}
|
||||||
|
self.bot.database["werewolf games"].update_one({"_id":"#"+str(ctx.channel.id)},
|
||||||
|
{"$set":{"users."+"#"+str(ctx.message.author.id):user}})
|
||||||
|
return "You joined the werewolf game", True
|
||||||
|
else:
|
||||||
|
return "It's too late to join", False
|
||||||
|
|
||||||
|
async def parseWerewolf(self,ctx,content):
|
||||||
|
if content == "start":
|
||||||
|
response, started = self.werewolfStart("#"+str(ctx.channel.id))
|
||||||
|
await ctx.send(response)
|
||||||
|
if started:
|
||||||
|
await self.werewolfLoop(ctx,0)
|
||||||
|
|
||||||
|
elif content == "stop":
|
||||||
|
await ctx.send(self.werewolfStop("#"+str(ctx.channel.id)))
|
||||||
|
|
||||||
|
elif content == "join":
|
||||||
|
response, joined = await self.werewolfJoin(ctx)
|
||||||
|
await ctx.send(response)
|
||||||
|
if joined:
|
||||||
|
game = self.bot.database["werewolf games"].find_one({"_id":"#"+str(ctx.channel.id)})
|
||||||
|
if game["current message"] != None:
|
||||||
|
await ctx.channel.fetch_message(game["current message"]).delete()
|
||||||
|
users = ""
|
||||||
|
for x, user in enumerate(list(game["users"].keys())):
|
||||||
|
users += str(x+1)+") "+self.bot.funcs.getName(user)+"\n"
|
||||||
|
|
||||||
|
if len(list(game["users"].keys())) < minimumPlayers:
|
||||||
|
users += f"You need at least {minimumPlayers} players to play werewolf."
|
||||||
|
em = discord.Embed(title="Current Players",description=users,colour=0x00FF00)
|
||||||
|
await ctx.send(embed=em)
|
||||||
Reference in New Issue
Block a user