From 4f046d7ab2389190336866f0c5950fbba42dc446 Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Sun, 22 Mar 2020 14:17:42 +0100 Subject: [PATCH] Fun lil' commit --- __pycache__/swchar.cpython-36.pyc | Bin 0 -> 1909 bytes __pycache__/swroll.cpython-36.pyc | Bin 0 -> 4189 bytes characters.json | 3 ++ skills.json | 33 +++++++++++++++ skills.txt | 31 ++++++++++++++ swchar.py | 66 +++++++++++++++++++++++++++--- swroll.py | 22 ++++++++-- testing.py | 4 ++ 8 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 __pycache__/swchar.cpython-36.pyc create mode 100644 __pycache__/swroll.cpython-36.pyc create mode 100644 skills.json create mode 100644 skills.txt create mode 100644 testing.py diff --git a/__pycache__/swchar.cpython-36.pyc b/__pycache__/swchar.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9066cd2172ec365d5eb22b053b1cf67a72730a3e GIT binary patch literal 1909 zcmbtUOK&4Z5boEE$ByF!h~gv!F~DjgUvhwz5UYp)Lyfo9G?NFr%W+GS7MR58ikQpu%wE!tcO>4E0U3TU2OQ9?18QGLs0O)kCm+P+*x z3)t#lTb2#5RU|zot@o~BcXHUGg%}y7yA)OUI5dce>_anqAS^^6*_{2hI-`~jSWf43 z#!exkAIK3oBRR?0(AQ6LmXl2)`6f9A+cEgz6md9R>GmQWb*<87cVN<_pt=x;(S>U9 zLZq2W3gOHmP9xdkn!%X`eOU+@+30toYoOme*?-zOfiO+yus=-WXwW%OW@yu_W4gMZ zS=0G$tP+{VlcZzDc;aq0DJtj6;zCNN$=2caL$1$q@ZR!;XEtti1?dbb4g4_#0i>3c)NYwV{hr#el}LnKgW zCz(Q$yS@xvZ^I-P`ny2*aheWKvJLQ?br6UG{H#G&DT5XOB0kk2cy5`x*y|pK0K6YS zb1b@qfF5KJcNxUtQeu%omJfu>Du62&L;nrc2{H)t$!R_7m0Agk^@qV5qW=cq5Wvh< z9(p1B*dUN%PNfHsdO5Sz+ykw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+4 zz3?=s;x_ul_lTT}qLi?$Vo6&V^Q1~9?huXwd?^$}TGr#!`OYL^|AdII>@Z5W#z?%5 zae;AlUS1SjTZG#qo>9Eix$+Af0lGkTfH-C{x)LG=#1o8bNN%+7-8Lp#zi`66?eq1W z7#$vROFzCF7r*fh94+H?|GaXnPV|@T=#MYi;cGwPCr>WNm+Z4IC$X_Qj&XfKkuz)J z^(mfKL-G6He(G)SP8z9H?3gZgtZrG^J1>#kRbMjk;W?S)R7Sr*2Dbuao}80OO=Z#- z$l&IH%opcmGEaVzD4BXBv)-lRD4W^{6CTIrOU2Tx_!j9Xf&{Vs;ZOz!>76m7_&|+7bBQ^O1#HDLKtU`?>AP*k`2)5PkrSPM06(eaM^-Maf}Dc=jWR zIGD#<15wyzgv1Ok}Y65SHa(KGjOGaog3YGHu z2#qM&DM1vMac@p65KQiH9j!o@f3I=xKxPthcW5UAeK5o>vaLXO2OTb&B-JKDzYR!p zeG%>_r3=6~=%830hFDtGsZEfPIZSPrdjr1j+AFj$kCqZ;BWhlyjkva$TgY9`&E>WK E0*lawrvLx| literal 0 HcmV?d00001 diff --git a/characters.json b/characters.json index cb98515..c6f7c2d 100644 --- a/characters.json +++ b/characters.json @@ -19,6 +19,9 @@ "Cunning": 0, "Willpower": 0, "Presence": 0 + }, + "Skills" : { + } } } \ No newline at end of file diff --git a/skills.json b/skills.json new file mode 100644 index 0000000..5339172 --- /dev/null +++ b/skills.json @@ -0,0 +1,33 @@ +{ + "Astrogation" : "Intellect", + "Computers" : "Intellect", + "Cool" : "Presence", + "Vigilance" : "Willpower", + "Mechanics" : "Intellect", + "Melee" : "Brawn", + "Perception" : "Cunning", + "Piloting - Space" : "Agility", + "Ranged - Heavy" : "Agility", + "Ranged - Light" : "Agility", + "Athletics" : "Brawn", + "Coercion" : "Willpower", + "Coordination" : "Agility", + "Charm" : "Presence", + "Medicine" : "Intellect", + "Negotiation" : "Presence", + "Piloting - Planetary" : "Agility", + "Stealth" : "Agility", + "Skullduggery" : "Cunning", + "Brawl" : "Brawn", + "Discipline" : "Willpower", + "Gunnery" : "Agility", + "Core Worlds" : "Intellect", + "Outer Rim" : "Intellect", + "Underworld" : "Intellect", + "Leadership" : "Presence", + "Lore" : "Intellect", + "Resilience" : "Brawn", + "Streetwise" : "Cunning", + "Survival" : "Cunning", + "Xenology" : "Intellect" +} \ No newline at end of file diff --git a/skills.txt b/skills.txt new file mode 100644 index 0000000..256b59b --- /dev/null +++ b/skills.txt @@ -0,0 +1,31 @@ +Astrogation +Computers +Cool +Vigilance +Mechanics +Melee +Perception +Piloting - Space +Ranged - Heavy +Ranged - Light +Athletics +Coercion +Coordination +Charm +Medicine +Negotiation +Piloting - Planetary +Stealth +Skullduggery +Brawl +Discipline +Gunnery +Core Worlds +Outer Rim +Underworld +Leadership +Lore +Resilience +Streetwise +Survival +Xenology \ No newline at end of file diff --git a/swchar.py b/swchar.py index 0f0ecc3..4b8613e 100644 --- a/swchar.py +++ b/swchar.py @@ -1,18 +1,72 @@ import json +import string + +def getName(user : str): + with open("characters.json", "r") as f: + data = json.load(f) + + if user in data: + return data[user]["Name"] + else: + return user + +def setUpDict(cmd : dict): + keys = list(cmd) + values = list(cmd.values()) + result = "" + for x in range(len(keys)): + if x%3 != 2: + result += keys[x] + ": " + str(values[x]) + "\t" + else: + result += keys[x] + ": " + str(values[x]) + "\n" + return result + +def lookUp(data : dict, key : str, cmd : str = ""): + if key in data: + if cmd == "": + return data[key] + else: + while cmd[0] == ' ': + cmd = cmd[1:] + try: + cmd = type(data[key])(cmd) + data[key] = cmd + return data + except: + return "Wrong data type" def charData(user : str, key : str,cmd : str = ""): with open("characters.json", "r") as f: data = json.load(f) + key = string.capwords(key) + if user in data: if key in data[user]: - if cmd == "": - return data[user][key] + if type(data[user][key]) is dict: + if cmd == "": + return setUpDict(data[user][key]) + else: + newKey = cmd.split(" ")[0] + newcmd = cmd[len(newKey):] + + lookUpResult = lookUp(data[user][key],newKey,newcmd) + + if type(lookUpResult) is dict: + data[user][key] = lookUpResult + with open("characters.json", "w") as f: + json.dump(data,f,indent = 4) + return "Changed " + data[user]["Name"] + "'s " + key + else: + return lookUpResult else: - data[user]["Name"] = cmd - with open("characters.json", "w") as f: - json.dump(data,f,indent = 4) - return "Changed " + user + "'s character's name to " + cmd + if cmd == "": + return data[user][key] + else: + data[user][key] = cmd + with open("characters.json", "w") as f: + json.dump(data,f,indent = 4) + return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd else: return "Couldn't find that data. Are you sure you spelled it correctly?" else: diff --git a/swroll.py b/swroll.py index aa51357..807bcb7 100644 --- a/swroll.py +++ b/swroll.py @@ -1,5 +1,12 @@ import random import re +import string +import json + +from swchar import getName, charData + +with open("skills.json", "r") as f: + skillData = json.load(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 = "" @@ -92,7 +99,10 @@ def diceToEmoji(dice : list): return emoji -def parseRoll(user : str,cmd : str): +def getDice(user : str, skill : str): + return "yes" + +def parseRoll(user : str,cmd : str = ""): cmd = re.sub(' +',' ',cmd.upper()) + " " if cmd[0] == " ": cmd = cmd[1:] @@ -102,6 +112,10 @@ def parseRoll(user : str,cmd : str): else: rollParameters = [0,0,0,0,0,0,0] + if string.capwords(cmd[0]) in skillData: + skillLevel = charData(user,"Skills " + string.capwords(cmd[0])) + charLevel = charData(user,"Characteristics " + string.capwords(skillData[cmd[0]])) + try: for x in range(len(commands)): if commands[x-1] != "": @@ -127,9 +141,11 @@ def parseRoll(user : str,cmd : str): rollResults = roll(rollParameters[0],rollParameters[1],rollParameters[2],rollParameters[3],rollParameters[4],rollParameters[5],rollParameters[6]) simplified = simplify(rollResults) + + name = getName(user) if simplified != rollResults: - return user + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) + "\nSimplified: " + resultToEmoji(simplify(rollResults)) + return name + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) + "\nSimplified: " + resultToEmoji(simplify(rollResults)) else: - return user + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) + return name + " rolls " + diceToEmoji(rollParameters) + "\nResult: " + resultToEmoji(rollResults) diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..1396edf --- /dev/null +++ b/testing.py @@ -0,0 +1,4 @@ +from swchar import charData +from swroll import parseRoll + +print(charData("Template","Name","Jo Jo")) \ No newline at end of file