diff options
-rw-r--r-- | Pipfile | 1 | ||||
-rw-r--r-- | Pipfile.lock | 25 | ||||
-rw-r--r-- | sbdata/__main__.py | 25 | ||||
-rw-r--r-- | sbdata/repo.py | 2 | ||||
-rw-r--r-- | sbdata/tasks.py | 23 |
5 files changed, 70 insertions, 6 deletions
@@ -8,6 +8,7 @@ requests = "*" mwparserfromhell = "*" click = "*" questionary = "*" +rich = "*" [dev-packages] mypy = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 9480071..33c0b7a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "2f97b2115fdfc808a8b0d6e47b772ed9a39aa5e4a87cf2c2846103de8d070412" + "sha256": "d800669875d1b92f0d8196a0fe4a8dd6302fdbc9bd9ddde374263bcd15e76aec" }, "pipfile-spec": 6, "requires": { @@ -39,6 +39,13 @@ "index": "pypi", "version": "==8.0.4" }, + "commonmark": { + "hashes": [ + "sha256:452f9dc859be7f06631ddcb328b6919c67984aca654e5fefb3914d54691aed60", + "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9" + ], + "version": "==0.9.1" + }, "idna": { "hashes": [ "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff", @@ -89,6 +96,14 @@ "markers": "python_full_version >= '3.6.2'", "version": "==3.0.28" }, + "pygments": { + "hashes": [ + "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65", + "sha256:4e426f72023d88d03b2fa258de560726ce890ff3b630f88c21cbb8b2503b8c6a" + ], + "markers": "python_version >= '3.5'", + "version": "==2.11.2" + }, "questionary": { "hashes": [ "sha256:600d3aefecce26d48d97eee936fdb66e4bc27f934c3ab6dd1e292c4f43946d90", @@ -105,6 +120,14 @@ "index": "pypi", "version": "==2.27.1" }, + "rich": { + "hashes": [ + "sha256:14bfd0507edc633e021b02c45cbf7ca22e33b513817627b8de3412f047a3e798", + "sha256:fdcd2f8d416e152bcf35c659987038d1ae5a7bd336e821ca7551858a4c7e38a9" + ], + "index": "pypi", + "version": "==12.0.0" + }, "urllib3": { "hashes": [ "sha256:000ca7f471a233c2251c6c7023ee85305721bfdf18621ebff4fd17a8653427ed", diff --git a/sbdata/__main__.py b/sbdata/__main__.py index 596a51f..5453611 100644 --- a/sbdata/__main__.py +++ b/sbdata/__main__.py @@ -4,7 +4,8 @@ import sys from typing import Any import questionary - +import rich +import rich.table from sbdata.repo import Item from sbdata.task import Arguments, tasks @@ -19,6 +20,12 @@ class ObjectEncoder(json.JSONEncoder): return super().default(o) +def render_thing(i): + if isinstance(i, Item): + return i.internalname + return str(i) + + def main(): args = Arguments(sys.argv) task = args.get_value( @@ -30,6 +37,22 @@ def main(): data = task.run(args) if args.has_flag('json'): print(json.dumps(data, cls=ObjectEncoder)) + if args.has_flag('explore'): + if not (isinstance(data, list) and len(data) > 0 and dataclasses.is_dataclass(data[0])): + print('Cannot explore this') + return + console = rich.get_console() + keys = list(data[0].__dict__.keys()) + query = '' + while True: + table = rich.table.Table() + for k in keys: + table.add_column(k) + for item in data: + if any(query in render_thing(val).casefold() for val in item.__dict__.values()): + table.add_row(*[render_thing(getattr(item, k)) for k in keys]) + console.print(table) + query = console.input("Search: ") if __name__ == '__main__': diff --git a/sbdata/repo.py b/sbdata/repo.py index 475f2a6..7fdfca3 100644 --- a/sbdata/repo.py +++ b/sbdata/repo.py @@ -40,7 +40,7 @@ def find_item_by_name(name: str) -> typing.Optional[Item]: if item.internalname.casefold() == name or bare_name(item.displayname) in name or (item.itemid == 'minecraft:enchanted_book' - and name in bare_name(item.lore[0]))] + and bare_name(item.lore[0]).endswith(name))] if pot: return pot[0] return None diff --git a/sbdata/tasks.py b/sbdata/tasks.py index 8ac1f8c..ede5bac 100644 --- a/sbdata/tasks.py +++ b/sbdata/tasks.py @@ -15,6 +15,7 @@ class DungeonDrop: item: Item floor: int chest: str + cost: int drop_chances: dict[str, str] def get_drop_chance(self, has_s_plus: bool, talisman_level: int, boss_luck: int): @@ -22,6 +23,16 @@ class DungeonDrop: return self.drop_chances.get(drop_identifier) +default_chest_costs: dict[str, dict[int, int]] = dict( + Wood={7: 0}, + Gold={1: 25_000, 2: 50_000, 7: 100_000}, + Diamond={1: 50_000, 2: 100_000, 7: 250_000}, + Emerald={1: 100_000, 2: 250_000, 7: 500_000}, + Obsidian={1: 250_000, 2: 500_000, 7: 1_000_000}, + Bedrock={4: 4, 7: 2_000_000} +) + + @register_task("Fetch Dungeon Loot") def fetch_dungeon_loot(args: Arguments): items = [] @@ -31,6 +42,7 @@ def fetch_dungeon_loot(args: Arguments): item = None ifloor = None chest = None + cost = None drop_chances = {} for param in template.params: @@ -42,14 +54,19 @@ def fetch_dungeon_loot(args: Arguments): elif attr_name == 'customlink': if item is None: item = find_item_by_name(attr_value.split('#')[-1]) + elif attr_name == 'cost': + cost = int(attr_value.replace(',', '')) 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: + if item is None or ifloor is None or chest is None or cost is None: print('WARNING: Missing data for item: ' + str(template)) else: - items.append(DungeonDrop(item, ifloor, chest, drop_chances)) - return items + if cost == 0: + defaults = default_chest_costs[chest] + cost = defaults[min(f for f in defaults.keys() if f >= ifloor)] + items.append(DungeonDrop(item, ifloor, chest, cost, drop_chances)) + return items |