-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
executable file
·148 lines (123 loc) · 4.24 KB
/
gen.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/python3
import random, subprocess
def vypocitejPostihy(char, hlavniStaty):
switcher = {1: -5, 2: -4, 3: -4, 4: -3, 5: -3, 6: -2, 7: -2, 8: -1, 9: -1,
10: 0, 11: 0, 12: 0, 13: 1, 14: 1, 15: 2, 16: 2, 17: 3, 18: 3,
19: 4, 20: 4, 21: 5}
vypocitejHp(char, switcher)
postihleStaty = ["sila","obratnost","odolnost","inteligence","charisma"]
for i in postihleStaty:
if switcher[char[i]] < 0:
print(f"Postih {i}: {char[i]} {switcher[char[i]]}")
char[i] = str(char[i]) + f" {str(switcher[char[i]])}"
else:
print(f"Postih {i}: {char[i]} +{switcher[char[i]]}")
char[i] = str(char[i]) + f" +{str(switcher[char[i]])}"
def vypocitejHp(char, sw):
char["hp"] = int(char["hp"]) + int(sw[char["odolnost"]])
def vyberMenu(name, menuArr):
print(f"{name}:")
valid = False
while not valid:
for i in range(len(menuArr)):
print(f"{i+1} {menuArr[i].split(';')[0]}")
try:
volba = int(input("Volím: "))
valid = True
except Exception as e:
print(e)
return menuArr[volba-1]
def najdiOpravu(soubor, char):
opravy = {}
objekty = []
with open(soubor, "r") as f:
data = f.readlines()
keys = data[0].replace("#","").strip().split(";")
for i in data:
if i[0]!="#" and i!="":
objekty.append(i.strip())
for i in objekty:
if i.split(";")[0].lower() == char["rasa"]:
objekt = i.split(";")
for i, j in zip(keys, objekt):
opravy[i] = j
return opravy
def vyberZeSouboru(soubor):
char = {}
objekty = []
with open(soubor, "r") as f:
data = f.readlines()
keys = data[0].replace("#","").strip().split(";")
for i in data:
if i[0]!="#" and i!="":
objekty.append(i.strip())
objekt = vyberMenu(keys[0],objekty)
objekt = objekt.split(";")
for i, j in zip(keys, objekt):
char[i] = j
return char
def nahradNedostatky(char, rasa):
nahraditelne = ["sila","obratnost","odolnost","inteligence","charisma"]
hlavniStaty = []
for i in nahraditelne:
if char[i] == "x":
char[i] = rasa[i]
else:
hlavniStaty.append(i)
for i in rasa:
if i not in nahraditelne:
char[i] = rasa[i]
return hlavniStaty
def vypisCharakteru(char):
print(f"""Jméno: {char["jmeno"]}
Povolání: {char["povolani"]}
Rasa: {char["rasa"]}
Třída Velikosti: {char["tridavel"]}
Životy: {char["hp"]}
Síla: {char["sila"]}
Inteligence: {char["inteligence"]}
Odolnost: {char["odolnost"]}
Obratnost: {char["obratnost"]}
Charisma: {char["charisma"]}""")
def vygenerujStaty(char, hlavniStaty):
switcher = {5: 1, 10: 2, 15: 3}
staty = ["sila","obratnost","odolnost","inteligence","charisma"]
opravy = najdiOpravu("tabOprav", char)
for i in staty:
meze = char[i].split("-")
pocetHodu = int(meze[1]) - int(meze[0])
pocetHodu = switcher[pocetHodu]
bonus = int(meze[0]) - pocetHodu
hod = 0
for j in range(pocetHodu):
hod += random.randint(1,6)
print(f"Hodil si {hod} pro {i}")
char[i] = hod + bonus
if i in hlavniStaty:
print(f"Rasová oprava pro {i}: {char[i]} + {opravy[i]}")
char[i] = char[i] + int(opravy[i])
if char[i] < 1:
char[i] = 1
def generateLows(char):
staty = ["sila","obratnost","odolnost","inteligence","charisma"]
minima = {}
for i in staty:
minima[i] = int(char[i].split("-")[0])
return minima
def checkForLows(char, minima):
staty = ["sila","obratnost","odolnost","inteligence","charisma"]
for i in staty:
if char[i] < minima[i]:
char[i] = minima[i]
if __name__ == "__main__":
char = vyberZeSouboru("povolani")
rasa = vyberZeSouboru("rasy")
hlavniStaty = nahradNedostatky(char, rasa)
minima = generateLows(char)
with open("jmena", "r") as f:
char["jmeno"] = random.choice(f.readlines()).strip()
vygenerujStaty(char, hlavniStaty)
checkForLows(char, minima)
vypocitejPostihy(char, hlavniStaty)
print("===\nVypočtené staty\n===")
vypisCharakteru(char)