diff --git a/__pycache__/swchar.cpython-36.pyc b/__pycache__/swchar.cpython-36.pyc new file mode 100644 index 0000000..9066cd2 Binary files /dev/null and b/__pycache__/swchar.cpython-36.pyc differ diff --git a/__pycache__/swroll.cpython-36.pyc b/__pycache__/swroll.cpython-36.pyc new file mode 100644 index 0000000..346a5a2 Binary files /dev/null and b/__pycache__/swroll.cpython-36.pyc differ 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