dice in swroll

This commit is contained in:
NikolajDanger
2020-04-02 16:47:41 +02:00
parent 43d4fca76f
commit 87cebc6ab7
4 changed files with 149 additions and 36 deletions

View File

@ -164,13 +164,19 @@ async def on_message(message):
elif message.content.lower().startswith("!swroll"): elif message.content.lower().startswith("!swroll"):
funcs.logThis(message.author.name+" ran \""+message.content+"\"") funcs.logThis(message.author.name+" ran \""+message.content+"\"")
command = funcs.cap(message.content.lower().replace("!swroll","")) command = funcs.cap(message.content.lower().replace("!swroll",""))
await message.channel.send(funcs.parseRoll(message.author.name,command)) newMessage = funcs.parseRoll(message.author.name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
# Deals with Destiny Points and stuff # Deals with Destiny Points and stuff
elif message.content.lower().startswith("!swd"): elif message.content.lower().startswith("!swd"):
funcs.logThis(message.author.name+" ran \""+message.content+"\"") funcs.logThis(message.author.name+" ran \""+message.content+"\"")
command = message.content.lower().replace("!swd","") command = message.content.lower().replace("!swd","")
await message.channel.send(funcs.parseDestiny(message.author.name,command)) newMessage = funcs.parseDestiny(message.author.name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
# Accesses and changes character sheet data with the parseChar function # Accesses and changes character sheet data with the parseChar function
# from funcs/swfuncs/swchar.py # from funcs/swfuncs/swchar.py

View File

@ -4,12 +4,13 @@ from funcs import logThis
def destinyNew(num : int): def destinyNew(num : int):
logThis("Creating a new destiny pool with "+str(num)+" players") logThis("Creating a new destiny pool with "+str(num)+" players")
roll = swroll.roll(0,0,0,0,0,0,num) roll, diceResults = swroll.roll(0,0,0,0,0,0,num)
roll = "".join(sorted(roll))
with open("resources/destinyPoints.txt","wt") as f: with open("resources/destinyPoints.txt","wt") as f:
f.write(roll) f.write(roll)
return "Rolled for Destiny Points and got:\n"+swroll.resultToEmoji(roll) return "Rolled for Destiny Points and got:\n"+swroll.diceResultToEmoji(diceResults)+"\n"+swroll.resultToEmoji(roll)
def destinyUse(user : str): def destinyUse(user : str):
with open("resources/destinyPoints.txt","rt") as f: with open("resources/destinyPoints.txt","rt") as f:
@ -19,6 +20,7 @@ def destinyUse(user : str):
logThis("Trying to use a dark side destiny point") logThis("Trying to use a dark side destiny point")
if 'B' in points: if 'B' in points:
points = points.replace("B","L",1) points = points.replace("B","L",1)
points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f: with open("resources/destinyPoints.txt","wt") as f:
f.write(points) f.write(points)
logThis("Did it") logThis("Did it")
@ -30,6 +32,7 @@ def destinyUse(user : str):
logThis("Trying to use a light side destiny point") logThis("Trying to use a light side destiny point")
if 'L' in points: if 'L' in points:
points = points.replace("L","B",1) points = points.replace("L","B",1)
points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f: with open("resources/destinyPoints.txt","wt") as f:
f.write(points) f.write(points)
logThis("Did it") logThis("Did it")

View File

@ -12,28 +12,43 @@ with open("resources/swskills.json", "r") as f:
def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0): def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0):
result = "" result = ""
diceResult = []
for x in range(abi): for x in range(abi):
result += random.choice(["","S","S","SS","A","A","SA","AA"]) choice = random.choice(["","S","S","SS","A","A","SA","AA"])
result += choice
diceResult.append("abi"+choice)
for x in range(prof): for x in range(prof):
result += random.choice(["","S","S","SS","SS","A","SA","SA","SA","AA","AA","R"]) choice = random.choice(["","S","S","SS","SS","A","SA","SA","SA","AA","AA","R"])
result += choice
diceResult.append("prof"+choice)
for x in range(dif): for x in range(dif):
result += random.choice(["","F","FF","H","H","H","HH","FH"]) choice = random.choice(["","F","FF","H","H","H","HH","FH"])
result += choice
diceResult.append("dif"+choice)
for x in range(cha): for x in range(cha):
result += random.choice(["","F","F","FF","FF","H","H","FH","FH","HH","HH","D"]) choice = random.choice(["","F","F","FF","FF","H","H","FH","FH","HH","HH","D"])
result += choice
diceResult.append("cha"+choice)
for x in range(boo): for x in range(boo):
result += random.choice(["","","S","SA","AA","A"]) choice = random.choice(["","","S","SA","AA","A"])
result += choice
diceResult.append("boo"+choice)
for x in range(setb): for x in range(setb):
result += random.choice(["","","F","F","H","H"]) choice = random.choice(["","","F","F","H","H"])
result += choice
diceResult.append("setb"+choice)
for x in range (force): for x in range (force):
result += random.choice(["B","B","B","B","B","B","BB","L","L","Ll","LL","LL"]) choice = random.choice(["B","B","B","B","B","B","BB","L","L","LL","LL","LL"])
result += choice
diceResult.append("force"+choice)
return result return result, diceResult
def simplify(result : str): def simplify(result : str):
logThis("Simplifying "+result) logThis("Simplifying "+result)
@ -60,6 +75,94 @@ def simplify(result : str):
return simp return simp
def diceResultToEmoji(diceResults : list):
emoji = ""
for result in diceResults:
if result == "abiA":
emoji += "<:abil1a:695267684476125264> "
if result == "abiSA":
emoji += "<:abil1a1s:695267684484513842> "
if result == "abiS":
emoji += "<:abil1s:695267684514005013> "
if result == "abiAA":
emoji += "<:abil2a:695267684547428352> "
if result == "abiSS":
emoji += "<:abil2s:695267684761206914> "
if result == "abi":
emoji += "<:abilbla:695267684660674602> "
if result == "profA":
emoji += "<:prof1a:695267685361123338> "
if result == "profSA":
emoji += "<:prof1a1s:695267685067653140> "
if result == "profR":
emoji += "<:prof1r:695267685067522088> "
if result == "profS":
emoji += "<:prof1s:695267684899881012> "
if result == "profAA":
emoji += "<:prof2a:695267684996218982> "
if result == "profSS":
emoji += "<:prof2s:695267684878647327> "
if result == "prof":
emoji += "<:profbla:695267684698292235> "
if result == "difF":
emoji += "<:dif1f:695267684924915804> "
if result == "difH":
emoji += "<:dif1h:695267684908138506> "
if result == "difFH":
emoji += "<:dif1h1f:695267684908269678> "
if result == "difFF":
emoji += "<:dif2f:695267684924784680> "
if result == "difHH":
emoji += "<:dif2h:695267685071585340> "
if result == "dif":
emoji += "<:difbla:695267685000544276> "
if result == "chaD":
emoji += "<:cha1d:695267684962533447> "
if result == "chaF":
emoji += "<:cha1f:695267684601954346> "
if result == "chaH":
emoji += "<:cha1h:695267685046681620> "
if result == "chaFH":
emoji += "<:cha1h1f:695267685063327784> "
if result == "chaFF":
emoji += "<:cha2f:695267684832641097> "
if result == "chaHH":
emoji += "<:cha2h:695267684631183381> "
if result == "cha":
emoji += "<:chabla:695267684895686787> "
if result == "booA":
emoji += "<:boo1a:695267684975116329> "
if result == "booSA":
emoji += "<:boo1a1s:695267684970922024> "
if result == "booS":
emoji += "<:boo1s:695267684979441714> "
if result == "booAA":
emoji += "<:boo2a:695267685100945488> "
if result == "boo":
emoji += "<:boobla:695267684757012550> "
if result == "setbF":
emoji += "<:set1f:695267685054939197> "
if result == "setbH":
emoji += "<:set1h:695267685147082802> "
if result == "setb":
emoji += "<:setbla:695267685151408169> "
if result == "forceB":
emoji += "<:for1b:695267684593434677> "
if result == "forceL":
emoji += "<:for1l:695267684606148640> "
if result == "forceBB":
emoji += "<:for2b:695267684903944303> "
if result == "forceLL":
emoji += "<:for2l:695267684992024626> "
return emoji
def resultToEmoji(result : str): def resultToEmoji(result : str):
emoji = "" emoji = ""
for char in result: for char in result:
@ -173,22 +276,23 @@ def parseRoll(user : str,cmd : str = ""):
try: try:
logThis("Converting commands to dice") logThis("Converting commands to dice")
for x in range(len(commands)): for x in range(len(commands)-1):
if commands[x-1] != "": if commands[x] != "":
if commands[x-1][0] == "A": commands[x] = commands[x].upper()
rollParameters[0] = int(commands[x-1].replace("A","")) if commands[x][0] == "A":
elif commands[x-1][0] == "P": rollParameters[0] = int(commands[x].replace("A",""))
rollParameters[1] = int(commands[x-1].replace("P","")) elif commands[x][0] == "P":
elif commands[x-1][0] == "D": rollParameters[1] = int(commands[x].replace("P",""))
rollParameters[2] = int(commands[x-1].replace("D","")) elif commands[x][0] == "D":
elif commands[x-1][0] == "C": rollParameters[2] = int(commands[x].replace("D",""))
rollParameters[3] = int(commands[x-1].replace("C","")) elif commands[x][0] == "C":
elif commands[x-1][0] == "B": rollParameters[3] = int(commands[x].replace("C",""))
rollParameters[4] = int(commands[x-1].replace("B","")) elif commands[x][0] == "B":
elif commands[x-1][0] == "S": rollParameters[4] = int(commands[x].replace("B",""))
rollParameters[5] = int(commands[x-1].replace("S","")) elif commands[x][0] == "S":
elif commands[x-1][0] == "F": rollParameters[5] = int(commands[x].replace("S",""))
rollParameters[6] = int(commands[x-1].replace("F","")) elif commands[x][0] == "F":
rollParameters[6] = int(commands[x].replace("F",""))
else: else:
rollParameters[x-1] = int(commands[x-1]) rollParameters[x-1] = int(commands[x-1])
except: except:
@ -196,16 +300,16 @@ def parseRoll(user : str,cmd : str = ""):
return "Invalid input!" return "Invalid input!"
logThis("Rolling "+str(rollParameters)) logThis("Rolling "+str(rollParameters))
rollResults = roll(rollParameters[0],rollParameters[1],rollParameters[2],rollParameters[3],rollParameters[4],rollParameters[5],rollParameters[6]) rollResults, diceResults = roll(rollParameters[0],rollParameters[1],rollParameters[2],rollParameters[3],rollParameters[4],rollParameters[5],rollParameters[6])
simplified = simplify(rollResults) simplified = simplify(rollResults)
name = swchar.getName(user) name = swchar.getName(user)
if simplified != rollResults: logThis("Returns results and simplified results")
logThis("Returns results and simplified results")
return name + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) + "\nSimplified: " + resultToEmoji(simplify(rollResults)) if simplified == "":
return name + " rolls: " + "\n" + diceResultToEmoji(diceResults) + "\nEverything cancels out!"
else: else:
logThis("Returns results") return name + " rolls: " + "\n" + diceResultToEmoji(diceResults) + "\n" + resultToEmoji(simplified)
return name + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults)

View File

@ -1 +1 @@
LLLLl LLLLL