reworking a bunch of stuff

This commit is contained in:
Nikolaj
2024-10-28 13:05:06 +01:00
parent f21cbba726
commit bc59bf9b05
142 changed files with 1385 additions and 845 deletions

View File

@ -0,0 +1,5 @@
"""Functions related to the Star Wars TTRPG."""
__all__ = ["StarWars"]
from .star_wars import StarWars

View File

@ -0,0 +1,10 @@
from .star_wars_char import StarWarsChar
from .star_wars_roll import StarWarsRoll
from .star_wars_destiny import StarWarsDestiny
class StarWars():
def __init__(self, bot):
self.bot = bot
self.character = StarWarsChar(self.bot)
self.roll = StarWarsRoll(self.bot)
self.destiny = StarWarsDestiny(self.bot)

View File

@ -0,0 +1,528 @@
import json
import string
import discord
class StarWarsChar():
def __init__(self, bot):
self.bot = bot
def get_char_name(self, user : str):
self.bot.log("Getting name for "+self.bot.database_funcs.get_name(user)+"'s character")
user_character = self.bot.database["starwars characters"].find_one({"_id":user})
if user_character != None:
self.bot.log("Name is "+user_character["Name"])
return user_character["Name"]
else:
self.bot.log("Just using "+self.bot.database_funcs.get_name(user))
return self.bot.database_funcs.get_name(user)
def set_up_dict(self, cmd : dict):
self.bot.log("Setting up a dictionary in a nice way")
if bool(cmd):
keys = list(cmd)
values = list(cmd.values())
result = ""
if isinstance(values[0],dict):
return ", ".join(values)
else:
for i, key in enumerate(keys):
if type(key) is list:
if i%3 != 2:
result += "**" + key + "**" + ": " + ", ".join(values[i]) + " "
else:
result += "**" + key + "**" + ": " + ", ".join(values[i]) + "\n"
else:
if i%3 != 2:
result += "**" + key + "**" + ": " + str(values[i]) + " "
else:
result += "**" + key + "**" + ": " + str(values[i]) + "\n"
self.bot.log("Returning a dictionary, but well formatted")
return result
else:
self.bot.log("Couldn't find anything")
return "There doesn't seem to be anything here..."
def look_up(self, data : dict, key : str, cmd : str = ""):
if cmd == " ":
cmd = ""
elif cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
self.bot.log("Looking up "+key)
if key in data:
self.bot.log(key+" exists")
if cmd == "":
if type(data[key]) is dict and key != "Weapons":
return self.set_up_dict(data[key])
elif key == "Weapons":
self.bot.log("Does this even get used? I'm too scared to delete it")
if bool(data[key]):
self.bot.log("Found "+(", ".join(list(data[key]))))
return ", ".join(list(data[key]))
else:
self.bot.log("There is nothing here")
return "There doesn't seem to be anything here..."
else:
if str(data[key]) != "":
self.bot.log("Returning "+str(data[key]))
return data[key]
else:
self.bot.log("There was nothing there")
return "There doesn't seem to be anything here"
elif cmd[0] == '+':
self.bot.log("Trying to add to "+key)
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Yeah, that fucked up")
return "Can't do that"
if type(data[key]) is int:
try:
new_value = data[key] + int(cmd)
data[key] = new_value
self.bot.log("Added "+cmd+" to "+key)
return data
except:
self.bot.log("Couldn't add "+cmd+" to "+key)
return "Can't add that"
elif type(data[key]) is list:
try:
data[key].append(cmd)
self.bot.log("Added "+cmd+" to "+key)
return data
except:
self.bot.log("Couldn't add "+cmd+" to "+key)
return "Can't add that"
else:
self.bot.log("Yeah, I can't add that to "+key)
return "Can't add that"
elif cmd[0] == '-':
self.bot.log("Trying to remove/subtract from "+key)
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Yeah, that fucked up")
return "Can't do that"
if type(data[key]) is int:
try:
new_value = data[key] - int(cmd)
data[key] = new_value
self.bot.log("Subtracted "+cmd+" from "+key)
return data
except:
self.bot.log("Couldn't subtract "+cmd+" from "+key)
return "Can't remove that"
elif type(data[key]) is list:
try:
data[key].remove(cmd)
self.bot.log("Removed "+cmd+" from "+key)
return data
except:
self.bot.log("Couldn't remove "+cmd+" from "+key)
return "Can't remove that"
else:
self.bot.log("Yeah, I can't remove/subtract that from "+key)
return "Can't remove that"
else:
while cmd[0] == ' ':
cmd = cmd[1:]
if type(data[key]) is dict:
new_key = cmd.split(" ")[0]
cmd = cmd[len(new_key):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
self.bot.log("Looking up "+new_key+" in "+key)
look_up_result = self.look_up(data[key],new_key,cmd)
if type(look_up_result) is dict:
data[key] = look_up_result
return data
else:
return look_up_result
elif type(data[key]) != list:
self.bot.log("Trying to change "+key+" to "+cmd)
try:
cmd = type(data[key])(cmd)
data[key] = cmd
self.bot.log("Did that")
return data
except:
self.bot.log("No. That did not work")
return "Wrong data type"
else:
self.bot.log("Yeah, that didn't work")
return "Wrong data type"
else:
self.bot.log("Couldn't find "+key)
self.bot.log("Testing to see if it's a multi-word key")
cmd = key + " " + cmd
words = cmd.split(" ")
search = ""
i = 0
while search not in data:
try:
search += " " + words[i]
i += 1
except:
self.bot.log("It wasn't. "+search+" doesn't exist")
return search + " doesn't exist"
if search[0] == " ":
search = search[1:]
self.bot.log("Yeah! Did that! The key was "+search)
cmd = cmd[len(search):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
self.bot.log("Returning "+search)
return self.set_up_dict(data[search])
else:
new_key = cmd.split(" ")[0]
cmd = cmd[len(new_key):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
look_up_result = self.look_up(data[search],new_key,cmd)
if type(look_up_result) is dict:
data[search] = look_up_result
return data
else:
return look_up_result
def character_sheet(self,character : dict):
self.bot.log("Setting up a character sheet for "+character["Name"])
divider = "--------------------\n"
name = character["Name"]
textf = ""
if character["Force-rating"] != 0:
textf = "\n**Force Rating**: "+str(character["Force-rating"])
text1 = "**Species**: "+character["Species"]+"\n**Career**: "+character["Career"]+"\n**Specialization Trees**: "+", ".join(character["Specialization-trees"])+textf+"\n**Soak**: "+str(character["Soak"])
text2 = "\n\n**Wounds**: "+str(character["Wounds"])+"/"+str(character["Wound-threshold"])+"\n**Strain**: "+str(character["Strain"])+"/"+str(character["Strain-threshold"])
text3 = self.set_up_dict(character["Characteristics"])
text4 = self.set_up_dict(character["Skills"])
text5 = ""
text6 = ""
text7 = ""
text8 = ""
if bool(character["Talents"]):
text5 = "**Talents**: "+", ".join(list(character["Talents"]))+"\n\n"
if bool(character["Force-powers"]):
text6 = "**Force Powers**: "+", ".join(list(character["Force-powers"]))+"\n\n"
text7 = "**Equipment**: "+", ".join(character["Equipment"])+"\n**Credits**: "+str(character["Credits"])+"\n**Weapons**: "+", ".join(list(character["Weapons"]))+"\n"+divider
if bool(character["Obligations"]):
text8 = "**Obligations**: "+",".join(list(character["Obligations"]))
return name, text1+text2+"\n\n"+text3+divider+text4+"\n"+divider+text5+text6+text7+text8
def char_data(self,user : str,cmd : str):
user_character = self.bot.database["starwars characters"].find_one({"_id":user})
key = string.capwords(cmd.split(" ")[0])
cmd = cmd[len(key):]
if cmd == " ":
cmd = ""
elif cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
self.bot.log("Looking for "+self.bot.database_funcs.get_name(user)+"'s character")
if user_character != None:
self.bot.log("Found it! Looking for "+key+" in the data")
if key in user_character:
self.bot.log("Found it!")
if type(user_character[key]) is dict:
self.bot.log("It's a dictionary!")
if cmd == "":
self.bot.log("Retrieving data")
if key == "Weapons":
if bool(user_character[key]):
self.bot.log("Returning a list of weapons")
return ", ".join(list(user_character[key]))
else:
self.bot.log("The character doesn't have any weapons. Which is probably for the best. Like, who just walks around with weapons?")
return "There doesn't seem to be anything there..."
else:
return self.set_up_dict(user_character[key])
elif cmd[0] == "+":
self.bot.log("Gonna add something!!!")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Nope. That didn't happen")
return "Can't do that"
if (key == "Talents" or key == "Force-powers") and "," in cmd:
cmd = cmd.split(",")
while cmd[1][0] == " ":
cmd[1] = cmd[1][1:]
self.bot.log("Adding "+cmd[0]+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key+"."+cmd[0] : cmd[1]}})
return cmd[0]+" added to "+key+" for " + user_character["Name"]
elif key == "Obligations" and "," in cmd:
cmd = cmd.split(",")
while cmd[1][0] == " ":
cmd[1] = cmd[1][1:]
self.bot.log("Adding "+cmd[0]+" to "+key)
try:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key+"."+cmd[0] : int(cmd[1])}})
except:
self.bot.log("Fucked that up")
return "Wrong data type"
return cmd[0]+" added to "+key+" for " + user_character["Name"]
elif key == "Weapons":
with open("gwendolyn/resources/star_wars/starwarstemplates.json", "r") as file_pointer:
templates = json.load(file_pointer)
new_weapon = templates["Weapon"]
self.bot.log("Adding "+cmd+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key+"."+cmd : new_weapon}})
return cmd+" added to weapons for " + user_character["Name"]
else:
self.bot.log("That's not happening")
return "Can't add that"
elif cmd[0] == "-":
self.bot.log("Gonna subtract/remove something")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("AAAAAAAAAAAA ")
return "Can't do that "
if key == "Talents" or key == "Force-powers" or key == "Weapons" or key == "Obligations":
self.bot.log("Trying to remove "+cmd+" from "+key)
if cmd in user_character[key]:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$unset": {cmd}})
self.bot.log("I did that")
return cmd+" removed from "+key+" from "+user_character["Name"]
else:
self.bot.log("Welp. I fucked that up")
return "Can't remove that"
else:
self.bot.log("Urgh!")
return "Can't remove that"
else:
self.bot.log("Looking up "+cmd+" in "+key)
if key == "Talents" or key == "Force-powers":
new_key = cmd
new_cmd = ""
else:
new_key = string.capwords(cmd.split(" ")[0])
new_cmd = cmd[len(new_key):]
look_up_result = self.look_up(user_character[key],new_key,new_cmd)
if type(look_up_result) is dict:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key : look_up_result}})
return "Changed " + user_character["Name"] + "'s " + key
else:
return look_up_result
else:
if cmd == "":
self.bot.log("Retrieving data")
if type(user_character[key]) is list:
return key+":\n"+", ".join(user_character[key])
else:
return user_character[key]
elif cmd[0] == '+':
self.bot.log("Adding")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Error message")
return "Can't do that"
if type(user_character[key]) is int:
try:
self.bot.log("Adding "+cmd+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$inc": {key : int(cmd)}})
return "Added " + cmd + " to " + user_character["Name"] + "'s " + key
except:
self.bot.log("BITCH SANDWICH")
return "Can't add that"
elif type(user_character[key]) is list:
try:
self.bot.log("Adding "+cmd+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$push": {key : cmd}})
return "Added " + cmd + " to " + user_character["Name"] + "'s " + key
except:
self.bot.log("tstststststs")
return "Can't add that"
else:
self.bot.log("Help")
return "Can't add that"
elif cmd[0] == '-':
self.bot.log("Removing/subtracting")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("lalalala ")
return "Can't do that"
if type(user_character[key]) is int:
try:
self.bot.log("Subtracting "+cmd+" from "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$inc": {key : -int(cmd)}})
return "Subtracted " + cmd + " from " + user_character["Name"] + "'s " + key
except:
self.bot.log("Tried it. Didn't want to")
return "Can't remove that"
elif type(user_character[key]) is list:
try:
self.bot.log("removing "+cmd+" from "+key)
try:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$pull": {key : cmd}})
except:
self.bot.log("They can only remove stuff that's actually in the list")
return "Not in list"
return "Removed " + cmd + " from " + user_character["Name"] + "'s " + key
except:
self.bot.log("nah")
return "Can't remove that"
else:
self.bot.log("nyope")
return "Can't remove that"
else:
self.bot.log("Changing "+key+" to "+cmd)
if type(user_character[key]) is int:
try:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key : int(cmd)}})
except:
self.bot.log("I don't wanna tho")
return "Can't do that"
elif type(user_character[key]) is str:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key : cmd}})
else:
self.bot.log("I don't wanna tho")
return "Can't do that"
return "Changed " + user_character["Name"] + "'s " + key +" to " + cmd
else:
self.bot.log(key+" isn't in there")
return "Couldn't find that data. Are you sure you spelled it correctly?"
else:
self.bot.log(user+" doesn't have a character")
return "You don't have a character. You can make one with /starwarscharacter"
def replace_spaces(self,cmd : str):
with_spaces = ["Specialization Trees","Wound Threshold","Strain Threshold","Defense - Ranged","Defense - Melee","Force Rating","Core Worlds","Outer Rim","Piloting - Planetary","Piloting - Space","Ranged - Heavy","Ranged - Light","Lightsaber Characteristic","Critical Injuries","Force Powers"]
without_spaces = ["Specialization-trees","Wound-threshold","Strain-threshold","Defense-ranged","Defense-melee","Force-rating","Core-worlds","Outer-rim","Piloting-planetary","Piloting-space","Ranged-heavy","Ranged-light","Lightsaber-characteristic","Critical-injuries","Force-powers"]
for i, value in enumerate(without_spaces):
cmd = cmd.replace(with_spaces[i],value)
return cmd
def replace_with_spaces(self,cmd : str):
with_spaces = ["Specialization Trees","Wound Threshold","Strain Threshold","Defense - Ranged","Defense - Melee","Force Rating","Core Worlds","Outer Rim","Piloting - Planetary","Piloting - Space","Ranged - Heavy","Ranged - light","Lightsaber Characteristic","Critical Injuries","Force Powers"]
without_spaces = ["Specialization-trees","Wound-threshold","Strain-threshold","Defense-ranged","Defense-melee","Force-rating","Core-worlds","Outer-rim","Piloting-planetary","Piloting-space","Ranged-heavy","Ranged-light","Lightsaber-characteristic","Critical-injuries","Force-powers"]
for i, value in enumerate(without_spaces):
cmd = cmd.replace(value,with_spaces[i])
return cmd
async def parse_char(self, ctx, parameters : str):
user = f"#{ctx.author.id}"
cmd = string.capwords(parameters.replace("+","+ ").replace("-","- ").replace(",",", "))
return_embed = False
cmd = self.replace_spaces(cmd)
user_character = self.bot.database["starwars characters"].find_one({"_id":user})
if cmd == " ":
cmd = ""
elif cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
if user_character != None:
title, text = self.character_sheet(user_character)
text = self.replace_with_spaces(text)
return_embed = True
else:
self.bot.log("Makin' a character for "+self.bot.database_funcs.get_name(user))
with open("gwendolyn/resources/star_wars/starwarstemplates.json", "r") as file_pointer:
templates = json.load(file_pointer)
new_char = templates["Character"]
new_char["_id"] = user
self.bot.database["starwars characters"].insert_one(new_char)
await ctx.send("Character for " + self.bot.database_funcs.get_name(user) + " created")
else:
if cmd == "Purge":
self.bot.log("Deleting "+self.bot.database_funcs.get_name(user)+"'s character")
self.bot.database["starwars characters"].delete_one({"_id":user})
await ctx.send("Character for " + self.bot.database_funcs.get_name(user) + " deleted")
else:
await ctx.send(self.replace_with_spaces(str(self.char_data(user,cmd))))
if return_embed:
embed = discord.Embed(title = title, description = text, colour=0xDEADBF)
await ctx.send(embed = embed)
def lightsaber_char(self,user : str):
user_character = self.bot.database["starwars characters"].find_one({"_id":user})
if user_character != None:
return user_character["Lightsaber-characteristic"]
def user_has_char(self,user : str):
user_character = self.bot.database["starwars characters"].find_one({"_id":user})
return user_character != None

View File

@ -0,0 +1,72 @@
class StarWarsDestiny():
def __init__(self, bot):
self.bot = bot
def destiny_new(self, num : int):
self.bot.log("Creating a new destiny pool with "+str(num)+" players")
roll, dice_results = self.bot.star_wars.roll.roll(0,0,0,0,0,0,num)
roll = "".join(sorted(roll))
with open("gwendolyn/resources/star_wars/destinyPoints.txt","wt") as file_pointer:
file_pointer.write(roll)
return "Rolled for Destiny Points and got:\n"+self.bot.star_wars.roll.diceResultToEmoji(dice_results)+"\n"+self.bot.star_wars.roll.resultToEmoji(roll)
def destiny_use(self, user : str):
with open("gwendolyn/resources/star_wars/destinyPoints.txt","rt") as file_pointer:
points = file_pointer.read()
if user == "Nikolaj":
self.bot.log("Trying to use a dark side destiny point")
if 'B' in points:
points = points.replace("B","L",1)
points = "".join(sorted(points))
with open("gwendolyn/resources/star_wars/destinyPoints.txt","wt") as file_pointer:
file_pointer.write(points)
self.bot.log("Did it")
return "Used a dark side destiny point. Destiny pool is now:\n"+self.bot.star_wars.roll.resultToEmoji(points)
else:
self.bot.log("There were no dark side destiny points")
return "No dark side destiny points"
else:
self.bot.log("Trying to use a light side destiny point")
if 'L' in points:
points = points.replace("L","B",1)
points = "".join(sorted(points))
with open("gwendolyn/resources/star_wars/destinyPoints.txt","wt") as file_pointer:
file_pointer.write(points)
self.bot.log("Did it")
return "Used a light side destiny point. Destiny pool is now:\n"+self.bot.star_wars.roll.resultToEmoji(points)
else:
self.bot.log("There were no dark side destiny points")
return "No light side destiny points"
async def parse_destiny(self, ctx, cmd : str):
user = f"#{ctx.author.id}"
if cmd != "":
while cmd[0] == ' ':
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
self.bot.log("Retrieving destiny pool info")
with open("gwendolyn/resources/star_wars/destinyPoints.txt","rt") as file_pointer:
send_message = self.bot.star_wars.roll.resultToEmoji(file_pointer.read())
else:
commands = cmd.upper().split(" ")
if commands[0] == "N":
if len(commands) > 1:
send_message = self.destiny_new(int(commands[1]))
else:
send_message = "You need to give an amount of players"
elif commands[0] == "U":
send_message = self.destiny_use(user)
else:
send_message = "I didn't quite understand that"
message_list = send_message.split("\n")
await ctx.send(message_list[0])
if len(message_list) > 1:
for message_item in message_list[1:]:
await ctx.channel.send(message_item)

View File

@ -0,0 +1,391 @@
import random
import re
import string
import json
with open("gwendolyn/resources/star_wars/starwarsskills.json", "r") as f:
skill_data = json.load(f)
class StarWarsRoll():
def __init__(self, bot):
self.bot = bot
# Rolls the specified dice
def roll(self, abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0):
result = ""
dice_result = []
for _ in range(abi):
choice = random.choice(["","S","S","SS","A","A","SA","AA"])
result += choice
dice_result.append("abi"+choice)
for _ in range(prof):
choice = random.choice(["","S","S","SS","SS","A","SA","SA","SA","AA","AA","R"])
result += choice
dice_result.append("prof"+choice)
for _ in range(dif):
choice = random.choice(["","F","FF","H","H","H","HH","FH"])
result += choice
dice_result.append("dif"+choice)
for _ in range(cha):
choice = random.choice(["","F","F","FF","FF","H","H","FH","FH","HH","HH","D"])
result += choice
dice_result.append("cha"+choice)
for _ in range(boo):
choice = random.choice(["","","S","SA","AA","A"])
result += choice
dice_result.append("boo"+choice)
for _ in range(setb):
choice = random.choice(["","","F","F","H","H"])
result += choice
dice_result.append("setb"+choice)
for _ in range (force):
choice = random.choice(["B","B","B","B","B","B","BB","L","L","LL","LL","LL"])
result += choice
dice_result.append("force"+choice)
return result, dice_result
# Lets dice cancel each other out
def simplify(self, result : str):
self.bot.log("Simplifying "+result)
simp = ""
success = (result.count('S') + result.count('R')) - (result.count('F') + result.count('D'))
advantage = result.count('A') - result.count('H')
result = re.sub("S|A|F|H","",result)
if success > 0:
for _ in range(success):
simp += "S"
elif success < 0:
for _ in range(abs(success)):
simp += "F"
if advantage > 0:
for _ in range(advantage):
simp += "A"
elif advantage < 0:
for _ in range(abs(advantage)):
simp += "H"
simp += result
return simp
# Returns emoji that symbolize the dice results
def dice_result_to_emoji(self, dice_results : list):
emoji = ""
for result in dice_results:
if result == "abiA":
emoji += "<:abil1a:695267684476125264> "
elif result == "abiSA":
emoji += "<:abil1a1s:695267684484513842> "
elif result == "abiS":
emoji += "<:abil1s:695267684514005013> "
elif result == "abiAA":
emoji += "<:abil2a:695267684547428352> "
elif result == "abiSS":
emoji += "<:abil2s:695267684761206914> "
elif result == "abi":
emoji += "<:abilbla:695267684660674602> "
elif result == "profA":
emoji += "<:prof1a:695267685361123338> "
elif result == "profSA":
emoji += "<:prof1a1s:695267685067653140> "
elif result == "profR":
emoji += "<:prof1r:695267685067522088> "
elif result == "profS":
emoji += "<:prof1s:695267684899881012> "
elif result == "profAA":
emoji += "<:prof2a:695267684996218982> "
elif result == "profSS":
emoji += "<:prof2s:695267684878647327> "
elif result == "prof":
emoji += "<:profbla:695267684698292235> "
elif result == "difF":
emoji += "<:dif1f:695267684924915804> "
elif result == "difH":
emoji += "<:dif1h:695267684908138506> "
elif result == "difFH":
emoji += "<:dif1h1f:695267684908269678> "
elif result == "difFF":
emoji += "<:dif2f:695267684924784680> "
elif result == "difHH":
emoji += "<:dif2h:695267685071585340> "
elif result == "dif":
emoji += "<:difbla:695267685000544276> "
elif result == "chaD":
emoji += "<:cha1d:695267684962533447> "
elif result == "chaF":
emoji += "<:cha1f:695267684601954346> "
elif result == "chaH":
emoji += "<:cha1h:695267685046681620> "
elif result == "chaFH":
emoji += "<:cha1h1f:695267685063327784> "
elif result == "chaFF":
emoji += "<:cha2f:695267684832641097> "
elif result == "chaHH":
emoji += "<:cha2h:695267684631183381> "
elif result == "cha":
emoji += "<:chabla:695267684895686787> "
elif result == "booA":
emoji += "<:boo1a:695267684975116329> "
elif result == "booSA":
emoji += "<:boo1a1s:695267684970922024> "
elif result == "booS":
emoji += "<:boo1s:695267684979441714> "
elif result == "booAA":
emoji += "<:boo2a:695267685100945488> "
elif result == "boo":
emoji += "<:boobla:695267684757012550> "
elif result == "setbF":
emoji += "<:set1f:695267685054939197> "
elif result == "setbH":
emoji += "<:set1h:695267685147082802> "
elif result == "setb":
emoji += "<:setbla:695267685151408169> "
elif result == "forceB":
emoji += "<:for1b:695267684593434677> "
elif result == "forceL":
emoji += "<:for1l:695267684606148640> "
elif result == "forceBB":
emoji += "<:for2b:695267684903944303> "
elif result == "forceLL":
emoji += "<:for2l:695267684992024626> "
return emoji
# Returns emoji that symbolize the results of the dice rolls
def result_to_emoji(self, result : str):
emoji = ""
for char in result:
if char == 'S':
emoji += "<:success:826026925280854026> "
elif char == 'A':
emoji += "<:advantage:826026925515604009> "
elif char == 'R':
emoji += "<:triumph:826026925319127070> "
elif char == 'F':
emoji += "<:failure:826026925288980511> "
elif char == 'H':
emoji += "<:threat:826026925280985108> "
elif char == 'D':
emoji += "<:despair:826026925272203294> "
elif char == 'L':
emoji += "<:light:826026925059211295>"
elif char == 'B':
emoji += "<:dark:826026925289373717>"
return emoji
# Converts emoji into letters
def emoji_to_result(self, emoji : str):
result = ""
for char in emoji:
if char == "<:light:691010089905029171>":
emoji += 'L'
if char == "<:dark:691010101901000852>":
emoji += 'B'
return result
# Returns emoji that symbolize the dice
def dice_to_emoji(self, dice : list):
emoji = ""
for _ in range(dice[0]):
emoji += "<:ability:690974213397282826> "
for _ in range(dice[1]):
emoji += "<:proficiency:690973435354153071> "
for _ in range(dice[2]):
emoji += "<:difficulty:690973992470708296> "
for _ in range(dice[3]):
emoji += "<:challenge:690973419906400306> "
for _ in range(dice[4]):
emoji += "<:boost:690972178216386561> "
for _ in range(dice[5]):
emoji += "<:setback:690972157890658415> "
for _ in range(dice[6]):
emoji += "<:force:690973451883774013> "
return emoji
# Rolls for obligation
def obligation_roll(self):
self.bot.log("Rolling for obligation")
data = self.bot.database["starwarscharacters"]
table = []
for character in data:
for obligation in data[character]["Obligations"]:
for _ in range(data[character]["Obligations"][obligation]):
table.append(data[character]["Name"]+", "+obligation)
while len(table) < 100:
table.append("Nothing")
return random.choice(table)
# Rolls for critical injury
async def crit_roll(self, ctx, addington : int):
difficulty_die = "<:difficulty:690973992470708296>"
setback_die = "<:setback:690972157890658415>"
boost_die = "<:boost:690972178216386561>"
roll = random.randint(1,100) + addington
injuries = [
"**Minor nick**: The target suffers 1 strain, "+difficulty_die] * 5 + [
"**Slowed down**: The target can only act during the last allied initiative slot this turn, "+difficulty_die] * 5 + [
"**Sudden Jolt**: The target drops whatever is in hand, "+difficulty_die] * 5 + [
"**Distracted**: The target cannot perform a Free maneuver during his next turn, "+difficulty_die] * 5 + [
"**Off-Balance**: The target adds "+setback_die+" to his next skill check, "+difficulty_die] * 5 + [
"**Discouraging Wound**: Flip one light side Destiny point to a dark side Destiny point (reverse if NPC), "+difficulty_die] * 5 + [
"**Stunned**: The target is staggered until the end of his next turn, "+difficulty_die] * 5 + [
"**Stinger**: Increase the difficulty of next check by one, "+difficulty_die] * 5 + [
"**Bowled Over**: The target is knocked prone and suffers 1 strain, "+difficulty_die+difficulty_die] * 5 + [
"**Head Ringer**: The target increases the difficulty of all Intellect and Cunning checks by one until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**Fearsome Wound**: The target increases the difficulty of all Presence and Willpower checks by one until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**Agonizing Wound**: The target increases the difficulty of all Brawn and Agility checks by one until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**Slightly Dazed**: The target is disoriented until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**Scattered Senses**: The target removes all "+boost_die+" from skill checks until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**Hamstrung**: The target loses his free maneuver until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**Overpowered**: The target leaves himself open, and the attacker may immediately attempt another free attack agains him, using the exact same pool as the original, "+difficulty_die+difficulty_die] * 5 + [
"**Winded**: Until the end of the encounter, the target cannot voluntarily suffer strain to activate any abilities or gain additional maneuvers, "+difficulty_die+difficulty_die] * 5 + [
"**Compromised**: Incerase difficulty of all skill checks by one until the end of the encounter, "+difficulty_die+difficulty_die] * 5 + [
"**At the brink**: The target suffers 1 strain each time he performs an action, "+difficulty_die+difficulty_die+difficulty_die] * 5 + [
"**Crippled**: One of the target's limbs (selected by the GM) is crippled until healed or replaced. Increase difficulty of all checks that require use of that limb by one, "+difficulty_die+difficulty_die+difficulty_die] * 5 + [
"**Maimed**: One of the target's limbs (selected by the GM) is permanently lost. Unless the target has a cybernetic replacement, the target cannot perform actions that would require the use of that limb. All other actions gain "+setback_die+", "+difficulty_die+difficulty_die+difficulty_die] * 5 + [
"HI"] * 5 + [
"**Temporarily Lame**: Until this critical injury is healed, the target cannot perform more than one maneuver during his turn, "+difficulty_die+difficulty_die+difficulty_die] * 5 + [
"**Blinded**: The target can no longer see. Upgrade the difficulty of all checks twice. Upgrade the difficulty of perception checks three times, "+difficulty_die+difficulty_die+difficulty_die] * 5 + [
"**Knocked Senseless**: The target is staggered for the remainder of the encounter, "+difficulty_die+difficulty_die+difficulty_die] * 5 + [
"GI"] * 5 + [
"**Bleeding Out**: Every round, the target suffers 1 wound and 1 strain at the beginning of his turn. For every five wounds he suffers beyond his wound threshold, he suffers one additional critical injury. (If he suffers this one again, roll again), "+difficulty_die+difficulty_die+difficulty_die+difficulty_die] * 10 + [
"**The End is Nigh**: The target will die after the last initiative slot during the next round, "+difficulty_die+difficulty_die+difficulty_die+difficulty_die] * 10 + [
"**Dead**: U B Dead :("]
if roll >= len(injuries):
results = injuries[-1]
else:
results = injuries[roll]
if results == "HI":
characteristic = random.choice(["brawn"] * 3 + ["agility"] * 3 + ["intellect", "cunning", "presence"])
results = "**Horrific Injury**: Until this criticil injury is healed, treat the target's "+characteristic+" as if it's one lower, "+difficulty_die+difficulty_die+difficulty_die
if results == "GI":
characteristic = random.choice(["brawn"] * 3 + ["agility"] * 3 + ["intellect", "cunning", "presence"])
results = "**Gruesome Injury**: The target's "+characteristic+" is permanently one lower, "+difficulty_die+difficulty_die+difficulty_die+difficulty_die
send_message = "Roll: "+str(roll)+"\nInjury:\n"+results
message_list = send_message.split("\n")
await ctx.send(message_list[0])
if len(message_list) > 1:
for message_item in message_list[1:]:
await ctx.channel.send(message_item)
# Parses the command into something the other functions understand
async def parse_roll(self, ctx, cmd : str = ""):
user = f"#{ctx.author.id}"
cmd = re.sub(' +',' ',cmd.upper()) + " "
if cmd[0] == " ":
cmd = cmd[1:]
cmd = self.bot.star_wars.character.replaceSpaces(string.capwords(cmd))
commands = cmd.split(" ")
valid_command = False
if commands[0] == "":
roll_parameters = [1,0,3,0,0,0,0]
else:
roll_parameters = [0,0,0,0,0,0,0]
if string.capwords(commands[0]) == "Obligations":
send_message = self.obligation_roll()
elif string.capwords(commands[0]) in skill_data:
self.bot.log("Oh look! This guy has skills!")
if self.bot.star_wars.character.userHasChar(user):
self.bot.log("They have a character. That much we know")
skill_level = self.bot.star_wars.character.char_data(user,"Skills " + string.capwords(commands[0]))
if string.capwords(commands[0]) == "Lightsaber":
self.bot.log("The skill is lightsaber")
char_level = self.bot.star_wars.character.char_data(user,"Characteristics " + self.bot.star_wars.character.lightsaberChar(user))
else:
char_level = self.bot.star_wars.character.char_data(user,"Characteristics " + skill_data[string.capwords(commands[0])])
ability_dice = abs(char_level-skill_level)
proficiency_dice = min(skill_level,char_level)
commands = [str(ability_dice)] + [str(proficiency_dice)] + commands[1:]
self.bot.log("Converted skill to dice")
valid_command = True
else:
self.bot.log("Okay, no they don't i guess")
send_message = "You don't have a user. You can make one with /starwarscharacter"
elif string.capwords(commands[0]) in ["Ranged","Piloting"]:
self.bot.log("They fucked up writing the name of a ranged or piloting skill")
if string.capwords(commands[0]) == "Ranged":
send_message = "Did you mean \"Ranged - Heavy\" or \"Ranged - Light\""
else:
send_message = "Did you mean \"Piloting - Planetary\" or \"Piloting - Space\""
else:
valid_command = True
if valid_command:
self.bot.log("Converting commands to dice")
for i, command in enumerate(commands):
if command != "":
command = command.upper()
if command[0] == "A":
roll_parameters[0] = int(command.replace("A",""))
elif command[0] == "P":
roll_parameters[1] = int(command.replace("P",""))
elif command[0] == "D":
roll_parameters[2] = int(command.replace("D",""))
elif command[0] == "C":
roll_parameters[3] = int(command.replace("C",""))
elif command[0] == "B":
roll_parameters[4] = int(command.replace("B",""))
elif command[0] == "S":
roll_parameters[5] = int(command.replace("S",""))
elif command[0] == "F":
roll_parameters[6] = int(command.replace("F",""))
else:
roll_parameters[i] = int(command)
self.bot.log("Rolling "+str(roll_parameters))
roll_results, dice_results = self.roll(roll_parameters[0],roll_parameters[1],roll_parameters[2],roll_parameters[3],roll_parameters[4],roll_parameters[5],roll_parameters[6])
simplified = self.simplify(roll_results)
name = self.bot.star_wars.character.getChar_name(user)
self.bot.log("Returns results and simplified results")
if simplified == "":
send_message = name + " rolls: " + "\n" + self.dice_result_to_emoji(dice_results) + "\nEverything cancels out!"
else:
send_message = name + " rolls: " + "\n" + self.dice_result_to_emoji(dice_results) + "\n" + self.result_to_emoji(simplified)
message_list = send_message.split("\n")
await ctx.send(message_list[0])
if len(message_list) > 1:
for message_item in message_list[1:]:
if message_item == "":
self.bot.log("Tried to send empty message")
else:
await ctx.channel.send(message_item)