-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_race.py
113 lines (98 loc) · 4.04 KB
/
set_race.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import utils
import requests
import create_char_shared as shared
abilitiyScores = ("strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma")
alignments = ("Lawful Good", "Neutral Good", "Chaotic Good", "Lawful Neutral", "Neutral", "Chaotic neutral", "Lawful Evil", "Neutral Evil", "Chaotic Evil")
def race(character):
print("race")
char = character
char["state"] = "race"
races = []
r = requests.get("http://dnd5eapi.co/api/races")
rjson = r.json()
for item in rjson["results"]:
races.append(item["name"])
race, index = utils.choiceMenu(races, "CHOOSE YOUR RACE")
print(race)
if race in races:
char["race"] = race
char["raceindex"] = index
return char, race
else:
return char, race
def setRaceManual(character):
print("setRaceManual")
char = character
char["state"] = "setRaceManual"
url = "http://dnd5eapi.co/api/races/" + str(char["raceindex"])
r = requests.get(url)
rjson = r.json()
if str(rjson["name"]) != str(char["race"]):
print("Api race {} does not match choosen race {}. Saving and quitting").format(str(rjson["name"]), str(char["race"]) )
return char, False
else:
value = ""
char["manualState"] = "begin"
lastState = ""
try:
while value != "saveandquit" and value != "quit" and value != True:
print("NOTHER STEP")
if char["manualState"] == "begin":
char["age"], value = utils.enterText("ENTER YOUR AGE")
lastState = "begin"
char["manualState"] = "language"
elif char["manualState"] == "language":
if "language_options" in rjson.keys():
char, value = shared.chooseLanguages(char, rjson)
lastState = "language"
char["manualState"] = "alignment"
elif char["manualState"] == "alignment":
char["alignment"], value = utils.choiceMenu(alignments, "ENTER YOUR ALIGNMENT")
lastState = "alignment"
char["manualState"] = "proficiency"
elif char["manualState"] == "proficiency":
if "starting_proficiency_options" in rjson.keys():
char, value = shared.chooseProficiencies(char, rjson)
lastState = "proficiency"
char["manualState"] = "finish"
elif char["manualState"] == "finish":
print("we did it!")
lastState = "finish"
value = True
print("out of loop")
char["manualState"] = lastState
return char, value
except Exception as e:
print(e)
char["manualState"] = lastState
def setRaceAuto(character):
print("setRaceAuto")
char = character
char["state"] = "setRaceAuto"
print("YOU CHOOSE: " + str(char["race"]).upper())
url = "http://dnd5eapi.co/api/races/" + str(char["raceindex"])
r = requests.get(url)
rjson = r.json()
if str(rjson["name"]) != str(char["race"]):
print("Api race {} does not match choosen race {}. Saving and quitting").format(str(rjson["name"]), str(char["race"]) )
return char, False
else:
char["abilities"] = []
for i in range (0, len(abilitiyScores)):
ability = {}
ability["name"] = abilitiyScores[i]
ability["score"] = rjson["ability_bonuses"][i]
char["abilities"].append(ability)
char["size"] = str(rjson["size"])
char["speed"] = str(rjson["speed"])
char["proficiencies"] = []
for p in rjson["starting_proficiencies"]:
char["proficiencies"].append(str(p["name"]))
char["languages"] = []
for p in rjson["languages"]:
char["languages"].append(str(p["name"]))
char["traits"] = []
for p in rjson["traits"]:
char["traits"].append(str(p["name"]))
print(char)
return char, True