From 87cebc6ab74e7a19f568e864ec9642e1ce7840de Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Thu, 2 Apr 2020 16:47:41 +0200 Subject: [PATCH] dice in swroll --- Gwendolyn.py | 10 ++- funcs/swfuncs/swdestiny.py | 7 +- funcs/swfuncs/swroll.py | 166 +++++++++++++++++++++++++++++------- resources/destinyPoints.txt | 2 +- 4 files changed, 149 insertions(+), 36 deletions(-) diff --git a/Gwendolyn.py b/Gwendolyn.py index 1b3acfb..88d3e62 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -164,13 +164,19 @@ async def on_message(message): elif message.content.lower().startswith("!swroll"): funcs.logThis(message.author.name+" ran \""+message.content+"\"") 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 elif message.content.lower().startswith("!swd"): funcs.logThis(message.author.name+" ran \""+message.content+"\"") 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 # from funcs/swfuncs/swchar.py diff --git a/funcs/swfuncs/swdestiny.py b/funcs/swfuncs/swdestiny.py index d68e6d3..5d8b1ed 100644 --- a/funcs/swfuncs/swdestiny.py +++ b/funcs/swfuncs/swdestiny.py @@ -4,12 +4,13 @@ from funcs import logThis def destinyNew(num : int): 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: 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): 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") if 'B' in points: points = points.replace("B","L",1) + points = "".join(sorted(points)) with open("resources/destinyPoints.txt","wt") as f: f.write(points) logThis("Did it") @@ -30,6 +32,7 @@ def destinyUse(user : str): logThis("Trying to use a light side destiny point") if 'L' in points: points = points.replace("L","B",1) + points = "".join(sorted(points)) with open("resources/destinyPoints.txt","wt") as f: f.write(points) logThis("Did it") diff --git a/funcs/swfuncs/swroll.py b/funcs/swfuncs/swroll.py index c627b28..6647e0c 100644 --- a/funcs/swfuncs/swroll.py +++ b/funcs/swfuncs/swroll.py @@ -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): result = "" + diceResult = [] 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): - 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): - 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): - 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): - 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): - 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): - 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): logThis("Simplifying "+result) @@ -60,6 +75,94 @@ def simplify(result : str): 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): emoji = "" for char in result: @@ -173,22 +276,23 @@ def parseRoll(user : str,cmd : str = ""): try: logThis("Converting commands to dice") - for x in range(len(commands)): - if commands[x-1] != "": - if commands[x-1][0] == "A": - rollParameters[0] = int(commands[x-1].replace("A","")) - elif commands[x-1][0] == "P": - rollParameters[1] = int(commands[x-1].replace("P","")) - elif commands[x-1][0] == "D": - rollParameters[2] = int(commands[x-1].replace("D","")) - elif commands[x-1][0] == "C": - rollParameters[3] = int(commands[x-1].replace("C","")) - elif commands[x-1][0] == "B": - rollParameters[4] = int(commands[x-1].replace("B","")) - elif commands[x-1][0] == "S": - rollParameters[5] = int(commands[x-1].replace("S","")) - elif commands[x-1][0] == "F": - rollParameters[6] = int(commands[x-1].replace("F","")) + for x in range(len(commands)-1): + if commands[x] != "": + commands[x] = commands[x].upper() + if commands[x][0] == "A": + rollParameters[0] = int(commands[x].replace("A","")) + elif commands[x][0] == "P": + rollParameters[1] = int(commands[x].replace("P","")) + elif commands[x][0] == "D": + rollParameters[2] = int(commands[x].replace("D","")) + elif commands[x][0] == "C": + rollParameters[3] = int(commands[x].replace("C","")) + elif commands[x][0] == "B": + rollParameters[4] = int(commands[x].replace("B","")) + elif commands[x][0] == "S": + rollParameters[5] = int(commands[x].replace("S","")) + elif commands[x][0] == "F": + rollParameters[6] = int(commands[x].replace("F","")) else: rollParameters[x-1] = int(commands[x-1]) except: @@ -196,16 +300,16 @@ def parseRoll(user : str,cmd : str = ""): return "Invalid input!" 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) name = swchar.getName(user) - if simplified != rollResults: - logThis("Returns results and simplified results") - return name + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) + "\nSimplified: " + resultToEmoji(simplify(rollResults)) + logThis("Returns results and simplified results") + + if simplified == "": + return name + " rolls: " + "\n" + diceResultToEmoji(diceResults) + "\nEverything cancels out!" else: - logThis("Returns results") - return name + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) - + return name + " rolls: " + "\n" + diceResultToEmoji(diceResults) + "\n" + resultToEmoji(simplified) + diff --git a/resources/destinyPoints.txt b/resources/destinyPoints.txt index fb92b78..731f7d2 100644 --- a/resources/destinyPoints.txt +++ b/resources/destinyPoints.txt @@ -1 +1 @@ -LLLLl \ No newline at end of file +LLLLL \ No newline at end of file