-
Notifications
You must be signed in to change notification settings - Fork 4
/
character.py
328 lines (270 loc) · 10.2 KB
/
character.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import csv
import json
import operator
import random
import sys
import time
"""
GURPS is a trademark of Steve Jackson Games, and its rules and art are copyrighted
by Steve Jackson Games. All rights are reserved by Steve Jackson Games. This game aid is
the original creation of John Murray and is released for free distribution, and not for
resale, under the permissions granted in the
<a href="http://www.sjgames.com/general/online_policy.html">Steve Jackson Games Online
Policy</a>.
"""
class Skill():
def __init__(self, name, atributeStr, atributeVal, difficulty=0, points=1):
"""
Default to 0 (easy) and 1 point spent
"""
# Error checking
assert(type(atributeStr) == type(str()))
assert(type(atributeVal) == type(int()))
assert(type(points) == type(int()))
assert(points>0)
self.Name=name
self.AtributeString = atributeStr
self.AtributeValue = atributeVal
if(type(difficulty) == type(int())):
self.Difficulty = difficulty
else:
if(difficulty=="E"):
self.Difficulty=0
elif(difficulty=="A"):
self.Difficulty=1
elif(difficulty=="H"):
self.Difficulty=2
elif(difficulty=="VH"):
self.Difficulty=3
self.Points = points
self.CalcSkillMod()
def CalcSkillMod(self):
assert(self.Points > 0)
if(self.Points < 4):
self.SkillMod = int(self.Points / 2)
else:
self.SkillMod = int(self.Points/4) + 1
if( self.Difficulty == 0 ):
pass
elif( self.Difficulty == 1 ):
self.SkillMod -= 1
elif( self.Difficulty == 2 ):
self.SkillMod -= 2
elif( self.Difficulty == 3 ):
self.SkillMod -= 3
else:
print "INVALID DIFFiCULTY!"
assert(False)
def SetAtrib(self, atributeStr, atributeVal):
self.AtributeString = atributeStr
self.AtributeValue = atributeVal
def ModPoints(self, deltaPoints):
self.Points += deltaPoints
self.CalcSkillMod()
def SetPoints(self, newPoints):
self.Points = newPoints
self.CalcSkillMod()
def Check(self, mods=0):
dieRoll = list()
for i in range(3):
dieRoll.append(random.randint(1,6))
return (self.SkillMod + self.AtributeValue) - sum(dieRoll) + mods
def Print(self):
print "%s-%d (%+d)" %(self.Name, self.SkillMod + self.AtributeValue, self.SkillMod)
def GetPrint(self):
return "%s-%d (%+d)" %(self.Name, self.SkillMod + self.AtributeValue, self.SkillMod)
class CharSheet():
def __init__(self,default=10):
self.name = "DEFAULT"
self.ST = default
self.DX = default
self.IQ = default
self.HT = default
self.HP = self.ST
self.WILL = self.IQ
self.PER = self.IQ
self.FP = self.HT
self.Skills = dict()
self.Height=0
self.Weight=0
self.Points=0+(default-10)*(10+20+20+10)
def Roll(self,template,statPoints=0,skillPoints=0):
self.Height = random.gauss(1.778,0.15)
self.GenerateName()
with open(template,'rb') as f:
settingsData=json.load(f)
dataAttributes = settingsData['Attributes']
dataSkills = settingsData['Skills']
runningTotalAttributes = 0
for i in dataAttributes:
oldData = dataAttributes[i]["weight"]
dataAttributes[i]["weight"] = dataAttributes[i]["weight"] + runningTotalAttributes
runningTotalAttributes += oldData
runningTotalSkills = 0
for i in dataSkills:
oldData = dataSkills[i]["weight"]
dataSkills[i]["weight"] = dataSkills[i]["weight"] + runningTotalSkills
runningTotalSkills += oldData
startPoints = (self.ST - 10)*10
startPoints += (self.DX - 10)*20
startPoints += (self.IQ - 10)*20
startPoints += (self.HT - 10)*10
startPoints += (self.HP - self.ST)*2
startPoints += (self.WILL - self.IQ)*5
startPoints += (self.PER - self.IQ)*5
startPoints += (self.FP - self.HT)*3
while(startPoints < statPoints):
# Spend points on stuff!
# Select a weighted
selection = random.randint(0,runningTotalAttributes)
for i in dataAttributes:
if(selection <= dataAttributes[i]["weight"]):
selection = i
break
if(selection == "ST"):
self.ST+=1
self.HP+=1
self.Points+=10
statPoints -=10
elif(selection == "DX"):
self.DX+=1
self.Points+=20
statPoints -=20
elif(selection == "IQ"):
self.IQ+=1
self.WILL+=1
self.PER+=1
self.Points+=20
statPoints -=20
elif(selection == "HT"):
self.HT+=1
self.FP+=1
self.Points+=10
statPoints -=10
elif(selection == "HP" and self.HP+1 <= self.ST*1.3):
# Limited to +/- 30% of ST
self.HP+=1
self.Points+=2
statPoints -=2
elif(selection == "WILL" and self.WILL <=20):
self.WILL+=1
self.Points+=5
statPoints -=5
elif(selection == "PER" and self.PER <= 20):
self.PER+=1
self.Points+=5
statPoints -=5
elif(selection == "FP" and self.FP+1 <= self.HT*1.3):
self.FP+=1
self.Points+=3
statPoints -=3
startPoints = 0
while(startPoints < skillPoints):
selection = random.randint(0,runningTotalSkills)
for i in dataSkills:
if(selection <= dataSkills[i]["weight"]):
selection = i
break
# Update skill or add a new one
if(selection in self.Skills):
self.Skills[selection].ModPoints(1)
else:
#__init__(self, name, atributeStr, atributeVal, difficulty=0, points=1):
self.Skills[selection]=Skill( i,
str(dataSkills[i]["attribute"]),
getattr(self,dataSkills[i]["attribute"]),
dataSkills[i]["diff"]
)
self.Points+=1
skillPoints -=1
# Update Skills
for i in self.Skills:
tempAttribute = self.Skills[i].AtributeString
self.Skills[i].SetAtrib(tempAttribute,getattr(self,tempAttribute))
def __str__(self):
return self.name
def Print(self):
print "Name:",self.name
print " ST: %3d" % (self.ST)
print " DX: %3d" % (self.DX)
print " IQ: %3d" % (self.IQ)
print " HT: %3d" % (self.HT)
print " HP: %3d" % (self.HP)
print " WILL: %3d" % (self.WILL)
print " PER: %3d" % (self.PER)
print " FP: %3d" % (self.FP)
print " Points: %3d" % (self.Points)
print " Skills:"
sortedSkills = sorted(self.Skills.iteritems(), key=operator.itemgetter(0))
for i in sortedSkills:
print " ",i[1].GetPrint()
def PrintWiki(self):
print "!!!",self.name
wikiName = self.name.replace(' ',"_").replace(',','')
print "((Colony:NPC:Farmer:%s|SubPage))"%(wikiName)
print "||ST| %3d" % (self.ST)
print "DX| %3d" % (self.DX)
print "IQ| %3d" % (self.IQ)
print "HT| %3d" % (self.HT)
print "HP| %3d" % (self.HP)
print "WILL| %3d" % (self.WILL)
print "PER| %3d" % (self.PER)
print "FP| %3d" % (self.FP)
print "Points| %3d||" % (self.Points)
print "*Skills:"
sortedSkills = sorted(self.Skills.iteritems(), key=operator.itemgetter(0))
for i in sortedSkills:
print "**",i[1].GetPrint()
def GenerateName(self,gender="male"):
self.name = self.ParseNameFile('data/lastnames.csv') + ", " + self.ParseNameFile('data/firstnames.csv',gender)
def ParseNameFile(self,namesFile,gender="male"):
with open(namesFile,'r') as namesFile:
nameReader = csv.reader(namesFile)
firstNamesMale = list()
firstNamesFemale = list()
# Skip the header
nameReader.next()
for i in nameReader:
firstNamesMale.append(i[1:3])
if(gender=="female"):
firstNamesFemale.append(i[3:5])
# Convert counts to ints
if(gender=="male"):
for i in firstNamesMale:
i[1]=int(i[1])
elif(gender=="female"):
for i in firstNamesFemale:
i[1]=int(i[1])
# Prep ints for random selection
if(gender=="male"):
runningTotalMale=0
for i in firstNamesMale:
oldData = i[1]
i[1]=i[1]+runningTotalMale
runningTotalMale+=oldData
if(gender=="female"):
runningTotalFemale=0
for i in firstNamesFemale:
oldData = i[1]
i[1]=i[1]+runningTotalFemale
runningTotalFemale+=oldData
# Randomly select one of the weight targets
if(gender=="male"):
selecton = random.randint(0,runningTotalMale)
for i in firstNamesMale:
if selecton <= i[1]:
return i[0].title()
elif(gender=="female"):
selecton = random.randint(0,runningTotalFemale)
for i in firstNamesFemale:
if selecton <= i[1]:
return i[0].title()
x = list()
for i in range(10):
x.append(CharSheet(5))
x[i].Roll('data/workerTemplate.json',50,100)
x = sorted(x, key=operator.attrgetter('name'))
for i in x:
i.PrintWiki()
# i.Print()
print