summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--creature.py48
-rw-r--r--creature_stats/ac.csv27
-rw-r--r--creature_stats/hp.csv27
-rw-r--r--creature_stats/saves.csv27
4 files changed, 129 insertions, 0 deletions
diff --git a/creature.py b/creature.py
new file mode 100644
index 0000000..3584cf0
--- /dev/null
+++ b/creature.py
@@ -0,0 +1,48 @@
+import csv
+from enum import Enum
+
+class Difficulty(Enum):
+ Terrible = -2
+ Low = -1
+ Moderate = 0
+ High = 1
+ Extreme = 2
+
+ @classmethod
+ def from_str(cls, name):
+ name = name.strip().lower()
+ for member in cls:
+ if member.name.lower() == name:
+ return member
+ raise ValueError(f"{name!r} is not a valid {cls.__name__}")
+
+
+def load_csv(name, value_parser=None):
+ if value_parser is None:
+ value_parser = lambda x:x
+ res = dict() # Table by level and Difficulty
+ with open(f"creature_stats/{name}.csv", newline='', encoding='utf8') as file:
+ reader = csv.DictReader(file)
+ for row in reader:
+ level = int(row.pop("Level"))
+ res[level] = {Difficulty.from_str(name):
+ value_parser(val) for name,val in row.items()}
+ return res
+
+def parse_range(str_data):
+ try:
+ value = int(str_data)
+ return (value, value)
+ except ValueError:
+ return tuple([int(i) for i in str_data.split("-")[:2]])
+
+class StatsDB:
+ def __init__(self) -> None:
+ self.ac = load_csv("ac", int)
+ self.saves = load_csv("saves", int)
+ self.hp = load_csv("hp", parse_range)
+
+stats = StatsDB()
+
+# if __name__ == '__main__':
+# main()
diff --git a/creature_stats/ac.csv b/creature_stats/ac.csv
new file mode 100644
index 0000000..0743521
--- /dev/null
+++ b/creature_stats/ac.csv
@@ -0,0 +1,27 @@
+Level,Extreme,High,Moderate,Low
+–1,18,15,14,12
+0,19,16,15,13
+1,19,16,15,13
+2,21,18,17,15
+3,22,19,18,16
+4,24,21,20,18
+5,25,22,21,19
+6,27,24,23,21
+7,28,25,24,22
+8,30,27,26,24
+9,31,28,27,25
+10,33,30,29,27
+11,34,31,30,28
+12,36,33,32,30
+13,37,34,33,31
+14,39,36,35,33
+15,40,37,36,34
+16,42,39,38,36
+17,43,40,39,37
+18,45,42,41,39
+19,46,43,42,40
+20,48,45,44,42
+21,49,46,45,43
+22,51,48,47,45
+23,52,49,48,46
+24,54,51,50,48 \ No newline at end of file
diff --git a/creature_stats/hp.csv b/creature_stats/hp.csv
new file mode 100644
index 0000000..c38f96f
--- /dev/null
+++ b/creature_stats/hp.csv
@@ -0,0 +1,27 @@
+Level,High,Moderate,Low
+-1,9,8-7,6-5
+0,20-17,16-14,13-11
+1,26-24,21-19,16-14
+2,40-36,32-28,25-21
+3,59-53,48-42,37-31
+4,78-72,63-57,48-42
+5,97-91,78-72,59-53
+6,123-115,99-91,75-67
+7,148-140,119-111,90-82
+8,173-165,139-131,105-97
+9,198-190,159-151,120-112
+10,223-215,179-171,135-127
+11,248-240,199-191,150-142
+12,273-265,219-211,165-157
+13,298-290,239-231,180-172
+14,323-315,259-251,195-187
+15,348-340,279-271,210-202
+16,373-365,299-291,225-217
+17,398-390,319-311,240-232
+18,423-415,339-331,255-247
+19,448-440,359-351,270-262
+20,473-465,379-371,285-277
+21,505-495,405-395,305-295
+22,544-532,436-424,329-317
+23,581-569,466-454,351-339
+24,633-617,508-492,383-367 \ No newline at end of file
diff --git a/creature_stats/saves.csv b/creature_stats/saves.csv
new file mode 100644
index 0000000..ec41b0f
--- /dev/null
+++ b/creature_stats/saves.csv
@@ -0,0 +1,27 @@
+Level,Extreme,High,Moderate,Low,Terrible
+–1,9,8,5,2,0
+0,10,9,6,3,1
+1,11,10,7,4,2
+2,12,11,8,5,3
+3,14,12,9,6,4
+4,15,14,11,8,6
+5,17,15,12,9,7
+6,18,17,14,11,8
+7,20,18,15,12,10
+8,21,19,16,13,11
+9,23,21,18,15,12
+10,24,22,19,16,14
+11,26,24,21,18,15
+12,27,25,22,19,16
+13,29,26,23,20,18
+14,30,28,25,22,19
+15,32,29,26,23,20
+16,33,30,28,25,22
+17,35,32,29,26,23
+18,36,33,30,27,24
+19,38,35,32,29,26
+20,39,36,33,30,27
+21,41,38,35,32,28
+22,43,39,36,33,30
+23,44,40,37,34,31
+24,46,42,38,36,32 \ No newline at end of file