def test_create_message_for_hint_relative_item(echoes_game_patches,
                                               blank_pickup, players_config,
                                               distance_precise, distance_text,
                                               reference_precision,
                                               reference_name):
    patches = echoes_game_patches.assign_new_pickups([
        (PickupIndex(5), PickupTarget(blank_pickup, 0)),
        (PickupIndex(15),
         PickupTarget(
             dataclasses.replace(blank_pickup, name="Reference Pickup"), 0)),
    ])

    hint = Hint(
        HintType.LOCATION,
        PrecisionPair(HintLocationPrecision.RELATIVE_TO_INDEX,
                      HintItemPrecision.DETAILED,
                      include_owner=False,
                      relative=RelativeDataItem(distance_precise,
                                                PickupIndex(15),
                                                reference_precision)),
        PickupIndex(5))

    namer = EchoesHintNamer({0: patches}, PlayersConfiguration(0, {0: "You"}))
    exporter = HintExporter(namer, random.Random(0), ["A Joke"])

    # Run
    result = exporter.create_message_for_hint(hint, {0: patches},
                                              players_config, True)

    # Assert
    assert result == (
        f'The &push;&main-color=#FF6705B3;Blank Pickup&pop; can be found '
        f'&push;&main-color=#FF3333;{distance_text} {7 + (distance_precise or 0)} '
        f'rooms&pop; away from {reference_name}.')
def test_create_message_for_hint_relative_area(echoes_game_patches,
                                               blank_pickup, players_config,
                                               echoes_hint_exporter, offset,
                                               distance_text):
    patches = echoes_game_patches.assign_new_pickups([
        (PickupIndex(5), PickupTarget(blank_pickup, 0)),
    ])

    hint = Hint(
        HintType.LOCATION,
        PrecisionPair(HintLocationPrecision.RELATIVE_TO_AREA,
                      HintItemPrecision.DETAILED,
                      include_owner=False,
                      relative=RelativeDataArea(
                          offset, AreaIdentifier("Torvus Bog", "Great Bridge"),
                          HintRelativeAreaName.NAME)), PickupIndex(5))

    namer = EchoesHintNamer({0: patches}, PlayersConfiguration(0, {0: "You"}))
    exporter = HintExporter(namer, random.Random(0), ["A Joke"])

    # Run
    result = exporter.create_message_for_hint(hint, {0: patches},
                                              players_config, True)

    # Assert
    assert result == (
        f'The &push;&main-color=#FF6705B3;Blank Pickup&pop; can be found '
        f'&push;&main-color=#FF3333;{distance_text} {10 + (offset or 0)} rooms&pop; away from '
        f'Torvus Bog - Great Bridge.')
def test_create_hints_item_dark_temple_keys_cross_game(
    blank_pickup,
    echoes_resource_database,
    echoes_game_patches,
    default_echoes_configuration,
    prime_game_patches,
    default_prime_configuration,
):
    # Setup
    players_config = PlayersConfiguration(
        player_index=0,
        player_names={
            0: "Player 1",
            1: "Player 2",
        },
    )

    keys = [
        dataclasses.replace(
            blank_pickup,
            progression=((echoes_resource_database.get_item(item), 1), ))
        for item in echoes_items.DARK_TEMPLE_KEY_ITEMS[1]
    ]

    echoes_patches = dataclasses.replace(
        echoes_game_patches,
        configuration=default_echoes_configuration,
        pickup_assignment={
            PickupIndex(14): PickupTarget(keys[0], 0),
            PickupIndex(80): PickupTarget(keys[2], 0),
        })
    prime_patches = dataclasses.replace(
        prime_game_patches,
        configuration=default_prime_configuration,
        pickup_assignment={
            PickupIndex(23): PickupTarget(keys[1], 0),
        })

    hint = Hint(HintType.RED_TEMPLE_KEY_SET,
                None,
                dark_temple=HintDarkTemple.TORVUS_BOG)

    namer = EchoesHintNamer({
        0: echoes_patches,
        1: prime_patches
    }, players_config)
    exporter = HintExporter(namer, random.Random(0), ["A Joke"])

    # Run
    result = exporter.create_message_for_hint(hint, {
        0: echoes_patches,
        1: prime_patches
    }, players_config, True)

    # Assert
    assert result == (
        'The keys to &push;&main-color=#FF6705B3;Dark Torvus Temple&pop; can be found '
        'in &push;&main-color=#FF3333;Chozo Ruins&pop;, '
        '&push;&main-color=#FF3333;Dark Torvus Bog&pop; and '
        '&push;&main-color=#FF3333;Temple Grounds&pop;.')
def test_create_hints_item_joke(empty_patches, players_config):
    # Setup
    asset_id = 1000
    logbook_node, _, world_list = _create_world_list(asset_id, PickupIndex(50))

    patches = dataclasses.replace(
        empty_patches,
        hints={
            world_list.identifier_for_node(logbook_node):
            Hint(HintType.JOKE, None)
        })
    rng = MagicMock()
    namer = EchoesHintNamer({0: patches}, players_config)

    # Run
    result = hints.create_patches_hints({0: patches}, players_config,
                                        world_list, namer, rng)

    # Assert
    joke = "While walking, holding L makes you move faster."
    message = f"&push;&main-color=#45F731;{joke}&pop;"
    assert result[0]['strings'][0] == message
    assert result == [{
        'asset_id': asset_id,
        'strings': [message, '', message]
    }]
    def update_content(self, configuration: BaseConfiguration,
                       all_patches: dict[int, GamePatches],
                       players: PlayersConfiguration):
        self.tree_widget.clear()
        self.tree_widget.setColumnCount(3)
        self.tree_widget.setHeaderLabels(["Hint", "Pickup", "In-Game Text"])

        game = filtered_database.game_description_for_layout(configuration)
        world_list = game.world_list
        patches = all_patches[players.player_index]

        per_world: dict[str, dict[str,
                                  tuple[str,
                                        str]]] = collections.defaultdict(dict)
        namer = EchoesHintNamer(all_patches, players)
        exporter = HintExporter(namer, random.Random(0), ["A joke hint."])

        for identifier, hint in patches.hints.items():
            node = world_list.node_by_identifier(identifier)
            source_world = world_list.nodes_to_world(node)
            source_name = world_list.node_name(node)

            hint_text = exporter.create_message_for_hint(
                hint, all_patches, players, False)

            if hint.target is None:
                hinted_pickup = ""
            else:
                target = patches.pickup_assignment.get(hint.target)
                if target is None:
                    hinted_pickup = "Nothing"
                else:
                    hinted_pickup = target.pickup.name
                    if players.is_multiworld:
                        hinted_pickup = f"{players.player_names[target.player]}'s {hinted_pickup}"

            per_world[source_world.name][source_name] = (hint_text,
                                                         hinted_pickup)

        for world_name, world_contents in iterate_key_sorted(per_world):
            world_item = QtWidgets.QTreeWidgetItem(self.tree_widget)
            world_item.setText(0, world_name)
            world_item.setExpanded(True)
            for source_name, content in iterate_key_sorted(world_contents):
                area_item = QtWidgets.QTreeWidgetItem(world_item)
                area_item.setText(0, source_name)
                area_item.setText(1, content[1])
                area_item.setText(2, content[0])

        self.tree_widget.resizeColumnToContents(0)
        self.tree_widget.resizeColumnToContents(1)
        self.tree_widget.resizeColumnToContents(3)
def test_create_hints_item_location(echoes_game_patches, blank_pickup, item,
                                    location, owner, is_multiworld,
                                    echoes_game_description, monkeypatch):
    # Setup
    asset_id = 1000
    pickup_index = PickupIndex(50)
    logbook_node, _, world_list = _create_world_list(asset_id, pickup_index)
    monkeypatch.setattr(echoes_game_description, "world_list", world_list)

    players_config = PlayersConfiguration(
        player_index=0,
        player_names={
            i: f"Player {i + 1}"
            for i in range(int(is_multiworld) + 1)
        },
    )
    location_precision, determiner, item_name = item
    if owner and is_multiworld:
        determiner = "&push;&main-color=#d4cc33;Player 1&pop;'s"

    patches = dataclasses.replace(
        echoes_game_patches,
        pickup_assignment={
            pickup_index: PickupTarget(blank_pickup, 0),
        },
        hints={
            world_list.identifier_for_node(logbook_node):
            Hint(
                HintType.LOCATION,
                PrecisionPair(location[0],
                              location_precision,
                              include_owner=owner),
                pickup_index,
            )
        })
    rng = MagicMock()
    namer = EchoesHintNamer({0: patches}, players_config)

    # Run
    result = hints.create_patches_hints({0: patches}, players_config,
                                        world_list, namer, rng)

    # Assert
    message = "{} {} can be found in {}.".format(determiner, item_name,
                                                 location[1])
    # message = "The Flying Ing Cache in {} contains {}.".format(location[1], item[1])
    assert result[0]['strings'][0] == message
    assert result == [{
        'asset_id': asset_id,
        'strings': [message, '', message]
    }]
Beispiel #7
0
def test_hide_hints(empty_patches):
    # Setup
    expected = [
        {
            "asset_id": 0xD97685FE,
            "strings": make_useless_stk_hint(1)
        },
        {
            "asset_id": 0x32413EFD,
            "strings": make_useless_stk_hint(2)
        },
        {
            "asset_id": 0xDD8355C3,
            "strings": make_useless_stk_hint(3)
        },
        {
            "asset_id": 0x3F5F4EBA,
            "strings": make_useless_stk_hint(4)
        },
        {
            "asset_id": 0xD09D2584,
            "strings": make_useless_stk_hint(5)
        },
        {
            "asset_id": 0x3BAA9E87,
            "strings": make_useless_stk_hint(6)
        },
        {
            "asset_id": 0xD468F5B9,
            "strings": make_useless_stk_hint(7)
        },
        {
            "asset_id": 0x2563AE34,
            "strings": make_useless_stk_hint(8)
        },
        {
            "asset_id": 0xCAA1C50A,
            "strings": make_useless_stk_hint(9)
        },
    ]

    namer = EchoesHintNamer({0: empty_patches}, PlayersConfiguration(0, {}))

    # Run
    result = randovania.games.prime2.exporter.hints.hide_stk_hints(namer)

    # Assert
    assert result == expected
def test_create_hints_light_suit_location(echoes_game_patches, players_config,
                                          blank_pickup, item,
                                          echoes_game_description,
                                          monkeypatch):
    # Setup
    asset_id = 1000
    pickup_index = PickupIndex(50)

    logbook_node, _, world_list = _create_world_list(asset_id, pickup_index)
    monkeypatch.setattr(echoes_game_description, "world_list", world_list)

    patches = dataclasses.replace(
        echoes_game_patches,
        pickup_assignment={
            pickup_index: PickupTarget(blank_pickup, 0),
        },
        hints={
            world_list.identifier_for_node(logbook_node):
            Hint(
                HintType.LOCATION,
                PrecisionPair(HintLocationPrecision.LIGHT_SUIT_LOCATION,
                              item[0],
                              include_owner=False),
                pickup_index,
            )
        })
    rng = MagicMock()
    namer = EchoesHintNamer({0: patches}, players_config)

    # Run
    result = hints.create_patches_hints({0: patches}, players_config,
                                        world_list, namer, rng)

    # Assert
    message = f"U-Mos's reward for returning the Sanctuary energy is {item[1]}."
    assert result == [{
        'asset_id': asset_id,
        'strings': [message, '', message]
    }]
def test_create_hints_guardians(echoes_game_patches, pickup_index_and_guardian,
                                blank_pickup, item, players_config,
                                echoes_game_description, monkeypatch):
    # Setup
    asset_id = 1000
    pickup_index, guardian = pickup_index_and_guardian

    logbook_node, _, world_list = _create_world_list(asset_id, pickup_index)
    monkeypatch.setattr(echoes_game_description, "world_list", world_list)

    patches = dataclasses.replace(
        echoes_game_patches,
        pickup_assignment={
            pickup_index: PickupTarget(blank_pickup, 0),
        },
        hints={
            world_list.identifier_for_node(logbook_node):
            Hint(
                HintType.LOCATION,
                PrecisionPair(HintLocationPrecision.GUARDIAN,
                              item[0],
                              include_owner=False),
                pickup_index,
            )
        })
    rng = MagicMock()
    namer = EchoesHintNamer({0: patches}, players_config)

    # Run
    result = hints.create_patches_hints({0: patches}, players_config,
                                        world_list, namer, rng)

    # Assert
    message = f"{guardian} is guarding {item[1]}."
    assert result == [{
        'asset_id': asset_id,
        'strings': [message, '', message]
    }]
def test_create_hints_nothing(echoes_game_patches, players_config, monkeypatch,
                              echoes_game_description):
    # Setup
    asset_id = 1000
    pickup_index = PickupIndex(0)

    logbook_node, _, world_list = _create_world_list(asset_id, pickup_index)
    monkeypatch.setattr(echoes_game_description, "world_list", world_list)

    patches = dataclasses.replace(
        echoes_game_patches,
        hints={
            world_list.identifier_for_node(logbook_node):
            Hint(
                HintType.LOCATION,
                PrecisionPair(HintLocationPrecision.DETAILED,
                              HintItemPrecision.DETAILED,
                              include_owner=False),
                pickup_index,
            )
        })
    rng = MagicMock()
    namer = EchoesHintNamer({0: patches}, players_config)

    # Run
    result = hints.create_patches_hints({0: patches}, players_config,
                                        world_list, namer, rng)

    # Assert
    message = (
        "The &push;&main-color=#FF6705B3;Energy Transfer Module&pop; can be found in "
        "&push;&main-color=#FF3333;World - Area&pop;.")
    assert result == [{
        'asset_id': asset_id,
        'strings': [message, '', message]
    }]
def test_create_hints_item_dark_temple_keys(echoes_game_patches,
                                            players_config,
                                            echoes_game_description,
                                            blank_pickup, indices,
                                            expected_message, preset_manager):
    # Setup
    db = echoes_game_description.resource_database
    keys = [
        (PickupIndex(index),
         dataclasses.replace(blank_pickup,
                             progression=((db.get_item(item), 1), )))
        for index, item in zip(indices, echoes_items.DARK_TEMPLE_KEY_ITEMS[1])
    ]

    patches = dataclasses.replace(
        echoes_game_patches,
        configuration=preset_manager.default_preset_for_game(
            db.game_enum).get_preset().configuration,
        pickup_assignment={
            pickup_index: PickupTarget(key, 0)
            for pickup_index, key in keys
        })

    hint = Hint(HintType.RED_TEMPLE_KEY_SET,
                None,
                dark_temple=HintDarkTemple.TORVUS_BOG)

    namer = EchoesHintNamer({0: patches}, players_config)
    exporter = HintExporter(namer, random.Random(0), ["A Joke"])

    # Run
    result = exporter.create_message_for_hint(hint, {0: patches},
                                              players_config, True)

    # Assert
    assert result == expected_message
Beispiel #12
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.namer = EchoesHintNamer(self.description.all_patches,
                                  self.players_config)
Beispiel #13
0
def test_create_hints_all_placed(hide_area: bool, multiworld: bool,
                                 empty_patches, default_echoes_configuration,
                                 default_prime_configuration):
    # Setup
    echoes_game = default_database.game_description_for(
        RandovaniaGame.METROID_PRIME_ECHOES)
    players_config = PlayersConfiguration(0, {
        0: "you",
        1: "them"
    } if multiworld else {0: "you"})

    patches = empty_patches.assign_new_pickups([
        (PickupIndex(17 + key),
         PickupTarget(
             pickup_creator.create_sky_temple_key(
                 key, echoes_game.resource_database), 0))
        for key in range(5 if multiworld else 9)
    ])
    patches = dataclasses.replace(patches,
                                  configuration=default_echoes_configuration)

    other_patches = empty_patches.assign_new_pickups([
        (PickupIndex(17 + key),
         PickupTarget(
             pickup_creator.create_sky_temple_key(
                 key, echoes_game.resource_database), 0))
        for key in range(5, 9)
    ])
    other_patches = dataclasses.replace(
        other_patches, configuration=default_prime_configuration)
    assets = [
        0xD97685FE, 0x32413EFD, 0xDD8355C3, 0x3F5F4EBA, 0xD09D2584, 0x3BAA9E87,
        0xD468F5B9, 0x2563AE34, 0xCAA1C50A
    ]

    locations = [
        "Sky Temple Grounds - Profane Path",
        "Sky Temple Grounds - Phazon Grounds",
        "Sky Temple Grounds - Ing Reliquary",
        "Great Temple - Transport A Access",
        "Great Temple - Temple Sanctuary",
        "Great Temple - Transport B Access",
        "Great Temple - Main Energy Controller",
        "Great Temple - Main Energy Controller",
        "Agon Wastes - Mining Plaza",
    ]
    other_locations = [
        "Chozo Ruins - Watery Hall Access",
        "Chozo Ruins - Watery Hall",
        "Chozo Ruins - Watery Hall",
        "Chozo Ruins - Dynamo",
    ]
    if multiworld:
        locations[-len(other_locations):] = other_locations

    expected = [{
        "asset_id":
        asset_id,
        "strings":
        _create_hint_text(hide_area, multiworld, i + 1, text)
    } for i, (asset_id, text) in enumerate(zip(assets, locations))]

    namer = EchoesHintNamer({0: patches, 1: other_patches}, players_config)

    # Run
    result = randovania.games.prime2.exporter.hints.create_stk_hints(
        {
            0: patches,
            1: other_patches
        } if multiworld else {0: patches}, players_config,
        echoes_game.resource_database, namer, hide_area)

    # Assert
    assert result == expected
Beispiel #14
0
def test_create_hints_all_starting(hide_area: bool, multiworld: bool,
                                   empty_patches, echoes_game_description,
                                   default_echoes_configuration):
    # Setup
    players_config = PlayersConfiguration(0, {
        0: "you",
        1: "them"
    } if multiworld else {0: "you"})
    patches = empty_patches.assign_extra_initial_items({
        echoes_game_description.resource_database.get_item(
            echoes_items.SKY_TEMPLE_KEY_ITEMS[key]): 1
        for key in range(9)
    })
    patches = dataclasses.replace(patches,
                                  configuration=default_echoes_configuration)
    namer = EchoesHintNamer({0: patches}, players_config)

    expected = [
        {
            "asset_id": 0xD97685FE,
            "strings": make_starting_stk_hint(1)
        },
        {
            "asset_id": 0x32413EFD,
            "strings": make_starting_stk_hint(2)
        },
        {
            "asset_id": 0xDD8355C3,
            "strings": make_starting_stk_hint(3)
        },
        {
            "asset_id": 0x3F5F4EBA,
            "strings": make_starting_stk_hint(4)
        },
        {
            "asset_id": 0xD09D2584,
            "strings": make_starting_stk_hint(5)
        },
        {
            "asset_id": 0x3BAA9E87,
            "strings": make_starting_stk_hint(6)
        },
        {
            "asset_id": 0xD468F5B9,
            "strings": make_starting_stk_hint(7)
        },
        {
            "asset_id": 0x2563AE34,
            "strings": make_starting_stk_hint(8)
        },
        {
            "asset_id": 0xCAA1C50A,
            "strings": make_starting_stk_hint(9)
        },
    ]

    # Run
    result = randovania.games.prime2.exporter.hints.create_stk_hints(
        {0: patches}, players_config,
        echoes_game_description.resource_database, namer, hide_area)

    # Assert
    assert result == expected
def _echoes_hint_exporter(echoes_game_patches) -> HintExporter:
    namer = EchoesHintNamer({0: echoes_game_patches},
                            PlayersConfiguration(0, {0: "You"}))
    return HintExporter(namer, random.Random(0), ["A Joke"])