From 6b50c9508ebfc261268a120bf23cff86b684b8e8 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 15 Nov 2023 21:16:37 -0600 Subject: [PATCH 1/5] The Messenger: super complicated fix for a super uncommon scenario --- worlds/messenger/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 304b43cf5316..612473ac01e2 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -1,7 +1,7 @@ import logging -from typing import Any, Dict, List, Optional +from typing import Any, Counter, Dict, List, Optional -from BaseClasses import CollectionState, Item, ItemClassification, Tutorial +from BaseClasses import CollectionState, Item, ItemClassification, Location, Tutorial from worlds.AutoWorld import WebWorld, World from .constants import ALL_ITEMS, ALWAYS_LOCATIONS, BOSS_LOCATIONS, FILLER, NOTES, PHOBEKINS from .options import Goal, Logic, MessengerOptions, NotesNeeded, PowerSeals @@ -147,6 +147,22 @@ def set_rules(self) -> None: else: MessengerOOBRules(self).set_messenger_rules() + def stage_fill_hook(self, prog_items: List[Item], useful_items: List[Item], filler_items: List[Item], + locations: List[Location]) -> None: + players = self.multiworld.get_game_players(self.game) + total_items = len(prog_items) + items = {} + for index in range(int((total_items * .9)), total_items): + item = prog_items[index] + if item.player in players and item.name in {"Wingsuit", "Rope Dart"}: + items.setdefault(prog_items[index].player, []).append((index, prog_items[index])) + for player, item_pairs in items.items(): + if len(item_pairs) > 1: + item_to_move = self.random.choice(item_pairs) + new_index = self.random.randrange(0, int((total_items * .1))) + prog_items.pop(item_to_move[0]) + prog_items.insert(new_index, item_to_move[1]) + def fill_slot_data(self) -> Dict[str, Any]: shop_prices = {SHOP_ITEMS[item].internal_name: price for item, price in self.shop_prices.items()} figure_prices = {FIGURINES[item].internal_name: price for item, price in self.figurine_prices.items()} From 7b09a15d5a37487a77a4fbfd6345f8225894cb0d Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 15 Nov 2023 21:17:12 -0600 Subject: [PATCH 2/5] unused import --- worlds/messenger/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 612473ac01e2..a59f11601e66 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -1,5 +1,5 @@ import logging -from typing import Any, Counter, Dict, List, Optional +from typing import Any, Dict, List, Optional from BaseClasses import CollectionState, Item, ItemClassification, Location, Tutorial from worlds.AutoWorld import WebWorld, World From e69f8da0076e6a0e7c504ebbfd90798fb334c190 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 15 Nov 2023 21:22:24 -0600 Subject: [PATCH 3/5] forgot it's supposed to be a class method --- worlds/messenger/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index a59f11601e66..7674d960b2cf 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from BaseClasses import CollectionState, Item, ItemClassification, Location, Tutorial +from BaseClasses import CollectionState, Item, ItemClassification, Location, MultiWorld, Tutorial from worlds.AutoWorld import WebWorld, World from .constants import ALL_ITEMS, ALWAYS_LOCATIONS, BOSS_LOCATIONS, FILLER, NOTES, PHOBEKINS from .options import Goal, Logic, MessengerOptions, NotesNeeded, PowerSeals @@ -147,9 +147,10 @@ def set_rules(self) -> None: else: MessengerOOBRules(self).set_messenger_rules() - def stage_fill_hook(self, prog_items: List[Item], useful_items: List[Item], filler_items: List[Item], - locations: List[Location]) -> None: - players = self.multiworld.get_game_players(self.game) + @classmethod + def stage_fill_hook(cls, multiworld: MultiWorld, prog_items: List[Item], useful_items: List[Item], + filler_items: List[Item], locations: List[Location]) -> None: + players = multiworld.get_game_players(cls.game) total_items = len(prog_items) items = {} for index in range(int((total_items * .9)), total_items): @@ -158,8 +159,8 @@ def stage_fill_hook(self, prog_items: List[Item], useful_items: List[Item], fill items.setdefault(prog_items[index].player, []).append((index, prog_items[index])) for player, item_pairs in items.items(): if len(item_pairs) > 1: - item_to_move = self.random.choice(item_pairs) - new_index = self.random.randrange(0, int((total_items * .1))) + item_to_move = multiworld.random.choice(item_pairs) + new_index = multiworld.random.randrange(0, int((total_items * .1))) prog_items.pop(item_to_move[0]) prog_items.insert(new_index, item_to_move[1]) From 0cc314536c7631f437a7f4cbdabd1b7f12e72295 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 15 Nov 2023 21:25:00 -0600 Subject: [PATCH 4/5] hasty forgot to clean that up --- worlds/messenger/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 7674d960b2cf..91ebd95ca151 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -156,7 +156,7 @@ def stage_fill_hook(cls, multiworld: MultiWorld, prog_items: List[Item], useful_ for index in range(int((total_items * .9)), total_items): item = prog_items[index] if item.player in players and item.name in {"Wingsuit", "Rope Dart"}: - items.setdefault(prog_items[index].player, []).append((index, prog_items[index])) + items.setdefault(item.player, []).append((index, item)) for player, item_pairs in items.items(): if len(item_pairs) > 1: item_to_move = multiworld.random.choice(item_pairs) From 7fb6bfc1318186ea55ec501b8f1cae3fe31cbbcd Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 15 Nov 2023 21:28:02 -0600 Subject: [PATCH 5/5] comment to sanitize myself --- worlds/messenger/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 91ebd95ca151..4f5b72466e3f 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -150,6 +150,9 @@ def set_rules(self) -> None: @classmethod def stage_fill_hook(cls, multiworld: MultiWorld, prog_items: List[Item], useful_items: List[Item], filler_items: List[Item], locations: List[Location]) -> None: + # it's possible for both items to get placed near the end of the itempool causing swap to be entered early + # as more than half of the player's locations become unavailable immediately. + # Please don't copy this nightmare players = multiworld.get_game_players(cls.game) total_items = len(prog_items) items = {}