-
Notifications
You must be signed in to change notification settings - Fork 0
/
roll-crit_hits_revisited.py
executable file
·1317 lines (1191 loc) · 38.2 KB
/
roll-crit_hits_revisited.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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Critical Hits Revisited
"""
# Futures
from __future__ import unicode_literals
import sys
import logging
import inspect
import csv
import random
import re
import textwrap
# Other Libs
# from typing import Any, Union
# from colorama import Fore, Style
import d20
from Weapon import Weapon
from PlayerCharacter import PC
# Owned
# from {path} import {class}
__author__ = "Buckley Collum"
__copyright__ = "Copyright 2020, QuoinWorks"
__credits__ = ["Buckley Collum"]
__license__ = "GNU General Public License v3.0"
__version__ = "0.1.6"
__maintainer__ = "Buckley Collum"
__email__ = "buckleycollum@gmail.com"
__status__ = "Dev"
default_loglevel = 'warning'
class Color:
HEADER = "\033[95m"
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
characterClass = {
"artificer": {"proficiency": {"weapon": ["simple"]}},
"barbarian": {"proficiency": {"weapon": ["simple", "martial"]}},
"bard": {"proficiency": {"weapon": ["simple", "martial"]}},
"cleric": {"proficiency": {"weapon": ["simple"]}},
"druid": {"proficiency": {"weapon": ["simple", "martial"]}},
"fighter": {"proficiency": {"weapon": ["simple", "martial"]}},
"monk": {"proficiency": {"weapon": ["simple"]}},
"paladin": {"proficiency": {"weapon": ["simple", "martial"]}},
"ranger": {"proficiency": {"weapon": ["simple", "martial"]}},
"rogue": {"proficiency": {"weapon": ["simple", "martial"]}},
"sorcerer": {"proficiency": {"weapon": ["simple", "martial"]}},
"warlock": {"proficiency": {"weapon": ["simple", "martial"]}},
"wizard": {"proficiency": {"weapon": ["simple", "martial"]}},
}
damages = {
"bludgeoning": (
("You call that a crit?", 1, "", ""),
(
"Smashed off balance!",
1,
"Your next attack against the creature has advantage.",
"",
),
("Good hit!", 2, "", ""),
(
"Sent reeling!",
2,
"You push the creature up to 15 feet in any direction.",
"",
),
("Great hit!", 3, "", ""),
("Take a seat!", 3, "The creature is knocked prone.", ""),
(
"Rocked and rolled!",
3,
"You push the creature up to 15 feet away, and the creature is knocked prone.",
"",
),
("Grievous injury!", 4, "", "minor"),
("Crushed!", 5, "", "major"),
(
"Splat!",
5,
"The creature is stunned until the end of your next turn.",
"major",
),
),
"piercing": (
("You call that a crit?", 1, "", ""),
("Lunge and thrust!", 3, "", ""),
("Good hit!", 2, "", ""),
("Stabbed!", 3, "", ""),
("Great hit!", 3, "", ""),
("Swiss cheese!", 3, "", "minor"),
("Punctured!", 3, "", "minor"),
("Cruel prick!", 3, "", "major"),
("Run through!", 4, "", "major"),
("Pierce!", 5, "", "major"),
),
"slashing": (
("You call that a crit?", 1, "", ""),
(
"Sliced and diced!",
1,
"The creature loses 1d6 hit points at the start of its next turn.",
"",
),
("Good hit!", 2, "", ""),
(
"Open gash!",
1,
"The creature is bleeding! For the next minute the creature loses 1d4 damage"
"at the start of each of its turns until it uses an action to staunch this wound.",
"",
),
("Great hit!", 3, "", ""),
(
"Deep slice!",
3,
"The creature is bleeding! For the next minute the creature loses 1d8 hit points "
"at the start of each of its turns until it uses an action to staunch this wound.",
"",
),
(
"Lacerated!",
3,
"The creature is bleeding! For the next minute the creature loses 1d12 hit points "
"at the start of each of its turns until it uses an action to staunch this wound.",
"",
),
("Severed!", 4, "", "minor"),
("Dissected!", 5, "", "major"),
(
"Slash!",
5,
"The creature is bleeding! For the next minute the creature loses 2d8 hit points "
"at the start of each of its turns until it uses an action to staunch this wound.",
"major",
),
),
"acid": (
("You call that a crit?", 1, "", ""),
(
"Scalding bile!",
1,
"The creature is scarred. While scarred the creature has "
"disadvantage on all Charisma ability checks except Charisma (Intimidation). "
"Being scarred can be healed in the same way as a minor injury.",
"",
),
("Good hit!", 2, "", ""),
(
"Melted flesh!",
1,
"The creature is disfigured. While disfigured the creature has "
"disadvantage on all Charisma ability checks except Charisma (Intimidation). "
"Being disfigured can be removed with the spell greater restoration.",
"",
),
("Great hit!", 3, "", ""),
(
"Boiling flesh!",
3,
"If the creature is wearing armor its AC modifier is reduced by 1 until "
"it can be repaired (for 1/4th the price of new armor of the same type) "
"or cleaned (if the armor is magical). If the creature is not wearing armor, "
"roll on the minor injury chart.",
"minor",
),
(
"Horrific mutilation!",
3,
"the creature is disfigured. While disfigured the creature has disadvantage "
"on all Charisma ability checks except Charisma (Intimidation). "
"Being disfigured can be removed with the spell greater restoration.",
"minor",
),
(
"Caustic trauma!",
4,
"If the creature is wearing armor, roll on the minor injury chart and "
"its AC modifier is reduced by 2 until it can be repaired (for half the price "
"of new armor of the same type) or cleaned (if the armor is magical). "
"If the creature is not wearing armor, roll on the major injury chart.",
"major",
),
("Vitriolic!", 5, "", "major"),
(
"Acid bath!",
5,
"If the creature is wearing armor, the armor is destroyed (if non-magical)or "
"rendered useless until cleaned during a long rest (if magical) and roll on "
"the major injury chart. If the creature is not wearing armor, roll on the "
"major injury chart and the creature is disfigured. "
"While disfigured the creature has disadvantage on all Charisma ability checks "
"except Charisma (Intimidation). Being disfigured can be removed with "
"the spell greater restoration.",
"major",
),
),
"cold": (
("You call that a crit?", 1, "", ""),
(
"Scalding bile!",
1,
"The creature may only move half its movement speed on its next turn.",
"",
),
("Good hit!", 2, "", ""),
(
"Frosty!",
1,
"The creature’s movement speed is 0 until the end of its next turn.",
"",
),
("Great hit!", 3, "", ""),
(
"Freezing!",
3,
"The creature is paralyzed until the end of its next turn.",
"",
),
(
"Frozen!",
3,
"The creature is paralyzed until the end of its next turn. "
"If the creature takes damage before the end of its next turn, "
"roll on the minor injury chart.",
"",
),
(
"Ice block!",
4,
"The creature is paralyzed until the end of its next turn and "
"rolls on the minor injury chart.",
"minor",
),
("Glacial!", 5, "", "major"),
(
"Subzero!",
5,
"The creature is paralyzed for the next minute. "
"The creature may attempt a saving throw at the end "
"of each of its turns (DC 16) to end this effect. "
"If it fails this saving throw three times it is "
"frozen solid and becomes a petrified but frozen solid "
"in a block of ice rather than turned to stone.",
"major",
),
),
"fire": (
("You call that a crit?", 1, "", ""),
(
"Heat wave!",
1,
"Attack rolls for attacks that deal fire damage have advantage "
"when made against the creature until the end of its next turn.",
"",
),
("Good hit!", 2, "", ""),
(
"Hot flash!",
1,
"The creature is on fire. While the creature is on fire it takes "
"2d4 fire damage at the start of each of its turns. "
"The creature can end this condition by dropping prone and "
"using 5 feet of movement to roll on the ground.",
"",
),
("Great hit!", 3, "", ""),
(
"Ablaze!",
3,
"The creature is on fire. While the creature is on fire, "
"it takes 2d6 fire damage at the start of each of its turns. "
"The creature can end this condition by dropping prone and "
"using 5 feet of movement to roll on the ground.",
"",
),
(
"Burnt to a crisp!",
3,
"The creature is charred. If the creature has resistance to fire, "
"it loses that resistance. If the creature does not have resistance "
"to fire, it gains vulnerability to fire. Both of these effects can "
"be ended the same as a minor injury.",
"",
),
(
"Hellfire!",
4,
"The creature is on fire. While the creature is on fire it takes "
"2d6 fire damage at the start of each of its turns. The creature can "
"end this condition by dropping prone and using 5 feet of movement "
"to roll on the ground.",
"minor",
),
("Combustion!", 5, "", "major"),
(
"Inferno!",
5,
"The creature is on fire. While the creature is on fire it takes "
"2d8 fire damage at the start of each of its turns. "
"The creature can end this condition by dropping prone and "
"using 5 feet of movement to roll on the ground.",
"major",
),
),
"force": (
("You call that a crit?", 1, "", ""),
(
"Spellstruck!",
1,
"The creature has disadvantage on saving throws against "
"spells until the end of its next turn.",
"",
),
("Good hit!", 2, "", ""),
(
"Eldritch incandescence!",
1,
"Spell attack rolls against the creature have advantage "
"until the end of its next turn.",
"",
),
("Great hit!", 3, "", ""),
(
"Bewitching blow!",
3,
"The creature is spellbound until the end of its next turn. "
"While spellbound it makes saving throws against spells with "
"disadvantage and spell attack rolls against it have advantage.",
"",
),
(
"Mystic magnet!",
3,
"The creature is spellbound for the next minute. "
"While spellbound it makes saving throws against spells with "
"disadvantage and spell attack rolls against it have advantage. "
"At the end of each of the creature’s turns it can make an Intelligence "
"saving throw (DC 14) to end this effect.",
"minor",
),
(
"Ensorcelled!",
4,
"the creature is spellbound for the next minute. "
"While spellbound it makes saving throws against spells with "
"disadvantage and spell attack rolls against it have advantage. "
"At the end of each of the creature’s turns it can make an "
"Intelligence saving throw (DC 16) to end this effect.",
"",
),
("Arcane injury!", 5, "", "major"),
(
"Magically mauled!",
5,
"The creature is spellbound for the next minute. "
"While spellbound it makes saving throws against spells with "
"disadvantage and spell attack rolls against it have advantage. "
"At the end of each of the creature’s turns it can make an "
"Intelligence saving throw (DC 18) to end this effect.",
"major",
),
),
"lightning": (
("You call that a crit?", 1, "", ""),
(
"Shocking!",
1,
"The creature cannot use reactions until the end of its next turn.",
"",
),
("Good hit!", 2, "", ""),
(
"Sparks fly!",
1,
"You may choose one other creature within 15 ft. of the victim. "
"That creature must succeed on a Dexterity saving throw (DC 14) or "
"take half as much damage.",
"",
),
("Great hit!", 3, "", ""),
(
"Electric arc!",
3,
"You may choose one other creature within 15 ft. of the victim. "
"That creature must succeed on a Dexterity saving throw (DC 18) or "
"take half as much damage.",
"minor",
),
(
"Fulminate!",
3,
"If the creature is wearing metal armor, then roll on the major injury chart instead.",
"minor",
),
(
"Lit up!",
4,
"The creature and each creature you choose within 15 ft. of it "
"cannot take reactions until the end of their next turn.",
"minor",
),
("Electrocuted!", 5, "", "major"),
(
"Lightning rod!",
5,
"You may choose one other creature within 15 ft. of the victim. "
"That creature must succeed on a Dexterity saving throw (DC 20) or "
"take half as much damage.",
"major",
),
),
"necrotic": (
("You call that a crit?", 1, "", ""),
(
"Spoil!",
1,
"The creature cannot regain hit points until the end of its next turn.",
"",
),
("Good hit!", 2, "", ""),
(
"Fester!",
1,
"The creature’s maximum hit points are reduced by the same amount.",
"",
),
("Great hit!", 3, "", ""),
(
"Decay!",
3,
"The creature’s maximum hit points are reduced by the same amount.",
"",
),
(
"Rot!",
3,
"the creature cannot regain hit points for the next minute. "
"It may make a saving throw (DC 16) at the end of each of its turns to end this effect.",
"",
),
(
"Blight!",
4,
"The creature’s maximum hit points are reduced by the same amount. ",
"minor",
),
("Atrophy!", 5, "", "major"),
(
"Putrefy!",
5,
"The creature’s maximum hit points are reduced by the same amount, and "
"the creature cannot regain hit points until the end of its next turn. ",
"major",
),
),
"poison": (
("You call that a crit?", 1, "", ""),
(
"Nauseous!",
1,
"The creature has disadvantage on its next ability check, "
"attack roll, or saving throw.",
"",
),
("Good hit!", 2, "", ""),
(
"Sickened!",
1,
"The creature has disadvantage on all ability checks, "
"attack rolls, and saving throws until the end of its next turn.",
"",
),
("Great hit!", 3, "", ""),
(
"Poisoned!",
3,
"The creature may attempt a saving throw (DC 12) at the end of each "
"of its turns to end this effect.",
"minor",
),
(
"Contaminated!",
3,
"The creature is poisoned for the next minute. "
"The creature may attempt a saving throw (DC 16) at the end of each "
"of its turns to end this effect.",
"",
),
(
"Toxic shock!",
4,
"The creature is poisoned for the next minute. "
"The creature may attempt a saving throw (DC 12) at the end of each "
"of its turns to end this effect.",
"minor",
),
("System failure!", 5, "", "major"),
(
"Biological breakdown!",
5,
"The creature is poisoned for the next minute. "
"The creature may attempt a saving throw (DC 16) at the end of each "
"of its turns to end this effect.",
"major",
),
),
"psychic": (
("You call that a crit?", 1, "", ""),
(
"Disoriented!",
1,
"You control the creature’s movement on its next turn.",
"",
),
(
"Confused!",
1,
"The creature cannot differentiate friend from foe until the end of its next turn.",
"",
),
("Good hit!", 2, "", ""),
("Great hit!", 3, "", ""),
("Dominated!", 3, "You control the creature’s action on its next turn.", ""),
("Psychological fracture!", 3, "", "insanity.disadvantage()"),
("Psychological break!", 4, "", "insanity"),
("Madness!", 5, "", "insanity"),
("Mind melt!", 5, "", "insanity.advantage()"),
),
"radiant": (
("You call that a crit?", 1, "", ""),
("Scalding bile!", 1, "", ""),
("Good hit!", 2, "", ""),
("Melted flesh!", 1, "", ""),
("Great hit!", 3, "", ""),
("Boiling flesh!", 3, "", "minor"),
("Horrific mutilation!", 3, "", "minor"),
("Caustic trauma!", 4, "", "major"),
("Vitriolic!", 5, "", "major"),
("Acid bath!", 5, "", "major"),
),
"thunder": (
("You call that a crit?", 1, "", ""),
("Scalding bile!", 1, "", ""),
("Good hit!", 2, "", ""),
("Melted flesh!", 1, "", ""),
("Great hit!", 3, "", ""),
("Boiling flesh!", 3, "", "minor"),
("Horrific mutilation!", 3, "", "minor"),
("Caustic trauma!", 4, "", "major"),
("Vitriolic!", 5, "", "major"),
("Acid bath!", 5, "", "major"),
),
}
def dmg_icon(damage_type="bludgeoning") -> str:
dmgs = {
"bludgeoning": "🔨",
"piercing": "🗡",
"slashing": "⚔️",
"acid": "",
"cold": "❄️",
"fire": "🔥",
"force": "💨",
"lightning": "⚡️",
"necrotic": "\u2623", # u'💀', ☣
"poison": "\u2620",
"psychic": "🧠",
"radiant": "\u2622", # u'💥',
"thunder": "☁️",
"sneak": "😏",
}
# 'necrotic': u'💀',
# 'radiant': u'💥',
return dmgs[damage_type]
addon = {
"none": [None, None],
"minor": ["injury", "minor"],
"major": ["injury", "major"],
"insanity": ["insanity", ""],
"insanity_adv": ["insanity", "advantage"],
"insanity_dis": ["insanity", "disadvantage"],
}
injuryDescription = {
"minor": (
"Injured leg! The creature’s movement speed is reduced by 10 ft.",
"Injured arm! Randomly determine one of the creature’s arms. "
"That arm cannot be used to hold a shield and the creature has "
"disadvantage on any rolls involving the use of that arm.",
"Multiple injuries! The creature’s maximum hit points are "
"reduced by an amount equivalent to half of the damage dealt by the attack.",
"Badly beaten! The creature has disadvantage on Constitution saving throws",
"Ringing blow! The creature is stunned until the end of its "
"next turn and deafened until it completes a the recuperate downtime activity.",
"Blow to the head! The creature is unconscious for 2d12 hours.",
),
"major": (
"Crippled leg! The creature’s movement speed is reduced by 10 feet and "
"it has disadvantage on Dexterity saving throws.",
"Crippled arm! Randomly determine one of the creature’s arms. "
"That arm cannot be used to hold an item and any ability check requiring "
"that arm automatically fails or has disadvantage (DM’s choice).",
"Severely wounded! The creature’s maximum hit points are reduced by an "
"amount equivalent to the damage dealt by the attack.",
"Edge of death! The creature has disadvantage on Constitution and death saving throws.",
"My eyes! The creature is blinded.",
"Decapitated! The creature is dead.",
),
}
def csv_dict_list(variables_file):
# Open csv, iterate over the rows and map values to a list of dictionaries containing key/value pairs
reader = csv.DictReader(open(variables_file, "r"))
dict_list = []
for line in reader:
dict_list.append(line)
return dict_list
def insanity(i):
switcher = {
1: "Synesthesia. You can hear colors, smell sounds, or taste textures. "
"Regardless of the specific manifestation, you have disadvantage on all "
"Perception and Investigation skill checks.",
2: "Kleptomania. Once per day when you are in a personal residence or marketplace, "
"the DM can call on you to succeed on a Wisdom saving throw (DC 12) or "
"attempt to steal an item of insignificant practical and monetary value.",
3: "Paranoia. Once per day following an interaction with another creature "
"(including other PCs) the DM can call on you to succeed on a Wisdom saving "
"throw (DC 12) or you suspect that creature is secretly plotting against you.",
4: "Obsession. Choose a person or personal interest you are obsessed with. "
"Once per day, when you are presented with an opportunity to interact with or "
"learn more about the subject of your obsession, then the DM can call on you "
"to succeed on a Wisdom saving throw (DC 14) or ignore everything else to "
"obsess over the object of your fascination.",
5: "Addiction. Choose a behavior or substance you have used."
"Once per day, when you are presented with an opportunity to do "
"the behavior or use the substance, the DM can call on you to succeed on a Wisdom "
"saving throw (DC 14) or ignore everything else to indulge in your vice.",
6: "Odd Thinking. Once per day when you hear a rational explanation for an event or "
"occurrence, your DM may call on you to succeed on a Wisdom saving throw (DC 12) or "
"you reject the rational explanation for a conspiratorial or fantastical explanation.",
7: "Narcissism. When you take an action or series of action that doesn’t directly benefit you, "
"you must pass a Wisdom saving throw (DC 11) or you can’t take that action or series of actions. "
"If any self-sacrifice on your part would be required, then the DC of the saving throw is "
"increased to 16.",
8: "Delusional. When you gain this insanity, the DM will tell you a belief that you have. "
"No matter what evidence is presented to the contrary, so long as you have this insanity, "
"you cannot be persuaded that this belief is not true.",
9: "Pica. Once per day the DM can call on you to pass a Wisdom saving throw (DC 14) or "
"immediately eat one non-food object (such as dirt, napkins, or a small piece of jewelry) "
"of the DM’s choice.",
10: "Retrograde amnesia. You forget everything about your personal life prior to the moment "
"you received this insanity.",
11: "Overwhelmed. If you do not have immunity or resistance to psychic damage, "
"then you gain vulnerability to psychic damage. If you have resistance to "
"psychic damage, then you lose it. If you have immunity to psychic damage, "
"then you lose it but gain resistance to psychic damage.",
12: "Anterograde amnesia. Whenever you try to recall a fact you learned since you "
"received this insanity, make a Wisdom saving throw (DC 12). If you fail you "
"cannot recall the fact.",
13: "Dependence. You must pass a Wisdom saving throw (DC 14) to take an action "
"that one or more of your allies disapprove of.",
14: "Anxious. You have disadvantage on saving throws against being frightened. "
"Additionally, once per day the DM can call on you to succeed a Wisdom saving "
"throw (DC 14) or be frightened by a creature of the DM’s choosing for the next minute.",
15: "Mute. Whenever you wish to speak aloud (including casting a spell that has verbal components), "
"then you must succeed on a Wisdom saving throw (DC 13) to do so.",
16: "Narcolepsy. You have disadvantage on saving throws against sleeping or unconsciousness. "
"Once per day the DM may call on you to succeed on a Constitution saving throw (DC 12) or "
"fall unconscious for one minute or until you take damage or another creature spends "
"their action trying to rouse you.",
17: "Insomnia. You cannot take long rests and your short rests take 8 hours to complete.",
18: "Homicidal. After each long rest you must pass a Wisdom saving throw (DC 14) or be "
"overcome with the urge to end the life of a humanoid creature and you cannot benefit "
"from another long rest until you do so.",
19: "Suicidal. After each long rest you must pass a Wisdom saving throw (DC 12) or "
"make an attempt to end your own life.",
20: "Catatonia. You are unconscious for 10d10 years.",
}
return switcher.get(i, f"Invalid roll: {i}")
def roll(d=20):
"""Roll a 'd'-sided dice"""
return random.randint(1, d)
def advantage():
return max([roll(20) for _ in range(2)])
def disadvantage():
return min([roll(20) for _ in range(2)])
def append(incoming, hunt, new):
if hunt.lower() in incoming.lower():
index = incoming.lower().find(hunt.lower())
return incoming[: index + len(hunt)] + new + incoming[index + len(hunt):]
else:
return incoming
def weapon_attack(
attacker=None, target=None, weapon=None, adv=False, dis=False, condition=None
):
# Attack Roll = Ability Modifier + Proficiency + Enchantment/Item Bonus + Class Features
output = (
f"{'' if attacker is None else attacker.name + ' is '} attacking "
f"{'' if target is None else target} with the "
f"{'magical +' + str(weapon.bonus_magic) if weapon.magical else ''} "
f"{weapon.name}"
)
output += f", and has {Color.BLUE}Advantage{Color.ENDC}." if adv else ""
print(f"{' '.join(output.split())}") # clean any repeated spaces
if condition:
# ToDo: placeholder to handle influence of condition, e.g., blinded
pass
# If Rogue and has Advantage, then add sneak attack damage to weapon
if "Rogue" in attacker.cclass and adv:
regexp = re.compile("(\\d+).*Rogue")
rogue_level = int(regexp.search(attacker.cclass).group(1)) # get Rogue level
weapon.damage += [[(rogue_level + 1) // 2, 6, "sneak"]] # append sneak damage to Weapon
attack_roll_str = attacker.attack_roll(adv, dis)
d20roll = d20.roll(attack_roll_str)
# d20roll = d20.roll('20')
# Critical 20, for testing
logging.debug(d20roll.crit)
print(f'\tYour Attack roll is ', end='')
if d20roll.crit == d20.CritType.CRIT or d20roll.total >= attacker.crit:
print(f"a Critical HIT: {d20roll.result}")
criticalhit(attacker, weapon, target)
elif d20roll.crit == d20.CritType.FAIL: # total == 1:
print(f"a Critical Fail: {d20roll.result}")
critical_miss(weapon)
else:
attackbonus = attacker.attack_bonus(weapon)
attack_result_str = " + ".join([str(d20roll.total), attackbonus])
attack_result = d20.roll(f"{attack_result_str}")
print(
f"{attack_roll_str} + {attackbonus} = {attack_result_str.replace(' ', '')} = {Color.YELLOW}{attack_result.total}{Color.ENDC}."
)
hitanddamage(attacker, weapon, target)
def die_roll_str(d) -> str:
return f"{d[0]}d{d[1]} [{d[2]}]"
def critical_miss(weapon=None):
print(f"{Color.RED}Critical Fail!{Color.ENDC}")
def indent(my_paragraph) -> str:
return f"\t{my_paragraph}"
print(f"Critical fail roll for d100 is {roll(100)}") # for David Gavrin's table
mymiss = roll(20)
if mymiss == 1:
if weapon:
if weapon.magical:
print(f"\tMagic backfires!")
magic_damage = d20.roll('+'.join([die_roll_str(weapon.damage[0]), str(weapon.bonus_magic)]))
print(
f"\tYou take {magic_damage.result} points of {weapon.damage[0][2]} damage."
)
elif weapon.list == "ranged":
print(
f"\tThe bowstring on {weapon.name} broke!\n"
f"\tOn your next turn you lose your Action and half your movement.\n"
f"\tEither use your next turn to replace the string, or switch weapons."
)
else:
print(
f"\tDangerous Design-Flaw! {weapon.name} broke, and injured you.\n"
f"\tTake {d20.roll(die_roll_str(weapon.damage[0])).result} points of {weapon.damage[0][2]} damage."
)
print(f"")
# print("Weapon breaks!")
elif mymiss < 4:
print(
"\tPoor attack: Has 50% chance to hit any character in the line of attack or within 5' of the target."
)
if random.randint(0, 1):
print(f"\tWhuh? Looks like you missed everyone.")
else:
print(
f"\tYour victim takes {d20.roll(weapon.dice_roll_str).result} points of damage."
)
print(
f"\tAlso, due to dismay, lose your next Bonus Action (either this turn or the next turn)."
)
elif mymiss < 6:
print(
"\tDropped weapon! Disadvantage on next attack, and lose 10ft of motion next turn to pick up weapon."
)
elif mymiss < 11:
print(
"\tFumbled weapon! Lose half your motion until the end of your next turn as you regain your composure."
)
else:
print(
"\tYou missed spectacularly, and your opponent snickered at your failure."
)
def criticalhit(attacker, weapon, target=None, *, outside_roll=0):
"""Critical Hit"""
print(f"{Color.HEADER}Critical Hit!{Color.ENDC}")
rollmatch = {
1: 0,
2: 1,
3: 1,
4: 2,
5: 2,
6: 2,
7: 3,
8: 3,
9: 4,
10: 4,
11: 4,
12: 5,
13: 5,
14: 6,
15: 6,
16: 6,
17: 7,
18: 7,
19: 8,
20: 9,
}
title = effect = also = ''
if not attacker.crits_revisited:
# Double the number of dice rolls for criticals; e.g., change '2d6' to '4d6'
dice_roll_str = re.sub(
"(\\d+)d", lambda m: str(int(m.groups()[0]) * 2) + "d", weapon.dice_roll_str
)
else:
# Roll for Criticals Revisited lookup, if value not specified
my_crit_roll = d20.roll("1d20").total if not outside_roll else outside_roll
primary_damage_type = weapon.damage[0][2]
title, value, effect, also = damages[primary_damage_type][rollmatch[my_crit_roll]]
print(f"\tThe d20 roll for Crits Revisited is {my_crit_roll}")
logging.debug(damages[weapon.damage[0][2]][rollmatch[my_crit_roll]])
# add icons to damage type
new_dmg = []
for d in weapon.damage:
n, s, t = d
t += dmg_icon(t)
new_dmg.append([n, s, t.title()])
weapon.damage = new_dmg
logging.debug(weapon.damage)
dice_roll_str = crits_revisited_hp(weapon, value)
dice_roll_str += f" + {attacker.damage_bonus(weapon)}"
logging.debug(dice_roll_str)
critdamage = d20.roll(dice_roll_str)
print(
f"\t{Color.HEADER}{title}{Color.ENDC} Your {weapon.name} does {critdamage.result} points "
f"of {'magical ' if weapon.magical else ''}damage."
)
if attacker.crits_revisited:
output = ""
if effect:
output += f"\t{Color.YELLOW}{effect}{Color.ENDC}\n"
# ToDo: Add Insanity handling
# if also == 'insanity':
if also == "":
""" HACK to handle damage field that has '' instead of 'none' """
also = "none"
what, howmuch = addon[also]
logging.debug("%s, %s", what, howmuch)
# print(f" * {howmuch} {what}")
if what == "injury":
output += (
f"\t{Color.RED}{howmuch.title()} Injury: {injury(howmuch)}{Color.ENDC}\n"
)
elif what == "insanity":
output += f"\t{Color.YELLOW}Insanity: "
if howmuch == "advantage":
output += f"{insanity(advantage())}"
elif howmuch == "disadvantage":
output += f"{insanity(disadvantage())}"
else:
output += f"{insanity(roll())}"
output += f"{Color.ENDC}\n"
# ToDo: Clean-up TARGET name added into output
if target is not None:
pattern = re.compile(re.escape("creature"), re.IGNORECASE)
output = pattern.sub(target, output)
revision1 = (
append(output, "The creature", f" {target}") if target is not None else effect
)
revision2 = append(revision1, "the same amount", f" ({critdamage.total})")
wrapper = textwrap.TextWrapper(width=80, initial_indent="", subsequent_indent=" ")
word_list = wrapper.wrap(text=revision2)
for element in word_list:
print(element)
def crits_revisited_hp(weapon, value) -> str:
"""return string for crit revisited damage"""
func = inspect.currentframe().f_code
# FORMAT = "[ • %(funcName)20s() ] %(message)s"
# logging.basicConfig(format=FORMAT)
# logging.debug("%s", func.co_name)
critdamage = []
for die in weapon.damage:
# logging.debug("Die = %s", str(die))
quantity, sides, damage_type = die
if value == 1:
logging.debug('%s(): regular roll', func.co_name)
critdamage.append(die_roll_str(die))
elif value == 2:
logging.debug('%s(): maximum regular roll', func.co_name)
critdamage.append(str(sides))
elif value == 3:
logging.debug('%s(): double the rolls', func.co_name)
# Double the number of dice rolled; e.g. change '2d6' to '4d6'
critdamage.append(
re.sub(
"(\\d+)d",
lambda m: str(int(m.groups()[0]) * 2) + "d",
die_roll_str(die),
)
)
elif value == 4:
logging.debug('%s(): maximum + roll', func.co_name)
critdamage.append(str(sides))
critdamage.append(die_roll_str(die))
elif value == 5:
logging.debug('%s(): double maximum', func.co_name)
# print([str(sides)] * (2 * quantity))
# critdamage.extend([str(sides)] * (2 * quantity))
critdamage.extend([f"{2 * quantity}*{str(sides)}"])
# print(f"{value} and {critdamage}")
logging.debug("crit damage revisited = %s", str(critdamage))
return "+".join(critdamage)
def hitanddamage(attacker, weapon, target=None):
rollplus = ""
# print(attacker.feature)
if attacker.feature == "Great Weapon Fighting":
rollplus = "ro<3"
damagebonus = attacker.damage_bonus(weapon)
# print(damagebonus)
rollplus += f"{damagebonus}"
if weapon.magical > 0:
rollplus += f"{weapon.bonus_magic:+}"
new_dmg = []
for d in weapon.damage:
n, s, t = d
t += dmg_icon(t)
new_dmg.append([n, s, t.title()])
# print(new_dmg)
weapon.damage = new_dmg
damage_roll_str = " + ".join([weapon.dice_roll_str, rollplus])