-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobemaker.py
592 lines (521 loc) · 27.7 KB
/
probemaker.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#!', 'usr', 'bin', 'env python
# -*- coding: utf-8 -*-
import os
import json
import logging
from random import randint
import warnings
from typing import List
from difflib import get_close_matches
if "settings.py" in os.listdir():
from settings import *
else:
# fallback if no custom settings are provided
from settings_template import *
if debug:
print(os.listdir())
print(os.getcwd())
class Hero:
""" Class to create an Hero object from heros .json file
file -- .json file name from Optolith containing hero's data_folder
show_values -- If set, show all character values when load hero
"""
def __init__(self, file, logger, show_values=False):
""" Initialize Hero class() by loading and processing .json file
"""
# Prepare and load hero's .json file
f = open(file)
h_data = json.load(f)
self.name = h_data['name']
self.logger = logger
self.rolls = 'nothing'
print('=======================')
print('The great hero called ' + self.name + ' is being summoned into the working memory.')
print('=======================')
# Basic attributes
attr = h_data['attr']['values'] # Get data from .json file
attr_dict = {}
for a in attr:
attr_dict[a['id']] = a['value']
self.attr = dict() # Dict to collect all attributs
self.attr['MU'] = attr_dict['ATTR_1'] if 'ATTR_1' in attr_dict else 8
self.attr['KL'] = attr_dict['ATTR_2'] if 'ATTR_2' in attr_dict else 8
self.attr['IN'] = attr_dict['ATTR_3'] if 'ATTR_3' in attr_dict else 8
self.attr['CH'] = attr_dict['ATTR_4'] if 'ATTR_4' in attr_dict else 8
self.attr['FF'] = attr_dict['ATTR_5'] if 'ATTR_5' in attr_dict else 8
self.attr['GE'] = attr_dict['ATTR_6'] if 'ATTR_6' in attr_dict else 8
self.attr['KO'] = attr_dict['ATTR_7'] if 'ATTR_7' in attr_dict else 8
self.attr['KK'] = attr_dict['ATTR_8'] if 'ATTR_8' in attr_dict else 8
# Print attributes
print('These are ' + self.name + "'s basic atrributes:")
print('=======================')
for att in self.attr:
print(att + ': ' + str(self.attr[att]))
print('=======================')
# Get AP
self.ap = h_data['ap']
# Get race and compute max LP
self.LP_max = 2 * self.attr['KO']
self.race = h_data['r']
if self.race == 'R_1':
self.race = 'Human'
self.LP_max = self.LP_max + 5
elif self.race == 'R_2':
self.race = 'Halfelf'
self.LP_max = self.LP_max + 5
elif self.race == 'R_3':
self.race = 'Elf'
self.LP_max = self.LP_max + 2
elif self.race == 'R_4':
self.race = 'Dwarf'
self.LP_max = self.LP_max + 8
print(f'{self.name} is a cute {self.race}!')
# Set current LP
self.LP = self.LP_max
# Get Leiteigenschaft of character
LEG = h_data['attr']['attributeAdjustmentSelected']
attr_dict = {'ATTR_1': 'MU', 'ATTR_2': 'KL', 'ATTR_3': 'IN', 'ATTR_4': 'CH', 'ATTR_5': 'FF',
'ATTR_6': 'GE', 'ATTR_7': 'KO', 'ATTR_8': 'KK'}
self.leiteigenschaft = [attr_dict[LEG], self.attr[attr_dict[LEG]]]
print(f'{self.name}`s leiteigenschaft is {self.leiteigenschaft[0]}.')
print(f'{self.name} has {self.LP} of {self.LP_max} LP')
# Wundschwellen (Levels for infliction of pain)
self.wundschwelle = (self.LP_max/4)
self.wundschwelle = [self.wundschwelle*3, self.wundschwelle*2, self.wundschwelle]
self.wounds = 0
self.dead = False
print(f'{self.name}`s Wundschwellen: {self.wundschwelle}')
# Talents dict
talents = h_data['talents'] # Select data from .json file
self.skills = dict() # Dict to collect all talents
self.skills['Fliegen'] = ['MU', 'IN', 'GE', talents['TAL_1'] if 'TAL_1' in talents else 0, 'talent']
self.skills['Gaukeleien'] = ['MU', 'CH', 'FF', talents['TAL_2'] if 'TAL_2' in talents else 0, 'talent']
self.skills['Klettern'] = ['MU', 'GE', 'KK', talents['TAL_3'] if 'TAL_3' in talents else 0, 'talent']
self.skills['Koerperbeherrschung'] = ['GE', 'GE', 'KO', talents['TAL_4'] if 'TAL_4' in talents else 0, 'talent']
self.skills['Kraftakt'] = ['KO', 'KK', 'KK', talents['TAL_5'] if 'TAL_5' in talents else 0, 'talent']
self.skills['Reiten'] = ['CH', 'GE', 'KK', talents['TAL_6'] if 'TAL_6' in talents else 0, 'talent']
self.skills['Schwimmen'] = ['GE', 'KO', 'KK', talents['TAL_7'] if 'TAL_7' in talents else 0, 'talent']
self.skills['Selbstbeherrschung'] = ['MU', 'MU', 'KO', talents['TAL_8'] if 'TAL_8' in talents else 0, 'talent']
self.skills['Singen'] = ['KL', 'CH', 'KO', talents['TAL_9'] if 'TAL_9' in talents else 0, 'talent']
self.skills['Sinnesschaerfe'] = ['KL', 'IN', 'IN', talents['TAL_10'] if 'TAL_10' in talents else 0, 'talent']
self.skills['Tanzen'] = ['KL', 'CH', 'GE', talents['TAL_11'] if 'TAL_11' in talents else 0, 'talent']
self.skills['Taschendiebstahl'] = ['MU', 'FF', 'GE', talents['TAL_12'] if 'TAL_12' in talents else 0, 'talent']
self.skills['Verbergen'] = ['MU', 'IN', 'GE', talents['TAL_13'] if 'TAL_13' in talents else 0, 'talent']
self.skills['Zechen'] = ['KL', 'KO', 'KK', talents['TAL_14'] if 'TAL_14' in talents else 0, 'talent']
self.skills['Bekehren u Ueberzeugen'] = ['MU', 'KL', 'CH', talents['TAL_15'] if 'TAL_15' in talents else 0, 'talent']
self.skills['Betoeren'] = ['MU', 'CH', 'CH', talents['TAL_16'] if 'TAL_16' in talents else 0, 'talent']
self.skills['Einschuechtern'] = ['MU', 'IN', 'CH', talents['TAL_17'] if 'TAL_17' in talents else 0, 'talent']
self.skills['Etikette'] = ['KL', 'IN', 'CH', talents['TAL_18'] if 'TAL_18' in talents else 0, 'talent']
self.skills['Gassenwissen'] = ['KL', 'IN', 'CH', talents['TAL_19'] if 'TAL_19' in talents else 0, 'talent']
self.skills['Menschenkenntnis'] = ['KL', 'IN', 'CH', talents['TAL_20'] if 'TAL_20' in talents else 0, 'talent']
self.skills['Ueberreden'] = ['MU', 'IN', 'CH', talents['TAL_21'] if 'TAL_21' in talents else 0, 'talent']
self.skills['Verkleiden'] = ['IN', 'CH', 'GE', talents['TAL_22'] if 'TAL_22' in talents else 0, 'talent']
self.skills['Willenskraft'] = ['MU', 'IN', 'CH', talents['TAL_23'] if 'TAL_23' in talents else 0, 'talent']
self.skills['Faehrtensuchen'] = ['MU', 'IN', 'GE', talents['TAL_24'] if 'TAL_24' in talents else 0, 'talent']
self.skills['Fesseln'] = ['KL', 'FF', 'KK', talents['TAL_25'] if 'TAL_25' in talents else 0, 'talent']
self.skills['Fischen u Angeln'] = ['FF', 'GE', 'KO', talents['TAL_26'] if 'TAL_26' in talents else 0, 'talent']
self.skills['Orientierung'] = ['KL', 'IN', 'IN', talents['TAL_27'] if 'TAL_27' in talents else 0, 'talent']
self.skills['Pflanzenkunde'] = ['KL', 'FF', 'KO', talents['TAL_28'] if 'TAL_28' in talents else 0, 'talent']
self.skills['Tierkunde'] = ['MU', 'MU', 'CH', talents['TAL_29'] if 'TAL_29' in talents else 0, 'talent']
self.skills['Wildnisleben'] = ['MU', 'GE', 'KO', talents['TAL_30'] if 'TAL_30' in talents else 0, 'talent']
self.skills['Brett- u Gluecksspiel'] = ['KL', 'KL', 'IN', talents['TAL_31'] if 'TAL_31' in talents else 0, 'talent']
self.skills['Geographie'] = ['KL', 'KL', 'IN', talents['TAL_32'] if 'TAL_32' in talents else 0, 'talent']
self.skills['Geschichtswissen'] = ['KL', 'KL', 'IN', talents['TAL_33'] if 'TAL_33' in talents else 0, 'talent']
self.skills['Goetter u Kulte'] = ['KL', 'KL', 'IN', talents['TAL_34'] if 'TAL_34' in talents else 0, 'talent']
self.skills['Kriegskunst'] = ['MU', 'KL', 'IN', talents['TAL_35'] if 'TAL_35' in talents else 0, 'talent']
self.skills['Magiekunde'] = ['KL', 'KL', 'IN', talents['TAL_36'] if 'TAL_36' in talents else 0, 'talent']
self.skills['Mechanik'] = ['KL', 'KL', 'FF', talents['TAL_37'] if 'TAL_37' in talents else 0, 'talent']
self.skills['Rechnen'] = ['KL', 'KL', 'IN', talents['TAL_38'] if 'TAL_38' in talents else 0, 'talent']
self.skills['Rechtskunde'] = ['KL', 'KL', 'IN', talents['TAL_39'] if 'TAL_39' in talents else 0, 'talent']
self.skills['Sagen u Legenden'] = ['KL', 'KL', 'IN', talents['TAL_40'] if 'TAL_40' in talents else 0, 'talent']
self.skills['Sphaerenkunde'] = ['KL', 'KL', 'IN', talents['TAL_41'] if 'TAL_41' in talents else 0, 'talent']
self.skills['Sternkunde'] = ['KL', 'KL', 'IN', talents['TAL_42'] if 'TAL_42' in talents else 0, 'talent']
self.skills['Alchimie'] = ['MU', 'KL', 'FF', talents['TAL_43'] if 'TAL_43' in talents else 0, 'talent']
self.skills['Boote u Schiffe'] = ['FF', 'GE', 'KK', talents['TAL_44'] if 'TAL_44' in talents else 0, 'talent']
self.skills['Fahrzeuge'] = ['CH', 'FF', 'KO', talents['TAL_45'] if 'TAL_45' in talents else 0, 'talent']
self.skills['Handel'] = ['KL', 'IN', 'CH', talents['TAL_46'] if 'TAL_46' in talents else 0, 'talent']
self.skills['Heilkunde Gift'] = ['MU', 'KL', 'IN', talents['TAL_47'] if 'TAL_47' in talents else 0, 'talent']
self.skills['Heilkunde Krankheiten'] = [' MU', 'IN', 'KO', talents['TAL_48'] if 'TAL_48' in talents else 0, 'talent']
self.skills['Heilkunde Seele'] = ['IN', 'CH', 'KO', talents['TAL_49'] if 'TAL_49' in talents else 0, 'talent']
self.skills['Heilkunde Wunden'] = ['KL', 'FF', 'FF', talents['TAL_50'] if 'TAL_50' in talents else 0, 'talent']
self.skills['Holzbearbeitung'] = ['FF', 'GE', 'KK', talents['TAL_51'] if 'TAL_51' in talents else 0, 'talent']
self.skills['Lebensmittelbearbeitung'] = ['IN', 'FF', 'FF', talents['TAL_52'] if 'TAL_52' in talents else 0, 'talent']
self.skills['Lederbearbeitung'] = ['FF', 'GE', 'KO', talents['TAL_53'] if 'TAL_53' in talents else 0, 'talent']
self.skills['Malen u Zeichnen'] = ['IN', 'FF', 'FF', talents['TAL_54'] if 'TAL_54' in talents else 0, 'talent']
self.skills['Metallbearbeitung'] = ['FF', 'KO', 'KK', talents['TAL_55'] if 'TAL_55' in talents else 0, 'talent']
self.skills['Musizieren'] = ['CH', 'FF', 'KO', talents['TAL_56'] if 'TAL_56' in talents else 0, 'talent']
self.skills['Schloesserknacken'] = ['IN', 'FF', 'FF', talents['TAL_57'] if 'TAL_57' in talents else 0, 'talent']
self.skills['Steinbearbeitung'] = ['FF', 'FF', 'KK', talents['TAL_58'] if 'TAL_58' in talents else 0, 'talent']
self.skills['Stoffbearbeitung'] = ['KL', 'FF', 'FF ', talents['TAL_59'] if 'TAL_59' in talents else 0, 'talent']
self.skills['wichsen'] = ['MU', 'IN', 'KK', 5000, 'talent']
# Magic
spells = h_data['spells']
if len(spells) > 0:
self.AE_max = 20 + self.leiteigenschaft[1]
self.AE = self.AE_max
print(f'{self.name} has {self.AE} of {self.AE_max} AE')
if 'SPELL_367' in spells:
self.skills['Schelmenkleister'] = ['KL', 'IN', 'GE', spells['SPELL_367'], 'magic', 8]
#######################
# ADD MORE MAGIC HERE #
#######################
else:
self.AE_max = 0
self.AE = 0
print(f'{self.name} does not know any magic.')
# Liturgies
liturgies = h_data['liturgies']
if len(liturgies) > 0:
print('liturgies not implemented')
###########################
# ADD MORE liturgies HERE #
###########################
else:
print(f'{self.name} does not know any liturgies.')
if show_values:
print('=======================')
print(f"These are {self.name}'s talents:")
print('=======================')
print(self.skills)
print('=======================')
# Create a dict of everything that can be probed on
self.possible_probes = list()
self.possible_probes.append('take_hit')
self.possible_probes.append('give_hit')
self.possible_probes.append('sLP')
self.possible_probes.append('sAE')
self.possible_probes.append('cLP')
self.possible_probes.append('cAE')
# Add Attributes
for key in self.attr.keys():
self.possible_probes.append(key)
# Add Talents
for key in self.skills.keys():
self.possible_probes.append(key)
def perform_action(self, user_action: str, modifier: int = 0) -> bool:
"""
Method called when asked to do something
"""
# Quitting program
if user_action == 'feddich':
print(f'{self.name} has left the building with {self.LP} LP and {self.AE} AE.')
return False
# Perform probe
else:
if user_action in self.skills:
return self.skill_probe(user_action, modifier)
elif user_action in self.attr:
return self.perform_attr_probe(user_action, modifier)
elif user_action == 'take_hit':
self.take_a_hit()
return False, False, False, False, False
elif user_action == 'give_hit':
self.give_a_hit()
return True, False, False, False, False
elif user_action == 'sLP':
self.set_LP(modifier)
return True, False, False, False, False
elif user_action == 'sAE':
self.set_AE(modifier)
return True, False, False, False, False
elif user_action == 'cLP':
self.change_LP(modifier)
return True, False, False, False, False
elif user_action == 'cAE':
self.change_AE(modifier)
return False, False, False, False, False
else:
raise ValueError('Keyword ' + user_action + " not found, enter 'feddich' to quit")
return True
def change_LP(self, value):
"""Change amount of AE by value"""
old = self.LP
self.LP = min(self.LP + value, self.LP_max)
print(f'LP has changed from {old} to {self.LP}')
self.logger.info(f'reg_event;change_LP;{self.name};{old};{self.LP}')
self.check_pain()
def set_LP(self, value):
"""Set LP to value"""
old = self.LP
self.LP = value
print(f'LP set to {self.LP}')
self.logger.info(f'reg_event;set_LP;{self.name};{old};{self.LP}')
self.check_pain()
def set_AE(self, value):
"""Set AE to value"""
old = self.AE
self.AE = value
print(f'AE set to {self.AE}')
self.logger.info(f'reg_event;set_AE;{self.name};{old};{self.AE}')
self.check_pain()
def change_AE(self, value):
"""Change amount of AE by value"""
old = self.AE
self.AE = min(self.AE + value, self.AE_max)
print(f'AE has changed from {old} to {self.AE}')
self.logger.info(f'reg_event;change_AE;{self.name};{old};{self.AE}')
self.check_pain()
def check_pain(self): # Check if wounded( in pain)
if self.LP > self.wundschwelle[0]:
self.wounds = 0
elif self.LP <= self.wundschwelle[0] and self.LP > self.wundschwelle[1]:
self.wounds = 1
elif self.LP <= self.wundschwelle[1] and self.LP > self.wundschwelle[2]:
self.wounds = 2
elif 0 < self.LP <= self.wundschwelle[2]:
self.wounds = 3
elif self.LP <= 0:
print('YOU ARE DEAD')
self.dead = True
self.logger.info(f'{self.name};DEAD')
if self.wounds > 0:
print(f'{self.name}: LEVEL(S) OF PAIN: {self.wounds} (-{self.wounds} AT/PA))')
else:
print(f'{self.name}: HAS NO PAIN')
def perform_attr_probe(self, attr: str, mod: int = 0):
""" Performs an attribute probe with a modifier
"""
print(f"The mighty {self.name} has incredible {self.attr[attr]} points in {attr}," +
f"the modifier for this probe is {mod}")
# Booleans indicating whether something was meisterlich or a patzer
meister = False
mega_meister = False
patz = False
mega_patz = False
roll = randint(1, 20)
self.rolls = roll
res = self.attr[attr] - roll + mod
print(f'The die shows a {roll}')
if res >= 0 and roll != 20: # Passed
print(f"{self.name} has passed")
passed = True
if roll == 1:
print('Will it be meisterlich?')
roll2 = randint(1, 20)
res2 = self.attr[attr] - roll2 + mod
if res >= 0:
print('Yes!')
meister = True
else:
print('No :(')
if roll2 ==1:
mega_meister = True
elif roll != 20: # Failed by no patzer
print(f"{self.name} has failed")
passed = False
elif roll == 20: # Failed an CAN be a patzer
print(f"{self.name} has failed, but will it be a complete disaster?")
passed = False
roll2 = randint(1, 20)
res2 = self.attr[attr] - roll2 + mod
if res <= 0: # Patzer
print("Yes....")
patz = True
else: # Just a normal fail
print("No, thanks to the Twelve")
if roll2 == 20: # Doppel-20 patzer
mega_patz = True
else: # Dedugging...
print('This should never happen :(')
self.logger.info(f'attr_probe;{self.name};{attr};{self.attr[attr]};{mod};{roll};{res};{passed};{meister};{patz}')
return passed, meister, mega_meister, patz , mega_patz
def skill_probe(self, skill: str, mod: int = 0):
"""Method to perform a skill (talent, magic, or liturgy) probe
skill -- name of talent, magic, or liturgie to probe
mod -- modifier on probe
"""
# Booleans indicating whether something was meisterlich or a patzer
patz = False
mega_patz = False
meister = False
mega_meister = False
points_left = self.skills[skill][3] # Get number of skill points
print('=======================')
print(f'The mighty {self.name} has {points_left} skill points when he tries to {skill}.')
if mod != 0:
print(f'Probe modified by {mod}.')
if mod > 0:
str_mod = ' + ' + str(mod)
elif mod < 0:
str_mod = ' - ' + str(abs(mod))
else:
str_mod = ' +- ' + str(mod)
# Roll dice
rolls = [randint(1, 20), randint(1, 20), randint(1, 20)]
self.rolls = rolls
# Print die roll results
print('Die rolls:')
print(self.skills[skill][0] + ': ' + str(rolls[0]) + ' (' + str(self.attr[self.skills[skill][0]]) + str_mod + ')')
print(self.skills[skill][1] + ': ' + str(rolls[1]) + ' (' + str(self.attr[self.skills[skill][1]]) + str_mod + ')')
print(self.skills[skill][2] + ': ' + str(rolls[2]) + ' (' + str(self.attr[self.skills[skill][2]]) + str_mod + ')')
# Check if something meisterlich or a patzer occured (Doppel-20 or 1, Triple-20 or 1 )
if rolls.count(20) >= 2:
patz = True
if rolls.count(20) == 3:
mega_patz = True
if rolls.count(1) >= 2:
meister = True
if rolls.count(1) == 3:
mega_meister = True
# Get results
res1 = self.attr[self.skills[skill][0]] - rolls[0] + mod
res2 = self.attr[self.skills[skill][1]] - rolls[1] + mod
res3 = self.attr[self.skills[skill][2]] - rolls[2] + mod
# Check single results
if res1 < 0:
points_left = points_left + res1
if res2 < 0:
points_left = points_left + res2
if res3 < 0:
points_left = points_left + res3
# Check whether probe was passed and give corresponding message
# Fail message
if not patz and not mega_patz and points_left < 0:
print(f'{self.name} failed with {points_left}.')
passed = False
# Success messages
elif not patz and not mega_patz and points_left >= 0:
print(f'{self.name} passed with {points_left}.')
passed = True
elif meister and not mega_meister and points_left < 0:
print(f'Though {self.name} should have failed with {points_left} our hero was struck by the Gods' +
'and passed meisterlich.')
passed = True
elif mega_meister and points_left < 0:
print('Though ' + self.name + 'should have failed with ' + str(points_left) +
', our hero was struck by the Gods and passed mega meisterlich.')
passed = True
# Extra messages for meisterlich and patzing
if meister and not mega_meister:
print('... and it was meisterlich!')
elif mega_meister:
print('... and it was mega meisterlich!')
elif patz and not mega_patz:
print(f'{self.name} is an idiot and patzed.')
elif mega_patz:
print(f'{self.name} is an gigantic idiot and mega patzed.')
# Log stuff
if self.skills[skill][4] == 'talent':
self.logger.info(f'tal_probe;{self.name};{skill};{self.skills[skill]};{mod};{rolls};{res1};{res2};'
f'{res3};{points_left};{passed};{meister};{patz};{mega_meister};{mega_patz}')
elif self.skills[skill][4] == 'magic':
self.change_AE(-self.skills[skill][5])
self.logger.info(f'mag_probe;{self.name};{skill};{self.skills[skill]};{mod};{rolls};{res1};{res2};'
f'{res3};{points_left};{passed};{meister};{patz};{mega_meister};{mega_patz}')
return passed, meister, mega_meister, patz , mega_patz
def export(self, mode: str = "object"):
"""Method to export the hero either in JSON for Optolith or as an pickled object.
The idea is that the history of Proben can be tracked and analysed so that the corresponding
talents or attributes can be leveled ;-)
"""
def take_a_hit(self):
"""Take a hit by an enemy and log it"""
enemy = input(f'Aua! What has hit {self.name}? ')
damage = int(input(f'How much damage did {enemy} inflict? '))
self.change_LP(-damage)
source = input(f'How did {enemy} hit {self.name}? ')
source_class = input(f'What is the general class of {source}? ')
print('===========================================================================')
print('===========================================================================')
print(f'OMG! {self.name} was hit by a {enemy} and suffered {damage} damage from this brutal attack with a '
f'{source} in the style of {source_class} and with {self.LP} LP left suffers {self.wounds} LEVELS OF PAIN (-{self.wounds} AT/PA).')
print('===========================================================================')
print('===========================================================================')
self.logger.info(f'hit_taken;{self.name};{enemy};{damage};{source};{source_class}')
def give_a_hit(self):
"""Hit something"""
enemy = input(f'SCHWUSSS! What did {self.name} hit? ')
damage = int(input(f'How much damage did {self.name} inflict on {enemy}? '))
source = input(f'How did {self.name} hit {enemy}? ')
source_class = input(f'What is the general class of {source}? ')
print(f'N1! A {enemy} was hit by a {self.name} and suffered {damage} damage from this brutal attack with a '
f' {source} ({source_class}).')
self.logger.info(f'hit_given;{self.name};{enemy};{damage};{source};{source_class}')
def run(group: List[Hero]):
# Playing loop asking for names and modifiers for talent probes
# TODO never do an endless while loop, use a max_round = 10000 or so
playing = True # Check whether playing loop shall be stopped
while playing:
modifier = 0
if len(group) == 1:
name, stuff = list(group.items())[0]
else:
while True:
name = input(
'Who wants to perform something(' + str(names) + ')? '
'(Enter "feddich" to quit.) '
)
if name not in group and name != "feddich":
matches = get_close_matches(name, list(group.keys()) + ["feddich"], cutoff=.6)
if len(matches) == 1:
yes_no = input(f"Misspelled? Did you mean {matches[0]}? (y/n) ")
if yes_no == "y":
name = matches[0]
break
warnings.warn("This hero is not known!")
print("Please provide a valid hero name!!!")
else:
break
if name != 'feddich':
Digga = group[name]
while True:
user_action_and_mod = input(
"Oh mighty " + Digga.name + ', what are you trying to accomplish ' +
'next? (Enter talent or attribute name, optional modifier separated by a comma,' +
' enter "feddich" to quit.) '
)
if ',' in user_action_and_mod:
user_action = user_action_and_mod.split(',')[0].replace(' ', '')
modifier = int(user_action_and_mod.split(',')[1].replace(' ', ''))
else:
user_action = user_action_and_mod
if debug and user_action != "feddich":
print(f"You are trying to perform {user_action} with modifier {modifier}...")
if user_action not in Digga.possible_probes and user_action != "feddich":
matches = get_close_matches(user_action, list(Digga.possible_probes) + ["feddich"], cutoff=.3)
if len(matches) == 1:
yes_no = input(f"Misspelled? Did you mean {matches[0]}? (y/n) ")
if yes_no == "y":
user_action = matches[0]
break
elif len(matches) > 1:
print(f"Probably you meant any of {matches}. Please try again.")
else:
warnings.warn(f"This action is not known! ({user_action})")
print("Misspelled? Try again ;-)")
else:
break
playing = Digga.perform_action(user_action, modifier)
else:
for h in names:
print(f'{h} has left the building {group[h].LP} LP and {group[h].AE} AE.')
playing = False
logger.info('Probemaker is feddich')
if __name__ == "__main__":
if debug_log:
log_name = 'test.log'
else:
log_name = 'probe.log'
logging.basicConfig(filename=log_name,
# encoding='utf-8',
format='%(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S;', level=logging.DEBUG)
logger = logging.getLogger("Basic Logger")
logger.info('Probemaker started')
hfiles = dict() # Dict for heros' .json files
group = dict() # Dict to collect all Hero objects
names = list() # List to collect all names of heros in group
# Create total path to hero files
for hero in heros:
hfiles[hero] = (data_folder / hero).resolve()
if debug:
print(heros)
print("Data folder", data_folder)
print(hfiles)
# Create Hero objects
for h in hfiles:
Digga = Hero(hfiles[h], logger, show_values)
names.append(Digga.name)
group[Digga.name] = Digga
logger.info(f'{Digga.name} loaded')
run(group)