-
Notifications
You must be signed in to change notification settings - Fork 0
/
ability.py
373 lines (329 loc) · 9.68 KB
/
ability.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
manages al things related to abilities
"""
from config import * #@UnusedWildImport
from dice import rnd, rnd2
import re
class Ability(object):
"""
Base class
"""
def __init__(self, value=None):
self._value = None
self.value(value)
def value(self, value=None):
"""
setter & getter
"""
if value:
self._value = value
return self._value
def bonus(self):
"""
to be implemented in sons
"""
raise NameError('This must defined in derived class because depends on ability type.'
)
def b(self, singular_bonus):
"""
facility to quickly access to single bonus item
"""
return self.bonus()[singular_bonus]
class Strength(Ability):
"""
How strong one is
"""
def __init__(self, value=None):
self._hundreds = None
super(Strength, self).__init__(value)
self.data = {
'3': [-3, -1, -35, 1, 0],
'4': [-2, -1, -25, 1, 0],
'5': [-2, -1, -25, 1, 0],
'6': [-1, 0, -15, 1, 0],
'7': [-1, 0, -15, 1, 0],
'8': [0, 0, 0, 2, 1],
'9': [0, 0, 0, 2, 1],
'10': [0, 0, 0, 2, 2],
'11': [0, 0, 0, 2, 2],
'12': [0, 0, 10, 2, 4],
'13': [0, 0, 10, 2, 4],
'14': [0, 0, 20, 2, 7],
'15': [0, 0, 20, 2, 7],
'16': [0, 1, 35, 3, 10],
'17': [1, 1, 50, 3, 13],
'18': [1, 2, 75, 3, 16],
'18.50': [1, 3, 100, 3, 20],
'18.75': [2, 3, 125, 4, 25],
'18.90': [2, 4, 150, 4, 30],
'18.99': [2, 5, 200, 4, 35],
'18.001': [3, 6, 300, 5, 40],
}
def value(self, value=None):
"""
I had to reimplement because of extraordinary attribute management
"""
if value:
x = re.match(r'18/(\d+)', str(value))
self._hundreds = 0
if x:
self._hundreds = int(x.group(1))
self._value = 18
else:
self._value = value
if self._hundreds == 0:
return self._value
else:
return '18/%02d' % self._hundreds
def value_no_hundreds(self):
"""
returns value without extraordinary "part"
"""
return self._value
def bonus(self):
"""
different way to calculate bonus caused by extraordinary "part"
"""
#pdb.set_trace()
y = self.data
if self._hundreds==0:
x = str(self.value())
else:
if self._hundreds == 100:
x = '18.001'
elif self._hundreds < 51:
x = '18.50'
elif self._hundreds < 91:
x = '18.90'
elif self._hundreds <= 99:
x = '18.99'
else:
raise NameError('Strength value %s not valid'
% self.value())
return {
BONUS_TO_HIT: y[x][0],
BONUS_TO_DAMAGE: y[x][1],
ENCUMBRANCE_ADJUSTMENT: y[x][2],
MINOR_TEST: y[x][3],
MAJOR_TEST: y[x][4],
}
class Dexterity(Ability):
"""
how agile he is.
"""
def __init__(self, value=None):
super(Dexterity, self).__init__(value)
self.data = {
'3': [-3, -3, 4],
'4': [-2, -2, 3],
'5': [-1, -1, 2],
'6': [0, 0, 1],
'7': [0, 0, 0],
'8': [0, 0, 0],
'9': [0, 0, 0],
'10': [0, 0, 0],
'11': [0, 0, 0],
'12': [0, 0, 0],
'13': [0, 0, 0],
'14': [0, 0, 0],
'15': [0, 0, -1],
'16': [1, 1, -2],
'17': [2, 2, -3],
'18': [3, 3, -4],
'19': [3, 3, -4],
}
def bonus(self):
x = str(self.value())
y = self.data
return {SURPRISE_BONUS: y[x][0], MISSILE_BONUS_TO_HIT: y[x][1],
AC_ADJUSTMENT: y[x][2]}
class Constitution(Ability):
"""
I drink many beers!
"""
def __init__(self, value=None):
super(Constitution, self).__init__(value)
self.data = {
'3': [-2, 40, 35],
'4': [-1, 45, 40],
'5': [-1, 50, 45],
'6': [-1, 55, 50],
'7': [0, 60, 55],
'8': [0, 65, 60],
'9': [0, 70, 65],
'10': [0, 75, 70],
'11': [0, 80, 75],
'12': [0, 85, 80],
'13': [0, 90, 85],
'14': [0, 92, 88],
'15': [1, 94, 91],
'16': [2, 96, 95],
'17': [2, 98, 97],
'18': [2, 100, 99],
'19': [2, 100, 99],
}
def bonus(self):
x = str(self.value())
y = self.data
return {HIT_POINTS_BONUS: y[x][0], RAISE_DEAD: y[x][1],
SYSTEM_SHOCK: y[x][2]}
class ConstitutionWarrior(Constitution):
"""
Warriors have more hp
"""
def __init__(self, value=None):
Constitution.__init__(self, value)
self.data['17'][0] = 3
self.data['18'][0] = 4
self.data['19'][0] = 5
class Intelligence(Ability):
"""
10^10
"""
def __init__(self, value=None):
super(Intelligence, self).__init__(value)
self.data = {
'3': 0,
'4': 0,
'5': 0,
'6': 0,
'7': 0,
'8': 1,
'9': 1,
'10': 2,
'11': 2,
'12': 3,
'13': 3,
'14': 4,
'15': 4,
'16': 5,
'17': 6,
'18': 7,
'19': 8,
}
def bonus(self):
return {MAXIMUM_ADDITIONAL_LANGUAGES: self.data[str(self.value())]}
class Wisdom(Ability):
"""
Stupid is who behaves like a stupid
"""
def __init__(self, value=None):
super(Wisdom, self).__init__(value)
self.data = {
'3': -3,
'4': -2,
'5': -1,
'6': -1,
'7': -1,
'8': 0,
'9': 0,
'10': 0,
'11': 0,
'12': 0,
'13': 0,
'14': 0,
'15': 1,
'16': 2,
'17': 3,
'18': 4,
'19': 5,
}
def bonus(self):
return {MENTAL_SAVING_THROW_BONUS: self.data[str(self.value())]}
class Charisma(Ability):
"""
Mirror of my kingdom how is [...]
"""
def __init__(self, value=None):
super(Charisma, self).__init__(value)
self.data = {
'3': [1, -30, -25],
'4': [1, -25, -20],
'5': [2, -20, -15],
'6': [2, -15, -10],
'7': [3, -10, -5],
'8': [3, -5, 0],
'9': [4, 0, 0],
'10': [4, 0, 0],
'11': [4, 0, 0],
'12': [5, 0, 0],
'13': [5, 0, 5],
'14': [6, 5, 10],
'15': [7, 15, 15],
'16': [8, 20, 25],
'17': [10, 30, 30],
'18': [15, 40, 35],
'19': [20, 50, 40],
}
def bonus(self):
x = str(self.value())
y = self.data
return {MAXIMUM_HENCHMEN: y[x][0], LOYALTY_BONUS: y[x][1],
REACTION_BONUS: y[x][2]}
class Abilities:
"""
glueing all them together
"""
def __init__(self, **ability):
self._value = {
STRENGTH: Strength(ability[STRENGTH]),
INTELLIGENCE: Intelligence(ability[INTELLIGENCE]),
WISDOM: Wisdom(ability[WISDOM]),
CONSTITUTION: Constitution(ability[CONSTITUTION]),
DEXTERITY: Dexterity(ability[DEXTERITY]),
CHARISMA: Charisma(ability[CHARISMA]),
}
def get(self, ability=None):
if ability:
return self._value[ability]
else:
return self._value
class GenericAbilityGenerator:
"""
calculating with 3d6
"""
@staticmethod
def roll():
return rnd(3, 6)
class BestOfThreeAbilityGenerator:
"""
calculating with best 3d6 on 4d6
"""
@staticmethod
def roll():
return rnd2(4, 1, 6)
class AbilityGeneratorFactory:
"""
TODO manage warrior hp
"""
def create(self, **kwargs):
if kwargs.get('method') == BEST_OF_THREE:
x = Abilities(
strength=self.extraordinary(value=BestOfThreeAbilityGenerator.roll(),
profession=kwargs.get('profession')),
dexterity=BestOfThreeAbilityGenerator.roll(),
constitution=BestOfThreeAbilityGenerator.roll(),
wisdom=BestOfThreeAbilityGenerator.roll(),
intelligence=BestOfThreeAbilityGenerator.roll(),
charisma=BestOfThreeAbilityGenerator.roll(),
)
else:
x = Abilities(
strength=self.extraordinary(value=BestOfThreeAbilityGenerator.roll(),
profession=kwargs.get('profession')),
dexterity=GenericAbilityGenerator.roll(),
constitution=GenericAbilityGenerator.roll(),
wisdom=GenericAbilityGenerator.roll(),
intelligence=GenericAbilityGenerator.roll(),
charisma=GenericAbilityGenerator.roll(),
)
return x
def extraordinary(self, **kw):
"""
for checking extraordinary strength (e.g. if 18 is rolled and it's a warrior class then check for 18/xx stat)
"""
if kw['value'] == 18 and kw.get('profession') == 'fighter':
return '18/%02d' % rnd(1, 100)
return kw['value']