diff --git a/BaseClasses.py b/BaseClasses.py index f2aea3893dcf..2cc7596e5fe0 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -81,6 +81,7 @@ class MultiWorld(): random: random.Random per_slot_randoms: Dict[int, random.Random] + """Deprecated. Please use `self.random` instead.""" class AttributeProxy(): def __init__(self, rule): @@ -242,6 +243,7 @@ def set_options(self, args: Namespace) -> None: setattr(self, option_key, getattr(args, option_key, {})) self.worlds[player] = world_type(self, player) + self.worlds[player].random = self.per_slot_randoms[player] def set_item_links(self): item_links = {} diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index b569d3f462f1..32c189faf84f 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -203,6 +203,9 @@ class World(metaclass=AutoWorldRegister): location_names: ClassVar[Set[str]] """set of all potential location names""" + random: random.Random + """This world's random object. Should be used for any randomization needed in world for this player slot.""" + zip_path: ClassVar[Optional[pathlib.Path]] = None """If loaded from a .apworld, this is the Path to it.""" __file__: ClassVar[str] diff --git a/worlds/alttp/test/dungeons/TestDungeon.py b/worlds/alttp/test/dungeons/TestDungeon.py index 893e6919c2d0..73ece1541733 100644 --- a/worlds/alttp/test/dungeons/TestDungeon.py +++ b/worlds/alttp/test/dungeons/TestDungeon.py @@ -14,6 +14,7 @@ class TestDungeon(unittest.TestCase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/alttp/test/inverted/TestInverted.py b/worlds/alttp/test/inverted/TestInverted.py index 4e33444bb5ab..ad7458202ead 100644 --- a/worlds/alttp/test/inverted/TestInverted.py +++ b/worlds/alttp/test/inverted/TestInverted.py @@ -15,6 +15,7 @@ class TestInverted(TestBase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/alttp/test/inverted/TestInvertedBombRules.py b/worlds/alttp/test/inverted/TestInvertedBombRules.py index 0eeaf38564e9..89c5d7860323 100644 --- a/worlds/alttp/test/inverted/TestInvertedBombRules.py +++ b/worlds/alttp/test/inverted/TestInvertedBombRules.py @@ -15,6 +15,7 @@ class TestInvertedBombRules(unittest.TestCase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) self.multiworld.mode[1] = "inverted" args = Namespace for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): diff --git a/worlds/alttp/test/inverted_minor_glitches/TestInvertedMinor.py b/worlds/alttp/test/inverted_minor_glitches/TestInvertedMinor.py index afc683478c2d..72049e17742c 100644 --- a/worlds/alttp/test/inverted_minor_glitches/TestInvertedMinor.py +++ b/worlds/alttp/test/inverted_minor_glitches/TestInvertedMinor.py @@ -16,6 +16,7 @@ class TestInvertedMinor(TestBase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/alttp/test/inverted_owg/TestInvertedOWG.py b/worlds/alttp/test/inverted_owg/TestInvertedOWG.py index 359a58e4ed2a..77a551db6f87 100644 --- a/worlds/alttp/test/inverted_owg/TestInvertedOWG.py +++ b/worlds/alttp/test/inverted_owg/TestInvertedOWG.py @@ -17,6 +17,7 @@ class TestInvertedOWG(TestBase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/alttp/test/minor_glitches/TestMinor.py b/worlds/alttp/test/minor_glitches/TestMinor.py index de19a717060c..fdf626fe9d37 100644 --- a/worlds/alttp/test/minor_glitches/TestMinor.py +++ b/worlds/alttp/test/minor_glitches/TestMinor.py @@ -16,6 +16,7 @@ class TestMinor(TestBase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/alttp/test/owg/TestVanillaOWG.py b/worlds/alttp/test/owg/TestVanillaOWG.py index a12679b8cfd1..5b02666db37e 100644 --- a/worlds/alttp/test/owg/TestVanillaOWG.py +++ b/worlds/alttp/test/owg/TestVanillaOWG.py @@ -17,6 +17,7 @@ class TestVanillaOWG(TestBase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/alttp/test/vanilla/TestVanilla.py b/worlds/alttp/test/vanilla/TestVanilla.py index 32c9c6180049..92035c8641b3 100644 --- a/worlds/alttp/test/vanilla/TestVanilla.py +++ b/worlds/alttp/test/vanilla/TestVanilla.py @@ -15,6 +15,7 @@ class TestVanilla(TestBase): def setUp(self): self.multiworld = MultiWorld(1) + self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): setattr(args, name, {1: option.from_any(option.default)}) diff --git a/worlds/messenger/Shop.py b/worlds/messenger/Shop.py index 99f9a4436119..68f415349b7b 100644 --- a/worlds/messenger/Shop.py +++ b/worlds/messenger/Shop.py @@ -75,13 +75,12 @@ class ShopData(NamedTuple): def shuffle_shop_prices(world: MessengerWorld) -> Tuple[Dict[str, int], Dict[str, int]]: shop_price_mod = world.multiworld.shop_price[world.player].value shop_price_planned = world.multiworld.shop_price_plan[world.player] - local_random: Random = world.multiworld.per_slot_randoms[world.player] shop_prices: Dict[str, int] = {} figurine_prices: Dict[str, int] = {} for item, price in shop_price_planned.value.items(): if not isinstance(price, int): - price = local_random.choices(list(price.keys()), weights=list(price.values()))[0] + price = world.random.choices(list(price.keys()), weights=list(price.values()))[0] if "Figurine" in item: figurine_prices[item] = price else: @@ -90,7 +89,7 @@ def shuffle_shop_prices(world: MessengerWorld) -> Tuple[Dict[str, int], Dict[str remaining_slots = [item for item in [*SHOP_ITEMS, *FIGURINES] if item not in shop_price_planned.value] for shop_item in remaining_slots: shop_data = SHOP_ITEMS.get(shop_item, FIGURINES.get(shop_item)) - price = local_random.randint(shop_data.min_price, shop_data.max_price) + price = world.random.randint(shop_data.min_price, shop_data.max_price) adjusted_price = min(int(price * shop_price_mod / 100), 5000) if "Figurine" in shop_item: figurine_prices[shop_item] = adjusted_price diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 8cefdcc9108d..369b43fac9bb 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -102,7 +102,7 @@ def create_items(self) -> None: # make a list of all notes except those in the player's defined starting inventory, and adjust the # amount we need to put in the itempool and precollect based on that notes = [note for note in NOTES if note not in self.multiworld.precollected_items[self.player]] - self.multiworld.per_slot_randoms[self.player].shuffle(notes) + self.random.shuffle(notes) precollected_notes_amount = NotesNeeded.range_end - \ self.multiworld.notes_needed[self.player] - \ (len(NOTES) - len(notes)) @@ -129,7 +129,7 @@ def create_items(self) -> None: filler_pool = dict(list(FILLER.items())[2:]) if remaining_fill < 10 else FILLER itempool += [self.create_item(filler_item) for filler_item in - self.multiworld.random.choices( + self.random.choices( list(filler_pool), weights=list(filler_pool.values()), k=remaining_fill