def add_elevator_connections_to_patches(self, configuration: EchoesConfiguration, rng: Random, patches: GamePatches) -> GamePatches: elevator_connection = copy.copy(patches.elevator_connection) elevators = configuration.elevators if not elevators.is_vanilla: if rng is None: raise MissingRng("Elevator") world_list = filtered_database.game_description_for_layout(configuration).world_list elevator_db = elevator_distributor.create_elevator_database( world_list, elevators.editable_teleporters) if elevators.mode in {TeleporterShuffleMode.TWO_WAY_RANDOMIZED, TeleporterShuffleMode.TWO_WAY_UNCHECKED}: connections = elevator_distributor.two_way_elevator_connections( rng=rng, elevator_database=elevator_db, between_areas=elevators.mode == TeleporterShuffleMode.TWO_WAY_RANDOMIZED ) else: connections = elevator_distributor.one_way_elevator_connections( rng=rng, elevator_database=elevator_db, target_locations=elevators.valid_targets, replacement=elevators.mode != TeleporterShuffleMode.ONE_WAY_ELEVATOR, ) elevator_connection.update(connections) for teleporter, destination in elevators.static_teleporters.items(): elevator_connection[teleporter] = destination return dataclasses.replace(patches, elevator_connection=elevator_connection)
def add_elevator_connections_to_patches( layout_configuration: EchoesConfiguration, rng: Random, patches: GamePatches) -> GamePatches: """ :param layout_configuration: :param rng: :param patches: :return: """ elevator_connection = copy.copy(patches.elevator_connection) if layout_configuration.elevators != LayoutElevators.VANILLA: if rng is None: raise MissingRng("Elevator") world_list = data_reader.decode_data( layout_configuration.game_data).world_list areas_to_not_change = { 2278776548, # Sky Temple Gateway 2068511343, # Sky Temple Energy Controller 3136899603, # Aerie Transport Station 1564082177, # Aerie } elevator_db = elevator_distributor.create_elevator_database( world_list, areas_to_not_change) if layout_configuration.elevators in { LayoutElevators.TWO_WAY_RANDOMIZED, LayoutElevators.TWO_WAY_UNCHECKED }: connections = elevator_distributor.two_way_elevator_connections( rng=rng, elevator_database=elevator_db, between_areas=layout_configuration.elevators == LayoutElevators.TWO_WAY_RANDOMIZED) else: connections = elevator_distributor.one_way_elevator_connections( rng=rng, elevator_database=elevator_db, world_list=world_list, elevator_target=layout_configuration.elevators != LayoutElevators.ONE_WAY_ANYTHING, replacement=layout_configuration.elevators == LayoutElevators.ONE_WAY_ELEVATOR_REPLACEMENT, ) elevator_connection.update(connections) if layout_configuration.skip_final_bosses: elevator_connection[136970379] = AreaLocation(1006255871, 1393588666) return dataclasses.replace(patches, elevator_connection=elevator_connection)
def add_elevator_connections_to_patches( layout_configuration: LayoutConfiguration, rng: Random, patches: GamePatches) -> GamePatches: """ :param layout_configuration: :param rng: :param patches: :return: """ if layout_configuration.elevators != LayoutElevators.VANILLA: if rng is None: raise MissingRng("Elevator") world_list = default_database.default_prime2_game_description( ).world_list areas_to_not_change = { 2278776548, # Sky Temple Gateway 2068511343, # Sky Temple Energy Controller 3136899603, # Aerie Transport Station 1564082177, # Aerie } elevator_db = elevator_distributor.create_elevator_database( world_list, areas_to_not_change) if layout_configuration.elevators in { LayoutElevators.TWO_WAY_RANDOMIZED, LayoutElevators.TWO_WAY_UNCHECKED }: connections = elevator_distributor.two_way_elevator_connections( rng=rng, elevator_database=elevator_db, between_areas=layout_configuration.elevators == LayoutElevators.TWO_WAY_RANDOMIZED) else: connections = elevator_distributor.one_way_elevator_connections( rng=rng, elevator_database=elevator_db, world_list=world_list, elevator_target=layout_configuration.elevators == LayoutElevators.ONE_WAY_ELEVATOR) elevator_connection = copy.copy(patches.elevator_connection) elevator_connection.update(connections) return dataclasses.replace(patches, elevator_connection=elevator_connection) else: return patches
def test_two_way_elevator_connections_between_areas( mock_try_randomize_elevators: MagicMock, ): # Setup rng = MagicMock() elevator = MagicMock() database = MagicMock() mock_try_randomize_elevators.return_value = [elevator] # Run result = elevator_distributor.two_way_elevator_connections( rng, database, True) # Assert mock_try_randomize_elevators.assert_called_once_with(rng, database) assert result == { elevator.instance_id: elevator.connected_elevator.area_location, }
def test_two_way_elevator_connections_unchecked(): # Setup rng = random.Random(5000) elevators = [Elevator(i, i, i, i, i) for i in range(6)] database = tuple(elevators) # Run result = elevator_distributor.two_way_elevator_connections( rng, database, False) # Assert assert result == { 0: AreaLocation(4, 4), 1: AreaLocation(2, 2), 2: AreaLocation(1, 1), 3: AreaLocation(5, 5), 4: AreaLocation(0, 0), 5: AreaLocation(3, 3), }
def test_two_way_elevator_connections_between_areas( mock_try_randomize_elevators: MagicMock, ): # Setup rng = MagicMock() elevator_a: ElevatorHelper = MagicMock() elevator_b: ElevatorHelper = MagicMock() mock_try_randomize_elevators.return_value = [elevator_a, elevator_b] # Run result = elevator_distributor.two_way_elevator_connections( rng, (elevator_a, elevator_b), True) # Assert mock_try_randomize_elevators.assert_called_once_with( rng, (elevator_a, elevator_b)) assert result == { elevator_a.teleporter: elevator_a.connected_elevator.area_location, elevator_b.teleporter: elevator_b.connected_elevator.area_location, }
def test_two_way_elevator_connections_unchecked(): # Setup rng = random.Random(5000) elevators = [ ElevatorHelper(NodeIdentifier.create(f"w{i}", f"a{i}", f"n{i}"), AreaIdentifier(f"w{i}", f"a{i}")) for i in range(6) ] database = tuple(elevators) # Run result = elevator_distributor.two_way_elevator_connections( rng, database, False) # Assert assert result == { NodeIdentifier.create("w0", "a0", "n0"): AreaIdentifier("w4", "a4"), NodeIdentifier.create("w1", "a1", "n1"): AreaIdentifier("w2", "a2"), NodeIdentifier.create("w2", "a2", "n2"): AreaIdentifier("w1", "a1"), NodeIdentifier.create("w3", "a3", "n3"): AreaIdentifier("w5", "a5"), NodeIdentifier.create("w4", "a4", "n4"): AreaIdentifier("w0", "a0"), NodeIdentifier.create("w5", "a5", "n5"): AreaIdentifier("w3", "a3"), }
def test_two_way_elevator_connections_unchecked(): # Setup rng = random.Random(5000) elevators = [ ElevatorHelper(Teleporter(i, i, i), AreaLocation(i, i)) for i in range(6) ] database = tuple(elevators) # Run result = elevator_distributor.two_way_elevator_connections( rng, database, False) # Assert assert result == { Teleporter(0, 0, 0): AreaLocation(4, 4), Teleporter(1, 1, 1): AreaLocation(2, 2), Teleporter(2, 2, 2): AreaLocation(1, 1), Teleporter(3, 3, 3): AreaLocation(5, 5), Teleporter(4, 4, 4): AreaLocation(0, 0), Teleporter(5, 5, 5): AreaLocation(3, 3), }