aboutsummaryrefslogtreecommitdiff
path: root/sbdata/tasks.py
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-03-12 01:57:57 +0100
committernea <romangraef@gmail.com>2022-03-12 01:57:57 +0100
commite7caa7a9ba0202c44ad02ea9fd37c27bd4336c26 (patch)
tree03bce4042c47e475a99dfe90bc1e7a31afe25358 /sbdata/tasks.py
downloadsbdata-e7caa7a9ba0202c44ad02ea9fd37c27bd4336c26.tar.gz
sbdata-e7caa7a9ba0202c44ad02ea9fd37c27bd4336c26.tar.bz2
sbdata-e7caa7a9ba0202c44ad02ea9fd37c27bd4336c26.zip
Initial commit
Diffstat (limited to 'sbdata/tasks.py')
-rw-r--r--sbdata/tasks.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/sbdata/tasks.py b/sbdata/tasks.py
new file mode 100644
index 0000000..8ac1f8c
--- /dev/null
+++ b/sbdata/tasks.py
@@ -0,0 +1,55 @@
+import ast
+import dataclasses
+import json
+import re
+import sys
+import typing
+
+from sbdata.repo import find_item_by_name, Item
+from sbdata.task import register_task, Arguments
+from sbdata.wiki import get_wiki_sources_by_title
+
+
+@dataclasses.dataclass
+class DungeonDrop:
+ item: Item
+ floor: int
+ chest: str
+ drop_chances: dict[str, str]
+
+ def get_drop_chance(self, has_s_plus: bool, talisman_level: int, boss_luck: int):
+ drop_identifier = "S" + ('+' if has_s_plus else '') + 'ABCD'[talisman_level] + str(len([i for i in [0, 1, 3, 5, 10] if i >= boss_luck]))
+ return self.drop_chances.get(drop_identifier)
+
+
+@register_task("Fetch Dungeon Loot")
+def fetch_dungeon_loot(args: Arguments):
+ items = []
+ for floor in get_wiki_sources_by_title(*[f'Template:Catacombs Floor {f} Loot Master' for f in ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII']]).values():
+ for template in floor.filter_templates():
+ if template.name.strip() == 'Dungeon Chest Table/Row':
+ item = None
+ ifloor = None
+ chest = None
+ drop_chances = {}
+
+ for param in template.params:
+ attr_name = param.name.nodes[0].strip()
+ attr_value = param.value.nodes[0].strip()
+ if attr_name == 'item':
+ if item is None:
+ item = find_item_by_name(attr_value)
+ elif attr_name == 'customlink':
+ if item is None:
+ item = find_item_by_name(attr_value.split('#')[-1])
+ elif attr_name == 'chest':
+ chest = attr_value
+ elif attr_name == 'floor':
+ ifloor = int(attr_value)
+ elif attr_name.startswith("S"):
+ drop_chances[attr_name] = attr_value
+ if item is None or ifloor is None or chest is None:
+ print('WARNING: Missing data for item: ' + str(template))
+ else:
+ items.append(DungeonDrop(item, ifloor, chest, drop_chances))
+ return items