Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def create_items(self):
traps = []
configured_item_names = self.item_id_to_name.copy()

items_config = {}
items_config: dict[str, int|dict[str, int]] = {}
for name in configured_item_names.values():
if name == "__Victory__": continue
if name == filler_item_name: continue # intentionally using the Game.py filler_item_name here because it's a non-Items item
Expand All @@ -132,23 +132,25 @@ def create_items(self):

for name, configs in items_config.items():
total_created = 0
if type(configs) == int:
if type(configs) is int:
total_created = configs
for _ in range(configs):
new_item = self.create_item(name)
pool.append(new_item)
elif type(configs) == dict:
for cat, count in configs.values():
elif type(configs) is dict:
for cat, count in configs.items():
total_created += count
true_class = {
"filler": ItemClassification.filler,
"trap": ItemClassification.trap,
"useful": ItemClassification.useful,
"progression_skip_balancing": ItemClassification.progression_skip_balancing,
"progression": ItemClassification.progression
}.get(cat, cat)
if not isinstance(true_class, ItemClassification):
raise Exception(f"Item override for {name} improperly defined")
if isinstance(cat, ItemClassification):
true_class = cat
else:
try:
if cat.startswith('0b'):
true_class = ItemClassification(int(cat, base=0))
else:
true_class = ItemClassification[cat]
except Exception as ex:
raise Exception(f"Item override '{cat}' for {name} improperly defined\n\n{type(ex).__name__}:{ex}")

for _ in range(count):
new_item = self.create_item(name, true_class)
pool.append(new_item)
Expand All @@ -163,7 +165,7 @@ def create_items(self):
self.multiworld.early_items[self.player][name] = int(item["early"])

elif isinstance(item["early"],bool): #No need to deal with true vs false since false wont get here
self.multiworld.early_items[self.player][name] = item_count
self.multiworld.early_items[self.player][name] = total_created

else:
raise Exception(f"Item {name}'s 'early' has an invalid value of '{item['early']}'. \nA boolean or an integer was expected.")
Expand All @@ -177,15 +179,15 @@ def create_items(self):
self.multiworld.local_early_items[self.player][name] = int(item["local_early"])

elif isinstance(item["local_early"],bool):
self.multiworld.local_early_items[self.player][name] = item_count
self.multiworld.local_early_items[self.player][name] = total_created

else:
raise Exception(f"Item {name}'s 'local_early' has an invalid value of '{item['local_early']}'. \nA boolean or an integer was expected.")


pool = before_create_items_starting(pool, self, self.multiworld, self.player)

items_started = []
items_started: list[Item] = []

if starting_items:
for starting_item_block in starting_items:
Expand Down
1 change: 1 addition & 0 deletions src/hooks/World.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def after_create_regions(world: World, multiworld: MultiWorld, player: int):
# {"Item Name": {"progression": 2, "useful": 1}} <- This will create 3 items, with 2 classified as progression and 1 as useful
# {"Item Name": {0b0110: 5}} <- If you know the special flag for the item classes, you can also define non-standard options. This setup
# will create 5 items that are the "useful trap" class
# {"Item Name": {ItemClassification.useful: 5}} <- You can also use the classification directly
def before_create_items_all(item_config: dict[str: int|dict], world: World, multiworld: MultiWorld, player: int) -> dict[str: int|dict]:
return item_config

Expand Down