From 9b662b02e3de31b72397365c6b58a65cea9284f9 Mon Sep 17 00:00:00 2001 From: qwint Date: Mon, 15 Apr 2024 20:43:35 -0500 Subject: [PATCH 1/3] makes start inventory from pool warn and fixes the itempool to match when it can not find a matching item to remove --- Main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Main.py b/Main.py index f1d2f63692d6..e960175df5b3 100644 --- a/Main.py +++ b/Main.py @@ -199,8 +199,12 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No 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"{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}") + # find all filler we generated for the current player and remove until it matches + removables = [item for item in new_items if item.player == player] + for _ in range(len(remaining_items)): + new_items.remove(removables.pop()) assert len(multiworld.itempool) == len(new_items), "Item Pool amounts should not change." multiworld.itempool[:] = new_items From 972ad60ae7d3f4f2e35955c649f3780b825fe281 Mon Sep 17 00:00:00 2001 From: qwint Date: Mon, 15 Apr 2024 20:53:18 -0500 Subject: [PATCH 2/3] calc the difference correctly --- Main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Main.py b/Main.py index e960175df5b3..79ab87af2bf7 100644 --- a/Main.py +++ b/Main.py @@ -203,7 +203,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No f" is trying to remove items from their pool that don't exist: {remaining_items}") # find all filler we generated for the current player and remove until it matches removables = [item for item in new_items if item.player == player] - for _ in range(len(remaining_items)): + for _ in range(sum(remaining_items.values())): new_items.remove(removables.pop()) assert len(multiworld.itempool) == len(new_items), "Item Pool amounts should not change." multiworld.itempool[:] = new_items From 36275f5def3118f1ff0e142daf4017986e6f0f81 Mon Sep 17 00:00:00 2001 From: qwint Date: Tue, 16 Apr 2024 02:01:38 -0500 Subject: [PATCH 3/3] save new filler and non-removed items differently so we don't remove existing items at random --- Main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Main.py b/Main.py index 79ab87af2bf7..8b198a5fc17c 100644 --- a/Main.py +++ b/Main.py @@ -171,6 +171,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. if any(getattr(multiworld.worlds[player].options, "start_inventory_from_pool", None) for player in multiworld.player_ids): new_items: List[Item] = [] + old_items: List[Item] = [] depletion_pool: Dict[int, Dict[str, int]] = { player: getattr(multiworld.worlds[player].options, "start_inventory_from_pool", @@ -189,10 +190,10 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No depletion_pool[item.player][item.name] -= 1 # quick abort if we have found all items if not target: - new_items.extend(multiworld.itempool[i+1:]) + old_items.extend(multiworld.itempool[i+1:]) break else: - new_items.append(item) + old_items.append(item) # leftovers? if target: @@ -205,8 +206,8 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No 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), "Item Pool amounts should not change." - multiworld.itempool[:] = new_items + assert len(multiworld.itempool) == len(new_items + old_items), "Item Pool amounts should not change." + multiworld.itempool[:] = new_items + old_items # temporary home for item links, should be moved out of Main for group_id, group in multiworld.groups.items():