Core: change start inventory from pool to warn when nothing to remove (#3158)
* makes start inventory from pool warn and fixes the itempool to match when it can not find a matching item to remove * calc the difference correctly * save new filler and non-removed items differently so we don't remove existing items at random
This commit is contained in:
parent
21bbf5fb95
commit
ae0abd3821
15
Main.py
15
Main.py
|
@ -151,6 +151,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
||||||
# Because some worlds don't actually create items during create_items this has to be as late as possible.
|
# Because some worlds don't actually create items during create_items this has to be as late as possible.
|
||||||
if any(getattr(multiworld.worlds[player].options, "start_inventory_from_pool", None) for player in multiworld.player_ids):
|
if any(getattr(multiworld.worlds[player].options, "start_inventory_from_pool", None) for player in multiworld.player_ids):
|
||||||
new_items: List[Item] = []
|
new_items: List[Item] = []
|
||||||
|
old_items: List[Item] = []
|
||||||
depletion_pool: Dict[int, Dict[str, int]] = {
|
depletion_pool: Dict[int, Dict[str, int]] = {
|
||||||
player: getattr(multiworld.worlds[player].options,
|
player: getattr(multiworld.worlds[player].options,
|
||||||
"start_inventory_from_pool",
|
"start_inventory_from_pool",
|
||||||
|
@ -169,20 +170,24 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
||||||
depletion_pool[item.player][item.name] -= 1
|
depletion_pool[item.player][item.name] -= 1
|
||||||
# quick abort if we have found all items
|
# quick abort if we have found all items
|
||||||
if not target:
|
if not target:
|
||||||
new_items.extend(multiworld.itempool[i+1:])
|
old_items.extend(multiworld.itempool[i+1:])
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
new_items.append(item)
|
old_items.append(item)
|
||||||
|
|
||||||
# leftovers?
|
# leftovers?
|
||||||
if target:
|
if target:
|
||||||
for player, remaining_items in depletion_pool.items():
|
for player, remaining_items in depletion_pool.items():
|
||||||
remaining_items = {name: count for name, count in remaining_items.items() if count}
|
remaining_items = {name: count for name, count in remaining_items.items() if count}
|
||||||
if remaining_items:
|
if remaining_items:
|
||||||
raise Exception(f"{multiworld.get_player_name(player)}"
|
logger.warning(f"{multiworld.get_player_name(player)}"
|
||||||
f" is trying to remove items from their pool that don't exist: {remaining_items}")
|
f" is trying to remove items from their pool that don't exist: {remaining_items}")
|
||||||
assert len(multiworld.itempool) == len(new_items), "Item Pool amounts should not change."
|
# find all filler we generated for the current player and remove until it matches
|
||||||
multiworld.itempool[:] = new_items
|
removables = [item for item in new_items if item.player == player]
|
||||||
|
for _ in range(sum(remaining_items.values())):
|
||||||
|
new_items.remove(removables.pop())
|
||||||
|
assert len(multiworld.itempool) == len(new_items + old_items), "Item Pool amounts should not change."
|
||||||
|
multiworld.itempool[:] = new_items + old_items
|
||||||
|
|
||||||
multiworld.link_items()
|
multiworld.link_items()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue