Core: fix start_inventory_from_pool breaking if it's removing the last instance of an item from pool.

Core: fix start_inventory_from_pool removing arbitrary items from pool if quick abort branch is entered.
This commit is contained in:
Fabian Dill 2023-05-03 23:22:58 +02:00 committed by Fabian Dill
parent 97fd78ba1b
commit a0464ecea1
1 changed files with 10 additions and 5 deletions

15
Main.py
View File

@ -165,19 +165,24 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
for count in items.values():
new_items.append(player_world.create_filler())
target: int = sum(sum(items.values()) for items in depletion_pool.values())
for item in world.itempool:
for i, item in enumerate(world.itempool):
if depletion_pool[item.player].get(item.name, 0):
target -= 1
depletion_pool[item.player][item.name] -= 1
# quick abort if we have found all items
if not target:
new_items.extend(world.itempool[i+1:])
break
else:
new_items.append(item)
for player, remaining_items in depletion_pool.items():
if remaining_items:
raise Exception(f"{world.get_player_name(player)}"
f" is trying to remove items from their pool that don't exist: {remaining_items}")
# leftovers?
if target:
for player, remaining_items in depletion_pool.items():
remaining_items = {name: count for name, count in remaining_items.items() if count}
if remaining_items:
raise Exception(f"{world.get_player_name(player)}"
f" is trying to remove items from their pool that don't exist: {remaining_items}")
world.itempool[:] = new_items
# temporary home for item links, should be moved out of Main